hybrid-navigation 2.9.0 → 2.10.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/HybridNavigation.podspec +6 -6
- package/LICENSE +1 -1
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.4/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/configuration-cache/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/.name +1 -0
- package/android/.idea/gradle.xml +16 -0
- package/android/.idea/misc.xml +9 -0
- package/android/.idea/modules/android.iml +18 -0
- package/android/.idea/modules.xml +8 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/build.gradle +4 -4
- package/android/local.properties +8 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +27 -40
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +77 -48
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +4 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +94 -43
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +134 -117
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +65 -35
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +14 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +133 -92
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +161 -126
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +145 -114
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +40 -28
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +96 -75
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/Navigator.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +111 -79
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +187 -117
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +137 -96
- package/ios/HybridNavigation/ViewController/HBDModalViewController.m +7 -0
- package/ios/HybridNavigation.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/HybridNavigation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/HybridNavigation.xcodeproj/project.xcworkspace/xcuserdata/listen.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/HybridNavigation.xcodeproj/xcuserdata/listen.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/lib/ReactRegistry.d.ts +5 -3
- package/lib/typing.d.ts +1 -2
- package/package.json +24 -16
- package/src/DeepLink.ts +60 -0
- package/src/Garden.ts +171 -0
- package/src/NavigationModule.ts +33 -0
- package/src/Navigator.ts +404 -0
- package/src/ReactRegistry.tsx +140 -0
- package/src/hooks.ts +83 -0
- package/src/index.ts +9 -0
- package/src/router/drawer.ts +34 -0
- package/src/router/index.ts +166 -0
- package/src/router/screen.ts +12 -0
- package/src/router/stack.ts +80 -0
- package/src/router/tabs.ts +49 -0
- package/src/router/typing.ts +45 -0
- package/src/store.ts +49 -0
- package/src/typing.ts +148 -0
- package/src/utils.ts +83 -0
- package/.buckconfig +0 -6
- package/.editorconfig +0 -16
- package/.eslintignore +0 -5
- package/.gitattributes +0 -1
- package/.github/workflows/docs.yml +0 -25
- package/CHANGELOG.md +0 -429
- package/babel.config.js +0 -15
- package/docs/README.md +0 -109
- package/docs/custom-tabbar.md +0 -138
- package/docs/deeplink.md +0 -148
- package/docs/integration-native.md +0 -390
- package/docs/integration-react.md +0 -194
- package/docs/lifecycle.md +0 -85
- package/docs/navigation.md +0 -589
- package/docs/pass-and-return-value.md +0 -163
- package/docs/qa.md +0 -81
- package/docs/style.md +0 -533
- package/jest.config.js +0 -4
- package/metro.config.js +0 -17
- package/screenshot/android.png +0 -0
- package/screenshot/bulge.jpg +0 -0
- package/screenshot/controller-base.jpg +0 -0
- package/screenshot/demo-qrcode.png +0 -0
- package/screenshot/header-search-paths.jpg +0 -0
- package/screenshot/ios-react-script.png +0 -0
- package/screenshot/ios-run-script.jpg +0 -0
- package/screenshot/statusbar-inperfect.png +0 -0
- package/screenshot/statusbar-setup-step-1.png +0 -0
- package/screenshot/statusbar-setup-step-2.png +0 -0
- package/screenshot/tabbar.jpg +0 -0
- package/screenshot/topbar-default.png +0 -0
- package/screenshot/xcode-linking.png +0 -0
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
# 集成到以 RN 为主的项目
|
|
2
|
-
|
|
3
|
-
> 本文档仅适用于 RN0.60 以上版本
|
|
4
|
-
|
|
5
|
-
你想用 React Native 实现大部分业务,原生代码主要起到搭桥的作用。
|
|
6
|
-
|
|
7
|
-
假设你是通过 `react-native init MyApp` 创建的项目,目录结构是这样的:
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
MyApp/
|
|
11
|
-
|—— android/
|
|
12
|
-
|—— ios/
|
|
13
|
-
|—— node_modules/
|
|
14
|
-
|—— package.json
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## 添加依赖
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
npm install hybrid-navigation --save
|
|
21
|
-
# or
|
|
22
|
-
yarn add hybrid-navigation
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## RN 项目配置
|
|
26
|
-
|
|
27
|
-
打开 index.js 这个文件,通常,它就在 package.json 旁边。
|
|
28
|
-
|
|
29
|
-
以前,你是这么注册 React 组件
|
|
30
|
-
|
|
31
|
-
```javascript
|
|
32
|
-
import { AppRegistry } from 'react-native'
|
|
33
|
-
import App from './App'
|
|
34
|
-
import { name as appName } from './app.json'
|
|
35
|
-
|
|
36
|
-
AppRegistry.registerComponent(appName, () => App)
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
现在,你需要像下面那样
|
|
40
|
-
|
|
41
|
-
```javascript
|
|
42
|
-
import { ReactRegistry, Garden, Navigator, BarStyleDarkContent } from 'hybrid-navigation'
|
|
43
|
-
import App from './App'
|
|
44
|
-
|
|
45
|
-
// 配置全局样式
|
|
46
|
-
Garden.setStyle({
|
|
47
|
-
topBarStyle: BarStyleDarkContent,
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
// 重要必须
|
|
51
|
-
ReactRegistry.startRegisterComponent()
|
|
52
|
-
|
|
53
|
-
// 注意,你的每一个页面都需要注册
|
|
54
|
-
ReactRegistry.registerComponent('App', () => App)
|
|
55
|
-
|
|
56
|
-
// 重要必须
|
|
57
|
-
ReactRegistry.endRegisterComponent()
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
通过 `Navigator#setRoot` 来设置 UI 层级
|
|
61
|
-
|
|
62
|
-
```javascript
|
|
63
|
-
Navigator.setRoot({
|
|
64
|
-
stack: {
|
|
65
|
-
children: [{ screen: { moduleName: 'App' } }],
|
|
66
|
-
},
|
|
67
|
-
})
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
`setRoot` 具体用法请查看 [Navigator#setRoot](./navigation.md)
|
|
71
|
-
|
|
72
|
-
> 务必移除 StatusBar 相关组件和 api,交由本库管理状态栏相关状态。
|
|
73
|
-
|
|
74
|
-
### 支持 Redux
|
|
75
|
-
|
|
76
|
-
想要为每个页面都注入相同的属性,可以利用 `ReactRegistry.startRegisterComponent()` 这个方法,它接受一个 [HOC](https://reactjs.org/docs/higher-order-components.html) 作为参数。
|
|
77
|
-
|
|
78
|
-
想要支持 Redux,像下面这样配置即可
|
|
79
|
-
|
|
80
|
-
```jsx
|
|
81
|
-
function withRedux(WrappedComponent) {
|
|
82
|
-
return props => (
|
|
83
|
-
<Provider store={store}>
|
|
84
|
-
<WrappedComponent {...props} />
|
|
85
|
-
</Provider>
|
|
86
|
-
)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
ReactRegistry.startRegisterComponent(withRedux)
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
其中 `withRedux` 就是一个 [HOC](https://reactjs.org/docs/higher-order-components.html)
|
|
93
|
-
|
|
94
|
-
## Android 项目配置
|
|
95
|
-
|
|
96
|
-
假设你已经配置好了 React 项目
|
|
97
|
-
|
|
98
|
-
修改 MainActivity.java 文件
|
|
99
|
-
|
|
100
|
-
```diff
|
|
101
|
-
- import com.facebook.react.ReactActivity;
|
|
102
|
-
+ import com.reactnative.hybridnavigation.ReactAppCompatActivity;
|
|
103
|
-
|
|
104
|
-
- public class MainActivity extends ReactActivity {
|
|
105
|
-
+ public class MainActivity extends ReactAppCompatActivity {
|
|
106
|
-
- @Override
|
|
107
|
-
- protected String getMainComponentName() {
|
|
108
|
-
- return "MyApp";
|
|
109
|
-
- }
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
修改 MainApplication.java 文件
|
|
114
|
-
|
|
115
|
-
```diff
|
|
116
|
-
import com.facebook.react.ReactNativeHost;
|
|
117
|
-
+ import com.reactnative.hybridnavigation.ReactBridgeManager;
|
|
118
|
-
|
|
119
|
-
public void onCreate() {
|
|
120
|
-
super.onCreate();
|
|
121
|
-
SoLoader.init(this, /* native exopackage */ false);
|
|
122
|
-
|
|
123
|
-
+ ReactBridgeManager bridgeManager = ReactBridgeManager.get();
|
|
124
|
-
+ bridgeManager.install(getReactNativeHost());
|
|
125
|
-
}
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
如果你的 RN 版本 >=0.60 && < 0.62,修改 android/app/build.gradle 文件,添加依赖
|
|
129
|
-
|
|
130
|
-
```diff
|
|
131
|
-
implementation "com.facebook.react:react-native:+" // From node_modules
|
|
132
|
-
+ implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
## iOS 项目配置
|
|
136
|
-
|
|
137
|
-
更新 pod 依赖
|
|
138
|
-
|
|
139
|
-
```
|
|
140
|
-
cd ios & pod install
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
修改 AppDelegate.m 文件
|
|
144
|
-
|
|
145
|
-
```diff
|
|
146
|
-
#import <React/RCTBridge.h>
|
|
147
|
-
#import <React/RCTBundleURLProvider.h>
|
|
148
|
-
- #import <React/RCTRootView.h>
|
|
149
|
-
+ #import <HybridNavigation/HybridNavigation.h>
|
|
150
|
-
|
|
151
|
-
@implementation AppDelegate
|
|
152
|
-
|
|
153
|
-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
154
|
-
{
|
|
155
|
-
- RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
|
|
156
|
-
- moduleName:@"RN60"
|
|
157
|
-
- initialProperties:nil];
|
|
158
|
-
-
|
|
159
|
-
- rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
|
|
160
|
-
|
|
161
|
-
+ [[HBDReactBridgeManager get] installWithBridge:bridge];
|
|
162
|
-
+
|
|
163
|
-
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
|
164
|
-
+ self.window.windowLevel = UIWindowLevelStatusBar + 1;
|
|
165
|
-
UIViewController *rootViewController = [UIViewController new];
|
|
166
|
-
- rootViewController.view = rootView;
|
|
167
|
-
+ rootViewController.view.backgroundColor = UIColor.whiteColor;
|
|
168
|
-
self.window.rootViewController = rootViewController;
|
|
169
|
-
[self.window makeKeyAndVisible];
|
|
170
|
-
return YES;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
@end
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
修改 Info.plist 文件
|
|
177
|
-
|
|
178
|
-

|
|
179
|
-
|
|
180
|
-
## 关于闪屏
|
|
181
|
-
|
|
182
|
-
<a name="migrate-native"></a>
|
|
183
|
-
|
|
184
|
-
如果懂原生开发,建议像 example 这个项目那样配置闪屏。
|
|
185
|
-
|
|
186
|
-
## 参考
|
|
187
|
-
|
|
188
|
-
[一行命令创建 RN 项目并集成本库](https://github.com/listenzz/react-native-create-app)
|
|
189
|
-
|
|
190
|
-
[RN 0.62 集成本库示范项目](https://github.com/listenzz/RN062)
|
|
191
|
-
|
|
192
|
-
[RN 0.61 集成本库示范项目](https://github.com/listenzz/RN061)
|
|
193
|
-
|
|
194
|
-
[RN 0.60 集成本库示范项目](https://github.com/listenzz/RN060)
|
package/docs/lifecycle.md
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# 可见性监听
|
|
2
|
-
|
|
3
|
-
## 如何监听页面显示或隐藏
|
|
4
|
-
|
|
5
|
-
使用 `useVisibleEffect`
|
|
6
|
-
|
|
7
|
-
```tsx
|
|
8
|
-
import React, { useCallback } from 'react'
|
|
9
|
-
import { useVisibleEffect } from 'hybrid-navigation'
|
|
10
|
-
|
|
11
|
-
useVisibleEffect(
|
|
12
|
-
useCallback(() => {
|
|
13
|
-
Alert.alert('Lifecycle Alert!', 'componentDidAppear.')
|
|
14
|
-
return () => Alert.alert('Lifecycle Alert!', 'componentDidDisappear.')
|
|
15
|
-
}, []),
|
|
16
|
-
)
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
如果需要获取页面可见状态,使用 `useVisible` 或者 `useVisibility`。
|
|
20
|
-
|
|
21
|
-
## 类组件
|
|
22
|
-
|
|
23
|
-
本项目中的例子几乎都是用函数组件示例的,因为这是趋势,历史的车轮滚滚向前,该忘掉的就忘掉,该丢弃的就丢弃。
|
|
24
|
-
|
|
25
|
-
有时由于历史遗留问题,不得不使用类组件,此时如何监听页面可见性呢?
|
|
26
|
-
|
|
27
|
-
自定义一个 [HOC](https://reactjs.org/docs/higher-order-components.html)
|
|
28
|
-
|
|
29
|
-
```tsx
|
|
30
|
-
export interface Lifecycle {
|
|
31
|
-
componentDidAppear: () => void
|
|
32
|
-
componentDidDisappear: () => void
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function withLifecycle(ClassComponent: React.ComponentClass<any>) {
|
|
36
|
-
const FC = (props: any) => {
|
|
37
|
-
const ref = useRef<React.Component & Lifecycle>(null)
|
|
38
|
-
|
|
39
|
-
useVisibleEffect(
|
|
40
|
-
useCallback(() => {
|
|
41
|
-
if (ref.current?.componentDidAppear) {
|
|
42
|
-
ref.current.componentDidAppear()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const current = ref.current
|
|
46
|
-
return () => {
|
|
47
|
-
if (current?.componentDidDisappear) {
|
|
48
|
-
current.componentDidDisappear()
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}, []),
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
return <ClassComponent ref={ref} {...props} />
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
FC.navigationItem = (ClassComponent as any).navigationItem
|
|
58
|
-
const name = ClassComponent.displayName || ClassComponent.name
|
|
59
|
-
FC.displayName = `withLifecycle(${name})`
|
|
60
|
-
|
|
61
|
-
return FC
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
在类组件中添加 `componentDidAppear` 和 `componentDidDisappear` 两个实例方法,使用 `withLifecycle` 包裹类组件并导出,如下所示
|
|
66
|
-
|
|
67
|
-
```tsx
|
|
68
|
-
class MyClassComponent extends React.Component<InjectedProps> implements Lifecycle {
|
|
69
|
-
static navigationItem: NavigationItem = {
|
|
70
|
-
titleItem: {
|
|
71
|
-
title: '我的类组件',
|
|
72
|
-
},
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
componentDidAppear() {
|
|
76
|
-
console.info('MyClassComponent#componentDidAppear')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
componentDidDisappear() {
|
|
80
|
-
console.info('MyClassComponent#componentDidDisAppear')
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export default withLifecycle(MyClassComponent)
|
|
85
|
-
```
|