-
Notifications
You must be signed in to change notification settings - Fork 692
/
ToastsScreen.js
185 lines (166 loc) · 6.54 KB
/
ToastsScreen.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import React, {Component} from 'react';
import {StyleSheet} from 'react-native';
import {View, Text, Constants, PageControl, Toast, Carousel, Button, Colors} from 'react-native-ui-lib'; // eslint-disable-line
export default class AvatarsScreen extends Component {
state = {
currentPage: 0,
showToast: false,
};
render() {
return (
<View flex useSafeArea>
<Carousel onChangePage={currentPage => this.setState({currentPage})} initialPage={this.state.currentPage}>
<View style={styles.page} bg-red50>
<Toast visible message="Discount was added to 3 products" />
</View>
<View style={styles.page} bg-green50>
<Toast
visible
message="Discount was added to 3 products"
actions={[{label: 'Undo', onPress: () => alert('undo')}]}
/>
</View>
<View style={styles.page} bg-dark50>
<Toast
visible
message="Discount was added to 3 products"
allowDismiss
onDismiss={() => alert('dismiss!')}
/>
</View>
<View center flex style={styles.page} bg-violet70>
<Toast
message="Toast can appear from top"
allowDismiss
onDismiss={() => this.setState({showToast: false})}
visible={this.state.showToast}
/>
<Button size="medium" label="Show Toast" onPress={() => this.setState({showToast: true})} />
<Toast
message="Toast can appear from bottom"
position="bottom"
allowDismiss
onDismiss={() => this.setState({showToast: false})}
visible={this.state.showToast}
/>
</View>
<View flex spread centerH style={styles.page} bg-violet70>
<View flex spread style={styles.page}>
<Text>relative position</Text>
<View style={{position: 'absolute', top: 0, width: Constants.screenWidth}}>
<Toast
visible={this.state.showToast}
message="Toast can move content relative to it to the bottom"
position="relative"
actions={[{label: 'Close', onPress: () => this.setState({showToast: false})}]}
/>
<View style={{height: 50, backgroundColor: 'white', justifyContent: 'center', alignItems: 'center'}}>
<Button size="medium" label="Show Toast" onPress={() => this.setState({showToast: true})}/>
</View>
</View>
</View>
<View flex spread style={[styles.page, {justifyContent: 'flex-end', alignItems: 'center'}]}>
<Text style={{marginBottom: 50}}>relative position</Text>
<View style={{position: 'absolute', bottom: 0, width: Constants.screenWidth}}>
<Toast
visible={this.state.showToast}
message="Toast can appear at the top (expanding its relative parent height"
position="relative"
allowDismiss
onDismiss={() => this.setState({showToast: false})}
/>
<View style={{height: 50, backgroundColor: 'white', justifyContent: 'center', alignItems: 'center'}}>
<Button size="medium" label="Show Toast" onPress={() => this.setState({showToast: true})}/>
</View>
</View>
</View>
<View flex spread style={[styles.page, {justifyContent: 'flex-end', alignItems: 'center'}]}>
<Text>relative position</Text>
<View style={{position: 'absolute', bottom: 0, width: Constants.screenWidth}}>
<View style={{height: 50, backgroundColor: 'white', justifyContent: 'center', alignItems: 'center'}}>
<Button size="medium" label="Show Toast" onPress={() => this.setState({showToast: true})}/>
</View>
<Toast
visible={this.state.showToast}
message="Toast can move content relative to it to the top"
position="relative"
centerMessage
backgroundColor={Colors.white}
color={Colors.blue30}
actions={[
{
label: 'No, close it',
outline: true,
outlineColor: Colors.blue30,
color: Colors.blue30,
onPress: () => this.setState({showToast: false}),
},
{label: 'Yes, close it', onPress: () => this.setState({showToast: false})},
]}
/>
</View>
</View>
</View>
<View style={styles.page} bg-yellow70>
<Toast
visible
message="Notfication with different color"
backgroundColor={Colors.white}
color={Colors.dark10}
allowDismiss
/>
</View>
<View style={styles.page} bg-red80 padding-10>
<Text text20>Blurred Text</Text>
<Toast
visible
message="Notification With Blur Effect"
backgroundColor={Colors.rgba(Colors.white, 0.3)}
enableBlur
blurOption={{type: 'light', amount: 5}}
color={Colors.dark10}
allowDismiss
/>
</View>
<View style={styles.page} bg-orange70>
<Toast
visible
message="Do you approve user request?"
centerMessage
backgroundColor={Colors.white}
color={Colors.blue30}
actions={[
{
label: 'Block',
outline: true,
outlineColor: Colors.blue30,
color: Colors.blue30,
onPress: () => alert('block!'),
},
{label: 'Approve', onPress: () => alert('approve!')},
]}
/>
</View>
</Carousel>
<PageControl
containerStyle={styles.pageControl}
numOfPages={8}
currentPage={this.state.currentPage}
color={Colors.dark10}
size={15}
/>
</View>
);
}
}
const styles = StyleSheet.create({
page: {
width: Constants.screenWidth,
flex: 1,
},
pageControl: {
position: 'absolute',
bottom: 70,
width: Constants.screenWidth,
},
});