Skip to content

Instantly share code, notes, and snippets.

@khalid32
Last active June 24, 2017 13:55
Show Gist options
  • Select an option

  • Save khalid32/229610b0cd16b657644ad1008194e2b9 to your computer and use it in GitHub Desktop.

Select an option

Save khalid32/229610b0cd16b657644ad1008194e2b9 to your computer and use it in GitHub Desktop.
new native based react-navigation component for smooth navigation....
static navigationOptions = {
title: 'Welcome',
headerTintColor: 'white',
headerStyle: {
backgroundColor: 'red',
},
};
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View, Button } from 'react-native';
import { StackNavigator } from 'react-navigation';
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome',
};
render() {
const { navigate } = this.props.navigation;
return (
<View style={styles.container}>
<View style={[styles.adjust, {flex: 2, backgroundColor: '#68bc43'}]}>
<Text>Hello, Navigation!</Text>
</View>
<Button style={{flex:1}}
onPress={() => navigate('Chat', {user: 'Khalid'})}
title="Chat with.." />
</View>
);
}
}
class ChatScreen extends React.Component {
static navigationOptions = ({navigation}) =>({
title: `Chat with ${navigation.state.params.user}`,
});
render() {
const { params } = this.props.navigation.state;
return (
<View style={styles.container}>
<View style={[styles.adjust, {flex: 2, backgroundColor: '#c1bf38'}]}>
<Text>Chat with {params.user}</Text>
</View>
</View>
);
}
}
const SelfNavigation = StackNavigator({
Home: { screen: HomeScreen },
Chat: { screen: ChatScreen },
});
const styles = StyleSheet.create({
container:{
flex: 1,
},
adjust: {
justifyContent: 'center',
alignItems: 'center',
}
});
AppRegistry.registerComponent('SelfNavigation', () => SelfNavigation);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment