Created
October 23, 2023 17:59
-
-
Save SudoPlz/003d1f70a68034d5a9639d2d0dfca413 to your computer and use it in GitHub Desktop.
React-Native RCTLinking patch to never miss deep links
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/react-native/Libraries/LinkingIOS/RCTLinkingManager.mm b/node_modules/react-native/Libraries/LinkingIOS/RCTLinkingManager.mm | |
index cfa9078..6a3daf5 100644 | |
--- a/node_modules/react-native/Libraries/LinkingIOS/RCTLinkingManager.mm | |
+++ b/node_modules/react-native/Libraries/LinkingIOS/RCTLinkingManager.mm | |
@@ -18,15 +18,19 @@ | |
static void postNotificationWithURL(NSURL *URL, id sender) | |
{ | |
+ | |
NSDictionary<NSString *, id> *payload = @{@"url" : URL.absoluteString}; | |
[[NSNotificationCenter defaultCenter] postNotificationName:kOpenURLNotification object:sender userInfo:payload]; | |
} | |
@interface RCTLinkingManager () <NativeLinkingManagerSpec> | |
+ @property (nonatomic, strong) NSURL * lastDispatchedLink; | |
@end | |
@implementation RCTLinkingManager | |
+static NSURL *lastDispatchedLink; | |
+ | |
RCT_EXPORT_MODULE() | |
- (dispatch_queue_t)methodQueue | |
@@ -56,6 +60,7 @@ + (BOOL)application:(UIApplication *)app | |
openURL:(NSURL *)URL | |
options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options | |
{ | |
+ lastDispatchedLink = URL; | |
postNotificationWithURL(URL, self); | |
return YES; | |
} | |
@@ -167,6 +172,9 @@ - (void)handleOpenURLNotification:(NSNotification *)notification | |
self.bridge.launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey]; | |
if ([userActivityDictionary[UIApplicationLaunchOptionsUserActivityTypeKey] isEqual:NSUserActivityTypeBrowsingWeb]) { | |
initialURL = ((NSUserActivity *)userActivityDictionary[@"UIApplicationLaunchOptionsUserActivityKey"]).webpageURL; | |
+ } else if (initialURL == nil && lastDispatchedLink != nil) { | |
+ initialURL = lastDispatchedLink; | |
+ lastDispatchedLink = nil; | |
} | |
} | |
resolve(RCTNullIfNil(initialURL.absoluteString)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment