googlemaps / googlemaps/android-maps-compose
Bug with scrollGesturesEnabledDuringRotateOrZoom = false and rotationGesturesEnabled = false
- Dominant language
- Kotlin
- Stars
- 1.3k
- Forks
- 181
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 18
Description
android-maps-compose 4.3.0
If rotationGesturesEnabled = false and scrollGesturesEnabledDuringRotateOrZoom = false, a zoom (pinch) gesture with a rotation (or crossing fingers) will break the pan/drag gesture and make it lag. It looks like a CancellationException is swallowed internally (caught but not thrown), see : https://github.com/googlemaps/android-maps-compose/issues/502
Environment details :
android-maps-compose 4.3.0
doesn't seem to occur on the simulator, please use a real device.
Steps to reproduce :
- set rotationGesturesEnabled = false and scrollGesturesEnabledDuringRotateOrZoom = false
- Try to rotate the map with two fingers
- Try to pan.drag the map, it doesn't move as intended (zoom is not affected somehow)
Workaround :
- setting rotationGesturesEnabled = false and scrollGesturesEnabledDuringRotateOrZoom = true
Code example :
class RecompositionActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val cameraPositionState = rememberCameraPositionState {
position = defaultCameraPosition
}
Box(Modifier.fillMaxSize()) {
MapsComposeSampleTheme {
GoogleMapView(
modifier = Modifier.matchParentSize(),
cameraPositionState = cameraPositionState
)
}
}
}
}
@Composable
fun GoogleMapView(
modifier: Modifier = Modifier,
cameraPositionState: CameraPositionState = rememberCameraPositionState(),
content: @Composable () -> Unit = {},
) {
var location by remember { mutableStateOf(singapore) }
var zoom by remember { mutableStateOf(5f) }
val context = LocalContext.current
val singaporeState = MarkerState(position = location)
val mapProperties = remember {
MapProperties(
isBuildingEnabled = false,
isIndoorEnabled = false,
isMyLocationEnabled = false,
isTrafficEnabled = false,
mapType = MapType.SATELLITE,
)
}
val mapOptions = remember {
GoogleMapOptions()
.ambientEnabled(false)
.mapToolbarEnabled(false)
.compassEnabled(false)
}
val uiSettings = remember {
MapUiSettings(
compassEnabled = false,
indoorLevelPickerEnabled = false,
mapToolbarEnabled = false,
myLocationButtonEnabled = false,
rotationGesturesEnabled = false,
scrollGesturesEnabledDuringRotateOrZoom = false,
tiltGesturesEnabled = false,
zoomControlsEnabled = false,
)
}
val mapVisible by remember { mutableStateOf(true) }
if (mapVisible) {
// Detect when the map starts moving and print the reason
LaunchedEffect(cameraPositionState.isMoving) {
if (cameraPositionState.isMoving) {
Log.d(TAG, "Map camera started moving due to ${cameraPositionState.cameraMoveStartedReason.name}")
}
}
GoogleMap(
modifier = modifier.fillMaxSize(),
cameraPositionState = cameraPositionState,
googleMapOptionsFactory = {mapOptions},
onMapLoaded = {},
properties = mapProperties,
uiSettings = uiSettings,
onPOIClick = {
Log.d(TAG, "POI clicked: ${it.name}")
}
) {
val markerClick: (Marker) -> Boolean = {
Log.d(TAG, "${it.title} was clicked")
cameraPositionState.projection?.let { projection ->
Log.d(TAG, "The current projection is: $projection")
}
false
}
Marker(
state = singaporeState,
title = "Marker in Singapore",
onClick = markerClick
)
content()
}
}
}
}
Contributor guide
Assessment
This issue has not been assessed yet.