-
Notifications
You must be signed in to change notification settings - Fork 3
/
ThemeApp.js
76 lines (70 loc) · 1.61 KB
/
ThemeApp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* @flow
*/
import React, { Component, Children } from 'react';
import {
StyleSheet,
Text,
View,
} from 'react-native';
import PropTypes from 'prop-types';
import ThemeProvider from './ThemeProvider';
import themeLight from './theme-light';
import themeDark from './theme-dark';
import Button from './Button';
export default class ThemeApp extends Component {
constructor(props) {
super(props)
this.state = {
theme: themeLight
}
}
handlePress = () => {
this.setState({
theme: this.state.theme === themeLight
? themeDark : themeLight
})
}
render() {
return (
<ThemeProvider theme={this.state.theme}>
<View style={styles.container}>
<View style={{
flexDirection: 'row',
}}>
<Button>left</Button>
<Button
style={{
flex: 1,
marginLeft: 0,
marginRight: 0,
}}
textStyle={{
textAlign: 'center',
}}
>center</Button>
<Button>right</Button>
</View>
<Button onPress={this.handlePress}>Change theme</Button>
<Text style={styles.instructions}>
Themes in React Native.
</Text>
</View>
</ThemeProvider>
);
}
}
const styles = StyleSheet.create({
container: {
marginTop: 30,
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
instructions: {
textAlign: 'center',
color: '#333333',
margin: 20,
},
});