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

Add deep linking support to IntentAndroid #4320

Closed
wants to merge 7 commits into from
Closed

Add deep linking support to IntentAndroid #4320

wants to merge 7 commits into from

Conversation

satya164
Copy link
Contributor

Add a method to handle URLs registered to the app,

IntentAndroid.getInitialURL(url => {
    if (url) {
        // do stuff
    }
});

Refer - http://developer.android.com/training/app-indexing/deep-linking.html#adding-filters

The API cannot be same as the iOS API (i.e. as a constant), as the activity is not availble at the time of module initialization. Moreover, multiple activties can share the same bridge instance, and the activity itself is not a constant. Hence the initialURL can change.

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @mkonicek, @corbt and @satya164 to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Nov 24, 2015
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();

Intent intent = ((Activity) mActivityContext).getIntent();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not mActivity.getIntent() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no mActivity here! O.o

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just change all (activity's) Context to Activity class

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it should be a Activity instance.

@mkonicek
Copy link
Contributor

Nice! Thanks for working on this!

@satya164
Copy link
Contributor Author

@mkonicek Thanks. Waiting for the Dialog commit before I change anything here :D

@facebook-github-bot
Copy link
Contributor

@satya164 updated the pull request.

2 similar comments
@facebook-github-bot
Copy link
Contributor

@satya164 updated the pull request.

@facebook-github-bot
Copy link
Contributor

@satya164 updated the pull request.

@facebook-github-bot
Copy link
Contributor

@satya164 updated the pull request.

@facebook-github-bot
Copy link
Contributor

@satya164 updated the pull request.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@satya164 updated the pull request.

@satya164
Copy link
Contributor Author

satya164 commented Dec 4, 2015

@mkonicek I've updated the PR using getCurrentActivity() implemented in c06efc0.

However, the current activity is only set on onResume, so it's not available while calling getConstants method, to have a consistent API between iOS and Android we need that. I've added a method to set the current activity and added the code to the generator to set the activity in onCreate. It's backward compatible, but if someone wants the deep linking feature, and has created the project with the old template, he'll need to manually add the code required.

I'm not sure if it's the best approach though. Please have a look and lemme know.

cc @foghina

@mkonicek
Copy link
Contributor

mkonicek commented Dec 9, 2015

Just pinged @foghina, thanks for the patience. Many PRs in the queue and branch cut..


constants.put("initialURL", initialURL);

return constants;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable - the process could be started by an intent.

@foghina
Copy link
Contributor

foghina commented Dec 10, 2015

I don't like exposing setActivity on ReactInstanceManager.Builder. This sets the expectation that the activity will never change, but in fact, it can change. This is why it's called getCurrentActivity() and not getActivity(). Also, exposing the intent URL as a constant furthers this assumption and will break when you change activities without recreating the ReactContext.

Since the JS API is only similar but not identical and since the JS API is a function call anyway (IntentAndroid.popInitialURL()), you can easily rewrite it to call into a native method, instead of reading a native constant. Then all the changes in ReactInstanceManager and co. become unnecessary.

Exposing constants has bitten us in the past (see screen size), they should only be used for things that are really constant.

@satya164
Copy link
Contributor Author

@foghina @mkonicek Should I change this to a function getInitialURL which takes a callback then?

Note that this then diverges from the iOS API. Any thoughts on what should we do in the cross platform module?

@facebook-github-bot
Copy link
Contributor

@satya164 updated the pull request.

@facebook-github-bot
Copy link
Contributor

@satya164 updated the pull request.

@facebook-github-bot
Copy link
Contributor

@satya164 updated the pull request.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@satya164 updated the pull request.

@facebook-github-bot
Copy link
Contributor

@satya164 updated the pull request.

@satya164
Copy link
Contributor Author

@foghina @mkonicek Changed to use a callback instead of a constant to get initial URl.

@facebook-github-bot
Copy link
Contributor

@satya164 updated the pull request.


callback.invoke(initialURL);
} catch (Exception e) {
throw new JSApplicationIllegalArgumentException(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an error callback (all @ReactMethods have two callbacks) and call it here instead of throwing an exception? You should probably still log the full exception details, though, to make it easier to debug problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@foghina Was wondering the same thing. I kept it consistent with the canOpenURL method which is in the same file. It's really confusing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, darn. Then we can probably leave it as it is for the purposes of this PR but we should refactor this module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@foghina Yes, we should. I'll send another PR with the changes then, after this is merged.

@foghina
Copy link
Contributor

foghina commented Dec 15, 2015

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1658069957805935/int_phab to review.

@foghina
Copy link
Contributor

foghina commented Dec 15, 2015

@satya164 heads-up: patch failed internally because we don't mirror website/, so I had to remove the changes to that folder. Once this lands and is synced back you'll have to reapply your changes to website/. Sorry :(

@satya164
Copy link
Contributor Author

@foghina No probs. I'll send another PR with the website changes :)

@satya164 satya164 closed this in eb188c8 Dec 15, 2015
@satya164 satya164 deleted the intent branch December 30, 2015 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants