hybrid-navigation 2.4.3 → 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 +25 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/Constants.java +1 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +13 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +29 -84
- 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/ReactTabBar.java +0 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +49 -51
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +39 -59
- 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/docs/style.md +48 -63
- package/ios/HybridNavigation/Bridge/HBDGardenModule.m +3 -13
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +1 -1
- package/ios/HybridNavigation/ViewController/HBDTabBarController.h +1 -3
- package/ios/HybridNavigation/ViewController/HBDTabBarController.m +34 -33
- package/ios/HybridNavigation/ViewController/HBDViewController.m +5 -0
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +38 -12
- package/lib/Garden.d.ts +14 -0
- package/lib/Garden.js +33 -2
- 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
|
@@ -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
|
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
package com.reactnative.hybridnavigation;
|
|
2
2
|
|
|
3
|
-
import android.annotation.TargetApi;
|
|
4
3
|
import android.content.Context;
|
|
5
4
|
import android.graphics.Color;
|
|
6
5
|
import android.graphics.drawable.ColorDrawable;
|
|
7
6
|
import android.graphics.drawable.Drawable;
|
|
8
|
-
import android.os.Build;
|
|
9
7
|
import android.util.AttributeSet;
|
|
10
8
|
import android.view.LayoutInflater;
|
|
11
9
|
import android.view.View;
|
|
@@ -46,7 +44,6 @@ public class ReactTabBar extends FrameLayout {
|
|
|
46
44
|
init();
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
50
47
|
public ReactTabBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
|
51
48
|
super(context, attrs, defStyleAttr, defStyleRes);
|
|
52
49
|
init();
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
package com.reactnative.hybridnavigation;
|
|
2
2
|
|
|
3
|
+
import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_ITEM;
|
|
4
|
+
import static com.reactnative.hybridnavigation.Constants.ACTION_UPDATE_TAB_BAR;
|
|
5
|
+
import static com.reactnative.hybridnavigation.Constants.ARG_ACTION;
|
|
6
|
+
import static com.reactnative.hybridnavigation.Constants.ARG_OPTIONS;
|
|
7
|
+
import static com.reactnative.hybridnavigation.HBDEventEmitter.EVENT_NAVIGATION;
|
|
8
|
+
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_INDEX;
|
|
9
|
+
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_ON;
|
|
10
|
+
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_REQUEST_CODE;
|
|
11
|
+
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_CODE;
|
|
12
|
+
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_DATA;
|
|
13
|
+
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_SCENE_ID;
|
|
14
|
+
import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_RESULT;
|
|
15
|
+
import static com.reactnative.hybridnavigation.Parameters.mergeOptions;
|
|
16
|
+
|
|
3
17
|
import android.os.Bundle;
|
|
4
18
|
|
|
5
19
|
import androidx.annotation.NonNull;
|
|
@@ -12,27 +26,13 @@ import com.navigation.androidx.FragmentHelper;
|
|
|
12
26
|
import com.navigation.androidx.Style;
|
|
13
27
|
import com.navigation.androidx.TabBar;
|
|
14
28
|
import com.navigation.androidx.TabBarFragment;
|
|
29
|
+
import com.navigation.androidx.TabBarItem;
|
|
15
30
|
import com.navigation.androidx.TabBarProvider;
|
|
16
31
|
import com.navigation.androidx.TransitionAnimation;
|
|
17
32
|
|
|
18
33
|
import java.util.ArrayList;
|
|
19
34
|
import java.util.List;
|
|
20
35
|
|
|
21
|
-
import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_BADGE;
|
|
22
|
-
import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_ICON;
|
|
23
|
-
import static com.reactnative.hybridnavigation.Constants.ACTION_UPDATE_TAB_BAR;
|
|
24
|
-
import static com.reactnative.hybridnavigation.Constants.ARG_ACTION;
|
|
25
|
-
import static com.reactnative.hybridnavigation.Constants.ARG_OPTIONS;
|
|
26
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.EVENT_NAVIGATION;
|
|
27
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_INDEX;
|
|
28
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_ON;
|
|
29
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_REQUEST_CODE;
|
|
30
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_CODE;
|
|
31
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_DATA;
|
|
32
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_SCENE_ID;
|
|
33
|
-
import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_RESULT;
|
|
34
|
-
import static com.reactnative.hybridnavigation.Parameters.mergeOptions;
|
|
35
|
-
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Created by listen on 2018/1/15.
|
|
@@ -126,21 +126,17 @@ public class ReactTabBarFragment extends TabBarFragment {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
switch (action) {
|
|
129
|
-
case
|
|
130
|
-
|
|
131
|
-
break;
|
|
132
|
-
case ACTION_SET_TAB_ICON:
|
|
133
|
-
setTabIcon(options.getParcelableArrayList(ARG_OPTIONS));
|
|
129
|
+
case ACTION_SET_TAB_ITEM:
|
|
130
|
+
setTabItem(options.getParcelableArrayList(ARG_OPTIONS));
|
|
134
131
|
break;
|
|
135
132
|
case ACTION_UPDATE_TAB_BAR:
|
|
136
133
|
updateTabBarAppearance(options.getBundle(ARG_OPTIONS));
|
|
137
134
|
break;
|
|
138
135
|
}
|
|
139
|
-
|
|
140
136
|
}
|
|
141
137
|
}
|
|
142
138
|
|
|
143
|
-
private void
|
|
139
|
+
private void setTabItem(@Nullable ArrayList<Bundle> options) {
|
|
144
140
|
if (options == null) {
|
|
145
141
|
return;
|
|
146
142
|
}
|
|
@@ -149,42 +145,44 @@ public class ReactTabBarFragment extends TabBarFragment {
|
|
|
149
145
|
if (tabBar == null) {
|
|
150
146
|
return;
|
|
151
147
|
}
|
|
148
|
+
|
|
152
149
|
for (Bundle option : options) {
|
|
153
150
|
int index = (int) option.getDouble("index");
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
tabBar.hideBadgeAtIndex(index);
|
|
158
|
-
tabBar.showTextBadgeAtIndex(index, text);
|
|
159
|
-
if (dot) {
|
|
160
|
-
tabBar.showDotBadgeAtIndex(index);
|
|
151
|
+
TabBarItem tabBarItem = tabBar.getTabBarItem(index);
|
|
152
|
+
if (tabBarItem == null) {
|
|
153
|
+
continue;
|
|
161
154
|
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
155
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
156
|
+
// title
|
|
157
|
+
String title = option.getString("title");
|
|
158
|
+
if (title != null) {
|
|
159
|
+
tabBarItem.title = title;
|
|
160
|
+
}
|
|
170
161
|
|
|
171
|
-
|
|
172
|
-
int index = (int) option.getDouble("index");
|
|
162
|
+
// icon
|
|
173
163
|
Bundle icon = option.getBundle("icon");
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
tabBar.updateTabIcon(index, iconUri, unselectedIcon.getString("uri"));
|
|
180
|
-
} else {
|
|
181
|
-
tabBar.updateTabIcon(index, iconUri, null);
|
|
182
|
-
}
|
|
164
|
+
if (icon != null) {
|
|
165
|
+
Bundle unselected = icon.getBundle("unselected");
|
|
166
|
+
Bundle selected = icon.getBundle("selected");
|
|
167
|
+
if (unselected != null) {
|
|
168
|
+
tabBarItem.unselectedIconUri = unselected.getString("uri");
|
|
183
169
|
}
|
|
170
|
+
tabBarItem.iconUri = selected.getString("uri");
|
|
184
171
|
}
|
|
185
|
-
}
|
|
186
172
|
|
|
187
|
-
|
|
173
|
+
// badge
|
|
174
|
+
Bundle badge = option.getBundle("badge");
|
|
175
|
+
if (badge != null) {
|
|
176
|
+
boolean hidden = badge.getBoolean("hidden", true);
|
|
177
|
+
String text = !hidden ? badge.getString("text", "") : "";
|
|
178
|
+
boolean dot = !hidden && badge.getBoolean("dot", false);
|
|
179
|
+
|
|
180
|
+
tabBarItem.badgeText = text;
|
|
181
|
+
tabBarItem.showDotBadge = dot;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
tabBar.renderTabView(index);
|
|
185
|
+
}
|
|
188
186
|
}
|
|
189
187
|
|
|
190
188
|
private void updateTabBarAppearance(@Nullable Bundle options) {
|
|
@@ -201,7 +199,7 @@ public class ReactTabBarFragment extends TabBarFragment {
|
|
|
201
199
|
setOptions(mergeOptions(getOptions(), options));
|
|
202
200
|
|
|
203
201
|
if (tabBarColor != null) {
|
|
204
|
-
|
|
202
|
+
mStyle.setTabBarBackgroundColor(tabBarColor);
|
|
205
203
|
tabBar.setBarBackgroundColor(tabBarColor);
|
|
206
204
|
setNeedsNavigationBarAppearanceUpdate();
|
|
207
205
|
}
|
|
@@ -292,7 +290,7 @@ public class ReactTabBarFragment extends TabBarFragment {
|
|
|
292
290
|
}
|
|
293
291
|
|
|
294
292
|
public Style getStyle() {
|
|
295
|
-
return
|
|
293
|
+
return mStyle;
|
|
296
294
|
}
|
|
297
295
|
|
|
298
296
|
}
|