|
12 | 12 | import android.content.Intent;
|
13 | 13 | import android.content.pm.ActivityInfo;
|
14 | 14 | import android.content.res.Configuration;
|
| 15 | +import android.net.Uri; |
| 16 | +import android.nfc.NfcAdapter; |
15 | 17 | import android.os.Build;
|
16 | 18 | import android.os.Bundle;
|
17 | 19 | import android.view.KeyEvent;
|
18 | 20 | import androidx.annotation.Nullable;
|
19 | 21 | import com.facebook.infer.annotation.Assertions;
|
20 | 22 | import com.facebook.react.bridge.Callback;
|
| 23 | +import com.facebook.react.bridge.ReactContext; |
| 24 | +import com.facebook.react.bridge.ReactNoCrashSoftException; |
| 25 | +import com.facebook.react.bridge.ReactSoftExceptionLogger; |
21 | 26 | import com.facebook.react.config.ReactFeatureFlags;
|
| 27 | +import com.facebook.react.modules.core.DeviceEventManagerModule; |
22 | 28 | import com.facebook.react.modules.core.PermissionListener;
|
23 | 29 |
|
24 | 30 | /**
|
|
27 | 33 | * ReactApplication}.
|
28 | 34 | */
|
29 | 35 | public class ReactActivityDelegate {
|
| 36 | + private static final String TAG = "ReactActivityDelegate"; |
30 | 37 |
|
31 | 38 | private final @Nullable Activity mActivity;
|
32 | 39 | private final @Nullable String mMainComponentName;
|
@@ -131,6 +138,7 @@ protected ReactRootView createRootView() {
|
131 | 138 | if (mainComponentName != null) {
|
132 | 139 | loadApp(mainComponentName);
|
133 | 140 | }
|
| 141 | + emitUrlDeviceEventIfNecessary(); |
134 | 142 | }
|
135 | 143 |
|
136 | 144 | protected void loadApp(String appKey) {
|
@@ -231,4 +239,40 @@ protected boolean isFabricEnabled() {
|
231 | 239 | protected boolean isWideColorGamutEnabled() {
|
232 | 240 | return false;
|
233 | 241 | }
|
| 242 | + |
| 243 | + private void emitUrlDeviceEventIfNecessary() { |
| 244 | + ReactContext currentContext = |
| 245 | + ReactFeatureFlags.enableBridgelessArchitecture |
| 246 | + ? getReactHost().getCurrentReactContext() |
| 247 | + : getReactNativeHost().getReactInstanceManager().getCurrentReactContext(); |
| 248 | + |
| 249 | + if (currentContext == null) { |
| 250 | + ReactSoftExceptionLogger.logSoftException( |
| 251 | + TAG, |
| 252 | + new ReactNoCrashSoftException( |
| 253 | + "emitUrlDeviceEventIfNecessary: Tried to emit `url` event while context is null")); |
| 254 | + return; |
| 255 | + } |
| 256 | + |
| 257 | + if (mActivity == null) { |
| 258 | + ReactSoftExceptionLogger.logSoftException( |
| 259 | + TAG, |
| 260 | + new ReactNoCrashSoftException( |
| 261 | + "emitUrlDeviceEventIfNecessary: Tried to emit `url` event while activity is null")); |
| 262 | + return; |
| 263 | + } |
| 264 | + |
| 265 | + Intent intent = mActivity.getIntent(); |
| 266 | + String action = intent.getAction(); |
| 267 | + Uri uri = intent.getData(); |
| 268 | + if (uri != null |
| 269 | + && (Intent.ACTION_VIEW.equals(action) |
| 270 | + || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))) { |
| 271 | + DeviceEventManagerModule deviceEventManagerModule = |
| 272 | + currentContext.getNativeModule(DeviceEventManagerModule.class); |
| 273 | + if (deviceEventManagerModule != null) { |
| 274 | + deviceEventManagerModule.emitNewIntentReceived(uri); |
| 275 | + } |
| 276 | + } |
| 277 | + } |
234 | 278 | }
|
0 commit comments