1
- import React , { useState } from "react" ;
1
+ import React , { useEffect , useState } from "react" ;
2
2
import {
3
3
Alert ,
4
- Button ,
5
4
Image ,
6
5
Keyboard ,
7
6
StyleSheet ,
8
7
Text ,
9
8
TextInput ,
10
9
TouchableOpacity ,
11
10
TouchableWithoutFeedback ,
12
- View ,
13
11
} from "react-native" ;
14
- import {
15
- KeyboardExtender ,
16
- OverKeyboardView ,
17
- useKeyboardState ,
18
- } from "react-native-keyboard-controller" ;
12
+ import { KeyboardExtender } from "react-native-keyboard-controller" ;
19
13
import Reanimated , {
20
14
useAnimatedStyle ,
21
15
useSharedValue ,
@@ -26,14 +20,14 @@ import { SafeAreaView } from "react-native-safe-area-context";
26
20
// TODO: remove _touchHandler when view gets detached from keyboard?
27
21
// TODO: test how GestureHandler works there
28
22
// TODO: don't overwrite existing inputAccessoryView?
29
- // TODO: Android implementation
30
23
31
24
export default function KeyboardExtendExample ( ) {
32
25
const [ showExtend , setShowExtend ] = useState ( true ) ;
33
- const [ isOKVMode , setOKVMode ] = useState ( false ) ;
34
26
const opacity = useSharedValue ( 1 ) ;
35
- // TODO: replace with animated value
36
- const { height } = useKeyboardState ( ) ;
27
+
28
+ useEffect ( ( ) => {
29
+ opacity . set ( withTiming ( showExtend ? 1 : 0 ) ) ;
30
+ } , [ showExtend ] ) ;
37
31
38
32
const animatedStyle = useAnimatedStyle (
39
33
( ) => ( {
@@ -44,10 +38,7 @@ export default function KeyboardExtendExample() {
44
38
45
39
return (
46
40
< >
47
- < Image
48
- source = { require ( "./background.jpg" ) }
49
- style = { { ...StyleSheet . absoluteFillObject , flex : 1 , width : "100%" } }
50
- />
41
+ < Image source = { require ( "./background.jpg" ) } style = { styles . background } />
51
42
< TouchableWithoutFeedback onPress = { ( ) => Keyboard . dismiss ( ) } >
52
43
< SafeAreaView edges = { [ "top" ] } style = { styles . container } >
53
44
< TextInput
@@ -56,28 +47,36 @@ export default function KeyboardExtendExample() {
56
47
placeholderTextColor = "#5c5c5c"
57
48
style = { styles . input }
58
49
testID = "donation_amount"
50
+ onFocus = { ( ) => setShowExtend ( true ) }
51
+ />
52
+ < TextInput
53
+ keyboardType = "numeric"
54
+ placeholder = "Postal code"
55
+ placeholderTextColor = "#5c5c5c"
56
+ style = { styles . input }
57
+ testID = "postal_code"
58
+ onFocus = { ( ) => setShowExtend ( false ) }
59
59
/>
60
-
61
- < OverKeyboardView visible = { isOKVMode } >
62
- < View style = { { flex : 1 , justifyContent : "flex-end" } } >
63
- { /* TODO replace hardcoded value */ }
64
- < TextInput
65
- placeholder = "Search..."
66
- style = { [ styles . input , { marginBottom : height - 61.73 } ] }
67
- />
68
- </ View >
69
- </ OverKeyboardView >
70
60
</ SafeAreaView >
71
61
</ TouchableWithoutFeedback >
72
62
< KeyboardExtender enabled = { showExtend } >
73
63
< Reanimated . View style = { [ styles . keyboardExtend , animatedStyle ] } >
74
- < TouchableOpacity onPress = { ( ) => Alert . alert ( "10$" ) } >
64
+ < TouchableOpacity
65
+ testID = "donation_10"
66
+ onPress = { ( ) => Alert . alert ( "10 dollars" ) }
67
+ >
75
68
< Text style = { styles . priceText } > 10$</ Text >
76
69
</ TouchableOpacity >
77
- < TouchableOpacity onPress = { ( ) => Alert . alert ( "20$" ) } >
70
+ < TouchableOpacity
71
+ testID = "donation_20"
72
+ onPress = { ( ) => Alert . alert ( "20 dollars" ) }
73
+ >
78
74
< Text style = { styles . priceText } > 20$</ Text >
79
75
</ TouchableOpacity >
80
- < TouchableOpacity onPress = { ( ) => Alert . alert ( "50$" ) } >
76
+ < TouchableOpacity
77
+ testID = "donation_50"
78
+ onPress = { ( ) => Alert . alert ( "50 dollars" ) }
79
+ >
81
80
< Text style = { styles . priceText } > 50$</ Text >
82
81
</ TouchableOpacity >
83
82
</ Reanimated . View >
@@ -87,6 +86,11 @@ export default function KeyboardExtendExample() {
87
86
}
88
87
89
88
const styles = StyleSheet . create ( {
89
+ background : {
90
+ ...StyleSheet . absoluteFillObject ,
91
+ flex : 1 ,
92
+ width : "100%" ,
93
+ } ,
90
94
container : {
91
95
flex : 1 ,
92
96
paddingHorizontal : 20 ,
@@ -107,23 +111,9 @@ const styles = StyleSheet.create({
107
111
alignItems : "center" ,
108
112
} ,
109
113
priceText : {
110
- color : "white " ,
114
+ color : "black " ,
111
115
fontSize : 18 ,
112
- fontWeight : "bold " ,
116
+ fontWeight : "600 " ,
113
117
padding : 20 ,
114
118
} ,
115
- overKeyboardView : {
116
- width : "100%" ,
117
- padding : 10 ,
118
- backgroundColor : "rgba(255, 255, 255, 0.9)" ,
119
- alignItems : "center" ,
120
- } ,
121
- hiddenInput : {
122
- height : 0 ,
123
- width : 0 ,
124
- } ,
125
- helpText : {
126
- fontSize : 14 ,
127
- color : "#666" ,
128
- } ,
129
119
} ) ;
0 commit comments