hybrid-navigation 2.20.0 → 3.0.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/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/{HBDBarButtonItem.m → HBDBarButtonItem.mm} +19 -11
- package/ios/HybridNavigation/View/{HBDNavigationBar.m → HBDNavigationBar.mm} +68 -5
- 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} +1 -42
- 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/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
|
@@ -18,6 +18,8 @@ import com.navigation.androidx.BarStyle;
|
|
|
18
18
|
import com.navigation.androidx.DrawableUtils;
|
|
19
19
|
import com.navigation.androidx.Style;
|
|
20
20
|
|
|
21
|
+
import java.util.Objects;
|
|
22
|
+
|
|
21
23
|
public class GlobalStyle {
|
|
22
24
|
|
|
23
25
|
private static final String TAG = "Navigation";
|
|
@@ -68,7 +70,7 @@ public class GlobalStyle {
|
|
|
68
70
|
} else {
|
|
69
71
|
style.setToolbarBackgroundColor(Color.WHITE);
|
|
70
72
|
}
|
|
71
|
-
|
|
73
|
+
}
|
|
72
74
|
|
|
73
75
|
String topBarColorDarkContent = options.getString("topBarColorDarkContent");
|
|
74
76
|
if (topBarColorDarkContent != null) {
|
|
@@ -161,25 +163,17 @@ public class GlobalStyle {
|
|
|
161
163
|
// --------- tabBar ------------
|
|
162
164
|
// -----------------------------
|
|
163
165
|
|
|
164
|
-
//
|
|
165
|
-
String
|
|
166
|
-
if (
|
|
167
|
-
style.setTabBarBackgroundColor(
|
|
166
|
+
// tabBarBackgroundColor
|
|
167
|
+
String tabBarBackgroundColor = options.getString("tabBarBackgroundColor");
|
|
168
|
+
if (tabBarBackgroundColor != null) {
|
|
169
|
+
style.setTabBarBackgroundColor(tabBarBackgroundColor);
|
|
168
170
|
}
|
|
169
171
|
|
|
170
|
-
String
|
|
171
|
-
|
|
172
|
-
style.setTabBarItemColor(tabBarItemColor);
|
|
173
|
-
} else {
|
|
174
|
-
style.setTabBarItemColor("#FF5722");
|
|
175
|
-
}
|
|
172
|
+
String tabBarItemSelectedColor = options.getString("tabBarItemSelectedColor");
|
|
173
|
+
style.setTabBarItemColor(Objects.requireNonNullElse(tabBarItemSelectedColor, "#FF5722"));
|
|
176
174
|
|
|
177
|
-
String
|
|
178
|
-
|
|
179
|
-
style.setTabBarUnselectedItemColor(tabBarUnselectedItemColor);
|
|
180
|
-
} else {
|
|
181
|
-
style.setTabBarUnselectedItemColor("#BDBDBD");
|
|
182
|
-
}
|
|
175
|
+
String tabBarItemNormalColor = options.getString("tabBarItemNormalColor");
|
|
176
|
+
style.setTabBarUnselectedItemColor(Objects.requireNonNullElse(tabBarItemNormalColor, "#666666"));
|
|
183
177
|
|
|
184
178
|
// tabBarShadowImage
|
|
185
179
|
Bundle shadowImage = options.getBundle("tabBarShadowImage");
|
|
@@ -230,9 +224,8 @@ public class GlobalStyle {
|
|
|
230
224
|
}
|
|
231
225
|
|
|
232
226
|
Drawable drawable = DrawableUtils.fromUri(context, uri);
|
|
233
|
-
if (drawable instanceof BitmapDrawable) {
|
|
234
|
-
|
|
235
|
-
bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);
|
|
227
|
+
if (drawable instanceof BitmapDrawable bitmapDrawable) {
|
|
228
|
+
bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);
|
|
236
229
|
}
|
|
237
230
|
return drawable;
|
|
238
231
|
}
|
|
@@ -13,7 +13,6 @@ import androidx.annotation.CallSuper;
|
|
|
13
13
|
import androidx.annotation.NonNull;
|
|
14
14
|
import androidx.annotation.Nullable;
|
|
15
15
|
|
|
16
|
-
import com.facebook.react.ReactInstanceManager;
|
|
17
16
|
import com.facebook.react.bridge.ReactContext;
|
|
18
17
|
import com.navigation.androidx.AppUtils;
|
|
19
18
|
import com.navigation.androidx.AwesomeFragment;
|
|
@@ -31,25 +30,21 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
31
30
|
private static final String SAVED_OPTIONS = "hybrid_options";
|
|
32
31
|
private static final String SAVED_PROPS = "hybrid_props";
|
|
33
32
|
|
|
34
|
-
private final
|
|
33
|
+
private final ReactManager reactManager = ReactManager.get();
|
|
35
34
|
|
|
36
35
|
private Garden garden;
|
|
37
36
|
|
|
38
37
|
@NonNull
|
|
39
|
-
public
|
|
40
|
-
return
|
|
38
|
+
public ReactManager getReactManager() {
|
|
39
|
+
return reactManager;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
public boolean isReactModuleRegisterCompleted() {
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
protected final ReactInstanceManager getReactInstanceManager() {
|
|
48
|
-
return bridgeManager.getReactInstanceManager();
|
|
43
|
+
return reactManager.isReactModuleRegisterCompleted();
|
|
49
44
|
}
|
|
50
45
|
|
|
51
46
|
protected final ReactContext getCurrentReactContext() {
|
|
52
|
-
return
|
|
47
|
+
return reactManager.getCurrentReactContext();
|
|
53
48
|
}
|
|
54
49
|
|
|
55
50
|
@Override
|
|
@@ -64,7 +59,7 @@ public class HybridFragment extends AwesomeFragment {
|
|
|
64
59
|
@Override
|
|
65
60
|
public void onDestroy() {
|
|
66
61
|
super.onDestroy();
|
|
67
|
-
|
|
62
|
+
reactManager.watchMemory(this);
|
|
68
63
|
}
|
|
69
64
|
|
|
70
65
|
@Override
|
|
@@ -1,32 +1,66 @@
|
|
|
1
1
|
package com.reactnative.hybridnavigation;
|
|
2
2
|
|
|
3
3
|
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
4
5
|
|
|
5
|
-
import com.facebook.react.
|
|
6
|
+
import com.facebook.react.BaseReactPackage;
|
|
6
7
|
import com.facebook.react.bridge.NativeModule;
|
|
7
8
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
-
import com.facebook.react.
|
|
9
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
10
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
9
11
|
|
|
10
|
-
import java.util.
|
|
11
|
-
import java.util.
|
|
12
|
-
import java.util.List;
|
|
12
|
+
import java.util.HashMap;
|
|
13
|
+
import java.util.Map;
|
|
13
14
|
|
|
14
|
-
public class HybridNavigationPackage
|
|
15
|
+
public class HybridNavigationPackage extends BaseReactPackage {
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
|
|
29
|
-
return Collections.emptyList();
|
|
30
|
-
}
|
|
17
|
+
@Nullable
|
|
18
|
+
@Override
|
|
19
|
+
public NativeModule getModule(@NonNull String name, @NonNull ReactApplicationContext context) {
|
|
20
|
+
return switch (name) {
|
|
21
|
+
case NativeEvent.NAME -> new NativeEvent(context);
|
|
22
|
+
case NativeNavigation.NAME ->
|
|
23
|
+
new NativeNavigation(context, ReactManager.get());
|
|
24
|
+
case NativeGarden.NAME ->
|
|
25
|
+
new NativeGarden(context, ReactManager.get());
|
|
26
|
+
default -> null;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
31
29
|
|
|
30
|
+
@NonNull
|
|
31
|
+
@Override
|
|
32
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
33
|
+
return new ReactModuleInfoProvider() {
|
|
34
|
+
@NonNull
|
|
35
|
+
@Override
|
|
36
|
+
public Map<String, ReactModuleInfo> getReactModuleInfos() {
|
|
37
|
+
Map<String, ReactModuleInfo> map = new HashMap<>();
|
|
38
|
+
map.put(NativeNavigation.NAME, new ReactModuleInfo(
|
|
39
|
+
NativeNavigation.NAME, // name
|
|
40
|
+
NativeNavigation.NAME, // className
|
|
41
|
+
false, // canOverrideExistingModule
|
|
42
|
+
false, // needsEagerInit
|
|
43
|
+
false, // isCXXModule
|
|
44
|
+
true // isTurboModule
|
|
45
|
+
));
|
|
46
|
+
map.put(NativeGarden.NAME, new ReactModuleInfo(
|
|
47
|
+
NativeGarden.NAME, // name
|
|
48
|
+
NativeGarden.NAME, // className
|
|
49
|
+
false, // canOverrideExistingModule
|
|
50
|
+
false, // needsEagerInit
|
|
51
|
+
false, // isCXXModule
|
|
52
|
+
true // isTurboModule
|
|
53
|
+
));
|
|
54
|
+
map.put(NativeEvent.NAME, new ReactModuleInfo(
|
|
55
|
+
NativeEvent.NAME, // name
|
|
56
|
+
NativeEvent.NAME, // className
|
|
57
|
+
false, // canOverrideExistingModule
|
|
58
|
+
false, // needsEagerInit
|
|
59
|
+
false, // isCXXModule
|
|
60
|
+
true // isTurboModule
|
|
61
|
+
));
|
|
62
|
+
return map;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
32
66
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package com.reactnative.hybridnavigation;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
+
import com.facebook.react.bridge.ReactContext;
|
|
7
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
8
|
+
|
|
9
|
+
@ReactModule(name = NativeEvent.NAME)
|
|
10
|
+
public class NativeEvent extends NativeEventSpec {
|
|
11
|
+
|
|
12
|
+
public static final String NAME = "HBDNativeEvent";
|
|
13
|
+
|
|
14
|
+
public NativeEvent(ReactApplicationContext reactContext) {
|
|
15
|
+
super(reactContext);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Override
|
|
19
|
+
@NonNull
|
|
20
|
+
public String getName() {
|
|
21
|
+
return NAME;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public static NativeEvent getInstance() {
|
|
25
|
+
ReactManager reactManager = ReactManager.get();
|
|
26
|
+
ReactContext reactContext = reactManager.getCurrentReactContext();
|
|
27
|
+
assert reactContext != null;
|
|
28
|
+
return reactContext.getNativeModule(NativeEvent.class);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
package com.reactnative.hybridnavigation;
|
|
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
|
+
|
|
10
|
+
import android.app.Activity;
|
|
11
|
+
import android.os.Bundle;
|
|
12
|
+
|
|
13
|
+
import androidx.annotation.NonNull;
|
|
14
|
+
import androidx.annotation.Nullable;
|
|
15
|
+
import androidx.fragment.app.FragmentManager;
|
|
16
|
+
|
|
17
|
+
import com.facebook.common.logging.FLog;
|
|
18
|
+
import com.facebook.react.bridge.JavaOnlyMap;
|
|
19
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
20
|
+
import com.facebook.react.bridge.ReactContext;
|
|
21
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
22
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
23
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
24
|
+
import com.facebook.react.bridge.WritableMap;
|
|
25
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
26
|
+
import com.navigation.androidx.AwesomeFragment;
|
|
27
|
+
import com.navigation.androidx.DrawerFragment;
|
|
28
|
+
import com.navigation.androidx.FragmentHelper;
|
|
29
|
+
import com.navigation.androidx.TabBarFragment;
|
|
30
|
+
|
|
31
|
+
import java.util.HashMap;
|
|
32
|
+
import java.util.Map;
|
|
33
|
+
|
|
34
|
+
@ReactModule(name = NativeGarden.NAME)
|
|
35
|
+
public class NativeGarden extends NativeGardenSpec {
|
|
36
|
+
private static final String TAG = "Navigation";
|
|
37
|
+
public static final String NAME = "HBDNativeGarden";
|
|
38
|
+
private final ReactManager reactManager;
|
|
39
|
+
|
|
40
|
+
public NativeGarden(ReactApplicationContext reactContext, ReactManager reactManager) {
|
|
41
|
+
super(reactContext);
|
|
42
|
+
this.reactManager = reactManager;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Override
|
|
46
|
+
@NonNull
|
|
47
|
+
public String getName() {
|
|
48
|
+
return NAME;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Override
|
|
52
|
+
protected Map<String, Object> getTypedExportedConstants() {
|
|
53
|
+
final Map<String, Object> constants = new HashMap<>();
|
|
54
|
+
constants.put("TOOLBAR_HEIGHT", 56);
|
|
55
|
+
return constants;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Override
|
|
59
|
+
public void setStyle(ReadableMap style) {
|
|
60
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
61
|
+
FLog.i(TAG, "GardenModule#setStyle");
|
|
62
|
+
Garden.createGlobalStyle(toBundle(style));
|
|
63
|
+
|
|
64
|
+
ReactAppCompatActivity activity = getActiveActivity();
|
|
65
|
+
if (activity != null) {
|
|
66
|
+
activity.inflateStyle();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Override
|
|
72
|
+
public void setTitleItem(String sceneId, ReadableMap item) {
|
|
73
|
+
updateOptions(sceneId, item, "titleItem");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Override
|
|
77
|
+
public void setLeftBarButtonItem(String sceneId, @Nullable ReadableMap item) {
|
|
78
|
+
updateOptions(sceneId, item, "leftBarButtonItem");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@Override
|
|
82
|
+
public void setRightBarButtonItem(String sceneId, @Nullable ReadableMap item) {
|
|
83
|
+
updateOptions(sceneId, item, "rightBarButtonItem");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Override
|
|
87
|
+
public void setLeftBarButtonItems(String sceneId, @Nullable ReadableArray items) {
|
|
88
|
+
updateOptions(sceneId, items, "leftBarButtonItems");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Override
|
|
92
|
+
public void setRightBarButtonItems(String sceneId, @Nullable ReadableArray items) {
|
|
93
|
+
updateOptions(sceneId, items, "rightBarButtonItems");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@Override
|
|
97
|
+
public void updateOptions(String sceneId, ReadableMap options) {
|
|
98
|
+
FLog.i(TAG, "update options:" + options);
|
|
99
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
100
|
+
HybridFragment fragment = findHybridFragmentBySceneId(sceneId);
|
|
101
|
+
if (fragment != null) {
|
|
102
|
+
fragment.getGarden().updateOptions(options);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@Override
|
|
108
|
+
public void updateTabBar(String sceneId, ReadableMap item) {
|
|
109
|
+
FLog.i(TAG, "updateTabBar:" + item);
|
|
110
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
111
|
+
TabBarFragment tabBarFragment = getTabBarFragment(sceneId);
|
|
112
|
+
if (tabBarFragment == null) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
Bundle bundle = new Bundle();
|
|
117
|
+
bundle.putString(ARG_ACTION, ACTION_UPDATE_TAB_BAR);
|
|
118
|
+
bundle.putBundle(ARG_OPTIONS, toBundle(item));
|
|
119
|
+
tabBarFragment.updateTabBar(bundle);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@Override
|
|
124
|
+
public void setTabItem(String sceneId, ReadableArray options) {
|
|
125
|
+
FLog.i(TAG, "setTabItem:" + options);
|
|
126
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
127
|
+
TabBarFragment tabBarFragment = getTabBarFragment(sceneId);
|
|
128
|
+
if (tabBarFragment == null) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
Bundle bundle = new Bundle();
|
|
133
|
+
bundle.putString(ARG_ACTION, ACTION_SET_TAB_ITEM);
|
|
134
|
+
bundle.putSerializable(ARG_OPTIONS, toList(options));
|
|
135
|
+
tabBarFragment.updateTabBar(bundle);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@Override
|
|
140
|
+
public void setMenuInteractive(String sceneId, boolean enabled) {
|
|
141
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
142
|
+
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
143
|
+
if (fragment == null) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
DrawerFragment drawerFragment = fragment.getDrawerFragment();
|
|
148
|
+
if (drawerFragment == null) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
drawerFragment.setMenuInteractive(enabled);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private void updateOptions(String sceneId, @Nullable ReadableMap readableMap, String key) {
|
|
157
|
+
WritableMap writableMap = new JavaOnlyMap();
|
|
158
|
+
if (readableMap == null) {
|
|
159
|
+
writableMap.putNull(key);
|
|
160
|
+
} else {
|
|
161
|
+
writableMap.putMap(key, readableMap);
|
|
162
|
+
}
|
|
163
|
+
updateOptions(sceneId, writableMap);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private void updateOptions(String sceneId, @Nullable ReadableArray readableArray, String key) {
|
|
167
|
+
WritableMap writableMap = new JavaOnlyMap();
|
|
168
|
+
if (readableArray == null) {
|
|
169
|
+
writableMap.putNull(key);
|
|
170
|
+
} else {
|
|
171
|
+
writableMap.putArray(key, readableArray);
|
|
172
|
+
}
|
|
173
|
+
updateOptions(sceneId, writableMap);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@Nullable
|
|
177
|
+
private ReactAppCompatActivity getActiveActivity() {
|
|
178
|
+
ReactContext reactContext = getReactApplicationContext();
|
|
179
|
+
if (!reactContext.hasActiveReactInstance()) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
Activity activity = reactContext.getCurrentActivity();
|
|
184
|
+
if (activity instanceof ReactAppCompatActivity) {
|
|
185
|
+
return (ReactAppCompatActivity) activity;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private HybridFragment findHybridFragmentBySceneId(String sceneId) {
|
|
192
|
+
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
193
|
+
if (fragment instanceof HybridFragment) {
|
|
194
|
+
return (HybridFragment) fragment;
|
|
195
|
+
}
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
private AwesomeFragment findFragmentBySceneId(String sceneId) {
|
|
200
|
+
if (!reactManager.isViewHierarchyReady()) {
|
|
201
|
+
FLog.w(TAG, "View hierarchy is not ready now.");
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
ReactAppCompatActivity activity = getActiveActivity();
|
|
206
|
+
if (activity == null) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
211
|
+
return FragmentHelper.findAwesomeFragment(fragmentManager, sceneId);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
@Nullable
|
|
215
|
+
private TabBarFragment getTabBarFragment(String sceneId) {
|
|
216
|
+
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
217
|
+
if (fragment != null) {
|
|
218
|
+
return fragment.getTabBarFragment();
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
}
|