Skip to content

Commit 433b00a

Browse files
committed
Fix: ensure pager and toolbar state sync after interrupted animation
1 parent 4a29b16 commit 433b00a

File tree

1 file changed

+13
-5
lines changed
  • feature/creation/src/main/java/com/android/developers/androidify/creation

1 file changed

+13
-5
lines changed

feature/creation/src/main/java/com/android/developers/androidify/creation/CreationScreen.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ fun EditScreen(
363363
}
364364
} else {
365365
BottomButtons(
366-
onButtonColorClicked = { showColorPickerBottomSheet = !showColorPickerBottomSheet },
366+
onButtonColorClicked = {
367+
showColorPickerBottomSheet = !showColorPickerBottomSheet
368+
},
367369
uiState = uiState,
368370
onStartClicked = onStartClicked,
369371
modifier = Modifier
@@ -403,10 +405,16 @@ private fun MainCreationPane(
403405
val pagerState = rememberPagerState(0) { PromptType.entries.size }
404406
val focusManager = LocalFocusManager.current
405407
LaunchedEffect(uiState.selectedPromptOption) {
406-
pagerState.animateScrollToPage(
407-
uiState.selectedPromptOption.ordinal,
408-
animationSpec = spatialSpec,
409-
)
408+
launch {
409+
pagerState.animateScrollToPage(
410+
uiState.selectedPromptOption.ordinal,
411+
animationSpec = spatialSpec,
412+
)
413+
}.invokeOnCompletion {
414+
if (uiState.selectedPromptOption != PromptType.entries[pagerState.currentPage]) {
415+
onSelectedPromptOptionChanged(PromptType.entries[pagerState.currentPage])
416+
}
417+
}
410418
}
411419
LaunchedEffect(pagerState) {
412420
snapshotFlow { pagerState.currentPage }.collect { page ->

0 commit comments

Comments
 (0)