/
ToastsScreen.js
206 lines (189 loc) · 6.13 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import _ from 'lodash';
import React, {Component} from 'react';
import {StyleSheet} from 'react-native';
import {Assets, Colors, View, Button, Text, Icon, TouchableOpacity, Toast} from 'react-native-ui-lib';
const colors = [Colors.green30, Colors.red30, Colors.violet30];
const shareIcon = require('../../assets/icons/share.png');
const plusIcon = require('../../assets/icons/plus.png');
const settingsIcon = require('../../assets/icons/settings.png');
export default class ToastsScreen extends Component {
constructor(props) {
super(props);
this.state = {
showToast: false,
showTopToast: false,
showCustomToast: false,
selectedColor: 'none',
showLoader: false,
showDismiss: false,
showContent: false
};
}
renderColors() {
return (
<View row>
{_.map(['none', ...colors], (color, index) => {
const isSelected = color === this.state.selectedColor;
const backgroundColor = color === 'none' ? undefined : color;
return (
<TouchableOpacity key={color} onPress={() => this.setState({selectedColor: color})}>
<View center style={[styles.color, {backgroundColor}, isSelected && styles.selected]}>
{color === 'none' && <Icon source={plusIcon} tintColor={Colors.black}/>}
</View>
</TouchableOpacity>
);
})}
</View>
);
}
renderAboveToast = () => {
if (this.state.showContent) {
return (
<View flex bottom right paddingB-50 paddingR-20 pointerEvents={'box-none'}>
<Button iconSource={shareIcon} color={Colors.white} style={{height: 50, width: 50}}/>
</View>
);
}
};
renderBelowToast = () => {
if (this.state.showContent) {
return (
<View center bg-violet50 padding-8>
<Text white text70>Objects may be closer than they appear</Text>
</View>
);
}
};
renderCustomContent = () => {
const {selectedColor} = this.state;
const backgroundColor = selectedColor === 'none' ? undefined : selectedColor;
return (
<View flex padding-10 style={{backgroundColor}}>
<Text white text60>
This is a custom content
</Text>
<Text white>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry
standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to
make a type specimen book.
</Text>
</View>
);
};
dismissTopToast = () => {
this.setState({showTopToast: false});
}
dismissBottomToast = () => {
this.setState({showToast: false});
}
dismissCustomToast = () => {
this.setState({showCustomToast: false});
}
render() {
const {showToast, showTopToast, showCustomToast, selectedColor, showLoader, showDismiss} = this.state;
const backgroundColor = selectedColor === 'none' ? undefined : selectedColor;
return (
<View flex center bg-grey80 style={styles.container}>
<Toast
renderAttachment={this.renderBelowToast}
visible={this.state.showTopToast}
position={'top'}
backgroundColor={backgroundColor}
message="Toast with two lines of text. Toast with two lines of text"
onDismiss={this.dismissTopToast}
// autoDismiss={3000}
showDismiss={showDismiss}
// action={{iconSource: Assets.icons.x, onPress: () => console.log('dismiss')}}
showLoader={showLoader}
/>
<Toast
renderAttachment={this.renderAboveToast}
visible={this.state.showToast}
position={'bottom'}
backgroundColor={backgroundColor}
message="Toast with one line of text"
icon={settingsIcon}
onDismiss={this.dismissBottomToast}
// autoDismiss={3000}
showDismiss={showDismiss}
action={{label: 'Undo', onPress: () => console.log('undo')}}
showLoader={showLoader}
/>
<Toast
visible={this.state.showCustomToast}
position={'bottom'}
onDismiss={this.dismissCustomToast}
>
{this.renderCustomContent()}
</Toast>
<View center>
<Text marginV-10 text60>
Toggle Toast
</Text>
<View center row marginB-10>
<Button
outline
size="medium"
label="TOP"
onPress={() => this.setState({showTopToast: !showTopToast})}
marginR-10
/>
<Button
outline
size="medium"
label="BOTTOM"
onPress={() => this.setState({showToast: !showToast, showCustomToast: false})}
marginR-10
/>
<Button
outline
size="medium"
label="CUSTOM"
onPress={() => this.setState({showCustomToast: !showCustomToast, showToast: false})}
/>
</View>
<Text marginV-10 text60>
Toast Background Color
</Text>
{this.renderColors()}
<View center row marginV-20>
<Button
outline
size="medium"
label="Show Loader"
onPress={() => this.setState({showLoader: !showLoader, showDismiss: false})}
marginR-10
/>
<Button
outline
size="medium"
label="Show Dismiss"
onPress={() => this.setState({showLoader: false, showDismiss: !showDismiss})}
/>
</View>
<View center row marginV-20>
<Button
outline
size="medium"
label="Toggle content above bottom toast"
onPress={() => this.setState({showContent: !this.state.showContent})}
/>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {},
color: {
width: 30,
height: 30,
borderRadius: 15,
marginLeft: 5
},
selected: {
borderWidth: 2,
borderColor: Colors.grey10
}
});