diff --git a/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java b/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java index 01fabe358..1c74dfcec 100644 --- a/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java +++ b/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java @@ -591,13 +591,13 @@ public boolean dispatchTouchEvent(MotionEvent ev) { // Timer Implementation public void startMonitoringRegion() { - if (isMonitoringRegion) return; + if (this.map == null || isMonitoringRegion) return; timerHandler.postDelayed(timerRunnable, 100); isMonitoringRegion = true; } public void stopMonitoringRegion() { - if (!isMonitoringRegion) return; + if (this.map == null || !isMonitoringRegion) return; timerHandler.removeCallbacks(timerRunnable); isMonitoringRegion = false; } diff --git a/components/MapView.js b/components/MapView.js index a7762665d..2cb76b445 100644 --- a/components/MapView.js +++ b/components/MapView.js @@ -284,6 +284,11 @@ const propTypes = { */ legalLabelInsets: EdgeInsetsPropType, + /** + * Callback that is called once the map is fully loaded. + */ + onMapReady: PropTypes.func, + /** * Callback that is called continuously when the user is dragging the map. */ @@ -394,13 +399,15 @@ class MapView extends React.Component { } _onMapReady() { - const { region, initialRegion } = this.props; + const { region, initialRegion, onMapReady } = this.props; if (region) { this.map.setNativeProps({ region }); } else if (initialRegion) { this.map.setNativeProps({ region: initialRegion }); } - this.setState({ isReady: true }); + this.setState({ isReady: true }, () => { + if (onMapReady) onMapReady(); + }); } _onLayout(e) { diff --git a/docs/mapview.md b/docs/mapview.md index c3e5e0bea..a5c1e3d9c 100644 --- a/docs/mapview.md +++ b/docs/mapview.md @@ -34,8 +34,9 @@ | Event Name | Returns | Notes |---|---|---| -| `onRegionChange` | `Region` | Callback that is called continuously when the user is dragging the map. -| `onRegionChangeComplete` | `Region` | Callback that is called once, when the user is done moving the map. +| `onMapReady` | | Callback that is called once the map is fully loaded. +| `onRegionChange` | `Region` | Callback that is called continuously when the region changes, such as when a user is dragging the map. +| `onRegionChangeComplete` | `Region` | Callback that is called once when the region changes, such as when the user is done moving the map. | `onPress` | `{ coordinate: LatLng, position: Point }` | Callback that is called when user taps on the map. | `onPanDrag` | `{ coordinate: LatLng, position: Point }` | Callback that is called when user presses and drags the map. **NOTE**: for iOS `scrollEnabled` should be set to false to trigger the event | `onLongPress` | `{ coordinate: LatLng, position: Point }` | Callback that is called when user makes a "long press" somewhere on the map. diff --git a/ios/AirGoogleMaps/AIRGoogleMap.h b/ios/AirGoogleMaps/AIRGoogleMap.h index 10a4f1f65..da2885bed 100644 --- a/ios/AirGoogleMaps/AIRGoogleMap.h +++ b/ios/AirGoogleMaps/AIRGoogleMap.h @@ -34,6 +34,7 @@ @property (nonatomic, assign) BOOL pitchEnabled; @property (nonatomic, assign) BOOL showsUserLocation; +- (void)didFinishTileRendering; - (BOOL)didTapMarker:(GMSMarker *)marker; - (void)didTapAtCoordinate:(CLLocationCoordinate2D)coordinate; - (void)didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate; diff --git a/ios/AirGoogleMaps/AIRGoogleMapManager.m b/ios/AirGoogleMaps/AIRGoogleMapManager.m index 988e78d81..904e7e21e 100644 --- a/ios/AirGoogleMaps/AIRGoogleMapManager.m +++ b/ios/AirGoogleMaps/AIRGoogleMapManager.m @@ -55,6 +55,7 @@ - (UIView *)view RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(pitchEnabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsUserLocation, BOOL) +RCT_EXPORT_VIEW_PROPERTY(onMapReady, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock) @@ -177,6 +178,11 @@ - (UIView *)view } +- (void)mapViewDidFinishTileRendering:(GMSMapView *)mapView { + AIRGoogleMap *googleMapView = (AIRGoogleMap *)mapView; + [googleMapView didFinishTileRendering]; +} + - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker { AIRGoogleMap *googleMapView = (AIRGoogleMap *)mapView; return [googleMapView didTapMarker:marker];