hybrid-navigation 2.5.0 → 2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +13 -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/docs/qa.md +17 -0
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +1 -1
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +5 -4
- package/ios/HybridNavigation/ViewController/HBDViewController.m +5 -0
- package/lib/Navigator.js +1 -1
- package/lib/typing.d.ts +1 -0
- package/package.json +7 -7
- package/android/src/main/java/com/reactnative/hybridnavigation/UiTaskExecutor.java +0 -81
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## 2.7.1 (2022-01-05)
|
|
2
|
+
|
|
3
|
+
### iOS specific
|
|
4
|
+
|
|
5
|
+
- 修复 iOS 15.2 下,自定义返回图标无效的问题
|
|
6
|
+
|
|
7
|
+
## 2.7.0(2021-12-28)
|
|
8
|
+
|
|
9
|
+
### Android specific
|
|
10
|
+
|
|
11
|
+
- 支持 appcompat 1.3
|
|
12
|
+
|
|
13
|
+
## 2.6.0 (2021-11-29)
|
|
14
|
+
|
|
15
|
+
- 支持动态设置 `screenBackgroundColor`
|
|
16
|
+
|
|
17
|
+
## 2.5.1 (2021-11-09)
|
|
18
|
+
|
|
19
|
+
### Android specific
|
|
20
|
+
|
|
21
|
+
- 修复导致键盘 `adjustResize` 模式无效的问题
|
|
22
|
+
|
|
1
23
|
## 2.5.0 (2021-11-04)
|
|
2
24
|
|
|
3
25
|
- 添加 `Garden#setTabItem`,可以动态修改 tab 图标,标题,徽章。
|
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
|
}
|
|
@@ -2,6 +2,7 @@ package com.reactnative.hybridnavigation;
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.graphics.Color;
|
|
5
|
+
import android.graphics.drawable.ColorDrawable;
|
|
5
6
|
import android.os.Bundle;
|
|
6
7
|
import android.text.TextUtils;
|
|
7
8
|
import android.view.View;
|
|
@@ -90,7 +91,7 @@ public class Garden {
|
|
|
90
91
|
return;
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
AwesomeToolbar toolbar = fragment.
|
|
94
|
+
AwesomeToolbar toolbar = fragment.getToolbar();
|
|
94
95
|
if (toolbar == null) {
|
|
95
96
|
return;
|
|
96
97
|
}
|
|
@@ -107,6 +108,7 @@ public class Garden {
|
|
|
107
108
|
} else if (rightBarButtonItem != null) {
|
|
108
109
|
setRightBarButtonItem(rightBarButtonItem);
|
|
109
110
|
}
|
|
111
|
+
|
|
110
112
|
Bundle leftBarButtonItem = options.getBundle("leftBarButtonItem");
|
|
111
113
|
ArrayList<Bundle> leftBarButtonItems = options.getParcelableArrayList("leftBarButtonItems");
|
|
112
114
|
if (leftBarButtonItems != null) {
|
|
@@ -265,6 +267,15 @@ public class Garden {
|
|
|
265
267
|
|
|
266
268
|
applyOptions(patches);
|
|
267
269
|
|
|
270
|
+
if (readableMap.hasKey("screenBackgroundColor")) {
|
|
271
|
+
String color = readableMap.getString("screenBackgroundColor");
|
|
272
|
+
style.setScreenBackgroundColor(Color.parseColor(color));
|
|
273
|
+
View root = fragment.getView();
|
|
274
|
+
if (root != null) {
|
|
275
|
+
root.setBackground(new ColorDrawable(Color.parseColor(color)));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
268
279
|
if (shouldUpdateStatusBar(readableMap)) {
|
|
269
280
|
fragment.setNeedsStatusBarAppearanceUpdate();
|
|
270
281
|
}
|
|
@@ -338,7 +349,7 @@ public class Garden {
|
|
|
338
349
|
}
|
|
339
350
|
|
|
340
351
|
private boolean shouldUpdateNavigationBar(@NonNull ReadableMap readableMap) {
|
|
341
|
-
String[] keys = new String[]{"navigationBarColorAndroid", "navigationBarHiddenAndroid"};
|
|
352
|
+
String[] keys = new String[]{"navigationBarColorAndroid", "navigationBarHiddenAndroid", "screenBackgroundColor"};
|
|
342
353
|
for (String key : keys) {
|
|
343
354
|
if (readableMap.hasKey(key)) {
|
|
344
355
|
return true;
|
|
@@ -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
|
|