forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBannerExample.tsx
111 lines (105 loc) · 2.43 KB
/
BannerExample.tsx
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
import * as React from 'react';
import {
View,
StyleSheet,
Image,
ScrollView,
SafeAreaView,
Dimensions,
Platform,
} from 'react-native';
import { Banner, FAB, useTheme } from 'react-native-paper';
const PHOTOS = Array.from({ length: 24 }).map(
(_, i) => `https://unsplash.it/300/300/?random&__id=${i}`
);
const BannerExample = () => {
const [visible, setVisible] = React.useState<boolean>(true);
const {
colors: { background },
} = useTheme();
return (
<View style={[styles.container, { backgroundColor: background }]}>
<ScrollView>
<Banner
actions={[
{
label: 'Fix it',
onPress: () => setVisible(false),
},
{
label: 'Learn more',
onPress: () => setVisible(false),
},
]}
icon={require('../../assets/images/email-icon.png')}
visible={visible}
>
Two line text string with two actions. One to two lines is preferable
on mobile.
</Banner>
<View style={styles.grid}>
{PHOTOS.map((uri) => (
<View key={uri} style={styles.item}>
<Image source={{ uri }} style={styles.photo} />
</View>
))}
</View>
</ScrollView>
<SafeAreaView>
<View>
<FAB
icon="eye"
label={visible ? 'Hide banner' : 'Show banner'}
style={styles.fab}
onPress={() => setVisible(!visible)}
/>
</View>
</SafeAreaView>
</View>
);
};
BannerExample.title = 'Banner';
const styles = StyleSheet.create({
container: {
flex: 1,
},
...Platform.select({
web: {
grid: {
// there is no 'grid' type in RN :(
display: 'grid' as 'none',
gridTemplateColumns: 'repeat(auto-fill, minmax(150px, 1fr))',
gridRowGap: '8px',
gridColumnGap: '8px',
padding: 8,
},
item: {
width: '100%',
height: 150,
},
},
default: {
grid: {
flexDirection: 'row',
flexWrap: 'wrap',
padding: 4,
},
item: {
height: Dimensions.get('window').width / 2,
width: '50%',
padding: 4,
},
},
}),
photo: {
flex: 1,
resizeMode: 'cover',
},
fab: {
alignSelf: 'center',
position: 'absolute',
bottom: 0,
margin: 16,
},
});
export default BannerExample;