Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly update the scaffoldState when the scrollstate changes. #2278

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.key
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.wear.compose.foundation.ExperimentalWearFoundationApi
Expand Down Expand Up @@ -56,34 +57,39 @@ fun ScreenScaffold(

val key = remember { Any() }

DisposableEffect(key) {
onDispose {
scaffoldState.removeScreen(key)
// We need to update the scaffoldState with the proper scrollState
key(scrollState) {
DisposableEffect(key) {
onDispose {
scaffoldState.removeScreen(key)
}
}
}

OnFocusChange { focused ->
if (focused) {
scaffoldState.addScreen(key, timeText, scrollState)
} else {
scaffoldState.removeScreen(key)
OnFocusChange { focused ->
if (focused) {
scaffoldState.addScreen(key, timeText, scrollState)
} else {
scaffoldState.removeScreen(key)
}
}
}

Scaffold(
modifier = modifier,
timeText = timeText,
positionIndicator = {
if (positionIndicator != null) {
positionIndicator()
} else if (scrollState is ScalingLazyColumnState) {
PositionIndicator(scalingLazyListState = scrollState.state)
} else if (scrollState is ScalingLazyListState) {
PositionIndicator(scalingLazyListState = scrollState)
} else if (scrollState is LazyListState) {
PositionIndicator(scrollState)
} else if (scrollState is ScrollState) {
PositionIndicator(scrollState)
positionIndicator = remember(scrollState, positionIndicator) {
{
if (positionIndicator != null) {
positionIndicator()
} else if (scrollState is ScalingLazyColumnState) {
PositionIndicator(scalingLazyListState = scrollState.state)
} else if (scrollState is ScalingLazyListState) {
PositionIndicator(scalingLazyListState = scrollState)
} else if (scrollState is LazyListState) {
PositionIndicator(scrollState)
} else if (scrollState is ScrollState) {
PositionIndicator(scrollState)
}
}
},
content = { Box { content() } },
Expand Down
Loading