Skip to content

Commit

Permalink
Merge pull request #22 from googlemaps/arsalaza/fix-ios-issue
Browse files Browse the repository at this point in the history
fix: address crash on single destination navigation due to invalid waypoint
  • Loading branch information
ArturoSalazarB16 authored Feb 14, 2024
2 parents d7b79ed + 25e3c89 commit b355193
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ export const getNavigationViewController = (
return {
setDestination: (waypoint: Waypoint, routingOptions?: RoutingOptions) => {
let args: object[] = [];
args.push(waypoint);
args.push([waypoint]);

if (routingOptions != null) {
args.push(routingOptions);
}

sendCommand(viewId, commands.setDestination, args);
sendCommand(viewId, commands.setDestinations, args);
},
setDestinations: (
waypoints: Waypoint[],
Expand Down
26 changes: 15 additions & 11 deletions ios/react-native-navigation-sdk/NavViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -201,25 +201,29 @@ - (void)setDestinations:(NSArray *)waypoints
destinations = [[NSMutableArray alloc] init];

for (NSDictionary *wp in waypoints) {
NSString *placeId = @"";
GMSNavigationMutableWaypoint *w;

placeId = wp[@"placeId"];
NSString *placeId = wp[@"placeId"];

if ([placeId isEqual:@""] && wp[@"position"] != nil) {
if (placeId && ![placeId isEqual:@""]) {
w = [[GMSNavigationMutableWaypoint alloc] initWithPlaceID:placeId title:wp[@"title"]];
} else if (wp[@"position"]) {
w = [[GMSNavigationMutableWaypoint alloc]
initWithLocation:[ObjectTranslationUtil getLocationCoordinateFrom:wp[@"position"]]
title:wp[@"title"]
preferSameSideOfRoad:wp[@"preferSameSideOfRoad"]];
w.vehicleStopover = wp[@"vehicleStopover"];
initWithLocation:[ObjectTranslationUtil getLocationCoordinateFrom:wp[@"position"]]
title:wp[@"title"]];
} else {
// The validation will be done on the client, so just ignore this waypoint here.
continue;
}

if (![placeId isEqual:@""]) {
w = [[GMSNavigationMutableWaypoint alloc] initWithPlaceID:placeId title:wp[@"title"]];
w.vehicleStopover = wp[@"vehicleStopover"];
w.preferSameSideOfRoad = wp[@"preferSameSideOfRoad"];
if (wp[@"preferSameSideOfRoad"] != nil) {
w.preferSameSideOfRoad = [wp[@"preferSameSideOfRoad"] boolValue];
}

if (wp[@"vehicleStopover"] != nil) {
w.vehicleStopover = [wp[@"vehicleStopover"] boolValue];
}

if (wp[@"preferredHeading"] != nil) {
w.preferredHeading = [wp[@"preferredHeading"] intValue];
}
Expand Down
8 changes: 0 additions & 8 deletions ios/react-native-navigation-sdk/RCTNavViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,6 @@ + (BOOL)requiresMainQueueSetup {
});
}

RCT_EXPORT_METHOD(setDestination: (nonnull NSNumber *)reactTag
waypoints: (nonnull NSArray *)waypoints
routingOptions: (NSDictionary *)routingOptions) {
dispatch_async(dispatch_get_main_queue(), ^{
[viewController setDestinations:waypoints withRoutingOptions: routingOptions];
});
}

RCT_EXPORT_METHOD(setDestinations: (nonnull NSNumber *)reactTag
waypoints: (nonnull NSArray *)waypoints
routingOptions: (NSDictionary *)routingOptions) {
Expand Down

0 comments on commit b355193

Please sign in to comment.