hybrid-navigation 3.0.9 → 3.1.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/Garden.java +10 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +6 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +3 -0
- package/dist/Navigation.js +43 -23
- package/dist/Options.d.ts +1 -0
- package/dist/handler/DispatchCommandHandler.js +6 -2
- package/dist/handler/LayoutCommandHandler.js +6 -2
- package/ios/GlobalStyle.h +1 -0
- package/ios/GlobalStyle.mm +6 -0
- package/ios/Navigator/HBDStackNavigator.mm +2 -2
- package/ios/ViewController/HBDFadeAnimation.mm +32 -8
- package/ios/ViewController/HBDNavigationController.mm +92 -17
- package/ios/ViewController/HBDReactViewController.mm +47 -6
- package/ios/ViewController/HBDViewController.h +1 -0
- package/ios/ViewController/HBDViewController.mm +4 -2
- package/package.json +1 -1
- package/src/Navigation.ts +43 -23
- package/src/Options.ts +1 -0
- package/src/handler/DispatchCommandHandler.ts +6 -2
- package/src/handler/LayoutCommandHandler.ts +6 -2
- package/src/index.ts +2 -0
- package/dist/NavigationModule.d.ts +0 -34
- package/dist/NavigationModule.js +0 -83
- package/src/NavigationModule.ts +0 -98
|
@@ -71,6 +71,10 @@ public class Garden {
|
|
|
71
71
|
|
|
72
72
|
this.swipeBackEnabled = options.getBoolean("swipeBackEnabled", true);
|
|
73
73
|
this.toolbarHidden = options.getBoolean("topBarHidden", false);
|
|
74
|
+
// 全局 topBarHidden 优先,一旦设置则局部开启无效
|
|
75
|
+
if (getGlobalStyle().isTopBarHidden()) {
|
|
76
|
+
this.toolbarHidden = true;
|
|
77
|
+
}
|
|
74
78
|
Bundle tabItem = options.getBundle("tabItem");
|
|
75
79
|
this.hidesBottomBarWhenPushed = tabItem == null || tabItem.getBoolean("hideTabBarWhenPush", true);
|
|
76
80
|
this.extendedLayoutIncludesTopBar = options.getBoolean("extendedLayoutIncludesTopBar", false);
|
|
@@ -290,6 +294,12 @@ public class Garden {
|
|
|
290
294
|
|
|
291
295
|
Bundle options = mergeOptions(fragment.getOptions(), patches);
|
|
292
296
|
fragment.setOptions(options);
|
|
297
|
+
// 全局 topBarHidden 优先,一旦设置则局部开启无效
|
|
298
|
+
if (getGlobalStyle().isTopBarHidden()) {
|
|
299
|
+
this.toolbarHidden = true;
|
|
300
|
+
} else if (readableMap.hasKey("topBarHidden")) {
|
|
301
|
+
this.toolbarHidden = options.getBoolean("topBarHidden", false);
|
|
302
|
+
}
|
|
293
303
|
|
|
294
304
|
if (readableMap.hasKey("leftBarButtonItem")) {
|
|
295
305
|
Bundle bundle = options.getBundle("leftBarButtonItem");
|
|
@@ -25,13 +25,19 @@ public class GlobalStyle {
|
|
|
25
25
|
private static final String TAG = "Navigation";
|
|
26
26
|
|
|
27
27
|
private final Bundle options;
|
|
28
|
+
private final boolean topBarHidden;
|
|
28
29
|
|
|
29
30
|
public Bundle getOptions() {
|
|
30
31
|
return options;
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
public boolean isTopBarHidden() {
|
|
35
|
+
return topBarHidden;
|
|
36
|
+
}
|
|
37
|
+
|
|
33
38
|
public GlobalStyle(Bundle options) {
|
|
34
39
|
this.options = options;
|
|
40
|
+
this.topBarHidden = options != null && options.getBoolean("topBarHidden", false);
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
public void inflateStyle(Context context, Style style) {
|
|
@@ -173,6 +173,9 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
protected boolean shouldAnimatedTransition() {
|
|
176
|
+
if (forceScreenLandscape()) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
176
179
|
Bundle options = getOptions();
|
|
177
180
|
return options.getBoolean("animatedTransition", true);
|
|
178
181
|
}
|
package/dist/Navigation.js
CHANGED
|
@@ -5,9 +5,9 @@ import DispatchCommandHandler from './handler/DispatchCommandHandler';
|
|
|
5
5
|
import ResultEventHandler from './handler/ResultEventHandler';
|
|
6
6
|
import VisibilityEventHandler from './handler/VisibilityEventHandler';
|
|
7
7
|
import NativeEvent from './NativeEvent';
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
export const { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK } =
|
|
8
|
+
import NativeNavigation from './NativeNavigation';
|
|
9
|
+
import NativeGarden from './NativeGarden';
|
|
10
|
+
export const { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK } = NativeNavigation.getConstants();
|
|
11
11
|
class NavigationImpl {
|
|
12
12
|
dispatchHandler = new DispatchCommandHandler();
|
|
13
13
|
resultHandler = new ResultEventHandler();
|
|
@@ -26,7 +26,7 @@ class NavigationImpl {
|
|
|
26
26
|
startRegisterComponent(hoc) {
|
|
27
27
|
this.hoc = hoc;
|
|
28
28
|
this.registerEnded = false;
|
|
29
|
-
|
|
29
|
+
NativeNavigation.startRegisterReactComponent();
|
|
30
30
|
}
|
|
31
31
|
endRegisterComponent() {
|
|
32
32
|
if (this.registerEnded) {
|
|
@@ -34,7 +34,7 @@ class NavigationImpl {
|
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
this.registerEnded = true;
|
|
37
|
-
|
|
37
|
+
NativeNavigation.endRegisterReactComponent();
|
|
38
38
|
}
|
|
39
39
|
registerComponent(appKey, getComponentFunc, routeConfig) {
|
|
40
40
|
if (routeConfig) {
|
|
@@ -47,7 +47,7 @@ class NavigationImpl {
|
|
|
47
47
|
// build static options
|
|
48
48
|
let options = this.bindBarButtonClickEvent('permanent', WrappedComponent.navigationItem) ||
|
|
49
49
|
{};
|
|
50
|
-
|
|
50
|
+
NativeNavigation.registerReactComponent(appKey, options);
|
|
51
51
|
let RootComponent = this.wrap(appKey)(WrappedComponent);
|
|
52
52
|
AppRegistry.registerComponent(appKey, () => RootComponent);
|
|
53
53
|
}
|
|
@@ -88,7 +88,7 @@ class NavigationImpl {
|
|
|
88
88
|
if (resultCode < RESULT_OK) {
|
|
89
89
|
console.warn('`resultCode` can only be `RESULT_OK`, `RESULT_CANCEL` or an integer greater than 0.');
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
NativeNavigation.setResult(sceneId, resultCode, data);
|
|
92
92
|
};
|
|
93
93
|
result(sceneId, resultCode) {
|
|
94
94
|
return this.resultHandler.waitResult(sceneId, resultCode);
|
|
@@ -104,59 +104,79 @@ class NavigationImpl {
|
|
|
104
104
|
this.layoutHandler.setRootLayoutUpdateListener(willSetRoot, didSetRoot);
|
|
105
105
|
}
|
|
106
106
|
currentTab(sceneId) {
|
|
107
|
-
return
|
|
107
|
+
return new Promise(resolve => {
|
|
108
|
+
NativeNavigation.currentTab(sceneId, (_, index) => {
|
|
109
|
+
resolve(index);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
108
112
|
}
|
|
109
113
|
findSceneIdByModuleName(moduleName) {
|
|
110
|
-
return
|
|
114
|
+
return new Promise(resolve => {
|
|
115
|
+
NativeNavigation.findSceneIdByModuleName(moduleName, (_, sceneId) => {
|
|
116
|
+
resolve(sceneId);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
111
119
|
}
|
|
112
120
|
isStackRoot(sceneId) {
|
|
113
|
-
return
|
|
121
|
+
return new Promise(resolve => {
|
|
122
|
+
NativeNavigation.isStackRoot(sceneId, (_, result) => {
|
|
123
|
+
resolve(result);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
114
126
|
}
|
|
115
127
|
signalFirstRenderComplete(sceneId) {
|
|
116
|
-
|
|
128
|
+
NativeNavigation.signalFirstRenderComplete(sceneId);
|
|
117
129
|
}
|
|
118
130
|
currentRoute() {
|
|
119
|
-
return
|
|
131
|
+
return new Promise(resolve => {
|
|
132
|
+
NativeNavigation.currentRoute((_, route) => {
|
|
133
|
+
resolve(route);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
120
136
|
}
|
|
121
137
|
routeGraph() {
|
|
122
|
-
return
|
|
138
|
+
return new Promise(resolve => {
|
|
139
|
+
NativeNavigation.routeGraph((_, graph) => {
|
|
140
|
+
resolve(graph);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
123
143
|
}
|
|
124
144
|
setDefaultOptions(options) {
|
|
125
|
-
|
|
145
|
+
NativeGarden.setStyle(options);
|
|
126
146
|
}
|
|
127
147
|
setLeftBarButtonItem(sceneId, buttonItem) {
|
|
128
148
|
const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
|
|
129
|
-
|
|
149
|
+
NativeGarden.setLeftBarButtonItem(sceneId, options);
|
|
130
150
|
}
|
|
131
151
|
setRightBarButtonItem(sceneId, buttonItem) {
|
|
132
152
|
const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
|
|
133
|
-
|
|
153
|
+
NativeGarden.setRightBarButtonItem(sceneId, options);
|
|
134
154
|
}
|
|
135
155
|
setLeftBarButtonItems(sceneId, buttonItems) {
|
|
136
156
|
const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
|
|
137
|
-
|
|
157
|
+
NativeGarden.setLeftBarButtonItems(sceneId, options);
|
|
138
158
|
}
|
|
139
159
|
setRightBarButtonItems(sceneId, buttonItems) {
|
|
140
160
|
const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
|
|
141
|
-
|
|
161
|
+
NativeGarden.setRightBarButtonItems(sceneId, options);
|
|
142
162
|
}
|
|
143
163
|
setTitleItem(sceneId, titleItem) {
|
|
144
|
-
|
|
164
|
+
NativeGarden.setTitleItem(sceneId, titleItem);
|
|
145
165
|
}
|
|
146
166
|
updateOptions(sceneId, options) {
|
|
147
|
-
|
|
167
|
+
NativeGarden.updateOptions(sceneId, options);
|
|
148
168
|
}
|
|
149
169
|
updateTabBar(sceneId, options) {
|
|
150
|
-
|
|
170
|
+
NativeGarden.updateTabBar(sceneId, options);
|
|
151
171
|
}
|
|
152
172
|
setTabItem(sceneId, item) {
|
|
153
173
|
if (!Array.isArray(item)) {
|
|
154
174
|
item = [item];
|
|
155
175
|
}
|
|
156
|
-
|
|
176
|
+
NativeGarden.setTabItem(sceneId, item);
|
|
157
177
|
}
|
|
158
178
|
setMenuInteractive(sceneId, enabled) {
|
|
159
|
-
|
|
179
|
+
NativeGarden.setMenuInteractive(sceneId, enabled);
|
|
160
180
|
}
|
|
161
181
|
setBarButtonClickEventListener(listener) {
|
|
162
182
|
this.buttonHandler.setBarButtonClickEventListener(listener);
|
package/dist/Options.d.ts
CHANGED
|
@@ -111,6 +111,7 @@ export interface DefaultOptions {
|
|
|
111
111
|
tabBarItemSelectedColor?: Color;
|
|
112
112
|
tabBarItemNormalColor?: Color;
|
|
113
113
|
tabBarBadgeColor?: Color;
|
|
114
|
+
topBarHidden?: boolean;
|
|
114
115
|
}
|
|
115
116
|
export type TabBarStyle = Pick<DefaultOptions, 'tabBarBackgroundColor' | 'tabBarShadowImage' | 'tabBarItemSelectedColor' | 'tabBarItemNormalColor'>;
|
|
116
117
|
export interface TabItemInfo {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import NativeNavigation from '../NativeNavigation';
|
|
2
2
|
export default class DispatchCommandHandler {
|
|
3
3
|
interceptor = () => false;
|
|
4
4
|
async dispatch(sceneId, action, params) {
|
|
@@ -12,7 +12,11 @@ export default class DispatchCommandHandler {
|
|
|
12
12
|
if (intercepted) {
|
|
13
13
|
return false;
|
|
14
14
|
}
|
|
15
|
-
return
|
|
15
|
+
return new Promise(resolve => {
|
|
16
|
+
NativeNavigation.dispatch(sceneId, action, params, (_, result) => {
|
|
17
|
+
resolve(result);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
16
20
|
}
|
|
17
21
|
intercept(action, params) {
|
|
18
22
|
if (!this.interceptor) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import NavigationModule from '../NavigationModule';
|
|
2
1
|
import NativeEvent from '../NativeEvent';
|
|
2
|
+
import NativeNavigation from '../NativeNavigation';
|
|
3
3
|
export default class LayoutCommandHandler {
|
|
4
4
|
willSetRoot = () => { };
|
|
5
5
|
didSetRoot = () => { };
|
|
@@ -13,7 +13,11 @@ export default class LayoutCommandHandler {
|
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
setRoot(layout, sticky = false) {
|
|
16
|
-
return
|
|
16
|
+
return new Promise(resolve => {
|
|
17
|
+
NativeNavigation.setRoot(layout, sticky, (_, success) => {
|
|
18
|
+
resolve(success);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
17
21
|
}
|
|
18
22
|
setRootLayoutUpdateListener(willSetRoot = () => { }, didSetRoot = () => { }) {
|
|
19
23
|
this.willSetRoot = willSetRoot;
|
package/ios/GlobalStyle.h
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
@property(nonatomic, strong, readonly) UIColor *screenBackgroundColor;
|
|
10
10
|
@property(nonatomic, assign, readonly, getter=isBackTitleHidden) BOOL backTitleHidden;
|
|
11
|
+
@property(nonatomic, assign, readonly, getter=isTopBarHidden) BOOL topBarHidden;
|
|
11
12
|
@property(nonatomic, assign, readonly) BOOL alwaysSplitNavigationBarTransition;
|
|
12
13
|
@property(nonatomic, assign) UIInterfaceOrientationMask interfaceOrientation;
|
|
13
14
|
|
package/ios/GlobalStyle.mm
CHANGED
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
@property(nonatomic, strong) UIColor *tabBarItemNormalColor;
|
|
30
30
|
|
|
31
31
|
@property(nonatomic, assign, readwrite) BOOL alwaysSplitNavigationBarTransition;
|
|
32
|
+
@property(nonatomic, assign, readwrite, getter=isTopBarHidden) BOOL topBarHidden;
|
|
32
33
|
|
|
33
34
|
@end
|
|
34
35
|
|
|
@@ -85,6 +86,11 @@ static GlobalStyle *globalStyle;
|
|
|
85
86
|
self.alwaysSplitNavigationBarTransition = [splitTopBarTransitionIOS boolValue];
|
|
86
87
|
}
|
|
87
88
|
|
|
89
|
+
NSNumber *topBarHidden = self.options[@"topBarHidden"];
|
|
90
|
+
if (topBarHidden) {
|
|
91
|
+
self.topBarHidden = [topBarHidden boolValue];
|
|
92
|
+
}
|
|
93
|
+
|
|
88
94
|
NSString *topBarColorDarkContent = self.options[@"topBarColorDarkContent"];
|
|
89
95
|
if (topBarColorDarkContent) {
|
|
90
96
|
self.barTintColorDarkContent = [HBDUtils colorWithHexString:topBarColorDarkContent];
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
BOOL animated = YES;
|
|
123
123
|
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
124
124
|
HBDViewController *hdbvc = (HBDViewController *)vc;
|
|
125
|
-
|
|
125
|
+
animated = hdbvc.animatedTransition || hdbvc.forceScreenLandscape;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
if (animated) {
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
BOOL animated = YES;
|
|
139
139
|
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
140
140
|
HBDViewController *hdbvc = (HBDViewController *)vc;
|
|
141
|
-
|
|
141
|
+
animated = hdbvc.animatedTransition || hdbvc.forceScreenLandscape;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
if (animated) {
|
|
@@ -3,20 +3,44 @@
|
|
|
3
3
|
@implementation HBDFadeAnimation
|
|
4
4
|
|
|
5
5
|
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext {
|
|
6
|
-
return 0.
|
|
6
|
+
return 0.25f;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
|
|
10
|
+
UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];
|
|
10
11
|
UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];
|
|
12
|
+
UIView *containerView = [transitionContext containerView];
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
if (!toView) {
|
|
15
|
+
[transitionContext completeTransition:NO];
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
toView
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
if (fromView) {
|
|
20
|
+
// Pop 操作:fromView 淡出,toView 淡入
|
|
21
|
+
[containerView insertSubview:toView belowSubview:fromView];
|
|
22
|
+
toView.alpha = 0;
|
|
23
|
+
|
|
24
|
+
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
|
|
25
|
+
fromView.alpha = 0;
|
|
26
|
+
toView.alpha = 1;
|
|
27
|
+
} completion:^(BOOL finished) {
|
|
28
|
+
fromView.alpha = 1;
|
|
29
|
+
toView.alpha = 1;
|
|
30
|
+
[transitionContext completeTransition:!transitionContext.transitionWasCancelled];
|
|
31
|
+
}];
|
|
32
|
+
} else {
|
|
33
|
+
// Push 操作:toView 淡入(fromView 保持可见直到被移除)
|
|
34
|
+
[containerView addSubview:toView];
|
|
35
|
+
toView.alpha = 0;
|
|
36
|
+
|
|
37
|
+
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
|
|
38
|
+
toView.alpha = 1;
|
|
39
|
+
} completion:^(BOOL finished) {
|
|
40
|
+
toView.alpha = 1;
|
|
41
|
+
[transitionContext completeTransition:!transitionContext.transitionWasCancelled];
|
|
42
|
+
}];
|
|
43
|
+
}
|
|
20
44
|
}
|
|
21
45
|
|
|
22
46
|
@end
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#import "HBDUtils.h"
|
|
6
6
|
#import "HBDPushAnimation.h"
|
|
7
7
|
#import "HBDPopAnimation.h"
|
|
8
|
+
#import "HBDFadeAnimation.h"
|
|
8
9
|
#import "GlobalStyle.h"
|
|
9
10
|
|
|
10
11
|
#import <React/RCTLog.h>
|
|
@@ -16,8 +17,14 @@
|
|
|
16
17
|
@property(nonatomic, weak) id <UINavigationControllerDelegate> proxyDelegate;
|
|
17
18
|
@property(nonatomic, weak, readonly) HBDNavigationController *nav;
|
|
18
19
|
@property(nonatomic, strong) UIPercentDrivenInteractiveTransition *interactiveTransition;
|
|
20
|
+
@property(nonatomic, assign) UIEdgeInsets hbd_savedAdditionalSafeAreaInsetsForTo;
|
|
21
|
+
@property(nonatomic, assign) BOOL hbd_didCompensateSafeAreaForTo;
|
|
22
|
+
@property(nonatomic, assign) UIEdgeInsets hbd_savedAdditionalSafeAreaInsetsForFrom;
|
|
23
|
+
@property(nonatomic, assign) BOOL hbd_didCompensateSafeAreaForFrom;
|
|
19
24
|
|
|
20
25
|
- (instancetype)initWithNavigationController:(HBDNavigationController *)navigationController;
|
|
26
|
+
- (void)hbd_compensateSafeAreaForViewController:(UIViewController *)vc expectedTopInset:(CGFloat)expectedTopInset isToVC:(BOOL)isToVC;
|
|
27
|
+
- (void)hbd_restoreCompensatedSafeAreaForFrom:(UIViewController *)from to:(UIViewController *)to viewController:(UIViewController *)viewController;
|
|
21
28
|
|
|
22
29
|
@end
|
|
23
30
|
|
|
@@ -69,11 +76,11 @@
|
|
|
69
76
|
|
|
70
77
|
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
|
|
71
78
|
HBDNavigationController *nav = self.nav;
|
|
72
|
-
|
|
79
|
+
|
|
73
80
|
if (nav.transitionCoordinator) {
|
|
74
81
|
return NO;
|
|
75
82
|
}
|
|
76
|
-
|
|
83
|
+
|
|
77
84
|
if (nav.viewControllers.count > 1) {
|
|
78
85
|
UIViewController *topVC = nav.topViewController;
|
|
79
86
|
return topVC.hbd_swipeBackEnabled && topVC.hbd_backInteractive;
|
|
@@ -196,6 +203,30 @@
|
|
|
196
203
|
if (self.proxyDelegate && [self.proxyDelegate respondsToSelector:@selector(navigationController:animationControllerForOperation:fromViewController:toViewController:)]) {
|
|
197
204
|
return [self.proxyDelegate navigationController:navigationController animationControllerForOperation:operation fromViewController:fromVC toViewController:toVC];
|
|
198
205
|
} else {
|
|
206
|
+
// 检查是否需要使用淡入淡出动画(横屏页面)
|
|
207
|
+
// 只要 from 或 to 页面有一个是横屏,就采用 fade 动画
|
|
208
|
+
BOOL shouldUseFadeAnimation = NO;
|
|
209
|
+
|
|
210
|
+
// 检查 fromVC 是否是横屏
|
|
211
|
+
if ([fromVC isKindOfClass:[HBDViewController class]]) {
|
|
212
|
+
HBDViewController *hbdFromVC = (HBDViewController *)fromVC;
|
|
213
|
+
if (hbdFromVC.forceScreenLandscape) {
|
|
214
|
+
shouldUseFadeAnimation = YES;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 检查 toVC 是否是横屏
|
|
219
|
+
if (!shouldUseFadeAnimation && [toVC isKindOfClass:[HBDViewController class]]) {
|
|
220
|
+
HBDViewController *hbdToVC = (HBDViewController *)toVC;
|
|
221
|
+
if (hbdToVC.forceScreenLandscape) {
|
|
222
|
+
shouldUseFadeAnimation = YES;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (shouldUseFadeAnimation) {
|
|
227
|
+
return [HBDFadeAnimation new];
|
|
228
|
+
}
|
|
229
|
+
|
|
199
230
|
if (operation == UINavigationControllerOperationPush) {
|
|
200
231
|
if ([self shouldBetterTransitionWithViewController:toVC]) {
|
|
201
232
|
return [HBDPushAnimation new];
|
|
@@ -219,6 +250,36 @@
|
|
|
219
250
|
return shouldBetter;
|
|
220
251
|
}
|
|
221
252
|
|
|
253
|
+
- (void)hbd_compensateSafeAreaForViewController:(UIViewController *)vc expectedTopInset:(CGFloat)expectedTopInset isToVC:(BOOL)isToVC {
|
|
254
|
+
if (vc.isViewLoaded) {
|
|
255
|
+
[vc.view layoutIfNeeded];
|
|
256
|
+
}
|
|
257
|
+
CGFloat systemTop = vc.isViewLoaded ? vc.view.safeAreaInsets.top : 0;
|
|
258
|
+
CGFloat compensate = expectedTopInset > systemTop ? (expectedTopInset - systemTop) : 0;
|
|
259
|
+
if (isToVC) {
|
|
260
|
+
self.hbd_savedAdditionalSafeAreaInsetsForTo = vc.additionalSafeAreaInsets;
|
|
261
|
+
self.hbd_didCompensateSafeAreaForTo = (compensate > 0);
|
|
262
|
+
} else {
|
|
263
|
+
self.hbd_savedAdditionalSafeAreaInsetsForFrom = vc.additionalSafeAreaInsets;
|
|
264
|
+
self.hbd_didCompensateSafeAreaForFrom = (compensate > 0);
|
|
265
|
+
}
|
|
266
|
+
if (compensate > 0) {
|
|
267
|
+
UIEdgeInsets o = vc.additionalSafeAreaInsets;
|
|
268
|
+
vc.additionalSafeAreaInsets = UIEdgeInsetsMake(o.top + compensate, o.left, o.bottom, o.right);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
- (void)hbd_restoreCompensatedSafeAreaForFrom:(UIViewController *)from to:(UIViewController *)to viewController:(UIViewController *)viewController {
|
|
273
|
+
if (self.hbd_didCompensateSafeAreaForTo && to == viewController) {
|
|
274
|
+
viewController.additionalSafeAreaInsets = self.hbd_savedAdditionalSafeAreaInsetsForTo;
|
|
275
|
+
self.hbd_didCompensateSafeAreaForTo = NO;
|
|
276
|
+
}
|
|
277
|
+
if (self.hbd_didCompensateSafeAreaForFrom) {
|
|
278
|
+
from.additionalSafeAreaInsets = self.hbd_savedAdditionalSafeAreaInsetsForFrom;
|
|
279
|
+
self.hbd_didCompensateSafeAreaForFrom = NO;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
222
283
|
- (void)showViewController:(UIViewController *_Nonnull)viewController withCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator {
|
|
223
284
|
UIViewController *from = [coordinator viewControllerForKey:UITransitionContextFromViewControllerKey];
|
|
224
285
|
UIViewController *to = [coordinator viewControllerForKey:UITransitionContextToViewControllerKey];
|
|
@@ -236,8 +297,7 @@
|
|
|
236
297
|
}
|
|
237
298
|
|
|
238
299
|
[coordinator animateAlongsideTransition:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
239
|
-
|
|
240
|
-
} completion:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
300
|
+
} completion:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
241
301
|
backButtonLabel.hbd_specifiedTextColor = nil;
|
|
242
302
|
}];
|
|
243
303
|
}
|
|
@@ -247,10 +307,16 @@
|
|
|
247
307
|
[coordinator animateAlongsideTransition:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
248
308
|
BOOL shouldFake = [self shouldShowFakeBarFrom:from to:to viewController:viewController];
|
|
249
309
|
if (shouldFake) {
|
|
250
|
-
// title attributes, button tint color, barStyle
|
|
251
310
|
[self.nav updateNavigationBarTintColorForViewController:viewController];
|
|
252
|
-
// background alpha, background color, shadow image alpha
|
|
253
311
|
[self.nav showFakeBarFrom:from to:to];
|
|
312
|
+
|
|
313
|
+
// 转场涉及旋转时不应用 safe area 补偿,避免布局错乱
|
|
314
|
+
BOOL noRotation = CGAffineTransformIsIdentity(context.targetTransform);
|
|
315
|
+
if (noRotation) {
|
|
316
|
+
CGFloat expectedTopInset = CGRectGetMaxY(self.nav.navigationBar.frame);
|
|
317
|
+
[self hbd_compensateSafeAreaForViewController:to expectedTopInset:expectedTopInset isToVC:YES];
|
|
318
|
+
[self hbd_compensateSafeAreaForViewController:from expectedTopInset:expectedTopInset isToVC:NO];
|
|
319
|
+
}
|
|
254
320
|
} else {
|
|
255
321
|
[self.nav updateNavigationBarForViewController:viewController];
|
|
256
322
|
if (@available(iOS 13.0, *)) {
|
|
@@ -262,17 +328,14 @@
|
|
|
262
328
|
}
|
|
263
329
|
} completion:^(id <UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
264
330
|
self.nav.poppingViewController = nil;
|
|
265
|
-
|
|
266
|
-
self.nav.navigationBar.scrollEdgeAppearance.backgroundColor = UIColor.clearColor;
|
|
267
|
-
self.nav.navigationBar.standardAppearance.backgroundColor = UIColor.clearColor;
|
|
268
|
-
}
|
|
331
|
+
[self hbd_restoreCompensatedSafeAreaForFrom:from to:to viewController:viewController];
|
|
269
332
|
|
|
333
|
+
// Restore navigation bar state first, before clearing appearance.
|
|
270
334
|
if (context.isCancelled) {
|
|
271
335
|
if (to == viewController) {
|
|
272
336
|
[self.nav updateNavigationBarForViewController:from];
|
|
273
337
|
}
|
|
274
338
|
} else {
|
|
275
|
-
// `to` != `viewController` when present
|
|
276
339
|
[self.nav updateNavigationBarForViewController:viewController];
|
|
277
340
|
UIViewController *poppingVC = self.nav.poppingViewController;
|
|
278
341
|
if (poppingVC && [poppingVC isKindOfClass:[HBDViewController class]]) {
|
|
@@ -280,6 +343,11 @@
|
|
|
280
343
|
}
|
|
281
344
|
}
|
|
282
345
|
|
|
346
|
+
if (@available(iOS 13.0, *)) {
|
|
347
|
+
self.nav.navigationBar.scrollEdgeAppearance.backgroundColor = UIColor.clearColor;
|
|
348
|
+
self.nav.navigationBar.standardAppearance.backgroundColor = UIColor.clearColor;
|
|
349
|
+
}
|
|
350
|
+
|
|
283
351
|
if (to == viewController) {
|
|
284
352
|
[self.nav clearFake];
|
|
285
353
|
}
|
|
@@ -309,14 +377,18 @@
|
|
|
309
377
|
}
|
|
310
378
|
}
|
|
311
379
|
|
|
380
|
+
// Fake bar: hide real bar (alpha=0) and add fromFakeBar/toFakeBar on each VC's view for smooth bar color change.
|
|
312
381
|
- (BOOL)shouldShowFakeBarFrom:(UIViewController *)from to:(UIViewController *)to viewController:(UIViewController *_Nonnull)viewController {
|
|
313
|
-
if ([GlobalStyle globalStyle].alwaysSplitNavigationBarTransition && to == viewController) {
|
|
314
|
-
return YES;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
382
|
if (to != viewController) {
|
|
318
383
|
return NO;
|
|
319
384
|
}
|
|
385
|
+
// toVC 的 bar 为 hidden 时直接隐藏 UINavigationBar,不使用 fake bar
|
|
386
|
+
if (to.hbd_barHidden) {
|
|
387
|
+
return NO;
|
|
388
|
+
}
|
|
389
|
+
if ([GlobalStyle globalStyle].alwaysSplitNavigationBarTransition && to == viewController) {
|
|
390
|
+
return YES;
|
|
391
|
+
}
|
|
320
392
|
|
|
321
393
|
if (![from.hbd_barTintColor.description isEqual:to.hbd_barTintColor.description]) {
|
|
322
394
|
return YES;
|
|
@@ -420,8 +492,6 @@
|
|
|
420
492
|
UIEdgeInsets safeAreaInsets = self.view.safeAreaInsets;
|
|
421
493
|
UIEdgeInsets additionalInsets = self.additionalSafeAreaInsets;
|
|
422
494
|
|
|
423
|
-
// RCTLogInfo(@"[Navigation] safeAreaInsets:%@, additionalInsets:%@", NSStringFromUIEdgeInsets(safeAreaInsets), NSStringFromUIEdgeInsets(additionalInsets));
|
|
424
|
-
|
|
425
495
|
BOOL statusBarHidden = RCTKeyWindow().windowScene.statusBarManager.statusBarHidden;
|
|
426
496
|
|
|
427
497
|
if (statusBarHidden && safeAreaInsets.top == 0) {
|
|
@@ -488,6 +558,11 @@
|
|
|
488
558
|
}
|
|
489
559
|
|
|
490
560
|
- (void)updateNavigationBarForViewController:(UIViewController *)vc {
|
|
561
|
+
// 仅全局 topBarHidden 时直接隐藏 UINavigationBar
|
|
562
|
+
if ([GlobalStyle globalStyle].topBarHidden) {
|
|
563
|
+
[self setNavigationBarHidden:YES animated:NO];
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
491
566
|
[self updateNavigationBarStyleForViewController:vc];
|
|
492
567
|
[self updateNavigationBarAlphaForViewController:vc];
|
|
493
568
|
[self updateNavigationBarBackgroundForViewController:vc];
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#import "HBDTitleView.h"
|
|
6
6
|
#import "HBDUtils.h"
|
|
7
7
|
#import "HBDNativeEvent.h"
|
|
8
|
+
#import "GlobalStyle.h"
|
|
8
9
|
|
|
9
10
|
#import <React/RCTConvert.h>
|
|
10
11
|
#import <React/RCTSurfaceHostingProxyRootView.h>
|
|
@@ -48,16 +49,16 @@
|
|
|
48
49
|
rootView.passThroughTouches = passThroughTouches;
|
|
49
50
|
rootView.backgroundColor = UIColor.clearColor;
|
|
50
51
|
rootView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
51
|
-
|
|
52
|
-
self.view =
|
|
53
|
-
[rootView setFrame:self.view.frame];
|
|
52
|
+
self.view = [[UIView alloc] init];
|
|
53
|
+
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
54
54
|
[self.view addSubview:rootView];
|
|
55
|
-
[self updateReactViewConstraints];
|
|
56
55
|
RCTLogInfo(@"[Navigation] 加载页面 %@", self.moduleName);
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
- (void)viewDidLoad {
|
|
60
59
|
[super viewDidLoad];
|
|
60
|
+
[self updateReactViewConstraints];
|
|
61
|
+
|
|
61
62
|
NSDictionary *titleItem = self.options[@"titleItem"];
|
|
62
63
|
if (titleItem && self.navigationController) {
|
|
63
64
|
if (self.hbd_barHidden) {
|
|
@@ -84,13 +85,53 @@
|
|
|
84
85
|
|
|
85
86
|
- (void)viewSafeAreaInsetsDidChange {
|
|
86
87
|
[super viewSafeAreaInsetsDidChange];
|
|
88
|
+
if (self.hbd_shouldCorrectSafeAreaTopToStatusBar) {
|
|
89
|
+
CGFloat statusBarHeight = [self hbd_statusBarHeight];
|
|
90
|
+
CGFloat currentEffectiveTop = self.view.safeAreaInsets.top;
|
|
91
|
+
if (fabs(currentEffectiveTop - statusBarHeight) > 0.5) {
|
|
92
|
+
CGFloat systemTop = currentEffectiveTop - self.additionalSafeAreaInsets.top;
|
|
93
|
+
UIEdgeInsets o = self.additionalSafeAreaInsets;
|
|
94
|
+
self.additionalSafeAreaInsets = UIEdgeInsetsMake(statusBarHeight - systemTop, o.left, o.bottom, o.right);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
87
97
|
[self updateReactViewConstraints];
|
|
88
98
|
}
|
|
89
99
|
|
|
100
|
+
- (void)viewDidLayoutSubviews {
|
|
101
|
+
[super viewDidLayoutSubviews];
|
|
102
|
+
[self updateReactViewConstraints];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
- (CGFloat)hbd_statusBarHeight {
|
|
106
|
+
if (@available(iOS 13.0, *)) {
|
|
107
|
+
UIWindowScene *scene = self.view.window.windowScene;
|
|
108
|
+
if (scene) {
|
|
109
|
+
return scene.statusBarManager.statusBarFrame.size.height;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return [UIApplication sharedApplication].statusBarFrame.size.height;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/// 局部隐藏 topBar 或局部透明 topBar(非全局隐藏)时,需将 SafeArea 顶部修正为状态栏高度
|
|
116
|
+
- (BOOL)hbd_shouldCorrectSafeAreaTopToStatusBar {
|
|
117
|
+
if ([GlobalStyle globalStyle].topBarHidden) {
|
|
118
|
+
return NO;
|
|
119
|
+
}
|
|
120
|
+
if (![self.parentViewController isKindOfClass:UINavigationController.class]) {
|
|
121
|
+
return NO;
|
|
122
|
+
}
|
|
123
|
+
return self.hbd_barHidden || self.hbd_barAlpha < 1.0 || colorHasAlphaComponent(self.hbd_barTintColor);
|
|
124
|
+
}
|
|
125
|
+
|
|
90
126
|
- (void)updateReactViewConstraints {
|
|
91
127
|
if (self.isViewLoaded && self.rootView) {
|
|
92
|
-
CGFloat bottomInset = self.shouldFitWindowInsetsBottom ? 0: self.
|
|
93
|
-
CGFloat topInset
|
|
128
|
+
CGFloat bottomInset = self.shouldFitWindowInsetsBottom ? 0: self.tabBarController.tabBar.frame.size.height;
|
|
129
|
+
CGFloat topInset;
|
|
130
|
+
if (self.shouldFitWindowInsetsTop) {
|
|
131
|
+
topInset = self.hbd_shouldCorrectSafeAreaTopToStatusBar ? [self hbd_statusBarHeight] : 0;
|
|
132
|
+
} else {
|
|
133
|
+
topInset = self.view.safeAreaInsets.top;
|
|
134
|
+
}
|
|
94
135
|
[self.rootView setFrame:CGRectMake(
|
|
95
136
|
0,
|
|
96
137
|
topInset,
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
@property(nonatomic, copy, readonly) NSDictionary *props;
|
|
9
9
|
@property(nonatomic, copy, readonly) NSDictionary *options;
|
|
10
10
|
@property(nonatomic, assign, readonly) BOOL animatedTransition;
|
|
11
|
+
@property(nonatomic, assign, readonly) BOOL forceScreenLandscape;
|
|
11
12
|
|
|
12
13
|
- (instancetype)initWithModuleName:(NSString *)moduleName props:(NSDictionary *)props options:(NSDictionary *)options NS_DESIGNATED_INITIALIZER;
|
|
13
14
|
|
|
@@ -296,9 +296,11 @@
|
|
|
296
296
|
self.hbd_barAlpha = [topBarAlpha floatValue];
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
|
|
300
|
-
if ([
|
|
299
|
+
// 全局 topBarHidden 优先,一旦设置则局部开启无效
|
|
300
|
+
if ([GlobalStyle globalStyle].topBarHidden) {
|
|
301
301
|
self.hbd_barHidden = YES;
|
|
302
|
+
} else if (options[@"topBarHidden"] != nil) {
|
|
303
|
+
self.hbd_barHidden = [options[@"topBarHidden"] boolValue];
|
|
302
304
|
}
|
|
303
305
|
|
|
304
306
|
if ([GlobalStyle globalStyle].isBackTitleHidden) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hybrid-navigation",
|
|
3
3
|
"description": "React Native Navigation that supports seamless navigation between Native and React.",
|
|
4
|
-
"version": "3.0
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"main": "./dist/index",
|
|
6
6
|
"module": "./dist/index",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
package/src/Navigation.ts
CHANGED
|
@@ -21,8 +21,8 @@ import VisibilityEventHandler, {
|
|
|
21
21
|
} from './handler/VisibilityEventHandler';
|
|
22
22
|
|
|
23
23
|
import NativeEvent from './NativeEvent';
|
|
24
|
-
import
|
|
25
|
-
import
|
|
24
|
+
import NativeNavigation from './NativeNavigation';
|
|
25
|
+
import NativeGarden from './NativeGarden';
|
|
26
26
|
|
|
27
27
|
export type { ResultType } from './handler/ResultEventHandler';
|
|
28
28
|
import type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
|
|
@@ -34,7 +34,7 @@ type Nullable<T> = {
|
|
|
34
34
|
[P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P];
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export const { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK } =
|
|
37
|
+
export const { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK } = NativeNavigation.getConstants();
|
|
38
38
|
|
|
39
39
|
export type NavigationSubscription = {
|
|
40
40
|
remove: () => void;
|
|
@@ -113,7 +113,7 @@ class NavigationImpl implements Navigation {
|
|
|
113
113
|
startRegisterComponent(hoc?: HOC) {
|
|
114
114
|
this.hoc = hoc;
|
|
115
115
|
this.registerEnded = false;
|
|
116
|
-
|
|
116
|
+
NativeNavigation.startRegisterReactComponent();
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
endRegisterComponent() {
|
|
@@ -122,7 +122,7 @@ class NavigationImpl implements Navigation {
|
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
124
|
this.registerEnded = true;
|
|
125
|
-
|
|
125
|
+
NativeNavigation.endRegisterReactComponent();
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
registerComponent(
|
|
@@ -143,7 +143,7 @@ class NavigationImpl implements Navigation {
|
|
|
143
143
|
let options: object =
|
|
144
144
|
this.bindBarButtonClickEvent('permanent', (WrappedComponent as any).navigationItem) ||
|
|
145
145
|
{};
|
|
146
|
-
|
|
146
|
+
NativeNavigation.registerReactComponent(appKey, options);
|
|
147
147
|
|
|
148
148
|
let RootComponent = this.wrap!(appKey)(WrappedComponent);
|
|
149
149
|
AppRegistry.registerComponent(appKey, () => RootComponent);
|
|
@@ -206,7 +206,7 @@ class NavigationImpl implements Navigation {
|
|
|
206
206
|
'`resultCode` can only be `RESULT_OK`, `RESULT_CANCEL` or an integer greater than 0.',
|
|
207
207
|
);
|
|
208
208
|
}
|
|
209
|
-
|
|
209
|
+
NativeNavigation.setResult(sceneId, resultCode, data as object);
|
|
210
210
|
};
|
|
211
211
|
|
|
212
212
|
result<T extends ResultType>(sceneId: string, resultCode: number) {
|
|
@@ -227,74 +227,94 @@ class NavigationImpl implements Navigation {
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
currentTab(sceneId: string) {
|
|
230
|
-
return
|
|
230
|
+
return new Promise<number>(resolve => {
|
|
231
|
+
NativeNavigation.currentTab(sceneId, (_, index) => {
|
|
232
|
+
resolve(index);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
231
235
|
}
|
|
232
236
|
|
|
233
237
|
findSceneIdByModuleName(moduleName: string) {
|
|
234
|
-
return
|
|
238
|
+
return new Promise<string | null>(resolve => {
|
|
239
|
+
NativeNavigation.findSceneIdByModuleName(moduleName, (_, sceneId) => {
|
|
240
|
+
resolve(sceneId);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
235
243
|
}
|
|
236
244
|
|
|
237
245
|
isStackRoot(sceneId: string) {
|
|
238
|
-
return
|
|
246
|
+
return new Promise<boolean>(resolve => {
|
|
247
|
+
NativeNavigation.isStackRoot(sceneId, (_, result) => {
|
|
248
|
+
resolve(result);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
239
251
|
}
|
|
240
252
|
|
|
241
253
|
signalFirstRenderComplete(sceneId: string) {
|
|
242
|
-
|
|
254
|
+
NativeNavigation.signalFirstRenderComplete(sceneId);
|
|
243
255
|
}
|
|
244
256
|
|
|
245
257
|
currentRoute(): Promise<Route> {
|
|
246
|
-
return
|
|
258
|
+
return new Promise<Route>(resolve => {
|
|
259
|
+
NativeNavigation.currentRoute((_, route) => {
|
|
260
|
+
resolve(route);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
247
263
|
}
|
|
248
264
|
|
|
249
265
|
routeGraph(): Promise<RouteGraph[]> {
|
|
250
|
-
return
|
|
266
|
+
return new Promise<RouteGraph[]>(resolve => {
|
|
267
|
+
NativeNavigation.routeGraph((_, graph) => {
|
|
268
|
+
resolve(graph);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
251
271
|
}
|
|
252
272
|
|
|
253
273
|
setDefaultOptions(options: DefaultOptions) {
|
|
254
|
-
|
|
274
|
+
NativeGarden.setStyle(options);
|
|
255
275
|
}
|
|
256
276
|
|
|
257
277
|
setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null) {
|
|
258
278
|
const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
|
|
259
|
-
|
|
279
|
+
NativeGarden.setLeftBarButtonItem(sceneId, options);
|
|
260
280
|
}
|
|
261
281
|
|
|
262
282
|
setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null) {
|
|
263
283
|
const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
|
|
264
|
-
|
|
284
|
+
NativeGarden.setRightBarButtonItem(sceneId, options);
|
|
265
285
|
}
|
|
266
286
|
|
|
267
287
|
setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
|
|
268
288
|
const options = this.bindBarButtonClickEvent(sceneId, buttonItems) as Array<{}> | null;
|
|
269
|
-
|
|
289
|
+
NativeGarden.setLeftBarButtonItems(sceneId, options);
|
|
270
290
|
}
|
|
271
291
|
|
|
272
292
|
setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
|
|
273
293
|
const options = this.bindBarButtonClickEvent(sceneId, buttonItems) as Array<{}> | null;
|
|
274
|
-
|
|
294
|
+
NativeGarden.setRightBarButtonItems(sceneId, options);
|
|
275
295
|
}
|
|
276
296
|
|
|
277
297
|
setTitleItem(sceneId: string, titleItem: TitleItem) {
|
|
278
|
-
|
|
298
|
+
NativeGarden.setTitleItem(sceneId, titleItem);
|
|
279
299
|
}
|
|
280
300
|
|
|
281
301
|
updateOptions(sceneId: string, options: NavigationOption) {
|
|
282
|
-
|
|
302
|
+
NativeGarden.updateOptions(sceneId, options);
|
|
283
303
|
}
|
|
284
304
|
|
|
285
305
|
updateTabBar(sceneId: string, options: TabBarStyle) {
|
|
286
|
-
|
|
306
|
+
NativeGarden.updateTabBar(sceneId, options);
|
|
287
307
|
}
|
|
288
308
|
|
|
289
309
|
setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]) {
|
|
290
310
|
if (!Array.isArray(item)) {
|
|
291
311
|
item = [item];
|
|
292
312
|
}
|
|
293
|
-
|
|
313
|
+
NativeGarden.setTabItem(sceneId, item);
|
|
294
314
|
}
|
|
295
315
|
|
|
296
316
|
setMenuInteractive(sceneId: string, enabled: boolean) {
|
|
297
|
-
|
|
317
|
+
NativeGarden.setMenuInteractive(sceneId, enabled);
|
|
298
318
|
}
|
|
299
319
|
|
|
300
320
|
setBarButtonClickEventListener(listener: BarButtonClickEventListener) {
|
package/src/Options.ts
CHANGED
|
@@ -124,6 +124,7 @@ export interface DefaultOptions {
|
|
|
124
124
|
tabBarItemSelectedColor?: Color; // 底部 TabBarItem icon 选中颜色
|
|
125
125
|
tabBarItemNormalColor?: Color; // 底部 TabBarItem icon 未选中颜色,默认为 #666666
|
|
126
126
|
tabBarBadgeColor?: Color; // Tab badge 颜色
|
|
127
|
+
topBarHidden?: boolean; // 全局隐藏 TopBar,一旦设置则局部 topBarHidden: false 无效
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
export type TabBarStyle = Pick<
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import NativeNavigation from '../NativeNavigation';
|
|
2
2
|
import { NavigationItem } from '../Options';
|
|
3
3
|
import { BuildInLayout, Layout } from '../Route';
|
|
4
4
|
|
|
@@ -42,7 +42,11 @@ export default class DispatchCommandHandler {
|
|
|
42
42
|
if (intercepted) {
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
|
-
return
|
|
45
|
+
return new Promise<boolean>(resolve => {
|
|
46
|
+
NativeNavigation.dispatch(sceneId, action, params, (_, result) => {
|
|
47
|
+
resolve(result);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
private intercept(action: string, params: InterceptParams) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import NavigationModule from '../NavigationModule';
|
|
2
1
|
import { BuildInLayout, Layout } from '../Route';
|
|
3
2
|
import NativeEvent from '../NativeEvent';
|
|
3
|
+
import NativeNavigation from '../NativeNavigation';
|
|
4
4
|
|
|
5
5
|
export default class LayoutCommandHandler {
|
|
6
6
|
private willSetRoot = () => {};
|
|
@@ -18,7 +18,11 @@ export default class LayoutCommandHandler {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
setRoot(layout: BuildInLayout | Layout, sticky = false) {
|
|
21
|
-
return
|
|
21
|
+
return new Promise<boolean>(resolve => {
|
|
22
|
+
NativeNavigation.setRoot(layout, sticky, (_, success) => {
|
|
23
|
+
resolve(success);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { withNavigation } from './NavigationComponentWrap';
|
|
2
2
|
import navigation from './Navigation';
|
|
3
|
+
|
|
3
4
|
navigation.setNavigationComponentWrap(withNavigation);
|
|
4
5
|
const Navigation = navigation;
|
|
5
6
|
export default Navigation;
|
|
7
|
+
|
|
6
8
|
export { RESULT_OK, RESULT_CANCEL, RESULT_BLOCK } from './Navigation';
|
|
7
9
|
export { withNavigationItem } from './NavigationComponentWrap';
|
|
8
10
|
export type { NavigationProps } from './NavigationComponentWrap';
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Route, RouteGraph, RouteConfig, ResultType } from './NativeNavigation';
|
|
2
|
-
declare function getConstants(): {
|
|
3
|
-
RESULT_OK: number;
|
|
4
|
-
RESULT_CANCEL: number;
|
|
5
|
-
RESULT_BLOCK: number;
|
|
6
|
-
};
|
|
7
|
-
declare function startRegisterReactComponent(): void;
|
|
8
|
-
declare function endRegisterReactComponent(): void;
|
|
9
|
-
declare function registerReactComponent(appKey: string, options: RouteConfig): void;
|
|
10
|
-
declare function signalFirstRenderComplete(sceneId: string): void;
|
|
11
|
-
declare function setResult<T extends ResultType>(sceneId: string, resultCode: number, data: T): void;
|
|
12
|
-
declare function setRoot(layout: object, sticky: boolean): Promise<boolean>;
|
|
13
|
-
declare function dispatch(sceneId: string, action: string, params: object): Promise<boolean>;
|
|
14
|
-
declare function currentTab(sceneId: string): Promise<number>;
|
|
15
|
-
declare function isStackRoot(sceneId: string): Promise<boolean>;
|
|
16
|
-
declare function findSceneIdByModuleName(moduleName: string): Promise<string | null>;
|
|
17
|
-
declare function currentRoute(): Promise<Route>;
|
|
18
|
-
declare function routeGraph(): Promise<RouteGraph[]>;
|
|
19
|
-
declare const _default: {
|
|
20
|
-
getConstants: typeof getConstants;
|
|
21
|
-
startRegisterReactComponent: typeof startRegisterReactComponent;
|
|
22
|
-
endRegisterReactComponent: typeof endRegisterReactComponent;
|
|
23
|
-
registerReactComponent: typeof registerReactComponent;
|
|
24
|
-
signalFirstRenderComplete: typeof signalFirstRenderComplete;
|
|
25
|
-
setResult: typeof setResult;
|
|
26
|
-
setRoot: typeof setRoot;
|
|
27
|
-
dispatch: typeof dispatch;
|
|
28
|
-
currentTab: typeof currentTab;
|
|
29
|
-
isStackRoot: typeof isStackRoot;
|
|
30
|
-
findSceneIdByModuleName: typeof findSceneIdByModuleName;
|
|
31
|
-
currentRoute: typeof currentRoute;
|
|
32
|
-
routeGraph: typeof routeGraph;
|
|
33
|
-
};
|
|
34
|
-
export default _default;
|
package/dist/NavigationModule.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import NativeNavigation from './NativeNavigation';
|
|
2
|
-
function getConstants() {
|
|
3
|
-
return NativeNavigation.getConstants();
|
|
4
|
-
}
|
|
5
|
-
function startRegisterReactComponent() {
|
|
6
|
-
NativeNavigation.startRegisterReactComponent();
|
|
7
|
-
}
|
|
8
|
-
function endRegisterReactComponent() {
|
|
9
|
-
NativeNavigation.endRegisterReactComponent();
|
|
10
|
-
}
|
|
11
|
-
function registerReactComponent(appKey, options) {
|
|
12
|
-
NativeNavigation.registerReactComponent(appKey, options);
|
|
13
|
-
}
|
|
14
|
-
function signalFirstRenderComplete(sceneId) {
|
|
15
|
-
NativeNavigation.signalFirstRenderComplete(sceneId);
|
|
16
|
-
}
|
|
17
|
-
function setResult(sceneId, resultCode, data) {
|
|
18
|
-
NativeNavigation.setResult(sceneId, resultCode, data);
|
|
19
|
-
}
|
|
20
|
-
function setRoot(layout, sticky) {
|
|
21
|
-
return new Promise(resolve => {
|
|
22
|
-
NativeNavigation.setRoot(layout, sticky, (_, success) => {
|
|
23
|
-
resolve(success);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function dispatch(sceneId, action, params) {
|
|
28
|
-
return new Promise(resolve => {
|
|
29
|
-
NativeNavigation.dispatch(sceneId, action, params, (_, result) => {
|
|
30
|
-
resolve(result);
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
function currentTab(sceneId) {
|
|
35
|
-
return new Promise(resolve => {
|
|
36
|
-
NativeNavigation.currentTab(sceneId, (_, index) => {
|
|
37
|
-
resolve(index);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function isStackRoot(sceneId) {
|
|
42
|
-
return new Promise(resolve => {
|
|
43
|
-
NativeNavigation.isStackRoot(sceneId, (_, result) => {
|
|
44
|
-
resolve(result);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function findSceneIdByModuleName(moduleName) {
|
|
49
|
-
return new Promise(resolve => {
|
|
50
|
-
NativeNavigation.findSceneIdByModuleName(moduleName, (_, sceneId) => {
|
|
51
|
-
resolve(sceneId);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function currentRoute() {
|
|
56
|
-
return new Promise(resolve => {
|
|
57
|
-
NativeNavigation.currentRoute((_, route) => {
|
|
58
|
-
resolve(route);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function routeGraph() {
|
|
63
|
-
return new Promise(resolve => {
|
|
64
|
-
NativeNavigation.routeGraph((_, graph) => {
|
|
65
|
-
resolve(graph);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
export default {
|
|
70
|
-
getConstants,
|
|
71
|
-
startRegisterReactComponent,
|
|
72
|
-
endRegisterReactComponent,
|
|
73
|
-
registerReactComponent,
|
|
74
|
-
signalFirstRenderComplete,
|
|
75
|
-
setResult,
|
|
76
|
-
setRoot,
|
|
77
|
-
dispatch,
|
|
78
|
-
currentTab,
|
|
79
|
-
isStackRoot,
|
|
80
|
-
findSceneIdByModuleName,
|
|
81
|
-
currentRoute,
|
|
82
|
-
routeGraph,
|
|
83
|
-
};
|
package/src/NavigationModule.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import type { Route, RouteGraph, RouteConfig, ResultType } from './NativeNavigation';
|
|
2
|
-
import NativeNavigation from './NativeNavigation';
|
|
3
|
-
|
|
4
|
-
function getConstants() {
|
|
5
|
-
return NativeNavigation.getConstants();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function startRegisterReactComponent() {
|
|
9
|
-
NativeNavigation.startRegisterReactComponent();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function endRegisterReactComponent() {
|
|
13
|
-
NativeNavigation.endRegisterReactComponent();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function registerReactComponent(appKey: string, options: RouteConfig) {
|
|
17
|
-
NativeNavigation.registerReactComponent(appKey, options);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function signalFirstRenderComplete(sceneId: string) {
|
|
21
|
-
NativeNavigation.signalFirstRenderComplete(sceneId);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function setResult<T extends ResultType>(sceneId: string, resultCode: number, data: T) {
|
|
25
|
-
NativeNavigation.setResult(sceneId, resultCode, data as object);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function setRoot(layout: object, sticky: boolean) {
|
|
29
|
-
return new Promise<boolean>(resolve => {
|
|
30
|
-
NativeNavigation.setRoot(layout, sticky, (_, success) => {
|
|
31
|
-
resolve(success);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function dispatch(sceneId: string, action: string, params: object) {
|
|
37
|
-
return new Promise<boolean>(resolve => {
|
|
38
|
-
NativeNavigation.dispatch(sceneId, action, params, (_, result) => {
|
|
39
|
-
resolve(result);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function currentTab(sceneId: string) {
|
|
45
|
-
return new Promise<number>(resolve => {
|
|
46
|
-
NativeNavigation.currentTab(sceneId, (_, index) => {
|
|
47
|
-
resolve(index);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function isStackRoot(sceneId: string) {
|
|
53
|
-
return new Promise<boolean>(resolve => {
|
|
54
|
-
NativeNavigation.isStackRoot(sceneId, (_, result) => {
|
|
55
|
-
resolve(result);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function findSceneIdByModuleName(moduleName: string) {
|
|
61
|
-
return new Promise<string | null>(resolve => {
|
|
62
|
-
NativeNavigation.findSceneIdByModuleName(moduleName, (_, sceneId) => {
|
|
63
|
-
resolve(sceneId);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function currentRoute() {
|
|
69
|
-
return new Promise<Route>(resolve => {
|
|
70
|
-
NativeNavigation.currentRoute((_, route) => {
|
|
71
|
-
resolve(route);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function routeGraph() {
|
|
77
|
-
return new Promise<RouteGraph[]>(resolve => {
|
|
78
|
-
NativeNavigation.routeGraph((_, graph) => {
|
|
79
|
-
resolve(graph);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export default {
|
|
85
|
-
getConstants,
|
|
86
|
-
startRegisterReactComponent,
|
|
87
|
-
endRegisterReactComponent,
|
|
88
|
-
registerReactComponent,
|
|
89
|
-
signalFirstRenderComplete,
|
|
90
|
-
setResult,
|
|
91
|
-
setRoot,
|
|
92
|
-
dispatch,
|
|
93
|
-
currentTab,
|
|
94
|
-
isStackRoot,
|
|
95
|
-
findSceneIdByModuleName,
|
|
96
|
-
currentRoute,
|
|
97
|
-
routeGraph,
|
|
98
|
-
};
|