Bug Fix: Android app not focused when using urlHandler or customActionHandler #79
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #76.
I went tracing through this and iterable/iterable-android-sdk to figure out why we had some many issues with our Android app not bring brought into focus. I'll lay out what I found here, starting at the top level.
The actual
config.customActionHandler
you assign is fired here, viaRNEventEmitter
. Note that nothing is actually done with the return value from your JS handler.The event which executes the above is triggered in native Android here. The key issue here is this function always returns
true
, which tells the native code that any custom urls/actions are always handled. This also happens for urls.The above function is called here, where if we have a
customActionHandler
defined, then we return the result of the above (which as we saw, is alwaystrue
). Otherwise we returnfalse
.The problem comes here, where we execute the action, and if
handled === true
than we don't bring the app into focus. I believe this may have been doing sensibly for nativeAndroid
apps, where they want to intercept a URL/action and can easily bring the app into foreground. However this is not the same for RN, as this code need to be run on native side.I initially created a fork of
iterable/iterable-android-sdk
which fixed the issue, but I later realize it would likely to be easier to fix for the RN use case, without breaking changes to the existingiterable-android-sdk
, if we made the changes in this PR.