1- import { useState , useEffect } from 'react'
1+ import { useState , useEffect , useRef } from 'react'
22import { 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'
44import BackButton from '../components/BackButton'
55import { TextInput } from '../forms/TextInput.styled'
6- import { NumberStepper } from '../forms/NumberStepper'
6+ import { NumberStepper } from '../forms/NumberStepper.styled '
77import { Checkbox } from '../forms/Checkbox.styled'
88import { useFormState } from '@green-stack/forms/useFormState'
99import { z , schema } from '@green-stack/schemas'
@@ -12,6 +12,8 @@ import { CheckList } from '../forms/CheckList.styled'
1212import { RadioGroup } from '../forms/RadioGroup.styled'
1313import { Select } from '../forms/Select.styled'
1414import { isEmpty } from '@green-stack/utils/commonUtils'
15+ import { useScrollToFocusedInput } from '@green-stack/hooks/useScrollToFocusedInput'
16+ import { TextArea } from '../forms/TextArea.styled'
1517
1618/* --- Schema --------------------------------------------------------------------------------- */
1719
@@ -21,6 +23,7 @@ const TestForm = schema('TestForm', {
2123 identifiesWith : z . string ( ) . optional ( ) ,
2224 excitingFeatures : z . array ( z . string ( ) ) . default ( [ ] ) ,
2325 minHourlyPrice : z . number ( ) . optional ( ) ,
26+ feedbackSuggestions : z . string ( ) . optional ( ) ,
2427} )
2528
2629type TestForm = z . input < typeof TestForm >
@@ -32,6 +35,14 @@ const FormsScreen = (props: TestForm) => {
3235 const { setParams } = useRouter ( )
3336 const params = useRouteParams ( props )
3437
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+
3546 // State
3647 const [ validateOnChange , setValidateOnChange ] = useState ( ! ! params . validateOnChange )
3748 const [ showFormState , setShowFormState ] = useState ( false )
@@ -61,9 +72,10 @@ const FormsScreen = (props: TestForm) => {
6172 // -- Render --
6273
6374 return (
64- < >
75+ < KeyboardAvoidingView { ... kbScroller . avoidingViewProps } >
6576 < StatusBar style = "dark" />
6677 < ScrollView
78+ { ...kbScroller . scrollViewProps }
6779 className = "flex flex-1 min-h-screen bg-white"
6880 contentContainerClassName = "min-h-screen"
6981 >
@@ -79,6 +91,7 @@ const FormsScreen = (props: TestForm) => {
7991 < TextInput
8092 placeholder = "e.g. thorr@fullproduct.dev"
8193 { ...formState . getTextInputProps ( 'email' ) }
94+ { ...kbScroller . registerInput ( emailInputRef ) }
8295 />
8396
8497 < Text className = "text-sm text-secondary mt-2" >
@@ -95,6 +108,7 @@ const FormsScreen = (props: TestForm) => {
95108 max = { 150 }
96109 step = { 1 }
97110 { ...formState . getInputProps ( 'age' ) }
111+ { ...kbScroller . registerInput ( ageInputRef ) }
98112 />
99113
100114 < Text className = "text-sm text-secondary mt-2" >
@@ -187,6 +201,26 @@ const FormsScreen = (props: TestForm) => {
187201
188202 < View className = "h-1 w-12 my-6 bg-slate-300" />
189203
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+
190224 { /* -- useFormstate -- */ }
191225
192226 { validateOnChange && (
@@ -219,11 +253,14 @@ const FormsScreen = (props: TestForm) => {
219253 </ >
220254 ) }
221255
256+ { kbScroller . keyboardPaddedView }
257+
222258 </ View >
223259 </ View >
260+
224261 </ ScrollView >
225262 < BackButton backLink = "/subpages/Universal%20Nav" color = "#333333" />
226- </ >
263+ </ KeyboardAvoidingView >
227264 )
228265}
229266
0 commit comments