hybrid-navigation 2.20.1 → 3.0.1

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 (136) hide show
  1. package/HybridNavigation.podspec +7 -5
  2. package/README.md +17 -0
  3. package/android/build.gradle +56 -19
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +1 -2
  6. package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +320 -326
  7. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +13 -20
  8. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +6 -11
  9. package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +55 -21
  10. package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +31 -0
  11. package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +223 -0
  12. package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +370 -0
  13. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +239 -224
  14. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +177 -198
  15. package/android/src/main/java/com/reactnative/hybridnavigation/ReactDrawerFragment.java +2 -9
  16. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +41 -78
  17. package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +438 -0
  18. package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +10 -19
  19. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +7 -15
  20. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +135 -173
  21. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +54 -227
  22. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +2 -3
  23. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +12 -14
  24. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +18 -21
  25. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +17 -20
  26. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +13 -26
  27. package/dist/NativeEvent.d.ts +33 -0
  28. package/dist/NativeEvent.js +2 -0
  29. package/dist/NativeGarden.d.ts +18 -0
  30. package/dist/NativeGarden.js +2 -0
  31. package/dist/NativeNavigation.d.ts +47 -0
  32. package/dist/NativeNavigation.js +2 -0
  33. package/dist/Navigation.js +3 -3
  34. package/dist/NavigationModule.d.ts +3 -3
  35. package/dist/NavigationModule.js +18 -19
  36. package/dist/Navigator.js +1 -2
  37. package/dist/Options.d.ts +4 -7
  38. package/dist/Route.d.ts +0 -2
  39. package/dist/handler/BarButtonEventHandler.js +2 -2
  40. package/dist/handler/LayoutCommandHandler.js +3 -3
  41. package/dist/handler/ResultEventHandler.js +3 -3
  42. package/dist/handler/VisibilityEventHandler.js +11 -4
  43. package/dist/index.d.ts +0 -1
  44. package/dist/index.js +0 -1
  45. package/ios/HybridNavigation/GlobalStyle.h +0 -6
  46. package/ios/HybridNavigation/{GlobalStyle.m → GlobalStyle.mm} +54 -44
  47. package/ios/HybridNavigation/HBDUtils.h +0 -4
  48. package/ios/HybridNavigation/{HBDUtils.m → HBDUtils.mm} +0 -41
  49. package/ios/HybridNavigation/Navigator/{HBDScreenNavigator.m → HBDScreenNavigator.mm} +3 -9
  50. package/ios/HybridNavigation/Navigator/{HBDStackNavigator.m → HBDStackNavigator.mm} +0 -4
  51. package/ios/HybridNavigation/Navigator/{HBDTabNavigator.m → HBDTabNavigator.mm} +1 -55
  52. package/ios/HybridNavigation/React/HBDNativeEvent.h +13 -0
  53. package/ios/HybridNavigation/React/HBDNativeEvent.mm +31 -0
  54. package/ios/HybridNavigation/React/HBDNativeGarden.h +10 -0
  55. package/ios/HybridNavigation/React/HBDNativeGarden.mm +151 -0
  56. package/ios/HybridNavigation/React/HBDNativeNavigation.h +11 -0
  57. package/ios/HybridNavigation/React/HBDNativeNavigation.mm +263 -0
  58. package/ios/HybridNavigation/{ReactBridge → React}/HBDReactBridgeManager.h +3 -1
  59. package/ios/HybridNavigation/{ReactBridge/HBDReactBridgeManager.m → React/HBDReactBridgeManager.mm} +7 -30
  60. package/ios/HybridNavigation/View/{HBDNavigationBar.m → HBDNavigationBar.mm} +8 -28
  61. package/ios/HybridNavigation/View/HBDRootView.h +2 -2
  62. package/ios/HybridNavigation/View/{HBDRootView.m → HBDRootView.mm} +2 -2
  63. package/ios/HybridNavigation/View/HBDTitleView.h +2 -2
  64. package/ios/HybridNavigation/View/{HBDTitleView.m → HBDTitleView.mm} +3 -3
  65. package/ios/HybridNavigation/View/UIImage+WithBadge.h +13 -0
  66. package/ios/HybridNavigation/View/UIImage+WithBadge.mm +36 -0
  67. package/ios/HybridNavigation/ViewController/{HBDDrawerController.m → HBDDrawerController.mm} +2 -25
  68. package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -4
  69. package/ios/HybridNavigation/ViewController/{HBDReactViewController.m → HBDReactViewController.mm} +40 -31
  70. package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -2
  71. package/ios/HybridNavigation/ViewController/HBDTabBarController.mm +140 -0
  72. package/ios/HybridNavigation/ViewController/HBDViewController+Garden.h +0 -2
  73. package/ios/HybridNavigation/ViewController/{HBDViewController+Garden.m → HBDViewController+Garden.mm} +8 -26
  74. package/ios/HybridNavigation/ViewController/HBDViewController.h +2 -0
  75. package/ios/HybridNavigation/ViewController/{HBDViewController.m → HBDViewController.mm} +67 -57
  76. package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +0 -2
  77. package/ios/HybridNavigation/ViewController/{UIViewController+HBD.m → UIViewController+HBD.mm} +10 -44
  78. package/package.json +11 -2
  79. package/src/DeepLink.ts +3 -3
  80. package/src/NativeEvent.ts +40 -0
  81. package/src/NativeGarden.ts +27 -0
  82. package/src/NativeNavigation.ts +72 -0
  83. package/src/Navigation.ts +13 -13
  84. package/src/NavigationComponentWrap.tsx +4 -4
  85. package/src/NavigationModule.ts +21 -46
  86. package/src/Navigator.ts +13 -13
  87. package/src/Options.ts +9 -9
  88. package/src/Route.ts +0 -2
  89. package/src/handler/BarButtonEventHandler.ts +4 -8
  90. package/src/handler/DispatchCommandHandler.ts +4 -8
  91. package/src/handler/LayoutCommandHandler.ts +4 -5
  92. package/src/handler/ResultEventHandler.ts +11 -27
  93. package/src/handler/VisibilityEventHandler.ts +23 -32
  94. package/src/hooks.ts +2 -2
  95. package/src/index.ts +4 -5
  96. package/src/router/drawer.ts +5 -5
  97. package/src/router/index.ts +15 -15
  98. package/src/router/screen.ts +2 -2
  99. package/src/router/stack.ts +4 -4
  100. package/src/router/tabs.ts +3 -3
  101. package/src/store.ts +1 -1
  102. package/android/src/main/java/com/reactnative/hybridnavigation/DefaultTabBarProvider.java +0 -143
  103. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +0 -230
  104. package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +0 -89
  105. package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +0 -71
  106. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +0 -370
  107. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +0 -445
  108. package/dist/Event.d.ts +0 -16
  109. package/dist/Event.js +0 -62
  110. package/dist/GardenModule.d.ts +0 -24
  111. package/dist/GardenModule.js +0 -21
  112. package/ios/HybridNavigation/HBDAnimationObserver.h +0 -24
  113. package/ios/HybridNavigation/HBDAnimationObserver.m +0 -45
  114. package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.h +0 -28
  115. package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.m +0 -72
  116. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +0 -6
  117. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +0 -157
  118. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +0 -6
  119. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +0 -249
  120. package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -9
  121. package/ios/HybridNavigation/View/HBDReactTabBar.m +0 -36
  122. package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -9
  123. package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -46
  124. package/ios/HybridNavigation/ViewController/HBDTabBarController.m +0 -265
  125. package/src/Event.ts +0 -117
  126. package/src/GardenModule.ts +0 -50
  127. /package/ios/HybridNavigation/Navigator/{HBDDrawerNavigator.m → HBDDrawerNavigator.mm} +0 -0
  128. /package/ios/HybridNavigation/Navigator/{HBDNavigatorRegistry.m → HBDNavigatorRegistry.mm} +0 -0
  129. /package/ios/HybridNavigation/{ReactBridge → React}/HBDNavigator.h +0 -0
  130. /package/ios/HybridNavigation/View/{HBDBackBarButtonItem.m → HBDBackBarButtonItem.mm} +0 -0
  131. /package/ios/HybridNavigation/View/{HBDBarButtonItem.m → HBDBarButtonItem.mm} +0 -0
  132. /package/ios/HybridNavigation/ViewController/{HBDFadeAnimation.m → HBDFadeAnimation.mm} +0 -0
  133. /package/ios/HybridNavigation/ViewController/{HBDNavigationController.m → HBDNavigationController.mm} +0 -0
  134. /package/ios/HybridNavigation/ViewController/{HBDPopAnimation.m → HBDPopAnimation.mm} +0 -0
  135. /package/ios/HybridNavigation/ViewController/{HBDPushAnimation.m → HBDPushAnimation.mm} +0 -0
  136. /package/ios/HybridNavigation/ViewController/{UINavigationController+HBD.m → UINavigationController+HBD.mm} +0 -0
@@ -1,265 +0,0 @@
1
- #import "HBDTabBarController.h"
2
-
3
- #import "HBDReactViewController.h"
4
- #import "HBDReactBridgeManager.h"
5
- #import "HBDUtils.h"
6
- #import "HBDEventEmitter.h"
7
- #import "HBDReactTabBar.h"
8
- #import "HBDFadeAnimation.h"
9
-
10
- #import <React/RCTRootView.h>
11
- #import <React/RCTRootViewDelegate.h>
12
- #import <React/RCTLog.h>
13
-
14
-
15
- @interface HBDTabBarController () <UITabBarControllerDelegate, RCTRootViewDelegate>
16
-
17
- @property(nonatomic, strong) RCTRootView *rootView;
18
- @property(nonatomic, copy) NSDictionary *tabBarOptions;
19
- @property(nonatomic, assign) BOOL hasCustomTabBar;
20
-
21
- @end
22
-
23
- @implementation HBDTabBarController
24
-
25
- - (instancetype)initWithTabBarOptions:(NSDictionary *)options {
26
- self.tabBarOptions = options;
27
- self.hasCustomTabBar = YES;
28
- return [super init];
29
- }
30
-
31
- - (UIViewController *)childViewControllerForStatusBarHidden {
32
- return self.selectedViewController;
33
- }
34
-
35
- - (UIViewController *)childViewControllerForHomeIndicatorAutoHidden {
36
- return self.selectedViewController;
37
- }
38
-
39
- - (void)viewDidLoad {
40
- [super viewDidLoad];
41
- self.definesPresentationContext = NO;
42
- self.delegate = self;
43
- self.intercepted = YES;
44
- if (self.hasCustomTabBar) {
45
- [self setValue:[[HBDReactTabBar alloc] init] forKey:@"tabBar"];
46
- [self customTabBar];
47
- }
48
- }
49
-
50
- - (void)viewWillLayoutSubviews {
51
- [super viewWillLayoutSubviews];
52
- if (self.hasCustomTabBar) {
53
- [self removeTabBarAboriginal];
54
- [self.tabBar bringSubviewToFront:self.rootView];
55
- }
56
- }
57
-
58
- - (void)customTabBar {
59
- NSString *moduleName = self.tabBarOptions[@"tabBarModuleName"];
60
- NSMutableDictionary *props = [[self props] mutableCopy];
61
- props[@"selectedIndex"] = self.tabBarOptions[@"selectedIndex"];
62
- RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:[HBDReactBridgeManager get].bridge moduleName:moduleName initialProperties:props];
63
- rootView.backgroundColor = UIColor.clearColor;
64
-
65
- BOOL sizeIndeterminate = [self.tabBarOptions[@"sizeIndeterminate"] boolValue];
66
- if (sizeIndeterminate) {
67
- rootView.delegate = self;
68
- rootView.passThroughTouches = YES;
69
- rootView.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
70
- } else {
71
- rootView.frame = CGRectMake(0, 1, CGRectGetWidth(self.tabBar.bounds), 48);
72
- }
73
- [self.tabBar addSubview:rootView];
74
- self.rootView = rootView;
75
- }
76
-
77
- - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
78
- CGFloat width = rootView.intrinsicContentSize.width;
79
- CGFloat height = rootView.intrinsicContentSize.height;
80
- CGRect frame = CGRectMake(0, 48 - height, width, height);
81
- self.rootView.frame = frame;
82
- }
83
-
84
- - (NSDictionary *)props {
85
- NSMutableDictionary *props = [[NSMutableDictionary alloc] init];
86
- NSDictionary *options = self.tabBarOptions;
87
- props[@"sceneId"] = self.sceneId;
88
- props[@"tabs"] = options[@"tabs"];
89
- props[@"selectedIndex"] = @(self.selectedIndex);
90
- props[@"badgeColor"] = options[@"badgeColor"];
91
-
92
- NSString *tabBarItemColor = options[@"tabBarItemColor"];
93
- NSString *tabBarUnselectedItemColor = options[@"tabBarUnselectedItemColor"];
94
- if (tabBarItemColor) {
95
- props[@"itemColor"] = tabBarItemColor;
96
- props[@"unselectedItemColor"] = RCTNullIfNil(tabBarUnselectedItemColor);
97
- }
98
- return props;
99
- }
100
-
101
- - (void)removeTabBarAboriginal {
102
- NSUInteger count = self.tabBar.subviews.count;
103
- for (NSUInteger i = count; i > 0; i--) {
104
- NSUInteger index = i - 1;
105
- UIView *view = self.tabBar.subviews[index];
106
- NSString *viewName = [[[view classForCoder] description] stringByReplacingOccurrencesOfString:@"_" withString:@""];
107
- if ([viewName isEqualToString:@"UITabBarButton"]) {
108
- [view removeFromSuperview];
109
- }
110
- }
111
- }
112
-
113
- - (void)setTabItem:(NSArray<NSDictionary *> *)options {
114
- for (NSDictionary *option in options) {
115
- NSUInteger index = (NSUInteger) (option[@"index"] ? [option[@"index"] integerValue] : 0);
116
- if (self.hasCustomTabBar) {
117
- [self updateCustomTabItem:option atIndex:index];
118
- } else {
119
- UIViewController *tab = self.viewControllers[index];
120
- [tab hbd_updateTabBarItem:option];
121
- }
122
- }
123
-
124
- if (self.hasCustomTabBar) {
125
- self.rootView.appProperties = [self props];
126
- }
127
- }
128
-
129
- - (NSMutableDictionary *)tabAtIndex:(NSUInteger)index {
130
- NSMutableDictionary *options = [self.tabBarOptions mutableCopy];
131
- NSMutableArray *tabs = [options[@"tabs"] mutableCopy];
132
- options[@"tabs"] = tabs;
133
- NSMutableDictionary *tab = [tabs[index] mutableCopy];
134
- tabs[index] = tab;
135
- self.tabBarOptions = options;
136
- return tab;
137
- }
138
-
139
- - (void)updateCustomTabItem:(NSDictionary *)option atIndex:(NSUInteger)index {
140
- NSMutableDictionary *tab = [self tabAtIndex:index];
141
-
142
- // title
143
- NSString *title = option[@"title"];
144
- if (title != nil) {
145
- tab[@"title"] = title;
146
- }
147
-
148
- // icon title
149
- NSDictionary *icon = option[@"icon"];
150
- if (icon != nil) {
151
- NSDictionary *selected = icon[@"selected"];
152
- tab[@"icon"] = [HBDUtils iconUriFromUri:selected[@"uri"]];
153
-
154
- NSDictionary *unselected = icon[@"unselected"];
155
- if (unselected != nil) {
156
- tab[@"unselectedIcon"] = RCTNullIfNil([HBDUtils iconUriFromUri:unselected[@"uri"]]);
157
- }
158
- }
159
-
160
- // badge
161
- NSDictionary *badge = option[@"badge"];
162
- if (badge != nil) {
163
- BOOL hidden = badge[@"hidden"] ? [badge[@"hidden"] boolValue] : YES;
164
- NSString *text = hidden ? nil : (badge[@"text"] ? badge[@"text"] : nil);
165
- BOOL dot = hidden ? NO : (badge[@"dot"] ? [badge[@"dot"] boolValue] : NO);
166
- tab[@"dot"] = @(dot);
167
- tab[@"badgeText"] = RCTNullIfNil(text);
168
- }
169
- }
170
-
171
- - (void)updateTabBar:(NSDictionary *)options {
172
- UITabBar *tabBar = self.tabBar;
173
- NSString *tabBarColor = options[@"tabBarColor"];
174
- if (tabBarColor) {
175
- if (@available(iOS 15.0, *)) {
176
- [tabBar standardAppearance].backgroundImage = [HBDUtils imageWithColor:[HBDUtils colorWithHexString:tabBarColor]];
177
- [tabBar scrollEdgeAppearance].backgroundImage = [HBDUtils imageWithColor:[HBDUtils colorWithHexString:tabBarColor]];
178
- } else {
179
- [tabBar setBackgroundImage:[HBDUtils imageWithColor:[HBDUtils colorWithHexString:tabBarColor]]];
180
- }
181
- }
182
-
183
- NSDictionary *tabBarShadowImage = options[@"tabBarShadowImage"];
184
- if (RCTNilIfNull(tabBarShadowImage)) {
185
- UIImage *image = [UIImage new];
186
- NSDictionary *imageItem = tabBarShadowImage[@"image"];
187
- NSString *color = tabBarShadowImage[@"color"];
188
- if (imageItem) {
189
- image = [HBDUtils UIImage:imageItem];
190
- } else if (color) {
191
- image = [HBDUtils imageWithColor:[HBDUtils colorWithHexString:color]];
192
- }
193
- tabBar.shadowImage = image;
194
- }
195
-
196
- NSString *tabBarItemColor = options[@"tabBarItemColor"];
197
- NSString *tabBarUnselectedItemColor = options[@"tabBarUnselectedItemColor"];
198
- if (tabBarItemColor) {
199
- if (self.hasCustomTabBar) {
200
- NSMutableDictionary *options = [self.tabBarOptions mutableCopy];
201
- options[@"tabBarItemColor"] = tabBarItemColor;
202
- options[@"tabBarUnselectedItemColor"] = RCTNullIfNil(tabBarUnselectedItemColor);
203
- self.tabBarOptions = options;
204
- self.rootView.appProperties = [self props];
205
- } else {
206
- tabBar.tintColor = [HBDUtils colorWithHexString:tabBarItemColor];
207
- if (tabBarUnselectedItemColor) {
208
- tabBar.unselectedItemTintColor = [HBDUtils colorWithHexString:tabBarUnselectedItemColor];
209
- }
210
- }
211
- }
212
- }
213
-
214
- - (void)didReceiveResultCode:(NSInteger)resultCode resultData:(NSDictionary *)data requestCode:(NSInteger)requestCode {
215
- [super didReceiveResultCode:resultCode resultData:data requestCode:requestCode];
216
- if (self.hasCustomTabBar) {
217
- [HBDEventEmitter sendEvent:EVENT_NAVIGATION data:@{
218
- KEY_ON: ON_COMPONENT_RESULT,
219
- KEY_REQUEST_CODE: @(requestCode),
220
- KEY_RESULT_CODE: @(resultCode),
221
- KEY_RESULT_DATA: RCTNullIfNil(data),
222
- KEY_SCENE_ID: self.sceneId,
223
- }];
224
- }
225
- }
226
-
227
- - (void)setSelectedIndex:(NSUInteger)selectedIndex {
228
- [self setSelectedViewController:self.viewControllers[selectedIndex]];
229
- }
230
-
231
- - (void)setSelectedViewController:(__kindof UIViewController *)selectedViewController {
232
- NSUInteger index = [self.viewControllers indexOfObject:selectedViewController];
233
- [super setSelectedViewController:selectedViewController];
234
-
235
- if (self.hasCustomTabBar && self.rootView) {
236
- NSMutableDictionary *props = [[self props] mutableCopy];
237
- props[@"selectedIndex"] = @(index);
238
- self.rootView.appProperties = props;
239
- }
240
- }
241
-
242
- - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
243
- if ([[HBDReactBridgeManager get] hasRootLayout] && self.intercepted) {
244
- long from = self.selectedIndex;
245
- long to = [self.childViewControllers indexOfObject:viewController];
246
-
247
- [HBDEventEmitter sendEvent:EVENT_SWITCH_TAB data:@{
248
- KEY_SCENE_ID: self.sceneId,
249
- KEY_INDEX: [NSString stringWithFormat:@"%ld-%ld", from, to],
250
- }];
251
- return NO;
252
- }
253
- return YES;
254
- }
255
-
256
- - (id<UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController animationControllerForTransitionFromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC {
257
-
258
- if (toVC.viewLoaded) {
259
- return nil;
260
- }
261
-
262
- return [[HBDFadeAnimation alloc] init];
263
- }
264
-
265
- @end
package/src/Event.ts DELETED
@@ -1,117 +0,0 @@
1
- import {NativeModules, NativeEventEmitter, NativeModule} from 'react-native';
2
- import type {Visibility} from './Route';
3
- interface HBDEventEmitter extends NativeModule {
4
- getConstants: () => {
5
- EVENT_NAVIGATION: string;
6
- EVENT_SWITCH_TAB: string;
7
- EVENT_DID_SET_ROOT: string;
8
- EVENT_WILL_SET_ROOT: string;
9
- ON_COMPONENT_RESULT: string;
10
- ON_BAR_BUTTON_ITEM_CLICK: string;
11
- ON_COMPONENT_APPEAR: string;
12
- ON_COMPONENT_DISAPPEAR: string;
13
- KEY_REQUEST_CODE: string;
14
- KEY_RESULT_CODE: string;
15
- KEY_RESULT_DATA: string;
16
- KEY_SCENE_ID: string;
17
- KEY_MODULE_NAME: string;
18
- KEY_INDEX: string;
19
- KEY_ACTION: string;
20
- KEY_ON: string;
21
- };
22
- }
23
-
24
- const HBDEventEmitter: HBDEventEmitter = NativeModules.HBDEventEmitter;
25
- const HBDEventReceiver = new NativeEventEmitter(HBDEventEmitter);
26
-
27
- function listenComponentResult(
28
- listener: (
29
- sceneId: string,
30
- requestCode: number,
31
- resultCode: number,
32
- resultData: object,
33
- ) => void,
34
- ) {
35
- const {
36
- EVENT_NAVIGATION,
37
- KEY_ON,
38
- ON_COMPONENT_RESULT,
39
- KEY_REQUEST_CODE,
40
- KEY_RESULT_CODE,
41
- KEY_RESULT_DATA,
42
- KEY_SCENE_ID,
43
- } = HBDEventEmitter.getConstants();
44
-
45
- return HBDEventReceiver.addListener(EVENT_NAVIGATION, data => {
46
- if (data[KEY_ON] === ON_COMPONENT_RESULT) {
47
- const requestCode = data[KEY_REQUEST_CODE];
48
- const resultCode = data[KEY_RESULT_CODE];
49
- const resultData = data[KEY_RESULT_DATA];
50
- const sceneId = data[KEY_SCENE_ID];
51
-
52
- listener(sceneId, requestCode, resultCode, resultData);
53
- }
54
- });
55
- }
56
-
57
- function listenComponentVisibility(listener: (sceneId: string, visibility: Visibility) => void) {
58
- const {EVENT_NAVIGATION, KEY_ON, ON_COMPONENT_APPEAR, ON_COMPONENT_DISAPPEAR, KEY_SCENE_ID} =
59
- HBDEventEmitter.getConstants();
60
-
61
- return HBDEventReceiver.addListener(EVENT_NAVIGATION, data => {
62
- if (data[KEY_ON] === ON_COMPONENT_APPEAR) {
63
- listener(data[KEY_SCENE_ID], 'visible');
64
- }
65
-
66
- if (data[KEY_ON] === ON_COMPONENT_DISAPPEAR) {
67
- listener(data[KEY_SCENE_ID], 'invisible');
68
- }
69
- });
70
- }
71
-
72
- function listenBarButtonItemClick(listener: (sceneId: string, action: string) => void) {
73
- const {EVENT_NAVIGATION, KEY_ON, ON_BAR_BUTTON_ITEM_CLICK, KEY_ACTION, KEY_SCENE_ID} =
74
- HBDEventEmitter.getConstants();
75
-
76
- return HBDEventReceiver.addListener(
77
- EVENT_NAVIGATION,
78
- data => {
79
- if (data[KEY_ON] === ON_BAR_BUTTON_ITEM_CLICK) {
80
- listener(data[KEY_SCENE_ID], data[KEY_ACTION]);
81
- }
82
- },
83
- {},
84
- );
85
- }
86
-
87
- function listenTabSwitch(listener: (sceneId: string, from: number, to: number) => void) {
88
- const {EVENT_SWITCH_TAB, KEY_INDEX, KEY_SCENE_ID} = HBDEventEmitter.getConstants();
89
- return HBDEventReceiver.addListener(EVENT_SWITCH_TAB, event => {
90
- const index = event[KEY_INDEX];
91
- const [from, to] = index.split('-');
92
- listener(event[KEY_SCENE_ID], parseInt(from, 10), parseInt(to, 10));
93
- });
94
- }
95
-
96
- function listenWillSetRoot(willSetRoot: () => void) {
97
- const {EVENT_WILL_SET_ROOT} = HBDEventEmitter.getConstants();
98
- return HBDEventReceiver.addListener(EVENT_WILL_SET_ROOT, _ => {
99
- willSetRoot();
100
- });
101
- }
102
-
103
- function listenDidSetRoot(didSetRoot: (tag: number) => void) {
104
- const {EVENT_DID_SET_ROOT} = HBDEventEmitter.getConstants();
105
- return HBDEventReceiver.addListener(EVENT_DID_SET_ROOT, (event: {tag: number}) => {
106
- didSetRoot(event.tag);
107
- });
108
- }
109
-
110
- export default {
111
- listenBarButtonItemClick,
112
- listenComponentResult,
113
- listenComponentVisibility,
114
- listenTabSwitch,
115
- listenWillSetRoot,
116
- listenDidSetRoot,
117
- };
@@ -1,50 +0,0 @@
1
- import {NativeModules, NativeModule, NativeEventEmitter, Platform} from 'react-native';
2
-
3
- interface GardenModule extends NativeModule {
4
- getConstants: () => {
5
- TOOLBAR_HEIGHT: number;
6
- STATUSBAR_HEIGHT: number;
7
- EVENT_STATUSBAR_FRAME_CHANGE: string;
8
- };
9
-
10
- setStyle: (style: object) => void;
11
- setTitleItem: (sceneId: string, item: object) => void;
12
- setLeftBarButtonItem: (sceneId: string, item: object | null) => void;
13
- setRightBarButtonItem: (sceneId: string, item: object | null) => void;
14
- setLeftBarButtonItems: (sceneId: string, item: object | null) => void;
15
- setRightBarButtonItems: (sceneId: string, item: object | null) => void;
16
- updateOptions: (sceneId: string, options: object) => void;
17
- updateTabBar: (sceneId: string, item: object) => void;
18
- setTabItem: (sceneId: string, item: object) => void;
19
- setMenuInteractive: (sceneId: string, enabled: boolean) => void;
20
- }
21
-
22
- const GardenModule: GardenModule = NativeModules.GardenModule;
23
-
24
- const {STATUSBAR_HEIGHT, TOOLBAR_HEIGHT, EVENT_STATUSBAR_FRAME_CHANGE} =
25
- GardenModule.getConstants();
26
-
27
- let _statusBarHeight = STATUSBAR_HEIGHT;
28
-
29
- if (Platform.OS === 'ios') {
30
- const GardenEventReceiver = new NativeEventEmitter(GardenModule);
31
- GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({statusBarHeight: height}) => {
32
- _statusBarHeight = height;
33
- });
34
- }
35
-
36
- function statusBarHeight() {
37
- return _statusBarHeight;
38
- }
39
-
40
- function toolbarHeight() {
41
- return TOOLBAR_HEIGHT;
42
- }
43
-
44
- function topBarHeight() {
45
- return statusBarHeight() + toolbarHeight();
46
- }
47
-
48
- export {statusBarHeight, toolbarHeight, topBarHeight};
49
-
50
- export default GardenModule;