hybrid-navigation 2.8.3 → 2.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) 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/HBDReactRootView.java +1 -8
  8. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +94 -43
  9. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +134 -117
  10. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +65 -35
  11. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +14 -3
  12. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +133 -89
  13. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +161 -126
  14. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +145 -114
  15. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +40 -28
  16. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +96 -75
  17. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/Navigator.java +1 -1
  18. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +111 -79
  19. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +187 -117
  20. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +137 -96
  21. package/ios/HybridNavigation/ViewController/HBDModalViewController.m +7 -0
  22. package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +16 -0
  23. package/ios/HybridNavigation.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  24. package/ios/HybridNavigation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  25. package/ios/HybridNavigation.xcodeproj/project.xcworkspace/xcuserdata/listen.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  26. package/ios/HybridNavigation.xcodeproj/xcuserdata/listen.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  27. package/lib/Navigator.d.ts +6 -6
  28. package/lib/ReactRegistry.d.ts +3 -3
  29. package/lib/ReactRegistry.js +14 -10
  30. package/lib/typing.d.ts +8 -8
  31. package/package.json +27 -16
  32. package/src/DeepLink.ts +60 -0
  33. package/src/Garden.ts +171 -0
  34. package/src/NavigationModule.ts +33 -0
  35. package/src/Navigator.ts +404 -0
  36. package/src/ReactRegistry.tsx +138 -0
  37. package/src/hooks.ts +83 -0
  38. package/src/index.ts +9 -0
  39. package/src/router/drawer.ts +34 -0
  40. package/src/router/index.ts +166 -0
  41. package/src/router/screen.ts +12 -0
  42. package/src/router/stack.ts +80 -0
  43. package/src/router/tabs.ts +49 -0
  44. package/src/router/typing.ts +45 -0
  45. package/src/store.ts +49 -0
  46. package/src/typing.ts +148 -0
  47. package/src/utils.ts +83 -0
  48. package/.buckconfig +0 -6
  49. package/.editorconfig +0 -16
  50. package/.eslintignore +0 -5
  51. package/.gitattributes +0 -1
  52. package/.github/workflows/docs.yml +0 -25
  53. package/CHANGELOG.md +0 -399
  54. package/babel.config.js +0 -15
  55. package/docs/README.md +0 -109
  56. package/docs/custom-tabbar.md +0 -138
  57. package/docs/deeplink.md +0 -148
  58. package/docs/integration-native.md +0 -390
  59. package/docs/integration-react.md +0 -194
  60. package/docs/lifecycle.md +0 -85
  61. package/docs/navigation.md +0 -589
  62. package/docs/pass-and-return-value.md +0 -163
  63. package/docs/qa.md +0 -57
  64. package/docs/style.md +0 -533
  65. package/jest.config.js +0 -4
  66. package/metro.config.js +0 -17
  67. package/screenshot/android.png +0 -0
  68. package/screenshot/bulge.jpg +0 -0
  69. package/screenshot/controller-base.jpg +0 -0
  70. package/screenshot/demo-qrcode.png +0 -0
  71. package/screenshot/header-search-paths.jpg +0 -0
  72. package/screenshot/ios-react-script.png +0 -0
  73. package/screenshot/ios-run-script.jpg +0 -0
  74. package/screenshot/statusbar-inperfect.png +0 -0
  75. package/screenshot/statusbar-setup-step-1.png +0 -0
  76. package/screenshot/statusbar-setup-step-2.png +0 -0
  77. package/screenshot/tabbar.jpg +0 -0
  78. package/screenshot/topbar-default.png +0 -0
  79. package/screenshot/xcode-linking.png +0 -0
@@ -19,6 +19,10 @@
19
19
  }
20
20
 
21
21
  - (void)setLeftBarButtonItem:(NSDictionary *)item {
22
+ if (self.hbd_barHidden) {
23
+ return;
24
+ }
25
+
22
26
  if (item) {
23
27
  NSMutableArray *array = [[NSMutableArray alloc] init];
24
28
  if (@available(iOS 11.0, *)) {
@@ -43,6 +47,10 @@
43
47
  }
44
48
 
45
49
  - (void)setRightBarButtonItem:(NSDictionary *)item {
50
+ if (self.hbd_barHidden) {
51
+ return;
52
+ }
53
+
46
54
  if (item) {
47
55
  NSMutableArray *array = [[NSMutableArray alloc] init];
48
56
  if (@available(iOS 11.0, *)) {
@@ -67,6 +75,10 @@
67
75
  }
68
76
 
69
77
  - (void)setLeftBarButtonItems:(NSArray *)items {
78
+ if (self.hbd_barHidden) {
79
+ return;
80
+ }
81
+
70
82
  if (items) {
71
83
  NSArray *barButtonItems = [self createBarButtonItems:items];
72
84
  NSMutableArray *array = [[NSMutableArray alloc] init];
@@ -93,6 +105,10 @@
93
105
  }
94
106
 
95
107
  - (void)setRightBarButtonItems:(NSArray *)items {
108
+ if (self.hbd_barHidden) {
109
+ return;
110
+ }
111
+
96
112
  if (items) {
97
113
  NSArray *barButtonItems = [self createBarButtonItems:items];
98
114
  NSMutableArray *array = [[NSMutableArray alloc] init];
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "self:">
6
+ </FileRef>
7
+ </Workspace>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>IDEDidComputeMac32BitWarning</key>
6
+ <true/>
7
+ </dict>
8
+ </plist>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>SchemeUserState</key>
6
+ <dict>
7
+ <key>HybridNavigation.xcscheme_^#shared#^_</key>
8
+ <dict>
9
+ <key>orderHint</key>
10
+ <integer>0</integer>
11
+ </dict>
12
+ </dict>
13
+ </dict>
14
+ </plist>
@@ -1,11 +1,11 @@
1
1
  import { RouteGraph, Route } from './router';
2
2
  import { Visibility } from './hooks';
3
- import { IndexType, ResultType, NavigationInterceptor, Layout, NavigationItem, PropsType } from './typing';
3
+ import { IndexType, ResultType, NavigationInterceptor, Layout, BuildInLayout, NavigationItem, PropsType } from './typing';
4
4
  import { Garden } from './Garden';
5
5
  interface Params {
6
6
  animated?: boolean;
7
7
  moduleName?: string;
8
- layout?: Layout;
8
+ layout?: BuildInLayout | Layout;
9
9
  popToRoot?: boolean;
10
10
  requestCode?: number;
11
11
  props?: IndexType;
@@ -25,7 +25,7 @@ export declare class Navigator {
25
25
  static current(): Promise<Navigator>;
26
26
  static currentRoute(): Promise<Route>;
27
27
  static routeGraph(): Promise<RouteGraph[]>;
28
- static setRoot(layout: Layout, sticky?: boolean): Promise<void>;
28
+ static setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<void>;
29
29
  static setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
30
30
  static dispatch(sceneId: string, action: string, params?: Params): Promise<boolean>;
31
31
  static setInterceptor(interceptFn: NavigationInterceptor): void;
@@ -43,17 +43,17 @@ export declare class Navigator {
43
43
  private resultListener;
44
44
  private waitResult;
45
45
  push<T extends ResultType, P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem): Promise<[number, T]>;
46
- pushLayout<T extends ResultType>(layout: Layout): Promise<[number, T]>;
46
+ pushLayout<T extends ResultType>(layout: BuildInLayout | Layout): Promise<[number, T]>;
47
47
  pop(): Promise<boolean>;
48
48
  popTo(moduleName: string, inclusive?: boolean): Promise<boolean>;
49
49
  popToRoot(): Promise<boolean>;
50
50
  redirectTo<P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem): Promise<boolean>;
51
51
  isStackRoot(): Promise<boolean>;
52
52
  present<T extends ResultType, P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem): Promise<[number, T]>;
53
- presentLayout<T extends ResultType>(layout: Layout): Promise<[number, T]>;
53
+ presentLayout<T extends ResultType>(layout: BuildInLayout | Layout): Promise<[number, T]>;
54
54
  dismiss(): Promise<boolean>;
55
55
  showModal<T extends ResultType, P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem): Promise<[number, T]>;
56
- showModalLayout<T extends ResultType>(layout: Layout): Promise<[number, T]>;
56
+ showModalLayout<T extends ResultType>(layout: BuildInLayout | Layout): Promise<[number, T]>;
57
57
  hideModal(): Promise<boolean>;
58
58
  setResult<T extends ResultType>(resultCode: number, data?: T): void;
59
59
  switchTab(index: number, popToRoot?: boolean): Promise<boolean>;
@@ -1,5 +1,5 @@
1
1
  import { ComponentProvider } from 'react-native';
2
- import React, { ComponentType } from 'react';
2
+ import React from 'react';
3
3
  import { Navigator } from './Navigator';
4
4
  import { Garden } from './Garden';
5
5
  import { RouteConfig } from './router';
@@ -10,11 +10,11 @@ export interface InjectedProps {
10
10
  sceneId: string;
11
11
  }
12
12
  export declare const NavigationContext: React.Context<any>;
13
- export declare type HOC = (WrappedComponent: ComponentType<any>) => ComponentType<any>;
13
+ export declare type HOC = (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
14
14
  export declare class ReactRegistry {
15
15
  static registerEnded: boolean;
16
16
  static startRegisterComponent(hoc?: HOC): void;
17
17
  static endRegisterComponent(): void;
18
18
  static registerComponent(appKey: string, getComponentFunc: ComponentProvider, routeConfig?: RouteConfig): void;
19
19
  }
20
- export declare function withNavigationItem(item: NavigationItem): (WrappedComponent: ComponentType<any>) => React.ComponentType<any>;
20
+ export declare function withNavigationItem(item: NavigationItem): (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
@@ -74,24 +74,28 @@ export class ReactRegistry {
74
74
  if (routeConfig) {
75
75
  router.registerRoute(appKey, routeConfig);
76
76
  }
77
- const WrappedComponent = getComponentFunc();
77
+ let WrappedComponent = getComponentFunc();
78
+ if (wrap) {
79
+ WrappedComponent = wrap(WrappedComponent);
80
+ }
78
81
  // build static options
79
82
  let options = bindBarButtonItemClickEvent(WrappedComponent.navigationItem) || {};
80
83
  NavigationModule.registerReactComponent(appKey, options);
81
- let RootComponent;
82
- if (wrap) {
83
- RootComponent = wrap(withNavigator(appKey)(WrappedComponent));
84
- }
85
- else {
86
- RootComponent = withNavigator(appKey)(WrappedComponent);
87
- }
84
+ let RootComponent = withNavigator(appKey)(WrappedComponent);
88
85
  AppRegistry.registerComponent(appKey, () => RootComponent);
89
86
  }
90
87
  }
91
88
  export function withNavigationItem(item) {
92
89
  return function (WrappedComponent) {
93
- ;
94
- WrappedComponent.navigationItem = item;
90
+ let navigationItem = WrappedComponent.navigationItem;
91
+ if (navigationItem) {
92
+ ;
93
+ WrappedComponent.navigationItem = { ...navigationItem, ...item };
94
+ }
95
+ else {
96
+ ;
97
+ WrappedComponent.navigationItem = item;
98
+ }
95
99
  return WrappedComponent;
96
100
  };
97
101
  }
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;
@@ -94,9 +93,6 @@ export interface TabItem {
94
93
  unselectedIcon?: ImageSource;
95
94
  hideTabBarWhenPush?: boolean;
96
95
  }
97
- export interface Layout {
98
- [index: string]: {};
99
- }
100
96
  export interface Screen extends Layout {
101
97
  screen: {
102
98
  moduleName: string;
@@ -106,13 +102,13 @@ export interface Screen extends Layout {
106
102
  }
107
103
  export interface Stack extends Layout {
108
104
  stack: {
109
- children: Layout[];
105
+ children: Array<BuildInLayout | Layout>;
110
106
  options?: {};
111
107
  };
112
108
  }
113
109
  export interface Tabs extends Layout {
114
110
  tabs: {
115
- children: Layout[];
111
+ children: Array<BuildInLayout | Layout>;
116
112
  options?: {
117
113
  selectedIndex?: number;
118
114
  tabBarModuleName?: string;
@@ -122,7 +118,7 @@ export interface Tabs extends Layout {
122
118
  }
123
119
  export interface Drawer extends Layout {
124
120
  drawer: {
125
- children: [Layout, Layout];
121
+ children: [BuildInLayout | Layout, BuildInLayout | Layout];
126
122
  options?: {
127
123
  maxDrawerWidth?: number;
128
124
  minDrawerMargin?: number;
@@ -130,4 +126,8 @@ export interface Drawer extends Layout {
130
126
  };
131
127
  };
132
128
  }
129
+ export declare type BuildInLayout = Screen | Stack | Tabs | Drawer;
130
+ export interface Layout {
131
+ [index: string]: {};
132
+ }
133
133
  export {};
package/package.json CHANGED
@@ -1,7 +1,29 @@
1
1
  {
2
2
  "name": "hybrid-navigation",
3
3
  "description": "React Native Navigation that supports seamless navigation between Native and React.",
4
- "version": "2.8.3",
4
+ "version": "2.10.1",
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
+ "!android/.gradle",
17
+ "!android/.idea",
18
+ "!android/local.properties",
19
+ "!ios/build",
20
+ "!**/__tests__"
21
+ ],
22
+ "repository": "https://github.com/listenzz/hybrid-navigation",
23
+ "homepage": "https://github.com/listenzz/hybrid-navigation#readme",
24
+ "author": "listen <listenzz@163.com> (https://github.com/listenzz)",
25
+ "license": "MIT",
26
+ "licenseFilename": "LICENSE",
5
27
  "keywords": [
6
28
  "react-native",
7
29
  "navigation",
@@ -9,25 +31,15 @@
9
31
  "router",
10
32
  "hybrid"
11
33
  ],
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
34
  "scripts": {
23
35
  "build": "rm -rf ./lib && tsc -p tsconfig.build.json",
24
36
  "prepare": "npm run build",
25
- "tsc": "tsc",
26
37
  "start": "react-native start --reset-cache",
27
38
  "run:ios": "react-native run-ios --project-path ./example/ios",
28
39
  "start:android": "adb shell am start -n com.reactnative.hybridnavigation.example/.MainActivity",
29
40
  "run:android": "cd example/android && ./gradlew installDebug && npm run start:android",
30
41
  "test": "jest",
42
+ "tsc": "tsc",
31
43
  "lint": "eslint . --fix --ext .js,.jsx,.ts,.tsx",
32
44
  "docs:dev": "vuepress dev docs",
33
45
  "docs:build": "vuepress build docs"
@@ -48,9 +60,8 @@
48
60
  "@types/react": "^17.0.1",
49
61
  "@types/react-native": "^0.66.2",
50
62
  "@types/react-redux": "^7.1.9",
51
- "@types/react-test-renderer": "17.0.1",
63
+ "@types/react-test-renderer": "17.0.2",
52
64
  "babel-jest": "^27.2.0",
53
- "babel-plugin-module-resolver": "^4.0.0",
54
65
  "jest": "^27.2.0",
55
66
  "metro-react-native-babel-preset": "^0.68.0",
56
67
  "react": "17.0.2",
@@ -58,11 +69,11 @@
58
69
  "react-native-fast-image": "^8.5.11",
59
70
  "react-native-iphone-x-helper": "^1.2.0",
60
71
  "react-native-keyboard-aware-scroll-view": "^0.9.5",
61
- "react-native-toast-hybrid": "^2.4.4",
72
+ "react-native-toast-hybrid": "^2.5.0",
62
73
  "react-redux": "^7.2.5",
63
74
  "react-test-renderer": "17.0.2",
64
75
  "redux": "^4.1.1",
65
- "typescript": "^4.4.3",
76
+ "typescript": "^4.6.4",
66
77
  "vuepress": "^2.0.0-beta.26",
67
78
  "zustand": "^3.7.1"
68
79
  },
@@ -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 }