1
- import { useState , useEffect } from 'react'
1
+ import { useState , useEffect , useRef } from 'react'
2
2
import { StatusBar } from 'expo-status-bar'
3
- import { View , Text , H1 , H2 , H3 , Link , ScrollView } from '../components/styled'
3
+ import { View , Text , H1 , H2 , H3 , Link , ScrollView , KeyboardAvoidingView } from '../components/styled'
4
4
import BackButton from '../components/BackButton'
5
5
import { TextInput } from '../forms/TextInput.styled'
6
- import { NumberStepper } from '../forms/NumberStepper'
6
+ import { NumberStepper } from '../forms/NumberStepper.styled '
7
7
import { Checkbox } from '../forms/Checkbox.styled'
8
8
import { useFormState } from '@green-stack/forms/useFormState'
9
9
import { z , schema } from '@green-stack/schemas'
@@ -12,6 +12,8 @@ import { CheckList } from '../forms/CheckList.styled'
12
12
import { RadioGroup } from '../forms/RadioGroup.styled'
13
13
import { Select } from '../forms/Select.styled'
14
14
import { isEmpty } from '@green-stack/utils/commonUtils'
15
+ import { useScrollToFocusedInput } from '@green-stack/hooks/useScrollToFocusedInput'
16
+ import { TextArea } from '../forms/TextArea.styled'
15
17
16
18
/* --- Schema --------------------------------------------------------------------------------- */
17
19
@@ -21,6 +23,7 @@ const TestForm = schema('TestForm', {
21
23
identifiesWith : z . string ( ) . optional ( ) ,
22
24
excitingFeatures : z . array ( z . string ( ) ) . default ( [ ] ) ,
23
25
minHourlyPrice : z . number ( ) . optional ( ) ,
26
+ feedbackSuggestions : z . string ( ) . optional ( ) ,
24
27
} )
25
28
26
29
type TestForm = z . input < typeof TestForm >
@@ -32,6 +35,14 @@ const FormsScreen = (props: TestForm) => {
32
35
const { setParams } = useRouter ( )
33
36
const params = useRouteParams ( props )
34
37
38
+ // Refs
39
+ const emailInputRef = useRef < any$Ignore > ( null )
40
+ const ageInputRef = useRef < any$Ignore > ( null )
41
+ const feedbackInputRef = useRef < any$Ignore > ( null )
42
+
43
+ // Hooks
44
+ const kbScroller = useScrollToFocusedInput ( )
45
+
35
46
// State
36
47
const [ validateOnChange , setValidateOnChange ] = useState ( ! ! params . validateOnChange )
37
48
const [ showFormState , setShowFormState ] = useState ( false )
@@ -61,9 +72,10 @@ const FormsScreen = (props: TestForm) => {
61
72
// -- Render --
62
73
63
74
return (
64
- < >
75
+ < KeyboardAvoidingView { ... kbScroller . avoidingViewProps } >
65
76
< StatusBar style = "dark" />
66
77
< ScrollView
78
+ { ...kbScroller . scrollViewProps }
67
79
className = "flex flex-1 min-h-screen bg-white"
68
80
contentContainerClassName = "min-h-screen"
69
81
>
@@ -79,6 +91,7 @@ const FormsScreen = (props: TestForm) => {
79
91
< TextInput
80
92
placeholder = "e.g. [email protected] "
81
93
{ ...formState . getTextInputProps ( 'email' ) }
94
+ { ...kbScroller . registerInput ( emailInputRef ) }
82
95
/>
83
96
84
97
< Text className = "text-sm text-secondary mt-2" >
@@ -95,6 +108,7 @@ const FormsScreen = (props: TestForm) => {
95
108
max = { 150 }
96
109
step = { 1 }
97
110
{ ...formState . getInputProps ( 'age' ) }
111
+ { ...kbScroller . registerInput ( ageInputRef ) }
98
112
/>
99
113
100
114
< Text className = "text-sm text-secondary mt-2" >
@@ -187,6 +201,26 @@ const FormsScreen = (props: TestForm) => {
187
201
188
202
< View className = "h-1 w-12 my-6 bg-slate-300" />
189
203
204
+ { /* -- TextArea -- */ }
205
+
206
+ < H2 className = "text-black" >
207
+ What's missing?
208
+ </ H2 >
209
+
210
+ < View className = "h-4" />
211
+
212
+ < TextArea
213
+ placeholder = "How could we further improve your workflow?"
214
+ { ...formState . getTextInputProps ( 'feedbackSuggestions' ) }
215
+ { ...kbScroller . registerInput ( feedbackInputRef ) }
216
+ />
217
+
218
+ < Text className = "text-sm text-secondary mt-2" >
219
+ Feedback or suggestions appreciated
220
+ </ Text >
221
+
222
+ < View className = "h-1 w-12 my-6 bg-slate-300" />
223
+
190
224
{ /* -- useFormstate -- */ }
191
225
192
226
{ validateOnChange && (
@@ -219,11 +253,14 @@ const FormsScreen = (props: TestForm) => {
219
253
</ >
220
254
) }
221
255
256
+ { kbScroller . keyboardPaddedView }
257
+
222
258
</ View >
223
259
</ View >
260
+
224
261
</ ScrollView >
225
262
< BackButton backLink = "/subpages/Universal%20Nav" color = "#333333" />
226
- </ >
263
+ </ KeyboardAvoidingView >
227
264
)
228
265
}
229
266
0 commit comments