Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use InteractionManager to wait for Activity #35289

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Libraries/Linking/Linking.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import type {EventSubscription} from '../vendor/emitter/EventEmitter';

import NativeEventEmitter from '../EventEmitter/NativeEventEmitter';
import InteractionManager from '../Interaction/InteractionManager';
import Platform from '../Utilities/Platform';
import NativeIntentAndroid from './NativeIntentAndroid';
import NativeLinkingManager from './NativeLinkingManager';
Expand Down Expand Up @@ -96,9 +95,7 @@ class Linking extends NativeEventEmitter<LinkingEventDefinitions> {
*/
getInitialURL(): Promise<?string> {
return Platform.OS === 'android'
? InteractionManager.runAfterInteractions().then(() =>
nullthrows(NativeIntentAndroid).getInitialURL(),
)
? nullthrows(NativeIntentAndroid).getInitialURL()
: nullthrows(NativeLinkingManager).getInitialURL();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import androidx.annotation.Nullable;
import com.facebook.fbreact.specs.NativeIntentAndroidSpec;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableArray;
Expand Down Expand Up @@ -50,18 +51,20 @@ public String getName() {
public void getInitialURL(Promise promise) {
try {
Activity currentActivity = getCurrentActivity();
String initialURL = null;
if (currentActivity == null) {
waitForActivityAndGetInitialURL(promise);
return;
}

if (currentActivity != null) {
Intent intent = currentActivity.getIntent();
String action = intent.getAction();
Uri uri = intent.getData();
Intent intent = currentActivity.getIntent();
String action = intent.getAction();
Uri uri = intent.getData();

if (uri != null
&& (Intent.ACTION_VIEW.equals(action)
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))) {
initialURL = uri.toString();
}
String initialURL = null;
if (uri != null
&& (Intent.ACTION_VIEW.equals(action)
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))) {
initialURL = uri.toString();
}

promise.resolve(initialURL);
Expand All @@ -72,6 +75,24 @@ public void getInitialURL(Promise promise) {
}
}

private void waitForActivityAndGetInitialURL(final Promise promise) {
final ReactApplicationContext context = getReactApplicationContext();
context.addLifecycleEventListener(
new LifecycleEventListener() {
@Override
public void onHostResume() {
getInitialURL(promise);
context.removeLifecycleEventListener(this);
}

@Override
public void onHostPause() {}

@Override
public void onHostDestroy() {}
});
}

/**
* Starts a corresponding external activity for the given URL.
*
Expand Down