-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitchTheme.js
77 lines (64 loc) · 1.66 KB
/
SwitchTheme.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
77
import React, { Component } from 'react'
import { styles } from './styles'
import { Picker } from 'react-native'
import { Theme, Text, View, withStyles } from 'react-native-themeable'
const redTheme = withStyles([
{
$type: Text,
color: 'black',
fontSize: 16,
}, {
$type: View,
backgroundColor: 'red',
},
])
const blueTheme = withStyles([
{
$type: Text,
color: 'white',
fontSize: 26,
}, {
$type: View,
backgroundColor: 'blue',
},
])
const greenTheme = withStyles([
{
$type: Text,
color: 'pink',
fontSize: 33,
}, {
$type: View,
backgroundColor: 'green',
},
])
const themes = { redTheme, greenTheme, blueTheme }
export default class SwitchTheme extends Component {
constructor(...args) {
super(...args)
this.state = { themeName: 'redTheme' }
this.onValueChange = this.onValueChange.bind(this)
}
onValueChange(themeName) {
this.setState({ themeName })
}
render() {
return (
<View style={styles.container}>
<Text style={styles.description}>
In this example you can switch theme dynamically by clicking picker:
</Text>
<Theme apply={themes[this.state.themeName]}>
<Picker onValueChange={this.onValueChange} selectedValue={this.state.themeName} style={{width: 100}}>
<Picker.Item label='red' value='redTheme' />
<Picker.Item label='green' value='greenTheme' />
<Picker.Item label='blue' value='blueTheme' />
</Picker>
<View style={{padding: 10}}>
<Text>Color and font size is defined by selected theme</Text>
</View>
</Theme>
</View>
)
}
}