-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathModalScreen.tsx
More file actions
118 lines (108 loc) · 3.8 KB
/
ModalScreen.tsx
File metadata and controls
118 lines (108 loc) · 3.8 KB
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
import { useRef, useState, useEffect } from 'react';
import { Modal, StyleSheet, Text, View } from 'react-native';
import { TrueSheet, TrueSheetProvider } from '@lodev09/react-native-true-sheet';
import { BLUE, DARK, DARK_BLUE, DARK_GRAY, GAP, LIGHT_GRAY, SPACING } from '../utils';
import { Button, DemoContent, Input, Spacer } from '../components';
import { PromptSheet, FlatListSheet } from '../components/sheets';
export interface ModalScreenProps {
onNavigateToTest?: () => void;
onDismiss?: () => void;
}
export const ModalScreen = ({ onNavigateToTest, onDismiss }: ModalScreenProps) => {
const promptSheet = useRef<TrueSheet>(null);
const flatlistSheet = useRef<TrueSheet>(null);
const [modalVisible, setModalVisible] = useState(false);
const modalSimpleSheet = useRef<TrueSheet>(null);
const modalFlatlistSheet = useRef<TrueSheet>(null);
useEffect(() => {
if (modalVisible) {
modalSimpleSheet.current?.present();
}
}, [modalVisible]);
return (
<TrueSheetProvider>
<View style={styles.content}>
<View style={styles.heading}>
<Text style={styles.title}>Modal Screen</Text>
<Text style={styles.subtitle}>
This is a fullScreenModal opened from a TrueSheet. You can present sheets from here too!
</Text>
</View>
<Input />
<Button text="Dismiss Modal" onPress={onDismiss} />
<Button text="TrueSheet Prompt" onPress={() => promptSheet.current?.present()} />
<Button text="TrueSheet FlatList" onPress={() => flatlistSheet.current?.present()} />
<Button text="Open RN Modal" onPress={() => setModalVisible(true)} />
<Spacer />
<Button text="Navigate Test" onPress={onNavigateToTest} />
<PromptSheet initialDetentIndex={0} ref={promptSheet} dimmed={false} />
<FlatListSheet ref={flatlistSheet} />
<Modal
visible={modalVisible}
animationType="slide"
onRequestClose={() => setModalVisible(false)}
>
<TrueSheetProvider>
<View style={styles.modalContent}>
<View style={styles.heading}>
<Text style={styles.title}>React Native Modal</Text>
<Text style={styles.subtitle}>
This is a React Native Modal. You can present TrueSheets from here!
</Text>
</View>
<Button text="Simple Sheet" onPress={() => modalSimpleSheet.current?.present()} />
<Button text="FlatList Sheet" onPress={() => modalFlatlistSheet.current?.present()} />
<Spacer />
<Button text="Close Modal" onPress={() => setModalVisible(false)} />
<TrueSheet
ref={modalSimpleSheet}
detents={['auto']}
// initialDetentIndex={0}
dimmed={false}
style={styles.simpleSheet}
backgroundColor={DARK}
>
<DemoContent color={DARK_BLUE} text="Simple Sheet" />
<Button text="Dismiss" onPress={() => modalSimpleSheet.current?.dismiss()} />
</TrueSheet>
<FlatListSheet ref={modalFlatlistSheet} />
</View>
</TrueSheetProvider>
</Modal>
</View>
</TrueSheetProvider>
);
};
const styles = StyleSheet.create({
content: {
backgroundColor: BLUE,
justifyContent: 'center',
flex: 1,
padding: SPACING,
gap: GAP,
},
modalContent: {
backgroundColor: DARK_GRAY,
justifyContent: 'center',
flex: 1,
padding: SPACING,
gap: GAP,
},
simpleSheet: {
padding: SPACING,
gap: GAP,
},
heading: {
marginBottom: SPACING * 2,
},
title: {
fontSize: 24,
lineHeight: 30,
fontWeight: '500',
color: 'white',
},
subtitle: {
lineHeight: 24,
color: LIGHT_GRAY,
},
});