<@UHAJKUSTU> `handleBackButton` seems to not be wo...
# decompose
v
@Arkadii Ivanov
handleBackButton
seems to not be working with bottom sheets, I have these 2 use cases, in which back button does not work • When I use SlotNavigation to show a bottom sheet • When i use StackNavigation inside a BottomSheet
a
I'm pretty sure it should work on Android. Would be nice to have a reproducer.
You may also check the docs: https://arkivanov.github.io/Decompose/component/back-button/#callback-order There might be something that intercepts the back button.
v
1. For the 1st usecase of showing sheet
Copy code
val navigation = SlotNavigation<DuplicateNewsConfig>()
internal val slot = component.childSlot(
    source = navigation,
    handleBackButton = true,
    serializer = DuplicateNewsConfig.serializer()
) { config, context ->
    DuplicateNewsComponent(config.newsId, context) { news ->
        navigation.dismiss {
            if (!it) return@dismiss
            onNewsSelect(news)
        }
    }
}
And this is how I display the sheet
Copy code
duplicateNewsSlot.child?.instance?.also {
    val sheetState = rememberModalBottomSheetState()
    DuplicateNewsBottomSheet(
        component = it,
        sheetState = sheetState,
        onDismiss = {
            scope.launch { sheetState.hide() }
                .invokeOnCompletion { component.onDuplicateNewsDismiss() }
        }
    )
}
a
Oh, I guess
onDismiss
should work? Or is it not working? If the Composable DuplicateNewsBottomSheet installs
BackHandler {}
, then it would intercept the Child Slot's
handleBackButton
, I guess. Would it be possible to provide a complete reproducer project?
v
Yeah sure,
@Arkadii Ivanov I think this is some bug in compose itself I tried the exact same code shown here and back press does not close the modal bottom sheet
a
Indeed, I remember some issues with it. It might be intercepting the back button and doing nothing. But I couldn't find any tickets (filed bugs) about it.
Worth trying some latest versions of compose. This might be already fixed.
v
For the 2nd use case, where I have a stack navigation inside a bottom sheet, back button does not pop the top config
a
That might be due to the same reason?
You can try using BackHandler {} inside the sheet, and pop manually.
v
Hey, you were right Its fixed in CMP 1.6.2 I was in 1.5.11
But still In 2nd use case, back button closes the modal rathet than popping from stack nav How can i handle this?
I want it to first pop till last config, and then the modal should close
Isnt the back handler of StackNav attached the last so it should override the default one?
a
Yep, it looks like the sheet installs it's own back handler and intercepts. You can try installing your own BackHandler {} inside the sheet and pop manually.
Those modal sheets are quite painful.
v
Yeah they are I'll try this, thanks
👍 1