Skip to content

Instantly share code, notes, and snippets.

@spencercarli
Created May 2, 2017 15:43
Show Gist options
  • Save spencercarli/a2ebb59f339ee4fe767f44c011e0aa92 to your computer and use it in GitHub Desktop.
Save spencercarli/a2ebb59f339ee4fe767f44c011e0aa92 to your computer and use it in GitHub Desktop.
// app/components/Container.js
import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
text: {
color: '#fff',
fontSize: 30,
fontWeight: '500',
},
});
const Container = ({ backgroundColor, onPress, children }) => (
<View style={[styles.container, { backgroundColor }]}>
<TouchableOpacity onPress={onPress}>
<Text style={styles.text}>{backgroundColor}</Text>
</TouchableOpacity>
{children}
</View>
);
export default Container;
// index.ios.js, index.android.js
import { AppRegistry } from 'react-native';
import App from './app/index';
AppRegistry.registerComponent('GettingStartedReactNativeNav', () => App);
// app/index.js
import React from 'react';
import Screen from './screens/Screen1';
export default Screen;
// app/screens/Screen1.js
import React, { Component } from 'react';
import { Text } from 'react-native';
import Container from '../components/Container';
class Screen extends Component {
render() {
return (
<Container
backgroundColor="#F44336"
onPress={() => console.log('press')}
/>
);
}
}
export default Screen;
// app/screens/Screen2.js
import React, { Component } from 'react';
import { Text } from 'react-native';
import Container from '../components/Container';
class Screen extends Component {
render() {
return (
<Container
backgroundColor="#c95e0c"
onPress={() => console.log('press')}
/>
);
}
}
export default Screen;
// app/screens/Screen3.js
import React, { Component } from 'react';
import { Text } from 'react-native';
import Container from '../components/Container';
class Screen extends Component {
render() {
return (
<Container
backgroundColor="#067a46"
onPress={() => console.log('press')}
/>
);
}
}
export default Screen;
// app/screens/Screen4.js
import React, { Component } from 'react';
import { Text } from 'react-native';
import Container from '../components/Container';
class Screen extends Component {
render() {
return (
<Container
backgroundColor="#01446b"
onPress={() => console.log('press')}
/>
);
}
}
export default Screen;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment