Skip to content

Commit

Permalink
Emit url device event in ReactActivityDelegate::onCreate (#45254)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #45254

Changelog:
[General][Changed] - Emit `url` device event in `ReactActivityDelegate::onCreate`.

Differential Revision: D59282348
  • Loading branch information
fabriziocucci authored and facebook-github-bot committed Jul 2, 2024
1 parent e35a2f4 commit b96b5af
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.net.Uri;
import android.nfc.NfcAdapter;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactNoCrashSoftException;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.modules.core.PermissionListener;

/**
Expand All @@ -27,6 +33,7 @@
* ReactApplication}.
*/
public class ReactActivityDelegate {
private static final String TAG = "ReactActivityDelegate";

private final @Nullable Activity mActivity;
private final @Nullable String mMainComponentName;
Expand Down Expand Up @@ -131,6 +138,7 @@ protected ReactRootView createRootView() {
if (mainComponentName != null) {
loadApp(mainComponentName);
}
emitUrlDeviceEventIfNecessary();
}

protected void loadApp(String appKey) {
Expand Down Expand Up @@ -231,4 +239,40 @@ protected boolean isFabricEnabled() {
protected boolean isWideColorGamutEnabled() {
return false;
}

private void emitUrlDeviceEventIfNecessary() {
ReactContext currentContext =
ReactFeatureFlags.enableBridgelessArchitecture
? getReactHost().getCurrentReactContext()
: getReactNativeHost().getReactInstanceManager().getCurrentReactContext();

if (currentContext == null) {
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"emitUrlDeviceEventIfNecessary: Tried to emit `url` event while context is null"));
return;
}

if (mActivity == null) {
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"emitUrlDeviceEventIfNecessary: Tried to emit `url` event while activity is null"));
return;
}

Intent intent = mActivity.getIntent();
String action = intent.getAction();
Uri uri = intent.getData();
if (uri != null
&& (Intent.ACTION_VIEW.equals(action)
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))) {
DeviceEventManagerModule deviceEventManagerModule =
currentContext.getNativeModule(DeviceEventManagerModule.class);
if (deviceEventManagerModule != null) {
deviceEventManagerModule.emitNewIntentReceived(uri);
}
}
}
}

0 comments on commit b96b5af

Please sign in to comment.