Skip to content

Commit

Permalink
fix: handle unnecessary invocation of handleSnapToIndex on onAnimate …
Browse files Browse the repository at this point in the history
…recreation
  • Loading branch information
IslamRustamov committed Dec 7, 2024
1 parent 7bfe7ae commit 33b827c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {
useImperativeHandle,
memo,
useEffect,
useRef,
} from 'react';
import { type Insets, Platform } from 'react-native';
import { State } from 'react-native-gesture-handler';
Expand Down Expand Up @@ -1854,14 +1855,21 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
[reduceMotion, handleOnChange, _providedOnClose]
);

/**
* Remember previously provided index, so that we don't cause
* unnecessary handleSnapToIndex
*/
const previousProvidedIndex = useRef(_providedIndex)

/**
* React to `index` prop to snap the sheet to the new position.
*
* @alias onIndexChange
*/
useEffect(() => {
if (isAnimatedOnMount.value) {
if (isAnimatedOnMount.value && previousProvidedIndex.current !== _providedIndex) {
handleSnapToIndex(_providedIndex);
previousProvidedIndex.current = _providedIndex
}
}, [_providedIndex, isAnimatedOnMount, handleSnapToIndex]);
//#endregion
Expand Down

0 comments on commit 33b827c

Please sign in to comment.