fix: some compose performance improvements and code clearing

This commit is contained in:
FunkyMuse 2023-08-28 14:14:45 +02:00
parent a93899eea2
commit fb76fe5513
12 changed files with 172 additions and 134 deletions

View file

@ -26,8 +26,7 @@ class FAQActivity : ComponentActivity() {
val faqItems = remember { intent.getSerializableExtra(APP_FAQ) as ArrayList<FAQItem> }
FAQScreen(
goBack = ::finish,
faqItems = faqItems.toImmutableList(),
canScroll = { canPerformScroll -> canScroll = canPerformScroll }
faqItems = faqItems.toImmutableList()
)
}
}

View file

@ -30,8 +30,7 @@ class LicenseActivity : ComponentActivity() {
LicenseScreen(
goBack = ::finish,
thirdPartyLicenses = thirdPartyLicenses,
onLicenseClick = ::launchViewIntent,
canScroll = { canPerformScroll -> canScroll = canPerformScroll }
onLicenseClick = ::launchViewIntent
)
}
}

View file

@ -7,12 +7,19 @@ import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat
import androidx.lifecycle.Lifecycle
@ -68,3 +75,57 @@ fun <T : Any> onEventValue(event: Lifecycle.Event = Lifecycle.Event.ON_START, va
}
return rememberedValue
}
@Composable
operator fun PaddingValues.plus(otherPaddingValues: PaddingValues): PaddingValues {
val layoutDirection = LocalLayoutDirection.current
return PaddingValues(
start = calculateLeftPadding(layoutDirection).plus(
otherPaddingValues.calculateLeftPadding(
layoutDirection
)
),
top = calculateTopPadding().plus(otherPaddingValues.calculateTopPadding()),
end = calculateRightPadding(layoutDirection).plus(
otherPaddingValues.calculateRightPadding(
layoutDirection
)
),
bottom = calculateBottomPadding().plus(otherPaddingValues.calculateBottomPadding())
)
}
@Composable
fun PaddingValues.plus(vararg otherPaddingValues: PaddingValues): PaddingValues {
val thisArray = arrayOf(this)
return PaddingValues(
start = thisArray.plus(otherPaddingValues).sumOfDps(PaddingValues::calculateStartPadding),
top = thisArray.plus(otherPaddingValues).sumOfDps(PaddingValues::calculateTopPadding),
end = thisArray.plus(otherPaddingValues).sumOfDps(PaddingValues::calculateEndPadding),
bottom = thisArray.plus(otherPaddingValues).sumOfDps(PaddingValues::calculateBottomPadding)
)
}
@Composable
private fun Array<out PaddingValues>.sumOfDps(aggregator: (PaddingValues, LayoutDirection) -> Dp): Dp {
val layoutDirection = LocalLayoutDirection.current
return asSequence().map { paddingValues ->
aggregator(paddingValues, layoutDirection)
}.sumOfDps()
}
private fun Array<out PaddingValues>.sumOfDps(aggregator: PaddingValues.() -> Dp): Dp =
asSequence().map { paddingValues ->
paddingValues.aggregator()
}.sumOfDps()
private fun Sequence<Dp>.sumOfDps(): Dp {
var sum = 0.dp
for (element in this) {
sum += element
}
return sum
}

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.commons.compose.screens
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
@ -26,13 +25,12 @@ internal fun AboutScreen(
socialSection: @Composable () -> Unit,
otherSection: @Composable () -> Unit,
) {
SettingsScaffold(title = stringResource(id = R.string.about), goBack = goBack) { paddingValues ->
SettingsScaffold(title = stringResource(id = R.string.about), goBack = goBack) {
aboutSection()
helpUsSection()
socialSection()
otherSection()
SettingsListItem(text = stringResource(id = R.string.about_footer))
Spacer(modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()))
}
}

View file

@ -46,7 +46,7 @@ internal fun ContributorsScreen(
)
},
goBack = goBack
) { paddingValues ->
) {
item {
SettingsGroupTitle {
SettingsTitleTextComponent(text = stringResource(id = R.string.development), modifier = startingPadding)
@ -93,9 +93,7 @@ internal fun ContributorsScreen(
Spacer(modifier = Modifier.padding(bottom = 8.dp))
}
}
item {
Spacer(modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()))
}
}
}

View file

@ -35,13 +35,12 @@ import kotlinx.collections.immutable.toImmutableList
internal fun FAQScreen(
goBack: () -> Unit,
faqItems: ImmutableList<FAQItem>,
canScroll: (canPerformScroll: Boolean) -> Unit,
) {
SettingsLazyScaffold(
title = stringResource(id = R.string.frequently_asked_questions),
goBack = goBack,
contentPadding = PaddingValues(bottom = 8.dp)
) { paddingValues ->
) {
itemsIndexed(faqItems) { index, faqItem ->
Column(modifier = Modifier.fillMaxWidth()) {
ListItem(
@ -83,9 +82,6 @@ internal fun FAQScreen(
}
}
}
item {
Spacer(modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()))
}
}
}
@ -128,8 +124,7 @@ private fun FAQScreenPreview() {
FAQItem(R.string.faq_4_title_commons, R.string.faq_4_text_commons),
FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons),
FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons)
).toImmutableList(),
canScroll = {}
).toImmutableList()
)
}
}

View file

@ -2,7 +2,6 @@ package com.simplemobiletools.commons.compose.screens
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material3.ListItem
@ -28,12 +27,11 @@ internal fun LicenseScreen(
goBack: () -> Unit,
thirdPartyLicenses: ImmutableList<License>,
onLicenseClick: (urlId: Int) -> Unit,
canScroll: (canPerformScroll: Boolean) -> Unit,
) {
SettingsLazyScaffold(
title = stringResource(id = R.string.third_party_licences),
goBack = goBack
) { paddingValues ->
) {
itemsIndexed(thirdPartyLicenses) { index, license ->
Column {
LicenseItem(license, onLicenseClick)
@ -42,9 +40,6 @@ internal fun LicenseScreen(
}
}
}
item {
Spacer(modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()))
}
}
}
@ -115,12 +110,10 @@ private fun LicenseScreenPreview() {
License(LICENSE_ANDROID_LAME, R.string.android_lame_title, R.string.android_lame_text, R.string.android_lame_url),
License(LICENSE_PDF_VIEWER, R.string.pdf_viewer_title, R.string.pdf_viewer_text, R.string.pdf_viewer_url),
License(LICENSE_ZIP4J, R.string.zip4j_title, R.string.zip4j_text, R.string.zip4j_url)
).toImmutableList(),
onLicenseClick = {
).toImmutableList()
) {
},
canScroll = {}
)
}
}
}

View file

@ -23,7 +23,6 @@ import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.onLongClick
@ -46,10 +45,7 @@ import com.simplemobiletools.commons.compose.menus.ActionMenu
import com.simplemobiletools.commons.compose.menus.OverflowMode
import com.simplemobiletools.commons.compose.settings.SettingsCheckBoxComponent
import com.simplemobiletools.commons.compose.settings.SettingsHorizontalDivider
import com.simplemobiletools.commons.compose.settings.scaffold.SettingsLazyScaffold
import com.simplemobiletools.commons.compose.settings.scaffold.SettingsNavigationIcon
import com.simplemobiletools.commons.compose.settings.scaffold.SettingsScaffoldTopBar
import com.simplemobiletools.commons.compose.settings.scaffold.canPerformVerticalScrollLazyListState
import com.simplemobiletools.commons.compose.settings.scaffold.*
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
import com.simplemobiletools.commons.compose.theme.ripple_dark
import com.simplemobiletools.commons.compose.theme.ripple_light
@ -120,8 +116,8 @@ internal fun ManageBlockedNumbersScreen(
)
}
},
) { paddingValues ->
val state = canPerformVerticalScrollLazyListState()
) {
val state = rememberCanPerformVerticalScrollLazyListState()
val autoScrollSpeed = remember { mutableFloatStateOf(0f) }
LaunchedEffect(autoScrollSpeed.floatValue) {
if (autoScrollSpeed.floatValue != 0f) {
@ -171,7 +167,7 @@ internal fun ManageBlockedNumbersScreen(
}
hasGivenPermissionToBlock && blockedNumbers.isNotEmpty() -> {
items(blockedNumbers, key = { it.id }) { blockedNumber ->
items(blockedNumbers, key = { blockedNumber -> blockedNumber.id }) { blockedNumber ->
val isSelected = selectedIds.value.contains(blockedNumber.id)
BlockedNumber(
modifier = Modifier
@ -189,8 +185,8 @@ internal fun ManageBlockedNumbersScreen(
value = isSelected,
interactionSource = remember { MutableInteractionSource() },
indication = null,
onValueChange = {
if (it) {
onValueChange = { selected ->
if (selected) {
selectedIds.value += blockedNumber.id
} else {
selectedIds.value -= blockedNumber.id
@ -209,9 +205,6 @@ internal fun ManageBlockedNumbersScreen(
isSelected = isSelected
)
}
item {
Spacer(modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()))
}
}
}
}
@ -308,24 +301,15 @@ private fun BlockedNumberTrailingContent(modifier: Modifier = Modifier, onDelete
@Composable
private fun ActionModeToolbar(
modifier: Modifier = Modifier,
selectedIdsCount: Int,
blockedNumbersCount: Int,
onBackClick: () -> Unit,
onCopy: () -> Unit,
onDelete: () -> Unit
) {
val layoutDirection = LocalLayoutDirection.current
val paddingValues = WindowInsets.navigationBars.asPaddingValues()
val context = LocalContext.current
val navigationIconInteractionSource = remember { MutableInteractionSource() }
val baseConfig = remember {
context.baseConfig
}
val bgColor = if (baseConfig.isUsingSystemTheme) {
colorResource(R.color.you_contextual_status_bar_color)
} else {
Color.Black
}
val bgColor = actionModeBgColor()
val textColor by remember {
derivedStateOf { Color(bgColor.toArgb().getContrastColor()) }
}
@ -342,15 +326,24 @@ private fun ActionModeToolbar(
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.primary
),
modifier = Modifier.padding(
top = paddingValues.calculateTopPadding(),
start = paddingValues.calculateStartPadding(layoutDirection),
end = paddingValues.calculateEndPadding(layoutDirection)
),
windowInsets = TopAppBarDefaults.windowInsets.exclude(WindowInsets.navigationBars)
modifier = modifier.topAppBarPaddings(),
windowInsets = topAppBarInsets()
)
}
@Composable
private fun actionModeBgColor(): Color {
val context = LocalContext.current
val baseConfig = remember {
context.baseConfig
}
return if (baseConfig.isUsingSystemTheme) {
colorResource(R.color.you_contextual_status_bar_color)
} else {
Color.Black
}
}
@Composable
private fun ActionMenu(
selectedIdsCount: Int,

View file

@ -20,6 +20,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import com.simplemobiletools.commons.compose.extensions.AdjustNavigationBarColors
import com.simplemobiletools.commons.compose.extensions.MyDevices
import com.simplemobiletools.commons.compose.extensions.plus
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
@Composable
@ -34,7 +35,7 @@ fun SettingsLazyScaffold(
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
userScrollEnabled: Boolean = true,
state: LazyListState = canPerformVerticalScrollLazyListState(),
state: LazyListState = rememberCanPerformVerticalScrollLazyListState(),
lazyContent: LazyListScope.(PaddingValues) -> Unit
) {
val context = LocalContext.current
@ -67,7 +68,7 @@ fun SettingsLazyScaffold(
modifier = Modifier
.matchParentSize(),
state = state,
contentPadding = contentPadding,
contentPadding = contentPadding.plus(PaddingValues(bottom = paddingValues.calculateBottomPadding())),
reverseLayout = reverseLayout,
verticalArrangement = verticalArrangement,
horizontalAlignment = horizontalAlignment,
@ -93,7 +94,7 @@ fun SettingsLazyScaffold(
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
userScrollEnabled: Boolean = true,
state: LazyListState = canPerformVerticalScrollLazyListState(),
state: LazyListState = rememberCanPerformVerticalScrollLazyListState(),
lazyContent: LazyListScope.(PaddingValues) -> Unit
) {
val context = LocalContext.current
@ -126,12 +127,12 @@ fun SettingsLazyScaffold(
modifier = Modifier
.matchParentSize(),
state = state,
contentPadding = contentPadding,
contentPadding = contentPadding.plus(PaddingValues(bottom = paddingValues.calculateBottomPadding())),
reverseLayout = reverseLayout,
verticalArrangement = verticalArrangement,
horizontalAlignment = horizontalAlignment,
flingBehavior = flingBehavior,
userScrollEnabled = userScrollEnabled
userScrollEnabled = userScrollEnabled,
) {
lazyContent(paddingValues)
}
@ -152,7 +153,7 @@ fun SettingsLazyScaffold(
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
userScrollEnabled: Boolean = true,
state: LazyListState = canPerformVerticalScrollLazyListState(),
state: LazyListState = rememberCanPerformVerticalScrollLazyListState(),
lazyContent: LazyListScope.(PaddingValues) -> Unit
) {
val context = LocalContext.current
@ -186,7 +187,7 @@ fun SettingsLazyScaffold(
modifier = Modifier
.matchParentSize(),
state = state,
contentPadding = contentPadding,
contentPadding = contentPadding.plus(PaddingValues(bottom = paddingValues.calculateBottomPadding())),
reverseLayout = reverseLayout,
verticalArrangement = verticalArrangement,
horizontalAlignment = horizontalAlignment,
@ -210,7 +211,7 @@ fun SettingsLazyScaffold(
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
userScrollEnabled: Boolean = true,
state: LazyListState = canPerformVerticalScrollLazyListState(),
state: LazyListState = rememberCanPerformVerticalScrollLazyListState(),
lazyContent: LazyListScope.(PaddingValues) -> Unit
) {
val context = LocalContext.current
@ -234,7 +235,7 @@ fun SettingsLazyScaffold(
modifier = Modifier
.matchParentSize(),
state = state,
contentPadding = contentPadding,
contentPadding = contentPadding.plus(PaddingValues(bottom = paddingValues.calculateBottomPadding())),
reverseLayout = reverseLayout,
verticalArrangement = verticalArrangement,
horizontalAlignment = horizontalAlignment,
@ -276,7 +277,7 @@ fun SettingsLazyScaffold(
}
@Composable
internal fun canPerformVerticalScrollLazyListState(): LazyListState {
internal fun rememberCanPerformVerticalScrollLazyListState(): LazyListState {
val scrollState = rememberLazyListState()
var canScroll by remember { mutableStateOf<Boolean?>(null) }
AdjustNavigationBarColors(canScroll)

View file

@ -63,6 +63,7 @@ fun SettingsScaffold(
verticalArrangement = verticalArrangement
) {
content(paddingValues)
Spacer(modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()))
}
}
}
@ -114,6 +115,7 @@ fun SettingsScaffold(
horizontalAlignment = horizontalAlignment,
) {
content(paddingValues)
Spacer(modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()))
}
}
}
@ -167,6 +169,7 @@ fun SettingsScaffold(
horizontalAlignment = horizontalAlignment,
) {
content(paddingValues)
Spacer(modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()))
}
}
}

View file

@ -5,10 +5,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.lerp
@ -23,7 +20,10 @@ import com.simplemobiletools.commons.extensions.getContrastColor
@Composable
internal fun SystemUISettingsScaffoldStatusBarColor(scrolledColor: Color) {
val insetController = rememberWindowInsetsController()
insetController.isAppearanceLightStatusBars = scrolledColor.isNotLitWell()
DisposableEffect(rememberWindowInsetsController()) {
insetController.isAppearanceLightStatusBars = scrolledColor.isNotLitWell()
onDispose { }
}
}
@Composable

View file

@ -23,6 +23,7 @@ import com.simplemobiletools.commons.compose.theme.AppThemeSurface
@Composable
internal fun SettingsScaffoldTopBar(
modifier: Modifier = Modifier,
title: String,
scrolledColor: Color,
navigationIconInteractionSource: MutableInteractionSource,
@ -32,8 +33,6 @@ internal fun SettingsScaffoldTopBar(
contrastColor: Color,
goBack: () -> Unit,
) {
val layoutDirection = LocalLayoutDirection.current
val paddingValues = WindowInsets.navigationBars.asPaddingValues()
TopAppBar(
title = {
Text(
@ -44,26 +43,17 @@ internal fun SettingsScaffoldTopBar(
color = scrolledColor
)
},
navigationIcon = {
SettingsNavigationIcon(goBack = goBack, navigationIconInteractionSource = navigationIconInteractionSource, iconColor = scrolledColor)
},
navigationIcon = { SettingsNavigationIcon(goBack = goBack, navigationIconInteractionSource = navigationIconInteractionSource, iconColor = scrolledColor) },
scrollBehavior = scrollBehavior,
colors = TopAppBarDefaults.largeTopAppBarColors(
scrolledContainerColor = Color(statusBarColor),
containerColor = if (colorTransitionFraction == 1f) contrastColor else MaterialTheme.colorScheme.surface,
navigationIconContentColor = if (colorTransitionFraction == 1f) contrastColor else MaterialTheme.colorScheme.surface
),
modifier = Modifier.padding(
top = paddingValues.calculateTopPadding(),
start = paddingValues.calculateStartPadding(layoutDirection),
end = paddingValues.calculateEndPadding(layoutDirection)
),
windowInsets = TopAppBarDefaults.windowInsets.exclude(WindowInsets.navigationBars)
colors = topAppBarColors(statusBarColor, colorTransitionFraction, contrastColor),
modifier = modifier.topAppBarPaddings(),
windowInsets = topAppBarInsets()
)
}
@Composable
internal fun SettingsScaffoldTopBar(
modifier: Modifier = Modifier,
title: @Composable (scrolledColor: Color) -> Unit,
scrolledColor: Color,
navigationIconInteractionSource: MutableInteractionSource,
@ -73,32 +63,21 @@ internal fun SettingsScaffoldTopBar(
contrastColor: Color,
goBack: () -> Unit,
) {
val layoutDirection = LocalLayoutDirection.current
val paddingValues = WindowInsets.navigationBars.asPaddingValues()
TopAppBar(
title = {
title(scrolledColor)
},
navigationIcon = {
SettingsNavigationIcon(goBack = goBack, navigationIconInteractionSource = navigationIconInteractionSource, iconColor = scrolledColor)
},
navigationIcon = { SettingsNavigationIcon(goBack = goBack, navigationIconInteractionSource = navigationIconInteractionSource, iconColor = scrolledColor) },
scrollBehavior = scrollBehavior,
colors = TopAppBarDefaults.largeTopAppBarColors(
scrolledContainerColor = Color(statusBarColor),
containerColor = if (colorTransitionFraction == 1f) contrastColor else MaterialTheme.colorScheme.surface,
navigationIconContentColor = if (colorTransitionFraction == 1f) contrastColor else MaterialTheme.colorScheme.surface
),
modifier = Modifier.padding(
top = paddingValues.calculateTopPadding(),
start = paddingValues.calculateStartPadding(layoutDirection),
end = paddingValues.calculateEndPadding(layoutDirection)
),
windowInsets = TopAppBarDefaults.windowInsets.exclude(WindowInsets.navigationBars)
colors = topAppBarColors(statusBarColor, colorTransitionFraction, contrastColor),
modifier = modifier.topAppBarPaddings(),
windowInsets = topAppBarInsets()
)
}
@Composable
internal fun SettingsScaffoldTopBar(
modifier: Modifier = Modifier,
title: @Composable (scrolledColor: Color) -> Unit,
actions: @Composable RowScope.() -> Unit,
scrolledColor: Color,
@ -109,28 +88,42 @@ internal fun SettingsScaffoldTopBar(
contrastColor: Color,
goBack: () -> Unit,
) {
val layoutDirection = LocalLayoutDirection.current
val paddingValues = WindowInsets.navigationBars.asPaddingValues()
TopAppBar(
title = {
title(scrolledColor)
},
navigationIcon = {
SettingsNavigationIcon(goBack = goBack, navigationIconInteractionSource = navigationIconInteractionSource, iconColor = scrolledColor)
},
navigationIcon = { SettingsNavigationIcon(goBack = goBack, navigationIconInteractionSource = navigationIconInteractionSource, iconColor = scrolledColor) },
actions = actions,
scrollBehavior = scrollBehavior,
colors = TopAppBarDefaults.largeTopAppBarColors(
scrolledContainerColor = Color(statusBarColor),
containerColor = if (colorTransitionFraction == 1f) contrastColor else MaterialTheme.colorScheme.surface,
navigationIconContentColor = if (colorTransitionFraction == 1f) contrastColor else MaterialTheme.colorScheme.surface
),
modifier = Modifier.padding(
top = paddingValues.calculateTopPadding(),
start = paddingValues.calculateStartPadding(layoutDirection),
end = paddingValues.calculateEndPadding(layoutDirection)
),
windowInsets = TopAppBarDefaults.windowInsets.exclude(WindowInsets.navigationBars)
colors = topAppBarColors(statusBarColor, colorTransitionFraction, contrastColor),
modifier = modifier.topAppBarPaddings(),
windowInsets = topAppBarInsets()
)
}
@Composable
private fun topAppBarColors(
statusBarColor: Int,
colorTransitionFraction: Float,
contrastColor: Color
) = TopAppBarDefaults.topAppBarColors(
scrolledContainerColor = Color(statusBarColor),
containerColor = if (colorTransitionFraction == 1f) contrastColor else MaterialTheme.colorScheme.surface,
navigationIconContentColor = if (colorTransitionFraction == 1f) contrastColor else MaterialTheme.colorScheme.surface
)
@Composable
internal fun topAppBarInsets() = TopAppBarDefaults.windowInsets.exclude(WindowInsets.navigationBars)
@Composable
internal fun Modifier.topAppBarPaddings(
paddingValues: PaddingValues = WindowInsets.navigationBars.asPaddingValues()
): Modifier {
val layoutDirection = LocalLayoutDirection.current
return padding(
top = paddingValues.calculateTopPadding(),
start = paddingValues.calculateStartPadding(layoutDirection),
end = paddingValues.calculateEndPadding(layoutDirection)
)
}
@ -152,18 +145,23 @@ internal fun SettingsNavigationIcon(
)
) { goBack() }
) {
if (iconColor == null) {
Icon(
imageVector = Icons.Filled.ArrowBack, contentDescription = stringResource(id = R.string.back),
modifier = Modifier.padding(4.dp)
)
} else {
Icon(
imageVector = Icons.Filled.ArrowBack, contentDescription = stringResource(id = R.string.back),
tint = iconColor,
modifier = Modifier.padding(4.dp)
)
}
BackIcon(iconColor)
}
}
@Composable
private fun BackIcon(iconColor: Color?) {
if (iconColor == null) {
Icon(
imageVector = Icons.Filled.ArrowBack, contentDescription = stringResource(id = R.string.back),
modifier = Modifier.padding(4.dp)
)
} else {
Icon(
imageVector = Icons.Filled.ArrowBack, contentDescription = stringResource(id = R.string.back),
tint = iconColor,
modifier = Modifier.padding(4.dp)
)
}
}