hybrid-navigation 2.12.4 → 2.13.0-beta.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/README.md +63 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +2 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +29 -30
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +2 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +4 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +24 -33
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +22 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +8 -8
- package/ios/HybridNavigation/GlobalStyle.h +0 -8
- package/ios/HybridNavigation/GlobalStyle.m +2 -8
- package/ios/HybridNavigation/HBDUtils.h +5 -13
- package/ios/HybridNavigation/HBDUtils.m +2 -12
- package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.m +91 -67
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.h +2 -7
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +28 -26
- package/ios/HybridNavigation/Navigator/HBDScreenNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDScreenNavigator.m +127 -99
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +199 -142
- package/ios/HybridNavigation/Navigator/HBDTabNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDTabNavigator.m +144 -124
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.h +1 -11
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.m +4 -10
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +5 -0
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +128 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +6 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +237 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigator.h +20 -0
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.h +12 -20
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.m +91 -91
- package/ios/HybridNavigation/View/HBDBarButtonItem.h +0 -8
- package/ios/HybridNavigation/View/HBDBarButtonItem.m +1 -11
- package/ios/HybridNavigation/View/HBDNavigationBar.h +0 -8
- package/ios/HybridNavigation/View/HBDNavigationBar.m +3 -12
- package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -8
- package/ios/HybridNavigation/View/HBDReactTabBar.m +1 -8
- package/ios/HybridNavigation/View/HBDRootView.h +0 -9
- package/ios/HybridNavigation/View/HBDRootView.m +0 -8
- package/ios/HybridNavigation/View/HBDTitleView.h +0 -9
- package/ios/HybridNavigation/View/HBDTitleView.m +1 -26
- package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -8
- package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -7
- package/ios/HybridNavigation/ViewController/HBDDrawerController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDDrawerController.m +2 -9
- package/ios/HybridNavigation/ViewController/HBDFadeAnimation.h +9 -0
- package/ios/HybridNavigation/ViewController/HBDFadeAnimation.m +22 -0
- package/ios/HybridNavigation/ViewController/HBDNavigationController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +17 -120
- package/ios/HybridNavigation/ViewController/HBDPopAnimation.h +0 -7
- package/ios/HybridNavigation/ViewController/HBDPopAnimation.m +1 -8
- package/ios/HybridNavigation/ViewController/HBDPushAnimation.h +0 -7
- package/ios/HybridNavigation/ViewController/HBDPushAnimation.m +1 -8
- package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDReactViewController.m +59 -26
- package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDTabBarController.m +12 -9
- package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +23 -33
- package/ios/HybridNavigation/ViewController/HBDViewController.h +1 -8
- package/ios/HybridNavigation/ViewController/HBDViewController.m +6 -23
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.h +0 -8
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -8
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +2 -16
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +32 -46
- package/lib/Navigator.d.ts +25 -25
- package/lib/Navigator.js +116 -73
- package/package.json +4 -5
- package/src/Navigator.ts +96 -58
- package/ios/HybridNavigation/Bridge/HBDGardenModule.h +0 -14
- package/ios/HybridNavigation/Bridge/HBDGardenModule.m +0 -155
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.h +0 -15
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +0 -272
- package/ios/HybridNavigation/Navigator/HBDNavigator.h +0 -26
package/README.md
CHANGED
|
@@ -11,6 +11,69 @@ React Native Navigation that supports seamless navigation between Native and Rea
|
|
|
11
11
|
|
|
12
12
|

|
|
13
13
|
|
|
14
|
+
## Support
|
|
15
|
+
|
|
16
|
+
| version | react-native version |
|
|
17
|
+
| ------- | -------------------- |
|
|
18
|
+
| 1.0.0+ | 0.60.0+ |
|
|
19
|
+
|
|
20
|
+
## 运行 example 项目
|
|
21
|
+
|
|
22
|
+
首先 clone 本项目
|
|
23
|
+
|
|
24
|
+
```shell
|
|
25
|
+
git clone git@github.com:listenzz/hybrid-navigation.git
|
|
26
|
+
cd hybrid-navigation
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
然后在项目根目录下运行如下命令:
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
npm install
|
|
33
|
+
# &
|
|
34
|
+
npm start
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 在 Android 上运行
|
|
38
|
+
|
|
39
|
+
首先,确保你有一个模拟器或设备
|
|
40
|
+
|
|
41
|
+
如果熟悉原生开发,使用 Android Studio 打开 example/android,像运行原生应用那样运行它,也可以使用命令行:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
# 在项目根目录下运行
|
|
45
|
+
npm run android
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
你可能需要运行如下命令,才可以使用 Hot Reload 功能
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
adb reverse tcp:8081 tcp:8081
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
[**Download demo apk**](https://todoit.oss-cn-shanghai.aliyuncs.com/app-release.apk)
|
|
55
|
+
|
|
56
|
+
或通过扫描二维码安装 demo
|
|
57
|
+
|
|
58
|
+

|
|
59
|
+
|
|
60
|
+
### 在 iOS 上运行
|
|
61
|
+
|
|
62
|
+
首先安装 cocoapods 依赖,在项目根目录下运行如下命令:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
cd example/ios && pod install
|
|
66
|
+
# 成功安装依赖后,回到根目录
|
|
67
|
+
cd -
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
如果熟悉原生开发,使用 Xcode 打开 example/ios,像运行原生应用那样运行它,或者使用命令行:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
# 在项目根目录下运行
|
|
74
|
+
npm run ios
|
|
75
|
+
```
|
|
76
|
+
|
|
14
77
|
## 文档
|
|
15
78
|
|
|
16
79
|
[从这里开始](https://todoit.tech/rn/hybrid-navigation/)
|
|
@@ -201,8 +201,8 @@ public class GardenModule extends ReactContextBaseJavaModule {
|
|
|
201
201
|
|
|
202
202
|
@Nullable
|
|
203
203
|
private ReactAppCompatActivity getActiveActivity() {
|
|
204
|
-
ReactContext reactContext =
|
|
205
|
-
if (reactContext == null) {
|
|
204
|
+
ReactContext reactContext = getReactApplicationContext();
|
|
205
|
+
if (reactContext == null || !reactContext.hasActiveReactInstance()) {
|
|
206
206
|
return null;
|
|
207
207
|
}
|
|
208
208
|
|
|
@@ -10,7 +10,7 @@ import androidx.fragment.app.FragmentManager;
|
|
|
10
10
|
|
|
11
11
|
import com.facebook.common.logging.FLog;
|
|
12
12
|
import com.facebook.react.bridge.Arguments;
|
|
13
|
-
import com.facebook.react.bridge.
|
|
13
|
+
import com.facebook.react.bridge.Callback;
|
|
14
14
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
15
15
|
import com.facebook.react.bridge.ReactContext;
|
|
16
16
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
@@ -39,15 +39,14 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
@Override
|
|
42
|
-
public void
|
|
43
|
-
|
|
44
|
-
FLog.i(TAG, "NavigationModule#onCatalystInstanceDestroy");
|
|
42
|
+
public void invalidate() {
|
|
43
|
+
FLog.i(TAG, "NavigationModule#invalidate");
|
|
45
44
|
UiThreadUtil.runOnUiThread(() -> {
|
|
46
|
-
bridgeManager.
|
|
45
|
+
bridgeManager.invalidate();
|
|
47
46
|
clearFragments();
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
|
-
|
|
49
|
+
|
|
51
50
|
private void clearFragments() {
|
|
52
51
|
AwesomeActivity activity = getActiveActivity();
|
|
53
52
|
if (activity != null) {
|
|
@@ -99,8 +98,8 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
99
98
|
@ReactMethod
|
|
100
99
|
public void setRoot(final ReadableMap layout, final boolean sticky, final int tag) {
|
|
101
100
|
UiThreadUtil.runOnUiThread(() -> {
|
|
102
|
-
ReactContext reactContext =
|
|
103
|
-
if (reactContext == null) {
|
|
101
|
+
ReactContext reactContext = getReactApplicationContext();
|
|
102
|
+
if (reactContext == null || !reactContext.hasActiveReactInstance()) {
|
|
104
103
|
FLog.w(TAG, "ReactContext hasn't active CatalystInstance, skip action `setRoot`");
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
@@ -127,52 +126,52 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
@ReactMethod
|
|
130
|
-
public void dispatch(final String sceneId, final String action, final ReadableMap extras,
|
|
129
|
+
public void dispatch(final String sceneId, final String action, final ReadableMap extras, Callback callback) {
|
|
131
130
|
UiThreadUtil.runOnUiThread(() -> {
|
|
132
131
|
AwesomeFragment target = findFragmentBySceneId(sceneId);
|
|
133
132
|
if (target == null) {
|
|
134
|
-
|
|
133
|
+
callback.invoke(null, false);
|
|
135
134
|
FLog.w(TAG, "Can't find target scene for action:" + action + ", maybe the scene is gone.\nextras: " + extras);
|
|
136
135
|
return;
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
if (!target.isAdded()) {
|
|
140
|
-
|
|
139
|
+
callback.invoke(null, false);
|
|
141
140
|
return;
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
bridgeManager.handleNavigation(target, action, extras,
|
|
143
|
+
bridgeManager.handleNavigation(target, action, extras, callback);
|
|
145
144
|
});
|
|
146
145
|
}
|
|
147
146
|
|
|
148
147
|
@ReactMethod
|
|
149
|
-
public void currentTab(final String sceneId, final
|
|
148
|
+
public void currentTab(final String sceneId, final Callback callback) {
|
|
150
149
|
UiThreadUtil.runOnUiThread(() -> {
|
|
151
150
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
152
151
|
if (fragment == null) {
|
|
153
|
-
|
|
152
|
+
callback.invoke(null, -1);
|
|
154
153
|
return;
|
|
155
154
|
}
|
|
156
155
|
|
|
157
156
|
TabBarFragment tabs = fragment.getTabBarFragment();
|
|
158
157
|
if (tabs == null) {
|
|
159
|
-
|
|
158
|
+
callback.invoke(null, -1);
|
|
160
159
|
return;
|
|
161
160
|
}
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
|
|
162
|
+
callback.invoke(null, tabs.getSelectedIndex());
|
|
164
163
|
});
|
|
165
164
|
}
|
|
166
165
|
|
|
167
166
|
@ReactMethod
|
|
168
|
-
public void isStackRoot(final String sceneId, final
|
|
167
|
+
public void isStackRoot(final String sceneId, final Callback callback) {
|
|
169
168
|
UiThreadUtil.runOnUiThread(() -> {
|
|
170
169
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
171
170
|
if (fragment == null) {
|
|
172
|
-
|
|
171
|
+
callback.invoke(null, false);
|
|
173
172
|
return;
|
|
174
173
|
}
|
|
175
|
-
|
|
174
|
+
callback.invoke(null, fragment.isStackRoot());
|
|
176
175
|
});
|
|
177
176
|
}
|
|
178
177
|
|
|
@@ -187,7 +186,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
187
186
|
}
|
|
188
187
|
|
|
189
188
|
@ReactMethod
|
|
190
|
-
public void findSceneIdByModuleName(@NonNull String moduleName,
|
|
189
|
+
public void findSceneIdByModuleName(@NonNull String moduleName, Callback callback) {
|
|
191
190
|
final Runnable task = new Runnable() {
|
|
192
191
|
@Override
|
|
193
192
|
public void run() {
|
|
@@ -201,13 +200,13 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
201
200
|
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
202
201
|
Fragment fragment = fragmentManager.findFragmentById(android.R.id.content);
|
|
203
202
|
if (!(fragment instanceof AwesomeFragment)) {
|
|
204
|
-
|
|
203
|
+
callback.invoke(null, null);
|
|
205
204
|
return;
|
|
206
205
|
}
|
|
207
206
|
|
|
208
207
|
String sceneId = findSceneIdByModuleName(moduleName, (AwesomeFragment) fragment);
|
|
209
208
|
FLog.i(TAG, "The sceneId found by " + moduleName + " : " + sceneId);
|
|
210
|
-
|
|
209
|
+
callback.invoke(null, sceneId);
|
|
211
210
|
});
|
|
212
211
|
}
|
|
213
212
|
};
|
|
@@ -249,7 +248,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
249
248
|
}
|
|
250
249
|
|
|
251
250
|
@ReactMethod
|
|
252
|
-
public void currentRoute(final
|
|
251
|
+
public void currentRoute(final Callback callback) {
|
|
253
252
|
Runnable task = new Runnable() {
|
|
254
253
|
@Override
|
|
255
254
|
public void run() {
|
|
@@ -271,7 +270,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
271
270
|
bundle.putString("moduleName", current.getModuleName());
|
|
272
271
|
bundle.putString("sceneId", current.getSceneId());
|
|
273
272
|
bundle.putString("mode", Navigator.Util.getMode(current));
|
|
274
|
-
|
|
273
|
+
callback.invoke(null, Arguments.fromBundle(bundle));
|
|
275
274
|
});
|
|
276
275
|
}
|
|
277
276
|
};
|
|
@@ -280,7 +279,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
280
279
|
}
|
|
281
280
|
|
|
282
281
|
@ReactMethod
|
|
283
|
-
public void routeGraph(final
|
|
282
|
+
public void routeGraph(final Callback callback) {
|
|
284
283
|
Runnable task = new Runnable() {
|
|
285
284
|
@Override
|
|
286
285
|
public void run() {
|
|
@@ -297,8 +296,8 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
297
296
|
UiThreadUtil.runOnUiThread(this, 16);
|
|
298
297
|
return;
|
|
299
298
|
}
|
|
300
|
-
|
|
301
|
-
|
|
299
|
+
|
|
300
|
+
callback.invoke(null, Arguments.fromList(graph));
|
|
302
301
|
});
|
|
303
302
|
}
|
|
304
303
|
};
|
|
@@ -323,8 +322,8 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
323
322
|
|
|
324
323
|
@Nullable
|
|
325
324
|
private ReactAppCompatActivity getActiveActivity() {
|
|
326
|
-
ReactContext reactContext =
|
|
327
|
-
if (reactContext == null) {
|
|
325
|
+
ReactContext reactContext = getReactApplicationContext();
|
|
326
|
+
if (reactContext == null || !reactContext.hasActiveReactInstance()) {
|
|
328
327
|
return null;
|
|
329
328
|
}
|
|
330
329
|
|
|
@@ -5,11 +5,10 @@ import android.os.Bundle;
|
|
|
5
5
|
import androidx.annotation.NonNull;
|
|
6
6
|
import androidx.annotation.Nullable;
|
|
7
7
|
|
|
8
|
-
import com.facebook.react.bridge.
|
|
8
|
+
import com.facebook.react.bridge.Callback;
|
|
9
9
|
import com.facebook.react.bridge.ReadableMap;
|
|
10
10
|
import com.navigation.androidx.AwesomeFragment;
|
|
11
11
|
import com.navigation.androidx.PresentationStyle;
|
|
12
|
-
import com.reactnative.hybridnavigation.HybridFragment;
|
|
13
12
|
|
|
14
13
|
import java.util.List;
|
|
15
14
|
|
|
@@ -46,6 +45,6 @@ public interface Navigator {
|
|
|
46
45
|
@Nullable
|
|
47
46
|
HybridFragment primaryFragment(@NonNull AwesomeFragment fragment);
|
|
48
47
|
|
|
49
|
-
void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull
|
|
48
|
+
void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull Callback callback);
|
|
50
49
|
|
|
51
50
|
}
|
|
@@ -12,7 +12,7 @@ import com.facebook.common.logging.FLog;
|
|
|
12
12
|
import com.facebook.react.ReactInstanceManager;
|
|
13
13
|
import com.facebook.react.ReactNativeHost;
|
|
14
14
|
import com.facebook.react.bridge.Arguments;
|
|
15
|
-
import com.facebook.react.bridge.
|
|
15
|
+
import com.facebook.react.bridge.Callback;
|
|
16
16
|
import com.facebook.react.bridge.ReactContext;
|
|
17
17
|
import com.facebook.react.bridge.ReadableMap;
|
|
18
18
|
import com.facebook.react.bridge.WritableMap;
|
|
@@ -176,7 +176,7 @@ public class ReactBridgeManager {
|
|
|
176
176
|
reactBridgeReloadListeners.remove(listener);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
public void
|
|
179
|
+
public void invalidate() {
|
|
180
180
|
invokeReloadListeners();
|
|
181
181
|
setPendingLayout(null, 0);
|
|
182
182
|
setReactModuleRegisterCompleted(false);
|
|
@@ -311,10 +311,10 @@ public class ReactBridgeManager {
|
|
|
311
311
|
return null;
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull
|
|
314
|
+
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
315
315
|
Navigator navigator = navigatorRegistry.navigatorForAction(action);
|
|
316
316
|
if (navigator != null) {
|
|
317
|
-
navigator.handleNavigation(target, action, extras,
|
|
317
|
+
navigator.handleNavigation(target, action, extras, callback);
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
|
package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java
CHANGED
|
@@ -5,7 +5,7 @@ import android.os.Bundle;
|
|
|
5
5
|
import androidx.annotation.NonNull;
|
|
6
6
|
import androidx.annotation.Nullable;
|
|
7
7
|
|
|
8
|
-
import com.facebook.react.bridge.
|
|
8
|
+
import com.facebook.react.bridge.Callback;
|
|
9
9
|
import com.facebook.react.bridge.ReadableArray;
|
|
10
10
|
import com.facebook.react.bridge.ReadableMap;
|
|
11
11
|
import com.navigation.androidx.AwesomeFragment;
|
|
@@ -143,22 +143,22 @@ public class DrawerNavigator implements Navigator {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
@Override
|
|
146
|
-
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull
|
|
146
|
+
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
147
147
|
DrawerFragment drawerFragment = target.getDrawerFragment();
|
|
148
148
|
if (drawerFragment == null) {
|
|
149
|
-
|
|
149
|
+
callback.invoke(null, false);
|
|
150
150
|
return;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
switch (action) {
|
|
154
154
|
case "toggleMenu":
|
|
155
|
-
drawerFragment.toggleMenu(() ->
|
|
155
|
+
drawerFragment.toggleMenu(() -> callback.invoke(null, true));
|
|
156
156
|
break;
|
|
157
157
|
case "openMenu":
|
|
158
|
-
drawerFragment.openMenu(() ->
|
|
158
|
+
drawerFragment.openMenu(() -> callback.invoke(null, true));
|
|
159
159
|
break;
|
|
160
160
|
case "closeMenu":
|
|
161
|
-
drawerFragment.closeMenu(() ->
|
|
161
|
+
drawerFragment.closeMenu(() -> callback.invoke(null, true));
|
|
162
162
|
break;
|
|
163
163
|
}
|
|
164
164
|
}
|
package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java
CHANGED
|
@@ -6,6 +6,7 @@ import androidx.annotation.NonNull;
|
|
|
6
6
|
import androidx.annotation.Nullable;
|
|
7
7
|
|
|
8
8
|
import com.facebook.react.bridge.Arguments;
|
|
9
|
+
import com.facebook.react.bridge.Callback;
|
|
9
10
|
import com.facebook.react.bridge.Promise;
|
|
10
11
|
import com.facebook.react.bridge.ReadableMap;
|
|
11
12
|
import com.navigation.androidx.AwesomeFragment;
|
|
@@ -90,92 +91,82 @@ public class ScreenNavigator implements Navigator {
|
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
@Override
|
|
93
|
-
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull
|
|
94
|
+
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
94
95
|
switch (action) {
|
|
95
96
|
case "present":
|
|
96
|
-
handlePresent(target, extras,
|
|
97
|
+
handlePresent(target, extras, callback);
|
|
97
98
|
break;
|
|
98
99
|
case "dismiss":
|
|
99
|
-
handleDismiss(target,
|
|
100
|
+
handleDismiss(target, callback);
|
|
100
101
|
break;
|
|
101
102
|
case "showModal":
|
|
102
|
-
handleShowModal(target, extras,
|
|
103
|
+
handleShowModal(target, extras, callback);
|
|
103
104
|
break;
|
|
104
105
|
case "hideModal":
|
|
105
|
-
handleHideModal(target,
|
|
106
|
+
handleHideModal(target, callback);
|
|
106
107
|
break;
|
|
107
108
|
case "presentLayout":
|
|
108
|
-
handlePresentLayout(target, extras,
|
|
109
|
+
handlePresentLayout(target, extras, callback);
|
|
109
110
|
break;
|
|
110
111
|
case "showModalLayout":
|
|
111
|
-
handleShowModalLayout(target, extras,
|
|
112
|
+
handleShowModalLayout(target, extras, callback);
|
|
112
113
|
break;
|
|
113
114
|
|
|
114
115
|
}
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
private void handleShowModalLayout(@NonNull AwesomeFragment presenting, @NonNull ReadableMap extras, @NonNull
|
|
118
|
+
private void handleShowModalLayout(@NonNull AwesomeFragment presenting, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
118
119
|
ReadableMap layout = extras.getMap("layout");
|
|
119
120
|
AwesomeFragment presented = getReactBridgeManager().createFragment(layout);
|
|
120
121
|
if (presented == null) {
|
|
121
|
-
|
|
122
|
+
callback.invoke(null, false);
|
|
122
123
|
return;
|
|
123
124
|
}
|
|
124
125
|
presented.setPresentationStyle(PresentationStyle.OverFullScreen);
|
|
125
126
|
int requestCode = extras.getInt("requestCode");
|
|
126
|
-
presenting.presentFragment(presented, requestCode, () ->
|
|
127
|
+
presenting.presentFragment(presented, requestCode, () -> callback.invoke(null, true), TransitionAnimation.Fade);
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
private void handlePresentLayout(@NonNull AwesomeFragment presenting, @NonNull ReadableMap extras, @NonNull
|
|
130
|
+
private void handlePresentLayout(@NonNull AwesomeFragment presenting, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
130
131
|
ReadableMap layout = extras.getMap("layout");
|
|
131
132
|
AwesomeFragment presented = getReactBridgeManager().createFragment(layout);
|
|
132
133
|
if (presented == null) {
|
|
133
|
-
|
|
134
|
+
callback.invoke(null, false);
|
|
134
135
|
return;
|
|
135
136
|
}
|
|
136
137
|
int requestCode = extras.getInt("requestCode");
|
|
137
|
-
presenting.presentFragment(presented, requestCode, () ->
|
|
138
|
+
presenting.presentFragment(presented, requestCode, () -> callback.invoke(null, true));
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
private void handleShowModal(@NonNull AwesomeFragment presenting, @NonNull ReadableMap extras, @NonNull
|
|
141
|
+
private void handleShowModal(@NonNull AwesomeFragment presenting, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
141
142
|
AwesomeFragment presented = createFragmentWithExtras(extras);
|
|
142
143
|
if (presented == null) {
|
|
143
|
-
|
|
144
|
+
callback.invoke(null, false);
|
|
144
145
|
return;
|
|
145
146
|
}
|
|
146
147
|
presented.setPresentationStyle(PresentationStyle.OverFullScreen);
|
|
147
148
|
int requestCode = extras.getInt("requestCode");
|
|
148
|
-
presenting.presentFragment(presented, requestCode, () ->
|
|
149
|
+
presenting.presentFragment(presented, requestCode, () -> callback.invoke(null, true), TransitionAnimation.Fade);
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
private void handleHideModal(@NonNull AwesomeFragment target, @NonNull
|
|
152
|
-
|
|
153
|
-
if (presenting != null) {
|
|
154
|
-
presenting.dismissFragment(() -> promise.resolve(true), TransitionAnimation.Fade);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
target.dismissFragment(() -> promise.resolve(true), TransitionAnimation.Fade);
|
|
152
|
+
private void handleHideModal(@NonNull AwesomeFragment target, @NonNull Callback callback) {
|
|
153
|
+
target.dismissFragment(() -> callback.invoke(null, true), TransitionAnimation.Fade);
|
|
158
154
|
}
|
|
159
155
|
|
|
160
|
-
private void handleDismiss(@NonNull AwesomeFragment target, @NonNull
|
|
161
|
-
|
|
162
|
-
if (presenting != null) {
|
|
163
|
-
presenting.dismissFragment(() -> promise.resolve(true));
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
target.dismissFragment(() -> promise.resolve(true));
|
|
156
|
+
private void handleDismiss(@NonNull AwesomeFragment target, @NonNull Callback callback) {
|
|
157
|
+
target.dismissFragment(() -> callback.invoke(null, true));
|
|
167
158
|
}
|
|
168
159
|
|
|
169
|
-
private void handlePresent(@NonNull AwesomeFragment target, @NonNull ReadableMap extras, @NonNull
|
|
160
|
+
private void handlePresent(@NonNull AwesomeFragment target, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
170
161
|
AwesomeFragment fragment = createFragmentWithExtras(extras);
|
|
171
162
|
if (fragment == null) {
|
|
172
|
-
|
|
163
|
+
callback.invoke(null, false);
|
|
173
164
|
return;
|
|
174
165
|
}
|
|
175
166
|
int requestCode = extras.getInt("requestCode");
|
|
176
167
|
ReactStackFragment stackFragment = new ReactStackFragment();
|
|
177
168
|
stackFragment.setRootFragment(fragment);
|
|
178
|
-
target.presentFragment(stackFragment, requestCode, () ->
|
|
169
|
+
target.presentFragment(stackFragment, requestCode, () -> callback.invoke(null, true));
|
|
179
170
|
}
|
|
180
171
|
|
|
181
172
|
private AwesomeFragment createFragmentWithExtras(@NonNull ReadableMap extras) {
|
package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java
CHANGED
|
@@ -9,7 +9,7 @@ import androidx.fragment.app.Fragment;
|
|
|
9
9
|
import androidx.fragment.app.FragmentManager;
|
|
10
10
|
|
|
11
11
|
import com.facebook.react.bridge.Arguments;
|
|
12
|
-
import com.facebook.react.bridge.
|
|
12
|
+
import com.facebook.react.bridge.Callback;
|
|
13
13
|
import com.facebook.react.bridge.ReadableArray;
|
|
14
14
|
import com.facebook.react.bridge.ReadableMap;
|
|
15
15
|
import com.navigation.androidx.AwesomeFragment;
|
|
@@ -111,58 +111,58 @@ public class StackNavigator implements Navigator {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
@Override
|
|
114
|
-
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull
|
|
114
|
+
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
115
115
|
StackFragment stackFragment = getStackFragment(target);
|
|
116
116
|
if (stackFragment == null) {
|
|
117
|
-
|
|
117
|
+
callback.invoke(null, false);
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
switch (action) {
|
|
122
122
|
case "push":
|
|
123
|
-
handlePush(
|
|
123
|
+
handlePush(stackFragment, extras, callback);
|
|
124
124
|
break;
|
|
125
125
|
case "pop":
|
|
126
|
-
stackFragment.popFragment(() ->
|
|
126
|
+
stackFragment.popFragment(() -> callback.invoke(null, true));
|
|
127
127
|
break;
|
|
128
128
|
case "popTo":
|
|
129
|
-
handlePopTo(
|
|
129
|
+
handlePopTo(stackFragment, extras, callback);
|
|
130
130
|
break;
|
|
131
131
|
case "popToRoot":
|
|
132
|
-
stackFragment.popToRootFragment(() ->
|
|
132
|
+
stackFragment.popToRootFragment(() -> callback.invoke(null,true));
|
|
133
133
|
break;
|
|
134
134
|
case "redirectTo":
|
|
135
|
-
handleRedirectTo(
|
|
135
|
+
handleRedirectTo(stackFragment, extras, target, callback);
|
|
136
136
|
break;
|
|
137
137
|
case "pushLayout":
|
|
138
|
-
handlePushLayout(
|
|
138
|
+
handlePushLayout(stackFragment, extras, callback);
|
|
139
139
|
break;
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
private void handlePushLayout(@NonNull
|
|
143
|
+
private void handlePushLayout(@NonNull StackFragment stackFragment, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
144
144
|
ReadableMap layout = extras.getMap("layout");
|
|
145
145
|
AwesomeFragment fragment = getReactBridgeManager().createFragment(layout);
|
|
146
146
|
if (fragment == null) {
|
|
147
|
-
|
|
147
|
+
callback.invoke(null, false);
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
|
-
stackFragment.pushFragment(fragment, () ->
|
|
150
|
+
stackFragment.pushFragment(fragment, () -> callback.invoke(null, true));
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
private void handleRedirectTo(@NonNull
|
|
153
|
+
private void handleRedirectTo(@NonNull StackFragment stackFragment, @NonNull ReadableMap extras, @NonNull AwesomeFragment target, @NonNull Callback callback) {
|
|
154
154
|
AwesomeFragment fragment = createFragmentWithExtras(extras);
|
|
155
155
|
if (fragment == null) {
|
|
156
|
-
|
|
156
|
+
callback.invoke(null, false);
|
|
157
157
|
return;
|
|
158
158
|
}
|
|
159
|
-
stackFragment.redirectToFragment(fragment, () ->
|
|
159
|
+
stackFragment.redirectToFragment(fragment, () -> callback.invoke(null, true), TransitionAnimation.Redirect, target);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
private void handlePopTo(@NonNull
|
|
162
|
+
private void handlePopTo(@NonNull StackFragment stackFragment, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
163
163
|
String moduleName = extras.getString("moduleName");
|
|
164
164
|
if (moduleName == null) {
|
|
165
|
-
|
|
165
|
+
callback.invoke(null, false);
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
168
|
|
|
@@ -170,11 +170,11 @@ public class StackNavigator implements Navigator {
|
|
|
170
170
|
FragmentManager fragmentManager = stackFragment.getChildFragmentManager();
|
|
171
171
|
AwesomeFragment fragment = findFragmentForPopTo(moduleName, inclusive, fragmentManager);
|
|
172
172
|
if (fragment == null) {
|
|
173
|
-
|
|
173
|
+
callback.invoke(null, false);
|
|
174
174
|
return;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
stackFragment.popToFragment(fragment, () ->
|
|
177
|
+
stackFragment.popToFragment(fragment, () -> callback.invoke(null, true));
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
@Nullable
|
|
@@ -207,13 +207,13 @@ public class StackNavigator implements Navigator {
|
|
|
207
207
|
return null;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
private void handlePush(@NonNull
|
|
210
|
+
private void handlePush(@NonNull StackFragment stackFragment, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
211
211
|
AwesomeFragment fragment = createFragmentWithExtras(extras);
|
|
212
212
|
if (fragment == null) {
|
|
213
|
-
|
|
213
|
+
callback.invoke(null, false);
|
|
214
214
|
return;
|
|
215
215
|
}
|
|
216
|
-
stackFragment.pushFragment(fragment, () ->
|
|
216
|
+
stackFragment.pushFragment(fragment, () -> callback.invoke(null, true));
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
private AwesomeFragment createFragmentWithExtras(@NonNull ReadableMap extras) {
|
|
@@ -5,7 +5,7 @@ import android.os.Bundle;
|
|
|
5
5
|
import androidx.annotation.NonNull;
|
|
6
6
|
import androidx.annotation.Nullable;
|
|
7
7
|
|
|
8
|
-
import com.facebook.react.bridge.
|
|
8
|
+
import com.facebook.react.bridge.Callback;
|
|
9
9
|
import com.facebook.react.bridge.ReadableArray;
|
|
10
10
|
import com.facebook.react.bridge.ReadableMap;
|
|
11
11
|
import com.navigation.androidx.AwesomeFragment;
|
|
@@ -151,35 +151,35 @@ public class TabNavigator implements Navigator {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
@Override
|
|
154
|
-
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull
|
|
154
|
+
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
155
155
|
TabBarFragment tabBarFragment = target.getTabBarFragment();
|
|
156
156
|
if (tabBarFragment == null) {
|
|
157
|
-
|
|
157
|
+
callback.invoke(null, false);
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
if ("switchTab".equals(action)) {
|
|
162
|
-
handleSwitchTab(
|
|
162
|
+
handleSwitchTab(tabBarFragment, extras, callback);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
private void handleSwitchTab(@NonNull
|
|
166
|
+
private void handleSwitchTab(@NonNull TabBarFragment tabBarFragment, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
167
167
|
int to = extras.getInt("to");
|
|
168
168
|
if (isSameTab(to, extras)) {
|
|
169
|
-
|
|
169
|
+
callback.invoke(null, true);
|
|
170
170
|
return;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
popToStackRootIfNeeded(extras, tabBarFragment);
|
|
174
174
|
|
|
175
175
|
if (!(tabBarFragment instanceof ReactTabBarFragment)) {
|
|
176
|
-
tabBarFragment.setSelectedIndex(to, () ->
|
|
176
|
+
tabBarFragment.setSelectedIndex(to, () -> callback.invoke(null, true));
|
|
177
177
|
return;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
ReactTabBarFragment reactTabBarFragment = (ReactTabBarFragment) tabBarFragment;
|
|
181
181
|
reactTabBarFragment.setIntercepted(false);
|
|
182
|
-
reactTabBarFragment.setSelectedIndex(to, () ->
|
|
182
|
+
reactTabBarFragment.setSelectedIndex(to, () -> callback.invoke(null, true));
|
|
183
183
|
reactTabBarFragment.setIntercepted(true);
|
|
184
184
|
}
|
|
185
185
|
|