mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-09 22:43:10 +08:00
Hook up Android intent to Linking.js #7079
Summary: Fixed #7118 by rreusser Closes https://github.com/facebook/react-native/pull/7940 Differential Revision: D3391586 fbshipit-source-id: f7e572a91347fb0629602374cb6944eabf5b0e8f
This commit is contained in:
committed by
Facebook Github Bot 0
parent
a966c85fce
commit
c36430a0d6
@@ -227,4 +227,13 @@ public abstract class ReactActivity extends Activity implements DefaultHardwareB
|
||||
public void invokeDefaultOnBackPressed() {
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewIntent(Intent intent) {
|
||||
if (mReactInstanceManager != null) {
|
||||
mReactInstanceManager.onNewIntent(intent);
|
||||
} else {
|
||||
super.onNewIntent(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,11 @@ public abstract class ReactInstanceManager {
|
||||
*/
|
||||
public abstract void onBackPressed();
|
||||
|
||||
/**
|
||||
* This method will give JS the opportunity to receive intents via Linking.
|
||||
*/
|
||||
public abstract void onNewIntent(Intent intent);
|
||||
|
||||
/**
|
||||
* Call this from {@link Activity#onPause()}. This notifies any listening modules so they can do
|
||||
* any necessary cleanup.
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
@@ -466,6 +467,22 @@ import static com.facebook.react.bridge.ReactMarkerConstants.RUN_JS_BUNDLE_START
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewIntent(Intent intent) {
|
||||
if (mCurrentReactContext == null) {
|
||||
FLog.w(ReactConstants.TAG, "Instance detached from instance manager");
|
||||
} else {
|
||||
String action = intent.getAction();
|
||||
Uri uri = intent.getData();
|
||||
|
||||
if (Intent.ACTION_VIEW.equals(action) && uri != null) {
|
||||
DeviceEventManagerModule deviceEventManagerModule =
|
||||
Assertions.assertNotNull(mCurrentReactContext).getNativeModule(DeviceEventManagerModule.class);
|
||||
deviceEventManagerModule.emitNewIntentReceived(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleElementInspector() {
|
||||
if (mCurrentReactContext != null) {
|
||||
mCurrentReactContext
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
@@ -57,6 +58,7 @@ import com.facebook.react.devsupport.DevServerHelper;
|
||||
import com.facebook.react.devsupport.DevSupportManager;
|
||||
import com.facebook.react.devsupport.DevSupportManagerFactory;
|
||||
import com.facebook.react.devsupport.ReactInstanceDevCommandsHandler;
|
||||
import com.facebook.react.devsupport.RedBoxHandler;
|
||||
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
||||
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
||||
import com.facebook.react.modules.debug.DeveloperSettings;
|
||||
@@ -67,10 +69,7 @@ import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import com.facebook.systrace.Systrace;
|
||||
import com.facebook.react.devsupport.RedBoxHandler;
|
||||
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.BUILD_JS_MODULE_CONFIG_END;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.BUILD_JS_MODULE_CONFIG_START;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.BUILD_NATIVE_MODULE_REGISTRY_END;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.BUILD_NATIVE_MODULE_REGISTRY_START;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_CATALYST_INSTANCE_END;
|
||||
@@ -476,6 +475,22 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewIntent(Intent intent) {
|
||||
if (mCurrentReactContext == null) {
|
||||
FLog.w(ReactConstants.TAG, "Instance detached from instance manager");
|
||||
} else {
|
||||
String action = intent.getAction();
|
||||
Uri uri = intent.getData();
|
||||
|
||||
if (Intent.ACTION_VIEW.equals(action) && uri != null) {
|
||||
DeviceEventManagerModule deviceEventManagerModule =
|
||||
Assertions.assertNotNull(mCurrentReactContext).getNativeModule(DeviceEventManagerModule.class);
|
||||
deviceEventManagerModule.emitNewIntentReceived(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleElementInspector() {
|
||||
if (mCurrentReactContext != null) {
|
||||
mCurrentReactContext
|
||||
|
||||
@@ -11,6 +11,8 @@ package com.facebook.react.modules.core;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
@@ -52,6 +54,15 @@ public class DeviceEventManagerModule extends ReactContextBaseJavaModule {
|
||||
.emit("hardwareBackPress", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an event to the JS instance that a new intent was received.
|
||||
*/
|
||||
public void emitNewIntentReceived(Uri uri) {
|
||||
getReactApplicationContext()
|
||||
.getJSModule(RCTDeviceEventEmitter.class)
|
||||
.emit("url", uri.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes the default back handler for the host of this catalyst instance. This should be invoked
|
||||
* if JS does not want to handle the back press itself.
|
||||
|
||||
Reference in New Issue
Block a user