Skip to content

Commit

Permalink
added map ready callback
Browse files Browse the repository at this point in the history
  • Loading branch information
freshnewegg committed Jun 15, 2017
1 parent f6cfb36 commit 8e07955
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/components/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ColorPropType,
findNodeHandle,
ViewPropTypes,
View,
} from 'react-native';
import MapMarker from './MapMarker';
import MapPolyline from './MapPolyline';
Expand Down Expand Up @@ -59,7 +60,7 @@ const propTypes = {
* Used to style and layout the `MapView`. See `StyleSheet.js` and
* `ViewStylePropTypes.js` for more info.
*/
style: ViewPropTypes.style,
style: View.propTypes.style,

/**
* A json object that describes the style of the map. This is transformed to a string
Expand Down Expand Up @@ -317,6 +318,12 @@ 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.
*/
Expand Down Expand Up @@ -429,15 +436,17 @@ class MapView extends React.Component {
this.map.setNativeProps({ customMapStyleString: JSON.stringify(customMapStyle) });
}

_onMapReady() {
const { region, initialRegion } = this.props;
_onMapReady(event) {
const { region, initialRegion, onMapReady } = this.props;
if (region) {
this.map.setNativeProps({ region });
} else if (initialRegion) {
this.map.setNativeProps({ region: initialRegion });
}
this._updateStyle();
this.setState({ isReady: true });
this.setState({ isReady: true }, () => {
onMapReady();
});
}

_onLayout(e) {
Expand Down
1 change: 1 addition & 0 deletions lib/ios/AirMaps/AIRMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ extern const CGFloat AIRMapZoomBoundBuffer;
@property (nonatomic, assign) BOOL ignoreRegionChanges;

@property (nonatomic, copy) RCTBubblingEventBlock onChange;
@property (nonatomic, copy) RCTBubblingEventBlock onMapReady;
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
@property (nonatomic, copy) RCTBubblingEventBlock onPanDrag;
@property (nonatomic, copy) RCTBubblingEventBlock onLongPress;
Expand Down
3 changes: 3 additions & 0 deletions lib/ios/AirMaps/AIRMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(legalLabelInsets, UIEdgeInsets)
RCT_EXPORT_VIEW_PROPERTY(mapType, MKMapType)
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onMapReady, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPanDrag, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)
Expand Down Expand Up @@ -651,6 +652,8 @@ - (void)mapViewDidFinishRenderingMap:(AIRMap *)mapView fullyRendered:(BOOL)fully
{
[mapView finishLoading];
[mapView cacheViewIfNeeded];

mapView.onMapReady(@{@"finished": @true});
}

#pragma mark Private
Expand Down

0 comments on commit 8e07955

Please sign in to comment.