Created
September 26, 2017 18:00
-
-
Save diego3g/42d79cd9448fcc56d3fa32f3d3994301 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
/* 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