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
|
@@ -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
|
package/docs/qa.md
CHANGED
|
@@ -36,3 +36,20 @@ module.exports = {
|
|
|
36
36
|
},
|
|
37
37
|
}
|
|
38
38
|
```
|
|
39
|
+
|
|
40
|
+
## 如何拦截 Android 物理返回键
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
useVisibleEffect(
|
|
44
|
+
useCallback(() => {
|
|
45
|
+
const handleBackPress = () => {
|
|
46
|
+
console.log('---------------')
|
|
47
|
+
// true 表示拦截,false 表示不拦截
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
BackHandler.addEventListener('hardwareBackPress', handleBackPress)
|
|
52
|
+
return () => BackHandler.removeEventListener('hardwareBackPress', handleBackPress)
|
|
53
|
+
}, []),
|
|
54
|
+
)
|
|
55
|
+
```
|
|
@@ -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) {
|
|
@@ -331,7 +331,7 @@ void printViewHierarchy(UIView *view, NSString *prefix) {
|
|
|
331
331
|
[self.nav showFakeBarFrom:from to:to];
|
|
332
332
|
} else {
|
|
333
333
|
[self.nav updateNavigationBarForViewController:viewController];
|
|
334
|
-
if (@available(iOS
|
|
334
|
+
if (@available(iOS 13.0, *)) {
|
|
335
335
|
if (to == viewController) {
|
|
336
336
|
self.nav.navigationBar.scrollEdgeAppearance.backgroundColor = viewController.hbd_barTintColor;
|
|
337
337
|
self.nav.navigationBar.standardAppearance.backgroundColor = viewController.hbd_barTintColor;
|
|
@@ -341,7 +341,7 @@ void printViewHierarchy(UIView *view, NSString *prefix) {
|
|
|
341
341
|
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
342
342
|
self.nav.poppingViewController = nil;
|
|
343
343
|
|
|
344
|
-
if (@available(iOS
|
|
344
|
+
if (@available(iOS 13.0, *)) {
|
|
345
345
|
self.nav.navigationBar.scrollEdgeAppearance.backgroundColor = UIColor.clearColor;
|
|
346
346
|
self.nav.navigationBar.standardAppearance.backgroundColor = UIColor.clearColor;
|
|
347
347
|
}
|
|
@@ -470,11 +470,12 @@ void printViewHierarchy(UIView *view, NSString *prefix) {
|
|
|
470
470
|
[self.navigationBar setTranslucent:YES];
|
|
471
471
|
[self.navigationBar setShadowImage:[UINavigationBar appearance].shadowImage];
|
|
472
472
|
|
|
473
|
-
if (@available(iOS
|
|
473
|
+
if (@available(iOS 13.0, *)) {
|
|
474
474
|
UINavigationBarAppearance *scrollEdgeAppearance = [[UINavigationBarAppearance alloc] init];
|
|
475
475
|
[scrollEdgeAppearance configureWithTransparentBackground];
|
|
476
476
|
scrollEdgeAppearance.shadowColor = UIColor.clearColor;
|
|
477
477
|
scrollEdgeAppearance.backgroundColor = UIColor.clearColor;
|
|
478
|
+
[scrollEdgeAppearance setBackIndicatorImage:[UINavigationBar appearance].backIndicatorImage transitionMaskImage:[UINavigationBar appearance].backIndicatorTransitionMaskImage];
|
|
478
479
|
self.navigationBar.scrollEdgeAppearance = scrollEdgeAppearance;
|
|
479
480
|
self.navigationBar.standardAppearance = [scrollEdgeAppearance copy];
|
|
480
481
|
}
|
|
@@ -626,7 +627,7 @@ void printViewHierarchy(UIView *view, NSString *prefix) {
|
|
|
626
627
|
- (void)updateNavigationBarTinitColorForViewController:(UIViewController *)vc {
|
|
627
628
|
self.navigationBar.tintColor = vc.hbd_tintColor;
|
|
628
629
|
self.navigationBar.titleTextAttributes = vc.hbd_titleTextAttributes;
|
|
629
|
-
if (@available(iOS
|
|
630
|
+
if (@available(iOS 13.0, *)) {
|
|
630
631
|
self.navigationBar.scrollEdgeAppearance.titleTextAttributes = vc.hbd_titleTextAttributes;
|
|
631
632
|
self.navigationBar.standardAppearance.titleTextAttributes = vc.hbd_titleTextAttributes;
|
|
632
633
|
}
|
|
@@ -285,6 +285,11 @@
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
[self applyNavigationBarOptions:target];
|
|
288
|
+
|
|
289
|
+
NSString *screenColor = options[@"screenBackgroundColor"];
|
|
290
|
+
if (screenColor && [self isViewLoaded]) {
|
|
291
|
+
self.view.backgroundColor = [HBDUtils colorWithHexString:screenColor];
|
|
292
|
+
}
|
|
288
293
|
|
|
289
294
|
NSNumber *statusBarHidden = [options objectForKey:@"statusBarHidden"];
|
|
290
295
|
if (statusBarHidden) {
|
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/lib/typing.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export declare const LayoutFittingCompressed = "compressed";
|
|
|
38
38
|
export declare type LayoutFittingCompressed = typeof LayoutFittingCompressed;
|
|
39
39
|
export declare type LayoutFitting = LayoutFittingExpanded | LayoutFittingCompressed;
|
|
40
40
|
export interface NavigationOption {
|
|
41
|
+
screenBackgroundColor?: Color;
|
|
41
42
|
passThroughTouches?: boolean;
|
|
42
43
|
statusBarHidden?: boolean;
|
|
43
44
|
statusBarColorAndroid?: Color;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hybrid-navigation",
|
|
3
3
|
"description": "React Native Navigation that supports seamless navigation between Native and React.",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.7.1",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
7
7
|
"navigation",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"path-to-regexp": "^6.1.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@babel/core": "^7.
|
|
44
|
-
"@babel/runtime": "^7.
|
|
43
|
+
"@babel/core": "^7.16.0",
|
|
44
|
+
"@babel/runtime": "^7.16.0",
|
|
45
45
|
"@gfez/eslint-config-react-native": "^1.0.0",
|
|
46
|
-
"@react-native-community/hooks": "^2.
|
|
46
|
+
"@react-native-community/hooks": "^2.8.0",
|
|
47
47
|
"@types/jest": "^27.0.1",
|
|
48
48
|
"@types/react": "^17.0.1",
|
|
49
|
-
"@types/react-native": "^0.
|
|
49
|
+
"@types/react-native": "^0.66.2",
|
|
50
50
|
"@types/react-redux": "^7.1.9",
|
|
51
51
|
"@types/react-test-renderer": "17.0.1",
|
|
52
52
|
"babel-jest": "^27.2.0",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"jest": "^27.2.0",
|
|
55
55
|
"metro-react-native-babel-preset": "^0.66.2",
|
|
56
56
|
"react": "17.0.2",
|
|
57
|
-
"react-native": "^0.66.
|
|
57
|
+
"react-native": "^0.66.2",
|
|
58
58
|
"react-native-fast-image": "^8.5.11",
|
|
59
59
|
"react-native-iphone-x-helper": "^1.2.0",
|
|
60
|
-
"react-native-keyboard-aware-scroll-view": "^0.9.
|
|
60
|
+
"react-native-keyboard-aware-scroll-view": "^0.9.5",
|
|
61
61
|
"react-native-toast-hybrid": "^2.4.4",
|
|
62
62
|
"react-redux": "^7.2.5",
|
|
63
63
|
"react-test-renderer": "17.0.2",
|
|
@@ -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
|
-
}
|