hybrid-navigation 2.6.0 → 2.7.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/CHANGELOG.md +6 -0
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +2 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +19 -57
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +1 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +5 -5
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +57 -94
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +12 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +10 -17
- package/android/src/main/java/com/reactnative/hybridnavigation/{ReactNavigationFragment.java → ReactStackFragment.java} +2 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +2 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +4 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/NavigatorRegistry.java +2 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +7 -7
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +24 -24
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +4 -4
- package/docs/integration-native.md +3 -3
- package/docs/pass-and-return-value.md +4 -4
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +1 -1
- package/lib/Navigator.js +1 -1
- package/package.json +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/UiTaskExecutor.java +0 -81
package/CHANGELOG.md
CHANGED
package/android/build.gradle
CHANGED
|
@@ -33,5 +33,5 @@ dependencies {
|
|
|
33
33
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
34
34
|
implementation 'com.facebook.react:react-native:+'
|
|
35
35
|
// api project(':navigation')
|
|
36
|
-
api 'io.github.listenzz:AndroidNavigation:
|
|
36
|
+
api 'io.github.listenzz:AndroidNavigation:12.0.0'
|
|
37
37
|
}
|
|
@@ -91,7 +91,7 @@ public class Garden {
|
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
AwesomeToolbar toolbar = fragment.
|
|
94
|
+
AwesomeToolbar toolbar = fragment.getToolbar();
|
|
95
95
|
if (toolbar == null) {
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
@@ -292,7 +292,7 @@ public class Garden {
|
|
|
292
292
|
boolean passThroughTouches = readableMap.getBoolean("passThroughTouches");
|
|
293
293
|
setPassThroughTouches(passThroughTouches);
|
|
294
294
|
}
|
|
295
|
-
|
|
295
|
+
|
|
296
296
|
Bundle options = mergeOptions(fragment.getOptions(), patches);
|
|
297
297
|
|
|
298
298
|
if (readableMap.hasKey("leftBarButtonItem")) {
|
|
@@ -9,25 +9,21 @@ import static com.reactnative.hybridnavigation.Parameters.toList;
|
|
|
9
9
|
|
|
10
10
|
import android.app.Activity;
|
|
11
11
|
import android.os.Bundle;
|
|
12
|
-
import android.os.Handler;
|
|
13
12
|
|
|
14
13
|
import androidx.annotation.NonNull;
|
|
15
14
|
import androidx.annotation.Nullable;
|
|
16
15
|
import androidx.drawerlayout.widget.DrawerLayout;
|
|
17
16
|
import androidx.fragment.app.FragmentManager;
|
|
18
|
-
import androidx.lifecycle.Lifecycle;
|
|
19
|
-
import androidx.lifecycle.LifecycleOwner;
|
|
20
|
-
import androidx.lifecycle.LifecycleRegistry;
|
|
21
17
|
|
|
22
18
|
import com.facebook.common.logging.FLog;
|
|
23
19
|
import com.facebook.react.bridge.JavaOnlyMap;
|
|
24
|
-
import com.facebook.react.bridge.LifecycleEventListener;
|
|
25
20
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
26
21
|
import com.facebook.react.bridge.ReactContext;
|
|
27
22
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
28
23
|
import com.facebook.react.bridge.ReactMethod;
|
|
29
24
|
import com.facebook.react.bridge.ReadableArray;
|
|
30
25
|
import com.facebook.react.bridge.ReadableMap;
|
|
26
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
31
27
|
import com.facebook.react.bridge.WritableMap;
|
|
32
28
|
import com.navigation.androidx.AwesomeFragment;
|
|
33
29
|
import com.navigation.androidx.DrawerFragment;
|
|
@@ -40,53 +36,16 @@ import java.util.Map;
|
|
|
40
36
|
/**
|
|
41
37
|
* Created by Listen on 2017/11/22.
|
|
42
38
|
*/
|
|
43
|
-
public class GardenModule extends ReactContextBaseJavaModule
|
|
39
|
+
public class GardenModule extends ReactContextBaseJavaModule {
|
|
44
40
|
|
|
45
41
|
private static final String TAG = "Navigator";
|
|
46
|
-
|
|
47
|
-
static final Handler sHandler = NavigationModule.sHandler;
|
|
48
|
-
private final UiTaskExecutor uiTaskExecutor;
|
|
49
|
-
private final LifecycleRegistry lifecycleRegistry;
|
|
50
|
-
private final ReactApplicationContext reactContext;
|
|
51
42
|
private final ReactBridgeManager bridgeManager;
|
|
52
43
|
|
|
53
44
|
public GardenModule(ReactApplicationContext reactContext, ReactBridgeManager bridgeManager) {
|
|
54
45
|
super(reactContext);
|
|
55
46
|
this.bridgeManager = bridgeManager;
|
|
56
|
-
this.reactContext = reactContext;
|
|
57
|
-
reactContext.addLifecycleEventListener(this);
|
|
58
|
-
lifecycleRegistry = new LifecycleRegistry(this);
|
|
59
|
-
lifecycleRegistry.setCurrentState(Lifecycle.State.CREATED);
|
|
60
|
-
uiTaskExecutor = new UiTaskExecutor(this, sHandler);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@Override
|
|
64
|
-
public void onHostResume() {
|
|
65
|
-
lifecycleRegistry.setCurrentState(Lifecycle.State.STARTED);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
@Override
|
|
69
|
-
public void onHostPause() {
|
|
70
|
-
lifecycleRegistry.setCurrentState(Lifecycle.State.CREATED);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
@Override
|
|
74
|
-
public void onHostDestroy() {
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
@NonNull
|
|
78
|
-
@Override
|
|
79
|
-
public Lifecycle getLifecycle() {
|
|
80
|
-
return lifecycleRegistry;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@Override
|
|
84
|
-
public void onCatalystInstanceDestroy() {
|
|
85
|
-
super.onCatalystInstanceDestroy();
|
|
86
|
-
reactContext.removeLifecycleEventListener(this);
|
|
87
|
-
lifecycleRegistry.setCurrentState(Lifecycle.State.DESTROYED);
|
|
88
47
|
}
|
|
89
|
-
|
|
48
|
+
|
|
90
49
|
@NonNull
|
|
91
50
|
@Override
|
|
92
51
|
public String getName() {
|
|
@@ -103,13 +62,13 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
|
|
|
103
62
|
|
|
104
63
|
@ReactMethod
|
|
105
64
|
public void setStyle(final ReadableMap style) {
|
|
106
|
-
|
|
65
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
107
66
|
FLog.i(TAG, "GardenModule#setStyle");
|
|
108
67
|
Garden.createGlobalStyle(toBundle(style));
|
|
109
|
-
|
|
110
|
-
ReactContext context =
|
|
111
|
-
if (context
|
|
112
|
-
ReactAppCompatActivity activity = (ReactAppCompatActivity) getCurrentActivity();
|
|
68
|
+
|
|
69
|
+
ReactContext context = getReactApplicationContextIfActiveOrWarn();
|
|
70
|
+
if (context != null) {
|
|
71
|
+
ReactAppCompatActivity activity = (ReactAppCompatActivity) context.getCurrentActivity();
|
|
113
72
|
if (activity != null) {
|
|
114
73
|
activity.inflateStyle();
|
|
115
74
|
}
|
|
@@ -145,7 +104,7 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
|
|
|
145
104
|
@ReactMethod
|
|
146
105
|
public void updateOptions(final String sceneId, final ReadableMap readableMap) {
|
|
147
106
|
FLog.i(TAG, "update options:" + readableMap);
|
|
148
|
-
|
|
107
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
149
108
|
HybridFragment fragment = findHybridFragmentBySceneId(sceneId);
|
|
150
109
|
if (fragment != null && fragment.isAdded()) {
|
|
151
110
|
fragment.getGarden().updateOptions(readableMap);
|
|
@@ -176,7 +135,7 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
|
|
|
176
135
|
@ReactMethod
|
|
177
136
|
public void updateTabBar(final String sceneId, final ReadableMap readableMap) {
|
|
178
137
|
FLog.i(TAG, "updateTabBar:" + readableMap);
|
|
179
|
-
|
|
138
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
180
139
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
181
140
|
if (fragment != null && fragment.getView() != null) {
|
|
182
141
|
TabBarFragment tabBarFragment = fragment.getTabBarFragment();
|
|
@@ -193,7 +152,7 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
|
|
|
193
152
|
@ReactMethod
|
|
194
153
|
public void setTabItem(final String sceneId, @NonNull final ReadableArray options) {
|
|
195
154
|
FLog.i(TAG, "setTabItem:" + options);
|
|
196
|
-
|
|
155
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
197
156
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
198
157
|
if (fragment != null && fragment.getView() != null) {
|
|
199
158
|
TabBarFragment tabBarFragment = fragment.getTabBarFragment();
|
|
@@ -206,10 +165,10 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
|
|
|
206
165
|
}
|
|
207
166
|
});
|
|
208
167
|
}
|
|
209
|
-
|
|
168
|
+
|
|
210
169
|
@ReactMethod
|
|
211
170
|
public void setMenuInteractive(final String sceneId, final boolean enabled) {
|
|
212
|
-
|
|
171
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
213
172
|
AwesomeFragment awesomeFragment = findFragmentBySceneId(sceneId);
|
|
214
173
|
if (awesomeFragment != null) {
|
|
215
174
|
DrawerFragment drawerFragment = awesomeFragment.getDrawerFragment();
|
|
@@ -221,13 +180,16 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
|
|
|
221
180
|
}
|
|
222
181
|
|
|
223
182
|
private AwesomeFragment findFragmentBySceneId(String sceneId) {
|
|
224
|
-
ReactContext reactContext =
|
|
225
|
-
if (
|
|
183
|
+
ReactContext reactContext = getReactApplicationContextIfActiveOrWarn();
|
|
184
|
+
if (reactContext == null) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
if (!bridgeManager.isViewHierarchyReady()) {
|
|
226
188
|
FLog.w(TAG, "View hierarchy is not ready now.");
|
|
227
189
|
return null;
|
|
228
190
|
}
|
|
229
191
|
|
|
230
|
-
Activity activity = getCurrentActivity();
|
|
192
|
+
Activity activity = reactContext.getCurrentActivity();
|
|
231
193
|
if (activity instanceof ReactAppCompatActivity) {
|
|
232
194
|
ReactAppCompatActivity reactActivity = (ReactAppCompatActivity) activity;
|
|
233
195
|
FragmentManager fragmentManager = reactActivity.getSupportFragmentManager();
|
|
@@ -38,9 +38,7 @@ public class GlobalStyle {
|
|
|
38
38
|
FLog.w(TAG, "Style options is null");
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
FLog.i(TAG, "GlobalStyle#inflateStyle");
|
|
43
|
-
|
|
41
|
+
|
|
44
42
|
// screenBackgroundColor
|
|
45
43
|
String screenBackgroundColor = options.getString("screenBackgroundColor");
|
|
46
44
|
if (screenBackgroundColor != null) {
|
|
@@ -87,11 +87,11 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
@Override
|
|
90
|
-
public void
|
|
91
|
-
super.
|
|
90
|
+
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
91
|
+
super.onViewCreated(view, savedInstanceState);
|
|
92
92
|
garden.configureToolbar();
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
public Garden getGarden() {
|
|
96
96
|
return garden;
|
|
97
97
|
}
|
|
@@ -117,11 +117,11 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
@Override
|
|
120
|
-
protected AwesomeToolbar
|
|
120
|
+
protected AwesomeToolbar onCreateToolbar(View parent) {
|
|
121
121
|
if (garden.toolbarHidden) {
|
|
122
122
|
return null;
|
|
123
123
|
}
|
|
124
|
-
return super.
|
|
124
|
+
return super.onCreateToolbar(parent);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
private Bundle options;
|
|
@@ -2,26 +2,21 @@ package com.reactnative.hybridnavigation;
|
|
|
2
2
|
|
|
3
3
|
import android.app.Activity;
|
|
4
4
|
import android.os.Bundle;
|
|
5
|
-
import android.os.Handler;
|
|
6
|
-
import android.os.Looper;
|
|
7
5
|
|
|
8
6
|
import androidx.annotation.NonNull;
|
|
9
7
|
import androidx.annotation.Nullable;
|
|
10
8
|
import androidx.fragment.app.Fragment;
|
|
11
9
|
import androidx.fragment.app.FragmentManager;
|
|
12
|
-
import androidx.lifecycle.Lifecycle;
|
|
13
|
-
import androidx.lifecycle.LifecycleOwner;
|
|
14
|
-
import androidx.lifecycle.LifecycleRegistry;
|
|
15
10
|
|
|
16
11
|
import com.facebook.common.logging.FLog;
|
|
17
12
|
import com.facebook.react.bridge.Arguments;
|
|
18
|
-
import com.facebook.react.bridge.LifecycleEventListener;
|
|
19
13
|
import com.facebook.react.bridge.Promise;
|
|
20
14
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
21
15
|
import com.facebook.react.bridge.ReactContext;
|
|
22
16
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
23
17
|
import com.facebook.react.bridge.ReactMethod;
|
|
24
18
|
import com.facebook.react.bridge.ReadableMap;
|
|
19
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
25
20
|
import com.navigation.androidx.AwesomeFragment;
|
|
26
21
|
import com.navigation.androidx.FragmentHelper;
|
|
27
22
|
import com.navigation.androidx.TabBarFragment;
|
|
@@ -36,58 +31,22 @@ import java.util.Map;
|
|
|
36
31
|
/**
|
|
37
32
|
* Created by Listen on 2017/11/20.
|
|
38
33
|
*/
|
|
39
|
-
public class NavigationModule extends ReactContextBaseJavaModule
|
|
34
|
+
public class NavigationModule extends ReactContextBaseJavaModule {
|
|
40
35
|
|
|
41
36
|
static final String TAG = "Navigator";
|
|
42
|
-
static final Handler sHandler = new Handler(Looper.getMainLooper());
|
|
43
|
-
|
|
44
37
|
private final ReactBridgeManager bridgeManager;
|
|
45
|
-
|
|
46
|
-
private final UiTaskExecutor uiTaskExecutor;
|
|
47
|
-
private final LifecycleRegistry lifecycleRegistry;
|
|
48
|
-
|
|
38
|
+
|
|
49
39
|
NavigationModule(ReactApplicationContext reactContext, ReactBridgeManager bridgeManager) {
|
|
50
40
|
super(reactContext);
|
|
51
41
|
this.bridgeManager = bridgeManager;
|
|
52
|
-
this.reactContext = reactContext;
|
|
53
|
-
reactContext.addLifecycleEventListener(this);
|
|
54
|
-
lifecycleRegistry = new LifecycleRegistry(this);
|
|
55
|
-
lifecycleRegistry.setCurrentState(Lifecycle.State.CREATED);
|
|
56
|
-
uiTaskExecutor = new UiTaskExecutor(this, sHandler);
|
|
57
42
|
FLog.i(TAG, "NavigationModule#onCreate");
|
|
58
43
|
}
|
|
59
|
-
|
|
60
|
-
@Override
|
|
61
|
-
public void onHostResume() {
|
|
62
|
-
FLog.i(TAG, "NavigationModule#onHostResume");
|
|
63
|
-
lifecycleRegistry.setCurrentState(Lifecycle.State.STARTED);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@Override
|
|
67
|
-
public void onHostPause() {
|
|
68
|
-
FLog.i(TAG, "NavigationModule#onHostPause");
|
|
69
|
-
lifecycleRegistry.setCurrentState(Lifecycle.State.CREATED);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@Override
|
|
73
|
-
public void onHostDestroy() {
|
|
74
|
-
FLog.i(TAG, "NavigationModule#onHostDestroy");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
@NonNull
|
|
78
|
-
@Override
|
|
79
|
-
public Lifecycle getLifecycle() {
|
|
80
|
-
return lifecycleRegistry;
|
|
81
|
-
}
|
|
82
|
-
|
|
44
|
+
|
|
83
45
|
@Override
|
|
84
46
|
public void onCatalystInstanceDestroy() {
|
|
85
47
|
super.onCatalystInstanceDestroy();
|
|
86
48
|
FLog.i(TAG, "NavigationModule#onCatalystInstanceDestroy");
|
|
87
|
-
|
|
88
|
-
lifecycleRegistry.setCurrentState(Lifecycle.State.DESTROYED);
|
|
89
|
-
sHandler.removeCallbacksAndMessages(null);
|
|
90
|
-
sHandler.post(() -> {
|
|
49
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
91
50
|
List<ReactBridgeManager.ReactBridgeReloadListener> listeners = bridgeManager.getReactBridgeReloadListeners();
|
|
92
51
|
for (ReactBridgeManager.ReactBridgeReloadListener listener : listeners) {
|
|
93
52
|
listener.onReload();
|
|
@@ -96,10 +55,14 @@ public class NavigationModule extends ReactContextBaseJavaModule implements Life
|
|
|
96
55
|
bridgeManager.setPendingLayout(null, 0);
|
|
97
56
|
bridgeManager.setReactModuleRegisterCompleted(false);
|
|
98
57
|
bridgeManager.setViewHierarchyReady(false);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
58
|
+
|
|
59
|
+
ReactContext reactContext = getReactApplicationContextIfActiveOrWarn();
|
|
60
|
+
if (reactContext != null) {
|
|
61
|
+
Activity activity = reactContext.getCurrentActivity();
|
|
62
|
+
if (activity instanceof ReactAppCompatActivity) {
|
|
63
|
+
ReactAppCompatActivity reactAppCompatActivity = (ReactAppCompatActivity) activity;
|
|
64
|
+
reactAppCompatActivity.clearFragments();
|
|
65
|
+
}
|
|
103
66
|
}
|
|
104
67
|
});
|
|
105
68
|
}
|
|
@@ -121,22 +84,22 @@ public class NavigationModule extends ReactContextBaseJavaModule implements Life
|
|
|
121
84
|
|
|
122
85
|
@ReactMethod
|
|
123
86
|
public void startRegisterReactComponent() {
|
|
124
|
-
|
|
87
|
+
UiThreadUtil.runOnUiThread(bridgeManager::startRegisterReactModule);
|
|
125
88
|
}
|
|
126
89
|
|
|
127
90
|
@ReactMethod
|
|
128
91
|
public void endRegisterReactComponent() {
|
|
129
|
-
|
|
92
|
+
UiThreadUtil.runOnUiThread(bridgeManager::endRegisterReactModule);
|
|
130
93
|
}
|
|
131
94
|
|
|
132
95
|
@ReactMethod
|
|
133
96
|
public void registerReactComponent(final String appKey, final ReadableMap options) {
|
|
134
|
-
|
|
97
|
+
UiThreadUtil.runOnUiThread(() -> bridgeManager.registerReactModule(appKey, options));
|
|
135
98
|
}
|
|
136
99
|
|
|
137
100
|
@ReactMethod
|
|
138
101
|
public void signalFirstRenderComplete(final String sceneId) {
|
|
139
|
-
|
|
102
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
140
103
|
AwesomeFragment awesomeFragment = findFragmentBySceneId(sceneId);
|
|
141
104
|
if (awesomeFragment instanceof ReactFragment) {
|
|
142
105
|
ReactFragment fragment = (ReactFragment) awesomeFragment;
|
|
@@ -147,24 +110,24 @@ public class NavigationModule extends ReactContextBaseJavaModule implements Life
|
|
|
147
110
|
|
|
148
111
|
@ReactMethod
|
|
149
112
|
public void setRoot(final ReadableMap layout, final boolean sticky, final int tag) {
|
|
150
|
-
|
|
151
|
-
ReactContext reactContext =
|
|
152
|
-
if (
|
|
113
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
114
|
+
ReactContext reactContext = getReactApplicationContextIfActiveOrWarn();
|
|
115
|
+
if (reactContext == null) {
|
|
153
116
|
FLog.w(TAG, "ReactContext hasn't active CatalystInstance, skip action `setRoot`");
|
|
154
117
|
return;
|
|
155
118
|
}
|
|
156
|
-
|
|
119
|
+
|
|
157
120
|
bridgeManager.setViewHierarchyReady(false);
|
|
158
121
|
bridgeManager.setRootLayout(layout, sticky);
|
|
159
122
|
bridgeManager.setPendingLayout(layout, tag);
|
|
160
|
-
|
|
161
|
-
Activity activity = getCurrentActivity();
|
|
123
|
+
|
|
124
|
+
Activity activity = reactContext.getCurrentActivity();
|
|
162
125
|
if (activity instanceof ReactAppCompatActivity && bridgeManager.isReactModuleRegisterCompleted()) {
|
|
163
|
-
ReactAppCompatActivity
|
|
126
|
+
ReactAppCompatActivity reactActivity = (ReactAppCompatActivity) activity;
|
|
164
127
|
AwesomeFragment fragment = bridgeManager.createFragment(layout);
|
|
165
128
|
if (fragment != null) {
|
|
166
129
|
FLog.i(TAG, "Have active Activity and React module was registered, set root Fragment immediately.");
|
|
167
|
-
|
|
130
|
+
reactActivity.setActivityRootFragment(fragment, tag);
|
|
168
131
|
}
|
|
169
132
|
}
|
|
170
133
|
});
|
|
@@ -172,7 +135,7 @@ public class NavigationModule extends ReactContextBaseJavaModule implements Life
|
|
|
172
135
|
|
|
173
136
|
@ReactMethod
|
|
174
137
|
public void dispatch(final String sceneId, final String action, final ReadableMap extras, Promise promise) {
|
|
175
|
-
|
|
138
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
176
139
|
AwesomeFragment target = findFragmentBySceneId(sceneId);
|
|
177
140
|
if (target != null && target.isAdded()) {
|
|
178
141
|
bridgeManager.handleNavigation(target, action, extras, promise);
|
|
@@ -185,7 +148,7 @@ public class NavigationModule extends ReactContextBaseJavaModule implements Life
|
|
|
185
148
|
|
|
186
149
|
@ReactMethod
|
|
187
150
|
public void currentTab(final String sceneId, final Promise promise) {
|
|
188
|
-
|
|
151
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
189
152
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
190
153
|
if (fragment != null) {
|
|
191
154
|
TabBarFragment tabs = fragment.getTabBarFragment();
|
|
@@ -199,18 +162,18 @@ public class NavigationModule extends ReactContextBaseJavaModule implements Life
|
|
|
199
162
|
}
|
|
200
163
|
|
|
201
164
|
@ReactMethod
|
|
202
|
-
public void
|
|
203
|
-
|
|
165
|
+
public void isStackRoot(final String sceneId, final Promise promise) {
|
|
166
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
204
167
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
205
168
|
if (fragment != null) {
|
|
206
|
-
promise.resolve(fragment.
|
|
169
|
+
promise.resolve(fragment.isStackRoot());
|
|
207
170
|
}
|
|
208
171
|
});
|
|
209
172
|
}
|
|
210
173
|
|
|
211
174
|
@ReactMethod
|
|
212
175
|
public void setResult(final String sceneId, final int resultCode, final ReadableMap result) {
|
|
213
|
-
|
|
176
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
214
177
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
215
178
|
if (fragment != null) {
|
|
216
179
|
fragment.setResult(resultCode, Arguments.toBundle(result));
|
|
@@ -220,18 +183,17 @@ public class NavigationModule extends ReactContextBaseJavaModule implements Life
|
|
|
220
183
|
|
|
221
184
|
@ReactMethod
|
|
222
185
|
public void findSceneIdByModuleName(@NonNull String moduleName, Promise promise) {
|
|
223
|
-
|
|
186
|
+
final Runnable task = new Runnable() {
|
|
224
187
|
@Override
|
|
225
188
|
public void run() {
|
|
226
|
-
ReactContext reactContext =
|
|
227
|
-
if (
|
|
228
|
-
FLog.w(TAG, "ReactContext hasn't active CatalystInstance, skip action `currentRoute`");
|
|
189
|
+
ReactContext reactContext = getReactApplicationContextIfActiveOrWarn();
|
|
190
|
+
if (reactContext == null) {
|
|
229
191
|
return;
|
|
230
192
|
}
|
|
231
193
|
|
|
232
|
-
Activity activity = getCurrentActivity();
|
|
194
|
+
Activity activity = reactContext.getCurrentActivity();
|
|
233
195
|
if (!bridgeManager.isViewHierarchyReady() || !(activity instanceof ReactAppCompatActivity)) {
|
|
234
|
-
|
|
196
|
+
UiThreadUtil.runOnUiThread(this, 16);
|
|
235
197
|
return;
|
|
236
198
|
}
|
|
237
199
|
|
|
@@ -247,7 +209,7 @@ public class NavigationModule extends ReactContextBaseJavaModule implements Life
|
|
|
247
209
|
}
|
|
248
210
|
}
|
|
249
211
|
};
|
|
250
|
-
|
|
212
|
+
UiThreadUtil.runOnUiThread(task);
|
|
251
213
|
}
|
|
252
214
|
|
|
253
215
|
private String findSceneIdByModuleName(@NonNull String moduleName, AwesomeFragment fragment) {
|
|
@@ -278,18 +240,17 @@ public class NavigationModule extends ReactContextBaseJavaModule implements Life
|
|
|
278
240
|
Runnable task = new Runnable() {
|
|
279
241
|
@Override
|
|
280
242
|
public void run() {
|
|
281
|
-
ReactContext reactContext =
|
|
282
|
-
if (
|
|
283
|
-
FLog.w(TAG, "ReactContext hasn't active CatalystInstance, skip action `currentRoute`");
|
|
243
|
+
ReactContext reactContext = getReactApplicationContextIfActiveOrWarn();
|
|
244
|
+
if (reactContext == null) {
|
|
284
245
|
return;
|
|
285
246
|
}
|
|
286
247
|
|
|
287
|
-
Activity activity = getCurrentActivity();
|
|
248
|
+
Activity activity = reactContext.getCurrentActivity();
|
|
288
249
|
if (!bridgeManager.isViewHierarchyReady() || !(activity instanceof ReactAppCompatActivity)) {
|
|
289
|
-
|
|
250
|
+
UiThreadUtil.runOnUiThread(this, 16);
|
|
290
251
|
return;
|
|
291
252
|
}
|
|
292
|
-
|
|
253
|
+
|
|
293
254
|
ReactAppCompatActivity reactAppCompatActivity = (ReactAppCompatActivity) activity;
|
|
294
255
|
FragmentManager fragmentManager = reactAppCompatActivity.getSupportFragmentManager();
|
|
295
256
|
HybridFragment current = bridgeManager.primaryFragment(fragmentManager);
|
|
@@ -301,12 +262,12 @@ public class NavigationModule extends ReactContextBaseJavaModule implements Life
|
|
|
301
262
|
bundle.putString("mode", Navigator.Util.getMode(current));
|
|
302
263
|
promise.resolve(Arguments.fromBundle(bundle));
|
|
303
264
|
} else {
|
|
304
|
-
|
|
265
|
+
UiThreadUtil.runOnUiThread(this, 16);
|
|
305
266
|
}
|
|
306
267
|
}
|
|
307
268
|
};
|
|
308
269
|
|
|
309
|
-
|
|
270
|
+
UiThreadUtil.runOnUiThread(task);
|
|
310
271
|
}
|
|
311
272
|
|
|
312
273
|
@ReactMethod
|
|
@@ -314,16 +275,14 @@ public class NavigationModule extends ReactContextBaseJavaModule implements Life
|
|
|
314
275
|
Runnable task = new Runnable() {
|
|
315
276
|
@Override
|
|
316
277
|
public void run() {
|
|
317
|
-
ReactContext reactContext =
|
|
318
|
-
|
|
319
|
-
if (!reactContext.hasActiveCatalystInstance()) {
|
|
320
|
-
FLog.w(TAG, "ReactContext hasn't active CatalystInstance, skip action `routeGraph`");
|
|
278
|
+
ReactContext reactContext = getReactApplicationContextIfActiveOrWarn();
|
|
279
|
+
if (reactContext == null) {
|
|
321
280
|
return;
|
|
322
281
|
}
|
|
323
282
|
|
|
324
|
-
Activity activity = getCurrentActivity();
|
|
283
|
+
Activity activity = reactContext.getCurrentActivity();
|
|
325
284
|
if (!bridgeManager.isViewHierarchyReady() || !(activity instanceof ReactAppCompatActivity)) {
|
|
326
|
-
|
|
285
|
+
UiThreadUtil.runOnUiThread(this, 16);
|
|
327
286
|
return;
|
|
328
287
|
}
|
|
329
288
|
|
|
@@ -333,22 +292,26 @@ public class NavigationModule extends ReactContextBaseJavaModule implements Life
|
|
|
333
292
|
if (graph.size() > 0) {
|
|
334
293
|
promise.resolve(Arguments.fromList(graph));
|
|
335
294
|
} else {
|
|
336
|
-
|
|
295
|
+
UiThreadUtil.runOnUiThread(this, 16);
|
|
337
296
|
}
|
|
338
297
|
}
|
|
339
298
|
};
|
|
340
299
|
|
|
341
|
-
|
|
300
|
+
UiThreadUtil.runOnUiThread(task);
|
|
342
301
|
}
|
|
343
302
|
|
|
344
303
|
private AwesomeFragment findFragmentBySceneId(String sceneId) {
|
|
345
|
-
ReactContext reactContext =
|
|
346
|
-
if (
|
|
304
|
+
ReactContext reactContext = getReactApplicationContextIfActiveOrWarn();
|
|
305
|
+
if (reactContext == null) {
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (!bridgeManager.isViewHierarchyReady()) {
|
|
347
310
|
FLog.w(TAG, "View hierarchy is not ready now.");
|
|
348
311
|
return null;
|
|
349
312
|
}
|
|
350
313
|
|
|
351
|
-
Activity activity = getCurrentActivity();
|
|
314
|
+
Activity activity = reactContext.getCurrentActivity();
|
|
352
315
|
if (activity instanceof ReactAppCompatActivity) {
|
|
353
316
|
ReactAppCompatActivity reactAppCompatActivity = (ReactAppCompatActivity) activity;
|
|
354
317
|
FragmentManager fragmentManager = reactAppCompatActivity.getSupportFragmentManager();
|
|
@@ -84,6 +84,7 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
|
|
|
84
84
|
@Override
|
|
85
85
|
public void onReactModuleRegisterCompleted() {
|
|
86
86
|
FLog.i(TAG, "ReactAppCompatActivity#onReactModuleRegisterCompleted");
|
|
87
|
+
inflateStyle();
|
|
87
88
|
createMainComponent();
|
|
88
89
|
}
|
|
89
90
|
|
|
@@ -95,9 +96,9 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
|
|
|
95
96
|
ReactBridgeManager bridgeManager = getReactBridgeManager();
|
|
96
97
|
if (getMainComponentName() != null) {
|
|
97
98
|
AwesomeFragment fragment = bridgeManager.createFragment(getMainComponentName());
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
setActivityRootFragment(
|
|
99
|
+
ReactStackFragment stackFragment = new ReactStackFragment();
|
|
100
|
+
stackFragment.setRootFragment(fragment);
|
|
101
|
+
setActivityRootFragment(stackFragment);
|
|
101
102
|
} else if (bridgeManager.hasPendingLayout()) {
|
|
102
103
|
FLog.i(TAG, "Set root Fragment from pending layout when create main component");
|
|
103
104
|
setActivityRootFragment(bridgeManager);
|
|
@@ -130,11 +131,13 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
|
|
|
130
131
|
private void setActivityRootFragment(ReactBridgeManager bridgeManager) {
|
|
131
132
|
int pendingTag = bridgeManager.getPendingTag();
|
|
132
133
|
ReadableMap pendingLayout = bridgeManager.getPendingLayout();
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
if (pendingTag != 0 && pendingLayout != null) {
|
|
135
|
+
AwesomeFragment fragment = bridgeManager.createFragment(pendingLayout);
|
|
136
|
+
if (fragment != null) {
|
|
137
|
+
setActivityRootFragment(fragment, pendingTag);
|
|
138
|
+
} else {
|
|
139
|
+
FLog.e(TAG, "Could not create fragment from pending layout.");
|
|
140
|
+
}
|
|
138
141
|
}
|
|
139
142
|
}
|
|
140
143
|
|
|
@@ -179,6 +182,7 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
|
|
|
179
182
|
@Override
|
|
180
183
|
protected void onResume() {
|
|
181
184
|
super.onResume();
|
|
185
|
+
setActivityRootFragment(getReactBridgeManager());
|
|
182
186
|
activityDelegate.onResume();
|
|
183
187
|
}
|
|
184
188
|
|
|
@@ -66,8 +66,8 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
|
|
|
66
66
|
|
|
67
67
|
@Override
|
|
68
68
|
protected boolean extendedLayoutIncludesToolbar() {
|
|
69
|
-
int color =
|
|
70
|
-
float alpha =
|
|
69
|
+
int color = mStyle.getToolbarBackgroundColor();
|
|
70
|
+
float alpha = mStyle.getToolbarAlpha();
|
|
71
71
|
Garden garden = getGarden();
|
|
72
72
|
return Color.alpha(color) < 255
|
|
73
73
|
|| alpha < 1.0
|
|
@@ -134,30 +134,23 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
@Override
|
|
137
|
-
public void
|
|
138
|
-
super.
|
|
137
|
+
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
138
|
+
super.onViewCreated(view, savedInstanceState);
|
|
139
139
|
if (!FragmentHelper.isHidden(this)) {
|
|
140
140
|
initTitleViewIfNeeded();
|
|
141
141
|
}
|
|
142
142
|
getReactBridgeManager().addReactBridgeReloadListener(this);
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
|
|
145
145
|
@Override
|
|
146
146
|
public void onDestroyView() {
|
|
147
147
|
super.onDestroyView();
|
|
148
148
|
if (reactRootViewHolder != null) {
|
|
149
149
|
reactRootViewHolder.setVisibilityObserver(null);
|
|
150
150
|
}
|
|
151
|
-
// unmountReactView();
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
@Override
|
|
155
|
-
public void onDestroy() {
|
|
156
|
-
super.onDestroy();
|
|
157
|
-
// unmount react view delay for better transition
|
|
158
151
|
unmountReactView();
|
|
159
152
|
}
|
|
160
|
-
|
|
153
|
+
|
|
161
154
|
@Override
|
|
162
155
|
public void onReload() {
|
|
163
156
|
unmountReactView();
|
|
@@ -265,7 +258,7 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
|
|
|
265
258
|
} else {
|
|
266
259
|
layoutParams = new Toolbar.LayoutParams(-2, -2, Gravity.CENTER);
|
|
267
260
|
}
|
|
268
|
-
|
|
261
|
+
getToolbar().addView(reactTitleView, layoutParams);
|
|
269
262
|
reactTitleView.startReactApplication(getReactInstanceManager(), moduleName, getProps());
|
|
270
263
|
}
|
|
271
264
|
}
|
|
@@ -297,10 +290,10 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
|
|
|
297
290
|
|
|
298
291
|
@Override
|
|
299
292
|
protected int preferredNavigationBarColor() {
|
|
300
|
-
if (
|
|
301
|
-
return
|
|
293
|
+
if (mStyle.getNavigationBarColor() != Style.INVALID_COLOR) {
|
|
294
|
+
return mStyle.getNavigationBarColor();
|
|
302
295
|
} else {
|
|
303
|
-
return
|
|
296
|
+
return mStyle.getScreenBackgroundColor();
|
|
304
297
|
}
|
|
305
298
|
}
|
|
306
299
|
}
|
|
@@ -4,7 +4,7 @@ import androidx.annotation.NonNull;
|
|
|
4
4
|
import androidx.annotation.Nullable;
|
|
5
5
|
|
|
6
6
|
import com.navigation.androidx.AwesomeFragment;
|
|
7
|
-
import com.navigation.androidx.
|
|
7
|
+
import com.navigation.androidx.StackFragment;
|
|
8
8
|
import com.navigation.androidx.TabBarItem;
|
|
9
9
|
import com.navigation.androidx.TransitionAnimation;
|
|
10
10
|
|
|
@@ -12,7 +12,7 @@ import com.navigation.androidx.TransitionAnimation;
|
|
|
12
12
|
* Created by Listen on 2018/1/15.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
public class
|
|
15
|
+
public class ReactStackFragment extends StackFragment {
|
|
16
16
|
|
|
17
17
|
private final ReactBridgeManager bridgeManager = ReactBridgeManager.get();
|
|
18
18
|
|
|
@@ -199,7 +199,7 @@ public class ReactTabBarFragment extends TabBarFragment {
|
|
|
199
199
|
setOptions(mergeOptions(getOptions(), options));
|
|
200
200
|
|
|
201
201
|
if (tabBarColor != null) {
|
|
202
|
-
|
|
202
|
+
mStyle.setTabBarBackgroundColor(tabBarColor);
|
|
203
203
|
tabBar.setBarBackgroundColor(tabBarColor);
|
|
204
204
|
setNeedsNavigationBarAppearanceUpdate();
|
|
205
205
|
}
|
|
@@ -290,7 +290,7 @@ public class ReactTabBarFragment extends TabBarFragment {
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
public Style getStyle() {
|
|
293
|
-
return
|
|
293
|
+
return mStyle;
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
}
|
|
@@ -22,7 +22,7 @@ import androidx.annotation.Nullable;
|
|
|
22
22
|
import com.facebook.react.ReactInstanceManager;
|
|
23
23
|
import com.facebook.react.bridge.ReactContext;
|
|
24
24
|
import com.navigation.androidx.AwesomeFragment;
|
|
25
|
-
import com.navigation.androidx.
|
|
25
|
+
import com.navigation.androidx.StackFragment;
|
|
26
26
|
import com.navigation.androidx.Style;
|
|
27
27
|
import com.navigation.androidx.TabBarFragment;
|
|
28
28
|
import com.navigation.androidx.TabBarItem;
|
|
@@ -109,9 +109,9 @@ public class ReactTabBarProvider implements TabBarProvider, ReactBridgeManager.R
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
private Pair<String, String> extractSceneIdAndModuleName(AwesomeFragment awesomeFragment) {
|
|
112
|
-
if (awesomeFragment instanceof
|
|
113
|
-
|
|
114
|
-
awesomeFragment =
|
|
112
|
+
if (awesomeFragment instanceof StackFragment) {
|
|
113
|
+
StackFragment stackFragment = (StackFragment) awesomeFragment;
|
|
114
|
+
awesomeFragment = stackFragment.getRootFragment();
|
|
115
115
|
}
|
|
116
116
|
if (awesomeFragment instanceof HybridFragment) {
|
|
117
117
|
HybridFragment hybridFragment = (HybridFragment) awesomeFragment;
|
package/android/src/main/java/com/reactnative/hybridnavigation/navigator/NavigatorRegistry.java
CHANGED
|
@@ -5,7 +5,7 @@ import androidx.annotation.Nullable;
|
|
|
5
5
|
|
|
6
6
|
import com.navigation.androidx.AwesomeFragment;
|
|
7
7
|
import com.navigation.androidx.DrawerFragment;
|
|
8
|
-
import com.navigation.androidx.
|
|
8
|
+
import com.navigation.androidx.StackFragment;
|
|
9
9
|
import com.navigation.androidx.TabBarFragment;
|
|
10
10
|
import com.reactnative.hybridnavigation.HybridFragment;
|
|
11
11
|
|
|
@@ -63,7 +63,7 @@ public class NavigatorRegistry {
|
|
|
63
63
|
if (fragment instanceof HybridFragment) {
|
|
64
64
|
return "screen";
|
|
65
65
|
}
|
|
66
|
-
if (fragment instanceof
|
|
66
|
+
if (fragment instanceof StackFragment) {
|
|
67
67
|
return "stack";
|
|
68
68
|
}
|
|
69
69
|
if (fragment instanceof TabBarFragment) {
|
package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java
CHANGED
|
@@ -12,7 +12,7 @@ import com.navigation.androidx.AwesomeFragment;
|
|
|
12
12
|
import com.navigation.androidx.FragmentHelper;
|
|
13
13
|
import com.reactnative.hybridnavigation.HybridFragment;
|
|
14
14
|
import com.reactnative.hybridnavigation.ReactBridgeManager;
|
|
15
|
-
import com.reactnative.hybridnavigation.
|
|
15
|
+
import com.reactnative.hybridnavigation.ReactStackFragment;
|
|
16
16
|
|
|
17
17
|
import java.util.Arrays;
|
|
18
18
|
import java.util.List;
|
|
@@ -99,9 +99,9 @@ public class ScreenNavigator implements Navigator {
|
|
|
99
99
|
fragment = createFragmentWithExtras(extras);
|
|
100
100
|
if (fragment != null) {
|
|
101
101
|
int requestCode = extras.getInt("requestCode");
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
target.presentFragment(
|
|
102
|
+
ReactStackFragment stackFragment = new ReactStackFragment();
|
|
103
|
+
stackFragment.setRootFragment(fragment);
|
|
104
|
+
target.presentFragment(stackFragment, requestCode, () -> promise.resolve(true));
|
|
105
105
|
} else {
|
|
106
106
|
promise.resolve(false);
|
|
107
107
|
}
|
|
@@ -118,13 +118,13 @@ public class ScreenNavigator implements Navigator {
|
|
|
118
118
|
fragment = createFragmentWithExtras(extras);
|
|
119
119
|
if (fragment != null) {
|
|
120
120
|
int requestCode = extras.getInt("requestCode");
|
|
121
|
-
target.
|
|
121
|
+
target.showAsDialog(fragment, requestCode, () -> promise.resolve(true));
|
|
122
122
|
} else {
|
|
123
123
|
promise.resolve(false);
|
|
124
124
|
}
|
|
125
125
|
break;
|
|
126
126
|
case "hideModal":
|
|
127
|
-
target.
|
|
127
|
+
target.hideAsDialog(() -> promise.resolve(true));
|
|
128
128
|
break;
|
|
129
129
|
case "presentLayout":
|
|
130
130
|
ReadableMap layout = extras.getMap("layout");
|
|
@@ -141,7 +141,7 @@ public class ScreenNavigator implements Navigator {
|
|
|
141
141
|
fragment = getReactBridgeManager().createFragment(modalLayout);
|
|
142
142
|
if (fragment != null) {
|
|
143
143
|
int requestCode = extras.getInt("requestCode");
|
|
144
|
-
target.
|
|
144
|
+
target.showAsDialog(fragment, requestCode, () -> promise.resolve(true));
|
|
145
145
|
} else {
|
|
146
146
|
promise.resolve(false);
|
|
147
147
|
}
|
package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java
CHANGED
|
@@ -14,11 +14,11 @@ import com.facebook.react.bridge.ReadableArray;
|
|
|
14
14
|
import com.facebook.react.bridge.ReadableMap;
|
|
15
15
|
import com.navigation.androidx.AwesomeFragment;
|
|
16
16
|
import com.navigation.androidx.DrawerFragment;
|
|
17
|
-
import com.navigation.androidx.
|
|
17
|
+
import com.navigation.androidx.StackFragment;
|
|
18
18
|
import com.navigation.androidx.TabBarFragment;
|
|
19
19
|
import com.reactnative.hybridnavigation.HybridFragment;
|
|
20
20
|
import com.reactnative.hybridnavigation.ReactBridgeManager;
|
|
21
|
-
import com.reactnative.hybridnavigation.
|
|
21
|
+
import com.reactnative.hybridnavigation.ReactStackFragment;
|
|
22
22
|
|
|
23
23
|
import java.util.ArrayList;
|
|
24
24
|
import java.util.Arrays;
|
|
@@ -55,9 +55,9 @@ public class StackNavigator implements Navigator {
|
|
|
55
55
|
ReadableMap root = children.getMap(0);
|
|
56
56
|
AwesomeFragment rootFragment = getReactBridgeManager().createFragment(root);
|
|
57
57
|
if (rootFragment != null) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return
|
|
58
|
+
ReactStackFragment stackFragment = new ReactStackFragment();
|
|
59
|
+
stackFragment.setRootFragment(rootFragment);
|
|
60
|
+
return stackFragment;
|
|
61
61
|
} else {
|
|
62
62
|
throw new IllegalArgumentException("can't create stack component with " + layout);
|
|
63
63
|
}
|
|
@@ -68,8 +68,8 @@ public class StackNavigator implements Navigator {
|
|
|
68
68
|
@Nullable
|
|
69
69
|
@Override
|
|
70
70
|
public Bundle buildRouteGraph(@NonNull AwesomeFragment fragment) {
|
|
71
|
-
if (fragment instanceof
|
|
72
|
-
|
|
71
|
+
if (fragment instanceof StackFragment && fragment.isAdded()) {
|
|
72
|
+
StackFragment stack = (StackFragment) fragment;
|
|
73
73
|
ArrayList<Bundle> children = new ArrayList<>();
|
|
74
74
|
List<AwesomeFragment> fragments = stack.getChildFragments();
|
|
75
75
|
for (int i = 0; i < fragments.size(); i++) {
|
|
@@ -91,8 +91,8 @@ public class StackNavigator implements Navigator {
|
|
|
91
91
|
|
|
92
92
|
@Override
|
|
93
93
|
public HybridFragment primaryFragment(@NonNull AwesomeFragment fragment) {
|
|
94
|
-
if (fragment instanceof
|
|
95
|
-
|
|
94
|
+
if (fragment instanceof StackFragment && fragment.isAdded()) {
|
|
95
|
+
StackFragment stack = (StackFragment) fragment;
|
|
96
96
|
return getReactBridgeManager().primaryFragment(stack.getTopFragment());
|
|
97
97
|
}
|
|
98
98
|
return null;
|
|
@@ -100,8 +100,8 @@ public class StackNavigator implements Navigator {
|
|
|
100
100
|
|
|
101
101
|
@Override
|
|
102
102
|
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull Promise promise) {
|
|
103
|
-
|
|
104
|
-
if (
|
|
103
|
+
StackFragment stackFragment = getStackFragment(target);
|
|
104
|
+
if (stackFragment == null) {
|
|
105
105
|
promise.resolve(false);
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
@@ -112,18 +112,18 @@ public class StackNavigator implements Navigator {
|
|
|
112
112
|
case "push":
|
|
113
113
|
fragment = createFragmentWithExtras(extras);
|
|
114
114
|
if (fragment != null) {
|
|
115
|
-
|
|
115
|
+
stackFragment.pushFragment(fragment, true, () -> promise.resolve(true));
|
|
116
116
|
} else {
|
|
117
117
|
promise.resolve(false);
|
|
118
118
|
}
|
|
119
119
|
break;
|
|
120
120
|
case "pop":
|
|
121
|
-
|
|
121
|
+
stackFragment.popFragment(true, () -> promise.resolve(true));
|
|
122
122
|
break;
|
|
123
123
|
case "popTo":
|
|
124
124
|
String moduleName = extras.getString("moduleName");
|
|
125
125
|
boolean inclusive = extras.getBoolean("inclusive");
|
|
126
|
-
FragmentManager fragmentManager =
|
|
126
|
+
FragmentManager fragmentManager = stackFragment.getChildFragmentManager();
|
|
127
127
|
int count = fragmentManager.getBackStackEntryCount();
|
|
128
128
|
for (int i = count - 1; i > -1; i--) {
|
|
129
129
|
FragmentManager.BackStackEntry entry = fragmentManager.getBackStackEntryAt(i);
|
|
@@ -145,18 +145,18 @@ public class StackNavigator implements Navigator {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
if (fragment != null) {
|
|
148
|
-
|
|
148
|
+
stackFragment.popToFragment(fragment, true, () -> promise.resolve(true));
|
|
149
149
|
} else {
|
|
150
150
|
promise.resolve(false);
|
|
151
151
|
}
|
|
152
152
|
break;
|
|
153
153
|
case "popToRoot":
|
|
154
|
-
|
|
154
|
+
stackFragment.popToRootFragment(true, () -> promise.resolve(true));
|
|
155
155
|
break;
|
|
156
156
|
case "redirectTo":
|
|
157
157
|
fragment = createFragmentWithExtras(extras);
|
|
158
158
|
if (fragment != null) {
|
|
159
|
-
|
|
159
|
+
stackFragment.redirectToFragment(fragment, true, () -> promise.resolve(true), target);
|
|
160
160
|
} else {
|
|
161
161
|
promise.resolve(false);
|
|
162
162
|
}
|
|
@@ -165,7 +165,7 @@ public class StackNavigator implements Navigator {
|
|
|
165
165
|
ReadableMap layout = extras.getMap("layout");
|
|
166
166
|
fragment = getReactBridgeManager().createFragment(layout);
|
|
167
167
|
if (fragment != null) {
|
|
168
|
-
|
|
168
|
+
stackFragment.pushFragment(fragment, true, () -> promise.resolve(true));
|
|
169
169
|
} else {
|
|
170
170
|
promise.resolve(false);
|
|
171
171
|
}
|
|
@@ -192,19 +192,19 @@ public class StackNavigator implements Navigator {
|
|
|
192
192
|
return fragment;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
-
private
|
|
195
|
+
private StackFragment getStackFragment(AwesomeFragment fragment) {
|
|
196
196
|
if (fragment != null) {
|
|
197
|
-
|
|
198
|
-
if (
|
|
197
|
+
StackFragment stackFragment = fragment.getStackFragment();
|
|
198
|
+
if (stackFragment == null && fragment.getDrawerFragment() != null) {
|
|
199
199
|
DrawerFragment drawerFragment = fragment.getDrawerFragment();
|
|
200
200
|
TabBarFragment tabBarFragment = drawerFragment.getContentFragment().getTabBarFragment();
|
|
201
201
|
if (tabBarFragment != null) {
|
|
202
|
-
|
|
202
|
+
stackFragment = tabBarFragment.getSelectedFragment().getStackFragment();
|
|
203
203
|
} else {
|
|
204
|
-
|
|
204
|
+
stackFragment = drawerFragment.getContentFragment().getStackFragment();
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
-
return
|
|
207
|
+
return stackFragment;
|
|
208
208
|
}
|
|
209
209
|
return null;
|
|
210
210
|
}
|
|
@@ -9,7 +9,7 @@ import com.facebook.react.bridge.Promise;
|
|
|
9
9
|
import com.facebook.react.bridge.ReadableArray;
|
|
10
10
|
import com.facebook.react.bridge.ReadableMap;
|
|
11
11
|
import com.navigation.androidx.AwesomeFragment;
|
|
12
|
-
import com.navigation.androidx.
|
|
12
|
+
import com.navigation.androidx.StackFragment;
|
|
13
13
|
import com.navigation.androidx.TabBarFragment;
|
|
14
14
|
import com.reactnative.hybridnavigation.HybridFragment;
|
|
15
15
|
import com.reactnative.hybridnavigation.ReactBridgeManager;
|
|
@@ -152,9 +152,9 @@ public class TabNavigator implements Navigator {
|
|
|
152
152
|
|
|
153
153
|
boolean popToRoot = extras.hasKey("popToRoot") && extras.getBoolean("popToRoot");
|
|
154
154
|
if (popToRoot) {
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
|
|
155
|
+
StackFragment stackFragment = tabBarFragment.getSelectedFragment().getStackFragment();
|
|
156
|
+
if (stackFragment != null && stackFragment.getChildFragments().size() > 1) {
|
|
157
|
+
stackFragment.popToRootFragment(false);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -244,9 +244,9 @@ protected void onCreateMainComponent() {
|
|
|
244
244
|
// super.onCreateMainComponent();
|
|
245
245
|
ReactBridgeManager bridgeManager = getReactBridgeManager();
|
|
246
246
|
|
|
247
|
-
|
|
247
|
+
ReactStackFragment navigation = new ReactStackFragment();
|
|
248
248
|
navigation.setRootFragment(bridgeManager.createFragment("Navigation"));
|
|
249
|
-
|
|
249
|
+
ReactStackFragment options = new ReactStackFragment();
|
|
250
250
|
options.setRootFragment(bridgeManager.createFragment("Options"));
|
|
251
251
|
|
|
252
252
|
ReactTabBarFragment tabBarFragment = new ReactTabBarFragment();
|
|
@@ -262,7 +262,7 @@ protected void onCreateMainComponent() {
|
|
|
262
262
|
@Override
|
|
263
263
|
protected void onCreateMainComponent() {
|
|
264
264
|
AwesomeFragment home = getReactBridgeManager().createFragment("Home");
|
|
265
|
-
|
|
265
|
+
ReactStackFragment navigation = new ReactStackFragment();
|
|
266
266
|
navigation.setRootFragment(home);
|
|
267
267
|
|
|
268
268
|
setActivityRootFragment(navigation);
|
|
@@ -90,13 +90,13 @@ HBDViewController *vc = [[HBDReactBridgeManager get] controllerWithModuleName:@"
|
|
|
90
90
|
|
|
91
91
|
```java
|
|
92
92
|
// android
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
|
|
93
|
+
StackFragment stackFragment = getStackFragment();
|
|
94
|
+
if (stackFragment != null) {
|
|
95
|
+
stackFragment.pushFragment(fragment);
|
|
96
96
|
}
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
关于
|
|
99
|
+
关于 StackFragment 的更多细节,请看 [AndroidNavigation](https://github.com/listenzz/AndroidNavigation) 这个子项目。
|
|
100
100
|
|
|
101
101
|
```objc
|
|
102
102
|
// ios
|
|
@@ -123,7 +123,7 @@ RCT_EXPORT_METHOD(currentTab:(NSString *)sceneId resolver:(RCTPromiseResolveBloc
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
RCT_EXPORT_METHOD(
|
|
126
|
+
RCT_EXPORT_METHOD(isStackRoot:(NSString *)sceneId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
127
127
|
UIViewController *vc = [self.bridgeManager controllerForSceneId:sceneId];
|
|
128
128
|
UINavigationController *nav = vc.navigationController;
|
|
129
129
|
if (nav) {
|
package/lib/Navigator.js
CHANGED
|
@@ -233,7 +233,7 @@ export class Navigator {
|
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
235
|
isStackRoot() {
|
|
236
|
-
return NavigationModule.
|
|
236
|
+
return NavigationModule.isStackRoot(this.sceneId);
|
|
237
237
|
}
|
|
238
238
|
async present(moduleName, props = {}, options = {}) {
|
|
239
239
|
const requestCode = --tag;
|
package/package.json
CHANGED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
package com.reactnative.hybridnavigation;
|
|
2
|
-
|
|
3
|
-
import android.os.Handler;
|
|
4
|
-
import android.os.Looper;
|
|
5
|
-
|
|
6
|
-
import androidx.lifecycle.Lifecycle;
|
|
7
|
-
import androidx.lifecycle.LifecycleObserver;
|
|
8
|
-
import androidx.lifecycle.LifecycleOwner;
|
|
9
|
-
import androidx.lifecycle.OnLifecycleEvent;
|
|
10
|
-
|
|
11
|
-
import java.util.LinkedList;
|
|
12
|
-
import java.util.Queue;
|
|
13
|
-
|
|
14
|
-
public class UiTaskExecutor implements LifecycleObserver {
|
|
15
|
-
|
|
16
|
-
private final Queue<Runnable> tasks = new LinkedList<>();
|
|
17
|
-
|
|
18
|
-
private final LifecycleOwner lifecycleOwner;
|
|
19
|
-
private final Handler handler;
|
|
20
|
-
|
|
21
|
-
public UiTaskExecutor(LifecycleOwner lifecycleOwner, Handler handler) {
|
|
22
|
-
this.lifecycleOwner = lifecycleOwner;
|
|
23
|
-
this.handler = handler;
|
|
24
|
-
getLifecycle().addObserver(this);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public void submit(Runnable task) {
|
|
28
|
-
if (getLifecycle().getCurrentState() != Lifecycle.State.DESTROYED) {
|
|
29
|
-
handler.post(() -> {
|
|
30
|
-
tasks.add(task);
|
|
31
|
-
considerExecute();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
|
|
37
|
-
void onStateChange() {
|
|
38
|
-
if (getLifecycle().getCurrentState() == Lifecycle.State.DESTROYED) {
|
|
39
|
-
getLifecycle().removeObserver(this);
|
|
40
|
-
handler.removeCallbacks(executeTask);
|
|
41
|
-
} else {
|
|
42
|
-
handler.post(executeTask);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
private boolean executing;
|
|
47
|
-
|
|
48
|
-
void considerExecute() {
|
|
49
|
-
if (isAtLeastStarted() && !executing) {
|
|
50
|
-
assertMainThread();
|
|
51
|
-
executing = true;
|
|
52
|
-
Runnable runnable = tasks.poll();
|
|
53
|
-
while (runnable != null) {
|
|
54
|
-
runnable.run();
|
|
55
|
-
runnable = tasks.poll();
|
|
56
|
-
}
|
|
57
|
-
executing = false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private final Runnable executeTask = this::considerExecute;
|
|
62
|
-
|
|
63
|
-
boolean isAtLeastStarted() {
|
|
64
|
-
return getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private Lifecycle getLifecycle() {
|
|
68
|
-
return lifecycleOwner.getLifecycle();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private void assertMainThread() {
|
|
72
|
-
if (!isMainThread()) {
|
|
73
|
-
throw new IllegalStateException("You should perform the task at main thread.");
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
static boolean isMainThread() {
|
|
78
|
-
return Looper.getMainLooper().getThread() == Thread.currentThread();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
}
|