Skip to content

Commit b355193

Browse files
Merge pull request #22 from googlemaps/arsalaza/fix-ios-issue
fix: address crash on single destination navigation due to invalid waypoint
2 parents d7b79ed + 25e3c89 commit b355193

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

components/navigation/navigationView/navigationViewController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ export const getNavigationViewController = (
3333
return {
3434
setDestination: (waypoint: Waypoint, routingOptions?: RoutingOptions) => {
3535
let args: object[] = [];
36-
args.push(waypoint);
36+
args.push([waypoint]);
3737

3838
if (routingOptions != null) {
3939
args.push(routingOptions);
4040
}
4141

42-
sendCommand(viewId, commands.setDestination, args);
42+
sendCommand(viewId, commands.setDestinations, args);
4343
},
4444
setDestinations: (
4545
waypoints: Waypoint[],

ios/react-native-navigation-sdk/NavViewController.m

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,25 +201,29 @@ - (void)setDestinations:(NSArray *)waypoints
201201
destinations = [[NSMutableArray alloc] init];
202202

203203
for (NSDictionary *wp in waypoints) {
204-
NSString *placeId = @"";
205204
GMSNavigationMutableWaypoint *w;
206205

207-
placeId = wp[@"placeId"];
206+
NSString *placeId = wp[@"placeId"];
208207

209-
if ([placeId isEqual:@""] && wp[@"position"] != nil) {
208+
if (placeId && ![placeId isEqual:@""]) {
209+
w = [[GMSNavigationMutableWaypoint alloc] initWithPlaceID:placeId title:wp[@"title"]];
210+
} else if (wp[@"position"]) {
210211
w = [[GMSNavigationMutableWaypoint alloc]
211-
initWithLocation:[ObjectTranslationUtil getLocationCoordinateFrom:wp[@"position"]]
212-
title:wp[@"title"]
213-
preferSameSideOfRoad:wp[@"preferSameSideOfRoad"]];
214-
w.vehicleStopover = wp[@"vehicleStopover"];
212+
initWithLocation:[ObjectTranslationUtil getLocationCoordinateFrom:wp[@"position"]]
213+
title:wp[@"title"]];
214+
} else {
215+
// The validation will be done on the client, so just ignore this waypoint here.
216+
continue;
215217
}
216218

217-
if (![placeId isEqual:@""]) {
218-
w = [[GMSNavigationMutableWaypoint alloc] initWithPlaceID:placeId title:wp[@"title"]];
219-
w.vehicleStopover = wp[@"vehicleStopover"];
220-
w.preferSameSideOfRoad = wp[@"preferSameSideOfRoad"];
219+
if (wp[@"preferSameSideOfRoad"] != nil) {
220+
w.preferSameSideOfRoad = [wp[@"preferSameSideOfRoad"] boolValue];
221221
}
222222

223+
if (wp[@"vehicleStopover"] != nil) {
224+
w.vehicleStopover = [wp[@"vehicleStopover"] boolValue];
225+
}
226+
223227
if (wp[@"preferredHeading"] != nil) {
224228
w.preferredHeading = [wp[@"preferredHeading"] intValue];
225229
}

ios/react-native-navigation-sdk/RCTNavViewManager.m

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,6 @@ + (BOOL)requiresMainQueueSetup {
250250
});
251251
}
252252

253-
RCT_EXPORT_METHOD(setDestination: (nonnull NSNumber *)reactTag
254-
waypoints: (nonnull NSArray *)waypoints
255-
routingOptions: (NSDictionary *)routingOptions) {
256-
dispatch_async(dispatch_get_main_queue(), ^{
257-
[viewController setDestinations:waypoints withRoutingOptions: routingOptions];
258-
});
259-
}
260-
261253
RCT_EXPORT_METHOD(setDestinations: (nonnull NSNumber *)reactTag
262254
waypoints: (nonnull NSArray *)waypoints
263255
routingOptions: (NSDictionary *)routingOptions) {

0 commit comments

Comments
 (0)