Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@diego3g
Created September 26, 2017 18:00
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 diego3g/42d79cd9448fcc56d3fa32f3d3994301 to your computer and use it in GitHub Desktop.
Save diego3g/42d79cd9448fcc56d3fa32f3d3994301 to your computer and use it in GitHub Desktop.
/* Core */
import React, { Component } from 'react';
/* Presentational */
import { View, Platform, Linking } from 'react-native';
export default class List extends Component {
async componentDidMount() {
if (Platform.OS === 'android') {
const url = await Linking.getInitialURL();
this.navigate(url);
} else {
Linking.addEventListener('url', this.handleOpenURL);
}
}
componentWillUnmount() {
Linking.removeEventListener('url', this.handleOpenURL);
}
handleOpenURL = (event) => {
this.navigate(event.url);
};
navigate = (url) => {
const { navigate } = this.props.navigation;
const route = url.replace(/.*?:\/\//g, '');
const recipe = route.match(/\/([^\/]+)\/?$/)[1];
const routeName = route.split('/')[0];
// routeName: recipe
// recipe: teste (parâmetro)
};
render() {
return <View />
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment