I'm trying out animation-codelab. In last chapter Gesture Animation. Swipe behavior doesn't work when Modifier is applied on Surface but works when it's applied on the Row itself. What could be the issue?
aniruddha dhamal
06/08/2021, 4:40 PM
Code snippet ::
Copy code
@Composable
private fun TaskRow(task: String, onRemove: () -> Unit) {
Surface(
modifier = Modifier
.fillMaxWidth()
.swipeToDismiss(onRemove), // Doesn't work
elevation = 2.dp
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
//.swipeToDismiss(onRemove), // Works when applied on Row
) {
...
t
tad
06/08/2021, 4:42 PM
Surface is probably eating the gesture events. Try wrapping it in a Box with the modifier.
tad
06/08/2021, 4:44 PM
I get why they changed the onClick handling for Surface, but it's leading to a fractured API where we have to know to handle particular layouts differently instead of slapping Modifiers on them like every other layout.
☝️ 1
a
aniruddha dhamal
06/08/2021, 5:21 PM
Wrapping Row in Box works but not with wrapping Surface.
When should we use Box vs Surface? Surface provides benefit of color n contentColor. Does Box also provide that?