Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Add isLayerReady check before adding compass.
Browse files Browse the repository at this point in the history
  • Loading branch information
pengdev committed Oct 22, 2019
1 parent db02638 commit 87b1e16
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ private void updateCompassListenerState(boolean canListen) {
return;
}

if (!isComponentInitialized || !isComponentStarted || !isEnabled) {
if (!isComponentInitialized || !isComponentStarted || !isEnabled || !isLayerReady) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,24 @@ class LocationComponentTest {
verify(compassEngine, never()).addCompassListener(any(CompassListener::class.java))
}

@Test
fun compass_notAddListenerWhenLayerNotReady() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
locationComponent.isLocationComponentEnabled = true
locationComponent.onStart()
`when`(locationLayerController.isConsumingCompass).thenReturn(true)

locationComponent.onStartLoadingMap()
// Layer should be disabled at this point
locationComponent.setCameraMode(CameraMode.TRACKING)
verify(compassEngine, never()).addCompassListener(any(CompassListener::class.java))

locationComponent.onFinishLoadingStyle()
// Layer should be enabled at this point
locationComponent.setCameraMode(CameraMode.TRACKING_GPS)
verify(compassEngine).addCompassListener(any(CompassListener::class.java))
}

@Test
fun developerAnimationCalled() {
locationComponent.activateLocationComponent(context, mock(Style::class.java), locationEngine, locationEngineRequest, locationComponentOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,10 @@ private void toggleMapStyle() {
return;
}

String styleUrl = Style.DARK.equals(mapboxMap.getStyle().getUri()) ? Style.LIGHT : Style.DARK;
mapboxMap.setStyle(new Style.Builder().fromUri(styleUrl));
mapboxMap.getStyle(style -> {
String styleUrl = Style.DARK.equals(style.getUri()) ? Style.LIGHT : Style.DARK;
mapboxMap.setStyle(new Style.Builder().fromUri(styleUrl));
});
}

private void disableGesturesManagement() {
Expand Down

0 comments on commit 87b1e16

Please sign in to comment.