forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToolbarExample.js
137 lines (127 loc) · 3.25 KB
/
ToolbarExample.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* @flow */
import * as React from 'react';
import { View, Platform, StatusBar, StyleSheet } from 'react-native';
import {
Colors,
Switch,
Paragraph,
Toolbar,
ToolbarContent,
ToolbarAction,
ToolbarBackAction,
withTheme,
} from 'react-native-paper';
import type { Theme } from 'react-native-paper/types';
type Props = {
navigation: any,
theme: Theme,
};
const initialParams = {
showLeftIcon: true,
showSubtitle: true,
showSearchIcon: true,
showMoreIcon: true,
};
const MORE_ICON = Platform.OS === 'ios' ? 'more-horiz' : 'more-vert';
class ToolbarExample extends React.Component<Props> {
static title = 'Toolbar';
static navigationOptions = ({ navigation }) => {
const params = { ...initialParams, ...navigation.state.params };
return {
header: (
<Toolbar
dark
statusBarHeight={Platform.OS === 'ios' ? 20 : StatusBar.currentHeight}
>
{params.showLeftIcon && (
<ToolbarBackAction onPress={() => navigation.goBack()} />
)}
<ToolbarContent
title="Title"
subtitle={params.showSubtitle ? 'Subtitle' : null}
/>
{params.showSearchIcon && (
<ToolbarAction icon="search" onPress={() => {}} />
)}
{params.showMoreIcon && (
<ToolbarAction icon={MORE_ICON} onPress={() => {}} />
)}
</Toolbar>
),
};
};
render() {
const { navigation, theme: { colors: { background } } } = this.props;
const params = { ...initialParams, ...navigation.state.params };
return (
<View
style={[
styles.container,
{
backgroundColor: background,
},
]}
>
<View style={styles.row}>
<Paragraph>Left icon</Paragraph>
<Switch
value={params.showLeftIcon}
onValueChange={value =>
navigation.setParams({
showLeftIcon: value,
})
}
/>
</View>
<View style={styles.row}>
<Paragraph>Subtitle</Paragraph>
<Switch
value={params.showSubtitle}
onValueChange={value =>
navigation.setParams({
showSubtitle: value,
})
}
/>
</View>
<View style={styles.row}>
<Paragraph>Search icon</Paragraph>
<Switch
value={params.showSearchIcon}
onValueChange={value =>
navigation.setParams({
showSearchIcon: value,
})
}
/>
</View>
<View style={styles.row}>
<Paragraph>More icon</Paragraph>
<Switch
value={params.showMoreIcon}
onValueChange={value =>
navigation.setParams({
showMoreIcon: value,
})
}
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: Colors.white,
paddingVertical: 8,
},
row: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingVertical: 8,
paddingHorizontal: 16,
},
});
export default withTheme(ToolbarExample);