From 3621eb181ba0f0997077b70729db55bf119df20b Mon Sep 17 00:00:00 2001 From: Marius Petcu Date: Sat, 2 Jul 2016 23:15:37 +0300 Subject: [PATCH] Pass animation status in onRegion*Change --- API.md | 4 ++-- .../ReactNativeMapboxGLView.java | 14 +++++++++----- ios/RCTMapboxGL/RCTMapboxGL.m | 6 ++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/API.md b/API.md index e757f6c..a03c2e7 100644 --- a/API.md +++ b/API.md @@ -52,8 +52,8 @@ import { MapView } from 'react-native-mapbox-gl'; | Prop | Payload shape | Description |---|---|---| -| `onRegionWillChange` | `{latitude: 0, longitude: 0, zoomLevel: 0, direction: 0, pitch: 0}` | Fired when the map begins panning or zooming. -| `onRegionDidChange` | `{latitude: 0, longitude: 0, zoomLevel: 0, direction: 0, pitch: 0}` | Fired when the map ends panning or zooming. +| `onRegionWillChange` | `{latitude: 0, longitude: 0, zoomLevel: 0, direction: 0, pitch: 0, animated: false}` | Fired when the map begins panning or zooming. `animated` indicates whether the action is user-driven or animation-driven. +| `onRegionDidChange` | `{latitude: 0, longitude: 0, zoomLevel: 0, direction: 0, pitch: 0, animated: false}` | Fired when the map ends panning or zooming. | `onOpenAnnotation` | `{id: 'marker_id', title: null, subtitle: null, latitude: 0, longitude: 0}` | Fired when tapping an annotation. | `onRightAnnotationTapped` | `{id: 'marker_id', title: null, subtitle: null, latitude: 0, longitude: 0}` | Fired when user taps the `rightCalloutAccessory` of an annotation. | `onChangeUserTrackingMode` | `Mapbox.userTrackingMode.none` | Fired when the user tracking mode gets changed by an user pan or rotate. diff --git a/android/src/main/java/com/mapbox/reactnativemapboxgl/ReactNativeMapboxGLView.java b/android/src/main/java/com/mapbox/reactnativemapboxgl/ReactNativeMapboxGLView.java index a0c2a00..0b4f660 100644 --- a/android/src/main/java/com/mapbox/reactnativemapboxgl/ReactNativeMapboxGLView.java +++ b/android/src/main/java/com/mapbox/reactnativemapboxgl/ReactNativeMapboxGLView.java @@ -63,6 +63,7 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements private boolean _recentlyChanged = false; private boolean _willChangeThrottled = false; private boolean _didChangeThrottled = false; + private boolean _changeWasAnimated = false; private Map _annotations = new HashMap(); private Map _annotationIdsToName = new HashMap(); @@ -424,7 +425,7 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements _handler.post(new TrackingModeChangeRunnable(this)); } - WritableMap serializeCurrentRegion() { + WritableMap serializeCurrentRegion(boolean animated) { CameraPosition camera = _map == null ? _initialCamera.build() : _map.getCameraPosition(); @@ -436,6 +437,7 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements src.putDouble("zoomLevel", camera.zoom); src.putDouble("direction", camera.bearing); src.putDouble("pitch", camera.tilt); + src.putBoolean("animated", animated); event.putMap("src", src); return event; } @@ -454,10 +456,10 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements private void flushRegionChangedThrottle(boolean fireAgain) { _recentlyChanged = false; if (_willChangeThrottled) { - emitEvent("onRegionWillChange", serializeCurrentRegion()); + emitEvent("onRegionWillChange", serializeCurrentRegion(_changeWasAnimated)); } if (_didChangeThrottled) { - emitEvent("onRegionDidChange", serializeCurrentRegion()); + emitEvent("onRegionDidChange", serializeCurrentRegion(_changeWasAnimated)); } if (fireAgain && _didChangeThrottled) { @@ -475,8 +477,9 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements if (_recentlyChanged) { _willChangeThrottled = true; + _changeWasAnimated = animated; } else { - emitEvent("onRegionWillChange", serializeCurrentRegion()); + emitEvent("onRegionWillChange", serializeCurrentRegion(animated)); } } @@ -487,8 +490,9 @@ public class ReactNativeMapboxGLView extends RelativeLayout implements if (_recentlyChanged) { _didChangeThrottled = true; + _changeWasAnimated = animated; } else { - emitEvent("onRegionDidChange", serializeCurrentRegion()); + emitEvent("onRegionDidChange", serializeCurrentRegion(animated)); _recentlyChanged = true; _handler.postDelayed(new RegionChangedThrottleRunnable(this), 100); } diff --git a/ios/RCTMapboxGL/RCTMapboxGL.m b/ios/RCTMapboxGL/RCTMapboxGL.m index 362c738..d81ba38 100644 --- a/ios/RCTMapboxGL/RCTMapboxGL.m +++ b/ios/RCTMapboxGL/RCTMapboxGL.m @@ -474,7 +474,8 @@ @"longitude": @(region.longitude), @"zoomLevel": @(_map.zoomLevel), @"direction": @(_map.direction), - @"pitch": @(0) } }); + @"pitch": @(0), + @"animated": @(animated) } }); } @@ -488,7 +489,8 @@ @"longitude": @(region.longitude), @"zoomLevel": @(_map.zoomLevel), @"direction": @(_map.direction), - @"pitch": @(0) } }); + @"pitch": @(0), + @"animated": @(animated) } }); } - (void)handleSingleTap:(UITapGestureRecognizer *)sender