-
-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathindex.tsx
More file actions
136 lines (131 loc) · 3.33 KB
/
index.tsx
File metadata and controls
136 lines (131 loc) · 3.33 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import React, { useEffect, useMemo, useState } from "react";
import {
Alert,
Image,
Keyboard,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
TouchableWithoutFeedback,
} from "react-native";
import {
KeyboardExtender,
useKeyboardState,
} from "react-native-keyboard-controller";
import Reanimated, {
useAnimatedStyle,
useSharedValue,
withTiming,
} from "react-native-reanimated";
import { SafeAreaView } from "react-native-safe-area-context";
export default function KeyboardExtendExample() {
const appearance = useKeyboardState((state) => state.appearance);
const [showExtend, setShowExtend] = useState(true);
const opacity = useSharedValue(1);
useEffect(() => {
opacity.set(withTiming(showExtend ? 1 : 0));
}, [showExtend]);
const animatedStyle = useAnimatedStyle(
() => ({
opacity: opacity.value,
}),
[],
);
const textStyle = useMemo(
() => [
styles.priceText,
appearance === "light"
? styles.lightKeyboardText
: styles.darkKeyboardText,
],
[appearance],
);
return (
<>
<Image source={require("./background.jpg")} style={styles.background} />
<TouchableWithoutFeedback
testID="keyboard_extender.dismiss"
onPress={() => Keyboard.dismiss()}
>
<SafeAreaView edges={["top"]} style={styles.container}>
<TextInput
keyboardType="numeric"
placeholder="Donation amount"
placeholderTextColor="#5c5c5c"
style={styles.input}
testID="donation_amount"
onFocus={() => setShowExtend(true)}
/>
<TextInput
keyboardType="numeric"
placeholder="Postal code"
placeholderTextColor="#5c5c5c"
style={styles.input}
testID="postal_code"
onFocus={() => setShowExtend(false)}
/>
</SafeAreaView>
</TouchableWithoutFeedback>
<KeyboardExtender enabled={showExtend}>
<Reanimated.View style={[styles.keyboardExtend, animatedStyle]}>
<TouchableOpacity
testID="donation_10"
onPress={() => Alert.alert("10 dollars")}
>
<Text style={textStyle}>10$</Text>
</TouchableOpacity>
<TouchableOpacity
testID="donation_20"
onPress={() => Alert.alert("20 dollars")}
>
<Text style={textStyle}>20$</Text>
</TouchableOpacity>
<TouchableOpacity
testID="donation_50"
onPress={() => Alert.alert("50 dollars")}
>
<Text style={textStyle}>50$</Text>
</TouchableOpacity>
</Reanimated.View>
</KeyboardExtender>
</>
);
}
const styles = StyleSheet.create({
background: {
...StyleSheet.absoluteFillObject,
flex: 1,
width: "100%",
},
container: {
flex: 1,
paddingHorizontal: 20,
},
input: {
height: 40,
borderWidth: 2,
borderColor: "#1c1c1c",
borderRadius: 8,
padding: 10,
fontSize: 18,
marginBottom: 20,
},
keyboardExtend: {
width: "100%",
flexDirection: "row",
justifyContent: "space-around",
alignItems: "center",
},
priceText: {
fontSize: 18,
fontWeight: "600",
padding: 20,
},
lightKeyboardText: {
color: "black",
},
darkKeyboardText: {
color: "white",
},
});