Skip to content

Instantly share code, notes, and snippets.

@aniltirola
Created August 20, 2018 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aniltirola/11dbe26f464bba315219d7ff5fe5e1bd to your computer and use it in GitHub Desktop.
Save aniltirola/11dbe26f464bba315219d7ff5fe5e1bd to your computer and use it in GitHub Desktop.
expo deeplinking in android detached app fires multiple times when app in background
import React from 'react';
import { StyleSheet, Text, View, Linking } from 'react-native';
export default class App extends React.Component {
componentDidMount() {
this._getInitialUrl();
Linking.addEventListener('url', this._handleDeepURL);
}
componentWillUnmount() {
Linking.removeEventListener('url', this._handleDeepURL);
}
_getInitialUrl = async () => {
try {
const url = await Linking.getInitialURL()
console.log(this._getConsolePrefix() + '_getInitialUrl', url)
}
catch (e) {
console.log(this._getConsolePrefix() + 'error in _getInitialUrl:', e)
}
}
_handleDeepURL = e => {
console.log(this._getConsolePrefix() + '_handleDeepURL', e)
}
_getConsolePrefix = () => {
const date = new Date();
return date.toLocaleTimeString() + ':' + date.getMilliseconds() + ':';
}
render() {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment