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,16 +1,10 @@
1
- //
2
- // HBDTabNavigator.m
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/6/28.
6
- // Copyright © 2018年 Listen. All rights reserved.
7
- //
8
-
9
1
  #import "HBDTabNavigator.h"
2
+
10
3
  #import "HBDTabBarController.h"
11
4
  #import "HBDReactBridgeManager.h"
12
5
  #import "HBDUtils.h"
13
6
  #import "GlobalStyle.h"
7
+
14
8
  #import <React/RCTUtils.h>
15
9
 
16
10
  @implementation HBDTabNavigator
@@ -23,65 +17,65 @@
23
17
  return @[@"switchTab"];
24
18
  }
25
19
 
26
- - (UIViewController *)createViewControllerWithLayout:(NSDictionary *)layout {
27
- NSDictionary *tabs = layout[self.name];
28
- NSArray *children = tabs[@"children"];
29
- if (children) {
30
- NSDictionary *options = tabs[@"options"];
31
- NSMutableDictionary *tabBarOptions = [@{} mutableCopy];
32
- NSString *tabBarModuleName = options[@"tabBarModuleName"];
33
- BOOL hasCustomTabBar = tabBarModuleName.length > 0;
34
-
35
- NSMutableArray *controllers = [[NSMutableArray alloc] initWithCapacity:4];
36
- for (NSDictionary *tab in children) {
37
- UIViewController *vc = [[HBDReactBridgeManager get] controllerWithLayout:tab];
38
- if (vc) {
39
- [controllers addObject:vc];
40
- }
41
- }
42
-
43
- if (hasCustomTabBar) {
44
- NSArray *tabInfos = [self tabsInfoWithChildren:controllers];
45
- tabBarOptions[@"tabs"] = tabInfos;
46
- tabBarOptions[@"tabBarModuleName"] = tabBarModuleName;
47
- tabBarOptions[@"sizeIndeterminate"] = @([options[@"sizeIndeterminate"] boolValue]);
48
- tabBarOptions[@"selectedIndex"] = options[@"selectedIndex"] ?: @(0);
49
- GlobalStyle *style = [GlobalStyle globalStyle];
50
- tabBarOptions[@"tabBarItemColor"] = style.tabBarItemColorHexString;
51
- tabBarOptions[@"tabBarUnselectedItemColor"] = style.tabBarUnselectedItemColorHexString;
52
- tabBarOptions[@"badgeColor"] = style.badgeColorHexString;
53
- }
54
-
55
- HBDTabBarController *tabBarController = nil;
56
-
57
- if (hasCustomTabBar) {
58
- tabBarController = [[HBDTabBarController alloc] initWithTabBarOptions:tabBarOptions];
59
- } else {
60
- tabBarController = [[HBDTabBarController alloc] init];
20
+ - (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
21
+ NSDictionary *model = layout[self.name];
22
+ NSArray *children = model[@"children"];
23
+ if (!children) {
24
+ return nil;
25
+ }
26
+
27
+ NSMutableArray *viewControllers = [[NSMutableArray alloc] initWithCapacity:4];
28
+ for (NSDictionary *tab in children) {
29
+ UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:tab];
30
+ [viewControllers addObject:vc];
31
+ }
32
+
33
+ NSDictionary *options = model[@"options"];
34
+ NSArray *tabModels = [self tabModelsWithViewControllers:viewControllers];
35
+ HBDTabBarController *tabBarController = [self createTabBarControllerWithTabModels:tabModels options:options];
36
+ [tabBarController setViewControllers:viewControllers];
37
+
38
+ if (options) {
39
+ NSNumber *selectedIndex = options[@"selectedIndex"];
40
+ if (selectedIndex) {
41
+ tabBarController.intercepted = NO;
42
+ tabBarController.selectedIndex = (NSUInteger) [selectedIndex integerValue];
43
+ tabBarController.intercepted = YES;
61
44
  }
45
+ }
62
46
 
63
- [tabBarController setViewControllers:controllers];
64
-
65
- if (options) {
66
- NSNumber *selectedIndex = options[@"selectedIndex"];
67
- if (selectedIndex) {
68
- tabBarController.intercepted = NO;
69
- tabBarController.selectedIndex = (NSUInteger) [selectedIndex integerValue];
70
- tabBarController.intercepted = YES;
71
- }
72
- }
47
+ return tabBarController;
48
+ }
73
49
 
74
- return tabBarController;
50
+ - (HBDTabBarController *)createTabBarControllerWithTabModels:(NSArray *)tabModels options:(NSDictionary *)options {
51
+ NSString *moduleName = options[@"tabBarModuleName"];
52
+ BOOL hasCustomTabBar = moduleName.length > 0;
53
+
54
+ if (!hasCustomTabBar) {
55
+ return [[HBDTabBarController alloc] init];
75
56
  }
76
- return nil;
57
+
58
+ GlobalStyle *style = [GlobalStyle globalStyle];
59
+
60
+ NSDictionary *tabBarOptions = @{
61
+ @"tabs": tabModels,
62
+ @"tabBarModuleName": moduleName,
63
+ @"sizeIndeterminate": options[@"sizeIndeterminate"],
64
+ @"selectedIndex": options[@"selectedIndex"] ?: @(0),
65
+ @"tabBarItemColor": style.tabBarItemColorHexString,
66
+ @"tabBarUnselectedItemColor": style.tabBarUnselectedItemColorHexString,
67
+ @"badgeColor": style.badgeColorHexString,
68
+ };
69
+
70
+ return [[HBDTabBarController alloc] initWithTabBarOptions:tabBarOptions];
77
71
  }
78
72
 
79
- - (NSArray<NSDictionary *> *)tabsInfoWithChildren:(NSArray<UIViewController *> *)children {
73
+ - (NSArray<NSDictionary *> *)tabModelsWithViewControllers:(NSArray<UIViewController *> *)children {
80
74
  NSUInteger count = children.count;
81
- UIViewController *vc = nil;
82
- NSMutableArray *tabInfos = [[NSMutableArray alloc] initWithCapacity:4];
75
+ NSMutableArray *tabModels = [[NSMutableArray alloc] initWithCapacity:4];
76
+
83
77
  for (NSUInteger i = 0; i < count; i++) {
84
- vc = children[i];
78
+ UIViewController *vc = children[i];
85
79
  if ([vc isKindOfClass:[UINavigationController class]]) {
86
80
  UINavigationController *nav = (UINavigationController *) vc;
87
81
  vc = nav.childViewControllers[0];
@@ -98,97 +92,123 @@
98
92
  @"unselectedIcon": RCTNullIfNil([HBDUtils iconUriFromUri:tabItem[@"unselectedIcon"][@"uri"]]),
99
93
  @"title": RCTNullIfNil(tabItem[@"title"]),
100
94
  };
101
- [tabInfos addObject:tab];
95
+ [tabModels addObject:tab];
102
96
  }
103
97
  }
104
98
  }
105
- return [tabInfos copy];
99
+
100
+ return [tabModels copy];
106
101
  }
107
102
 
108
- - (NSDictionary *)buildRouteGraphWithViewController:(UIViewController *)vc {
109
- if ([vc isKindOfClass:[HBDTabBarController class]]) {
110
- HBDTabBarController *tabBarController = (HBDTabBarController *) vc;
111
- NSMutableArray *children = [[NSMutableArray alloc] init];
112
- for (NSUInteger i = 0; i < tabBarController.childViewControllers.count; i++) {
113
- UIViewController *child = tabBarController.childViewControllers[i];
114
- NSDictionary *graph = [[HBDReactBridgeManager get] buildRouteGraphWithViewController:child];
115
- [children addObject:graph];
116
- }
117
- return @{
118
- @"layout": self.name,
119
- @"sceneId": vc.sceneId,
120
- @"children": children,
121
- @"mode": [vc hbd_mode],
122
- @"selectedIndex": @(tabBarController.selectedIndex)
123
- };
124
- }
125
- return nil;
103
+ - (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
104
+ if (![vc isKindOfClass:[HBDTabBarController class]]) {
105
+ return nil;
106
+ }
107
+
108
+ HBDTabBarController *tabBarController = (HBDTabBarController *) vc;
109
+ NSMutableArray *children = [[NSMutableArray alloc] init];
110
+ for (NSUInteger i = 0; i < tabBarController.childViewControllers.count; i++) {
111
+ UIViewController *child = tabBarController.childViewControllers[i];
112
+ NSDictionary *graph = [[HBDReactBridgeManager get] routeGraphWithViewController:child];
113
+ [children addObject:graph];
114
+ }
115
+
116
+ return @{
117
+ @"layout": self.name,
118
+ @"sceneId": tabBarController.sceneId,
119
+ @"children": children,
120
+ @"mode": [tabBarController hbd_mode],
121
+ @"selectedIndex": @(tabBarController.selectedIndex)
122
+ };
126
123
  }
127
124
 
128
125
  - (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
129
- if ([vc isKindOfClass:[UITabBarController class]]) {
130
- UITabBarController *tabBarVc = (UITabBarController *) vc;
131
- return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:tabBarVc.selectedViewController];
126
+ if (![vc isKindOfClass:[UITabBarController class]]) {
127
+ return nil;
132
128
  }
133
- return nil;
129
+ UITabBarController *tabBarController = (UITabBarController *) vc;
130
+ return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:tabBarController.selectedViewController];
134
131
  }
135
132
 
136
- - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
137
-
138
- UITabBarController *tabBarController = nil;
133
+ - (UITabBarController *)tabBarControllerForViewController:(UIViewController *)vc {
139
134
  if ([vc isKindOfClass:[UITabBarController class]]) {
140
- tabBarController = (UITabBarController *) vc;
135
+ return (UITabBarController *) vc;
136
+ } else {
137
+ return vc.tabBarController;
138
+ }
139
+ }
140
+
141
+ - (void)handleSwitchTabWithTabBarController:(UITabBarController *)tabBarController extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
142
+ BOOL popToRoot = [extras[@"popToRoot"] boolValue];
143
+ NSNumber *from = extras[@"from"];
144
+ NSUInteger to = [extras[@"to"] integerValue];
145
+
146
+ if (from && [from integerValue] == to) {
147
+ callback(@[NSNull.null, @YES]);
148
+ return;
149
+ }
150
+
151
+ if (popToRoot) {
152
+ UIViewController *selectedViewController = [tabBarController selectedViewController];
153
+ UINavigationController *nav = nil;
154
+ if ([selectedViewController isKindOfClass:[UINavigationController class]]) {
155
+ nav = (UINavigationController *)selectedViewController;
156
+ } else {
157
+ nav = selectedViewController.navigationController;
158
+ }
159
+
160
+ if (nav && nav.childViewControllers.count > 1) {
161
+ [nav popToRootViewControllerAnimated:NO];
162
+ }
163
+ }
164
+
165
+ if ([tabBarController isKindOfClass:[HBDTabBarController class]]) {
166
+ HBDTabBarController *hbdTabBarController = (HBDTabBarController *)tabBarController;
167
+ hbdTabBarController.intercepted = NO;
168
+ tabBarController.selectedIndex = to;
169
+ hbdTabBarController.intercepted = YES;
141
170
  } else {
142
- tabBarController = vc.tabBarController;
171
+ tabBarController.selectedIndex = to;
143
172
  }
173
+
174
+ callback(@[NSNull.null, @YES]);
175
+ }
176
+
177
+ - (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
178
+ if (!vc.hbd_inViewHierarchy) {
179
+ callback(@[NSNull.null, @NO]);
180
+ return;
181
+ }
182
+
183
+ UITabBarController *tabBarController = [self tabBarControllerForViewController:vc];
144
184
 
145
185
  if (!tabBarController) {
146
- resolve(@(NO));
186
+ callback(@[NSNull.null, @NO]);
147
187
  return;
148
188
  }
149
189
 
150
190
  if (!tabBarController.hbd_viewAppeared) {
151
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t) (0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
152
- [self handleNavigationWithViewController:vc action:action extras:extras resolver:resolve rejecter:reject];
153
- });
191
+ [self performSelector:@selector(handleNavigation:) withObject:@{
192
+ @"viewController": vc,
193
+ @"action": action,
194
+ @"extras": extras,
195
+ @"callback": callback,
196
+ } afterDelay:0.05];
154
197
  return;
155
198
  }
156
199
 
157
200
  if ([action isEqualToString:@"switchTab"]) {
158
- BOOL popToRoot = [extras[@"popToRoot"] boolValue];
159
- NSNumber *from = extras[@"from"];
160
- NSUInteger to = [extras[@"to"] integerValue];
161
-
162
- if (from && [from integerValue] == to) {
163
- resolve(@(YES));
164
- return;
165
- }
166
-
167
- if (popToRoot) {
168
- UIViewController *selectedViewController = [tabBarController selectedViewController];
169
- UINavigationController *nav = nil;
170
- if ([selectedViewController isKindOfClass:[UINavigationController class]]) {
171
- nav = (UINavigationController *) selectedViewController;
172
- } else {
173
- nav = selectedViewController.navigationController;
174
- }
175
-
176
- if (nav && nav.childViewControllers.count > 1) {
177
- [nav popToRootViewControllerAnimated:NO];
178
- }
179
- }
180
-
181
- if ([tabBarController isKindOfClass:[HBDTabBarController class]]) {
182
- HBDTabBarController *hbdTabBarVC = (HBDTabBarController *) tabBarController;
183
- hbdTabBarVC.intercepted = NO;
184
- tabBarController.selectedIndex = to;
185
- hbdTabBarVC.intercepted = YES;
186
- } else {
187
- tabBarController.selectedIndex = to;
188
- }
201
+ [self handleSwitchTabWithTabBarController:tabBarController extras:extras callback:callback];
202
+ return;
189
203
  }
204
+ }
205
+
206
+ -(void)handleNavigation:(NSDictionary *)params {
207
+ [self handleNavigationWithViewController:params[@"viewController"] action:params[@"action"] extras:params[@"extras"] callback:params[@"callback"]];
208
+ }
190
209
 
191
- resolve(@(YES));
210
+ - (void)invalidate {
211
+ [NSObject cancelPreviousPerformRequestsWithTarget:self];
192
212
  }
193
213
 
194
214
  @end
@@ -1,13 +1,3 @@
1
- //
2
- // HBDEventEmitter.h
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/12/27.
6
- // Copyright © 2018 Listen. All rights reserved.
7
- //
8
-
9
- #import <Foundation/Foundation.h>
10
- #import <React/RCTBridgeModule.h>
11
1
  #import <React/RCTEventEmitter.h>
12
2
 
13
3
  NS_ASSUME_NONNULL_BEGIN
@@ -29,7 +19,7 @@ extern NSString *const KEY_INDEX;
29
19
  extern NSString *const KEY_ACTION;
30
20
  extern NSString *const KEY_ON;
31
21
 
32
- @interface HBDEventEmitter : RCTEventEmitter <RCTBridgeModule>
22
+ @interface HBDEventEmitter : RCTEventEmitter
33
23
 
34
24
  + (void)sendEvent:(NSString *)eventName data:(NSDictionary *)data;
35
25
 
@@ -1,14 +1,9 @@
1
- //
2
- // HBDEventEmitter.m
3
- // HybridNavigation
4
- //
5
- // Created by Listen on 2018/12/27.
6
- // Copyright © 2018 Listen. All rights reserved.
7
- //
8
-
9
1
  #import "HBDEventEmitter.h"
2
+
10
3
  #import "HBDReactBridgeManager.h"
11
4
 
5
+ #import <React/RCTBridgeModule.h>
6
+
12
7
  NSString *const ON_COMPONENT_RESULT = @"ON_COMPONENT_RESULT";
13
8
  NSString *const ON_BAR_BUTTON_ITEM_CLICK = @"ON_BAR_BUTTON_ITEM_CLICK";
14
9
  NSString *const ON_COMPONENT_APPEAR = @"ON_COMPONENT_APPEAR";
@@ -30,8 +25,7 @@ NSString *const KEY_ON = @"on";
30
25
 
31
26
  @implementation HBDEventEmitter
32
27
 
33
-
34
- RCT_EXPORT_MODULE(HBDEventEmitter);
28
+ RCT_EXPORT_MODULE(HBDEventEmitter)
35
29
 
36
30
  - (NSArray<NSString *> *)supportedEvents {
37
31
  return @[EVENT_NAVIGATION, EVENT_SWITCH_TAB, EVENT_DID_SET_ROOT, EVENT_WILL_SET_ROOT];
@@ -0,0 +1,6 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTEventEmitter.h>
3
+
4
+ @interface HBDGardenModule : RCTEventEmitter <RCTBridgeModule>
5
+
6
+ @end
@@ -0,0 +1,161 @@
1
+ #import "HBDGardenModule.h"
2
+
3
+ #import "HBDReactBridgeManager.h"
4
+ #import "HBDTabBarController.h"
5
+ #import "GlobalStyle.h"
6
+
7
+ #import <React/RCTLog.h>
8
+
9
+ static NSString *const EVENT_STATUSBAR_FRAME_CHANGE = @"EVENT_STATUSBAR_FRAME_CHANGE";
10
+
11
+ @interface HBDGardenModule ()
12
+
13
+ @property(nonatomic, strong, readonly) HBDReactBridgeManager *bridgeManager;
14
+
15
+ @end
16
+
17
+ @implementation HBDGardenModule
18
+
19
+ RCT_EXPORT_MODULE(GardenModule)
20
+
21
+ + (BOOL)requiresMainQueueSetup {
22
+ return YES;
23
+ }
24
+
25
+ - (dispatch_queue_t)methodQueue {
26
+ return dispatch_get_main_queue();
27
+ }
28
+
29
+ - (instancetype)init {
30
+ if (self = [super init]) {
31
+ _bridgeManager = [HBDReactBridgeManager get];
32
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleStatusBarFrameChange) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
33
+ }
34
+ return self;
35
+ }
36
+
37
+ - (void)dealloc {
38
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
39
+ }
40
+
41
+ - (NSDictionary *)constantsToExport {
42
+ return @{
43
+ @"TOOLBAR_HEIGHT": @(44),
44
+ @"STATUSBAR_HEIGHT": @([self currentStatusBarHeight]),
45
+ @"EVENT_STATUSBAR_FRAME_CHANGE": EVENT_STATUSBAR_FRAME_CHANGE,
46
+ };
47
+ }
48
+
49
+ - (NSArray<NSString *> *)supportedEvents {
50
+ return @[EVENT_STATUSBAR_FRAME_CHANGE];
51
+ }
52
+
53
+ - (CGFloat)currentStatusBarHeight {
54
+ if (@available(iOS 13.0, *)) {
55
+ UIStatusBarManager *statusBarManager = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager;
56
+ return statusBarManager.statusBarFrame.size.height;
57
+ } else {
58
+ return [[UIApplication sharedApplication] statusBarFrame].size.height;
59
+ }
60
+ }
61
+
62
+ - (void)handleStatusBarFrameChange {
63
+ RCTLogInfo(@"[Navigator] handleStatusBarFrameChange: %f", [self currentStatusBarHeight]);
64
+ if ([self.bridge isValid]) {
65
+ [self sendEventWithName:EVENT_STATUSBAR_FRAME_CHANGE body:@{
66
+ @"statusBarHeight": @([self currentStatusBarHeight])
67
+ }];
68
+ }
69
+ }
70
+
71
+ RCT_EXPORT_METHOD(setStyle:(NSDictionary *) style) {
72
+ [GlobalStyle createWithOptions:style];
73
+ }
74
+
75
+ RCT_EXPORT_METHOD(setTitleItem:(NSString *)sceneId item:(NSDictionary *)item) {
76
+ HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
77
+ if (vc) {
78
+ [vc updateNavigationBarOptions:@{@"titleItem": RCTNullIfNil(item)}];
79
+ }
80
+ }
81
+
82
+ RCT_EXPORT_METHOD(setLeftBarButtonItem:(NSString *)sceneId item:(NSDictionary *__nullable)item) {
83
+ HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
84
+ if (vc) {
85
+ [vc updateNavigationBarOptions:@{@"leftBarButtonItem": RCTNullIfNil(item)}];
86
+ }
87
+ }
88
+
89
+ RCT_EXPORT_METHOD(setRightBarButtonItem:(NSString *)sceneId item:(NSDictionary *__nullable)item) {
90
+ HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
91
+ if (vc) {
92
+ [vc updateNavigationBarOptions:@{@"rightBarButtonItem": RCTNullIfNil(item)}];
93
+ }
94
+ }
95
+
96
+ RCT_EXPORT_METHOD(setLeftBarButtonItems:(NSString *)sceneId item:(NSArray *__nullable)items) {
97
+ HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
98
+ if (vc) {
99
+ [vc updateNavigationBarOptions:@{@"leftBarButtonItems": RCTNullIfNil(items)}];
100
+ }
101
+ }
102
+
103
+ RCT_EXPORT_METHOD(setRightBarButtonItems:(NSString *)sceneId item:(NSArray *__nullable)items) {
104
+ HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
105
+ if (vc) {
106
+ [vc updateNavigationBarOptions:@{@"rightBarButtonItems": RCTNullIfNil(items)}];
107
+ }
108
+ }
109
+
110
+ RCT_EXPORT_METHOD(updateOptions:(NSString *)sceneId item:(NSDictionary *)options) {
111
+ RCTLogInfo(@"[Navigator] updateNavigationBarOptions: %@", options);
112
+ HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
113
+ if (vc) {
114
+ [vc updateNavigationBarOptions:options];
115
+ }
116
+ }
117
+
118
+ RCT_EXPORT_METHOD(updateTabBar:(NSString *)sceneId item:(NSDictionary *)item) {
119
+ RCTLogInfo(@"[Navigator] updateTabBar: %@", item);
120
+ UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
121
+ UITabBarController *tabBarVC = [self tabBarControllerWithViewController:vc];
122
+ if (tabBarVC && [tabBarVC isKindOfClass:[HBDTabBarController class]]) {
123
+ [((HBDTabBarController *)tabBarVC) updateTabBar:item];
124
+ }
125
+ }
126
+
127
+ RCT_EXPORT_METHOD(setTabItem:(NSString *)sceneId options:(NSArray<NSDictionary *> *)options) {
128
+ RCTLogInfo(@"[Navigator] setTabItem: %@", options);
129
+ UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
130
+ UITabBarController *tabBarController = [self tabBarControllerWithViewController:vc];
131
+ if ([tabBarController isKindOfClass:[HBDTabBarController class]]) {
132
+ HBDTabBarController *tabBarVC = (HBDTabBarController *)tabBarController;
133
+ [tabBarVC setTabItem:options];
134
+ }
135
+ }
136
+
137
+ RCT_EXPORT_METHOD(setMenuInteractive:(NSString *)sceneId enabled:(BOOL)enabled) {
138
+ UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
139
+ HBDDrawerController *drawer = [vc drawerController];
140
+ if (drawer) {
141
+ drawer.menuInteractive = enabled;
142
+ }
143
+ }
144
+
145
+ - (HBDViewController *)viewControllerWithSceneId:(NSString *)sceneId {
146
+ UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
147
+ if ([vc isKindOfClass:[HBDViewController class]]) {
148
+ return (HBDViewController *)vc;
149
+ }
150
+ return nil;
151
+ }
152
+
153
+ - (UITabBarController *)tabBarControllerWithViewController:(UIViewController *)vc {
154
+ if ([vc isKindOfClass:[UITabBarController class]]) {
155
+ return (UITabBarController *)vc;
156
+ } else {
157
+ return vc.tabBarController;
158
+ }
159
+ }
160
+
161
+ @end
@@ -0,0 +1,6 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface HBDNavigationModule : NSObject <RCTBridgeModule>
4
+
5
+ @end
6
+