Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kiryldz committed Aug 15, 2022
1 parent f585696 commit d7bf2f9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 30 deletions.
Expand Up @@ -27,7 +27,7 @@ private val emptyCancelable = Cancelable { }
* @param cameraOptions The camera options to ease to
* @param animationOptions Transition options (animation duration, listeners etc)
*
* @return [Cancelable] animator set object or empty cancelable object if associated map object was garbage collected.
* @return [Cancelable] animator set object or empty cancelable object if associated `MapView` was destroyed.
*/
@JvmOverloads
fun MapPluginExtensionsDelegate.easeTo(
Expand All @@ -45,7 +45,7 @@ fun MapPluginExtensionsDelegate.easeTo(
* @param cameraOptions The camera options to fly to
* @param animationOptions Transition options (animation duration, listeners etc)
*
* @return [Cancelable] animator set object or empty cancelable object if associated map object was garbage collected.
* @return [Cancelable] animator set object or empty cancelable object if associated `MapView` was destroyed.
*/
@JvmOverloads
fun MapPluginExtensionsDelegate.flyTo(
Expand All @@ -63,7 +63,7 @@ fun MapPluginExtensionsDelegate.flyTo(
* @param pitch The amount to pitch by
* @param animationOptions Transition options (animation duration, listeners etc)
*
* @return [Cancelable] animator set object or empty cancelable object if associated map object was garbage collected.
* @return [Cancelable] animator set object or empty cancelable object if associated `MapView` was destroyed.
*/
@JvmOverloads
fun MapPluginExtensionsDelegate.pitchBy(
Expand All @@ -82,7 +82,7 @@ fun MapPluginExtensionsDelegate.pitchBy(
* @param screenCoordinate The optional focal point to scale on
* @param animationOptions Transition options (animation duration, listeners etc)
*
* @return [Cancelable] animator set object or empty cancelable object if associated map object was garbage collected.
* @return [Cancelable] animator set object or empty cancelable object if associated `MapView` was destroyed.
*/
@JvmOverloads
fun MapPluginExtensionsDelegate.scaleBy(
Expand All @@ -101,7 +101,7 @@ fun MapPluginExtensionsDelegate.scaleBy(
* @param screenCoordinate The screen coordinate distance to move by
* @param animationOptions Transition options (animation duration, listeners etc)
*
* @return [Cancelable] animator set object or empty cancelable object if associated map object was garbage collected.
* @return [Cancelable] animator set object or empty cancelable object if associated `MapView` was destroyed.
*/
@JvmOverloads
fun MapPluginExtensionsDelegate.moveBy(
Expand All @@ -120,7 +120,7 @@ fun MapPluginExtensionsDelegate.moveBy(
* @param second The second pointer to rotate on
* @param animationOptions Transition options (animation duration, listeners etc)
*
* @return [Cancelable] animator set object or empty cancelable object if associated map object was garbage collected.
* @return [Cancelable] animator set object or empty cancelable object if associated `MapView` was destroyed.
*/
@JvmOverloads
fun MapPluginExtensionsDelegate.rotateBy(
Expand Down
2 changes: 0 additions & 2 deletions sdk/src/main/java/com/mapbox/maps/MapController.kt
Expand Up @@ -169,8 +169,6 @@ internal class MapController : MapPluginProviderDelegate, MapControllable {
return
}
lifecycleState = LifecycleState.STATE_DESTROYED
mapboxMap.setCameraAnimationPlugin(null)
mapboxMap.setGesturesAnimationPlugin(null)
pluginRegistry.onDestroy()
nativeObserver.onDestroy()
renderer.onDestroy()
Expand Down
10 changes: 6 additions & 4 deletions sdk/src/main/java/com/mapbox/maps/MapboxMap.kt
Expand Up @@ -1697,8 +1697,8 @@ class MapboxMap :
return nativeMap.getDragCameraOptions(fromPoint, toPoint)
}

internal fun setCameraAnimationPlugin(cameraAnimationsPlugin: CameraAnimationsPlugin?) {
if (cameraAnimationsPlugin == null || cameraAnimationsPlugin is CameraAnimationsPluginImpl) {
internal fun setCameraAnimationPlugin(cameraAnimationsPlugin: CameraAnimationsPlugin) {
if (cameraAnimationsPlugin is CameraAnimationsPluginImpl) {
this.cameraAnimationsPlugin = cameraAnimationsPlugin
} else {
logW(TAG, "MapboxMap camera extension functions could work only with Mapbox developed plugin!")
Expand All @@ -1721,8 +1721,8 @@ class MapboxMap :
return null
}

internal fun setGesturesAnimationPlugin(gesturesPlugin: GesturesPlugin?) {
if (gesturesPlugin == null || gesturesPlugin is GesturesPluginImpl) {
internal fun setGesturesAnimationPlugin(gesturesPlugin: GesturesPlugin) {
if (gesturesPlugin is GesturesPluginImpl) {
this.gesturesPlugin = gesturesPlugin
} else {
logW(TAG, "MapboxMap gestures extension functions could work only with Mapbox developed plugin!")
Expand All @@ -1746,6 +1746,8 @@ class MapboxMap :
}

internal fun onDestroy() {
cameraAnimationsPlugin = null
gesturesPlugin = null
observers.forEach {
nativeMap.unsubscribe(it)
}
Expand Down
4 changes: 0 additions & 4 deletions sdk/src/test/java/com/mapbox/maps/MapControllerTest.kt
Expand Up @@ -165,14 +165,10 @@ class MapControllerTest {
every { mockPluginRegistry.onDestroy() } just Runs
every { mockNativeObserver.onDestroy() } just Runs
every { mockRenderer.onDestroy() } just Runs
every { mockMapboxMap.setCameraAnimationPlugin(any()) } just Runs
every { mockMapboxMap.setGesturesAnimationPlugin(any()) } just Runs

testMapController.onDestroy()

verifySequence {
mockMapboxMap.setCameraAnimationPlugin(null)
mockMapboxMap.setGesturesAnimationPlugin(null)
mockPluginRegistry.onDestroy()
mockNativeObserver.onDestroy()
mockRenderer.onDestroy()
Expand Down
23 changes: 9 additions & 14 deletions sdk/src/test/java/com/mapbox/maps/MapboxMapTest.kt
Expand Up @@ -55,6 +55,15 @@ class MapboxMapTest {
assertFalse(mapboxMap.isValid())
}

@Test
fun onDestroyWithPlugins() {
mapboxMap.cameraAnimationsPlugin = mockk<CameraAnimationsPluginImpl>()
mapboxMap.gesturesPlugin = mockk<GesturesPluginImpl>()
mapboxMap.onDestroy()
assertTrue(mapboxMap.cameraAnimationsPlugin == null)
assertTrue(mapboxMap.gesturesPlugin == null)
}

@Test
fun loadStyleUri() {
Shadows.shadowOf(Looper.getMainLooper()).pause()
Expand Down Expand Up @@ -976,13 +985,6 @@ class MapboxMapTest {
unmockkStatic("com.mapbox.maps.MapboxLogger")
}

@Test
fun setCameraAnimationsPluginNull() {
mapboxMap.setCameraAnimationPlugin(mockk<CameraAnimationsPluginImpl>())
mapboxMap.setCameraAnimationPlugin(null)
assertNull(mapboxMap.cameraAnimationsPlugin)
}

@Test
fun setGesturesPluginInvalid() {
mockkStatic("com.mapbox.maps.MapboxLogger")
Expand All @@ -992,13 +994,6 @@ class MapboxMapTest {
unmockkStatic("com.mapbox.maps.MapboxLogger")
}

@Test
fun setGesturesPluginNull() {
mapboxMap.setGesturesAnimationPlugin(mockk<GesturesPluginImpl>())
mapboxMap.setGesturesAnimationPlugin(null)
assertNull(mapboxMap.gesturesPlugin)
}

@Test
fun cameraAnimationsPluginValid() {
val animations = mockk<CameraAnimationsPlugin>(relaxed = true)
Expand Down

0 comments on commit d7bf2f9

Please sign in to comment.