@@ -7,10 +7,9 @@ import React, {
77 type RefObject ,
88} from 'react' ;
99import Animated , {
10- scrollTo ,
1110 useAnimatedRef ,
11+ useAnimatedScrollHandler ,
1212 useAnimatedStyle ,
13- useDerivedValue ,
1413 useSharedValue ,
1514 withTiming ,
1615 type AnimatedScrollViewProps ,
@@ -85,15 +84,15 @@ function InsideScrollView(
8584 additionalPadding ?: number ;
8685 } >
8786) {
88- const { scrollRef, baseScrollViewProps, translateStyle } = useFormSmartScroll (
89- { padding : props ?. additionalPadding }
90- ) ;
87+ const { scrollRef, baseScrollViewProps, translateStyle, scrollHandler } =
88+ useFormSmartScroll ( { padding : props ?. additionalPadding } ) ;
9189
9290 return (
9391 < Animated . ScrollView
9492 ref = { scrollRef }
9593 { ...baseScrollViewProps }
9694 { ...props . scrollViewProps }
95+ onScroll = { scrollHandler }
9796 >
9897 < Animated . View style = { translateStyle } > { props . children } </ Animated . View >
9998 </ Animated . ScrollView >
@@ -136,6 +135,11 @@ export function useFormSmartScroll({
136135
137136 const currentFocus = useAtomValue ( currentFocusAtom ) ;
138137
138+ const scrollHandler = useAnimatedScrollHandler ( ( event ) => {
139+ console . log ( 'event' , event . contentOffset . y ) ;
140+ scrollY . value = event . contentOffset . y ;
141+ } ) ;
142+
139143 // we have a flick on first focus so we make the scrollview wait a bit before animate
140144 useLayoutEffect ( ( ) => {
141145 if ( currentFocus && ! isReady ) {
@@ -218,10 +222,6 @@ export function useFormSmartScroll({
218222 [ inputs ]
219223 ) ;
220224
221- useDerivedValue ( ( ) => {
222- scrollTo ( scrollRef , 0 , scrollY . value , false ) ;
223- } ) ;
224-
225225 const onFocus = useCallback (
226226 ( name : string ) => ( ) => {
227227 setState ( ( s ) => ( {
@@ -300,5 +300,6 @@ export function useFormSmartScroll({
300300 baseTextInputProps,
301301 currentFocus : currentFocus ?. name ,
302302 isReady,
303+ scrollHandler,
303304 } ;
304305}
0 commit comments