fix: navigation bar scrollables and paddings
This commit is contained in:
parent
d393051b1d
commit
85a42b23c6
11 changed files with 101 additions and 36 deletions
|
@ -19,9 +19,7 @@ import androidx.core.view.WindowCompat
|
|||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.compose.extensions.AdjustNavigationBarColors
|
||||
import com.simplemobiletools.commons.compose.extensions.TransparentSystemBars
|
||||
import com.simplemobiletools.commons.compose.screens.AboutScreen
|
||||
import com.simplemobiletools.commons.compose.screens.AboutSection
|
||||
import com.simplemobiletools.commons.compose.screens.HelpUsSection
|
||||
import com.simplemobiletools.commons.compose.screens.*
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
|
||||
import com.simplemobiletools.commons.dialogs.RateStarsDialog
|
||||
|
@ -74,17 +72,17 @@ class AboutActivity : ComponentActivity() {
|
|||
}
|
||||
},
|
||||
socialSection = {
|
||||
/*if (showExternalLinks) {
|
||||
if (showExternalLinks) {
|
||||
SocialSection(
|
||||
onFacebookClick = ::onFacebookClick,
|
||||
onGithubClick = ::onGithubClick,
|
||||
onRedditClick = ::onRedditClick,
|
||||
onTelegramClick = ::onTelegramClick
|
||||
)
|
||||
}*/
|
||||
}
|
||||
},
|
||||
otherSection = {
|
||||
/* val showWebsite = remember { resources.getBoolean(R.bool.show_donate_in_about) && !showExternalLinks }
|
||||
val showWebsite = remember { resources.getBoolean(R.bool.show_donate_in_about) && !showExternalLinks }
|
||||
var version = intent.getStringExtra(APP_VERSION_NAME) ?: ""
|
||||
if (baseConfig.appId.removeSuffix(".debug").endsWith(".pro")) {
|
||||
version += " ${getString(R.string.pro)}"
|
||||
|
@ -101,7 +99,7 @@ class AboutActivity : ComponentActivity() {
|
|||
onLicenseClick = ::onLicenseClick,
|
||||
version = fullVersion,
|
||||
onVersionClick = ::onVersionClick
|
||||
)*/
|
||||
)
|
||||
},
|
||||
canScroll = { isContentScrollable ->
|
||||
canScroll = isContentScrollable
|
||||
|
|
|
@ -3,9 +3,13 @@ package com.simplemobiletools.commons.activities
|
|||
import android.os.Bundle
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.core.view.WindowCompat
|
||||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.compose.extensions.AdjustNavigationBarColors
|
||||
import com.simplemobiletools.commons.compose.extensions.TransparentSystemBars
|
||||
import com.simplemobiletools.commons.compose.screens.ContributorsScreen
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
|
@ -19,6 +23,8 @@ class ContributorsActivity : AppCompatActivity() {
|
|||
setContent {
|
||||
TransparentSystemBars()
|
||||
AppThemeSurface {
|
||||
var canScroll by remember { mutableStateOf<Boolean?>(null) }
|
||||
AdjustNavigationBarColors(canScroll)
|
||||
val contributors = remember {
|
||||
languageContributors()
|
||||
}
|
||||
|
@ -28,7 +34,8 @@ class ContributorsActivity : AppCompatActivity() {
|
|||
ContributorsScreen(
|
||||
goBack = ::finish,
|
||||
showContributorsLabel = showContributorsLabel,
|
||||
contributors = contributors
|
||||
contributors = contributors,
|
||||
canScroll = { canPerformScroll -> canScroll = canPerformScroll }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,12 @@ package com.simplemobiletools.commons.activities
|
|||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.core.view.WindowCompat
|
||||
import com.simplemobiletools.commons.compose.extensions.AdjustNavigationBarColors
|
||||
import com.simplemobiletools.commons.compose.extensions.TransparentSystemBars
|
||||
import com.simplemobiletools.commons.compose.screens.FAQScreen
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
|
@ -19,8 +23,14 @@ class FAQActivity : ComponentActivity() {
|
|||
setContent {
|
||||
TransparentSystemBars()
|
||||
AppThemeSurface {
|
||||
var canScroll by remember { mutableStateOf<Boolean?>(null) }
|
||||
AdjustNavigationBarColors(canScroll)
|
||||
val faqItems = remember { intent.getSerializableExtra(APP_FAQ) as ArrayList<FAQItem> }
|
||||
FAQScreen(goBack = ::finish, faqItems = faqItems.toImmutableList())
|
||||
FAQScreen(
|
||||
goBack = ::finish,
|
||||
faqItems = faqItems.toImmutableList(),
|
||||
canScroll = { canPerformScroll -> canScroll = canPerformScroll }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,13 @@ package com.simplemobiletools.commons.activities
|
|||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.core.view.WindowCompat
|
||||
import com.simplemobiletools.commons.R
|
||||
import com.simplemobiletools.commons.compose.extensions.AdjustNavigationBarColors
|
||||
import com.simplemobiletools.commons.compose.extensions.TransparentSystemBars
|
||||
import com.simplemobiletools.commons.compose.screens.LicenseScreen
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
|
@ -23,7 +27,14 @@ class LicenseActivity : ComponentActivity() {
|
|||
val thirdPartyLicenses = remember { initLicenses().filter { licenseMask and it.id != 0L }.toImmutableList() }
|
||||
TransparentSystemBars()
|
||||
AppThemeSurface {
|
||||
LicenseScreen(goBack = ::finish, thirdPartyLicenses = thirdPartyLicenses, onLicenseClick = ::launchViewIntent)
|
||||
var canScroll by remember { mutableStateOf<Boolean?>(null) }
|
||||
AdjustNavigationBarColors(canScroll)
|
||||
LicenseScreen(
|
||||
goBack = ::finish,
|
||||
thirdPartyLicenses = thirdPartyLicenses,
|
||||
onLicenseClick = ::launchViewIntent,
|
||||
canScroll = { canPerformScroll -> canScroll = canPerformScroll }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ fun AdjustNavigationBarColors(canScroll: Boolean?) {
|
|||
val isSystemInDarkTheme = isSystemInDarkTheme()
|
||||
val isSurfaceLitWell = MaterialTheme.colorScheme.surface.isLitWell()
|
||||
val navigationBarColor = when (canScroll) {
|
||||
true -> Color(MaterialTheme.colorScheme.surface.toArgb().darkenColor(factor = 1)).copy(alpha = 0.5f)
|
||||
true -> Color(MaterialTheme.colorScheme.surface.toArgb().darkenColor()).copy(alpha = 0.5f)
|
||||
else -> Color.Transparent
|
||||
}
|
||||
DisposableEffect(systemUiController, !isSystemInDarkTheme, navigationBarColor) {
|
||||
|
|
|
@ -16,7 +16,7 @@ import com.simplemobiletools.commons.compose.settings.SettingsTitleTextComponent
|
|||
import com.simplemobiletools.commons.compose.settings.scaffold.SettingsScaffold
|
||||
import com.simplemobiletools.commons.compose.theme.AppThemeSurface
|
||||
|
||||
private val startingTitlePadding = Modifier.padding(start = 64.dp)
|
||||
private val startingTitlePadding = Modifier.padding(start = 58.dp)
|
||||
|
||||
@Composable
|
||||
internal fun AboutScreen(
|
||||
|
|
|
@ -27,15 +27,17 @@ import com.simplemobiletools.commons.models.LanguageContributor
|
|||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
private val startingPadding = Modifier.padding(start = 62.dp)
|
||||
private val startingPadding = Modifier.padding(start = 58.dp)
|
||||
|
||||
@Composable
|
||||
internal fun ContributorsScreen(
|
||||
goBack: () -> Unit,
|
||||
showContributorsLabel: Boolean,
|
||||
contributors: ImmutableList<LanguageContributor>
|
||||
contributors: ImmutableList<LanguageContributor>,
|
||||
canScroll: (canPerformScroll: Boolean) -> Unit,
|
||||
) {
|
||||
SettingsLazyScaffold(
|
||||
canScroll = canScroll,
|
||||
title = { scrolledColor ->
|
||||
Text(
|
||||
text = stringResource(id = R.string.contributors),
|
||||
|
@ -148,7 +150,8 @@ private fun ContributorsScreenPreview() {
|
|||
LanguageContributor(R.drawable.ic_flag_bengali_vector, R.string.translation_bengali, R.string.translators_bengali),
|
||||
LanguageContributor(R.drawable.ic_flag_catalan_vector, R.string.translation_catalan, R.string.translators_catalan),
|
||||
).toImmutableList(),
|
||||
showContributorsLabel = true
|
||||
showContributorsLabel = true,
|
||||
canScroll = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,12 +34,14 @@ import kotlinx.collections.immutable.toImmutableList
|
|||
@Composable
|
||||
internal fun FAQScreen(
|
||||
goBack: () -> Unit,
|
||||
faqItems: ImmutableList<FAQItem>
|
||||
faqItems: ImmutableList<FAQItem>,
|
||||
canScroll: (canPerformScroll: Boolean) -> Unit,
|
||||
) {
|
||||
SettingsLazyScaffold(
|
||||
title = stringResource(id = R.string.frequently_asked_questions),
|
||||
goBack = goBack,
|
||||
contentPadding = PaddingValues(bottom = 8.dp),
|
||||
canScroll = canScroll
|
||||
) { paddingValues ->
|
||||
itemsIndexed(faqItems) { index, faqItem ->
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
|
@ -74,9 +76,11 @@ internal fun FAQScreen(
|
|||
)
|
||||
Spacer(modifier = Modifier.padding(bottom = 8.dp))
|
||||
if (index != faqItems.lastIndex) {
|
||||
SettingsHorizontalDivider(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 4.dp))
|
||||
SettingsHorizontalDivider(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 4.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +129,8 @@ 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()
|
||||
).toImmutableList(),
|
||||
canScroll = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,9 +27,14 @@ import kotlinx.collections.immutable.toImmutableList
|
|||
internal fun LicenseScreen(
|
||||
goBack: () -> Unit,
|
||||
thirdPartyLicenses: ImmutableList<License>,
|
||||
onLicenseClick: (urlId: Int) -> Unit
|
||||
onLicenseClick: (urlId: Int) -> Unit,
|
||||
canScroll: (canPerformScroll: Boolean) -> Unit,
|
||||
) {
|
||||
SettingsLazyScaffold(title = stringResource(id = R.string.third_party_licences), goBack = goBack) { paddingValues ->
|
||||
SettingsLazyScaffold(
|
||||
title = stringResource(id = R.string.third_party_licences),
|
||||
goBack = goBack,
|
||||
canScroll = canScroll
|
||||
) { paddingValues ->
|
||||
itemsIndexed(thirdPartyLicenses) { index, license ->
|
||||
Column {
|
||||
LicenseItem(license, onLicenseClick)
|
||||
|
@ -114,7 +119,8 @@ private fun LicenseScreenPreview() {
|
|||
).toImmutableList(),
|
||||
onLicenseClick = {
|
||||
|
||||
}
|
||||
},
|
||||
canScroll = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import androidx.compose.material.icons.Icons
|
|||
import androidx.compose.material.icons.filled.AccessTime
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
|
@ -30,7 +31,6 @@ fun SettingsLazyScaffold(
|
|||
title: String,
|
||||
goBack: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
state: LazyListState = rememberLazyListState(),
|
||||
contentPadding: PaddingValues = PaddingValues(0.dp),
|
||||
reverseLayout: Boolean = false,
|
||||
verticalArrangement: Arrangement.Vertical =
|
||||
|
@ -38,6 +38,8 @@ fun SettingsLazyScaffold(
|
|||
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
|
||||
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
|
||||
userScrollEnabled: Boolean = true,
|
||||
canScroll: ((canPerformScroll: Boolean) -> Unit)? = null,
|
||||
state: LazyListState = verticalScrollState(canScroll),
|
||||
lazyContent: LazyListScope.(PaddingValues) -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
@ -89,7 +91,6 @@ fun SettingsLazyScaffold(
|
|||
modifier: Modifier = Modifier,
|
||||
title: @Composable (scrolledColor: Color) -> Unit,
|
||||
goBack: () -> Unit,
|
||||
state: LazyListState = rememberLazyListState(),
|
||||
contentPadding: PaddingValues = PaddingValues(0.dp),
|
||||
reverseLayout: Boolean = false,
|
||||
verticalArrangement: Arrangement.Vertical =
|
||||
|
@ -97,6 +98,8 @@ fun SettingsLazyScaffold(
|
|||
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
|
||||
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
|
||||
userScrollEnabled: Boolean = true,
|
||||
canScroll: ((canPerformScroll: Boolean) -> Unit)? = null,
|
||||
state: LazyListState = verticalScrollState(canScroll),
|
||||
lazyContent: LazyListScope.(PaddingValues) -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
@ -148,7 +151,6 @@ fun SettingsLazyScaffold(
|
|||
title: @Composable (scrolledColor: Color) -> Unit,
|
||||
actions: @Composable RowScope.() -> Unit,
|
||||
goBack: () -> Unit,
|
||||
state: LazyListState = rememberLazyListState(),
|
||||
contentPadding: PaddingValues = PaddingValues(0.dp),
|
||||
reverseLayout: Boolean = false,
|
||||
verticalArrangement: Arrangement.Vertical =
|
||||
|
@ -156,6 +158,8 @@ fun SettingsLazyScaffold(
|
|||
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
|
||||
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
|
||||
userScrollEnabled: Boolean = true,
|
||||
canScroll: ((canPerformScroll: Boolean) -> Unit)? = null,
|
||||
state: LazyListState = verticalScrollState(canScroll),
|
||||
lazyContent: LazyListScope.(PaddingValues) -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
@ -213,7 +217,6 @@ fun SettingsLazyScaffold(
|
|||
colorTransitionFraction: Float,
|
||||
contrastColor: Color,
|
||||
) -> Unit,
|
||||
state: LazyListState = rememberLazyListState(),
|
||||
contentPadding: PaddingValues = PaddingValues(0.dp),
|
||||
reverseLayout: Boolean = false,
|
||||
verticalArrangement: Arrangement.Vertical =
|
||||
|
@ -221,6 +224,8 @@ fun SettingsLazyScaffold(
|
|||
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
|
||||
flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior(),
|
||||
userScrollEnabled: Boolean = true,
|
||||
canScroll: ((canPerformScroll: Boolean) -> Unit)? = null,
|
||||
state: LazyListState = verticalScrollState(canScroll),
|
||||
lazyContent: LazyListScope.(PaddingValues) -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
@ -257,6 +262,15 @@ fun SettingsLazyScaffold(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun verticalScrollState(canScroll: ((canPerformScroll: Boolean) -> Unit)?): LazyListState {
|
||||
val scrollState = rememberLazyListState()
|
||||
LaunchedEffect(Unit) {
|
||||
canScroll?.invoke(scrollState.canScrollForward || scrollState.canScrollBackward)
|
||||
}
|
||||
return scrollState
|
||||
}
|
||||
|
||||
@MyDevices
|
||||
@Composable
|
||||
private fun SettingsLazyScaffoldPreview() {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.commons.compose.settings.scaffold
|
||||
|
||||
import androidx.compose.foundation.ScrollState
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
|
@ -27,7 +28,8 @@ fun SettingsScaffold(
|
|||
verticalArrangement: Arrangement.Vertical =
|
||||
if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
|
||||
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
|
||||
canScroll: (canPerformScroll: Boolean) -> Unit = {},
|
||||
canScroll: ((canPerformScroll: Boolean) -> Unit)? = null,
|
||||
scrollState: ScrollState = verticalScrollState(canScroll),
|
||||
content: @Composable ColumnScope.(PaddingValues) -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
@ -55,10 +57,6 @@ fun SettingsScaffold(
|
|||
},
|
||||
) { paddingValues ->
|
||||
ScreenBoxSettingsScaffold(paddingValues) {
|
||||
val scrollState = rememberScrollState()
|
||||
LaunchedEffect(Unit) {
|
||||
canScroll(scrollState.canScrollForward || scrollState.canScrollBackward)
|
||||
}
|
||||
Column(
|
||||
Modifier
|
||||
.matchParentSize()
|
||||
|
@ -81,6 +79,8 @@ fun SettingsScaffold(
|
|||
verticalArrangement: Arrangement.Vertical =
|
||||
if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
|
||||
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
|
||||
canScroll: ((canPerformScroll: Boolean) -> Unit)? = null,
|
||||
scrollState: ScrollState = verticalScrollState(canScroll),
|
||||
content: @Composable ColumnScope.(PaddingValues) -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
@ -112,7 +112,7 @@ fun SettingsScaffold(
|
|||
Column(
|
||||
modifier = Modifier
|
||||
.matchParentSize()
|
||||
.verticalScroll(rememberScrollState()),
|
||||
.verticalScroll(scrollState),
|
||||
verticalArrangement = verticalArrangement,
|
||||
horizontalAlignment = horizontalAlignment,
|
||||
) {
|
||||
|
@ -132,6 +132,8 @@ fun SettingsScaffold(
|
|||
verticalArrangement: Arrangement.Vertical =
|
||||
if (!reverseLayout) Arrangement.Top else Arrangement.Bottom,
|
||||
horizontalAlignment: Alignment.Horizontal = Alignment.Start,
|
||||
canScroll: ((canPerformScroll: Boolean) -> Unit)? = null,
|
||||
scrollState: ScrollState = verticalScrollState(canScroll),
|
||||
content: @Composable ColumnScope.(PaddingValues) -> Unit
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
|
@ -164,7 +166,7 @@ fun SettingsScaffold(
|
|||
Column(
|
||||
modifier = Modifier
|
||||
.matchParentSize()
|
||||
.verticalScroll(rememberScrollState()),
|
||||
.verticalScroll(scrollState),
|
||||
verticalArrangement = verticalArrangement,
|
||||
horizontalAlignment = horizontalAlignment,
|
||||
) {
|
||||
|
@ -174,15 +176,24 @@ fun SettingsScaffold(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun verticalScrollState(canScroll: ((canPerformScroll: Boolean) -> Unit)?): ScrollState {
|
||||
val scrollState = rememberScrollState()
|
||||
LaunchedEffect(Unit) {
|
||||
canScroll?.invoke(scrollState.canScrollForward || scrollState.canScrollBackward)
|
||||
}
|
||||
return scrollState
|
||||
}
|
||||
|
||||
@MyDevices
|
||||
@Composable
|
||||
private fun SettingsScaffoldPreview() {
|
||||
AppThemeSurface {
|
||||
SettingsScaffold(title = "About", goBack = {}, content = {
|
||||
SettingsScaffold(title = "About", goBack = {}) {
|
||||
ListItem(headlineContent = { Text(text = "Some text") },
|
||||
leadingContent = {
|
||||
Icon(imageVector = Icons.Filled.AccessTime, contentDescription = null)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue