Skip to content

Instantly share code, notes, and snippets.

@naishe
Created Dec 6, 2020
Embed
What would you like to do?
Deep Linking Push Notifications with React Navigation #6
// App.tsx
// only new changes shown, refer: https://gist.github.com/naishe/46dfb1e23612398e4bd525f03c001dd9
const linking: LinkingOptions = {
prefixes: ['myapp://', 'https://app.myapp.com'],
config: deepLinksConf,
async getInitialURL() { /* redacted */ },
subscribe(listener) {
const onReceiveURL = ({url}: {url: string}) => listener(url);
// Listen to incoming links from deep linking
Linking.addEventListener('url', onReceiveURL);
// Listen to firebase push notifications
const unsubscribeNotification = messaging().onNotificationOpenedApp(
(message) => {
const url = message?.data?.link;
if (url) {
// Any custom logic to check whether the URL needs to be handled
// Call the listener to let React Navigation handle the URL
listener(url);
}
},
);
return () => {
// Clean up the event listeners
Linking.removeEventListener('url', onReceiveURL);
unsubscribeNotification();
};
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment