[android] receive dynamic links support

This commit is contained in:
Omer Levy 2017-09-25 12:19:21 +03:00
parent d4a1304bea
commit 79d18e95e0
1 changed files with 18 additions and 7 deletions

View File

@ -9,6 +9,7 @@ import android.util.Log;
import java.util.Map; import java.util.Map;
import com.facebook.react.bridge.ActivityEventListener; import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactContextBaseJavaModule;
@ -27,14 +28,14 @@ import com.google.android.gms.tasks.OnFailureListener;
import io.invertase.firebase.Utils; import io.invertase.firebase.Utils;
public class RNFirebaseLinks extends ReactContextBaseJavaModule implements ActivityEventListener { public class RNFirebaseLinks extends ReactContextBaseJavaModule implements ActivityEventListener ,LifecycleEventListener {
private final static String TAG = RNFirebaseLinks.class.getCanonicalName(); private final static String TAG = RNFirebaseLinks.class.getCanonicalName();
private String initialLink = null; private String initialLink = null;
public RNFirebaseLinks(ReactApplicationContext reactContext) { public RNFirebaseLinks(ReactApplicationContext reactContext) {
super(reactContext); super(reactContext);
//getReactApplicationContext().addActivityEventListener(this); getReactApplicationContext().addActivityEventListener(this);
//registerLinksHandler(); getReactApplicationContext().addLifecycleEventListener(this);
} }
@Override @Override
@ -52,7 +53,6 @@ public class RNFirebaseLinks extends ReactContextBaseJavaModule implements Activ
if (activity == null) { if (activity == null) {
return; return;
} }
FirebaseDynamicLinks.getInstance() FirebaseDynamicLinks.getInstance()
.getDynamicLink(activity.getIntent()) .getDynamicLink(activity.getIntent())
.addOnSuccessListener(activity, new OnSuccessListener<PendingDynamicLinkData>() { .addOnSuccessListener(activity, new OnSuccessListener<PendingDynamicLinkData>() {
@ -62,10 +62,10 @@ public class RNFirebaseLinks extends ReactContextBaseJavaModule implements Activ
if (pendingDynamicLinkData != null) { if (pendingDynamicLinkData != null) {
Uri deepLinkUri = pendingDynamicLinkData.getLink(); Uri deepLinkUri = pendingDynamicLinkData.getLink();
String deepLink = deepLinkUri.toString(); String deepLink = deepLinkUri.toString();
// TODO: Validate that this is called when opening from a deep link
if (initialLink == null) { if (initialLink == null) {
initialLink = deepLink; initialLink = deepLink;
} }
Log.d(TAG, "sending a dynamic_link_received event!");
Utils.sendEvent(getReactApplicationContext(), "dynamic_link_received", deepLink); Utils.sendEvent(getReactApplicationContext(), "dynamic_link_received", deepLink);
} }
} }
@ -84,8 +84,19 @@ public class RNFirebaseLinks extends ReactContextBaseJavaModule implements Activ
} }
@Override @Override
public void onNewIntent(Intent intent) { public void onNewIntent(Intent intent) {}
// TODO: Do I need to re-register the links handler for each new intent?
@Override
public void onHostResume() {
registerLinksHandler();
}
@Override
public void onHostPause() {}
@Override
public void onHostDestroy() {
initialLink = null;
} }
@ReactMethod @ReactMethod