hybrid-navigation 2.12.4 → 2.13.0-beta.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.
Files changed (85) hide show
  1. package/README.md +63 -0
  2. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +6 -2
  3. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +29 -30
  4. package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +2 -3
  5. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +4 -4
  6. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +6 -6
  7. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +24 -33
  8. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +22 -22
  9. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +8 -8
  10. package/ios/HybridNavigation/GlobalStyle.h +0 -8
  11. package/ios/HybridNavigation/GlobalStyle.m +2 -8
  12. package/ios/HybridNavigation/HBDAnimationObserver.h +24 -0
  13. package/ios/HybridNavigation/HBDAnimationObserver.m +45 -0
  14. package/ios/HybridNavigation/HBDUtils.h +5 -13
  15. package/ios/HybridNavigation/HBDUtils.m +26 -12
  16. package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.h +0 -9
  17. package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.m +91 -67
  18. package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.h +2 -7
  19. package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +28 -26
  20. package/ios/HybridNavigation/Navigator/HBDScreenNavigator.h +0 -9
  21. package/ios/HybridNavigation/Navigator/HBDScreenNavigator.m +132 -99
  22. package/ios/HybridNavigation/Navigator/HBDStackNavigator.h +0 -9
  23. package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +203 -142
  24. package/ios/HybridNavigation/Navigator/HBDTabNavigator.h +0 -9
  25. package/ios/HybridNavigation/Navigator/HBDTabNavigator.m +144 -124
  26. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.h +1 -11
  27. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.m +4 -10
  28. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +6 -0
  29. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +161 -0
  30. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +6 -0
  31. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +239 -0
  32. package/ios/HybridNavigation/ReactBridge/HBDNavigator.h +20 -0
  33. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.h +12 -20
  34. package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.m +91 -91
  35. package/ios/HybridNavigation/View/HBDBarButtonItem.h +0 -8
  36. package/ios/HybridNavigation/View/HBDBarButtonItem.m +1 -11
  37. package/ios/HybridNavigation/View/HBDNavigationBar.h +0 -8
  38. package/ios/HybridNavigation/View/HBDNavigationBar.m +3 -12
  39. package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -8
  40. package/ios/HybridNavigation/View/HBDReactTabBar.m +1 -8
  41. package/ios/HybridNavigation/View/HBDRootView.h +3 -10
  42. package/ios/HybridNavigation/View/HBDRootView.m +14 -25
  43. package/ios/HybridNavigation/View/HBDTitleView.h +0 -9
  44. package/ios/HybridNavigation/View/HBDTitleView.m +1 -26
  45. package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -8
  46. package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -7
  47. package/ios/HybridNavigation/ViewController/HBDDrawerController.h +0 -8
  48. package/ios/HybridNavigation/ViewController/HBDDrawerController.m +2 -9
  49. package/ios/HybridNavigation/ViewController/HBDFadeAnimation.h +9 -0
  50. package/ios/HybridNavigation/ViewController/HBDFadeAnimation.m +22 -0
  51. package/ios/HybridNavigation/ViewController/HBDNavigationController.h +0 -8
  52. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +17 -120
  53. package/ios/HybridNavigation/ViewController/HBDPopAnimation.h +0 -7
  54. package/ios/HybridNavigation/ViewController/HBDPopAnimation.m +1 -8
  55. package/ios/HybridNavigation/ViewController/HBDPushAnimation.h +0 -7
  56. package/ios/HybridNavigation/ViewController/HBDPushAnimation.m +1 -8
  57. package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -8
  58. package/ios/HybridNavigation/ViewController/HBDReactViewController.m +60 -27
  59. package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -8
  60. package/ios/HybridNavigation/ViewController/HBDTabBarController.m +15 -11
  61. package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +23 -33
  62. package/ios/HybridNavigation/ViewController/HBDViewController.h +1 -8
  63. package/ios/HybridNavigation/ViewController/HBDViewController.m +12 -25
  64. package/ios/HybridNavigation/ViewController/UINavigationController+HBD.h +0 -8
  65. package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -8
  66. package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +2 -16
  67. package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +32 -46
  68. package/lib/Garden.d.ts +3 -0
  69. package/lib/Garden.js +12 -1
  70. package/lib/NavigationModule.d.ts +0 -2
  71. package/lib/NavigationModule.js +0 -3
  72. package/lib/Navigator.d.ts +25 -25
  73. package/lib/Navigator.js +116 -73
  74. package/lib/index.d.ts +1 -1
  75. package/lib/index.js +1 -1
  76. package/package.json +4 -6
  77. package/src/Garden.ts +15 -1
  78. package/src/NavigationModule.ts +0 -4
  79. package/src/Navigator.ts +96 -58
  80. package/src/index.ts +1 -1
  81. package/ios/HybridNavigation/Bridge/HBDGardenModule.h +0 -14
  82. package/ios/HybridNavigation/Bridge/HBDGardenModule.m +0 -155
  83. package/ios/HybridNavigation/Bridge/HBDNavigationModule.h +0 -15
  84. package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +0 -272
  85. package/ios/HybridNavigation/Navigator/HBDNavigator.h +0 -26
@@ -1,14 +1,9 @@
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
+ #import "HBDAnimationObserver.h"
6
+
12
7
  #import <React/RCTLog.h>
13
8
 
14
9
  @implementation HBDScreenNavigator
@@ -21,28 +16,30 @@
21
16
  return @[@"present", @"presentLayout", @"dismiss", @"showModal", @"showModalLayout", @"hideModal"];
22
17
  }
23
18
 
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];
19
+ - (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
20
+ NSDictionary *model = layout[self.name];
21
+ if (!model) {
22
+ return nil;
31
23
  }
32
- return nil;
24
+
25
+ NSString *moduleName = model[@"moduleName"];
26
+ NSDictionary *props = model[@"props"];
27
+ NSDictionary *options = model[@"options"];
28
+ return [[HBDReactBridgeManager get] viewControllerWithModuleName:moduleName props:props options:options];
33
29
  }
34
30
 
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
- };
31
+ - (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
32
+ if (![vc isKindOfClass:[HBDViewController class]]) {
33
+ return nil;
44
34
  }
45
- return nil;
35
+
36
+ HBDViewController *screen = (HBDViewController *) vc;
37
+ return @{
38
+ @"layout": @"screen",
39
+ @"sceneId": screen.sceneId,
40
+ @"moduleName": RCTNullIfNil(screen.moduleName),
41
+ @"mode": [screen hbd_mode],
42
+ };
46
43
  }
47
44
 
48
45
  - (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
@@ -52,88 +49,124 @@
52
49
  return nil;
53
50
  }
54
51
 
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
- });
52
+ - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
53
+ if (!vc.hbd_inViewHierarchy) {
54
+ callback(@[NSNull.null, @NO]);
55
+ return;
56
+ }
57
+
58
+ if (!vc.hbd_viewAppeared) {
59
+ [self performSelector:@selector(handleNavigation:) withObject:@{
60
+ @"viewController": vc,
61
+ @"action": action,
62
+ @"extras": extras,
63
+ @"callback": callback,
64
+ } afterDelay:0.05];
61
65
  return;
62
66
  }
63
-
64
- UIViewController *viewController = nil;
65
67
 
66
68
  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
- }];
69
+ [self handlePresentWithViewController:vc extras:extras callback:callback];
70
+ return;
71
+ }
72
+
73
+ if ([action isEqualToString:@"dismiss"]) {
74
+ [self handleDismissWithViewController:vc callback:callback];
75
+ return;
76
+ }
77
+
78
+ if ([action isEqualToString:@"showModal"]) {
79
+ [self handleShowModalWithViewController:vc extras:extras callback:callback];
80
+ return;
81
+ }
82
+
83
+ if ([action isEqualToString:@"hideModal"]) {
84
+ [self handleDismissWithViewController:vc callback:callback];
85
+ return;
125
86
  }
87
+
88
+ if ([action isEqualToString:@"presentLayout"]) {
89
+ [self handlePresentLayoutWithViewController:vc extras:extras callback:callback];
90
+ return;
91
+ }
92
+
93
+ if ([action isEqualToString:@"showModalLayout"]) {
94
+ [self handleShowModalLayoutWithViewController:vc extras:extras callback:callback];
95
+ return;
96
+ }
97
+ }
98
+
99
+ - (void)handlePresentWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
100
+ UIViewController *vc = [self viewControllerWithExtras:extras];
101
+ NSInteger requestCode = [extras[@"requestCode"] integerValue];
102
+ HBDNavigationController *nav = [[HBDNavigationController alloc] initWithRootViewController:vc];
103
+ nav.modalPresentationStyle = UIModalPresentationCurrentContext;
104
+ [nav setRequestCode:requestCode];
105
+ [[HBDAnimationObserver sharedObserver] beginAnimation];
106
+ [presenting presentViewController:nav animated:YES completion:^{
107
+ callback(@[NSNull.null, @YES]);
108
+ }];
109
+ }
110
+
111
+ - (void)handleDismissWithViewController:(UIViewController *) vc callback:(RCTResponseSenderBlock)callback {
112
+ [vc dismissViewControllerAnimated:YES completion:^{
113
+ callback(@[NSNull.null, @YES]);
114
+ }];
115
+ }
116
+
117
+ - (void)handleShowModalWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
118
+ UIViewController *vc = [self viewControllerWithExtras:extras];
119
+ NSInteger requestCode = [extras[@"requestCode"] integerValue];
120
+ vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
121
+ vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
122
+ [vc setRequestCode:requestCode];
123
+ [[HBDAnimationObserver sharedObserver] beginAnimation];
124
+ [presenting presentViewController:vc animated:YES completion:^{
125
+ callback(@[NSNull.null, @YES]);
126
+ }];
127
+ }
128
+
129
+ - (void)handlePresentLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
130
+ NSDictionary *layout = extras[@"layout"];
131
+ NSInteger requestCode = [extras[@"requestCode"] integerValue];
132
+ UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
133
+ [vc setRequestCode:requestCode];
134
+ vc.modalPresentationStyle = UIModalPresentationCurrentContext;
135
+ [[HBDAnimationObserver sharedObserver] beginAnimation];
136
+ [presenting presentViewController:vc animated:YES completion:^{
137
+ callback(@[NSNull.null, @YES]);
138
+ }];
139
+ }
140
+
141
+ - (void)handleShowModalLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
142
+ NSInteger requestCode = [extras[@"requestCode"] integerValue];
143
+ NSDictionary *layout = extras[@"layout"];
144
+ UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
145
+ vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
146
+ vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
147
+ [vc setRequestCode:requestCode];
148
+ [[HBDAnimationObserver sharedObserver] beginAnimation];
149
+ [presenting presentViewController:vc animated:YES completion:^{
150
+ callback(@[NSNull.null, @YES]);
151
+ }];
126
152
  }
127
153
 
128
- - (UIViewController *)createViewControllerWithExtras:(NSDictionary *)extras {
154
+ - (UIViewController *)viewControllerWithExtras:(NSDictionary *)extras {
129
155
  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];
156
+ if (!moduleName) {
157
+ return nil;
135
158
  }
136
- return viewController;
159
+ NSDictionary *props = extras[@"props"];
160
+ NSDictionary *options = extras[@"options"];
161
+ return [[HBDReactBridgeManager get] viewControllerWithModuleName:moduleName props:props options:options];
162
+ }
163
+
164
+ -(void)handleNavigation:(NSDictionary *)params {
165
+ [self handleNavigationWithViewController:params[@"viewController"] action:params[@"action"] extras:params[@"extras"] callback:params[@"callback"]];
166
+ }
167
+
168
+ - (void)invalidate {
169
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
137
170
  }
138
171
 
139
172
  @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>