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

BottomSheet closes when recomposing #330

Open
jordond opened this issue Feb 9, 2024 · 8 comments
Open

BottomSheet closes when recomposing #330

jordond opened this issue Feb 9, 2024 · 8 comments
Labels
compose-kmp Compose KMP possible bugs

Comments

@jordond
Copy link

jordond commented Feb 9, 2024

I have a BottomSheet that when launched, allows the user to choose a color to base the app theme on. When a color is selected a new theme is generated and the colors in the app change.

When this happens the BottomSheet gets dismissed.

Here is some relevant code:

val screenModel = getScreenModel<SettingsModel>()
val state by screenModel.collectAsState()

val navigator = LocalNavigator.currentOrThrow

BottomSheetNavigator(
    sheetShape = MaterialTheme.shapes.large,
) { bottomSheetNavigator ->
    SettingsScreenContent(
        settings = state.settings,
        updateSettings = screenModel::update,
        onAction = { action ->
            when (action) {
                is Close -> navigator.pop()
                is ChangeTheme -> bottomSheetNavigator.show(DynamicThemeSheet())
            }
    )
}

And a video of it happening:

Screen.Recording.2024-02-09.at.4.29.17.PM.mov
@Kashifmasood07
Copy link

@jordond I am also facing the similar issue with textfield, were you able to solve it?

@Kashif-E
Copy link
Contributor

for me its only happening on ios not on android

@Kashif-E
Copy link
Contributor

@DevSrSouza can you please have a look at this? for me it happens only in ios and after updating to compose 1.6

@hm-tamim
Copy link
Contributor

hm-tamim commented Mar 6, 2024

Same here, only in iOS. It closes when TextField is focused and keyboard opens up. Compose 1.6

@hm-tamim
Copy link
Contributor

hm-tamim commented Mar 8, 2024

It seems the culprit is confirmValueChange in rememberModalBottomSheetState, it's using rememberSaveable where confirmValueChange is used as a key. When this method changes in iOS somehow when you open keyboard or any other thing that causes recomposition, it recreates the sheet state, which hides the bottom sheet modal.

Removing confirmValueChange and using LaunchedEffect to observe sheetState.currentValue solves the issue.

Let me raise a PR for this.

@DevSrSouza
Copy link
Collaborator

The PR from @hm-tamim was released on 1.0.0-alpha04. Try out and let us know if the issue is fixed.

@DevSrSouza DevSrSouza added the compose-kmp Compose KMP possible bugs label Apr 8, 2024
@Qw4z1
Copy link

Qw4z1 commented Apr 15, 2024

@DevSrSouza I had the same issue after updating compose, and can confirm that the issue is fixed in 1.1.0-alpha04. Big thanks to @hm-tamim!

@Kashif-E
Copy link
Contributor

@DevSrSouza it's fixed with @hm-tamim's contribution but there is a case, open any bottom sheet with a text field, keep the text field in focus and navigate to another screen pop the screen and in some cases backstack is cleared

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compose-kmp Compose KMP possible bugs
Projects
None yet
Development

No branches or pull requests

6 participants