hybrid-navigation 4.0.1 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -294,29 +294,7 @@
294
294
  return (UINavigationController *)vc;
295
295
  }
296
296
 
297
- UINavigationController *nav = vc.navigationController;
298
- if (nav) {
299
- return nav;
300
- }
301
-
302
- HBDDrawerController *drawer = vc.drawerController;
303
- if (!drawer) {
304
- return nil;
305
- }
306
-
307
- if ([drawer.contentController isKindOfClass:[UITabBarController class]]) {
308
- UITabBarController *tabs = (UITabBarController *)drawer.contentController;
309
- if ([tabs.selectedViewController isKindOfClass:[UINavigationController class]]) {
310
- return (UINavigationController *)tabs.selectedViewController;
311
- }
312
- return nil;
313
- }
314
-
315
- if ([drawer.contentController isKindOfClass:[UINavigationController class]]) {
316
- return (UINavigationController *)drawer.contentController;
317
- }
318
-
319
- return drawer.contentController.navigationController;
297
+ return vc.navigationController;
320
298
  }
321
299
 
322
300
  - (void)invalidate {
@@ -107,6 +107,11 @@
107
107
 
108
108
  - (void)isStackRoot:(nonnull NSString *)sceneId callback:(nonnull RCTResponseSenderBlock)callback {
109
109
  UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
110
+ if (!vc) {
111
+ callback(@[NSNull.null, @NO]);
112
+ return;
113
+ }
114
+
110
115
  UINavigationController *nav = vc.navigationController;
111
116
  if (!nav) {
112
117
  callback(@[NSNull.null, @NO]);
@@ -120,17 +125,28 @@
120
125
  }
121
126
 
122
127
  UIViewController *root = children[0];
123
- if ([root.sceneId isEqualToString:sceneId]) {
128
+ if ([self viewController:vc hasAncestorOrSelf:root]) {
124
129
  callback(@[NSNull.null, @YES]);
125
130
  return;
126
131
  }
127
132
 
128
- if (children.count == 1 && [root isKindOfClass:[UITabBarController class]]) {
129
- callback(@[NSNull.null, @YES]);
130
- return;
133
+ callback(@[NSNull.null, @NO]);
134
+ }
135
+
136
+ - (BOOL)viewController:(UIViewController *)viewController hasAncestorOrSelf:(UIViewController *)ancestor {
137
+ if (!viewController || !ancestor) {
138
+ return NO;
131
139
  }
132
140
 
133
- callback(@[NSNull.null, @NO]);
141
+ NSMutableSet<UIViewController *> *visited = [NSMutableSet set];
142
+ for (UIViewController *current = viewController; current != nil && ![visited containsObject:current]; current = current.parentViewController) {
143
+ if (current == ancestor) {
144
+ return YES;
145
+ }
146
+ [visited addObject:current];
147
+ }
148
+
149
+ return NO;
134
150
  }
135
151
 
136
152
  - (void)dispatch:(nonnull NSString *)sceneId action:(nonnull NSString *)action params:(nonnull NSDictionary *)params callback:(nonnull RCTResponseSenderBlock)callback {