hybrid-navigation 2.12.2 → 2.13.0-beta.0

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.
Files changed (75) hide show
  1. package/README.md +63 -0
  2. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +2 -2
  3. package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +1 -0
  4. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +29 -30
  5. package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +2 -3
  6. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +4 -4
  7. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +6 -6
  8. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +24 -33
  9. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +22 -22
  10. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +8 -8
  11. package/ios/HybridNavigation/GlobalStyle.h +0 -8
  12. package/ios/HybridNavigation/GlobalStyle.m +7 -15
  13. package/ios/HybridNavigation/HBDUtils.h +5 -13
  14. package/ios/HybridNavigation/HBDUtils.m +2 -12
  15. package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.h +0 -9
  16. package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.m +91 -67
  17. package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.h +2 -7
  18. package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +28 -26
  19. package/ios/HybridNavigation/Navigator/HBDScreenNavigator.h +0 -9
  20. package/ios/HybridNavigation/Navigator/HBDScreenNavigator.m +127 -99
  21. package/ios/HybridNavigation/Navigator/HBDStackNavigator.h +0 -9
  22. package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +199 -142
  23. package/ios/HybridNavigation/Navigator/HBDTabNavigator.h +0 -9
  24. package/ios/HybridNavigation/Navigator/HBDTabNavigator.m +144 -124
  25. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.h +1 -11
  26. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.m +4 -10
  27. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +5 -0
  28. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +128 -0
  29. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +6 -0
  30. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +237 -0
  31. package/ios/HybridNavigation/ReactBridge/HBDNavigator.h +20 -0
  32. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.h +12 -20
  33. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.m +91 -91
  34. package/ios/HybridNavigation/View/HBDBarButtonItem.h +0 -8
  35. package/ios/HybridNavigation/View/HBDBarButtonItem.m +1 -11
  36. package/ios/HybridNavigation/View/HBDNavigationBar.h +0 -8
  37. package/ios/HybridNavigation/View/HBDNavigationBar.m +13 -20
  38. package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -8
  39. package/ios/HybridNavigation/View/HBDReactTabBar.m +1 -8
  40. package/ios/HybridNavigation/View/HBDRootView.h +0 -9
  41. package/ios/HybridNavigation/View/HBDRootView.m +0 -8
  42. package/ios/HybridNavigation/View/HBDTitleView.h +0 -9
  43. package/ios/HybridNavigation/View/HBDTitleView.m +1 -26
  44. package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -8
  45. package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -7
  46. package/ios/HybridNavigation/ViewController/HBDDrawerController.h +0 -8
  47. package/ios/HybridNavigation/ViewController/HBDDrawerController.m +2 -9
  48. package/ios/HybridNavigation/ViewController/HBDFadeAnimation.h +9 -0
  49. package/ios/HybridNavigation/ViewController/HBDFadeAnimation.m +22 -0
  50. package/ios/HybridNavigation/ViewController/HBDNavigationController.h +0 -8
  51. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +17 -120
  52. package/ios/HybridNavigation/ViewController/HBDPopAnimation.h +0 -7
  53. package/ios/HybridNavigation/ViewController/HBDPopAnimation.m +1 -8
  54. package/ios/HybridNavigation/ViewController/HBDPushAnimation.h +0 -7
  55. package/ios/HybridNavigation/ViewController/HBDPushAnimation.m +1 -8
  56. package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -8
  57. package/ios/HybridNavigation/ViewController/HBDReactViewController.m +59 -26
  58. package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -8
  59. package/ios/HybridNavigation/ViewController/HBDTabBarController.m +12 -9
  60. package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +23 -33
  61. package/ios/HybridNavigation/ViewController/HBDViewController.h +1 -8
  62. package/ios/HybridNavigation/ViewController/HBDViewController.m +6 -23
  63. package/ios/HybridNavigation/ViewController/UINavigationController+HBD.h +0 -8
  64. package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -8
  65. package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +2 -16
  66. package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +32 -46
  67. package/lib/Navigator.d.ts +25 -25
  68. package/lib/Navigator.js +116 -73
  69. package/package.json +4 -5
  70. package/src/Navigator.ts +96 -58
  71. package/ios/HybridNavigation/Bridge/HBDGardenModule.h +0 -14
  72. package/ios/HybridNavigation/Bridge/HBDGardenModule.m +0 -155
  73. package/ios/HybridNavigation/Bridge/HBDNavigationModule.h +0 -15
  74. package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +0 -272
  75. package/ios/HybridNavigation/Navigator/HBDNavigator.h +0 -26
@@ -1,14 +1,8 @@
1
- //
2
- // HBDScreenNavigator.m
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/6/28.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import "HBDScreenNavigator.h"
2
+
10
3
  #import "HBDReactBridgeManager.h"
11
4
  #import "HBDNavigationController.h"
5
+
12
6
  #import <React/RCTLog.h>
13
7
 
14
8
  @implementation HBDScreenNavigator
@@ -21,28 +15,30 @@
21
15
  return @[@"present", @"presentLayout", @"dismiss", @"showModal", @"showModalLayout", @"hideModal"];
22
16
  }
23
17
 
24
- - (UIViewController *)createViewControllerWithLayout:(NSDictionary *)layout {
25
- NSDictionary *screen = layout[self.name];
26
- if (screen) {
27
- NSString *moduleName = screen[@"moduleName"];
28
- NSDictionary *props = screen[@"props"];
29
- NSDictionary *options = screen[@"options"];
30
- return [[HBDReactBridgeManager get] controllerWithModuleName:moduleName props:props options:options];
18
+ - (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
19
+ NSDictionary *model = layout[self.name];
20
+ if (!model) {
21
+ return nil;
31
22
  }
32
- return nil;
23
+
24
+ NSString *moduleName = model[@"moduleName"];
25
+ NSDictionary *props = model[@"props"];
26
+ NSDictionary *options = model[@"options"];
27
+ return [[HBDReactBridgeManager get] viewControllerWithModuleName:moduleName props:props options:options];
33
28
  }
34
29
 
35
- - (NSDictionary *)buildRouteGraphWithViewController:(UIViewController *)vc {
36
- if ([vc isKindOfClass:[HBDViewController class]]) {
37
- HBDViewController *screen = (HBDViewController *) vc;
38
- return @{
39
- @"layout": @"screen",
40
- @"sceneId": screen.sceneId,
41
- @"moduleName": RCTNullIfNil(screen.moduleName),
42
- @"mode": [vc hbd_mode],
43
- };
30
+ - (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
31
+ if (![vc isKindOfClass:[HBDViewController class]]) {
32
+ return nil;
44
33
  }
45
- return nil;
34
+
35
+ HBDViewController *screen = (HBDViewController *) vc;
36
+ return @{
37
+ @"layout": @"screen",
38
+ @"sceneId": screen.sceneId,
39
+ @"moduleName": RCTNullIfNil(screen.moduleName),
40
+ @"mode": [screen hbd_mode],
41
+ };
46
42
  }
47
43
 
48
44
  - (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
@@ -52,88 +48,120 @@
52
48
  return nil;
53
49
  }
54
50
 
55
- - (void)handleNavigationWithViewController:(UIViewController *)target action:(NSString *)action extras:(NSDictionary *)extras resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
56
-
57
- if (!target.hbd_viewAppeared) {
58
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
59
- [self handleNavigationWithViewController:target action:action extras:extras resolver:resolve rejecter:reject];
60
- });
51
+ - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
52
+ if (!vc.hbd_inViewHierarchy) {
53
+ callback(@[NSNull.null, @NO]);
54
+ return;
55
+ }
56
+
57
+ if (!vc.hbd_viewAppeared) {
58
+ [self performSelector:@selector(handleNavigation:) withObject:@{
59
+ @"viewController": vc,
60
+ @"action": action,
61
+ @"extras": extras,
62
+ @"callback": callback,
63
+ } afterDelay:0.05];
61
64
  return;
62
65
  }
63
-
64
- UIViewController *viewController = nil;
65
66
 
66
67
  if ([action isEqualToString:@"present"]) {
67
- viewController = [self createViewControllerWithExtras:extras];
68
- NSInteger requestCode = [extras[@"requestCode"] integerValue];
69
- HBDNavigationController *navVC = [[HBDNavigationController alloc] initWithRootViewController:viewController];
70
- navVC.modalPresentationStyle = UIModalPresentationCurrentContext;
71
- [navVC setRequestCode:requestCode];
72
- [target presentViewController:navVC animated:YES completion:^{
73
- resolve(@(YES));
74
- }];
75
- } else if ([action isEqualToString:@"dismiss"]) {
76
- UIViewController *presenting = target.presentingViewController;
77
- if (presenting) {
78
- [presenting dismissViewControllerAnimated:YES completion:^{
79
- resolve(@(YES));
80
- }];
81
- } else {
82
- [target dismissViewControllerAnimated:YES completion:^{
83
- resolve(@(YES));
84
- }];
85
- }
86
- } else if ([action isEqualToString:@"showModal"]) {
87
- viewController = [self createViewControllerWithExtras:extras];
88
- NSInteger requestCode = [extras[@"requestCode"] integerValue];
89
- viewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
90
- viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
91
- [viewController setRequestCode:requestCode];
92
- [target presentViewController:viewController animated:YES completion:^{
93
- resolve(@(YES));
94
- }];
95
- } else if ([action isEqualToString:@"hideModal"]) {
96
- UIViewController *presenting = target.presentingViewController;
97
- if (presenting) {
98
- [presenting dismissViewControllerAnimated:YES completion:^{
99
- resolve(@(YES));
100
- }];
101
- } else {
102
- [target dismissViewControllerAnimated:YES completion:^{
103
- resolve(@(YES));
104
- }];
105
- }
106
- } else if ([action isEqualToString:@"presentLayout"]) {
107
- NSDictionary *layout = extras[@"layout"];
108
- NSInteger requestCode = [extras[@"requestCode"] integerValue];
109
- viewController = [[HBDReactBridgeManager get] controllerWithLayout:layout];
110
- [viewController setRequestCode:requestCode];
111
- viewController.modalPresentationStyle = UIModalPresentationCurrentContext;
112
- [target presentViewController:viewController animated:YES completion:^{
113
- resolve(@(YES));
114
- }];
115
- } else if ([action isEqualToString:@"showModalLayout"]) {
116
- NSInteger requestCode = [extras[@"requestCode"] integerValue];
117
- NSDictionary *layout = extras[@"layout"];
118
- viewController = [[HBDReactBridgeManager get] controllerWithLayout:layout];
119
- viewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
120
- viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
121
- [viewController setRequestCode:requestCode];
122
- [target presentViewController:viewController animated:YES completion:^{
123
- resolve(@(YES));
124
- }];
68
+ [self handlePresentWithViewController:vc extras:extras callback:callback];
69
+ return;
70
+ }
71
+
72
+ if ([action isEqualToString:@"dismiss"]) {
73
+ [self handleDismissWithViewController:vc callback:callback];
74
+ return;
75
+ }
76
+
77
+ if ([action isEqualToString:@"showModal"]) {
78
+ [self handleShowModalWithViewController:vc extras:extras callback:callback];
79
+ return;
80
+ }
81
+
82
+ if ([action isEqualToString:@"hideModal"]) {
83
+ [self handleDismissWithViewController:vc callback:callback];
84
+ return;
125
85
  }
86
+
87
+ if ([action isEqualToString:@"presentLayout"]) {
88
+ [self handlePresentLayoutWithViewController:vc extras:extras callback:callback];
89
+ return;
90
+ }
91
+
92
+ if ([action isEqualToString:@"showModalLayout"]) {
93
+ [self handleShowModalLayoutWithViewController:vc extras:extras callback:callback];
94
+ return;
95
+ }
96
+ }
97
+
98
+ - (void)handlePresentWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
99
+ UIViewController *vc = [self viewControllerWithExtras:extras];
100
+ NSInteger requestCode = [extras[@"requestCode"] integerValue];
101
+ HBDNavigationController *nav = [[HBDNavigationController alloc] initWithRootViewController:vc];
102
+ nav.modalPresentationStyle = UIModalPresentationCurrentContext;
103
+ [nav setRequestCode:requestCode];
104
+ [presenting presentViewController:nav animated:YES completion:^{
105
+ callback(@[NSNull.null, @YES]);
106
+ }];
107
+ }
108
+
109
+ - (void)handleDismissWithViewController:(UIViewController *) vc callback:(RCTResponseSenderBlock)callback {
110
+ [vc dismissViewControllerAnimated:YES completion:^{
111
+ callback(@[NSNull.null, @YES]);
112
+ }];
113
+ }
114
+
115
+ - (void)handleShowModalWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
116
+ UIViewController *vc = [self viewControllerWithExtras:extras];
117
+ NSInteger requestCode = [extras[@"requestCode"] integerValue];
118
+ vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
119
+ vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
120
+ [vc setRequestCode:requestCode];
121
+ [presenting presentViewController:vc animated:YES completion:^{
122
+ callback(@[NSNull.null, @YES]);
123
+ }];
124
+ }
125
+
126
+ - (void)handlePresentLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
127
+ NSDictionary *layout = extras[@"layout"];
128
+ NSInteger requestCode = [extras[@"requestCode"] integerValue];
129
+ UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
130
+ [vc setRequestCode:requestCode];
131
+ vc.modalPresentationStyle = UIModalPresentationCurrentContext;
132
+ [presenting presentViewController:vc animated:YES completion:^{
133
+ callback(@[NSNull.null, @YES]);
134
+ }];
135
+ }
136
+
137
+ - (void)handleShowModalLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
138
+ NSInteger requestCode = [extras[@"requestCode"] integerValue];
139
+ NSDictionary *layout = extras[@"layout"];
140
+ UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
141
+ vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
142
+ vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
143
+ [vc setRequestCode:requestCode];
144
+ [presenting presentViewController:vc animated:YES completion:^{
145
+ callback(@[NSNull.null, @YES]);
146
+ }];
126
147
  }
127
148
 
128
- - (UIViewController *)createViewControllerWithExtras:(NSDictionary *)extras {
149
+ - (UIViewController *)viewControllerWithExtras:(NSDictionary *)extras {
129
150
  NSString *moduleName = extras[@"moduleName"];
130
- HBDViewController *viewController = nil;
131
- if (moduleName) {
132
- NSDictionary *props = extras[@"props"];
133
- NSDictionary *options = extras[@"options"];
134
- viewController = [[HBDReactBridgeManager get] controllerWithModuleName:moduleName props:props options:options];
151
+ if (!moduleName) {
152
+ return nil;
135
153
  }
136
- return viewController;
154
+ NSDictionary *props = extras[@"props"];
155
+ NSDictionary *options = extras[@"options"];
156
+ return [[HBDReactBridgeManager get] viewControllerWithModuleName:moduleName props:props options:options];
157
+ }
158
+
159
+ -(void)handleNavigation:(NSDictionary *)params {
160
+ [self handleNavigationWithViewController:params[@"viewController"] action:params[@"action"] extras:params[@"extras"] callback:params[@"callback"]];
161
+ }
162
+
163
+ - (void)invalidate {
164
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
137
165
  }
138
166
 
139
167
  @end
@@ -1,12 +1,3 @@
1
- //
2
- // HBDStackNavigator.h
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/6/28.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
- #import <Foundation/Foundation.h>
10
1
  #import "HBDNavigator.h"
11
2
 
12
3
  @interface HBDStackNavigator : NSObject <HBDNavigator>
@@ -1,12 +1,5 @@
1
- //
2
- // HBDStackNavigator.m
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/6/28.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import "HBDStackNavigator.h"
2
+
10
3
  #import "HBDReactBridgeManager.h"
11
4
  #import "HBDNavigationController.h"
12
5
  #import "UINavigationController+HBD.h"
@@ -21,177 +14,241 @@
21
14
  return @[@"push", @"pushLayout", @"pop", @"popTo", @"popToRoot", @"redirectTo"];
22
15
  }
23
16
 
24
- - (UIViewController *)createViewControllerWithLayout:(NSDictionary *)layout {
25
- NSDictionary *stack = layout[self.name];
26
- if (stack) {
27
- NSArray *children = stack[@"children"];
28
- UIViewController *root = [[HBDReactBridgeManager get] controllerWithLayout:children.firstObject];
29
- if (root) {
30
- return [[HBDNavigationController alloc] initWithRootViewController:root];
31
- }
17
+ - (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
18
+ NSDictionary *model = layout[self.name];
19
+ if (!model) {
20
+ return nil;
32
21
  }
33
- return nil;
22
+
23
+ NSArray *children = model[@"children"];
24
+ UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:children.firstObject];
25
+ return [[HBDNavigationController alloc] initWithRootViewController:vc];
34
26
  }
35
27
 
36
- - (NSDictionary *)buildRouteGraphWithViewController:(UIViewController *)vc {
37
- if ([vc isKindOfClass:[HBDNavigationController class]]) {
38
- HBDNavigationController *nav = (HBDNavigationController *) vc;
39
- NSMutableArray *children = [[NSMutableArray alloc] init];
40
- for (NSUInteger i = 0; i < nav.childViewControllers.count; i++) {
41
- UIViewController *child = nav.childViewControllers[i];
42
- NSDictionary *graph = [[HBDReactBridgeManager get] buildRouteGraphWithViewController:child];
43
- [children addObject:graph];
44
- }
45
-
46
- return @{
47
- @"layout": @"stack",
48
- @"sceneId": vc.sceneId,
49
- @"children": children,
50
- @"mode": [vc hbd_mode],
51
- };
28
+ - (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
29
+ if (![vc isKindOfClass:[HBDNavigationController class]]) {
30
+ return nil;
52
31
  }
53
- return nil;
32
+
33
+ HBDNavigationController *nav = (HBDNavigationController *) vc;
34
+
35
+ NSMutableArray *children = [[NSMutableArray alloc] init];
36
+ for (NSUInteger i = 0; i < nav.childViewControllers.count; i++) {
37
+ UIViewController *child = nav.childViewControllers[i];
38
+ NSDictionary *graph = [[HBDReactBridgeManager get] routeGraphWithViewController:child];
39
+ [children addObject:graph];
40
+ }
41
+
42
+ return @{
43
+ @"layout": @"stack",
44
+ @"sceneId": nav.sceneId,
45
+ @"children": children,
46
+ @"mode": [nav hbd_mode],
47
+ };
54
48
  }
55
49
 
56
50
  - (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
57
- if ([vc isKindOfClass:[UINavigationController class]]) {
58
- UINavigationController *nav = (UINavigationController *) vc;
59
- return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:nav.topViewController];
51
+ if (![vc isKindOfClass:[UINavigationController class]]) {
52
+ return nil;
60
53
  }
61
- return nil;
54
+ UINavigationController *nav = (UINavigationController *)vc;
55
+ return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:nav.topViewController];
62
56
  }
63
57
 
64
- - (void)handleNavigationWithViewController:(UIViewController *)target action:(NSString *)action extras:(NSDictionary *)extras resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
65
- UINavigationController *nav = [self navigationControllerForController:target];
58
+ - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
59
+ if (!vc.hbd_inViewHierarchy) {
60
+ callback(@[NSNull.null, @NO]);
61
+ return;
62
+ }
63
+
64
+ UINavigationController *nav = [self navigationControllerForViewController:vc];
66
65
  if (!nav) {
67
- resolve(@(NO));
66
+ callback(@[NSNull.null, @NO]);
68
67
  return;
69
68
  }
70
69
 
71
70
  if (nav.transitionCoordinator) {
72
- __weak typeof(self) selfObj = self;
73
- [nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
74
-
75
- } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
76
- [selfObj handleNavigationWithViewController:target action:action extras:extras resolver:resolve rejecter:reject];
71
+ [nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
72
+ // empty
73
+ } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
74
+ [self handleNavigationWithViewController:vc action:action extras:extras callback:callback];
77
75
  }];
78
76
  return;
79
77
  }
80
78
 
81
79
  if (!nav.hbd_viewAppeared) {
82
- __weak typeof(self) selfObj = self;
83
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
84
- [selfObj handleNavigationWithViewController:target action:action extras:extras resolver:resolve rejecter:reject];
85
- });
80
+ [self performSelector:@selector(handleNavigation:) withObject:@{
81
+ @"viewController": vc,
82
+ @"action": action,
83
+ @"extras": extras,
84
+ @"callback": callback,
85
+ } afterDelay:0.05];
86
86
  return;
87
87
  }
88
88
 
89
- UIViewController *viewController = nil;
90
-
91
89
  if ([action isEqualToString:@"push"]) {
92
- viewController = [self createViewControllerWithExtras:extras];
93
- if (!viewController) {
94
- resolve(@(NO));
95
- return;
96
- }
97
- viewController.hidesBottomBarWhenPushed = nav.hidesBottomBarWhenPushed;
98
- viewController.didShowActionBlock = ^{
99
- resolve(@(YES));
100
- };
101
- [nav pushViewController:viewController animated:YES];
102
- } else if ([action isEqualToString:@"pop"]) {
103
- nav.topViewController.didHideActionBlock = ^{
104
- resolve(@(YES));
105
- };
106
- [nav popViewControllerAnimated:YES];
107
- } else if ([action isEqualToString:@"popTo"]) {
108
- NSArray *children = nav.childViewControllers;
109
- NSUInteger count = children.count;
110
- NSString *moduleName = extras[@"moduleName"];
111
- BOOL inclusive = [extras[@"inclusive"] boolValue];
112
- for (NSUInteger i = count; i > 0; i--) {
113
- NSUInteger index = i - 1;
114
- HBDViewController *vc = children[index];
115
- if ([moduleName isEqualToString:vc.moduleName] || [moduleName isEqualToString:vc.sceneId]) {
116
- viewController = vc;
117
- if (inclusive && i > 0) {
118
- viewController = children[index];
119
- }
120
- break;
90
+ [self handlePushWithNavigationController:nav extras:extras callback:callback];
91
+ return;
92
+ }
93
+
94
+ if ([action isEqualToString:@"pop"]) {
95
+ [self handlePopWithNavigationController:nav callback:callback];
96
+ return;
97
+ }
98
+
99
+ if ([action isEqualToString:@"popTo"]) {
100
+ [self handlePopToWithNavigationController:nav extras:extras callback:callback];
101
+ return;
102
+ }
103
+
104
+ if ([action isEqualToString:@"popToRoot"]) {
105
+ [self handlePopToRootWithNavigationController:nav extras:extras callback:callback];
106
+ return;
107
+ }
108
+
109
+ if ([action isEqualToString:@"redirectTo"]) {
110
+ [self handleRedirectToWithNavigationController:nav target:vc extras:extras callback:callback];
111
+ return;
112
+ }
113
+
114
+ if ([action isEqualToString:@"pushLayout"]) {
115
+ [self handlePushLayoutWithNavigationController:nav extras:extras callback:callback];
116
+ return;
117
+ }
118
+ }
119
+
120
+ - (void)handlePushWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
121
+ UIViewController *vc = [self viewControllerWithExtras:extras];
122
+ if (!vc) {
123
+ callback(@[NSNull.null, @NO]);
124
+ return;
125
+ }
126
+
127
+ vc.hidesBottomBarWhenPushed = nav.hidesBottomBarWhenPushed;
128
+ [nav pushViewController:vc animated:YES];
129
+ [self animateAlongsideTransition:nav callback:callback];
130
+ }
131
+
132
+ - (void)handlePopWithNavigationController:(UINavigationController *)nav callback:(RCTResponseSenderBlock)callback {
133
+ [nav popViewControllerAnimated:YES];
134
+ [self animateAlongsideTransition:nav callback:callback];
135
+ }
136
+
137
+ - (void)handlePopToWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
138
+ UIViewController *vc = [self findViewControllerWithNavigationController:nav extras:extras];
139
+ if (!vc) {
140
+ callback(@[NSNull.null, @NO]);
141
+ return;
142
+ }
143
+
144
+ [nav popToViewController:vc animated:YES];
145
+ [self animateAlongsideTransition:nav callback:callback];
146
+ }
147
+
148
+ - (UIViewController *)findViewControllerWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras {
149
+ NSArray *children = nav.childViewControllers;
150
+ NSString *moduleName = extras[@"moduleName"];
151
+ BOOL inclusive = [extras[@"inclusive"] boolValue];
152
+
153
+ for (NSUInteger i = children.count; i > 0; i--) {
154
+ NSUInteger index = i - 1;
155
+ HBDViewController *vc = children[index];
156
+ if ([moduleName isEqualToString:vc.moduleName] || [moduleName isEqualToString:vc.sceneId]) {
157
+ if (inclusive && index > 0) {
158
+ return children[index - 1];
121
159
  }
160
+ return vc;
122
161
  }
162
+ }
163
+
164
+ return nil;
165
+ }
123
166
 
124
- if (viewController) {
125
- nav.topViewController.didHideActionBlock = ^{
126
- resolve(@(YES));
127
- };
128
- [nav popToViewController:viewController animated:YES];
129
- } else {
130
- resolve(@(NO));
131
- }
132
- } else if ([action isEqualToString:@"popToRoot"]) {
133
- nav.topViewController.didHideActionBlock = ^{
134
- resolve(@(YES));
135
- };
136
- [nav popToRootViewControllerAnimated:YES];
137
- } else if ([action isEqualToString:@"redirectTo"]) {
138
- viewController = [self createViewControllerWithExtras:extras];
139
- if (!viewController) {
140
- resolve(@(NO));
141
- return;
142
- }
143
- viewController.didShowActionBlock = ^{
144
- resolve(@(YES));
145
- };
146
- [nav redirectToViewController:viewController target:target animated:YES];
147
- } else if ([action isEqualToString:@"pushLayout"]) {
148
- NSDictionary *layout = extras[@"layout"];
149
- viewController = [[HBDReactBridgeManager get] controllerWithLayout:layout];
150
- if (viewController) {
151
- viewController.hidesBottomBarWhenPushed = nav.hidesBottomBarWhenPushed;
152
- viewController.didShowActionBlock = ^{
153
- resolve(@(YES));
154
- };
155
- [nav pushViewController:viewController animated:YES];
156
- } else {
157
- resolve(@(NO));
158
- }
167
+ - (void)handlePopToRootWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
168
+ [nav popToRootViewControllerAnimated:YES];
169
+ [self animateAlongsideTransition:nav callback:callback];
170
+ }
171
+
172
+ - (void)handleRedirectToWithNavigationController:(UINavigationController *)nav target:(UIViewController *)target extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
173
+ UIViewController *vc = [self viewControllerWithExtras:extras];
174
+ if (!vc) {
175
+ callback(@[NSNull.null, @NO]);
176
+ return;
159
177
  }
178
+
179
+ [nav redirectToViewController:vc target:target animated:YES];
180
+ [self animateAlongsideTransition:nav callback:callback];
160
181
  }
161
182
 
162
- - (UIViewController *)createViewControllerWithExtras:(NSDictionary *)extras {
163
- NSString *moduleName = extras[@"moduleName"];
164
- HBDViewController *viewController = nil;
165
- if (moduleName) {
166
- NSDictionary *props = extras[@"props"];
167
- NSDictionary *options = extras[@"options"];
168
- viewController = [[HBDReactBridgeManager get] controllerWithModuleName:moduleName props:props options:options];
183
+ - (void)handlePushLayoutWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
184
+ NSDictionary *layout = extras[@"layout"];
185
+ UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
186
+ if (!vc) {
187
+ callback(@[NSNull.null, @NO]);
188
+ return;
169
189
  }
170
- return viewController;
190
+
191
+ vc.hidesBottomBarWhenPushed = nav.hidesBottomBarWhenPushed;
192
+ [nav pushViewController:vc animated:YES];
193
+ [self animateAlongsideTransition:nav callback:callback];
171
194
  }
172
195
 
173
- - (UINavigationController *)navigationControllerForController:(UIViewController *)controller {
174
- UINavigationController *nav = nil;
175
- if ([controller isKindOfClass:[UINavigationController class]]) {
176
- nav = (UINavigationController *) controller;
177
- } else {
178
- nav = controller.navigationController;
196
+ - (void)animateAlongsideTransition:(UINavigationController *)nav callback:(RCTResponseSenderBlock)callback {
197
+ if (!nav.transitionCoordinator) {
198
+ callback(@[NSNull.null, @YES]);
199
+ return;
179
200
  }
201
+
202
+ [nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
203
+ // empty
204
+ } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
205
+ callback(@[NSNull.null, @YES]);
206
+ }];
207
+ }
180
208
 
181
- if (!nav && controller.drawerController) {
182
- HBDDrawerController *drawer = controller.drawerController;
183
- if ([drawer.contentController isKindOfClass:[UITabBarController class]]) {
184
- UITabBarController *tabBar = (UITabBarController *) drawer.contentController;
185
- if ([tabBar.selectedViewController isKindOfClass:[UINavigationController class]]) {
186
- nav = tabBar.selectedViewController;
187
- }
188
- } else if ([drawer.contentController isKindOfClass:[UINavigationController class]]) {
189
- nav = (UINavigationController *) drawer.contentController;
190
- } else {
191
- nav = drawer.contentController.navigationController;
209
+ - (UIViewController *)viewControllerWithExtras:(NSDictionary *)extras {
210
+ NSString *moduleName = extras[@"moduleName"];
211
+ NSDictionary *props = extras[@"props"];
212
+ NSDictionary *options = extras[@"options"];
213
+ return [[HBDReactBridgeManager get] viewControllerWithModuleName:moduleName props:props options:options];
214
+ }
215
+
216
+ - (UINavigationController *)navigationControllerForViewController:(UIViewController *)vc {
217
+ if ([vc isKindOfClass:[UINavigationController class]]) {
218
+ return (UINavigationController *)vc;
219
+ }
220
+
221
+ UINavigationController *nav = vc.navigationController;
222
+ if (nav) {
223
+ return nav;
224
+ }
225
+
226
+ HBDDrawerController *drawer = vc.drawerController;
227
+ if (!drawer) {
228
+ return nil;
229
+ }
230
+
231
+ if ([drawer.contentController isKindOfClass:[UITabBarController class]]) {
232
+ UITabBarController *tabBar = (UITabBarController *) drawer.contentController;
233
+ if ([tabBar.selectedViewController isKindOfClass:[UINavigationController class]]) {
234
+ return (UINavigationController *)tabBar.selectedViewController;
192
235
  }
236
+ return nil;
193
237
  }
194
- return nav;
238
+
239
+ if ([drawer.contentController isKindOfClass:[UINavigationController class]]) {
240
+ return (UINavigationController *) drawer.contentController;
241
+ }
242
+
243
+ return nil;
244
+ }
245
+
246
+ -(void)handleNavigation:(NSDictionary *)params {
247
+ [self handleNavigationWithViewController:params[@"viewController"] action:params[@"action"] extras:params[@"extras"] callback:params[@"callback"]];
248
+ }
249
+
250
+ - (void)invalidate {
251
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
195
252
  }
196
253
 
197
254
  @end