hybrid-navigation 2.13.0-beta.2 → 2.13.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.
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +3 -20
- package/ios/HybridNavigation/HBDUtils.h +3 -6
- package/ios/HybridNavigation/HBDUtils.m +10 -0
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +7 -2
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +1 -1
- package/ios/HybridNavigation/View/HBDRootView.m +9 -3
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +0 -30
- package/ios/HybridNavigation/ViewController/HBDViewController.m +7 -3
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -3
- package/lib/Event.d.ts +18 -0
- package/lib/Event.js +71 -0
- package/lib/Garden.d.ts +46 -68
- package/lib/Garden.js +53 -70
- package/lib/GardenModule.d.ts +20 -0
- package/lib/GardenModule.js +3 -0
- package/lib/Navigation.d.ts +74 -0
- package/lib/Navigation.js +182 -0
- package/lib/NavigationComponentWrap.d.ts +19 -0
- package/lib/NavigationComponentWrap.js +46 -0
- package/lib/NavigationModule.d.ts +33 -22
- package/lib/NavigationModule.js +79 -22
- package/lib/Navigator.d.ts +55 -28
- package/lib/Navigator.js +122 -263
- package/lib/{typing.d.ts → Options.d.ts} +46 -50
- package/lib/{typing.js → Options.js} +0 -0
- package/lib/ReactRegistry.d.ts +16 -14
- package/lib/ReactRegistry.js +18 -93
- package/lib/Route.d.ts +74 -0
- package/lib/{router/typing.js → Route.js} +0 -0
- package/lib/handler/BarButtonEventHandler.d.ts +10 -0
- package/lib/handler/BarButtonEventHandler.js +38 -0
- package/lib/handler/DispatchCommandHandler.d.ts +24 -0
- package/lib/handler/DispatchCommandHandler.js +28 -0
- package/lib/handler/LayoutCommandHandler.d.ts +11 -0
- package/lib/handler/LayoutCommandHandler.js +39 -0
- package/lib/handler/ResultEventHandler.d.ts +15 -0
- package/lib/handler/ResultEventHandler.js +47 -0
- package/lib/handler/VisibilityEventHandler.d.ts +13 -0
- package/lib/handler/VisibilityEventHandler.js +32 -0
- package/lib/hooks.d.ts +0 -1
- package/lib/hooks.js +14 -29
- package/lib/index.d.ts +10 -2
- package/lib/index.js +17 -2
- package/lib/router/drawer.d.ts +1 -1
- package/lib/router/index.d.ts +4 -7
- package/lib/router/index.js +13 -6
- package/lib/router/screen.d.ts +1 -1
- package/lib/router/stack.d.ts +1 -1
- package/lib/router/tabs.d.ts +1 -1
- package/lib/store.d.ts +0 -9
- package/lib/store.js +0 -22
- package/package.json +1 -1
- package/src/Event.ts +123 -0
- package/src/Garden.ts +63 -149
- package/src/GardenModule.ts +24 -0
- package/src/Navigation.ts +278 -0
- package/src/NavigationComponentWrap.tsx +73 -0
- package/src/NavigationModule.ts +118 -29
- package/src/Navigator.ts +147 -319
- package/src/{typing.ts → Options.ts} +51 -57
- package/src/ReactRegistry.tsx +25 -127
- package/src/Route.ts +88 -0
- package/src/handler/BarButtonEventHandler.ts +50 -0
- package/src/handler/DispatchCommandHandler.ts +56 -0
- package/src/handler/LayoutCommandHandler.ts +49 -0
- package/src/handler/ResultEventHandler.ts +67 -0
- package/src/handler/VisibilityEventHandler.ts +44 -0
- package/src/hooks.ts +13 -38
- package/src/index.ts +38 -3
- package/src/router/drawer.ts +1 -1
- package/src/router/index.ts +36 -12
- package/src/router/screen.ts +1 -1
- package/src/router/stack.ts +1 -1
- package/src/router/tabs.ts +1 -1
- package/src/store.ts +0 -28
- package/lib/router/typing.d.ts +0 -37
- package/lib/utils.d.ts +0 -9
- package/lib/utils.js +0 -50
- package/src/router/typing.ts +0 -45
- package/src/utils.ts +0 -83
|
@@ -28,7 +28,6 @@ import com.facebook.react.bridge.ReactContext;
|
|
|
28
28
|
import com.facebook.react.common.LifecycleState;
|
|
29
29
|
import com.navigation.androidx.FragmentHelper;
|
|
30
30
|
import com.navigation.androidx.Style;
|
|
31
|
-
import com.navigation.androidx.TransitionAnimation;
|
|
32
31
|
|
|
33
32
|
public class ReactFragment extends HybridFragment implements ReactRootViewHolder.VisibilityObserver, ReactBridgeManager.ReactBridgeReloadListener {
|
|
34
33
|
|
|
@@ -49,11 +48,8 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
|
|
|
49
48
|
reactRootViewHolder = (ReactRootViewHolder) containerLayout;
|
|
50
49
|
reactRootViewHolder.setVisibilityObserver(this);
|
|
51
50
|
}
|
|
52
|
-
|
|
51
|
+
|
|
53
52
|
if (!FragmentHelper.isHidden(this) || getShowsDialog()) {
|
|
54
|
-
if (getAnimation() != TransitionAnimation.None) {
|
|
55
|
-
postponeEnterTransition();
|
|
56
|
-
}
|
|
57
53
|
initReactRootView();
|
|
58
54
|
}
|
|
59
55
|
|
|
@@ -201,8 +197,7 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
|
|
|
201
197
|
return;
|
|
202
198
|
}
|
|
203
199
|
firstRenderCompleted = true;
|
|
204
|
-
|
|
205
|
-
|
|
200
|
+
|
|
206
201
|
if (isViewReady() && isResumed()) {
|
|
207
202
|
sendViewAppearEvent(true);
|
|
208
203
|
reactRootView.addOnGlobalLayoutListener();
|
|
@@ -301,17 +296,5 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
|
|
|
301
296
|
}
|
|
302
297
|
return new Toolbar.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity.CENTER);
|
|
303
298
|
}
|
|
304
|
-
|
|
305
|
-
@Override
|
|
306
|
-
public void postponeEnterTransition() {
|
|
307
|
-
super.postponeEnterTransition();
|
|
308
|
-
requireActivity().supportPostponeEnterTransition();
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
@Override
|
|
312
|
-
public void startPostponedEnterTransition() {
|
|
313
|
-
super.startPostponedEnterTransition();
|
|
314
|
-
requireActivity().supportStartPostponedEnterTransition();
|
|
315
|
-
}
|
|
316
|
-
|
|
299
|
+
|
|
317
300
|
}
|
|
@@ -5,12 +5,7 @@ UIKIT_STATIC_INLINE BOOL colorHasAlphaComponent(UIColor *color) {
|
|
|
5
5
|
if (!color) {
|
|
6
6
|
return YES;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
CGFloat green = 0;
|
|
10
|
-
CGFloat blue = 0;
|
|
11
|
-
CGFloat alpha = 0;
|
|
12
|
-
[color getRed:&red green:&green blue:&blue alpha:&alpha];
|
|
13
|
-
return alpha < 1.0;
|
|
8
|
+
return CGColorGetAlpha(color.CGColor) < 1.0;
|
|
14
9
|
}
|
|
15
10
|
|
|
16
11
|
UIKIT_STATIC_INLINE BOOL imageHasAlphaChannel(UIImage *image) {
|
|
@@ -51,4 +46,6 @@ UIKIT_STATIC_INLINE void hbd_exchangeImplementations(Class clazz, SEL originalSe
|
|
|
51
46
|
|
|
52
47
|
+ (BOOL)isInCall;
|
|
53
48
|
|
|
49
|
+
+ (void)printViewHierarchy:(UIView *)view withPrefix:(NSString *)prefix;
|
|
50
|
+
|
|
54
51
|
@end
|
|
@@ -178,6 +178,16 @@
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
+ (void)printViewHierarchy:(UIView *)view withPrefix:(NSString *)prefix {
|
|
182
|
+
NSString *viewName = [[[view classForCoder] description] stringByReplacingOccurrencesOfString:@"_" withString:@""];
|
|
183
|
+
NSLog(@"%@%@ %@", prefix, viewName, NSStringFromCGRect(view.frame));
|
|
184
|
+
if (view.subviews.count > 0) {
|
|
185
|
+
for (UIView *sub in view.subviews) {
|
|
186
|
+
[self printViewHierarchy:sub withPrefix:[NSString stringWithFormat:@"--%@", prefix]];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
181
191
|
static void (*__SWZ_didMoveToWindow_orig)(id self, SEL _cmd);
|
|
182
192
|
|
|
183
193
|
static void __HBD_didMoveToWindow(UIView *self, SEL _cmd) {
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
- (void)handlePushWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras
|
|
121
|
+
- (void)handlePushWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
122
122
|
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
123
123
|
if (!vc) {
|
|
124
124
|
callback(@[NSNull.null, @NO]);
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
[self animateAlongsideTransition:nav callback:callback];
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
- (void)handlePopToWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras
|
|
139
|
+
- (void)handlePopToWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
140
140
|
UIViewController *vc = [self findViewControllerWithNavigationController:nav extras:extras];
|
|
141
141
|
if (!vc) {
|
|
142
142
|
callback(@[NSNull.null, @NO]);
|
|
@@ -172,6 +172,11 @@
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
- (void)handleRedirectToWithNavigationController:(UINavigationController *)nav target:(UIViewController *)target extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
175
|
+
if (![nav.childViewControllers containsObject:target]) {
|
|
176
|
+
callback(@[NSNull.null, @NO]);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
175
180
|
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
176
181
|
if (!vc) {
|
|
177
182
|
callback(@[NSNull.null, @NO]);
|
|
@@ -61,7 +61,7 @@ RCT_EXPORT_METHOD(signalFirstRenderComplete:(NSString *) sceneId) {
|
|
|
61
61
|
// RCTLogInfo(@"[Navigator] signalFirstRenderComplete sceneId:%@", sceneId);
|
|
62
62
|
UIViewController *vc = [self.bridgeManager viewControllerWithSceneId:sceneId];
|
|
63
63
|
if ([vc isKindOfClass:[HBDReactViewController class]]) {
|
|
64
|
-
[(HBDReactViewController *)
|
|
64
|
+
[(HBDReactViewController *)vc signalFirstRenderComplete];
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
@implementation HBDRootView
|
|
10
10
|
|
|
11
11
|
- (instancetype)initWithRootView:(RCTRootView *)rootView {
|
|
12
|
-
if (self = [super
|
|
12
|
+
if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
|
|
13
13
|
_rootView = rootView;
|
|
14
14
|
}
|
|
15
15
|
return self;
|
|
@@ -17,8 +17,14 @@
|
|
|
17
17
|
|
|
18
18
|
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
|
|
19
19
|
UIView *hitView = [super hitTest:point withEvent:event];
|
|
20
|
-
if (self.rootView.passThroughTouches
|
|
21
|
-
|
|
20
|
+
if (self.rootView.passThroughTouches) {
|
|
21
|
+
if (hitView == self) {
|
|
22
|
+
return nil;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (hitView && CGRectEqualToRect(hitView.frame, self.rootView.bounds)) {
|
|
26
|
+
return nil;
|
|
27
|
+
}
|
|
22
28
|
}
|
|
23
29
|
return hitView;
|
|
24
30
|
}
|
|
@@ -11,36 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
#define hairlineWidth (1.f/[UIScreen mainScreen].scale)
|
|
13
13
|
|
|
14
|
-
UIColor *blendColor(UIColor *from, UIColor *to, CGFloat percent) {
|
|
15
|
-
CGFloat fromRed = 0;
|
|
16
|
-
CGFloat fromGreen = 0;
|
|
17
|
-
CGFloat fromBlue = 0;
|
|
18
|
-
CGFloat fromAlpha = 0;
|
|
19
|
-
[from getRed:&fromRed green:&fromGreen blue:&fromBlue alpha:&fromAlpha];
|
|
20
|
-
|
|
21
|
-
CGFloat toRed = 0;
|
|
22
|
-
CGFloat toGreen = 0;
|
|
23
|
-
CGFloat toBlue = 0;
|
|
24
|
-
CGFloat toAlpha = 0;
|
|
25
|
-
[to getRed:&toRed green:&toGreen blue:&toBlue alpha:&toAlpha];
|
|
26
|
-
|
|
27
|
-
CGFloat newRed = fromRed + (toRed - fromRed) * fminf(1, (float) (percent * 4));
|
|
28
|
-
CGFloat newGreen = fromGreen + (toGreen - fromGreen) * fminf(1, (float) (percent * 4));
|
|
29
|
-
CGFloat newBlue = fromBlue + (toBlue - fromBlue) * fminf(1, (float) (percent * 4));
|
|
30
|
-
CGFloat newAlpha = fromAlpha + (toAlpha - fromAlpha) * fminf(1, (float) (percent * 4));
|
|
31
|
-
return [UIColor colorWithRed:newRed green:newGreen blue:newBlue alpha:newAlpha];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
void printViewHierarchy(UIView *view, NSString *prefix) {
|
|
35
|
-
NSString *viewName = [[[view classForCoder] description] stringByReplacingOccurrencesOfString:@"_" withString:@""];
|
|
36
|
-
NSLog(@"%@%@ %@", prefix, viewName, NSStringFromCGRect(view.frame));
|
|
37
|
-
if (view.subviews.count > 0) {
|
|
38
|
-
for (UIView *sub in view.subviews) {
|
|
39
|
-
printViewHierarchy(sub, [NSString stringWithFormat:@"--%@", prefix]);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
14
|
@interface HBDNavigationControllerDelegate : UIScreenEdgePanGestureRecognizer <UINavigationControllerDelegate, UIGestureRecognizerDelegate>
|
|
45
15
|
|
|
46
16
|
@property(nonatomic, weak) id <UINavigationControllerDelegate> proxyDelegate;
|
|
@@ -201,8 +201,12 @@
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
if ([GlobalStyle globalStyle].isBackTitleHidden) {
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
if (@available(iOS 14.0, *)) {
|
|
205
|
+
self.navigationItem.backButtonDisplayMode = UINavigationItemBackButtonDisplayModeMinimal;
|
|
206
|
+
} else {
|
|
207
|
+
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:NULL];
|
|
208
|
+
self.navigationItem.backBarButtonItem = buttonItem;
|
|
209
|
+
}
|
|
206
210
|
}
|
|
207
211
|
|
|
208
212
|
NSDictionary *backItem = options[@"backItemIOS"];
|
|
@@ -215,7 +219,7 @@
|
|
|
215
219
|
}
|
|
216
220
|
self.navigationItem.backBarButtonItem = backButton;
|
|
217
221
|
}
|
|
218
|
-
|
|
222
|
+
|
|
219
223
|
NSNumber *swipeBackEnabled = options[@"swipeBackEnabled"];
|
|
220
224
|
if (swipeBackEnabled) {
|
|
221
225
|
self.hbd_swipeBackEnabled = [swipeBackEnabled boolValue];
|
|
@@ -9,9 +9,6 @@
|
|
|
9
9
|
- (void)redirectToViewController:(UIViewController *)controller target:(UIViewController *)target animated:(BOOL)animated {
|
|
10
10
|
NSMutableArray *children = [self.childViewControllers mutableCopy];
|
|
11
11
|
NSUInteger index = [children indexOfObject:target];
|
|
12
|
-
if (index == NSNotFound) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
12
|
NSUInteger count = self.childViewControllers.count;
|
|
16
13
|
[children removeObjectsInRange:NSMakeRange(index, count - index)];
|
|
17
14
|
[children addObject:controller];
|
package/lib/Event.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Visibility } from './Route';
|
|
2
|
+
declare function listenStatusBarHeightChange(listener: (statusBarHeight: number) => void): import("react-native").EmitterSubscription;
|
|
3
|
+
declare function listenComponentResult(listener: (sceneId: string, requestCode: number, resultCode: number, resultData: object) => void): import("react-native").EmitterSubscription;
|
|
4
|
+
declare function listenComponentVisibility(listener: (sceneId: string, visibility: Visibility) => void): import("react-native").EmitterSubscription;
|
|
5
|
+
declare function listenBarButtonItemClick(listener: (sceneId: string, action: string) => void): import("react-native").EmitterSubscription;
|
|
6
|
+
declare function listenTabSwitch(listener: (sceneId: string, from: number, to: number) => void): import("react-native").EmitterSubscription;
|
|
7
|
+
declare function listenWillSetRoot(willSetRoot: () => void): import("react-native").EmitterSubscription;
|
|
8
|
+
declare function listenDidSetRoot(didSetRoot: (tag: number) => void): import("react-native").EmitterSubscription;
|
|
9
|
+
declare const _default: {
|
|
10
|
+
listenStatusBarHeightChange: typeof listenStatusBarHeightChange;
|
|
11
|
+
listenBarButtonItemClick: typeof listenBarButtonItemClick;
|
|
12
|
+
listenComponentResult: typeof listenComponentResult;
|
|
13
|
+
listenComponentVisibility: typeof listenComponentVisibility;
|
|
14
|
+
listenTabSwitch: typeof listenTabSwitch;
|
|
15
|
+
listenWillSetRoot: typeof listenWillSetRoot;
|
|
16
|
+
listenDidSetRoot: typeof listenDidSetRoot;
|
|
17
|
+
};
|
|
18
|
+
export default _default;
|
package/lib/Event.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
2
|
+
import GardenModule from './GardenModule';
|
|
3
|
+
function listenStatusBarHeightChange(listener) {
|
|
4
|
+
const GardenEventReceiver = new NativeEventEmitter(GardenModule);
|
|
5
|
+
const { EVENT_STATUSBAR_FRAME_CHANGE } = GardenModule.getConstants();
|
|
6
|
+
return GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight }) => {
|
|
7
|
+
listener(statusBarHeight);
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
const HBDEventEmitter = NativeModules.HBDEventEmitter;
|
|
11
|
+
const HBDEventReceiver = new NativeEventEmitter(HBDEventEmitter);
|
|
12
|
+
function listenComponentResult(listener) {
|
|
13
|
+
const { EVENT_NAVIGATION, KEY_ON, ON_COMPONENT_RESULT, KEY_REQUEST_CODE, KEY_RESULT_CODE, KEY_RESULT_DATA, KEY_SCENE_ID, } = HBDEventEmitter.getConstants();
|
|
14
|
+
return HBDEventReceiver.addListener(EVENT_NAVIGATION, data => {
|
|
15
|
+
if (data[KEY_ON] === ON_COMPONENT_RESULT) {
|
|
16
|
+
const requestCode = data[KEY_REQUEST_CODE];
|
|
17
|
+
const resultCode = data[KEY_RESULT_CODE];
|
|
18
|
+
const resultData = data[KEY_RESULT_DATA];
|
|
19
|
+
const sceneId = data[KEY_SCENE_ID];
|
|
20
|
+
listener(sceneId, requestCode, resultCode, resultData);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function listenComponentVisibility(listener) {
|
|
25
|
+
const { EVENT_NAVIGATION, KEY_ON, ON_COMPONENT_APPEAR, ON_COMPONENT_DISAPPEAR, KEY_SCENE_ID } = HBDEventEmitter.getConstants();
|
|
26
|
+
return HBDEventReceiver.addListener(EVENT_NAVIGATION, data => {
|
|
27
|
+
if (data[KEY_ON] === ON_COMPONENT_APPEAR) {
|
|
28
|
+
listener(data[KEY_SCENE_ID], 'visible');
|
|
29
|
+
}
|
|
30
|
+
if (data[KEY_ON] === ON_COMPONENT_DISAPPEAR) {
|
|
31
|
+
listener(data[KEY_SCENE_ID], 'invisible');
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function listenBarButtonItemClick(listener) {
|
|
36
|
+
const { EVENT_NAVIGATION, KEY_ON, ON_BAR_BUTTON_ITEM_CLICK, KEY_ACTION, KEY_SCENE_ID } = HBDEventEmitter.getConstants();
|
|
37
|
+
return HBDEventReceiver.addListener(EVENT_NAVIGATION, data => {
|
|
38
|
+
if (data[KEY_ON] === ON_BAR_BUTTON_ITEM_CLICK) {
|
|
39
|
+
listener(data[KEY_SCENE_ID], data[KEY_ACTION]);
|
|
40
|
+
}
|
|
41
|
+
}, {});
|
|
42
|
+
}
|
|
43
|
+
function listenTabSwitch(listener) {
|
|
44
|
+
const { EVENT_SWITCH_TAB, KEY_INDEX, KEY_SCENE_ID } = HBDEventEmitter.getConstants();
|
|
45
|
+
return HBDEventReceiver.addListener(EVENT_SWITCH_TAB, event => {
|
|
46
|
+
const index = event[KEY_INDEX];
|
|
47
|
+
const [from, to] = index.split('-');
|
|
48
|
+
listener(event[KEY_SCENE_ID], parseInt(from, 10), parseInt(to, 10));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function listenWillSetRoot(willSetRoot) {
|
|
52
|
+
const { EVENT_WILL_SET_ROOT } = HBDEventEmitter.getConstants();
|
|
53
|
+
return HBDEventReceiver.addListener(EVENT_WILL_SET_ROOT, _ => {
|
|
54
|
+
willSetRoot();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function listenDidSetRoot(didSetRoot) {
|
|
58
|
+
const { EVENT_DID_SET_ROOT } = HBDEventEmitter.getConstants();
|
|
59
|
+
return HBDEventReceiver.addListener(EVENT_DID_SET_ROOT, (event) => {
|
|
60
|
+
didSetRoot(event.tag);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export default {
|
|
64
|
+
listenStatusBarHeightChange,
|
|
65
|
+
listenBarButtonItemClick,
|
|
66
|
+
listenComponentResult,
|
|
67
|
+
listenComponentVisibility,
|
|
68
|
+
listenTabSwitch,
|
|
69
|
+
listenWillSetRoot,
|
|
70
|
+
listenDidSetRoot,
|
|
71
|
+
};
|
package/lib/Garden.d.ts
CHANGED
|
@@ -1,84 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export interface ShadowImage {
|
|
3
|
-
image?: ImageSource;
|
|
4
|
-
color?: Color;
|
|
5
|
-
}
|
|
6
|
-
export interface Style {
|
|
7
|
-
screenBackgroundColor?: Color;
|
|
8
|
-
topBarStyle?: BarStyle;
|
|
9
|
-
topBarColor?: Color;
|
|
10
|
-
topBarColorDarkContent?: Color;
|
|
11
|
-
topBarColorLightContent?: Color;
|
|
12
|
-
statusBarColorAndroid?: Color;
|
|
13
|
-
navigationBarColorAndroid?: Color;
|
|
14
|
-
hideBackTitleIOS?: boolean;
|
|
15
|
-
elevationAndroid?: number;
|
|
16
|
-
shadowImage?: ShadowImage;
|
|
17
|
-
backIcon?: ImageSource;
|
|
18
|
-
topBarTintColor?: Color;
|
|
19
|
-
topBarTintColorDarkContent?: Color;
|
|
20
|
-
topBarTintColorLightContent?: Color;
|
|
21
|
-
titleTextColor?: Color;
|
|
22
|
-
titleTextColorDarkContent?: Color;
|
|
23
|
-
titleTextColorLightContent?: Color;
|
|
24
|
-
titleTextSize?: number;
|
|
25
|
-
titleAlignmentAndroid?: TitleAlignment;
|
|
26
|
-
barButtonItemTextSize?: number;
|
|
27
|
-
swipeBackEnabledAndroid?: boolean;
|
|
28
|
-
splitTopBarTransitionIOS?: boolean;
|
|
29
|
-
scrimAlphaAndroid?: number;
|
|
30
|
-
displayCutoutWhenLandscapeAndroid?: boolean;
|
|
31
|
-
tabBarColor?: Color;
|
|
32
|
-
tabBarShadowImage?: ShadowImage;
|
|
33
|
-
tabBarItemColor?: Color;
|
|
34
|
-
tabBarUnselectedItemColor?: Color;
|
|
35
|
-
tabBarBadgeColor?: Color;
|
|
36
|
-
}
|
|
37
|
-
export declare type TabBarStyle = Pick<Style, 'tabBarColor' | 'tabBarShadowImage' | 'tabBarItemColor' | 'tabBarUnselectedItemColor'>;
|
|
38
|
-
export interface TabBadge {
|
|
39
|
-
index: number;
|
|
40
|
-
text?: string;
|
|
41
|
-
hidden: boolean;
|
|
42
|
-
dot?: boolean;
|
|
43
|
-
}
|
|
44
|
-
export interface TabItemInfo {
|
|
45
|
-
index: number;
|
|
46
|
-
title?: string;
|
|
47
|
-
badge?: {
|
|
48
|
-
text?: string;
|
|
49
|
-
hidden: boolean;
|
|
50
|
-
dot?: boolean;
|
|
51
|
-
};
|
|
52
|
-
icon?: {
|
|
53
|
-
selected: ImageSource;
|
|
54
|
-
unselected?: ImageSource;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
export interface TabIcon {
|
|
58
|
-
index: number;
|
|
59
|
-
icon: ImageSource;
|
|
60
|
-
unselectedIcon?: ImageSource;
|
|
61
|
-
}
|
|
1
|
+
import type { BarButtonItem, DefaultOptions, NavigationOption, TabBarStyle, TabItemInfo, TitleItem } from './Options';
|
|
62
2
|
declare type Nullable<T> = {
|
|
63
3
|
[P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P];
|
|
64
4
|
};
|
|
65
|
-
export
|
|
5
|
+
export interface Garden {
|
|
6
|
+
}
|
|
7
|
+
export declare class Garden implements Garden {
|
|
66
8
|
sceneId: string;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use Navigation.setDefaultOptions() instead.
|
|
11
|
+
* @param style
|
|
12
|
+
*/
|
|
13
|
+
static setStyle(style: DefaultOptions): void;
|
|
71
14
|
constructor(sceneId: string);
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use Navigation.setLeftBarButtonItem() instead.
|
|
17
|
+
* @param buttonItem
|
|
18
|
+
*/
|
|
72
19
|
setLeftBarButtonItem(buttonItem: Nullable<BarButtonItem> | null): void;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use Navigation.setRightBarButtonItem() instead.
|
|
22
|
+
* @param buttonItem
|
|
23
|
+
*/
|
|
73
24
|
setRightBarButtonItem(buttonItem: Nullable<BarButtonItem> | null): void;
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @deprecated Use Navigation.setLeftBarButtonItems() instead.
|
|
28
|
+
* @param buttonItems
|
|
29
|
+
*/
|
|
74
30
|
setLeftBarButtonItems(buttonItems: Array<Nullable<BarButtonItem>> | null): void;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use Navigation.setRightBarButtonItems() instead.
|
|
33
|
+
* @param buttonItems
|
|
34
|
+
*/
|
|
75
35
|
setRightBarButtonItems(buttonItems: Array<Nullable<BarButtonItem>> | null): void;
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use Navigation.setTitleItem() instead.
|
|
38
|
+
* @param titleItem
|
|
39
|
+
*/
|
|
76
40
|
setTitleItem(titleItem: TitleItem): void;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use Navigation.updateOptions() instead.
|
|
43
|
+
* @param options
|
|
44
|
+
*/
|
|
77
45
|
updateOptions(options: NavigationOption): void;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Use Navigation.updateTabBar() instead.
|
|
48
|
+
* @param options
|
|
49
|
+
*/
|
|
78
50
|
updateTabBar(options: TabBarStyle): void;
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated Use Navigation.setTabItem() instead.
|
|
53
|
+
* @param item
|
|
54
|
+
*/
|
|
79
55
|
setTabItem(item: TabItemInfo | TabItemInfo[]): void;
|
|
80
|
-
|
|
81
|
-
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Use Navigation.setMenuInteractive() instead.
|
|
58
|
+
* @param enabled
|
|
59
|
+
*/
|
|
82
60
|
setMenuInteractive(enabled: boolean): void;
|
|
83
61
|
}
|
|
84
62
|
export {};
|
package/lib/Garden.js
CHANGED
|
@@ -1,95 +1,78 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { bindBarButtonItemClickEvent } from './utils';
|
|
3
|
-
const GardenModule = NativeModules.GardenModule;
|
|
4
|
-
const { STATUSBAR_HEIGHT, EVENT_STATUSBAR_FRAME_CHANGE, TOOLBAR_HEIGHT } = GardenModule.getConstants();
|
|
5
|
-
if (Platform.OS === 'ios') {
|
|
6
|
-
const GardenEventEmitter = new NativeEventEmitter(GardenModule);
|
|
7
|
-
GardenEventEmitter.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight }) => {
|
|
8
|
-
Garden.statusBarHeight = statusBarHeight;
|
|
9
|
-
Garden.topBarHeight = statusBarHeight + TOOLBAR_HEIGHT;
|
|
10
|
-
});
|
|
11
|
-
}
|
|
1
|
+
import Navigation from './Navigation';
|
|
12
2
|
export class Garden {
|
|
13
3
|
sceneId;
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use Navigation.setDefaultOptions() instead.
|
|
6
|
+
* @param style
|
|
7
|
+
*/
|
|
8
|
+
static setStyle(style) {
|
|
9
|
+
Navigation.setDefaultOptions(style);
|
|
16
10
|
}
|
|
17
|
-
static statusBarHeight = STATUSBAR_HEIGHT;
|
|
18
|
-
static toolbarHeight = TOOLBAR_HEIGHT;
|
|
19
|
-
static topBarHeight = TOOLBAR_HEIGHT + STATUSBAR_HEIGHT;
|
|
20
11
|
constructor(sceneId) {
|
|
21
12
|
this.sceneId = sceneId;
|
|
22
13
|
}
|
|
23
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Use Navigation.setLeftBarButtonItem() instead.
|
|
16
|
+
* @param buttonItem
|
|
17
|
+
*/
|
|
24
18
|
setLeftBarButtonItem(buttonItem) {
|
|
25
|
-
|
|
26
|
-
GardenModule.setLeftBarButtonItem(this.sceneId, options);
|
|
19
|
+
Navigation.setLeftBarButtonItem(this.sceneId, buttonItem);
|
|
27
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use Navigation.setRightBarButtonItem() instead.
|
|
23
|
+
* @param buttonItem
|
|
24
|
+
*/
|
|
28
25
|
setRightBarButtonItem(buttonItem) {
|
|
29
|
-
|
|
30
|
-
GardenModule.setRightBarButtonItem(this.sceneId, options);
|
|
26
|
+
Navigation.setRightBarButtonItem(this.sceneId, buttonItem);
|
|
31
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @deprecated Use Navigation.setLeftBarButtonItems() instead.
|
|
31
|
+
* @param buttonItems
|
|
32
|
+
*/
|
|
32
33
|
setLeftBarButtonItems(buttonItems) {
|
|
33
|
-
|
|
34
|
-
GardenModule.setLeftBarButtonItems(this.sceneId, options);
|
|
34
|
+
Navigation.setLeftBarButtonItems(this.sceneId, buttonItems);
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use Navigation.setRightBarButtonItems() instead.
|
|
38
|
+
* @param buttonItems
|
|
39
|
+
*/
|
|
36
40
|
setRightBarButtonItems(buttonItems) {
|
|
37
|
-
|
|
38
|
-
GardenModule.setRightBarButtonItems(this.sceneId, options);
|
|
41
|
+
Navigation.setRightBarButtonItems(this.sceneId, buttonItems);
|
|
39
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated Use Navigation.setTitleItem() instead.
|
|
45
|
+
* @param titleItem
|
|
46
|
+
*/
|
|
40
47
|
setTitleItem(titleItem) {
|
|
41
|
-
|
|
48
|
+
Navigation.setTitleItem(this.sceneId, titleItem);
|
|
42
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated Use Navigation.updateOptions() instead.
|
|
52
|
+
* @param options
|
|
53
|
+
*/
|
|
43
54
|
updateOptions(options) {
|
|
44
|
-
|
|
55
|
+
Navigation.updateOptions(this.sceneId, options);
|
|
45
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated Use Navigation.updateTabBar() instead.
|
|
59
|
+
* @param options
|
|
60
|
+
*/
|
|
46
61
|
updateTabBar(options) {
|
|
47
|
-
|
|
62
|
+
Navigation.updateTabBar(this.sceneId, options);
|
|
48
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated Use Navigation.setTabItem() instead.
|
|
66
|
+
* @param item
|
|
67
|
+
*/
|
|
49
68
|
setTabItem(item) {
|
|
50
|
-
|
|
51
|
-
item = [item];
|
|
52
|
-
}
|
|
53
|
-
GardenModule.setTabItem(this.sceneId, item);
|
|
54
|
-
}
|
|
55
|
-
setTabIcon(icon) {
|
|
56
|
-
console.warn(`Garden#setTabIcon is deprecated, use Garden#setTabItem instead.`);
|
|
57
|
-
if (!Array.isArray(icon)) {
|
|
58
|
-
icon = [icon];
|
|
59
|
-
}
|
|
60
|
-
const icons = icon;
|
|
61
|
-
const items = [];
|
|
62
|
-
for (const i of icons) {
|
|
63
|
-
items.push({
|
|
64
|
-
index: i.index,
|
|
65
|
-
icon: {
|
|
66
|
-
selected: i.icon,
|
|
67
|
-
unselected: i.unselectedIcon,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
this.setTabItem(items);
|
|
72
|
-
}
|
|
73
|
-
setTabBadge(badge) {
|
|
74
|
-
console.warn(`Garden#setTabBadge is deprecated, use Garden#setTabItem instead.`);
|
|
75
|
-
if (!Array.isArray(badge)) {
|
|
76
|
-
badge = [badge];
|
|
77
|
-
}
|
|
78
|
-
const badges = badge;
|
|
79
|
-
const items = [];
|
|
80
|
-
for (const b of badges) {
|
|
81
|
-
items.push({
|
|
82
|
-
index: b.index,
|
|
83
|
-
badge: {
|
|
84
|
-
hidden: b.hidden,
|
|
85
|
-
text: b.text,
|
|
86
|
-
dot: b.dot,
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
this.setTabItem(items);
|
|
69
|
+
Navigation.setTabItem(this.sceneId, item);
|
|
91
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* @deprecated Use Navigation.setMenuInteractive() instead.
|
|
73
|
+
* @param enabled
|
|
74
|
+
*/
|
|
92
75
|
setMenuInteractive(enabled) {
|
|
93
|
-
|
|
76
|
+
Navigation.setMenuInteractive(this.sceneId, enabled);
|
|
94
77
|
}
|
|
95
78
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { NativeModule } from 'react-native';
|
|
2
|
+
interface GardenModule extends NativeModule {
|
|
3
|
+
getConstants: () => {
|
|
4
|
+
TOOLBAR_HEIGHT: number;
|
|
5
|
+
STATUSBAR_HEIGHT: number;
|
|
6
|
+
EVENT_STATUSBAR_FRAME_CHANGE: string;
|
|
7
|
+
};
|
|
8
|
+
setStyle: (style: object) => void;
|
|
9
|
+
setTitleItem: (sceneId: string, item: object) => void;
|
|
10
|
+
setLeftBarButtonItem: (sceneId: string, item: object | null) => void;
|
|
11
|
+
setRightBarButtonItem: (sceneId: string, item: object | null) => void;
|
|
12
|
+
setLeftBarButtonItems: (sceneId: string, item: object | null) => void;
|
|
13
|
+
setRightBarButtonItems: (sceneId: string, item: object | null) => void;
|
|
14
|
+
updateOptions: (sceneId: string, options: object) => void;
|
|
15
|
+
updateTabBar: (sceneId: string, item: object) => void;
|
|
16
|
+
setTabItem: (sceneId: string, item: object) => void;
|
|
17
|
+
setMenuInteractive: (sceneId: string, enabled: boolean) => void;
|
|
18
|
+
}
|
|
19
|
+
declare const GardenModule: GardenModule;
|
|
20
|
+
export default GardenModule;
|