Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with scrollGesturesEnabledDuringRotateOrZoom = false and rotationGesturesEnabled = false #503

Open
jeffphp opened this issue Jan 6, 2024 · 1 comment
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@jeffphp
Copy link

jeffphp commented Jan 6, 2024

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 : #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()
        }
    }
}

}

@jeffphp jeffphp added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 6, 2024
@cghitathefork
Copy link

We're also facing this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants