Skip to content

Commit bbdd02e

Browse files
committed
fix(intro-screen-native): race condition in ios
1 parent e781ab1 commit bbdd02e

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

packages/pluggableWidgets/intro-screen-native/src/SwipeableContainer.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const SwipeableContainer = (props: SwipeableContainerProps): ReactElement
7070
const [width, setWidth] = useState(0);
7171
const [activeIndex, setActiveIndex] = useState(0);
7272
const flashList = useRef<FlashListRef<any>>(null);
73+
const isInitializing = useRef(true);
7374

7475
const rtlSafeIndex = useCallback(
7576
(i: number): number => (isAndroidRTL ? props.slides.length - 1 - i : i),
@@ -92,6 +93,16 @@ export const SwipeableContainer = (props: SwipeableContainerProps): ReactElement
9293
const slide = refreshActiveSlideAttribute(props.slides, props.activeSlide);
9394
if (width && props.activeSlide?.status === ValueStatus.Available && slide !== activeIndex) {
9495
goToSlide(slide);
96+
if (isInitializing.current) {
97+
if (isInitializing.current) {
98+
// Use requestAnimationFrame twice to wait for the next frame after scroll.
99+
requestAnimationFrame(() => {
100+
requestAnimationFrame(() => {
101+
isInitializing.current = false;
102+
});
103+
});
104+
}
105+
}
95106
}
96107
}, [props.activeSlide, activeIndex, width, props.slides, goToSlide]);
97108

@@ -298,6 +309,12 @@ export const SwipeableContainer = (props: SwipeableContainerProps): ReactElement
298309
if (newIndex === activeIndex) {
299310
return;
300311
}
312+
313+
if (isInitializing.current) {
314+
setActiveIndex(newIndex);
315+
return;
316+
}
317+
301318
const lastIndex = activeIndex;
302319
setActiveIndex(newIndex);
303320
onSlideChange(newIndex, lastIndex);

0 commit comments

Comments
 (0)