hybrid-navigation 2.20.1 → 3.0.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/HybridNavigation.podspec +7 -5
- package/README.md +17 -0
- package/android/build.gradle +56 -19
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +320 -326
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +13 -20
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +6 -11
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +55 -21
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +31 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +223 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +370 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +239 -224
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +177 -198
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactDrawerFragment.java +2 -9
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +41 -78
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +438 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +10 -19
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +7 -15
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +135 -173
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +54 -227
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +2 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +12 -14
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +18 -21
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +17 -20
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +13 -26
- package/dist/NativeEvent.d.ts +33 -0
- package/dist/NativeEvent.js +2 -0
- package/dist/NativeGarden.d.ts +18 -0
- package/dist/NativeGarden.js +2 -0
- package/dist/NativeNavigation.d.ts +47 -0
- package/dist/NativeNavigation.js +2 -0
- package/dist/Navigation.js +3 -3
- package/dist/NavigationModule.d.ts +3 -3
- package/dist/NavigationModule.js +18 -19
- package/dist/Navigator.js +1 -2
- package/dist/Options.d.ts +4 -7
- package/dist/Route.d.ts +0 -2
- package/dist/handler/BarButtonEventHandler.js +2 -2
- package/dist/handler/LayoutCommandHandler.js +3 -3
- package/dist/handler/ResultEventHandler.js +3 -3
- package/dist/handler/VisibilityEventHandler.js +11 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/ios/HybridNavigation/GlobalStyle.h +0 -6
- package/ios/HybridNavigation/{GlobalStyle.m → GlobalStyle.mm} +54 -44
- package/ios/HybridNavigation/HBDUtils.h +0 -4
- package/ios/HybridNavigation/{HBDUtils.m → HBDUtils.mm} +0 -41
- package/ios/HybridNavigation/Navigator/{HBDScreenNavigator.m → HBDScreenNavigator.mm} +3 -9
- package/ios/HybridNavigation/Navigator/{HBDStackNavigator.m → HBDStackNavigator.mm} +0 -4
- package/ios/HybridNavigation/Navigator/{HBDTabNavigator.m → HBDTabNavigator.mm} +1 -55
- package/ios/HybridNavigation/React/HBDNativeEvent.h +13 -0
- package/ios/HybridNavigation/React/HBDNativeEvent.mm +31 -0
- package/ios/HybridNavigation/React/HBDNativeGarden.h +10 -0
- package/ios/HybridNavigation/React/HBDNativeGarden.mm +151 -0
- package/ios/HybridNavigation/React/HBDNativeNavigation.h +11 -0
- package/ios/HybridNavigation/React/HBDNativeNavigation.mm +263 -0
- package/ios/HybridNavigation/{ReactBridge → React}/HBDReactBridgeManager.h +3 -1
- package/ios/HybridNavigation/{ReactBridge/HBDReactBridgeManager.m → React/HBDReactBridgeManager.mm} +7 -30
- package/ios/HybridNavigation/View/{HBDNavigationBar.m → HBDNavigationBar.mm} +8 -28
- package/ios/HybridNavigation/View/HBDRootView.h +2 -2
- package/ios/HybridNavigation/View/{HBDRootView.m → HBDRootView.mm} +2 -2
- package/ios/HybridNavigation/View/HBDTitleView.h +2 -2
- package/ios/HybridNavigation/View/{HBDTitleView.m → HBDTitleView.mm} +3 -3
- package/ios/HybridNavigation/View/UIImage+WithBadge.h +13 -0
- package/ios/HybridNavigation/View/UIImage+WithBadge.mm +36 -0
- package/ios/HybridNavigation/ViewController/{HBDDrawerController.m → HBDDrawerController.mm} +2 -25
- package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -4
- package/ios/HybridNavigation/ViewController/{HBDReactViewController.m → HBDReactViewController.mm} +40 -31
- package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -2
- package/ios/HybridNavigation/ViewController/HBDTabBarController.mm +140 -0
- package/ios/HybridNavigation/ViewController/HBDViewController+Garden.h +0 -2
- package/ios/HybridNavigation/ViewController/{HBDViewController+Garden.m → HBDViewController+Garden.mm} +8 -26
- package/ios/HybridNavigation/ViewController/HBDViewController.h +2 -0
- package/ios/HybridNavigation/ViewController/{HBDViewController.m → HBDViewController.mm} +67 -57
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +0 -2
- package/ios/HybridNavigation/ViewController/{UIViewController+HBD.m → UIViewController+HBD.mm} +10 -44
- package/package.json +11 -2
- package/src/DeepLink.ts +3 -3
- package/src/NativeEvent.ts +40 -0
- package/src/NativeGarden.ts +27 -0
- package/src/NativeNavigation.ts +72 -0
- package/src/Navigation.ts +13 -13
- package/src/NavigationComponentWrap.tsx +4 -4
- package/src/NavigationModule.ts +21 -46
- package/src/Navigator.ts +13 -13
- package/src/Options.ts +9 -9
- package/src/Route.ts +0 -2
- package/src/handler/BarButtonEventHandler.ts +4 -8
- package/src/handler/DispatchCommandHandler.ts +4 -8
- package/src/handler/LayoutCommandHandler.ts +4 -5
- package/src/handler/ResultEventHandler.ts +11 -27
- package/src/handler/VisibilityEventHandler.ts +23 -32
- package/src/hooks.ts +2 -2
- package/src/index.ts +4 -5
- package/src/router/drawer.ts +5 -5
- package/src/router/index.ts +15 -15
- package/src/router/screen.ts +2 -2
- package/src/router/stack.ts +4 -4
- package/src/router/tabs.ts +3 -3
- package/src/store.ts +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/DefaultTabBarProvider.java +0 -143
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +0 -230
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +0 -89
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +0 -71
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +0 -370
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +0 -445
- package/dist/Event.d.ts +0 -16
- package/dist/Event.js +0 -62
- package/dist/GardenModule.d.ts +0 -24
- package/dist/GardenModule.js +0 -21
- package/ios/HybridNavigation/HBDAnimationObserver.h +0 -24
- package/ios/HybridNavigation/HBDAnimationObserver.m +0 -45
- package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.h +0 -28
- package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.m +0 -72
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +0 -6
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +0 -157
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +0 -6
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +0 -249
- package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -9
- package/ios/HybridNavigation/View/HBDReactTabBar.m +0 -36
- package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -9
- package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -46
- package/ios/HybridNavigation/ViewController/HBDTabBarController.m +0 -265
- package/src/Event.ts +0 -117
- package/src/GardenModule.ts +0 -50
- /package/ios/HybridNavigation/Navigator/{HBDDrawerNavigator.m → HBDDrawerNavigator.mm} +0 -0
- /package/ios/HybridNavigation/Navigator/{HBDNavigatorRegistry.m → HBDNavigatorRegistry.mm} +0 -0
- /package/ios/HybridNavigation/{ReactBridge → React}/HBDNavigator.h +0 -0
- /package/ios/HybridNavigation/View/{HBDBackBarButtonItem.m → HBDBackBarButtonItem.mm} +0 -0
- /package/ios/HybridNavigation/View/{HBDBarButtonItem.m → HBDBarButtonItem.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDFadeAnimation.m → HBDFadeAnimation.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDNavigationController.m → HBDNavigationController.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDPopAnimation.m → HBDPopAnimation.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDPushAnimation.m → HBDPushAnimation.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{UINavigationController+HBD.m → UINavigationController+HBD.mm} +0 -0
|
@@ -1,211 +1,33 @@
|
|
|
1
1
|
package com.reactnative.hybridnavigation;
|
|
2
2
|
|
|
3
|
-
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
|
4
|
-
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
5
3
|
import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_ITEM;
|
|
6
4
|
import static com.reactnative.hybridnavigation.Constants.ACTION_UPDATE_TAB_BAR;
|
|
7
5
|
import static com.reactnative.hybridnavigation.Constants.ARG_ACTION;
|
|
8
6
|
import static com.reactnative.hybridnavigation.Constants.ARG_OPTIONS;
|
|
7
|
+
import static com.reactnative.hybridnavigation.Parameters.mergeOptions;
|
|
9
8
|
|
|
10
|
-
import android.content.Context;
|
|
11
|
-
import android.graphics.Color;
|
|
12
|
-
import android.graphics.drawable.ColorDrawable;
|
|
13
9
|
import android.os.Bundle;
|
|
14
|
-
import android.util.Pair;
|
|
15
|
-
import android.view.Gravity;
|
|
16
10
|
import android.view.View;
|
|
17
|
-
import android.widget.FrameLayout;
|
|
18
11
|
|
|
19
12
|
import androidx.annotation.NonNull;
|
|
20
13
|
import androidx.annotation.Nullable;
|
|
21
14
|
|
|
22
|
-
import com.facebook.react.ReactInstanceManager;
|
|
23
|
-
import com.facebook.react.bridge.ReactContext;
|
|
24
|
-
import com.navigation.androidx.AwesomeFragment;
|
|
25
|
-
import com.navigation.androidx.StackFragment;
|
|
26
15
|
import com.navigation.androidx.Style;
|
|
16
|
+
import com.navigation.androidx.TabBar;
|
|
27
17
|
import com.navigation.androidx.TabBarFragment;
|
|
28
18
|
import com.navigation.androidx.TabBarItem;
|
|
29
|
-
import com.navigation.androidx.TabBarProvider;
|
|
30
19
|
|
|
31
20
|
import java.util.ArrayList;
|
|
32
21
|
import java.util.List;
|
|
33
22
|
|
|
34
|
-
public class ReactTabBarProvider
|
|
23
|
+
public class ReactTabBarProvider extends com.navigation.androidx.DefaultTabBarProvider {
|
|
35
24
|
|
|
36
|
-
private static final String TAG = "Navigation";
|
|
37
|
-
|
|
38
|
-
private HBDReactRootView reactRootView;
|
|
39
25
|
private ReactTabBarFragment tabBarFragment;
|
|
40
|
-
private ReactTabBar tabBar;
|
|
41
26
|
|
|
42
27
|
@Override
|
|
43
28
|
public View onCreateTabBar(@NonNull List<TabBarItem> tabBarItems, @NonNull TabBarFragment tabBarFragment, @Nullable Bundle savedInstanceState) {
|
|
44
|
-
if (!(tabBarFragment instanceof ReactTabBarFragment)) {
|
|
45
|
-
throw new IllegalStateException("自定义 TabBar 必须和 ReactTabBarFragment 一起使用");
|
|
46
|
-
}
|
|
47
29
|
this.tabBarFragment = (ReactTabBarFragment) tabBarFragment;
|
|
48
|
-
|
|
49
|
-
Bundle options = this.tabBarFragment.getOptions();
|
|
50
|
-
String tabBarModuleName = options.getString("tabBarModuleName");
|
|
51
|
-
if (tabBarModuleName == null) {
|
|
52
|
-
throw new IllegalStateException("tabBarModuleName 不能为 null");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
HBDReactRootView reactRootView = createReactRootView();
|
|
56
|
-
this.reactRootView = reactRootView;
|
|
57
|
-
startReactApplication(tabBarItems, tabBarModuleName, reactRootView);
|
|
58
|
-
|
|
59
|
-
this.tabBar = createReactTabBar(reactRootView, options);
|
|
60
|
-
return tabBar;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@NonNull
|
|
64
|
-
private ReactTabBar createReactTabBar(HBDReactRootView reactRootView, Bundle options) {
|
|
65
|
-
boolean sizeIndeterminate = options.getBoolean("sizeIndeterminate");
|
|
66
|
-
ReactTabBar tabBar = new ReactTabBar(tabBarFragment.requireContext(), sizeIndeterminate);
|
|
67
|
-
Style style = tabBarFragment.getStyle();
|
|
68
|
-
tabBar.setTabBarBackground(new ColorDrawable(Color.parseColor(style.getTabBarBackgroundColor())));
|
|
69
|
-
tabBar.setShadow(style.getTabBarShadow());
|
|
70
|
-
tabBar.setRootView(reactRootView);
|
|
71
|
-
return tabBar;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private void startReactApplication(@NonNull List<TabBarItem> tabBarItems, String tabBarModuleName, HBDReactRootView reactRootView) {
|
|
75
|
-
Bundle options = tabBarFragment.getOptions();
|
|
76
|
-
inflateTabsIfNeeded(tabBarItems, options);
|
|
77
|
-
|
|
78
|
-
Bundle props = createProps(options);
|
|
79
|
-
props.putInt("selectedIndex", options.getInt("selectedIndex"));
|
|
80
|
-
|
|
81
|
-
ReactBridgeManager bridgeManager = getReactBridgeManager();
|
|
82
|
-
bridgeManager.addReactBridgeReloadListener(this);
|
|
83
|
-
ReactInstanceManager reactInstanceManager = bridgeManager.getReactInstanceManager();
|
|
84
|
-
|
|
85
|
-
reactRootView.startReactApplication(reactInstanceManager, tabBarModuleName, props);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
@NonNull
|
|
89
|
-
private HBDReactRootView createReactRootView() {
|
|
90
|
-
HBDReactRootView reactRootView = new HBDReactRootView(tabBarFragment.requireContext());
|
|
91
|
-
Bundle options = tabBarFragment.getOptions();
|
|
92
|
-
boolean sizeIndeterminate = options.getBoolean("sizeIndeterminate");
|
|
93
|
-
if (sizeIndeterminate) {
|
|
94
|
-
reactRootView.setLayoutParams(new FrameLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT, Gravity.BOTTOM));
|
|
95
|
-
reactRootView.setShouldConsumeTouchEvent(false);
|
|
96
|
-
} else {
|
|
97
|
-
reactRootView.setLayoutParams(new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT, Gravity.BOTTOM));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return reactRootView;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private void inflateTabsIfNeeded(@NonNull List<TabBarItem> tabBarItems, Bundle options) {
|
|
104
|
-
ArrayList<Bundle> tabs = options.getParcelableArrayList("tabs");
|
|
105
|
-
if (tabs != null) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
options.putParcelableArrayList("tabs", createTabs(tabBarItems));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
@NonNull
|
|
112
|
-
private ArrayList<Bundle> createTabs(@NonNull List<TabBarItem> tabBarItems) {
|
|
113
|
-
ArrayList<Bundle> tabs = new ArrayList<>();
|
|
114
|
-
Context context = tabBarFragment.requireContext();
|
|
115
|
-
List<AwesomeFragment> children = tabBarFragment.getChildAwesomeFragments();
|
|
116
|
-
for (int i = 0, size = tabBarItems.size(); i < size; i++) {
|
|
117
|
-
TabBarItem tabBarItem = tabBarItems.get(i);
|
|
118
|
-
Bundle tab = new Bundle();
|
|
119
|
-
tab.putInt("index", i);
|
|
120
|
-
tab.putString("icon", Utils.getIconUri(context, tabBarItem.iconUri));
|
|
121
|
-
tab.putString("unselectedIcon", Utils.getIconUri(context, tabBarItem.unselectedIconUri));
|
|
122
|
-
tab.putString("title", tabBarItem.title);
|
|
123
|
-
Pair<String, String> pair = extractSceneIdAndModuleName(children.get(i));
|
|
124
|
-
tab.putString("sceneId", pair.first);
|
|
125
|
-
tab.putString("moduleName", pair.second);
|
|
126
|
-
tabs.add(i, tab);
|
|
127
|
-
}
|
|
128
|
-
return tabs;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private Pair<String, String> extractSceneIdAndModuleName(AwesomeFragment fragment) {
|
|
132
|
-
if (fragment instanceof StackFragment) {
|
|
133
|
-
StackFragment stackFragment = (StackFragment) fragment;
|
|
134
|
-
fragment = stackFragment.getRootFragment();
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (fragment instanceof HybridFragment) {
|
|
138
|
-
HybridFragment hybridFragment = (HybridFragment) fragment;
|
|
139
|
-
return new Pair<>(hybridFragment.getSceneId(), hybridFragment.getModuleName());
|
|
140
|
-
}
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private void unmountReactView() {
|
|
145
|
-
ReactBridgeManager bridgeManager = getReactBridgeManager();
|
|
146
|
-
bridgeManager.removeReactBridgeReloadListener(this);
|
|
147
|
-
ReactContext reactContext = bridgeManager.getCurrentReactContext();
|
|
148
|
-
|
|
149
|
-
if (reactContext == null || !reactContext.hasActiveCatalystInstance()) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (reactRootView != null) {
|
|
154
|
-
reactRootView.unmountReactApplication();
|
|
155
|
-
reactRootView = null;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
@NonNull
|
|
160
|
-
private Bundle createProps(Bundle options) {
|
|
161
|
-
Bundle props = new Bundle();
|
|
162
|
-
|
|
163
|
-
props.putParcelableArrayList("tabs", options.getParcelableArrayList("tabs"));
|
|
164
|
-
props.putString("sceneId", tabBarFragment.getSceneId());
|
|
165
|
-
props.putInt("selectedIndex", tabBarFragment.getSelectedIndex());
|
|
166
|
-
|
|
167
|
-
String tabBarItemColor = options.getString("tabBarItemColor");
|
|
168
|
-
String tabBarUnselectedItemColor = options.getString("tabBarUnselectedItemColor");
|
|
169
|
-
|
|
170
|
-
if (tabBarItemColor != null) {
|
|
171
|
-
props.putString("itemColor", tabBarItemColor);
|
|
172
|
-
props.putString("unselectedItemColor", tabBarUnselectedItemColor);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
props.putString("badgeColor", options.getString("tabBarBadgeColor"));
|
|
176
|
-
return props;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
@Override
|
|
180
|
-
public void onDestroyTabBar() {
|
|
181
|
-
unmountReactView();
|
|
182
|
-
tabBarFragment = null;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
@Override
|
|
186
|
-
public void onReload() {
|
|
187
|
-
unmountReactView();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
@Override
|
|
191
|
-
public void onSaveInstanceState(@NonNull Bundle outState) {
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
@Override
|
|
196
|
-
public void setSelectedIndex(int index) {
|
|
197
|
-
if (tabBarFragment != null) {
|
|
198
|
-
Bundle props = createProps(tabBarFragment.getOptions());
|
|
199
|
-
props.putInt("selectedIndex", index);
|
|
200
|
-
reactRootView.setAppProperties(props);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
private final ReactBridgeManager bridgeManager = ReactBridgeManager.get();
|
|
205
|
-
|
|
206
|
-
@NonNull
|
|
207
|
-
public ReactBridgeManager getReactBridgeManager() {
|
|
208
|
-
return bridgeManager;
|
|
30
|
+
return super.onCreateTabBar(tabBarItems, tabBarFragment, savedInstanceState);
|
|
209
31
|
}
|
|
210
32
|
|
|
211
33
|
@Override
|
|
@@ -225,92 +47,97 @@ public class ReactTabBarProvider implements TabBarProvider, ReactBridgeManager.R
|
|
|
225
47
|
}
|
|
226
48
|
}
|
|
227
49
|
|
|
228
|
-
private void setTabItem(@Nullable ArrayList<Bundle>
|
|
229
|
-
if (
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
Bundle options = tabBarFragment.getOptions();
|
|
233
|
-
ArrayList<Bundle> tabs = options.getParcelableArrayList("tabs");
|
|
234
|
-
if (tabs == null) {
|
|
50
|
+
private void setTabItem(@Nullable ArrayList<Bundle> options) {
|
|
51
|
+
if (options == null) {
|
|
235
52
|
return;
|
|
236
53
|
}
|
|
237
54
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
55
|
+
TabBar tabBar = tabBarFragment.getTabBar();
|
|
56
|
+
|
|
57
|
+
for (Bundle option : options) {
|
|
58
|
+
int index = (int) option.getDouble("index");
|
|
59
|
+
TabBarItem tabBarItem = tabBar.getTabBarItem(index);
|
|
60
|
+
if (tabBarItem == null) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setTabItemTitle(option, tabBarItem);
|
|
65
|
+
setTabItemIcon(option, tabBarItem);
|
|
66
|
+
setTabItemBadge(option, tabBarItem);
|
|
67
|
+
tabBar.renderTabView(index);
|
|
244
68
|
}
|
|
245
|
-
reactRootView.setAppProperties(createProps(options));
|
|
246
69
|
}
|
|
247
70
|
|
|
248
|
-
private void
|
|
249
|
-
Bundle badge =
|
|
71
|
+
private void setTabItemBadge(Bundle option, TabBarItem tabBarItem) {
|
|
72
|
+
Bundle badge = option.getBundle("badge");
|
|
250
73
|
if (badge == null) {
|
|
251
74
|
return;
|
|
252
75
|
}
|
|
76
|
+
|
|
253
77
|
boolean hidden = badge.getBoolean("hidden", true);
|
|
254
78
|
String text = !hidden ? badge.getString("text", "") : "";
|
|
255
79
|
boolean dot = !hidden && badge.getBoolean("dot", false);
|
|
256
80
|
|
|
257
|
-
|
|
258
|
-
|
|
81
|
+
tabBarItem.badgeText = text;
|
|
82
|
+
tabBarItem.showDotBadge = dot;
|
|
259
83
|
}
|
|
260
84
|
|
|
261
|
-
private void
|
|
262
|
-
Bundle icon =
|
|
85
|
+
private void setTabItemIcon(Bundle option, TabBarItem tabBarItem) {
|
|
86
|
+
Bundle icon = option.getBundle("icon");
|
|
263
87
|
if (icon == null) {
|
|
264
88
|
return;
|
|
265
89
|
}
|
|
266
|
-
|
|
90
|
+
|
|
267
91
|
Bundle selected = icon.getBundle("selected");
|
|
92
|
+
tabBarItem.iconUri = selected.getString("uri");
|
|
93
|
+
|
|
94
|
+
Bundle unselected = icon.getBundle("unselected");
|
|
268
95
|
if (unselected != null) {
|
|
269
|
-
|
|
96
|
+
tabBarItem.unselectedIconUri = unselected.getString("uri");
|
|
270
97
|
}
|
|
271
|
-
tab.putString("icon", selected.getString("uri"));
|
|
272
98
|
}
|
|
273
99
|
|
|
274
|
-
private void
|
|
275
|
-
String title =
|
|
100
|
+
private void setTabItemTitle(Bundle option, TabBarItem tabBarItem) {
|
|
101
|
+
String title = option.getString("title");
|
|
276
102
|
if (title != null) {
|
|
277
|
-
|
|
103
|
+
tabBarItem.title = title;
|
|
278
104
|
}
|
|
279
105
|
}
|
|
280
106
|
|
|
281
|
-
private void updateTabBarStyle(@Nullable Bundle
|
|
282
|
-
if (
|
|
107
|
+
private void updateTabBarStyle(@Nullable Bundle options) {
|
|
108
|
+
if (options == null) {
|
|
283
109
|
return;
|
|
284
110
|
}
|
|
285
111
|
|
|
112
|
+
tabBarFragment.setOptions(mergeOptions(tabBarFragment.getOptions(), options));
|
|
113
|
+
TabBar tabBar = tabBarFragment.getTabBar();
|
|
286
114
|
|
|
287
|
-
|
|
288
|
-
|
|
115
|
+
String tabBarBackgroundColor = options.getString("tabBarBackgroundColor");
|
|
116
|
+
Bundle shadowImage = options.getBundle("tabBarShadowImage");
|
|
117
|
+
String tabBarItemSelectedColor = options.getString("tabBarItemSelectedColor");
|
|
118
|
+
String tabBarItemNormalColor = options.getString("tabBarItemNormalColor");
|
|
289
119
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
options.putString("tabBarColor", tabBarColor);
|
|
293
|
-
tabBar.setTabBarBackground(new ColorDrawable(Color.parseColor(tabBarColor)));
|
|
120
|
+
if (tabBarBackgroundColor != null) {
|
|
121
|
+
tabBar.setBarBackgroundColor(tabBarBackgroundColor);
|
|
294
122
|
|
|
295
123
|
Style style = tabBarFragment.getStyle();
|
|
296
|
-
style.setTabBarBackgroundColor(
|
|
124
|
+
style.setTabBarBackgroundColor(tabBarBackgroundColor);
|
|
297
125
|
tabBarFragment.setNeedsNavigationBarAppearanceUpdate();
|
|
298
126
|
}
|
|
299
127
|
|
|
300
|
-
Bundle shadowImage = bundle.getBundle("tabBarShadowImage");
|
|
301
128
|
if (shadowImage != null) {
|
|
302
|
-
|
|
303
|
-
|
|
129
|
+
tabBar.setShadowDrawable(Utils.createTabBarShadow(tabBarFragment.requireContext(), shadowImage));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (tabBarItemSelectedColor != null) {
|
|
133
|
+
tabBar.setSelectedItemColor(tabBarItemSelectedColor);
|
|
304
134
|
}
|
|
305
135
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
if (tabBarItemColor != null) {
|
|
309
|
-
options.putString("tabBarItemColor", tabBarItemColor);
|
|
310
|
-
options.putString("tabBarUnselectedItemColor", tabBarUnselectedItemColor);
|
|
311
|
-
Bundle props = createProps(options);
|
|
312
|
-
reactRootView.setAppProperties(props);
|
|
136
|
+
if (tabBarItemNormalColor != null) {
|
|
137
|
+
tabBar.setUnselectedItemColor(tabBarItemNormalColor);
|
|
313
138
|
}
|
|
139
|
+
|
|
140
|
+
tabBar.initialise(tabBar.getCurrentSelectedPosition());
|
|
314
141
|
}
|
|
315
142
|
|
|
316
143
|
}
|
|
@@ -43,9 +43,8 @@ public class Utils {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
Drawable drawable = DrawableUtils.fromUri(context, uri);
|
|
46
|
-
if (drawable instanceof BitmapDrawable) {
|
|
47
|
-
|
|
48
|
-
bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);
|
|
46
|
+
if (drawable instanceof BitmapDrawable bitmapDrawable) {
|
|
47
|
+
bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);
|
|
49
48
|
}
|
|
50
49
|
return drawable;
|
|
51
50
|
}
|
package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java
CHANGED
|
@@ -12,8 +12,8 @@ import com.navigation.androidx.AwesomeFragment;
|
|
|
12
12
|
import com.navigation.androidx.DrawerFragment;
|
|
13
13
|
import com.reactnative.hybridnavigation.HybridFragment;
|
|
14
14
|
import com.reactnative.hybridnavigation.Navigator;
|
|
15
|
-
import com.reactnative.hybridnavigation.ReactBridgeManager;
|
|
16
15
|
import com.reactnative.hybridnavigation.ReactDrawerFragment;
|
|
16
|
+
import com.reactnative.hybridnavigation.ReactManager;
|
|
17
17
|
|
|
18
18
|
import java.util.ArrayList;
|
|
19
19
|
import java.util.Arrays;
|
|
@@ -50,11 +50,11 @@ public class DrawerNavigator implements Navigator {
|
|
|
50
50
|
ReadableMap content = children.getMap(0);
|
|
51
51
|
ReadableMap menu = children.getMap(1);
|
|
52
52
|
|
|
53
|
-
AwesomeFragment contentFragment =
|
|
53
|
+
AwesomeFragment contentFragment = getReactManager().createFragment(content);
|
|
54
54
|
if (contentFragment == null) {
|
|
55
55
|
throw new IllegalArgumentException("can't create drawer content component with " + content);
|
|
56
56
|
}
|
|
57
|
-
AwesomeFragment menuFragment =
|
|
57
|
+
AwesomeFragment menuFragment = getReactManager().createFragment(menu);
|
|
58
58
|
if (menuFragment == null) {
|
|
59
59
|
throw new IllegalArgumentException("can't create drawer menu component with " + menu);
|
|
60
60
|
}
|
|
@@ -95,12 +95,11 @@ public class DrawerNavigator implements Navigator {
|
|
|
95
95
|
@Nullable
|
|
96
96
|
@Override
|
|
97
97
|
public Bundle buildRouteGraph(@NonNull AwesomeFragment fragment) {
|
|
98
|
-
if (!(fragment instanceof DrawerFragment) || !fragment.isAdded()) {
|
|
98
|
+
if (!(fragment instanceof DrawerFragment drawerFragment) || !fragment.isAdded()) {
|
|
99
99
|
return null;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
ArrayList<Bundle> children = buildChildrenGraph(drawer);
|
|
102
|
+
ArrayList<Bundle> children = buildChildrenGraph(drawerFragment);
|
|
104
103
|
Bundle graph = new Bundle();
|
|
105
104
|
graph.putString("layout", name());
|
|
106
105
|
graph.putString("sceneId", fragment.getSceneId());
|
|
@@ -115,7 +114,7 @@ public class DrawerNavigator implements Navigator {
|
|
|
115
114
|
List<AwesomeFragment> fragments = drawer.getChildAwesomeFragments();
|
|
116
115
|
for (int i = 0; i < fragments.size(); i++) {
|
|
117
116
|
AwesomeFragment child = fragments.get(i);
|
|
118
|
-
Bundle graph =
|
|
117
|
+
Bundle graph = getReactManager().buildRouteGraph(child);
|
|
119
118
|
if (graph != null) {
|
|
120
119
|
children.add(graph);
|
|
121
120
|
}
|
|
@@ -125,15 +124,14 @@ public class DrawerNavigator implements Navigator {
|
|
|
125
124
|
|
|
126
125
|
@Override
|
|
127
126
|
public HybridFragment primaryFragment(@NonNull AwesomeFragment fragment) {
|
|
128
|
-
if (!(fragment instanceof DrawerFragment) || !fragment.isAdded()) {
|
|
127
|
+
if (!(fragment instanceof DrawerFragment drawerFragment) || !fragment.isAdded()) {
|
|
129
128
|
return null;
|
|
130
129
|
}
|
|
131
130
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return getReactBridgeManager().primaryFragment(drawer.getMenuFragment());
|
|
131
|
+
if (drawerFragment.isMenuPrimary()) {
|
|
132
|
+
return getReactManager().primaryFragment(drawerFragment.getMenuFragment());
|
|
135
133
|
}
|
|
136
|
-
return
|
|
134
|
+
return getReactManager().primaryFragment(drawerFragment.getContentFragment());
|
|
137
135
|
}
|
|
138
136
|
|
|
139
137
|
@Override
|
|
@@ -163,7 +161,7 @@ public class DrawerNavigator implements Navigator {
|
|
|
163
161
|
}
|
|
164
162
|
}
|
|
165
163
|
|
|
166
|
-
private
|
|
167
|
-
return
|
|
164
|
+
private ReactManager getReactManager() {
|
|
165
|
+
return ReactManager.get();
|
|
168
166
|
}
|
|
169
167
|
}
|
package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java
CHANGED
|
@@ -15,11 +15,12 @@ import com.navigation.androidx.PresentationStyle;
|
|
|
15
15
|
import com.navigation.androidx.TransitionAnimation;
|
|
16
16
|
import com.reactnative.hybridnavigation.HybridFragment;
|
|
17
17
|
import com.reactnative.hybridnavigation.Navigator;
|
|
18
|
-
import com.reactnative.hybridnavigation.
|
|
18
|
+
import com.reactnative.hybridnavigation.ReactManager;
|
|
19
19
|
import com.reactnative.hybridnavigation.ReactStackFragment;
|
|
20
20
|
|
|
21
21
|
import java.util.Arrays;
|
|
22
22
|
import java.util.List;
|
|
23
|
+
import java.util.Objects;
|
|
23
24
|
|
|
24
25
|
public class ScreenNavigator implements Navigator {
|
|
25
26
|
|
|
@@ -59,20 +60,19 @@ public class ScreenNavigator implements Navigator {
|
|
|
59
60
|
Bundle props = buildProps(screen);
|
|
60
61
|
Bundle options = buildOptions(screen);
|
|
61
62
|
|
|
62
|
-
return
|
|
63
|
+
return getReactManager().createFragment(moduleName, props, options);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
@Override
|
|
66
67
|
public Bundle buildRouteGraph(@NonNull AwesomeFragment fragment) {
|
|
67
|
-
if (!(fragment instanceof HybridFragment) || !fragment.isAdded()) {
|
|
68
|
+
if (!(fragment instanceof HybridFragment hybridFragment) || !fragment.isAdded()) {
|
|
68
69
|
return null;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
|
|
72
|
-
Bundle route = new Bundle();
|
|
72
|
+
Bundle route = new Bundle();
|
|
73
73
|
route.putString("layout", name());
|
|
74
|
-
route.putString("sceneId",
|
|
75
|
-
route.putString("moduleName",
|
|
74
|
+
route.putString("sceneId", hybridFragment.getSceneId());
|
|
75
|
+
route.putString("moduleName", hybridFragment.getModuleName());
|
|
76
76
|
route.putString("mode", Navigator.Util.getMode(fragment));
|
|
77
77
|
return route;
|
|
78
78
|
}
|
|
@@ -84,11 +84,8 @@ public class ScreenNavigator implements Navigator {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
AwesomeFragment presented = FragmentHelper.getFragmentAfter(fragment);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
return (HybridFragment) fragment;
|
|
91
|
-
}
|
|
87
|
+
return (HybridFragment) Objects.requireNonNullElse(presented, fragment);
|
|
88
|
+
}
|
|
92
89
|
|
|
93
90
|
@Override
|
|
94
91
|
public void handleNavigation(@NonNull AwesomeFragment target, @NonNull String action, @NonNull ReadableMap extras, @NonNull Callback callback) {
|
|
@@ -123,7 +120,7 @@ public class ScreenNavigator implements Navigator {
|
|
|
123
120
|
}
|
|
124
121
|
|
|
125
122
|
ReadableMap layout = extras.getMap("layout");
|
|
126
|
-
presented =
|
|
123
|
+
presented = getReactManager().createFragment(layout);
|
|
127
124
|
if (presented == null) {
|
|
128
125
|
callback.invoke(null, false);
|
|
129
126
|
return;
|
|
@@ -141,7 +138,7 @@ public class ScreenNavigator implements Navigator {
|
|
|
141
138
|
}
|
|
142
139
|
|
|
143
140
|
ReadableMap layout = extras.getMap("layout");
|
|
144
|
-
presented =
|
|
141
|
+
presented = getReactManager().createFragment(layout);
|
|
145
142
|
if (presented == null) {
|
|
146
143
|
callback.invoke(null, false);
|
|
147
144
|
return;
|
|
@@ -162,12 +159,12 @@ public class ScreenNavigator implements Navigator {
|
|
|
162
159
|
callback.invoke(null, false);
|
|
163
160
|
return;
|
|
164
161
|
}
|
|
165
|
-
|
|
162
|
+
|
|
166
163
|
Bundle args = FragmentHelper.getArguments(presented);
|
|
167
164
|
args.putString(PresentableActivity.ARG_PRESENTING_SCENE_ID, presenting.getSceneId());
|
|
168
165
|
presented.setArguments(args);
|
|
169
166
|
presented.setPresentationStyle(PresentationStyle.OverFullScreen);
|
|
170
|
-
|
|
167
|
+
|
|
171
168
|
int requestCode = extras.getInt("requestCode");
|
|
172
169
|
presenting.presentFragment(presented, requestCode, () -> callback.invoke(null, true), TransitionAnimation.None);
|
|
173
170
|
}
|
|
@@ -192,11 +189,11 @@ public class ScreenNavigator implements Navigator {
|
|
|
192
189
|
callback.invoke(null, false);
|
|
193
190
|
return;
|
|
194
191
|
}
|
|
195
|
-
|
|
192
|
+
|
|
196
193
|
Bundle args = FragmentHelper.getArguments(presented);
|
|
197
194
|
args.putString(PresentableActivity.ARG_PRESENTING_SCENE_ID, presenting.getSceneId());
|
|
198
195
|
presented.setArguments(args);
|
|
199
|
-
|
|
196
|
+
|
|
200
197
|
int requestCode = extras.getInt("requestCode");
|
|
201
198
|
ReactStackFragment stackFragment = new ReactStackFragment();
|
|
202
199
|
stackFragment.setRootFragment(presented);
|
|
@@ -215,7 +212,7 @@ public class ScreenNavigator implements Navigator {
|
|
|
215
212
|
|
|
216
213
|
Bundle props = buildProps(extras);
|
|
217
214
|
Bundle options = buildOptions(extras);
|
|
218
|
-
return
|
|
215
|
+
return getReactManager().createFragment(moduleName, props, options);
|
|
219
216
|
}
|
|
220
217
|
|
|
221
218
|
@Nullable
|
|
@@ -234,7 +231,7 @@ public class ScreenNavigator implements Navigator {
|
|
|
234
231
|
return null;
|
|
235
232
|
}
|
|
236
233
|
|
|
237
|
-
private
|
|
238
|
-
return
|
|
234
|
+
private ReactManager getReactManager() {
|
|
235
|
+
return ReactManager.get();
|
|
239
236
|
}
|
|
240
237
|
}
|