Created
August 20, 2018 16:06
-
-
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
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
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