@@ -118,14 +118,18 @@ - (void)mergeOptions:(NSString *)componentId
118118
119119 UIViewController<RNNLayoutProtocol> *vc = [_layoutManager findComponentForId: componentId];
120120 RNNNavigationOptions *newOptions = [[RNNNavigationOptions alloc ] initWithDict: mergeOptions];
121- if ([vc conformsToProtocol: @protocol (RNNLayoutProtocol)] ||
122- [vc isKindOfClass: [RNNComponentViewController class ]]) {
121+ if (vc && ( [vc conformsToProtocol: @protocol (RNNLayoutProtocol)] ||
122+ [vc isKindOfClass: [RNNComponentViewController class ]]) ) {
123123 [CATransaction begin ];
124124 [CATransaction setCompletionBlock: completion];
125125
126126 [vc mergeOptions: newOptions];
127127
128128 [CATransaction commit ];
129+ } else {
130+ if (completion) {
131+ completion ();
132+ }
129133 }
130134}
131135
@@ -324,10 +328,10 @@ - (void)popTo:(NSString *)componentId
324328
325329 RNNComponentViewController *vc =
326330 (RNNComponentViewController *)[_layoutManager findComponentForId: componentId];
327- RNNNavigationOptions *options = [[RNNNavigationOptions alloc ] initWithDict: mergeOptions];
328- [vc mergeOptions: options];
329-
330331 if (vc) {
332+ RNNNavigationOptions *options = [[RNNNavigationOptions alloc ] initWithDict: mergeOptions];
333+ [vc mergeOptions: options];
334+
331335 [vc.stack popTo: vc
332336 animated: [vc.resolveOptionsWithDefault.animations.pop.enable withDefault: YES ]
333337 completion: ^(NSArray *poppedViewControllers) {
@@ -355,25 +359,27 @@ - (void)popToRoot:(NSString *)componentId
355359
356360 RNNComponentViewController *vc =
357361 (RNNComponentViewController *)[_layoutManager findComponentForId: componentId];
358- RNNNavigationOptions *options = [[RNNNavigationOptions alloc ] initWithDict: mergeOptions];
359- [vc mergeOptions: options];
360-
361- [CATransaction begin ];
362- [CATransaction setCompletionBlock: ^{
363- [self ->_eventEmitter sendOnNavigationCommandCompletion: popToRoot commandId: commandId];
364- completion ();
365- }];
366-
367- [vc.stack popToRoot: vc
368- animated: [vc.resolveOptionsWithDefault.animations.pop.enable withDefault: YES ]
369- completion: ^(NSArray *poppedViewControllers) {
370-
371- }
372- rejection: ^(NSString *code, NSString *message, NSError *error){
373-
374- }];
362+ if (vc) {
363+ RNNNavigationOptions *options = [[RNNNavigationOptions alloc ] initWithDict: mergeOptions];
364+ [vc mergeOptions: options];
375365
376- [CATransaction commit ];
366+ [vc.stack popToRoot: vc
367+ animated: [vc.resolveOptionsWithDefault.animations.pop.enable withDefault: YES ]
368+ completion: ^(NSArray *poppedViewControllers) {
369+ [self ->_eventEmitter sendOnNavigationCommandCompletion: popToRoot
370+ commandId: commandId];
371+ completion ();
372+ }
373+ rejection: rejection];
374+ } else {
375+ [RNNErrorHandler
376+ reject: rejection
377+ withErrorCode: 1012
378+ errorDescription:
379+ [NSString stringWithFormat:
380+ @" PopToRoot component failed - componentId '%@ ' not found" ,
381+ componentId]];
382+ }
377383}
378384
379385- (void )showModal : (NSDictionary *)layout
0 commit comments