Yingding Wang
01/09/2023, 7:36 PMhorologist.WearNavScaffold
intercepts the drag gesture intended for a AndroidView
composable. Does anybody experience the same issue?
Is it possible to disable the swipe back gesture on a NavGraphBuilder.scrollable
temporarily?Yingding Wang
01/09/2023, 7:46 PMAndroidView
composable. I used
requestDisallowInterceptTouchEvent(true)
on the view system before similar to this hack (https://stackoverflow.com/questions/31844471/android-dragging-in-mpandroidchart-is-unresponsive-when-contained-in-scrollvie/59769402#59769402)
Is it possible to achieve the same with compose-wear?Yingding Wang
01/09/2023, 7:49 PMyschimke
01/09/2023, 9:43 PMyschimke
01/09/2023, 9:43 PMstate: SwipeDismissableNavHostState = rememberSwipeDismissableNavHostState()
yschimke
01/09/2023, 9:44 PMyschimke
01/09/2023, 9:45 PMYingding Wang
01/09/2023, 11:09 PMswipeToDismissBoxState
inside the SwipeDismissableNavHostState
which takes AnimationSpec
and a callback, it doesn’t seem to have any influence of setting the regions to trigger swipe back?
public class SwipeToDismissBoxState(
animationSpec: AnimationSpec<Float> = SwipeToDismissBoxDefaults.AnimationSpec,
confirmStateChange: (SwipeToDismissValue) -> Boolean = { true },
)
yschimke
01/09/2023, 11:22 PMYingding Wang
01/10/2023, 12:10 AM.edgeSwipeToDismiss(swipeToDismissBoxState, 0.dp)
doesn’t help to deactivate the SwipeDismissableNavHost
in my case. Inside the androidx.wear.compose.material.SwipeToDismissBox
is a Box with swipable
modifier, which probably triggers the swipe gesture from the maxWidth
Box(
modifier = modifier
.fillMaxSize()
.onSizeChanged { maxWidth = it.width.toFloat() }
.swipeable(
state = state.swipeableState,
enabled = hasBackground,
anchors = anchors(maxWidth),
thresholds = { _, _ -> FractionalThreshold(SWIPE_THRESHOLD) },
resistance = ResistanceConfig(
basis = maxWidth,
factorAtMin = TOTAL_RESISTANCE,
factorAtMax = TOTAL_RESISTANCE,
),
orientation = Orientation.Horizontal,
)
Does this means, i need to use swipeable
on my AndroidView
with anchers = anchors(0.dp)
instead of edgeSwipeToDismiss
?Yingding Wang
01/10/2023, 12:14 AMmaxWidth
defined inside the SwipeToDismissBox
? A fraction maybe?
@Composable
@OptIn(ExperimentalWearMaterialApi::class)
public fun SwipeToDismissBox(
...
) {
// Will be updated in onSizeChanged, initialise to any value other than zero
// so that it is different to the other anchor used for the swipe gesture.
var maxWidth by remember { mutableStateOf(1f) }
yschimke
01/10/2023, 4:12 AMstevebower
01/10/2023, 12:11 PM/**
* Override a composable to be unswipeable by blocking the swipe-to-dismiss gesture.
*
* When a composable is on top of another composable that supports swipe-to-dismiss,
* then [Modifier.unswipeable] can be applied to the top composable to handle and ignore
* the swipe gesture. For example, this may be used to prevent swiping away a dialog.
*/
public fun Modifier.unswipeable() =
this.then(
Modifier.draggable(
orientation = Orientation.Horizontal,
enabled = true,
state = DraggableState {}
)
)
Yingding Wang
01/10/2023, 3:35 PMunswipeable
helps disable the swipe back on SwipeToDismissBox, which also allows very slow drag
events to be consumed by the AndroidView composable still. This is is a good hack
It would be super great if edgeSwipeToDismiss
can work on any composable, as stated in this issue https://issuetracker.google.com/issues/200699800stevebower
01/10/2023, 4:18 PMYingding Wang
01/11/2023, 5:08 PMedgeSwipeToDismiss
modifier doesn’t work on my AndroidView
, which is documented in https://issuetracker.google.com/issues/200699800
Thanks for looking into this.Michail Kulaga
01/11/2023, 5:45 PM