Skip to content

Instantly share code, notes, and snippets.

@prabakarviji
Last active December 7, 2017 11:41
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 prabakarviji/abcb0c3cdb9be68f502c69ef4fac6779 to your computer and use it in GitHub Desktop.
Save prabakarviji/abcb0c3cdb9be68f502c69ef4fac6779 to your computer and use it in GitHub Desktop.
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