-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.tsx
102 lines (95 loc) · 2.41 KB
/
App.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React, {useEffect, useMemo} from 'react';
import {StyleSheet, View, TouchableOpacity, Text, Animated} from 'react-native';
import {FadeAnimated} from './animated';
const Dialog = (props: any) => {
const animated = useMemo(() => {
return new FadeAnimated({});
}, []);
const animatedState = animated ? animated.getState() : {};
useEffect(() => {
if (props.visible) {
animated.toIn();
} else {
animated.toOut();
}
}, [animated, props.visible]);
if (!props.visible) {
return null;
}
return (
<View
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
alignContent: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
}}>
<Animated.View
style={[
{
alignItems: 'center',
justifyContent: 'center',
overflow: 'hidden',
transform: [{scale: animatedState.scale}],
opacity: animatedState.opacity,
},
]}>
<View
style={{
width: 200,
height: 150,
backgroundColor: 'white',
borderRadius: 8,
padding: 16,
alignItems: 'center',
justifyContent: 'center',
}}>
<Text>{props.bodyText}</Text>
<TouchableOpacity
style={{
width: 100,
height: 36,
backgroundColor: 'yellow',
alignItems: 'center',
justifyContent: 'center',
marginTop: 30,
}}
onPress={props.confirmCallback}>
<Text>关闭</Text>
</TouchableOpacity>
</View>
</Animated.View>
</View>
);
};
function App(): React.JSX.Element {
const [show, setShow] = React.useState(false);
return (
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<TouchableOpacity
onPress={() => {
setShow(true);
}}>
<Text>显示弹框</Text>
</TouchableOpacity>
<Dialog
visible={show}
confirmCallback={() => {
setShow(false);
}}
bodyText="测试动画弹框出现后无法点击消失"
confirmLabelText="确认"></Dialog>
</View>
);
}
export default App;