@@ -13,6 +13,7 @@ import Animated, {
13
13
useAnimatedScrollHandler ,
14
14
useAnimatedStyle ,
15
15
useSharedValue ,
16
+ withDelay ,
16
17
withTiming ,
17
18
type AnimatedRef ,
18
19
type AnimatedScrollViewProps ,
@@ -99,7 +100,7 @@ const SmartScrollProvider = ({ children }: { children: React.ReactNode }) => {
99
100
const scrollRef = useAnimatedRef < Animated . ScrollView > ( ) ;
100
101
const scrollY = useSharedValue ( 0 ) ;
101
102
const wrapperRef = React . useRef < View > ( null ) ;
102
- const [ isReady , setIsReady ] = useState ( true ) ;
103
+ const [ isReady , setIsReady ] = useState ( false ) ;
103
104
const [ elements , setElements ] = useState < Elements > ( { } ) ;
104
105
const [ wrapperOffset , setWrapperOffset ] = useState ( 0 ) ;
105
106
const [ inputs , setInputs ] = useState < InputType > ( { } ) ;
@@ -115,7 +116,9 @@ const SmartScrollProvider = ({ children }: { children: React.ReactNode }) => {
115
116
// we have a flick on first focus so we make the scrollview wait a bit before animate
116
117
useLayoutEffect ( ( ) => {
117
118
if ( currentFocus && ! isReady ) {
118
- setTimeout ( ( ) => setIsReady ( true ) , isAndroid ? 250 : 100 ) ;
119
+ requestAnimationFrame ( ( ) => {
120
+ setIsReady ( true ) ;
121
+ } ) ;
119
122
}
120
123
} , [ currentFocus ] ) ;
121
124
@@ -276,8 +279,22 @@ export function useFormSmartScroll({
276
279
) ;
277
280
278
281
const translateStyle = useAnimatedStyle ( ( ) => {
282
+ if ( ! isReady && currentFocus ) {
283
+ // On first focus, delay the animation with native driver
284
+ return {
285
+ transform : [
286
+ {
287
+ translateY : withDelay (
288
+ Platform . OS === 'android' ? 150 : 16 ,
289
+ withTiming ( translateY . value )
290
+ ) ,
291
+ } ,
292
+ ] ,
293
+ } ;
294
+ }
295
+
279
296
return {
280
- transform : [ { translateY : isReady ? translateY . value : 0 } ] ,
297
+ transform : [ { translateY : translateY . value } ] ,
281
298
} ;
282
299
} , [ currentFocus ] ) ;
283
300
0 commit comments