This commit is contained in:
Adam Lemiesz 2022-03-20 13:01:50 +01:00
parent 067ff83cf1
commit 107e8d853d
5 changed files with 36 additions and 29 deletions

View File

@ -558,6 +558,8 @@
<entry key="../../../../layout/compose-model-1647622253064.xml" value="0.1" />
<entry key="../../../../layout/compose-model-1647625897576.xml" value="0.16296296296296298" />
<entry key="../../../../layout/compose-model-1647626067141.xml" value="0.16296296296296298" />
<entry key="../../../../layout/compose-model-1647774676397.xml" value="0.16296296296296298" />
<entry key="../../../../layout/compose-model-1647775094061.xml" value="0.16296296296296298" />
</map>
</option>
</component>

View File

@ -81,7 +81,7 @@ dependencies {
}
group = 'org.lemiesz.alib'
version = '1.2.10'
version = '1.2.14'
afterEvaluate {
publishing {

View File

@ -18,32 +18,34 @@ import org.lemiesz.alib.logNav
import org.lemiesz.alib.ui.content.ComposeFragment
import org.lemiesz.alib.ui.FabState
import org.lemiesz.alib.ui.bar.TopBarState
import org.lemiesz.alib.ui.content.FragmentInfo
import org.lemiesz.alib.ui.content.WithParam
import org.lemiesz.alib.ui.content.WithoutParam
import org.lemiesz.klib.flow.mapStateFlow
import kotlin.reflect.KClass
interface NavPage {
val name: () -> String
val info: FragmentInfo
}
class NavPageSingle(
override val name: () -> String,
override val info: FragmentInfo,
val contentCreator: @Composable () -> Unit,
val fabCreator: @Composable (fabState: MutableState<FabState>) -> Unit,
val topBarCreator: @Composable (topBarState: MutableState<TopBarState>) -> Unit
val topBarCreator: @Composable (topBarState: MutableState<TopBarState>) -> Unit,
val topLevel: Boolean = false
) : NavPage {
fun route(): String = name()
fun route(): String = info.name
}
class NavPageParam<P : Any>(
override val name: () -> String,
override val info: FragmentInfo,
val contentCreator: @Composable (P) -> Unit,
val fabCreator: @Composable (fabState: MutableState<FabState>) -> Unit,
val topBarCreator: @Composable (topBarState: MutableState<TopBarState>) -> Unit,
val arg: KClass<P>
) : NavPage {
val routeString: String = "${name()}?param={param}"
val routeString: String = "${info.name}?param={param}"
@OptIn(ExperimentalSerializationApi::class)
@Composable
@ -119,7 +121,7 @@ object NavChartImpl : NavChart {
topBarCreator = { topBarState ->
fragment.topBarState = topBarState
},
name = { fragment.info.name }
info = fragment.info
).also {
pagesList.add(it)
}
@ -138,7 +140,7 @@ object NavChartImpl : NavChart {
topBarCreator = { topBarState ->
fragment.topBarState = topBarState
},
name = { fragment.info.name },
info = fragment.info,
arg = args
).also {
pagesList.add(it)
@ -155,7 +157,7 @@ object NavChartImpl : NavChart {
when (page) {
is NavPageSingle -> {
composable(
route = page.name(),
route = page.info.name,
) {
page.apply {
contentCreator()
@ -192,14 +194,19 @@ object NavChartImpl : NavChart {
}
fun navigateTo(entry: NavPageSingle) {
@Suppress("UNCHECKED_CAST")
hostController?.navigate(route = entry.route())
entry.apply {
if (topLevel) {
hostController?.backQueue?.firstOrNull()?.id?.also {
hostController?.clearBackStack(it)
}
}
hostController?.navigate(route = route())
logNav { "navigateTo" }
logNav { "navigateTo" }
}
}
fun <P : Any> navigateTo(param: P, entry: NavPageParam<P>) {
@Suppress("UNCHECKED_CAST")
hostController?.navigate(route = entry.route(param))
logNav { "navigateTo $param" }
}

View File

@ -18,8 +18,8 @@ import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.window.PopupProperties
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import org.lemiesz.alib.lib.rememberState
import org.lemiesz.alib.mock.PreviewTheme
@ -61,15 +61,13 @@ fun DropDown(
val mis = remember {
MutableInteractionSource().apply {
scope.launch {
interactions.collect {
Log.i("interaction", "$it")
when (it) {
is FocusInteraction.Focus -> openCloseOfDropDownList(true)
is FocusInteraction.Unfocus -> openCloseOfDropDownList(false)
}
interactions.onEach {
Log.i("interaction", "$it")
when (it) {
is FocusInteraction.Focus -> openCloseOfDropDownList(true)
is FocusInteraction.Unfocus -> openCloseOfDropDownList(false)
}
}
}.launchIn(scope)
}
}

View File

@ -8,16 +8,16 @@ import org.lemiesz.alib.ui.bar.TopBarState
class FragmentInfo(
val name: String,
val title: String,
val icon: ImageVector?
val title: @Composable () -> String,
val icon: (@Composable () -> ImageVector)?,
)
fun <C: ComposeFragment> C.fragmentInfo(
name: String = this::class.simpleName!!,
title: String = "",
icon: ImageVector? = null
title: (@Composable () -> String)? = null,
icon: (@Composable () -> ImageVector)? = null,
): FragmentInfo = FragmentInfo(
name = name,
title = title.ifBlank { name },
title = title ?: { "" },
icon = icon
)