Last active
December 7, 2017 11:41
-
-
Save prabakarviji/abcb0c3cdb9be68f502c69ef4fac6779 to your computer and use it in GitHub Desktop.
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, { Component } from 'react'; | |
import { View, Linking, Platform } from 'react-native'; | |
class LinkingDemo extends Component { | |
constructor(props) { | |
super(props); | |
this.state = {}; | |
} | |
componentDidMount() { | |
if (Platform.OS === 'android') { | |
Linking.getInitialURL().then(url => { | |
this.navigate(url); | |
}); | |
} else { | |
Linking.addEventListener('url', this.handleNavigation); | |
} | |
} | |
componentWillUnmount() { | |
Linking.removeEventListener('url', this.handleNavigation); | |
} | |
handleNavigation = (event) => { | |
//Based on the link url from external app, navigate to specific page | |
(event.url === "link://exampleurl/details") ? this.goToDetailsPage() : this.goToHomePage() | |
} | |
render() { | |
return ( | |
<View style={{ flex: 1 }}> | |
... | |
</View> | |
); | |
} | |
} | |
export default LinkingDemo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment