pull/1795/merge
Anh Tuan Le (Jason) 5 days ago committed by GitHub
commit a59f40e232
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -21,19 +21,25 @@ import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.MutableWindowInsets
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.exclude
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.onConsumedWindowInsetsChanged
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeContent
import androidx.compose.foundation.layout.safeDrawing import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsBottomHeight import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.layout.windowInsetsTopHeight
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
@ -43,6 +49,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag import androidx.compose.ui.platform.testTag
@ -95,6 +102,7 @@ fun TopicScreen(
) )
} }
@OptIn(ExperimentalLayoutApi::class)
@VisibleForTesting @VisibleForTesting
@Composable @Composable
internal fun TopicScreen( internal fun TopicScreen(
@ -109,16 +117,23 @@ internal fun TopicScreen(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
val state = rememberLazyListState() val state = rememberLazyListState()
val remainingInsets = remember { MutableWindowInsets() }
val safeContent = WindowInsets.safeContent
TrackScrollJank(scrollableState = state, stateName = "topic:screen") TrackScrollJank(scrollableState = state, stateName = "topic:screen")
Box( Box(
modifier = modifier, modifier = modifier.onConsumedWindowInsetsChanged { consumedWindowInsets ->
remainingInsets.insets = safeContent.exclude(consumedWindowInsets)
},
) { ) {
LazyColumn( LazyColumn(
state = state, state = state,
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
) { ) {
item { item {
Spacer(Modifier.windowInsetsTopHeight(WindowInsets.safeDrawing)) // Use actual remaining insets that has been consumed.
Spacer(
Modifier.height(remainingInsets.asPaddingValues().calculateTopPadding()),
)
} }
when (topicUiState) { when (topicUiState) {
TopicUiState.Loading -> item { TopicUiState.Loading -> item {

Loading…
Cancel
Save