Deep Linking Push Notifications with React Navigation #6
This file contains 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
// 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