Status Update
Comments
ke...@fbinv.com <ke...@fbinv.com> #2
Project: platform/frameworks/support
Branch: androidx-main
Author: Louis Pullen-Freilich <
Link:
Adds OverscrollEffect#withoutDrawing and OverscrollEffect#withoutEventHandling
Expand for full commit details
Adds OverscrollEffect#withoutDrawing and OverscrollEffect#withoutEventHandling
These APIs allow overscroll to have events dispatched to it by one component, and rendered in a separate component.
Fixes: b/266550551
Fixes: b/204650733
Fixes: b/255554340
Fixes: b/229537244
Test: OverscrollTest
Relnote: "Adds OverscrollEffect#withoutDrawing and OverscrollEffect#withoutEventHandling APIs - these APIs create a wrapped instance of the provided overscroll effect that doesn't draw / handle events respectively, which allows for rendering overscroll in a separate component from the component that is dispatching events. For example, disabling drawing the overscroll inside a lazy list, and then drawing the overscroll separately on top / elsewhere."
Change-Id: Idbb3d91546b49c1987a041f959bce4b2b09a9f61
Files:
- M
compose/foundation/foundation/api/current.txt
- M
compose/foundation/foundation/api/restricted_current.txt
- M
compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/OverscrollDemo.kt
- M
compose/foundation/foundation/samples/src/main/java/androidx/compose/foundation/samples/OverscrollSample.kt
- M
compose/foundation/foundation/src/androidInstrumentedTest/kotlin/androidx/compose/foundation/OverscrollTest.kt
- M
compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Overscroll.kt
Hash: f64e25b7a473c757d080521e7dd97b3f6670f60d
Date: Fri Nov 01 18:43:56 2024
ro...@gmail.com <ro...@gmail.com> #3
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.compose.foundation:foundation:1.8.0-alpha06
androidx.compose.foundation:foundation-android:1.8.0-alpha06
androidx.compose.foundation:foundation-jvmstubs:1.8.0-alpha06
androidx.compose.foundation:foundation-linuxx64stubs:1.8.0-alpha06
ke...@google.com <ke...@google.com>
ke...@google.com <ke...@google.com>
ke...@google.com <ke...@google.com>
ap...@google.com <ap...@google.com> #4
Branch: androidx-main
commit 90075b00a1b5e5ebd24fb8c03f8a3fc2a7c72e98
Author: Kevin Truong <kevinctruong@google.com>
Date: Wed Oct 04 16:06:44 2023
[BottomSheet] Adding ModalBottomSheetProperties class
Adding a ModalBottomSheetProperties that contains securePolicy, isFocuable, and shouldDismissOnBackPress. securePolicy is taken from the ModalBottomSheet API and placed into this class for neatness.
isFocusable and shouldDismissOnBackPress are parameters that can be used to determine if the modal bottom sheet should receive IME events, and shouldDismissOnBackPress determines if the modal bottom sheet should dismiss when back is pressed on the IME. These parameters are ported from PopupProperties and the implementation is very similar to their usage within Popup.
Bug: 278216859
Test: Updating modalBottomSheet_imePadding test to use the isFocusable parameter, so the text field within the modal bottom sheet can receive focus.
Relnote: adding ModalBottomSheetProperties. Moving securePolicy into ModalBottomSheetProperties. Adding isFocusable and shouldDismissOnBackPress to ModalBottomSheetProperties. These new booleans help determine how modal bottom sheet should handle IME events.
Change-Id: Iea56ff84fd2f8a70037607e8aef0ceaf7a47e3d0
M compose/material3/material3/api/current.txt
M compose/material3/material3/api/restricted_current.txt
M compose/material3/material3/src/androidInstrumentedTest/kotlin/androidx/compose/material3/ModalBottomSheetTest.kt
M compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/ModalBottomSheet.android.kt
ru...@gmail.com <ru...@gmail.com> #5
Any chance for a release including this fix soon?
ke...@payback.net <ke...@payback.net> #6
tf...@gmail.com <tf...@gmail.com> #7
There’s already a dedicated issue about the back not working when android:enableOnBackInvokedCallback=“true”
is set:
It seems like it’s blocked by a general lack of predictive back support in Compose, though:
sh...@navi.com <sh...@navi.com> #8
ar...@gmail.com <ar...@gmail.com> #9
I've tried androidx.compose.material3:material3:1.2.0-beta01
and I believe it's still not working. BackHandler {}
is not called inside ModalBottomSheet
, the sheet is closing instead.
ay...@gmail.com <ay...@gmail.com> #10
Any ideas on why this is marked as fixed?
el...@ur.se <el...@ur.se> #11
tf...@gmail.com <tf...@gmail.com> #12
The fix wasn't to support BackHandler {}
. They just added a new properties
arg that you can set whether the sheet should be dismissed on back or not:
ModalBottomSheet(
...
properties = ModalBottomSheetDefaults.properties(shouldDismissOnBackPress = /* boolean goes here */),
...
)
Since the sheet is in a separate window, I'm afraid this might be the best they can do. That's pretty similar to the API of dialogs, which also have their own window:
Dialog(
...
properties = DialogProperties(dismissOnBackPress = /* boolean goes here */),
...
)
But of course the APIs aren't super consistent 😅
as...@gmail.com <as...@gmail.com> #13
da...@tixr.com <da...@tixr.com> #14
The bug as it's stated in the title and the snippet still exists despite the "fix": it remains impossible to use a BackHandler
inside a ModalBottomSheet.
Some thoughts after looking at the code: somehow the ModalBottomSheetWindow
needs to implement a OnBackPressedDispatcherOwner
and delegate to it when back is pressed (in dispatchKeyEvent
), instead of directly calling onDismissRequest like it does today (material3 version 1.2.0).
I note that the "ModalBottomSheetWindow" is actually a View
, not a Window
-- perhaps that's why this is not trivial to fix.
Knowing the code doesn't give me a good idea for a workaround though...
da...@tixr.com <da...@tixr.com> #15
I have found a workaround. It consists in intercepting the key event, doing the same checks that ModalBottomSheetWindow.dispatchKeyEvent
would do, and then delegating that to the OnBackPressedDispatcherOwner
manually.
@Composable
fun ModalBottomSheetWithBackHandling(
onDismissRequest: () -> Unit,
modifier: Modifier = Modifier,
sheetState: SheetState = rememberModalBottomSheetState(),
properties: ModalBottomSheetProperties = ModalBottomSheetDefaults.properties(),
content: @Composable ColumnScope.() -> Unit,
) {
val scope = rememberCoroutineScope()
BackHandler(enabled = sheetState.targetValue != SheetValue.Hidden) {
// Always catch back here, but only let it dismiss if shouldDismissOnBackPress.
// If not, it will have no effect.
if (properties.shouldDismissOnBackPress) {
scope.launch { sheetState.hide() }.invokeOnCompletion {
if (!sheetState.isVisible) {
onDismissRequest()
}
}
}
}
val requester = remember { FocusRequester() }
val backPressedDispatcherOwner = LocalOnBackPressedDispatcherOwner.current
ModalBottomSheet(
onDismissRequest = onDismissRequest,
modifier = modifier
.focusRequester(requester)
.focusable()
.onPreviewKeyEvent {
if (it.key == Key.Back && it.type == KeyEventType.KeyUp && !it.nativeKeyEvent.isCanceled) {
backPressedDispatcherOwner?.onBackPressedDispatcher?.onBackPressed()
return@onPreviewKeyEvent true
}
return@onPreviewKeyEvent false
},
properties = ModalBottomSheetDefaults.properties(
securePolicy = properties.securePolicy,
isFocusable = properties.isFocusable,
// Set false otherwise the onPreviewKeyEvent doesn't work at all.
// The functionality of shouldDismissOnBackPress is achieved by the BackHandler.
shouldDismissOnBackPress = false,
),
content = content,
)
LaunchedEffect(Unit) {
requester.requestFocus()
}
}
ni...@gmail.com <ni...@gmail.com> #16
Thank you for your workaround code!
j6...@gmail.com <j6...@gmail.com> #17
The problem is if you're using focusManager.clearFocus()
anywhere in your code the ModalBottomSheet will lose focus.
da...@tixr.com <da...@tixr.com> #18
BackHandler seems to be working in androidx.compose.material3:material3:1.3.0-beta02 out of the box without the workaround I posted a couple of messages above.
de...@gmail.com <de...@gmail.com> #19
pb...@gmail.com <pb...@gmail.com> #20
jo...@gmail.com <jo...@gmail.com> #21
se...@gmail.com <se...@gmail.com> #22
The short version of this solution that worked for me:
Description
Given the code
Steps:
Expectation: BackHandler's lambda is called and snackbar appears on the screen.
Reality: modal bottom sheet closes.