Skip to content

Commit

Permalink
added bottom sheet padding to prevent displaying bottom behind system…
Browse files Browse the repository at this point in the history
…bars
  • Loading branch information
DatL4g committed Apr 24, 2024
1 parent 37ffbba commit acfcc9c
Showing 1 changed file with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,25 @@ import coil3.compose.rememberAsyncImagePainter
import dev.datlag.aniflow.LocalEdgeToEdge
import dev.datlag.aniflow.SharedRes
import dev.datlag.aniflow.anilist.CharacterStateMachine
import dev.datlag.aniflow.common.htmlToAnnotatedString
import dev.datlag.aniflow.common.isFullyExpandedOrTargeted
import dev.datlag.aniflow.common.preferred
import dev.datlag.aniflow.common.preferredName
import dev.datlag.aniflow.common.*
import dev.datlag.aniflow.ui.navigation.screen.medium.component.TranslateButton
import dev.datlag.tooling.compose.ifFalse
import dev.datlag.tooling.decompose.lifecycle.collectAsStateWithLifecycle
import dev.icerock.moko.resources.compose.stringResource

@OptIn(ExperimentalLayoutApi::class, ExperimentalMaterial3Api::class)
@Composable
fun CharacterDialog(component: CharacterComponent) {
val sheetState = rememberModalBottomSheetState()
val insets = if (LocalEdgeToEdge.current) {
WindowInsets(0, 0, 0, 0)
val (insets, bottomPadding) = if (LocalEdgeToEdge.current) {
WindowInsets(
left = 0,
top = 0,
right = 0,
bottom = 0
) to BottomSheetDefaults.windowInsets.only(WindowInsetsSides.Bottom).asPaddingValues()
} else {
BottomSheetDefaults.windowInsets
BottomSheetDefaults.windowInsets to PaddingValues()
}

ModalBottomSheet(
Expand Down Expand Up @@ -88,7 +91,7 @@ fun CharacterDialog(component: CharacterComponent) {
Text(
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(vertical = 8.dp),
.padding(top = 8.dp),
text = name.preferred(),
style = MaterialTheme.typography.headlineMedium,
maxLines = 2,
Expand All @@ -104,9 +107,17 @@ fun CharacterDialog(component: CharacterComponent) {
) {
val description by component.description.collectAsStateWithLifecycle()
val translatedDescription by component.translatedDescription.collectAsStateWithLifecycle()
val textHasPadding = remember(translatedDescription, description) {
!translatedDescription.isNullOrBlank() || !description.isNullOrBlank()
}

FlowRow(
modifier = Modifier.fillMaxWidth().padding(vertical = 16.dp),
modifier = Modifier
.fillMaxWidth()
.padding(top = 16.dp, bottom = 8.dp)
.ifFalse(textHasPadding) {
padding(bottomPadding.merge(PaddingValues(bottom = 16.dp)))
},
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically),
horizontalArrangement = Arrangement.SpaceAround
) {
Expand Down Expand Up @@ -185,7 +196,9 @@ fun CharacterDialog(component: CharacterComponent) {
Text(
modifier = Modifier
.verticalScroll(rememberScrollState())
.padding(bottom = 16.dp),
.padding(
bottomPadding.merge(PaddingValues(bottom = 16.dp))
),
text = it.htmlToAnnotatedString()
)
} ?: run {
Expand Down

0 comments on commit acfcc9c

Please sign in to comment.