Skip to content

Commit

Permalink
Merge branch 'feature/directions' into develop
Browse files Browse the repository at this point in the history
* feature/directions:
  Removes babelrc file
  Adds openCalloutInMaps function to MapMarker
  Requests location access permissions based on info.plist file
  • Loading branch information
Tim Matthews committed Apr 6, 2017
2 parents af4b54e + 6ad6989 commit 531ed82
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
14 changes: 0 additions & 14 deletions .babelrc

This file was deleted.

8 changes: 8 additions & 0 deletions lib/components/MapMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ class MapMarker extends React.Component {
this._runCommand('hideCallout', []);
}

openCalloutInMaps() {
if (Platform.OS === "ios") {
this._runCommand('openCalloutInMaps', []);
} else {
console.log("openCalloutInMaps is not yet supported on Android");
}
}

_getHandle() {
return findNodeHandle(this.marker);
}
Expand Down
8 changes: 7 additions & 1 deletion lib/ios/AirMaps/AIRMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ - (void)setShowsUserLocation:(BOOL)showsUserLocation
if (self.showsUserLocation != showsUserLocation) {
if (showsUserLocation && !_locationManager) {
_locationManager = [CLLocationManager new];
if ([_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {

// Request location access permission
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"] &&
[_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[_locationManager requestAlwaysAuthorization];
} else if ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] &&
[_locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[_locationManager requestWhenInUseAuthorization];
}
}
Expand Down
19 changes: 17 additions & 2 deletions lib/ios/AirMaps/AIRMapMarkerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ - (UIView *)view
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
id view = viewRegistry[reactTag];
if (![view isKindOfClass:[AIRMapMarker class]]) {
RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
RCTLogError(@"Invalid view returned from registry, expecting AIRMapMarker, got: %@", view);
} else {
[(AIRMapMarker *) view showCalloutView];
}
Expand All @@ -69,11 +69,26 @@ - (UIView *)view
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
id view = viewRegistry[reactTag];
if (![view isKindOfClass:[AIRMapMarker class]]) {
RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
RCTLogError(@"Invalid view returned from registry, expecting AIRMapMarker, got: %@", view);
} else {
[(AIRMapMarker *) view hideCalloutView];
}
}];
}

RCT_EXPORT_METHOD(openCalloutInMaps:(nonnull NSNumber *)reactTag)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
id view = viewRegistry[reactTag];
if (![view isKindOfClass:[AIRMapMarker class]]) {
RCTLogError(@"Invalid view returned from registry, expecting AIRMapMarker, got: %@", view);
} else {
AIRMapMarker *marker = (AIRMapMarker *)view;
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:marker.coordinate]];
mapItem.name = marker.title;
[MKMapItem openMapsWithItems:@[mapItem] launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDefault}];
}
}];
}

@end

0 comments on commit 531ed82

Please sign in to comment.