-
Notifications
You must be signed in to change notification settings - Fork 299
/
DemoScreen.js
366 lines (349 loc) · 9.53 KB
/
DemoScreen.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import React, { Component } from 'react';
import { Button, View, Text, StyleSheet } from 'react-native';
import Modal, {
ModalTitle,
ModalContent,
ModalFooter,
ModalButton,
SlideAnimation,
ScaleAnimation,
BottomModal,
ModalPortal,
} from 'react-native-modals';
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
dialogContentView: {
paddingLeft: 18,
paddingRight: 18,
},
navigationBar: {
borderBottomColor: '#b5b5b5',
borderBottomWidth: 0.5,
backgroundColor: '#ffffff',
},
navigationTitle: {
padding: 10,
},
navigationButton: {
padding: 10,
},
navigationLeftButton: {
paddingLeft: 20,
paddingRight: 40,
},
navigator: {
flex: 1,
// backgroundColor: '#000000',
},
customBackgroundModal: {
opacity: 0.5,
backgroundColor: '#000',
},
});
export default class App extends Component {
state = {
customBackgroundModal: false,
defaultAnimationModal: false,
swipeableModal: false,
scaleAnimationModal: false,
slideAnimationModal: false,
bottomModalAndTitle: false,
bottomModal: false,
};
render() {
return (
<View style={{ flex: 1 }}>
<View style={styles.container}>
<Button
title="Show Modal - Default Animation"
onPress={() => {
this.setState({
defaultAnimationModal: true,
});
}}
/>
<Button
title="Show Modal - Swipeable Modal Animation"
onPress={() => {
this.setState({
swipeableModal: true,
});
}}
/>
<Button
title="Show Modal - Scale Animation"
onPress={() => {
this.setState({
scaleAnimationModal: true,
});
}}
/>
<Button
title="Show Modal - Slide Animation"
onPress={() => {
this.setState({
slideAnimationModal: true,
});
}}
/>
<Button
title="Show Modal - Custom Background Style"
onPress={() => {
this.setState({
customBackgroundModal: true,
});
}}
/>
<Button
title="Bottom Modal with Title"
onPress={() => {
this.setState({
bottomModalAndTitle: true,
});
}}
/>
<Button
title="Bottom Modal without Title"
onPress={() => {
this.setState({
bottomModal: true,
});
}}
/>
</View>
<Modal
width={0.9}
visible={this.state.defaultAnimationModal}
rounded
actionsBordered
style={{ zIndex: 1000 }}
onTouchOutside={() => {
this.setState({ defaultAnimationModal: false });
}}
modalTitle={
<ModalTitle
title="Popup Modal - Default Animation"
align="left"
/>
}
footer={
<ModalFooter>
<ModalButton
text="CANCEL"
bordered
onPress={() => {
this.setState({ defaultAnimationModal: false });
}}
key="button-1"
/>
<ModalButton
text="OK"
bordered
onPress={() => {
this.setState({ defaultAnimationModal: false });
}}
key="button-2"
/>
</ModalFooter>
}
>
<ModalContent
style={{ backgroundColor: '#fff' }}
>
<Text>Default Animation</Text>
<Text>No onTouchOutside handler. will not dismiss when touch overlay.</Text>
<Button
title="To Empty Screen"
onPress={() => {
this.setState({
defaultAnimationModal: false,
scaleAnimationModal: false,
});
this.props.navigation.navigate('Empty');
}}
/>
</ModalContent>
</Modal>
<Modal
onDismiss={() => {
this.setState({ swipeableModal: false });
}}
width={0.9}
overlayOpacity={1}
visible={this.state.swipeableModal}
rounded
actionsBordered
onSwipeOut={() => {
this.setState({ swipeableModal: false });
}}
onTouchOutside={() => {
this.setState({ swipeableModal: false });
}}
swipeDirection={['down', 'up']}
modalAnimation={new SlideAnimation({ slideFrom: 'bottom' })}
modalTitle={
<ModalTitle
title="Swipeable Modal"
/>
}
footer={
<ModalFooter>
<ModalButton
text="CANCEL"
bordered
onPress={() => {
this.setState({ swipeableModal: false });
}}
key="button-1"
/>
<ModalButton
text="OK"
bordered
onPress={() => {
this.setState({ swipeableModal: false });
}}
key="button-2"
/>
</ModalFooter>
}
>
<ModalContent
style={{ backgroundColor: '#fff', paddingTop: 24 }}
>
<Text>Swipeable</Text>
<Text>Swipe Up/Down</Text>
</ModalContent>
</Modal>
<Modal
onTouchOutside={() => {
this.setState({ scaleAnimationModal: false });
}}
width={0.9}
visible={this.state.scaleAnimationModal}
onSwipeOut={() => this.setState({ scaleAnimationModal: false })}
modalAnimation={new ScaleAnimation()}
onHardwareBackPress={() => {
console.log('onHardwareBackPress');
this.setState({ scaleAnimationModal: false });
return true;
}}
modalTitle={
<ModalTitle
title="Modal - Scale Animation"
hasTitleBar={false}
/>
}
actions={[
<ModalButton
text="DISMISS"
onPress={() => {
this.setState({ scaleAnimationModal: false });
}}
key="button-1"
/>,
]}
>
<ModalContent>
<Button
title="Show Modal - Default Animation"
onPress={() => {
this.setState({ defaultAnimationModal: true });
}}
/>
</ModalContent>
</Modal>
<Modal
onDismiss={() => {
this.setState({ slideAnimationModal: false });
}}
onTouchOutside={() => {
this.setState({ slideAnimationModal: false });
}}
swipeDirection="down"
onSwipeOut={() => this.setState({ slideAnimationModal: false })}
visible={this.state.slideAnimationModal}
modalTitle={
<ModalTitle
title="Modal - Slide Animation"
hasTitleBar={false}
/>
}
modalAnimation={new SlideAnimation({ slideFrom: 'bottom' })}
>
<ModalContent>
<Text>Slide Animation</Text>
</ModalContent>
</Modal>
<Modal
onDismiss={() => {
this.setState({ customBackgroundModal: false });
}}
onTouchOutside={() => {
this.setState({ customBackgroundModal: false });
}}
zIndex={1000}
backgroundStyle={styles.customBackgroundModal}
modalStyle={{
backgroundColor: 'rgba(0,0,0,0.5)',
}}
modalTitle={
<ModalTitle
title="Modal - Custom Background Style"
hasTitleBar={false}
textStyle={{ color: '#fff' }}
/>
}
visible={this.state.customBackgroundModal}
>
<View style={styles.dialogContentView}>
<Text style={{ color: '#fff' }}>Custom backgroundStyle</Text>
</View>
</Modal>
<BottomModal
visible={this.state.bottomModalAndTitle}
onTouchOutside={() => this.setState({ bottomModalAndTitle: false })}
height={0.5}
width={1}
onSwipeOut={() => this.setState({ bottomModalAndTitle: false })}
modalTitle={
<ModalTitle
title="Bottom Modal"
hasTitleBar
/>
}
>
<ModalContent
style={{
flex: 1,
backgroundColor: 'fff',
}}
>
<Text>
Bottom Modal with Title
</Text>
</ModalContent>
</BottomModal>
<BottomModal
visible={this.state.bottomModal}
onTouchOutside={() => this.setState({ bottomModal: false })}
// modalStyle={{ }}
>
<ModalContent
style={{
backgroundColor: 'fff',
// height: '40%',
}}
>
<Text>
Bottom Modal without Title
</Text>
</ModalContent>
</BottomModal>
</View>
);
}
}