Fixed
Status Update
Comments
an...@google.com <an...@google.com>
za...@gmail.com <za...@gmail.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit 9082f62682f853ad5251a1c79dde9eccba7abdd9
Author: Max Alfonso-Ying <maxying@google.com>
Date: Thu Apr 18 00:34:40 2024
[M2 text field] Apply background to decoration box
...instead of to the BasicTextField, so changing the
backgroundColor will properly change the decoration
box's background color.
Fixes: b/307694651
Test: added unit tests
Relnote: "Fix backgroundColor not applying to
TextFieldDecorationBox and OutlinedTextFieldDecorationBox.
Decoration boxes now accept a `shape` parameter."
Change-Id: I371c26718597cb36ac537e9412ce476532afb40d
M compose/material/material/api/current.txt
M compose/material/material/api/restricted_current.txt
M compose/material/material/integration-tests/material-demos/src/main/java/androidx/compose/material/demos/TextFieldDecorationBoxDemos.kt
M compose/material/material/src/androidInstrumentedTest/kotlin/androidx/compose/material/textfield/TextFieldDecorationBoxTest.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/OutlinedTextField.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextField.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextFieldDefaults.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextFieldImpl.kt
https://android-review.googlesource.com/3046833
Branch: androidx-main
commit 9082f62682f853ad5251a1c79dde9eccba7abdd9
Author: Max Alfonso-Ying <maxying@google.com>
Date: Thu Apr 18 00:34:40 2024
[M2 text field] Apply background to decoration box
...instead of to the BasicTextField, so changing the
backgroundColor will properly change the decoration
box's background color.
Fixes:
Test: added unit tests
Relnote: "Fix backgroundColor not applying to
TextFieldDecorationBox and OutlinedTextFieldDecorationBox.
Decoration boxes now accept a `shape` parameter."
Change-Id: I371c26718597cb36ac537e9412ce476532afb40d
M compose/material/material/api/current.txt
M compose/material/material/api/restricted_current.txt
M compose/material/material/integration-tests/material-demos/src/main/java/androidx/compose/material/demos/TextFieldDecorationBoxDemos.kt
M compose/material/material/src/androidInstrumentedTest/kotlin/androidx/compose/material/textfield/TextFieldDecorationBoxTest.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/OutlinedTextField.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextField.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextFieldDefaults.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/TextFieldImpl.kt
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-main
commit 32d335ae09b704ce6e52b3e80d28a1cc8cdae474
Author: Zach Klippenstein <zach.klippenstein@gmail.com>
Date: Sun Aug 01 17:14:29 2021
Fix swipeable exception when offset is very close to an anchor.
Bug: 191993377
The logic in the findBounds function that determines when the given offset is an exact match for an anchor accounts for rounding error when comparing the floats. This means that, even when an offset is considered an exact match, the actual offset value might not be exactly equal to the matching anchor value. This breaks the logic in SwipeableState's progress getter, which uses the value returned by findBounds as a key into the anchors map. If that returned value is not exactly equal, the map throws a NoSuchElementException.
This fixes the issue by making findBounds return the anchor that was considered an exact match instead of the offset value itself.
Relnote: "Fix the behavior of SwipeableState in the case where the swipe offset is within a rounding error of an anchor."
Change-Id: I03d39d25bc376314d7197484c2a707498296aa97
Test: tested manually, leaving automated tests until swipeable rewrite
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/Swipeable.kt
https://android-review.googlesource.com/1783329
Branch: androidx-main
commit 32d335ae09b704ce6e52b3e80d28a1cc8cdae474
Author: Zach Klippenstein <zach.klippenstein@gmail.com>
Date: Sun Aug 01 17:14:29 2021
Fix swipeable exception when offset is very close to an anchor.
Bug: 191993377
The logic in the findBounds function that determines when the given offset is an exact match for an anchor accounts for rounding error when comparing the floats. This means that, even when an offset is considered an exact match, the actual offset value might not be exactly equal to the matching anchor value. This breaks the logic in SwipeableState's progress getter, which uses the value returned by findBounds as a key into the anchors map. If that returned value is not exactly equal, the map throws a NoSuchElementException.
This fixes the issue by making findBounds return the anchor that was considered an exact match instead of the offset value itself.
Relnote: "Fix the behavior of SwipeableState in the case where the swipe offset is within a rounding error of an anchor."
Change-Id: I03d39d25bc376314d7197484c2a707498296aa97
Test: tested manually, leaving automated tests until swipeable rewrite
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/Swipeable.kt
an...@glovoapp.com <an...@glovoapp.com> #5
Hey there!
Is there any timeline for this bugfix to hit the next minor release? I can still reproduce this crash in Compose 1.0.2.
Is there any timeline for this bugfix to hit the next minor release? I can still reproduce this crash in Compose 1.0.2.
ma...@google.com <ma...@google.com> #6
I believe this has been fixed. Could you post your code that hits this issue?
an...@glovoapp.com <an...@glovoapp.com> #7
Sure.
This is the composable that uses the swipeable
Modifier:
...
Box(
Modifier.background(
backgroundColor.copy(alpha = swipeableState.toBackgroundAlpha()),
),
) {
Box(
Modifier
.fillMaxWidth()
.height(constraints.maxHeight)
.nestedScroll(nestedScrollConnection)
.swipeable(
state = swipeableState,
enabled = swipeableState.currentValue == Expanded,
anchors = mapOf(
maxHeightInPixels to Collapsed,
0f to Expanded,
),
orientation = Orientation.Vertical,
resistance = null,
thresholds = { _, _ -> FractionalThreshold(MIN_DRAG_THRESHOLD) },
)
.offset {
IntOffset(
x = 0,
y = swipeableState.offset.value.roundToInt(),
)
}
.padding(top = topSpacing)
.clip(RoundedCornerShape(topStart = Radius.S, topEnd = Radius.S))
.background(surfaceColor),
) {
Column(Modifier.fillMaxHeight()) {
Box {
header()
}
Box(Modifier.verticalScroll(scrollState)) {
body()
}
}
}
}
...
And this is the extension function that raises the exception:
@ExperimentalMaterialApi
@Composable
private fun SwipeableState<BottomSheetState>.toBackgroundAlpha(): Float {
return if (offset.value == 0f) {
MIN_BACKGROUND_ALPHA
} else {
(MIN_BACKGROUND_ALPHA - progress.fraction).coerceAtLeast(0f)
}
}
The issue comes from the access to progress.fraction
.
And here's the stacktrace:
java.util.NoSuchElementException: Key 1.8626451E-8 is missing in the map.
at kotlin.collections.MapsKt__MapWithDefaultKt.getOrImplicitDefaultNullable(MapWithDefault.kt:24)
at kotlin.collections.MapsKt__MapsKt.getValue(Maps.kt:344)
at androidx.compose.material.SwipeableState.getProgress(Swipeable.kt:275)
...
an...@glovoapp.com <an...@glovoapp.com> #9
Perfect, thanks for the heads up!
I'd prefer to wait for the next stable release and avoid the direct access to progress.fraction
for now.
Description
Jetpack Compose release version: 1.0.0-beta09
Android Studio Build: 2020.3.1 Beta4
I have a BottomSheetScaffold (which is based on Swipeable) and it randomly crashes. Our QA reports seeing these crashes on Android 11 device when pressing HOME and returning back, but I'm not sure if this is related, I got them just by navigating between screens IIRC.
Unfortunately I can't figure out the minimal case to attach as a project.
Here's the stacktrace: