I'm trying out <animation-codelab>. In last chapte...
# compose
a
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?
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
Surface is probably eating the gesture events. Try wrapping it in a Box with the modifier.
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
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?
t
You can provide it yourself:
Copy code
CompositionLocalProvider(LocalContentColor provides myColor) { content() }
a
Got it! We need to manually add it.