Repository navigation
fix: route Android sheet back through models - #416
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
| containerColor = LocalLuiSemanticColors.current["background"] ?: MaterialTheme.colorScheme.surface, | ||
| ) { | ||
| BackHandler { | ||
| if (!skipPartiallyExpanded && sheetState.currentValue == SheetValue.Expanded) { |
There was a problem hiding this comment.
🟡 Compact medium sheets swallow Back
On a compact sheet configured with medium, BackHandler attempts to collapse even when Material created no partial anchor. The sheet does not move, and the model receives no dismissal event on the first Back press.
Learn more
The public sheet constructor sends the configured detents to the renderer. Material 3's rememberModalBottomSheetState only creates a partial anchor when the measured sheet is taller than half the available height. Without that anchor, partialExpand() changes the logical state without moving the sheet. Material's original Back handler checked hasPartiallyExpandedState and dismissed when there was no partial anchor.
Example: A sheet configured with medium,large measures 300 dp in an 800 dp viewport. Pressing Back leaves the sheet at the same height and sends no dismiss event; the model cannot close it or navigate on that press.
Recommended fix: Branch on sheetState.hasPartiallyExpandedState instead of the authored detent flag. Verify that a compact medium sheet emits dismiss on the first Back press and an expanded sheet with a real partial anchor collapses first.
| if (!skipPartiallyExpanded && sheetState.currentValue == SheetValue.Expanded) { | |
| if (sheetState.hasPartiallyExpandedState && sheetState.currentValue == SheetValue.Expanded) { |
Was this helpful? React with 👍 or 👎 to provide feedback.
| modifier = Modifier.luiChrome(node), | ||
| onDismissRequest = onDismiss, | ||
| sheetState = sheetState, | ||
| properties = ModalBottomSheetProperties(shouldDismissOnBackPress = false), |
| unchanged. Applications already handle `sheet ~on_dismiss` by updating their | ||
| model, so no code migration is required; handlers that assumed every Back | ||
| event meant close should perform their own hierarchical back navigation before | ||
| removing the sheet. |
There was a problem hiding this comment.
Summary
Android modal sheets no longer let Material hide the native sheet before the application handles hardware Back.
ModalBottomSheetnow usesshouldDismissOnBackPress = false; Back emits the sheet's existingDismissevent while the native sheet remains visible. The application model can therefore navigate inside a sheet before deciding whether the sheet should close, and the sheet disappears when the model removes it.For sheets with a medium detent, the explicit Back handling preserves Material's hierarchy: an expanded sheet first collapses with
partialExpand(), and only a later Back emitsDismiss. Outside presses and swipe dismissal keep Material's existing close behavior.Validation
./gradlew :lui:compileDebugKotlin— passed.Link to Devin session: https://app.devin.ai/sessions/a35d6ca9bf0447df91cc820d3bd6f48f
Open in Devin Desktop: https://app.devin.ai/desktop/session/a35d6ca9bf0447df91cc820d3bd6f48f?variant=devin
Requested by: @tiensonqin
👀 3 findings for you to triage