Adyen / adyen-react-native

Adyen React Native
https://docs.adyen.com/checkout
MIT License
42 stars 32 forks source link

Expo plugin breaks universal links on iOS and expo-router #453

Closed kpoelhekke closed 1 month ago

kpoelhekke commented 1 month ago

Describe the bug Whenever you use the Expo plugin to generate iOS native code the universial links to our application stop working whenever the app is open. When the app is hard closed the universal links work as expected.

We use links like: https://example.com/screen2

It seems like the codemod to change the continueUserActivity delegating the link to the ADYRedirectComponent which cannot handle it and then it stops.

To Reproduce Steps to reproduce the behavior:

  1. Create an Expo app with expo-router
  2. Use the Expo plugin to generate the iOS specific code
  3. Setup a domain in ios.associatedDomains in app.config.ts
  4. Setup the universal linking config for that domain itself
  5. Notice that the links don't work anymore when the app is already open

Expected behavior It should just continue delegating the url to the application itself whenever ADYRedirectComponent cannot handle it

Additional context We've managed to bypass it by patching the plugin, but I'm not really sure if this can give unintended behavior for Adyen specific links and if this is the cleanest way to implement it:

diff --git a/plugin/build/setApplicationContinueUserActivity.js b/plugin/build/setApplicationContinueUserActivity.js
index 2567e63a0cc237d05bb84b5015674d672db11c8b..2fe7b7d6b482e0290b3970f71e2d4f9eeaf28299 100644
--- a/plugin/build/setApplicationContinueUserActivity.js
+++ b/plugin/build/setApplicationContinueUserActivity.js
@@ -7,7 +7,7 @@ function setApplicationContinueUserActivity(contents) {
             '  if ([[userActivity activityType] isEqualToString:NSUserActivityTypeBrowsingWeb]) {\n' +
             '   NSURL *url = [userActivity webpageURL];\n' +
             '    if (![url isEqual:[NSNull null]]) {\n' +
-            '      return [ADYRedirectComponent applicationDidOpenURL:url];\n' +
+            '      [ADYRedirectComponent applicationDidOpenURL:url];\n' +
             '    }\n' +
             '  }\n');
     }
@@ -17,7 +17,7 @@ function setApplicationContinueUserActivity(contents) {
             '  if ([[userActivity activityType] isEqualToString:NSUserActivityTypeBrowsingWeb]) {\n' +
             '    NSURL *url = [userActivity webpageURL];\n' +
             '    if (![url isEqual:[NSNull null]]) {\n' +
-            '      return [ADYRedirectComponent applicationDidOpenURL:url];\n' +
+            '      [ADYRedirectComponent applicationDidOpenURL:url];\n' +
             '    }\n' +
             '  }\n' +
             '  return [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler];\n' +
descorp commented 1 month ago

Hey @kpoelhekke

Thank for feedback. We haven't check our plugin compatibility with expo-router yet.

It should just continue delegating the url to the application itself whenever ADYRedirectComponent cannot handle it

Correct. Best strategy would be to chain them:

return [ADYRedirectComponent applicationDidOpenURL:url] || {All other redirects};

However default code [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler] takes all parameters and makes thing bit more complicated.

You can try following to avoid unexpected side-effects:

 '    if (![url isEqual:[NSNull null]] && [ADYRedirectComponent applicationDidOpenURL:url]) {\n' +
 '      return YES;\n' +
 '    }\n' +
descorp commented 1 month ago

PR #455

kpoelhekke commented 1 month ago

Thanks for the quick action! I've implemented the change and can confirm it works as expected!

descorp commented 1 month ago

Released on v2.0.0

Thanks @kpoelhekke 💚 I am going to close this ticket