Skip to content

EmptySection flickers during pane transition animations due to premature state cleanup #9

@wo55555

Description

@wo55555

Description:
When using ListDetailPaneScaffold with AnimatedPane, navigating between the list pane and the detail pane causes the EmptySection to briefly flash during the enter and exit animations in phone-size screen.

Entry Problem:

LaunchedEffect(chatId) {
    viewModel.onAction(ChatDetailAction.OnSelectChat(chatId))  // ← changed after entry the detail pane
}

Back Problem:

BackHandler(enabled = scaffoldNavigator.canNavigateBack()) {
    scope.launch {
        scaffoldNavigator.navigateBack()
        viewModel.onAction(OnSelectChat(null))  // ← too early
    }
}

Solve:
Maybe can observe the chatId and state.chatUi at the same time to solve the entry problem:

showEmptySection = chatId == null && state.chatUi == null  // add a new variable in the ChatDetailScreen

and change the chatId in ChatListDetailAdaptiveLayout:

detailPane = {
    AnimatedPane {
        // Cleanup fires AFTER exit animation completes and content leaves composition
        DisposableEffect(Unit) {
            onDispose {
                viewModel.onAction(OnSelectChat(null))
            }
        }
        ...
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions