File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 11import React , {
22 useCallback ,
3+ useEffect ,
34 useMemo ,
5+ useState ,
46 type PropsWithChildren ,
57 type RefObject ,
68} from 'react' ;
@@ -125,6 +127,7 @@ export function useFormSmartScroll({
125127 const wrapperOffset = useAtomValue ( wrapperOffsetAtom ) ;
126128 const scrollY = useSharedValue ( 0 ) ;
127129 const scrollRef = useAnimatedRef < Animated . ScrollView > ( ) ;
130+ const [ isReady , setIsReady ] = useState ( false ) ;
128131
129132 const _keyboard = useKeyboard ( ) ;
130133
@@ -133,6 +136,12 @@ export function useFormSmartScroll({
133136
134137 const currentFocus = useAtomValue ( currentFocusAtom ) ;
135138
139+ useEffect ( ( ) => {
140+ if ( currentFocus && ! isReady ) {
141+ setTimeout ( ( ) => setIsReady ( true ) , 100 ) ;
142+ }
143+ } , [ currentFocus ] ) ;
144+
136145 const translateStyle = useAnimatedStyle ( ( ) => {
137146 function value ( ) : number {
138147 if ( ! currentFocus ) return 0 ;
@@ -181,7 +190,7 @@ export function useFormSmartScroll({
181190 }
182191
183192 return {
184- transform : [ { translateY : withTiming ( value ( ) ) } ] ,
193+ transform : [ { translateY : isReady ? withTiming ( value ( ) ) : 0 } ] ,
185194 } ;
186195 } ) ;
187196
@@ -289,5 +298,6 @@ export function useFormSmartScroll({
289298 baseScrollViewProps,
290299 baseTextInputProps,
291300 currentFocus : currentFocus ?. name ,
301+ isReady,
292302 } ;
293303}
You can’t perform that action at this time.
0 commit comments