https://kotlinlang.org logo
w

Wesley Darnell

06/08/2023, 1:57 AM
Hello! First time poster and new to compose. Have a wear-os with a simple HoritontalPager. 2 pages of a LazyScalingList then a 3rd with GoogleMap. Having an issue with the map and pager. Found my horizontal drags are being comsumed by the pager. Looking for options to let GoogleMap consume the actions instead, and stop propagation to the pager? I have been able to fully consume all the drags, but my current implementation would require handling all the map dragging myself. Don't want to re-invent the wheel and logic. Issue reported here by another, really wondering a current workaround: https://github.com/googlemaps/android-maps-compose/issues/274 Navigation on the map is handled by a overlayed button. Click goes back a page. Can also swipe on the button.
HorizontalPager(
pageCount = 2,
state = pagerState,
userScrollEnabled = true,
pageNestedScrollConnection = PagerDefaults.pageNestedScrollConnection(
Orientation.Horizontal
),
) { page ->
when (page) {
0 -> {
SwipeToDismissBox(
state = state,
onDismissed = {
navController.popBackStack()
},
hasBackground = true,
) {
ScalingLazyColumn() {
Item() {...}
}}
}
1 -> {
Box() {
GoogleMap(
modifier = Modifier.fillMaxSize()
.pointerInput(Unit) {
detectDragGestures(
onDrag = { change, offset ->
//stop propagation? Does stop horizontalPager behavior (As wanted)
change.consume()
//move google map
//TODO: Fix Ratio, way off.
cameraPositionState.position = CameraPosition.fromLatLngZoom(
...
)
}
)
},
cameraPositionState = cameraPositionState,
) {...}
Button(
onClick = {
coroutineScope.launch {
pagerState.animateScrollToPage(pagerState.currentPage - 1)
}
},
...
) {
//Back icon
Icon(...)
}
}
}
}
}
s

stevebower

06/08/2023, 4:29 PM
Hi Wesley - when pagerState.currentPage is the page with the maps component, set the HorizontalPager's userScrollEnabled = false and that will allow the gesture handling to be done by the maps component. We tried that out here and it works ok: https://github.com/android/wear-os-samples/pull/834/files
w

Wesley Darnell

06/08/2023, 9:25 PM
This works in my app, but it's failing to fully snap to the map page. It shuts off user scroll 50% into the map page.
s

stevebower

06/09/2023, 11:35 AM
That didn't happen in the PR we put together (see above). Make sure you're setting userScrollEnabled something like this:
userScrollEnabled = pagerState.currentPage != x
(where x is the page index for your map page). Sounds like you might be checking pagerState.targetPage.
w

Wesley Darnell

06/10/2023, 3:03 AM
I did have it set to currentPage, so that's odd. I found using pagerState.settledPage had the desired effect. Now properly lands on the map page. Though, now I am fighting my SwipeDismissableNavHost in my Scaffold. Horizontal swipes on the map are stolen by the swipe to dismiss. Edit: Looking at the PR now, and see this looks like it was considered. Working on implementing.
11 Views