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
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
|
-
## 2.
|
|
1
|
+
## 2.7.0(2021-12-28)
|
|
2
|
+
|
|
3
|
+
### Android specific
|
|
4
|
+
|
|
5
|
+
- 支持 appcompat 1.3
|
|
6
|
+
|
|
7
|
+
## 2.6.0 (2021-11-29)
|
|
8
|
+
|
|
9
|
+
- 支持动态设置 `screenBackgroundColor`
|
|
10
|
+
|
|
11
|
+
## 2.5.1 (2021-11-09)
|
|
12
|
+
|
|
13
|
+
### Android specific
|
|
14
|
+
|
|
15
|
+
- 修复导致键盘 `adjustResize` 模式无效的问题
|
|
16
|
+
|
|
17
|
+
## 2.5.0 (2021-11-04)
|
|
18
|
+
|
|
19
|
+
- 添加 `Garden#setTabItem`,可以动态修改 tab 图标,标题,徽章。
|
|
20
|
+
|
|
21
|
+
- 弃用 `Garden#setTabIcon`
|
|
22
|
+
|
|
23
|
+
- 弃用 `Garden#setTabBadge`
|
|
24
|
+
|
|
25
|
+
## 2.4.3 (2021-11-03)
|
|
2
26
|
|
|
3
27
|
### iOS specific
|
|
4
28
|
|
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
|
}
|
|
@@ -12,8 +12,7 @@ public class Constants {
|
|
|
12
12
|
public static final String ARG_ACTION = "action";
|
|
13
13
|
public static final String ARG_OPTIONS = "options";
|
|
14
14
|
|
|
15
|
-
public static final String
|
|
16
|
-
public static final String ACTION_SET_TAB_BADGE = "SET_TAB_BADGE";
|
|
15
|
+
public static final String ACTION_SET_TAB_ITEM = "SET_TAB_ITEM";
|
|
17
16
|
public static final String ACTION_UPDATE_TAB_BAR = "UPDATE_TAB_BAR";
|
|
18
17
|
|
|
19
18
|
}
|
|
@@ -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;
|
|
@@ -1,27 +1,29 @@
|
|
|
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.Parameters.toBundle;
|
|
8
|
+
import static com.reactnative.hybridnavigation.Parameters.toList;
|
|
9
|
+
|
|
3
10
|
import android.app.Activity;
|
|
4
|
-
import android.os.Build;
|
|
5
11
|
import android.os.Bundle;
|
|
6
|
-
import android.os.Handler;
|
|
7
12
|
|
|
8
13
|
import androidx.annotation.NonNull;
|
|
9
14
|
import androidx.annotation.Nullable;
|
|
10
15
|
import androidx.drawerlayout.widget.DrawerLayout;
|
|
11
16
|
import androidx.fragment.app.FragmentManager;
|
|
12
|
-
import androidx.lifecycle.Lifecycle;
|
|
13
|
-
import androidx.lifecycle.LifecycleOwner;
|
|
14
|
-
import androidx.lifecycle.LifecycleRegistry;
|
|
15
17
|
|
|
16
18
|
import com.facebook.common.logging.FLog;
|
|
17
19
|
import com.facebook.react.bridge.JavaOnlyMap;
|
|
18
|
-
import com.facebook.react.bridge.LifecycleEventListener;
|
|
19
20
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
20
21
|
import com.facebook.react.bridge.ReactContext;
|
|
21
22
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
22
23
|
import com.facebook.react.bridge.ReactMethod;
|
|
23
24
|
import com.facebook.react.bridge.ReadableArray;
|
|
24
25
|
import com.facebook.react.bridge.ReadableMap;
|
|
26
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
25
27
|
import com.facebook.react.bridge.WritableMap;
|
|
26
28
|
import com.navigation.androidx.AwesomeFragment;
|
|
27
29
|
import com.navigation.androidx.DrawerFragment;
|
|
@@ -31,64 +33,19 @@ import com.navigation.androidx.TabBarFragment;
|
|
|
31
33
|
import java.util.HashMap;
|
|
32
34
|
import java.util.Map;
|
|
33
35
|
|
|
34
|
-
import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_BADGE;
|
|
35
|
-
import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_ICON;
|
|
36
|
-
import static com.reactnative.hybridnavigation.Constants.ACTION_UPDATE_TAB_BAR;
|
|
37
|
-
import static com.reactnative.hybridnavigation.Constants.ARG_ACTION;
|
|
38
|
-
import static com.reactnative.hybridnavigation.Constants.ARG_OPTIONS;
|
|
39
|
-
import static com.reactnative.hybridnavigation.Parameters.toBundle;
|
|
40
|
-
import static com.reactnative.hybridnavigation.Parameters.toList;
|
|
41
|
-
|
|
42
36
|
/**
|
|
43
37
|
* Created by Listen on 2017/11/22.
|
|
44
38
|
*/
|
|
45
|
-
public class GardenModule extends ReactContextBaseJavaModule
|
|
39
|
+
public class GardenModule extends ReactContextBaseJavaModule {
|
|
46
40
|
|
|
47
41
|
private static final String TAG = "Navigator";
|
|
48
|
-
|
|
49
|
-
static final Handler sHandler = NavigationModule.sHandler;
|
|
50
|
-
private final UiTaskExecutor uiTaskExecutor;
|
|
51
|
-
private final LifecycleRegistry lifecycleRegistry;
|
|
52
|
-
private final ReactApplicationContext reactContext;
|
|
53
42
|
private final ReactBridgeManager bridgeManager;
|
|
54
43
|
|
|
55
44
|
public GardenModule(ReactApplicationContext reactContext, ReactBridgeManager bridgeManager) {
|
|
56
45
|
super(reactContext);
|
|
57
46
|
this.bridgeManager = bridgeManager;
|
|
58
|
-
this.reactContext = reactContext;
|
|
59
|
-
reactContext.addLifecycleEventListener(this);
|
|
60
|
-
lifecycleRegistry = new LifecycleRegistry(this);
|
|
61
|
-
lifecycleRegistry.setCurrentState(Lifecycle.State.CREATED);
|
|
62
|
-
uiTaskExecutor = new UiTaskExecutor(this, sHandler);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@Override
|
|
66
|
-
public void onHostResume() {
|
|
67
|
-
lifecycleRegistry.setCurrentState(Lifecycle.State.STARTED);
|
|
68
47
|
}
|
|
69
|
-
|
|
70
|
-
@Override
|
|
71
|
-
public void onHostPause() {
|
|
72
|
-
lifecycleRegistry.setCurrentState(Lifecycle.State.CREATED);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@Override
|
|
76
|
-
public void onHostDestroy() {
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@NonNull
|
|
80
|
-
@Override
|
|
81
|
-
public Lifecycle getLifecycle() {
|
|
82
|
-
return lifecycleRegistry;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
@Override
|
|
86
|
-
public void onCatalystInstanceDestroy() {
|
|
87
|
-
super.onCatalystInstanceDestroy();
|
|
88
|
-
reactContext.removeLifecycleEventListener(this);
|
|
89
|
-
lifecycleRegistry.setCurrentState(Lifecycle.State.DESTROYED);
|
|
90
|
-
}
|
|
91
|
-
|
|
48
|
+
|
|
92
49
|
@NonNull
|
|
93
50
|
@Override
|
|
94
51
|
public String getName() {
|
|
@@ -99,19 +56,19 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
|
|
|
99
56
|
@Override
|
|
100
57
|
public Map<String, Object> getConstants() {
|
|
101
58
|
final Map<String, Object> constants = new HashMap<>();
|
|
102
|
-
constants.put("TOOLBAR_HEIGHT",
|
|
59
|
+
constants.put("TOOLBAR_HEIGHT", 56);
|
|
103
60
|
return constants;
|
|
104
61
|
}
|
|
105
62
|
|
|
106
63
|
@ReactMethod
|
|
107
64
|
public void setStyle(final ReadableMap style) {
|
|
108
|
-
|
|
65
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
109
66
|
FLog.i(TAG, "GardenModule#setStyle");
|
|
110
67
|
Garden.createGlobalStyle(toBundle(style));
|
|
111
|
-
|
|
112
|
-
ReactContext context =
|
|
113
|
-
if (context
|
|
114
|
-
ReactAppCompatActivity activity = (ReactAppCompatActivity) getCurrentActivity();
|
|
68
|
+
|
|
69
|
+
ReactContext context = getReactApplicationContextIfActiveOrWarn();
|
|
70
|
+
if (context != null) {
|
|
71
|
+
ReactAppCompatActivity activity = (ReactAppCompatActivity) context.getCurrentActivity();
|
|
115
72
|
if (activity != null) {
|
|
116
73
|
activity.inflateStyle();
|
|
117
74
|
}
|
|
@@ -147,7 +104,7 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
|
|
|
147
104
|
@ReactMethod
|
|
148
105
|
public void updateOptions(final String sceneId, final ReadableMap readableMap) {
|
|
149
106
|
FLog.i(TAG, "update options:" + readableMap);
|
|
150
|
-
|
|
107
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
151
108
|
HybridFragment fragment = findHybridFragmentBySceneId(sceneId);
|
|
152
109
|
if (fragment != null && fragment.isAdded()) {
|
|
153
110
|
fragment.getGarden().updateOptions(readableMap);
|
|
@@ -178,7 +135,7 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
|
|
|
178
135
|
@ReactMethod
|
|
179
136
|
public void updateTabBar(final String sceneId, final ReadableMap readableMap) {
|
|
180
137
|
FLog.i(TAG, "updateTabBar:" + readableMap);
|
|
181
|
-
|
|
138
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
182
139
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
183
140
|
if (fragment != null && fragment.getView() != null) {
|
|
184
141
|
TabBarFragment tabBarFragment = fragment.getTabBarFragment();
|
|
@@ -193,30 +150,15 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
|
|
|
193
150
|
}
|
|
194
151
|
|
|
195
152
|
@ReactMethod
|
|
196
|
-
public void
|
|
197
|
-
|
|
153
|
+
public void setTabItem(final String sceneId, @NonNull final ReadableArray options) {
|
|
154
|
+
FLog.i(TAG, "setTabItem:" + options);
|
|
155
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
198
156
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
199
157
|
if (fragment != null && fragment.getView() != null) {
|
|
200
158
|
TabBarFragment tabBarFragment = fragment.getTabBarFragment();
|
|
201
159
|
if (tabBarFragment != null) {
|
|
202
160
|
Bundle bundle = new Bundle();
|
|
203
|
-
bundle.putString(ARG_ACTION,
|
|
204
|
-
bundle.putSerializable(ARG_OPTIONS, toList(options));
|
|
205
|
-
tabBarFragment.updateTabBar(bundle);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
@ReactMethod
|
|
212
|
-
public void setTabBadge(@NonNull final String sceneId, @NonNull final ReadableArray options) {
|
|
213
|
-
uiTaskExecutor.submit(() -> {
|
|
214
|
-
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
215
|
-
if (fragment != null) {
|
|
216
|
-
TabBarFragment tabBarFragment = fragment.getTabBarFragment();
|
|
217
|
-
if (tabBarFragment != null) {
|
|
218
|
-
Bundle bundle = new Bundle();
|
|
219
|
-
bundle.putString(ARG_ACTION, ACTION_SET_TAB_BADGE);
|
|
161
|
+
bundle.putString(ARG_ACTION, ACTION_SET_TAB_ITEM);
|
|
220
162
|
bundle.putSerializable(ARG_OPTIONS, toList(options));
|
|
221
163
|
tabBarFragment.updateTabBar(bundle);
|
|
222
164
|
}
|
|
@@ -226,7 +168,7 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
|
|
|
226
168
|
|
|
227
169
|
@ReactMethod
|
|
228
170
|
public void setMenuInteractive(final String sceneId, final boolean enabled) {
|
|
229
|
-
|
|
171
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
230
172
|
AwesomeFragment awesomeFragment = findFragmentBySceneId(sceneId);
|
|
231
173
|
if (awesomeFragment != null) {
|
|
232
174
|
DrawerFragment drawerFragment = awesomeFragment.getDrawerFragment();
|
|
@@ -238,13 +180,16 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
|
|
|
238
180
|
}
|
|
239
181
|
|
|
240
182
|
private AwesomeFragment findFragmentBySceneId(String sceneId) {
|
|
241
|
-
ReactContext reactContext =
|
|
242
|
-
if (
|
|
183
|
+
ReactContext reactContext = getReactApplicationContextIfActiveOrWarn();
|
|
184
|
+
if (reactContext == null) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
if (!bridgeManager.isViewHierarchyReady()) {
|
|
243
188
|
FLog.w(TAG, "View hierarchy is not ready now.");
|
|
244
189
|
return null;
|
|
245
190
|
}
|
|
246
191
|
|
|
247
|
-
Activity activity = getCurrentActivity();
|
|
192
|
+
Activity activity = reactContext.getCurrentActivity();
|
|
248
193
|
if (activity instanceof ReactAppCompatActivity) {
|
|
249
194
|
ReactAppCompatActivity reactActivity = (ReactAppCompatActivity) activity;
|
|
250
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;
|