hybrid-navigation 2.18.3 → 2.18.5
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/LICENSE +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +4 -54
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +0 -3
- package/{lib → dist}/Navigation.js +3 -2
- package/{lib → dist}/NavigationComponentWrap.js +6 -5
- package/{lib → dist}/Navigator.d.ts +0 -1
- package/{lib → dist}/Navigator.js +15 -4
- package/{lib → dist}/hooks.js +2 -1
- package/{lib → dist}/router/index.js +6 -2
- package/{lib → dist}/router/stack.js +1 -1
- package/ios/HybridNavigation/HBDUtils.h +2 -0
- package/ios/HybridNavigation/HBDUtils.m +12 -3
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +2 -6
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +11 -12
- package/ios/HybridNavigation/ViewController/HBDDrawerController.m +1 -1
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +1 -1
- package/ios/HybridNavigation/ViewController/HBDViewController.m +1 -1
- package/package.json +47 -78
- package/src/DeepLink.ts +52 -52
- package/src/Event.ts +88 -83
- package/src/GardenModule.ts +30 -30
- package/src/Navigation.ts +293 -281
- package/src/NavigationComponentWrap.tsx +52 -47
- package/src/NavigationModule.ts +77 -77
- package/src/Navigator.ts +212 -201
- package/src/Options.ts +120 -112
- package/src/Route.ts +59 -59
- package/src/handler/BarButtonEventHandler.ts +50 -46
- package/src/handler/DispatchCommandHandler.ts +56 -52
- package/src/handler/LayoutCommandHandler.ts +21 -21
- package/src/handler/ResultEventHandler.ts +63 -49
- package/src/handler/VisibilityEventHandler.ts +57 -40
- package/src/hooks.ts +23 -21
- package/src/index.ts +15 -15
- package/src/router/drawer.ts +24 -24
- package/src/router/index.ts +206 -198
- package/src/router/screen.ts +28 -28
- package/src/router/stack.ts +76 -76
- package/src/router/tabs.ts +28 -28
- package/src/store.ts +9 -9
- package/README.md +0 -79
- /package/{lib → dist}/DeepLink.d.ts +0 -0
- /package/{lib → dist}/DeepLink.js +0 -0
- /package/{lib → dist}/Event.d.ts +0 -0
- /package/{lib → dist}/Event.js +0 -0
- /package/{lib → dist}/GardenModule.d.ts +0 -0
- /package/{lib → dist}/GardenModule.js +0 -0
- /package/{lib → dist}/Navigation.d.ts +0 -0
- /package/{lib → dist}/NavigationComponentWrap.d.ts +0 -0
- /package/{lib → dist}/NavigationModule.d.ts +0 -0
- /package/{lib → dist}/NavigationModule.js +0 -0
- /package/{lib → dist}/Options.d.ts +0 -0
- /package/{lib → dist}/Options.js +0 -0
- /package/{lib → dist}/Route.d.ts +0 -0
- /package/{lib → dist}/Route.js +0 -0
- /package/{lib → dist}/handler/BarButtonEventHandler.d.ts +0 -0
- /package/{lib → dist}/handler/BarButtonEventHandler.js +0 -0
- /package/{lib → dist}/handler/DispatchCommandHandler.d.ts +0 -0
- /package/{lib → dist}/handler/DispatchCommandHandler.js +0 -0
- /package/{lib → dist}/handler/LayoutCommandHandler.d.ts +0 -0
- /package/{lib → dist}/handler/LayoutCommandHandler.js +0 -0
- /package/{lib → dist}/handler/ResultEventHandler.d.ts +0 -0
- /package/{lib → dist}/handler/ResultEventHandler.js +0 -0
- /package/{lib → dist}/handler/VisibilityEventHandler.d.ts +0 -0
- /package/{lib → dist}/handler/VisibilityEventHandler.js +0 -0
- /package/{lib → dist}/hooks.d.ts +0 -0
- /package/{lib → dist}/index.d.ts +0 -0
- /package/{lib → dist}/index.js +0 -0
- /package/{lib → dist}/router/drawer.d.ts +0 -0
- /package/{lib → dist}/router/drawer.js +0 -0
- /package/{lib → dist}/router/index.d.ts +0 -0
- /package/{lib → dist}/router/screen.d.ts +0 -0
- /package/{lib → dist}/router/screen.js +0 -0
- /package/{lib → dist}/router/stack.d.ts +0 -0
- /package/{lib → dist}/router/tabs.d.ts +0 -0
- /package/{lib → dist}/router/tabs.js +0 -0
- /package/{lib → dist}/store.d.ts +0 -0
- /package/{lib → dist}/store.js +0 -0
package/src/Options.ts
CHANGED
|
@@ -1,146 +1,154 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type {Insets} from 'react-native';
|
|
2
|
+
import type {Navigator} from './Navigator';
|
|
3
3
|
|
|
4
|
-
export type Color = string
|
|
5
|
-
export type ImageSource = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
export type Color = string;
|
|
5
|
+
export type ImageSource = {
|
|
6
|
+
uri: string;
|
|
7
|
+
scale?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
width?: number;
|
|
10
|
+
};
|
|
11
|
+
export const BarStyleLightContent = 'light-content';
|
|
12
|
+
export type BarStyleLightContent = typeof BarStyleLightContent;
|
|
13
|
+
export const BarStyleDarkContent = 'dark-content';
|
|
14
|
+
export type BarStyleDarkContent = typeof BarStyleDarkContent;
|
|
15
|
+
export type BarStyle = BarStyleLightContent | BarStyleDarkContent;
|
|
11
16
|
|
|
12
|
-
export const TitleAlignmentLeft = 'left'
|
|
13
|
-
export type TitleAlignmentLeft = typeof TitleAlignmentLeft
|
|
14
|
-
export const TitleAlignmentCenter = 'center'
|
|
15
|
-
export type TitleAlignmentCenter = typeof TitleAlignmentCenter
|
|
16
|
-
export type TitleAlignment = TitleAlignmentCenter | TitleAlignmentLeft
|
|
17
|
+
export const TitleAlignmentLeft = 'left';
|
|
18
|
+
export type TitleAlignmentLeft = typeof TitleAlignmentLeft;
|
|
19
|
+
export const TitleAlignmentCenter = 'center';
|
|
20
|
+
export type TitleAlignmentCenter = typeof TitleAlignmentCenter;
|
|
21
|
+
export type TitleAlignment = TitleAlignmentCenter | TitleAlignmentLeft;
|
|
17
22
|
|
|
18
|
-
export const LayoutFittingExpanded = 'expanded'
|
|
19
|
-
export type LayoutFittingExpanded = typeof LayoutFittingExpanded
|
|
20
|
-
export const LayoutFittingCompressed = 'compressed'
|
|
21
|
-
export type LayoutFittingCompressed = typeof LayoutFittingCompressed
|
|
22
|
-
export type LayoutFitting = LayoutFittingExpanded | LayoutFittingCompressed
|
|
23
|
+
export const LayoutFittingExpanded = 'expanded';
|
|
24
|
+
export type LayoutFittingExpanded = typeof LayoutFittingExpanded;
|
|
25
|
+
export const LayoutFittingCompressed = 'compressed';
|
|
26
|
+
export type LayoutFittingCompressed = typeof LayoutFittingCompressed;
|
|
27
|
+
export type LayoutFitting = LayoutFittingExpanded | LayoutFittingCompressed;
|
|
23
28
|
|
|
24
29
|
export interface NavigationOption {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
30
|
+
screenBackgroundColor?: Color; // 页面背景,默认是白色
|
|
31
|
+
statusBarHidden?: boolean; // 是否隐藏状态栏
|
|
32
|
+
statusBarColorAndroid?: Color; // 状态栏背景颜色
|
|
33
|
+
topBarStyle?: BarStyle; // TopBar 样式,决定了状态栏的颜色,可选项有 `BarStyleLightContent` 和 `BarStyleDarkContent`
|
|
34
|
+
topBarColor?: Color; // TopBar 背景颜色
|
|
35
|
+
topBarShadowHidden?: boolean; // 是否隐藏 TopBar 的阴影
|
|
36
|
+
topBarAlpha?: number; // TopBar 背景透明度
|
|
37
|
+
topBarTintColor?: Color; // TopBar 按钮颜色
|
|
38
|
+
titleTextColor?: Color; // TopBar 标题题字体颜色
|
|
39
|
+
titleTextSize?: number; // TopBar 标题字体大小
|
|
40
|
+
navigationBarColorAndroid?: Color; // Android 底部虚拟按钮背景颜色
|
|
41
|
+
navigationBarHiddenAndroid?: boolean; // 是否隐藏 Android 底部的虚拟导航栏
|
|
42
|
+
fitsOpaqueNavigationBarAndroid?: boolean; // 适配不透明的导航栏边衬区,默认为 true
|
|
43
|
+
displayCutoutWhenLandscapeAndroid?: boolean; // 横屏时,是否将界面延伸至刘海区域,默认 true
|
|
44
|
+
homeIndicatorAutoHiddenIOS?: boolean; // 是否隐藏 Home 指示器,默认 false
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
backButtonHidden?: boolean; // 是否显示返回按钮
|
|
47
|
+
backInteractive?: boolean; // 是否允许侧滑返回或通过返回键返回
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
export interface NavigationItem extends NavigationOption {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
passThroughTouches?: boolean; // 触摸事件是否可以穿透到下一层页面,很少用。
|
|
52
|
+
forceTransparentDialogWindow?: boolean; // 当页面是 Dialog 时,是否强制背景透明
|
|
53
|
+
animatedTransition?: boolean;
|
|
54
|
+
forceScreenLandscape?: boolean; // 是否强制横屏
|
|
55
|
+
topBarHidden?: boolean; // 是否隐藏 TopBar
|
|
56
|
+
extendedLayoutIncludesTopBar?: boolean; // 页面内容是否延伸到 TopBar 底下,通常用于需要动态改变 `topBarAlpha` 的场合
|
|
57
|
+
swipeBackEnabled?: boolean; // 是否可以通过右滑返回。如果 `backInteractive` 设置为 false, 那么该值无效。Android 下,只有开启了侧滑返回功能,该值才会生效。
|
|
58
|
+
titleItem?: TitleItem;
|
|
59
|
+
leftBarButtonItem?: BarButtonItem;
|
|
60
|
+
rightBarButtonItem?: BarButtonItem;
|
|
61
|
+
leftBarButtonItems?: BarButtonItem[];
|
|
62
|
+
rightBarButtonItems?: BarButtonItem[];
|
|
63
|
+
backItemIOS?: BackItem;
|
|
64
|
+
tabItem?: TabItem;
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
export interface BarButtonItem {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
title?: string;
|
|
69
|
+
icon?: ImageSource;
|
|
70
|
+
insetsIOS?: Insets;
|
|
71
|
+
action?: (navigator: Navigator) => void;
|
|
72
|
+
enabled?: boolean;
|
|
73
|
+
tintColor?: Color;
|
|
74
|
+
renderOriginal?: boolean;
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
export interface TitleItem {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
title?: string;
|
|
79
|
+
moduleName?: string;
|
|
80
|
+
layoutFitting?: LayoutFitting;
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
export interface BackItem {
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
title: string;
|
|
85
|
+
tintColor?: Color;
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
export interface TabItem {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
89
|
+
title: string;
|
|
90
|
+
icon?: ImageSource;
|
|
91
|
+
unselectedIcon?: ImageSource;
|
|
92
|
+
hideTabBarWhenPush?: boolean;
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
export interface ShadowImage {
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
image?: ImageSource;
|
|
97
|
+
color?: Color;
|
|
93
98
|
}
|
|
94
99
|
|
|
95
100
|
export interface DefaultOptions {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
101
|
+
screenBackgroundColor?: Color; // 页面背景,默认是白色
|
|
102
|
+
topBarStyle?: BarStyle; // TopBar 样式,决定了状态栏的颜色,可选项有 `BarStyleLightContent` 和 `BarStyleDarkContent`
|
|
103
|
+
topBarColor?: Color; // TopBar 背景颜色,默认根据 topBarStyle 来计算
|
|
104
|
+
topBarColorDarkContent?: Color; // TopBar 背景颜色,当 topBarStyle 的值为 BarStyleDarkContent 时生效,覆盖 topBarColor 的值
|
|
105
|
+
topBarColorLightContent?: Color; // TopBar 背景颜色,当 topBarStyle 的值为 BarStyleLightContent 时生效,覆盖 topBarColor 的值
|
|
106
|
+
statusBarColorAndroid?: Color; // 状态栏背景颜色,默认取 topBarColor 的值
|
|
107
|
+
navigationBarColorAndroid?: Color; // 底部虚拟键背景颜色,仅对 Android 8.0 以上版本生效
|
|
108
|
+
hideBackTitleIOS?: boolean; // 是否隐藏返回按钮旁边的文字,默认是 false, 仅对 iOS 生效
|
|
109
|
+
elevationAndroid?: number; // TopBar 阴影高度,默认值为 4 dp
|
|
110
|
+
shadowImage?: ShadowImage; // TopBar 阴影图片,仅对 iOS 生效
|
|
111
|
+
backIcon?: ImageSource; // 返回按钮图片
|
|
112
|
+
topBarTintColor?: Color; // TopBar 按钮的颜色。默认根据 topBarStyle 来计算
|
|
113
|
+
topBarTintColorDarkContent?: Color; // TopBar 按钮颜色,当 topBarStyle 的值为 BarStyleDarkContent 时生效,覆盖 topBarTintColor 的值
|
|
114
|
+
topBarTintColorLightContent?: Color; // TopBar 按钮颜色,当 topBarStyle 的值为 BarStyleLightContent 时生效,覆盖 topBarTintColor 的值
|
|
115
|
+
titleTextColor?: Color; // TopBar 标题颜色,默认根据 topBarStyle 来计算
|
|
116
|
+
titleTextColorDarkContent?: Color; // TopBar 标题颜色,当 topBarStyle 的值为 BarStyleDarkContent 时生效,覆盖 titleTextColor 的值
|
|
117
|
+
titleTextColorLightContent?: Color; // TopBar 标题颜色,当 topBarStyle 的值为 BarStyleLightContent 时生效,覆盖 titleTextColor 的值
|
|
118
|
+
titleTextSize?: number; // TopBar 标题字体大小,默认是 17 dp(pt)
|
|
119
|
+
titleAlignmentAndroid?: TitleAlignment; // TopBar 标题的位置,可选项有 `TitleAlignmentLeft` 和 `TitleAlignmentCenter` ,仅对 Android 生效
|
|
120
|
+
barButtonItemTextSize?: number; // TopBar 按钮字体大小,默认是 15 dp(pt)
|
|
121
|
+
swipeBackEnabledAndroid?: boolean; // Android 是否开启右滑返回,默认是 false
|
|
122
|
+
splitTopBarTransitionIOS?: boolean; // iOS 侧滑返回时,是否总是割裂导航栏背景
|
|
123
|
+
scrimAlphaAndroid?: number; // Android 侧滑返回遮罩效果 [0 - 255]
|
|
124
|
+
fitsOpaqueNavigationBarAndroid?: boolean; // 适配不透明的导航栏边衬区,默认为 true
|
|
125
|
+
displayCutoutWhenLandscapeAndroid?: boolean; // 横屏时,是否将界面延伸至刘海区域,默认 true
|
|
121
126
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
tabBarColor?: Color; // 底部 TabBar 背景颜色,请勿使用带透明度的颜色。
|
|
128
|
+
tabBarShadowImage?: ShadowImage; // 底部 TabBar 阴影图片。对于 iOS, 只有同时设置了 tabBarColor 才会生效
|
|
129
|
+
tabBarItemColor?: Color; // 底部 TabBarItem icon 选中颜色
|
|
130
|
+
tabBarUnselectedItemColor?: Color; // 底部 TabBarItem icon 未选中颜色,默认为 #BDBDBD
|
|
131
|
+
tabBarBadgeColor?: Color; // Tab badge 颜色
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
export type TabBarStyle = Pick<
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
135
|
+
DefaultOptions,
|
|
136
|
+
| 'tabBarColor'
|
|
137
|
+
| 'tabBarShadowImage'
|
|
138
|
+
| 'tabBarItemColor'
|
|
139
|
+
| 'tabBarUnselectedItemColor'
|
|
140
|
+
>;
|
|
133
141
|
|
|
134
142
|
export interface TabItemInfo {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
index: number;
|
|
144
|
+
title?: string;
|
|
145
|
+
badge?: {
|
|
146
|
+
text?: string;
|
|
147
|
+
hidden: boolean;
|
|
148
|
+
dot?: boolean;
|
|
149
|
+
};
|
|
150
|
+
icon?: {
|
|
151
|
+
selected: ImageSource;
|
|
152
|
+
unselected?: ImageSource;
|
|
153
|
+
};
|
|
146
154
|
}
|
package/src/Route.ts
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
export type Visibility = 'visible' | 'invisible' | 'pending'
|
|
1
|
+
export type Visibility = 'visible' | 'invisible' | 'pending';
|
|
2
2
|
|
|
3
3
|
export interface Screen extends Layout {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
screen: {
|
|
5
|
+
moduleName: string;
|
|
6
|
+
props?: object;
|
|
7
|
+
options?: {};
|
|
8
|
+
};
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface Stack extends Layout {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
stack: {
|
|
13
|
+
children: Array<BuildInLayout | Layout>;
|
|
14
|
+
options?: {};
|
|
15
|
+
};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export interface Tabs extends Layout {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
tabs: {
|
|
20
|
+
children: Array<BuildInLayout | Layout>;
|
|
21
|
+
options?: {
|
|
22
|
+
selectedIndex?: number;
|
|
23
|
+
tabBarModuleName?: string;
|
|
24
|
+
sizeIndeterminate?: boolean;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export interface Drawer extends Layout {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
drawer: {
|
|
31
|
+
children: [BuildInLayout | Layout, BuildInLayout | Layout];
|
|
32
|
+
options?: {
|
|
33
|
+
maxDrawerWidth?: number;
|
|
34
|
+
minDrawerMargin?: number;
|
|
35
|
+
menuInteractive?: boolean;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export type BuildInLayout = Screen | Stack | Tabs | Drawer
|
|
40
|
+
export type BuildInLayout = Screen | Stack | Tabs | Drawer;
|
|
41
41
|
|
|
42
42
|
export interface Layout {
|
|
43
|
-
|
|
43
|
+
[index: string]: {};
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export type RouteMode = 'modal' | 'present' | 'push'
|
|
47
|
-
export type LayoutMode = 'modal' | 'present' | 'normal'
|
|
46
|
+
export type RouteMode = 'modal' | 'present' | 'push';
|
|
47
|
+
export type LayoutMode = 'modal' | 'present' | 'normal';
|
|
48
48
|
|
|
49
49
|
export interface Route {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
sceneId: string;
|
|
51
|
+
moduleName: string;
|
|
52
|
+
mode: LayoutMode;
|
|
53
|
+
presentingId: string | null;
|
|
54
|
+
requestCode: number;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export interface RouteGraph {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
layout: string;
|
|
59
|
+
sceneId: string;
|
|
60
|
+
mode: LayoutMode;
|
|
61
|
+
children?: RouteGraph[];
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export interface RouteConfig {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
path?: string;
|
|
66
|
+
dependency?: string;
|
|
67
|
+
mode?: RouteMode;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
export interface RouteData {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
moduleName: string;
|
|
72
|
+
regexp?: RegExp;
|
|
73
|
+
path?: string;
|
|
74
|
+
dependency?: string;
|
|
75
|
+
mode: RouteMode;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
export interface RouteInfo {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
moduleName: string;
|
|
80
|
+
mode: RouteMode;
|
|
81
|
+
dependencies: string[];
|
|
82
|
+
props: object;
|
|
83
|
+
options: object;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
export interface RouteHandler {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
/**
|
|
88
|
+
* @param graph - current RouteGraph to process
|
|
89
|
+
* @param target - route may add to the graph
|
|
90
|
+
* @returns [boolean, RouteGraph] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
|
|
91
|
+
*/
|
|
92
|
+
process: (graph: RouteGraph, target: RouteInfo) => Promise<[boolean, RouteGraph | null]>;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
export type RouteInterceptor = (path: string) => boolean | Promise<boolean
|
|
95
|
+
export type RouteInterceptor = (path: string) => boolean | Promise<boolean>;
|
|
@@ -1,50 +1,54 @@
|
|
|
1
|
-
import Event from '../Event'
|
|
1
|
+
import Event from '../Event';
|
|
2
2
|
|
|
3
|
-
type BarButtonClickEventListener = (sceneId: string, value: Function) => void
|
|
3
|
+
type BarButtonClickEventListener = (sceneId: string, value: Function) => void;
|
|
4
4
|
|
|
5
5
|
export default class BarButtonEventHandler {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
6
|
+
private actions: Record<string, Function> = {};
|
|
7
|
+
private keyPairs: Record<string, string[]> = {};
|
|
8
|
+
private actionIdGenerator = 0;
|
|
9
|
+
|
|
10
|
+
bindBarButtonClickEvent(
|
|
11
|
+
sceneId: string,
|
|
12
|
+
item: object | null | undefined,
|
|
13
|
+
): object | null {
|
|
14
|
+
if (item === null || item === undefined) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return JSON.parse(
|
|
19
|
+
JSON.stringify(item, (key, value) => {
|
|
20
|
+
if (key !== 'action' || typeof value !== 'function') {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const actionKey =
|
|
25
|
+
'ON_BAR_BUTTON_ITEM_CLICK_' + this.actionIdGenerator++;
|
|
26
|
+
|
|
27
|
+
if (!this.keyPairs[sceneId]) {
|
|
28
|
+
this.keyPairs[sceneId] = [];
|
|
29
|
+
}
|
|
30
|
+
this.keyPairs[sceneId].push(actionKey);
|
|
31
|
+
this.actions[actionKey] = value;
|
|
32
|
+
|
|
33
|
+
return actionKey;
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
unbindBarButtonClickEvent(sceneId: string): void {
|
|
39
|
+
const keys = this.keyPairs[sceneId];
|
|
40
|
+
delete this.keyPairs[sceneId];
|
|
41
|
+
if (keys) {
|
|
42
|
+
keys.forEach(key => delete this.actions[key]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
setBarButtonClickEventListener(handler: BarButtonClickEventListener) {
|
|
47
|
+
Event.listenBarButtonItemClick((sceneId: string, action: string) => {
|
|
48
|
+
const listeners = this.actions;
|
|
49
|
+
if (listeners[action]) {
|
|
50
|
+
handler(sceneId, listeners[action]);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
50
54
|
}
|
|
@@ -1,63 +1,67 @@
|
|
|
1
|
-
import NavigationModule from '../NavigationModule'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import NavigationModule from '../NavigationModule';
|
|
2
|
+
import {NavigationItem} from '../Options';
|
|
3
|
+
import {BuildInLayout, Layout} from '../Route';
|
|
4
4
|
|
|
5
5
|
export interface DispatchParams {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
animated?: boolean;
|
|
7
|
+
moduleName?: string;
|
|
8
|
+
from?: string | number;
|
|
9
|
+
to?: string | number;
|
|
10
|
+
layout?: BuildInLayout | Layout;
|
|
11
|
+
popToRoot?: boolean;
|
|
12
|
+
requestCode?: number;
|
|
13
|
+
props?: object;
|
|
14
|
+
options?: NavigationItem;
|
|
15
|
+
[index: string]: any;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
interface InterceptParams {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
sceneId: string;
|
|
20
|
+
from?: number | string;
|
|
21
|
+
to?: number | string;
|
|
22
|
+
props?: object;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export type NavigationInterceptor = (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
) => boolean | Promise<boolean
|
|
26
|
+
action: string,
|
|
27
|
+
params: InterceptParams,
|
|
28
|
+
) => boolean | Promise<boolean>;
|
|
29
29
|
|
|
30
30
|
export default class DispatchCommandHandler {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
31
|
+
private interceptor: NavigationInterceptor = () => false;
|
|
32
|
+
|
|
33
|
+
async dispatch(
|
|
34
|
+
sceneId: string,
|
|
35
|
+
action: string,
|
|
36
|
+
params: DispatchParams,
|
|
37
|
+
): Promise<boolean> {
|
|
38
|
+
const {from, to, props} = params;
|
|
39
|
+
const intercepted = await this.intercept(action, {
|
|
40
|
+
sceneId,
|
|
41
|
+
from,
|
|
42
|
+
to,
|
|
43
|
+
props,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
if (intercepted) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return NavigationModule.dispatch(sceneId, action, params);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private intercept(action: string, params: InterceptParams) {
|
|
53
|
+
if (!this.interceptor) {
|
|
54
|
+
return Promise.resolve(false);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const result = this.interceptor(action, params);
|
|
58
|
+
if (result instanceof Promise) {
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
return Promise.resolve(result);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setInterceptor(interceptor: NavigationInterceptor) {
|
|
65
|
+
this.interceptor = interceptor;
|
|
66
|
+
}
|
|
63
67
|
}
|