Skip to content

Conversation

kez-lab
Copy link
Contributor

@kez-lab kez-lab commented May 22, 2025

Summary of changes

  • Modified the logic so that the ViewModel state and the actual pager's current page are synchronized only after the HorizontalPager's page transition animation completes.
  • This change prevents the Toolbar (page title) and the visible page from becoming out of sync during page transitions.

Related Issue

Detailed changes

  • Added synchronization of the ViewModel state with the current pager page in the invokeOnCompletion block after animateScrollToPage inside LaunchedEffect(uiState.selectedPromptOption).

Code example

LaunchedEffect(uiState.selectedPromptOption) {
    launch {
        pagerState.animateScrollToPage(
            uiState.selectedPromptOption.ordinal,
            animationSpec = spatialSpec,
        )
    }.invokeOnCompletion {
        if (uiState.selectedPromptOption != PromptType.entries[pagerState.currentPage]) {
            onSelectedPromptOptionChanged(PromptType.entries[pagerState.currentPage])
        }
    }
}

ScreenShot

Before

Screen_recording_20250522_213720.webm

After

Screen_recording_20250522_220528.webm

Copy link
Collaborator

@riggaroo riggaroo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fix :)

@riggaroo riggaroo merged commit 4756396 into android:main May 23, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug Report: CreationScreen Toolbar and targetState mismatch during HorizontalPager animation
2 participants