Status Update
Comments
jo...@google.com <jo...@google.com> #3
Thanks for the report!
jo...@google.com <jo...@google.com> #4
The release notes documentation has been edited to clarify this change in behavior for line height.
To support non-standard text sizes, we encourage users to follow the Material design system and use a different style = LocalTextStyle.current.copy(lineHeight = TextUnit.Unspecified)
, or create a custom Typography
entirely.
bu...@google.com <bu...@google.com> #6
In my case, I have multiple font sizes in the same Text
(using SpanStyle
in AnnotatedString
). There are legitimate reasons for this. For example, when combining Chinese and English (phonetic) together (for language-learning purposes).
jo...@google.com <jo...@google.com> #7
Copying comment from M2 issue:
Looking at the Material guidelines and MDC views, it looks like the gesture only influences how the sheet is drawn. AnchoredDraggable's APIs support this, although we might want to improve the contract of the anchoredDrag
method so users do not have to call settle
manually.
The implementation of this lies with the Material team, reassigning for prioritization:
Here is some example code:
/**
* This receiver allows manipulating the sheet's offset.
*/
interface SheetAnimationScope {
fun seekTo(fraction: Float)
}
/**
* Seek the [ModalBottomSheetState] to fractional values between [from] and [to]. This is useful
* to integrate seeking interactions such as predictive back.
*/
suspend fun seek(
from: ModalBottomSheetValue = currentValue,
to: ModalBottomSheetValue = if (from == HalfExpanded || from == Expanded) Hidden
else if (hasHalfExpandedState) HalfExpanded
else Expanded,
block: suspend SheetAnimationScope.() -> Unit
) {
anchoredDraggableState.anchoredDrag { anchors ->
val startOffset = anchors.positionOf(from)
val targetOffset = anchors.positionOf(to)
val distance = abs(startOffset - targetOffset)
val scope = object : SheetAnimationScope {
override fun seekTo(fraction: Float) {
val newOffset = distance * fraction
dragTo(startOffset + newOffset)
}
}
scope.block()
}
anchoredDraggableState.settle(0f)
}
PredictiveBackHandler { progress ->
bottomSheetState.seek(to = ModalBottomSheetValue.Hidden) {
progress.collect { backEvent ->
seekTo(backEvent.progress)
}
}
}
se...@google.com <se...@google.com> #8
CC: Dan, is this within the scope of your predictive back work in compose?
dn...@google.com <dn...@google.com> #9
Yes! Working on this in
With the approach in the CL above, ModalBottomSheet
will automatically animate itself during the predictive back swipe gesture on U+.
dn...@google.com <dn...@google.com>
ap...@google.com <ap...@google.com> #10
Branch: androidx-main
commit 699ee4fa3f47da2ccd52fb6b4628fc2d61cd5039
Author: Dan Nizri <dniz@google.com>
Date: Wed Dec 06 20:50:22 2023
Update Compose M3 ModalBottomSheet to support Predictive Back on U+
Bug: 281967264
Bug: 307969902
Bug: 304850357
Test: added screenshot tests
Relnote: "Update Compose M3 ModalBottomSheet to support Predictive Back on U+"
Change-Id: Iccf324cb6dfc7f4ea1fe413b69e035658282360d
A compose/material3/material3/src/androidInstrumentedTest/kotlin/androidx/compose/material3/ModalBottomSheetScreenshotTest.kt
M compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/ModalBottomSheet.android.kt
M compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/SearchBar.android.kt
A compose/material3/material3/src/androidMain/kotlin/androidx/compose/material3/internal/PredictiveBack.android.kt
dn...@google.com <dn...@google.com>
pr...@google.com <pr...@google.com> #11
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.compose.material3:material3:1.3.0-alpha01
androidx.compose.material3:material3-android:1.3.0-alpha01
androidx.compose.material3:material3-desktop:1.3.0-alpha01
Description
With Android 14, apps can opt in for predictive back where they show a preview of what is happening as the system back gesture is happening (rather than only after the user confirms the system back gesture).
The Activity 1.8.0 release adds a new
PredictiveBackHandler
that allows apps to capture theprogress
of the system back gesture and use it to drive the state of their own components.I wanted to use this to start hiding a Material3 Bottom Sheet by writing code like:
But as per the two TODO messages there, I ran into two issues:
There's no way to drive the progress towards the hidden state from outside the bottom sheet - I see that
ModalBottomSheet
does this internally to support dragging the bottom sheet down, but this isn't exposed anywhere.The use of a
suspend
show method here doesn't actually work well inPredictiveBackHandler
since the scope that is provided to the trailing lambda is cancelled by the time we need to callshow
(similar to other suspending lambdas, it uses coroutine's cancellation as its indicator for cancellation). It would be helpful to have a non-suspending way to set thetargetValue
and letModalBottomSheet
take care of moving to that state. I think we could possibly work around this by usingrememberCoroutineScope
and launching theshow
into that scope, but that seems even harder to get right.