Skip to content

Commit

Permalink
feat: react to index prop changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Jul 18, 2021
1 parent 603f492 commit 55af54b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, {
forwardRef,
useImperativeHandle,
memo,
useEffect,
} from 'react';
import { Keyboard, Platform } from 'react-native';
import invariant from 'invariant';
Expand Down Expand Up @@ -1695,16 +1696,32 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
},
[handleOnChange]
);

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

// render
print({
component: BottomSheet.name,
method: 'render',
params: {
topInset,
bottomInset,
animatedSnapPoints: animatedSnapPoints.value,
animatedCurrentIndex: animatedCurrentIndex.value,
providedIndex: _providedIndex,
},
});
return (
Expand Down

0 comments on commit 55af54b

Please sign in to comment.