Skip to content

Commit 2921a6e

Browse files
committed
fix(flick): fix flick on first focus
1 parent 975716d commit 2921a6e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Provider.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 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
}

0 commit comments

Comments
 (0)