mirror of
https://github.com/BetterAndroid/FlexiUI.git
synced 2025-09-09 20:14:18 +08:00
refactor: rename Navigation to NavigationBar
This commit is contained in:
@@ -64,7 +64,7 @@ import com.highcapable.flexiui.interaction.Interaction
|
|||||||
import com.highcapable.flexiui.interaction.rippleClickable
|
import com.highcapable.flexiui.interaction.rippleClickable
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
data class NavigationColors(
|
data class NavigationBarColors(
|
||||||
val backgroundColor: Color,
|
val backgroundColor: Color,
|
||||||
val indicatorColor: Color,
|
val indicatorColor: Color,
|
||||||
val selectedContentColor: Color,
|
val selectedContentColor: Color,
|
||||||
@@ -72,7 +72,7 @@ data class NavigationColors(
|
|||||||
)
|
)
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
data class NavigationStyle(
|
data class NavigationBarStyle(
|
||||||
val boxStyle: AreaBoxStyle,
|
val boxStyle: AreaBoxStyle,
|
||||||
val contentSpacing: Dp,
|
val contentSpacing: Dp,
|
||||||
val contentPadding: ComponentPadding,
|
val contentPadding: ComponentPadding,
|
||||||
@@ -82,12 +82,12 @@ data class NavigationStyle(
|
|||||||
@Composable
|
@Composable
|
||||||
fun NavigationRow(
|
fun NavigationRow(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
colors: NavigationColors = Navigation.colors,
|
colors: NavigationBarColors = NavigationBar.colors,
|
||||||
style: NavigationStyle = Navigation.style,
|
style: NavigationBarStyle = NavigationBar.style,
|
||||||
arrangement: Arrangement.Horizontal = Arrangement.SpaceBetween,
|
arrangement: Arrangement.Horizontal = Arrangement.SpaceBetween,
|
||||||
content: @Composable RowScope.() -> Unit
|
content: @Composable RowScope.() -> Unit
|
||||||
) {
|
) {
|
||||||
NavigationStyleBox(modifier, horizontal = true, colors, style) {
|
NavigationBarStyleBox(modifier, horizontal = true, colors, style) {
|
||||||
AreaRow(
|
AreaRow(
|
||||||
modifier = Modifier.fillMaxWidth().selectableGroup(),
|
modifier = Modifier.fillMaxWidth().selectableGroup(),
|
||||||
color = colors.backgroundColor,
|
color = colors.backgroundColor,
|
||||||
@@ -102,12 +102,12 @@ fun NavigationRow(
|
|||||||
@Composable
|
@Composable
|
||||||
fun NavigationColumn(
|
fun NavigationColumn(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
colors: NavigationColors = Navigation.colors,
|
colors: NavigationBarColors = NavigationBar.colors,
|
||||||
style: NavigationStyle = Navigation.style,
|
style: NavigationBarStyle = NavigationBar.style,
|
||||||
arrangement: Arrangement.Vertical = Arrangement.SpaceBetween,
|
arrangement: Arrangement.Vertical = Arrangement.SpaceBetween,
|
||||||
content: @Composable ColumnScope.() -> Unit
|
content: @Composable ColumnScope.() -> Unit
|
||||||
) {
|
) {
|
||||||
NavigationStyleBox(modifier, horizontal = false, colors, style) {
|
NavigationBarStyleBox(modifier, horizontal = false, colors, style) {
|
||||||
AreaColumn(
|
AreaColumn(
|
||||||
modifier = Modifier.fillMaxWidth().selectableGroup(),
|
modifier = Modifier.fillMaxWidth().selectableGroup(),
|
||||||
color = colors.backgroundColor,
|
color = colors.backgroundColor,
|
||||||
@@ -120,13 +120,13 @@ fun NavigationColumn(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun NavigationItem(
|
fun NavigationBarItem(
|
||||||
selected: Boolean,
|
selected: Boolean,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
horizontal: Boolean? = null,
|
horizontal: Boolean? = null,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
colors: NavigationColors? = null,
|
colors: NavigationBarColors? = null,
|
||||||
contentSpacing: Dp = Dp.Unspecified,
|
contentSpacing: Dp = Dp.Unspecified,
|
||||||
contentPadding: PaddingValues? = null,
|
contentPadding: PaddingValues? = null,
|
||||||
contentShape: Shape? = null,
|
contentShape: Shape? = null,
|
||||||
@@ -134,11 +134,11 @@ fun NavigationItem(
|
|||||||
icon: @Composable () -> Unit,
|
icon: @Composable () -> Unit,
|
||||||
text: @Composable (() -> Unit)? = null
|
text: @Composable (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
val currentHorizontal = horizontal ?: LocalHorizontalNavigation.current
|
val currentHorizontal = horizontal ?: LocalHorizontalNavigationBar.current
|
||||||
val currentColors = colors ?: LocalNavigationColors.current ?: Navigation.colors
|
val currentColors = colors ?: LocalNavigationBarColors.current ?: NavigationBar.colors
|
||||||
val currentContentSpacing = contentSpacing.orNull() ?: LocalNavigationContentSpacing.current.orNull() ?: Navigation.style.contentSpacing
|
val currentContentSpacing = contentSpacing.orNull() ?: LocalNavigationBarContentSpacing.current.orNull() ?: NavigationBar.style.contentSpacing
|
||||||
val currentContentPadding = contentPadding ?: LocalNavigationContentPadding.current ?: Navigation.style.contentPadding
|
val currentContentPadding = contentPadding ?: LocalNavigationBarContentPadding.current ?: NavigationBar.style.contentPadding
|
||||||
val currentContentShape = contentShape ?: LocalNavigationContentShape.current ?: Navigation.style.contentShape
|
val currentContentShape = contentShape ?: LocalNavigationBarContentShape.current ?: NavigationBar.style.contentShape
|
||||||
val animatedIndicatorColor by animateColorAsState(if (selected) currentColors.indicatorColor else Color.Transparent)
|
val animatedIndicatorColor by animateColorAsState(if (selected) currentColors.indicatorColor else Color.Transparent)
|
||||||
val animatedContentColor by animateColorAsState(if (selected) currentColors.selectedContentColor else currentColors.unselectedContentColor)
|
val animatedContentColor by animateColorAsState(if (selected) currentColors.selectedContentColor else currentColors.unselectedContentColor)
|
||||||
val currentIconStyle = LocalIconStyle.current.copy(tint = animatedContentColor)
|
val currentIconStyle = LocalIconStyle.current.copy(tint = animatedContentColor)
|
||||||
@@ -196,48 +196,48 @@ fun NavigationItem(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun NavigationStyleBox(
|
private fun NavigationBarStyleBox(
|
||||||
modifier: Modifier,
|
modifier: Modifier,
|
||||||
horizontal: Boolean,
|
horizontal: Boolean,
|
||||||
colors: NavigationColors,
|
colors: NavigationBarColors,
|
||||||
style: NavigationStyle,
|
style: NavigationBarStyle,
|
||||||
content: @Composable () -> Unit
|
content: @Composable () -> Unit
|
||||||
) {
|
) {
|
||||||
Box(modifier = modifier) {
|
Box(modifier = modifier) {
|
||||||
CompositionLocalProvider(
|
CompositionLocalProvider(
|
||||||
LocalHorizontalNavigation provides horizontal,
|
LocalHorizontalNavigationBar provides horizontal,
|
||||||
LocalNavigationColors provides colors,
|
LocalNavigationBarColors provides colors,
|
||||||
LocalNavigationContentPadding provides style.contentPadding,
|
LocalNavigationBarContentPadding provides style.contentPadding,
|
||||||
LocalNavigationContentShape provides style.contentShape,
|
LocalNavigationBarContentShape provides style.contentShape,
|
||||||
content = content
|
content = content
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object Navigation {
|
object NavigationBar {
|
||||||
val colors: NavigationColors
|
val colors: NavigationBarColors
|
||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
get() = defaultNavigationColors()
|
get() = defaultNavigationBarColors()
|
||||||
val style: NavigationStyle
|
val style: NavigationBarStyle
|
||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
get() = defaultNavigationStyle()
|
get() = defaultNavigationBarStyle()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val LocalHorizontalNavigation = compositionLocalOf { true }
|
private val LocalHorizontalNavigationBar = compositionLocalOf { true }
|
||||||
|
|
||||||
private val LocalNavigationColors = compositionLocalOf<NavigationColors?> { null }
|
private val LocalNavigationBarColors = compositionLocalOf<NavigationBarColors?> { null }
|
||||||
|
|
||||||
private val LocalNavigationContentSpacing = compositionLocalOf { Dp.Unspecified }
|
private val LocalNavigationBarContentSpacing = compositionLocalOf { Dp.Unspecified }
|
||||||
|
|
||||||
private val LocalNavigationContentPadding = compositionLocalOf<PaddingValues?> { null }
|
private val LocalNavigationBarContentPadding = compositionLocalOf<PaddingValues?> { null }
|
||||||
|
|
||||||
private val LocalNavigationContentShape = compositionLocalOf<Shape?> { null }
|
private val LocalNavigationBarContentShape = compositionLocalOf<Shape?> { null }
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
private fun defaultNavigationColors() = NavigationColors(
|
private fun defaultNavigationBarColors() = NavigationBarColors(
|
||||||
backgroundColor = AreaBox.color,
|
backgroundColor = AreaBox.color,
|
||||||
indicatorColor = LocalColors.current.themeTertiary,
|
indicatorColor = LocalColors.current.themeTertiary,
|
||||||
selectedContentColor = LocalColors.current.themePrimary,
|
selectedContentColor = LocalColors.current.themePrimary,
|
||||||
@@ -246,7 +246,7 @@ private fun defaultNavigationColors() = NavigationColors(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ReadOnlyComposable
|
@ReadOnlyComposable
|
||||||
private fun defaultNavigationStyle() = NavigationStyle(
|
private fun defaultNavigationBarStyle() = NavigationBarStyle(
|
||||||
boxStyle = AreaBox.style,
|
boxStyle = AreaBox.style,
|
||||||
contentSpacing = LocalSizes.current.spacingSecondary,
|
contentSpacing = LocalSizes.current.spacingSecondary,
|
||||||
contentPadding = ComponentPadding(
|
contentPadding = ComponentPadding(
|
Reference in New Issue
Block a user