hybrid-navigation 2.9.0 → 2.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/HybridNavigation.podspec +6 -6
  2. package/LICENSE +1 -1
  3. package/android/build.gradle +4 -4
  4. package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +27 -40
  5. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +77 -48
  6. package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +4 -4
  7. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +94 -43
  8. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +134 -117
  9. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +65 -35
  10. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +14 -3
  11. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +133 -92
  12. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +161 -126
  13. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +145 -114
  14. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +40 -28
  15. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +96 -75
  16. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/Navigator.java +1 -1
  17. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +111 -79
  18. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +187 -117
  19. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +137 -96
  20. package/ios/HybridNavigation/ViewController/HBDModalViewController.m +7 -0
  21. package/lib/Navigator.js +0 -1
  22. package/lib/ReactRegistry.d.ts +3 -3
  23. package/lib/typing.d.ts +1 -2
  24. package/package.json +24 -16
  25. package/src/DeepLink.ts +60 -0
  26. package/src/Garden.ts +171 -0
  27. package/src/NavigationModule.ts +33 -0
  28. package/src/Navigator.ts +403 -0
  29. package/src/ReactRegistry.tsx +138 -0
  30. package/src/hooks.ts +83 -0
  31. package/src/index.ts +9 -0
  32. package/src/router/drawer.ts +34 -0
  33. package/src/router/index.ts +166 -0
  34. package/src/router/screen.ts +12 -0
  35. package/src/router/stack.ts +80 -0
  36. package/src/router/tabs.ts +49 -0
  37. package/src/router/typing.ts +45 -0
  38. package/src/store.ts +49 -0
  39. package/src/typing.ts +148 -0
  40. package/src/utils.ts +83 -0
  41. package/.buckconfig +0 -6
  42. package/.editorconfig +0 -16
  43. package/.eslintignore +0 -5
  44. package/.gitattributes +0 -1
  45. package/.github/workflows/docs.yml +0 -25
  46. package/CHANGELOG.md +0 -429
  47. package/babel.config.js +0 -15
  48. package/docs/README.md +0 -109
  49. package/docs/custom-tabbar.md +0 -138
  50. package/docs/deeplink.md +0 -148
  51. package/docs/integration-native.md +0 -390
  52. package/docs/integration-react.md +0 -194
  53. package/docs/lifecycle.md +0 -85
  54. package/docs/navigation.md +0 -589
  55. package/docs/pass-and-return-value.md +0 -163
  56. package/docs/qa.md +0 -81
  57. package/docs/style.md +0 -533
  58. package/jest.config.js +0 -4
  59. package/metro.config.js +0 -17
  60. package/screenshot/android.png +0 -0
  61. package/screenshot/bulge.jpg +0 -0
  62. package/screenshot/controller-base.jpg +0 -0
  63. package/screenshot/demo-qrcode.png +0 -0
  64. package/screenshot/header-search-paths.jpg +0 -0
  65. package/screenshot/ios-react-script.png +0 -0
  66. package/screenshot/ios-run-script.jpg +0 -0
  67. package/screenshot/statusbar-inperfect.png +0 -0
  68. package/screenshot/statusbar-setup-step-1.png +0 -0
  69. package/screenshot/statusbar-setup-step-2.png +0 -0
  70. package/screenshot/tabbar.jpg +0 -0
  71. package/screenshot/topbar-default.png +0 -0
  72. package/screenshot/xcode-linking.png +0 -0
package/lib/typing.d.ts CHANGED
@@ -39,7 +39,6 @@ export declare type LayoutFittingCompressed = typeof LayoutFittingCompressed;
39
39
  export declare type LayoutFitting = LayoutFittingExpanded | LayoutFittingCompressed;
40
40
  export interface NavigationOption {
41
41
  screenBackgroundColor?: Color;
42
- passThroughTouches?: boolean;
43
42
  statusBarHidden?: boolean;
44
43
  statusBarColorAndroid?: Color;
45
44
  topBarStyle?: BarStyle;
@@ -57,7 +56,7 @@ export interface NavigationOption {
57
56
  backInteractive?: boolean;
58
57
  }
59
58
  export interface NavigationItem extends NavigationOption {
60
- screenBackgroundColor?: Color;
59
+ passThroughTouches?: boolean;
61
60
  forceTransparentDialogWindow?: boolean;
62
61
  topBarHidden?: boolean;
63
62
  extendedLayoutIncludesTopBar?: boolean;
package/package.json CHANGED
@@ -1,7 +1,26 @@
1
1
  {
2
2
  "name": "hybrid-navigation",
3
3
  "description": "React Native Navigation that supports seamless navigation between Native and React.",
4
- "version": "2.9.0",
4
+ "version": "2.10.2",
5
+ "main": "./lib/index.js",
6
+ "typings": "./lib/index.d.ts",
7
+ "react-native": "src/index",
8
+ "nativePackage": true,
9
+ "files": [
10
+ "src",
11
+ "lib",
12
+ "android",
13
+ "ios",
14
+ "HybridNavigation.podspec",
15
+ "!android/build",
16
+ "!ios/build",
17
+ "!**/__tests__"
18
+ ],
19
+ "repository": "https://github.com/listenzz/hybrid-navigation",
20
+ "homepage": "https://github.com/listenzz/hybrid-navigation#readme",
21
+ "author": "listen <listenzz@163.com> (https://github.com/listenzz)",
22
+ "license": "MIT",
23
+ "licenseFilename": "LICENSE",
5
24
  "keywords": [
6
25
  "react-native",
7
26
  "navigation",
@@ -9,25 +28,15 @@
9
28
  "router",
10
29
  "hybrid"
11
30
  ],
12
- "nativePackage": true,
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/listenzz/hybrid-navigation.git"
16
- },
17
- "homepage": "https://github.com/listenzz/hybrid-navigation",
18
- "author": "listen <listenzz@163.com>",
19
- "license": "MIT",
20
- "main": "./lib/index.js",
21
- "typings": "./lib/index.d.ts",
22
31
  "scripts": {
23
32
  "build": "rm -rf ./lib && tsc -p tsconfig.build.json",
24
33
  "prepare": "npm run build",
25
- "tsc": "tsc",
26
34
  "start": "react-native start --reset-cache",
27
35
  "run:ios": "react-native run-ios --project-path ./example/ios",
28
36
  "start:android": "adb shell am start -n com.reactnative.hybridnavigation.example/.MainActivity",
29
37
  "run:android": "cd example/android && ./gradlew installDebug && npm run start:android",
30
38
  "test": "jest",
39
+ "tsc": "tsc",
31
40
  "lint": "eslint . --fix --ext .js,.jsx,.ts,.tsx",
32
41
  "docs:dev": "vuepress dev docs",
33
42
  "docs:build": "vuepress build docs"
@@ -48,9 +57,8 @@
48
57
  "@types/react": "^17.0.1",
49
58
  "@types/react-native": "^0.66.2",
50
59
  "@types/react-redux": "^7.1.9",
51
- "@types/react-test-renderer": "17.0.1",
60
+ "@types/react-test-renderer": "17.0.2",
52
61
  "babel-jest": "^27.2.0",
53
- "babel-plugin-module-resolver": "^4.0.0",
54
62
  "jest": "^27.2.0",
55
63
  "metro-react-native-babel-preset": "^0.68.0",
56
64
  "react": "17.0.2",
@@ -58,11 +66,11 @@
58
66
  "react-native-fast-image": "^8.5.11",
59
67
  "react-native-iphone-x-helper": "^1.2.0",
60
68
  "react-native-keyboard-aware-scroll-view": "^0.9.5",
61
- "react-native-toast-hybrid": "^2.4.4",
69
+ "react-native-toast-hybrid": "^2.5.0",
62
70
  "react-redux": "^7.2.5",
63
71
  "react-test-renderer": "17.0.2",
64
72
  "redux": "^4.1.1",
65
- "typescript": "^4.4.3",
73
+ "typescript": "^4.6.4",
66
74
  "vuepress": "^2.0.0-beta.26",
67
75
  "zustand": "^3.7.1"
68
76
  },
@@ -0,0 +1,60 @@
1
+ import { EmitterSubscription, Linking } from 'react-native'
2
+ import { router } from './router'
3
+
4
+ let _active = 0
5
+ let _uriPrefix: string = ''
6
+ let _hasHandleInitialURL = false
7
+ let _linkingSubscription: EmitterSubscription | undefined
8
+
9
+ function activate(uriPrefix: string) {
10
+ if (!uriPrefix) {
11
+ throw new Error('must pass `uriPrefix` when activate router.')
12
+ }
13
+ if (_active === 0) {
14
+ _uriPrefix = uriPrefix
15
+ if (!_hasHandleInitialURL) {
16
+ _hasHandleInitialURL = true
17
+ Linking.getInitialURL()
18
+ .then(url => {
19
+ if (url) {
20
+ console.info(`deeplink:${url}`)
21
+ const path = url.replace(_uriPrefix, '')
22
+ return router.open(path)
23
+ }
24
+ })
25
+ .catch(err => console.error('An error occurred', err))
26
+ }
27
+ _linkingSubscription = Linking.addEventListener('url', handleLinking)
28
+ }
29
+ _active++
30
+ }
31
+
32
+ function deactivate() {
33
+ _active--
34
+ if (_active === 0) {
35
+ if (_linkingSubscription) {
36
+ _linkingSubscription.remove()
37
+ _linkingSubscription = undefined
38
+ } else {
39
+ Linking.removeEventListener('url', handleLinking)
40
+ }
41
+ }
42
+
43
+ if (_active < 0) {
44
+ _active = 0
45
+ }
46
+ }
47
+
48
+ function handleLinking(event: { url: string }): void {
49
+ console.info(`deeplink:${event.url}`)
50
+ let path = event.url.replace(_uriPrefix, '')
51
+ if (!path.startsWith('/')) {
52
+ path = '/' + path
53
+ }
54
+ router.open(path)
55
+ }
56
+
57
+ export const DeepLink = {
58
+ activate,
59
+ deactivate,
60
+ }
package/src/Garden.ts ADDED
@@ -0,0 +1,171 @@
1
+ import { NativeModules } from 'react-native'
2
+ import { bindBarButtonItemClickEvent } from './utils'
3
+ import { NavigationOption, ImageSource, Color, BarStyle, TitleAlignment, BarButtonItem, TitleItem } from './typing'
4
+
5
+ export interface ShadowImage {
6
+ image?: ImageSource
7
+ color?: Color
8
+ }
9
+
10
+ export interface Style {
11
+ screenBackgroundColor?: Color // 页面背景,默认是白色
12
+ topBarStyle?: BarStyle // TopBar 样式,决定了状态栏的颜色,可选项有 `BarStyleLightContent` 和 `BarStyleDarkContent`
13
+ topBarColor?: Color // TopBar 背景颜色,默认根据 topBarStyle 来计算
14
+ topBarColorDarkContent?: Color // TopBar 背景颜色,当 topBarStyle 的值为 BarStyleDarkContent 时生效,覆盖 topBarColor 的值
15
+ topBarColorLightContent?: Color // TopBar 背景颜色,当 topBarStyle 的值为 BarStyleLightContent 时生效,覆盖 topBarColor 的值
16
+ statusBarColorAndroid?: Color // 状态栏背景颜色,默认取 topBarColor 的值
17
+ navigationBarColorAndroid?: Color // 底部虚拟键背景颜色,仅对 Android 8.0 以上版本生效
18
+ hideBackTitleIOS?: boolean // 是否隐藏返回按钮旁边的文字,默认是 false, 仅对 iOS 生效
19
+ elevationAndroid?: number // TopBar 阴影高度,默认值为 4 dp
20
+ shadowImage?: ShadowImage // TopBar 阴影图片,仅对 iOS 生效
21
+ backIcon?: ImageSource // 返回按钮图片
22
+ topBarTintColor?: Color // TopBar 按钮的颜色。默认根据 topBarStyle 来计算
23
+ topBarTintColorDarkContent?: Color // TopBar 按钮颜色,当 topBarStyle 的值为 BarStyleDarkContent 时生效,覆盖 topBarTintColor 的值
24
+ topBarTintColorLightContent?: Color // TopBar 按钮颜色,当 topBarStyle 的值为 BarStyleLightContent 时生效,覆盖 topBarTintColor 的值
25
+ titleTextColor?: Color // TopBar 标题颜色,默认根据 topBarStyle 来计算
26
+ titleTextColorDarkContent?: Color // TopBar 标题颜色,当 topBarStyle 的值为 BarStyleDarkContent 时生效,覆盖 titleTextColor 的值
27
+ titleTextColorLightContent?: Color // TopBar 标题颜色,当 topBarStyle 的值为 BarStyleLightContent 时生效,覆盖 titleTextColor 的值
28
+ titleTextSize?: number // TopBar 标题字体大小,默认是 17 dp(pt)
29
+ titleAlignmentAndroid?: TitleAlignment // TopBar 标题的位置,可选项有 `TitleAlignmentLeft` 和 `TitleAlignmentCenter` ,仅对 Android 生效
30
+ barButtonItemTextSize?: number // TopBar 按钮字体大小,默认是 15 dp(pt)
31
+ swipeBackEnabledAndroid?: boolean // Android 是否开启右滑返回,默认是 false
32
+ splitTopBarTransitionIOS?: boolean // iOS 侧滑返回时,是否总是割裂导航栏背景
33
+ scrimAlphaAndroid?: number // Android 侧滑返回遮罩效果 [0 - 255]
34
+ displayCutoutWhenLandscapeAndroid?: boolean // 横屏时,是否将界面延伸至刘海区域,默认 true
35
+
36
+ tabBarColor?: Color // 底部 TabBar 背景颜色,请勿使用带透明度的颜色。
37
+ tabBarShadowImage?: ShadowImage // 底部 TabBar 阴影图片。对于 iOS, 只有同时设置了 tabBarColor 才会生效
38
+ tabBarItemColor?: Color // 底部 TabBarItem icon 选中颜色
39
+ tabBarUnselectedItemColor?: Color // 底部 TabBarItem icon 未选中颜色,默认为 #BDBDBD
40
+ tabBarBadgeColor?: Color // Tab badge 颜色
41
+ }
42
+
43
+ export type TabBarStyle = Pick<
44
+ Style,
45
+ 'tabBarColor' | 'tabBarShadowImage' | 'tabBarItemColor' | 'tabBarUnselectedItemColor'
46
+ >
47
+
48
+ export interface TabBadge {
49
+ index: number
50
+ text?: string
51
+ hidden: boolean
52
+ dot?: boolean
53
+ }
54
+
55
+ export interface TabItemInfo {
56
+ index: number
57
+ title?: string
58
+ badge?: {
59
+ text?: string
60
+ hidden: boolean
61
+ dot?: boolean
62
+ }
63
+ icon?: {
64
+ selected: ImageSource
65
+ unselected?: ImageSource
66
+ }
67
+ }
68
+
69
+ export interface TabIcon {
70
+ index: number
71
+ icon: ImageSource
72
+ unselectedIcon?: ImageSource
73
+ }
74
+
75
+ type Nullable<T> = {
76
+ [P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P]
77
+ }
78
+
79
+ const GardenModule = NativeModules.GardenModule
80
+ export class Garden {
81
+ static setStyle(style: Style = {}) {
82
+ GardenModule.setStyle(style)
83
+ }
84
+
85
+ constructor(public sceneId: string) {}
86
+
87
+ // --------------- instance method --------------
88
+
89
+ setLeftBarButtonItem(buttonItem: Nullable<BarButtonItem> | null) {
90
+ const options = bindBarButtonItemClickEvent(buttonItem, { sceneId: this.sceneId })
91
+ GardenModule.setLeftBarButtonItem(this.sceneId, options)
92
+ }
93
+
94
+ setRightBarButtonItem(buttonItem: Nullable<BarButtonItem> | null) {
95
+ const options = bindBarButtonItemClickEvent(buttonItem, { sceneId: this.sceneId })
96
+ GardenModule.setRightBarButtonItem(this.sceneId, options)
97
+ }
98
+
99
+ setLeftBarButtonItems(buttonItems: Array<Nullable<BarButtonItem>> | null) {
100
+ const options = bindBarButtonItemClickEvent(buttonItems, { sceneId: this.sceneId })
101
+ GardenModule.setLeftBarButtonItems(this.sceneId, options)
102
+ }
103
+
104
+ setRightBarButtonItems(buttonItems: Array<Nullable<BarButtonItem>> | null) {
105
+ const options = bindBarButtonItemClickEvent(buttonItems, { sceneId: this.sceneId })
106
+ GardenModule.setRightBarButtonItems(this.sceneId, options)
107
+ }
108
+
109
+ setTitleItem(titleItem: TitleItem) {
110
+ GardenModule.setTitleItem(this.sceneId, titleItem)
111
+ }
112
+
113
+ updateOptions(options: NavigationOption) {
114
+ GardenModule.updateOptions(this.sceneId, options)
115
+ }
116
+
117
+ updateTabBar(options: TabBarStyle) {
118
+ GardenModule.updateTabBar(this.sceneId, options)
119
+ }
120
+
121
+ setTabItem(item: TabItemInfo | TabItemInfo[]) {
122
+ if (!Array.isArray(item)) {
123
+ item = [item]
124
+ }
125
+ GardenModule.setTabItem(this.sceneId, item)
126
+ }
127
+
128
+ setTabIcon(icon: TabIcon | TabIcon[]) {
129
+ console.warn(`Garden#setTabIcon is deprecated, use Garden#setTabItem instead.`)
130
+ if (!Array.isArray(icon)) {
131
+ icon = [icon]
132
+ }
133
+ const icons = icon
134
+ const items: Array<TabItemInfo> = []
135
+ for (const i of icons) {
136
+ items.push({
137
+ index: i.index,
138
+ icon: {
139
+ selected: i.icon,
140
+ unselected: i.unselectedIcon,
141
+ },
142
+ })
143
+ }
144
+ this.setTabItem(items)
145
+ }
146
+
147
+ setTabBadge(badge: TabBadge | TabBadge[]) {
148
+ console.warn(`Garden#setTabBadge is deprecated, use Garden#setTabItem instead.`)
149
+ if (!Array.isArray(badge)) {
150
+ badge = [badge]
151
+ }
152
+
153
+ const badges = badge
154
+ const items: Array<TabItemInfo> = []
155
+ for (const b of badges) {
156
+ items.push({
157
+ index: b.index,
158
+ badge: {
159
+ hidden: b.hidden,
160
+ text: b.text,
161
+ dot: b.dot,
162
+ },
163
+ })
164
+ }
165
+ this.setTabItem(items)
166
+ }
167
+
168
+ setMenuInteractive(enabled: boolean) {
169
+ GardenModule.setMenuInteractive(this.sceneId, enabled)
170
+ }
171
+ }
@@ -0,0 +1,33 @@
1
+ import { NativeModules, NativeEventEmitter } from 'react-native'
2
+
3
+ const NavigationModule = NativeModules.NavigationModule
4
+ const GardenModule = NativeModules.GardenModule
5
+ const HBDEventEmitter = NativeModules.HBDEventEmitter
6
+
7
+ const EventEmitter: NativeEventEmitter = new NativeEventEmitter(HBDEventEmitter)
8
+ export const EVENT_SWITCH_TAB: string = HBDEventEmitter.EVENT_SWITCH_TAB
9
+ export const EVENT_NAVIGATION: string = HBDEventEmitter.EVENT_NAVIGATION
10
+ export const EVENT_WILL_SET_ROOT: string = HBDEventEmitter.EVENT_WILL_SET_ROOT
11
+ export const EVENT_DID_SET_ROOT: string = HBDEventEmitter.EVENT_DID_SET_ROOT
12
+
13
+ export const ON_COMPONENT_RESULT: string = HBDEventEmitter.ON_COMPONENT_RESULT
14
+ export const ON_BAR_BUTTON_ITEM_CLICK: string = HBDEventEmitter.ON_BAR_BUTTON_ITEM_CLICK
15
+ export const ON_COMPONENT_APPEAR: string = HBDEventEmitter.ON_COMPONENT_APPEAR
16
+ export const ON_COMPONENT_DISAPPEAR: string = HBDEventEmitter.ON_COMPONENT_DISAPPEAR
17
+
18
+ export const KEY_ON: string = HBDEventEmitter.KEY_ON
19
+ export const KEY_REQUEST_CODE: string = HBDEventEmitter.KEY_REQUEST_CODE
20
+ export const KEY_RESULT_CODE: string = HBDEventEmitter.KEY_RESULT_CODE
21
+ export const KEY_RESULT_DATA: string = HBDEventEmitter.KEY_RESULT_DATA
22
+ export const KEY_SCENE_ID: string = HBDEventEmitter.KEY_SCENE_ID
23
+ export const KEY_MODULE_NAME: string = HBDEventEmitter.KEY_MODULE_NAME
24
+ export const KEY_INDEX: string = HBDEventEmitter.KEY_INDEX
25
+ export const KEY_ACTION: string = HBDEventEmitter.KEY_ACTION
26
+
27
+ export const RESULT_OK: number = NavigationModule.RESULT_OK
28
+ export const RESULT_CANCEL: number = NavigationModule.RESULT_CANCEL
29
+
30
+ export const toolbarHeight: number = GardenModule.TOOLBAR_HEIGHT
31
+ export const TOOLBAR_HEIGHT: number = GardenModule.TOOLBAR_HEIGHT
32
+
33
+ export { EventEmitter, NavigationModule }