forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppbarExample.js
155 lines (145 loc) · 3.6 KB
/
AppbarExample.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* @flow */
import * as React from 'react';
import { View, Platform, StyleSheet } from 'react-native';
import {
Colors,
Appbar,
FAB,
Switch,
Paragraph,
withTheme,
type Theme,
} from 'react-native-paper';
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 AppbarExample extends React.Component<Props> {
static title = 'Appbar';
static navigationOptions = ({ navigation }) => {
const params = { ...initialParams, ...navigation.state.params };
return {
header: (
<Appbar.Header>
{params.showLeftIcon && (
<Appbar.BackAction onPress={() => navigation.goBack()} />
)}
<Appbar.Content
title="Title"
subtitle={params.showSubtitle ? 'Subtitle' : null}
/>
{params.showSearchIcon && (
<Appbar.Action icon="search" onPress={() => {}} />
)}
{params.showMoreIcon && (
<Appbar.Action icon={MORE_ICON} onPress={() => {}} />
)}
</Appbar.Header>
),
};
};
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>
<Appbar style={styles.bottom}>
<Appbar.Action icon="archive" onPress={() => {}} />
<Appbar.Action icon="mail" onPress={() => {}} />
<Appbar.Action icon="label" onPress={() => {}} />
<Appbar.Action icon="delete" onPress={() => {}} />
</Appbar>
<FAB icon="reply" onPress={() => {}} style={styles.fab} />
</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,
},
bottom: {
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
},
fab: {
position: 'absolute',
right: 16,
bottom: 28,
},
});
export default withTheme(AppbarExample);