refactor: some tweaks in Navigation

This commit is contained in:
2023-11-30 12:55:05 +08:00
parent 3ced4acbd3
commit a92499e5ce

View File

@@ -121,7 +121,7 @@ fun NavigationItem(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
enabled: Boolean = true, enabled: Boolean = true,
colors: NavigationColors? = null, colors: NavigationColors? = null,
contentSpace: Dp = Dp.Unspecified, contentSpacing: Dp = Dp.Unspecified,
contentPadding: PaddingValues? = null, contentPadding: PaddingValues? = null,
contentShape: Shape? = null, contentShape: Shape? = null,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
@@ -130,7 +130,7 @@ fun NavigationItem(
) { ) {
val currentHorizontal = horizontal ?: LocalHorizontalNavigation.current val currentHorizontal = horizontal ?: LocalHorizontalNavigation.current
val currentColors = colors ?: LocalNavigationColors.current ?: Navigation.colors val currentColors = colors ?: LocalNavigationColors.current ?: Navigation.colors
val currentContentSpace = contentSpace.orElse() ?: LocalNavigationContentSpace.current.orElse() ?: Navigation.style.contentSpacing val currentContentSpacing = contentSpacing.orElse() ?: LocalNavigationContentSpacing.current.orElse() ?: Navigation.style.contentSpacing
val currentContentPadding = contentPadding ?: LocalNavigationContentPadding.current ?: Navigation.style.contentPadding val currentContentPadding = contentPadding ?: LocalNavigationContentPadding.current ?: Navigation.style.contentPadding
val currentContentShape = contentShape ?: LocalNavigationContentShape.current ?: Navigation.style.contentShape val currentContentShape = contentShape ?: LocalNavigationContentShape.current ?: Navigation.style.contentShape
val animatedIndicatorColor by animateColorAsState(if (selected) currentColors.indicatorColor else Color.Transparent) val animatedIndicatorColor by animateColorAsState(if (selected) currentColors.indicatorColor else Color.Transparent)
@@ -167,7 +167,7 @@ fun NavigationItem(
exit = shrinkHorizontally() exit = shrinkHorizontally()
) { ) {
Row { Row {
Box(modifier = Modifier.width(currentContentSpace)) Box(modifier = Modifier.width(currentContentSpacing))
content() content()
} }
} }
@@ -180,7 +180,7 @@ fun NavigationItem(
) { ) {
icon() icon()
text?.also { content -> text?.also { content ->
Box(modifier = Modifier.height(currentContentSpace / 2)) Box(modifier = Modifier.height(currentContentSpacing / 2))
content() content()
} }
} }
@@ -222,7 +222,7 @@ private val LocalHorizontalNavigation = compositionLocalOf { true }
private val LocalNavigationColors = compositionLocalOf<NavigationColors?> { null } private val LocalNavigationColors = compositionLocalOf<NavigationColors?> { null }
private val LocalNavigationContentSpace = compositionLocalOf { Dp.Unspecified } private val LocalNavigationContentSpacing = compositionLocalOf { Dp.Unspecified }
private val LocalNavigationContentPadding = compositionLocalOf<PaddingValues?> { null } private val LocalNavigationContentPadding = compositionLocalOf<PaddingValues?> { null }