The onClick of CompactChip has stopped working aft...
# compose-wear
y
The onClick of CompactChip has stopped working after I upgraded to
Wear Compose 1.1.0-beta01
and
compose 1.3.0
. Is there an example how to define CompactChip and make it clickable?
Copy code
CompactChip(
    modifier = modifier.padding(top = 8.dp),
    onClick = onClick,
    label = {
        Text(
            text = stringResource(R.string.click_me),
            maxLines = 1,
            overflow = TextOverflow.Ellipsis
        )
    }
)
y
Probably worth raising a bug to track
y
@yschimke I found the root cause, I put the compact chip in the second page of
PagerScreen
using
horologist 0.1.15
with compose 1.3.0 and wear compose 1.1.0 beta01. The click event doesn’t seem to be forwarded to the second page, as i put the compat chip on the first page of PagerScreen, then it is clickable. Might be a bug combi for
horologist
with
compose 1.3.0
and
wear compose 1.1.0-beta01
I will open an issue for horologist.
y
Thanks, good catch.
y
Here is the issue https://github.com/google/horologist/issues/710, thanks for looking into this.
y
In best case if we release 0.2.x it might solve it. But I'll test in next couple of days
It seems to be edgeSwipeToDismiss that is blocking things. Not specifically CompactChip.
Copy code
PagerScreen(
    modifier = Modifier
        .fillMaxSize()
        .edgeSwipeToDismiss(swipeDismissState),
cc @stevebower
y
@yschimke @stevebower I opened a ticket at https://issuetracker.google.com/issues/256543970 to better track this particular issue.
j
edgeSwipeToDismiss is blocking whole screen or just edge? I don't recall any changes in edgeSwipeToDismiss for a long time - @Michail Kulaga
y
Whole screen from what I experience.
s
Hi - still looking at this, Yingding's repro is very useful. We'll update here when we have got further with the investigation.
Ok, I've updated the ticket. The short answer is that the sample code posted in the ticket needs to put a SwipeToDismissBox around the PagerScreen, otherwise the Modifier.edgeSwipeToDismiss cannot work properly. We will improve the documentation for Modifier.edgeSwipeToDismiss to make it clear that the SwipeToDismissBox is required. There is some more detail in the ticket on how to configure the SwipeToDismissBox correctly for this use case - it's actually even easier if SwipeDismissableNavHost is used for the app. Hope that helps!
y
@stevebower I see, thank you so much for looking into this. I reduced the code from a horologist example (https://github.com/google/horologist/blob/main/sample/src/main/java/com/google/android/horologist/navsample/NavWearApp.kt), where SwipeDismissableNavHostState() is indeed created and pass to a WearNavScaffold. I guess the SwipeToDismissBox is called internally. Surprisingly, my code without SwipeToDismissBox somehow worked with wear compose 1.0.2 and compose 1.2.1. Thanks so much for looking into this. Really appreciated it.
y
The navhost uses it
s
Yes - there was a recent change in the Compose Foundation library which changed the handling of nested scrolling/flinging. Whilst that change was fine, it caused a problem if a Modifier.edgeSwipeToDismiss was not sharing state with a parent SwipeToDismissBox - it would now wait indefinitely for the swipeable anchors to be provided once the swipe had begun.
y
I tested the suggestion to put a SwipeToDismissBox on top of the PagerScreen, for compose 1.3.0 and wear-compose 1.1.0-beta01 works great. The same code for compose 1.2.1 and wear-compose 1.0.2 is the nested scrolling very sensitive, with a swipe back on PagerScreen’s second page, I got onDismissed trigged. Interesting.
y
That sounds lime the preferred outcome
y
thanks so much for your help.