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
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
package com.reactnative.hybridnavigation;
|
|
2
|
-
|
|
3
|
-
import androidx.annotation.NonNull;
|
|
4
|
-
import androidx.annotation.Nullable;
|
|
5
|
-
|
|
6
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
-
import com.facebook.react.bridge.ReactContext;
|
|
8
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
9
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
10
|
-
import com.facebook.react.bridge.WritableMap;
|
|
11
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
12
|
-
|
|
13
|
-
import java.util.HashMap;
|
|
14
|
-
import java.util.Map;
|
|
15
|
-
|
|
16
|
-
public class HBDEventEmitter extends ReactContextBaseJavaModule {
|
|
17
|
-
|
|
18
|
-
public static final String KEY_REQUEST_CODE = "request_code";
|
|
19
|
-
public static final String KEY_RESULT_CODE = "result_code";
|
|
20
|
-
public static final String KEY_RESULT_DATA = "data";
|
|
21
|
-
public static final String KEY_SCENE_ID = "scene_id";
|
|
22
|
-
public static final String KEY_MODULE_NAME = "module_name";
|
|
23
|
-
public static final String KEY_INDEX = "index";
|
|
24
|
-
public static final String KEY_ACTION = "action";
|
|
25
|
-
public static final String KEY_ON = "on";
|
|
26
|
-
|
|
27
|
-
public static final String ON_COMPONENT_RESULT = "ON_COMPONENT_RESULT";
|
|
28
|
-
public static final String ON_BAR_BUTTON_ITEM_CLICK = "ON_BAR_BUTTON_ITEM_CLICK";
|
|
29
|
-
public static final String ON_COMPONENT_APPEAR = "ON_COMPONENT_APPEAR";
|
|
30
|
-
public static final String ON_COMPONENT_DISAPPEAR = "ON_COMPONENT_DISAPPEAR";
|
|
31
|
-
|
|
32
|
-
public static final String EVENT_SWITCH_TAB = "EVENT_SWITCH_TAB";
|
|
33
|
-
public static final String EVENT_DID_SET_ROOT = "EVENT_DID_SET_ROOT";
|
|
34
|
-
public static final String EVENT_WILL_SET_ROOT = "EVENT_WILL_SET_ROOT";
|
|
35
|
-
public static final String EVENT_NAVIGATION = "EVENT_NAVIGATION";
|
|
36
|
-
|
|
37
|
-
public HBDEventEmitter(ReactApplicationContext reactContext) {
|
|
38
|
-
super(reactContext);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@NonNull
|
|
42
|
-
@Override
|
|
43
|
-
public String getName() {
|
|
44
|
-
return "HBDEventEmitter";
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@Nullable
|
|
48
|
-
@Override
|
|
49
|
-
public Map<String, Object> getConstants() {
|
|
50
|
-
final Map<String, Object> constants = new HashMap<>();
|
|
51
|
-
constants.put("ON_COMPONENT_RESULT", ON_COMPONENT_RESULT);
|
|
52
|
-
constants.put("ON_BAR_BUTTON_ITEM_CLICK", ON_BAR_BUTTON_ITEM_CLICK);
|
|
53
|
-
constants.put("ON_COMPONENT_APPEAR", ON_COMPONENT_APPEAR);
|
|
54
|
-
constants.put("ON_COMPONENT_DISAPPEAR", ON_COMPONENT_DISAPPEAR);
|
|
55
|
-
constants.put("KEY_REQUEST_CODE", KEY_REQUEST_CODE);
|
|
56
|
-
constants.put("KEY_RESULT_CODE", KEY_RESULT_CODE);
|
|
57
|
-
constants.put("KEY_RESULT_DATA", KEY_RESULT_DATA);
|
|
58
|
-
constants.put("KEY_SCENE_ID", KEY_SCENE_ID);
|
|
59
|
-
constants.put("KEY_MODULE_NAME", KEY_MODULE_NAME);
|
|
60
|
-
constants.put("KEY_INDEX", KEY_INDEX);
|
|
61
|
-
constants.put("KEY_ACTION", KEY_ACTION);
|
|
62
|
-
constants.put("KEY_ON", KEY_ON);
|
|
63
|
-
constants.put("EVENT_SWITCH_TAB", EVENT_SWITCH_TAB);
|
|
64
|
-
constants.put("EVENT_NAVIGATION", EVENT_NAVIGATION);
|
|
65
|
-
constants.put("EVENT_DID_SET_ROOT", EVENT_DID_SET_ROOT);
|
|
66
|
-
constants.put("EVENT_WILL_SET_ROOT", EVENT_WILL_SET_ROOT);
|
|
67
|
-
return constants;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@ReactMethod
|
|
71
|
-
public void addListener(String eventType) {
|
|
72
|
-
// do nothing
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@ReactMethod
|
|
76
|
-
public void removeListeners(int count) {
|
|
77
|
-
// do nothing
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public static void sendEvent(@NonNull String eventName, @NonNull WritableMap params) {
|
|
81
|
-
ReactBridgeManager bridgeManager = ReactBridgeManager.get();
|
|
82
|
-
ReactContext reactContext = bridgeManager.getCurrentReactContext();
|
|
83
|
-
if (reactContext != null && reactContext.hasActiveCatalystInstance() && bridgeManager.isReactModuleRegisterCompleted()) {
|
|
84
|
-
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
85
|
-
.emit(eventName, params);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
package com.reactnative.hybridnavigation;
|
|
2
|
-
|
|
3
|
-
import android.annotation.SuppressLint;
|
|
4
|
-
import android.content.Context;
|
|
5
|
-
import android.os.Bundle;
|
|
6
|
-
import android.util.AttributeSet;
|
|
7
|
-
import android.view.MotionEvent;
|
|
8
|
-
|
|
9
|
-
import androidx.annotation.Nullable;
|
|
10
|
-
|
|
11
|
-
import com.facebook.react.ReactRootView;
|
|
12
|
-
|
|
13
|
-
public class HBDReactRootView extends ReactRootView {
|
|
14
|
-
|
|
15
|
-
protected static final String TAG = "Navigation";
|
|
16
|
-
|
|
17
|
-
public HBDReactRootView(Context context) {
|
|
18
|
-
super(context);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public HBDReactRootView(Context context, AttributeSet attrs) {
|
|
22
|
-
super(context, attrs);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public HBDReactRootView(Context context, AttributeSet attrs, int defStyle) {
|
|
26
|
-
super(context, attrs, defStyle);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private boolean shouldConsumeTouchEvent = true;
|
|
30
|
-
|
|
31
|
-
public void setShouldConsumeTouchEvent(boolean consume) {
|
|
32
|
-
this.shouldConsumeTouchEvent = consume;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@SuppressLint("ClickableViewAccessibility")
|
|
36
|
-
@Override
|
|
37
|
-
public boolean onTouchEvent(MotionEvent ev) {
|
|
38
|
-
int action = ev.getAction() & MotionEvent.ACTION_MASK;
|
|
39
|
-
if (action == MotionEvent.ACTION_DOWN) {
|
|
40
|
-
onChildStartedNativeGesture(ev);
|
|
41
|
-
}
|
|
42
|
-
return shouldConsumeTouchEvent;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 避免 reload 时,重复 run 的问题
|
|
46
|
-
private boolean shouldRunApplication = true;
|
|
47
|
-
|
|
48
|
-
@Override
|
|
49
|
-
public void runApplication() {
|
|
50
|
-
if (shouldRunApplication) {
|
|
51
|
-
shouldRunApplication = false;
|
|
52
|
-
super.runApplication();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private boolean hbd_isAttachedToReactInstance;
|
|
57
|
-
|
|
58
|
-
@Override
|
|
59
|
-
public void onAttachedToReactInstance() {
|
|
60
|
-
super.onAttachedToReactInstance();
|
|
61
|
-
hbd_isAttachedToReactInstance = true;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
@Override
|
|
65
|
-
public void setAppProperties(@Nullable Bundle appProperties) {
|
|
66
|
-
if (hbd_isAttachedToReactInstance) {
|
|
67
|
-
shouldRunApplication = true;
|
|
68
|
-
super.setAppProperties(appProperties);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
package com.reactnative.hybridnavigation;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.os.Bundle;
|
|
5
|
-
|
|
6
|
-
import androidx.annotation.NonNull;
|
|
7
|
-
import androidx.annotation.Nullable;
|
|
8
|
-
import androidx.fragment.app.Fragment;
|
|
9
|
-
import androidx.fragment.app.FragmentManager;
|
|
10
|
-
|
|
11
|
-
import com.facebook.common.logging.FLog;
|
|
12
|
-
import com.facebook.react.bridge.Arguments;
|
|
13
|
-
import com.facebook.react.bridge.Callback;
|
|
14
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
15
|
-
import com.facebook.react.bridge.ReactContext;
|
|
16
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
17
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
18
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
19
|
-
import com.facebook.react.bridge.UiThreadUtil;
|
|
20
|
-
import com.navigation.androidx.AwesomeActivity;
|
|
21
|
-
import com.navigation.androidx.AwesomeFragment;
|
|
22
|
-
import com.navigation.androidx.FragmentHelper;
|
|
23
|
-
import com.navigation.androidx.TabBarFragment;
|
|
24
|
-
|
|
25
|
-
import java.util.ArrayList;
|
|
26
|
-
import java.util.HashMap;
|
|
27
|
-
import java.util.List;
|
|
28
|
-
import java.util.Map;
|
|
29
|
-
|
|
30
|
-
public class NavigationModule extends ReactContextBaseJavaModule {
|
|
31
|
-
|
|
32
|
-
static final String TAG = "Navigation";
|
|
33
|
-
private final ReactBridgeManager bridgeManager;
|
|
34
|
-
|
|
35
|
-
NavigationModule(ReactApplicationContext reactContext, ReactBridgeManager bridgeManager) {
|
|
36
|
-
super(reactContext);
|
|
37
|
-
this.bridgeManager = bridgeManager;
|
|
38
|
-
FLog.i(TAG, "NavigationModule#onCreate");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@Override
|
|
42
|
-
public void invalidate() {
|
|
43
|
-
FLog.i(TAG, "NavigationModule#invalidate");
|
|
44
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
45
|
-
bridgeManager.invalidate();
|
|
46
|
-
clearFragments();
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private void clearFragments() {
|
|
51
|
-
AwesomeActivity activity = getActiveActivity();
|
|
52
|
-
if (activity != null) {
|
|
53
|
-
activity.clearFragments();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@NonNull
|
|
58
|
-
@Override
|
|
59
|
-
public String getName() {
|
|
60
|
-
return "NavigationModule";
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@Nullable
|
|
64
|
-
@Override
|
|
65
|
-
public Map<String, Object> getConstants() {
|
|
66
|
-
HashMap<String, Object> constants = new HashMap<>();
|
|
67
|
-
constants.put("RESULT_OK", Activity.RESULT_OK);
|
|
68
|
-
constants.put("RESULT_CANCEL", Activity.RESULT_CANCELED);
|
|
69
|
-
constants.put("RESULT_BLOCK", -2);
|
|
70
|
-
return constants;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
@ReactMethod
|
|
74
|
-
public void startRegisterReactComponent() {
|
|
75
|
-
UiThreadUtil.runOnUiThread(bridgeManager::startRegisterReactModule);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
@ReactMethod
|
|
79
|
-
public void endRegisterReactComponent() {
|
|
80
|
-
UiThreadUtil.runOnUiThread(bridgeManager::endRegisterReactModule);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@ReactMethod
|
|
84
|
-
public void registerReactComponent(final String appKey, final ReadableMap options) {
|
|
85
|
-
UiThreadUtil.runOnUiThread(() -> bridgeManager.registerReactModule(appKey, options));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
@ReactMethod
|
|
89
|
-
public void signalFirstRenderComplete(final String sceneId) {
|
|
90
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
91
|
-
AwesomeActivity activity = getActiveActivity();
|
|
92
|
-
if (activity == null) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
activity.scheduleTaskAtStarted(() -> {
|
|
97
|
-
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
98
|
-
if (fragment instanceof ReactFragment) {
|
|
99
|
-
ReactFragment reactFragment = (ReactFragment) fragment;
|
|
100
|
-
reactFragment.signalFirstRenderComplete();
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
@ReactMethod
|
|
107
|
-
public void setRoot(final ReadableMap layout, final boolean sticky, final Callback callback) {
|
|
108
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
109
|
-
ReactContext reactContext = getReactApplicationContext();
|
|
110
|
-
if (reactContext == null || !reactContext.hasActiveCatalystInstance()) {
|
|
111
|
-
FLog.w(TAG, "ReactContext hasn't active CatalystInstance, skip action `setRoot`");
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (bridgeManager.getPendingCallback() != null) {
|
|
116
|
-
bridgeManager.getPendingCallback().invoke(null, false);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
bridgeManager.setViewHierarchyReady(false);
|
|
120
|
-
bridgeManager.setRootLayout(layout, sticky);
|
|
121
|
-
bridgeManager.setPendingLayout(layout, callback);
|
|
122
|
-
|
|
123
|
-
if (!bridgeManager.isReactModuleRegisterCompleted()) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
ReactAppCompatActivity activity = getActiveActivity();
|
|
128
|
-
if (activity != null && !activity.getSupportFragmentManager().isStateSaved()) {
|
|
129
|
-
FLog.i(TAG, "Have active Activity and React module was registered, set root Fragment immediately.");
|
|
130
|
-
activity.setActivityRootFragment(layout);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
@ReactMethod
|
|
136
|
-
public void dispatch(final String sceneId, final String action, final ReadableMap extras, Callback callback) {
|
|
137
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
138
|
-
AwesomeActivity activity = getActiveActivity();
|
|
139
|
-
if (activity == null) {
|
|
140
|
-
callback.invoke(null, false);
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
activity.scheduleTaskAtStarted(() -> {
|
|
145
|
-
AwesomeFragment target = findFragmentBySceneId(sceneId);
|
|
146
|
-
if (target == null) {
|
|
147
|
-
callback.invoke(null, false);
|
|
148
|
-
FLog.w(TAG, "Can't find target scene for action:" + action + ", maybe the scene is gone.\nextras: " + extras);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (!target.isAdded() || FragmentHelper.isRemoving(target)) {
|
|
153
|
-
callback.invoke(null, false);
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
bridgeManager.handleNavigation(target, action, extras, callback);
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
@ReactMethod
|
|
163
|
-
public void currentTab(final String sceneId, final Callback callback) {
|
|
164
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
165
|
-
AwesomeActivity activity = getActiveActivity();
|
|
166
|
-
if (activity == null) {
|
|
167
|
-
callback.invoke(null, -1);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
activity.scheduleTaskAtStarted(() -> {
|
|
172
|
-
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
173
|
-
if (fragment == null) {
|
|
174
|
-
callback.invoke(null, -1);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
TabBarFragment tabs = fragment.getTabBarFragment();
|
|
179
|
-
if (tabs == null) {
|
|
180
|
-
callback.invoke(null, -1);
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
callback.invoke(null, tabs.getSelectedIndex());
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
@ReactMethod
|
|
190
|
-
public void isStackRoot(final String sceneId, final Callback callback) {
|
|
191
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
192
|
-
AwesomeActivity activity = getActiveActivity();
|
|
193
|
-
if (activity == null) {
|
|
194
|
-
callback.invoke(null, -1);
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
activity.scheduleTaskAtStarted(() -> {
|
|
199
|
-
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
200
|
-
if (fragment == null) {
|
|
201
|
-
callback.invoke(null, false);
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
callback.invoke(null, fragment.isStackRoot());
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
@ReactMethod
|
|
210
|
-
public void setResult(final String sceneId, final int resultCode, final ReadableMap result) {
|
|
211
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
212
|
-
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
213
|
-
if (fragment != null) {
|
|
214
|
-
fragment.setResult(resultCode, Arguments.toBundle(result));
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
@ReactMethod
|
|
220
|
-
public void findSceneIdByModuleName(@NonNull String moduleName, Callback callback) {
|
|
221
|
-
final Runnable task = new Runnable() {
|
|
222
|
-
@Override
|
|
223
|
-
public void run() {
|
|
224
|
-
AwesomeActivity activity = getActiveActivity();
|
|
225
|
-
if (activity == null || !bridgeManager.isViewHierarchyReady()) {
|
|
226
|
-
UiThreadUtil.runOnUiThread(this, 16);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
activity.scheduleTaskAtStarted(() -> {
|
|
231
|
-
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
232
|
-
Fragment fragment = fragmentManager.findFragmentById(android.R.id.content);
|
|
233
|
-
if (!(fragment instanceof AwesomeFragment)) {
|
|
234
|
-
callback.invoke(null, null);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
String sceneId = findSceneIdByModuleName(moduleName, (AwesomeFragment) fragment);
|
|
239
|
-
FLog.i(TAG, "The sceneId found by " + moduleName + " : " + sceneId);
|
|
240
|
-
callback.invoke(null, sceneId);
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
UiThreadUtil.runOnUiThread(task);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
private String findSceneIdByModuleName(@NonNull String moduleName, AwesomeFragment parent) {
|
|
249
|
-
String sceneId = findSceneIdFromParent(moduleName, parent);
|
|
250
|
-
if (sceneId != null) {
|
|
251
|
-
return sceneId;
|
|
252
|
-
}
|
|
253
|
-
return findSceneIdFromChildren(moduleName, parent.getChildAwesomeFragments());
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
private String findSceneIdFromChildren(@NonNull String moduleName, List<AwesomeFragment> children) {
|
|
257
|
-
for (int i = 0; i < children.size(); i++) {
|
|
258
|
-
AwesomeFragment child = children.get(i);
|
|
259
|
-
String sceneId = findSceneIdByModuleName(moduleName, child);
|
|
260
|
-
if (sceneId != null) {
|
|
261
|
-
return sceneId;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return null;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
@Nullable
|
|
268
|
-
private String findSceneIdFromParent(@NonNull String moduleName, AwesomeFragment fragment) {
|
|
269
|
-
if (!(fragment instanceof HybridFragment)) {
|
|
270
|
-
return null;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
HybridFragment hybridFragment = (HybridFragment) fragment;
|
|
274
|
-
if (moduleName.equals(hybridFragment.getModuleName())) {
|
|
275
|
-
return hybridFragment.getSceneId();
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
@ReactMethod
|
|
282
|
-
public void currentRoute(final Callback callback) {
|
|
283
|
-
Runnable task = new Runnable() {
|
|
284
|
-
@Override
|
|
285
|
-
public void run() {
|
|
286
|
-
AwesomeActivity activity = getActiveActivity();
|
|
287
|
-
if (activity == null || !bridgeManager.isViewHierarchyReady()) {
|
|
288
|
-
UiThreadUtil.runOnUiThread(this, 16);
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
activity.scheduleTaskAtStarted(() -> {
|
|
293
|
-
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
294
|
-
HybridFragment current = bridgeManager.primaryFragment(fragmentManager);
|
|
295
|
-
if (current == null) {
|
|
296
|
-
UiThreadUtil.runOnUiThread(this, 16);
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
Bundle bundle = new Bundle();
|
|
301
|
-
bundle.putString("moduleName", current.getModuleName());
|
|
302
|
-
bundle.putString("sceneId", current.getSceneId());
|
|
303
|
-
bundle.putString("mode", Navigator.Util.getMode(current));
|
|
304
|
-
bundle.putString("presentingId", current.getPresentingSceneId());
|
|
305
|
-
bundle.putInt("requestCode", current.getRequestCode());
|
|
306
|
-
callback.invoke(null, Arguments.fromBundle(bundle));
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
UiThreadUtil.runOnUiThread(task);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
@ReactMethod
|
|
315
|
-
public void routeGraph(final Callback callback) {
|
|
316
|
-
Runnable task = new Runnable() {
|
|
317
|
-
@Override
|
|
318
|
-
public void run() {
|
|
319
|
-
AwesomeActivity activity = getActiveActivity();
|
|
320
|
-
if (activity == null || !bridgeManager.isViewHierarchyReady()) {
|
|
321
|
-
UiThreadUtil.runOnUiThread(this, 16);
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
activity.scheduleTaskAtStarted(() -> {
|
|
326
|
-
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
327
|
-
ArrayList<Bundle> graph = bridgeManager.buildRouteGraph(fragmentManager);
|
|
328
|
-
if (graph.isEmpty()) {
|
|
329
|
-
UiThreadUtil.runOnUiThread(this, 16);
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
callback.invoke(null, Arguments.fromList(graph));
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
UiThreadUtil.runOnUiThread(task);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
private AwesomeFragment findFragmentBySceneId(String sceneId) {
|
|
342
|
-
if (!bridgeManager.isViewHierarchyReady()) {
|
|
343
|
-
FLog.w(TAG, "View hierarchy is not ready now.");
|
|
344
|
-
return null;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
ReactAppCompatActivity activity = getActiveActivity();
|
|
348
|
-
if (activity == null) {
|
|
349
|
-
return null;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
353
|
-
return FragmentHelper.findAwesomeFragment(fragmentManager, sceneId);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
@Nullable
|
|
357
|
-
private ReactAppCompatActivity getActiveActivity() {
|
|
358
|
-
ReactContext reactContext = getReactApplicationContext();
|
|
359
|
-
if (reactContext == null || !reactContext.hasActiveCatalystInstance()) {
|
|
360
|
-
return null;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
Activity activity = reactContext.getCurrentActivity();
|
|
364
|
-
if (activity instanceof ReactAppCompatActivity) {
|
|
365
|
-
return (ReactAppCompatActivity) activity;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
return null;
|
|
369
|
-
}
|
|
370
|
-
}
|