Skip to content

Commit 963609d

Browse files
authored
fix: fixed animatedIndex interpolate node to handle one snap point (#92)
1 parent 783642b commit 963609d

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/components/bottomSheet/BottomSheet.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,21 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
260260
const animatedIndex = useMemo(
261261
() =>
262262
interpolate(position, {
263-
inputRange: snapPoints.slice().reverse(),
264-
outputRange: snapPoints
265-
.slice()
266-
.map((_, index) => index)
267-
.reverse(),
263+
/**
264+
* this been added to resolve issues when provide
265+
* one snap point.
266+
*/
267+
inputRange: [...snapPoints.slice().reverse(), containerHeight],
268+
outputRange: [
269+
...snapPoints
270+
.slice()
271+
.map((_, index) => index)
272+
.reverse(),
273+
-1,
274+
],
268275
extrapolate: Extrapolate.CLAMP,
269276
}),
270-
[position, snapPoints]
277+
[position, containerHeight, snapPoints]
271278
);
272279

273280
const animatedPosition = useMemo(

src/components/bottomSheet/useTransition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export const useTransition = ({
271271
call(
272272
[config.toValue, ...snapPoints],
273273
([_toValue, ..._animatedSnapPoints]) => {
274-
const currentIndex = currentIndexRef.current || -1;
274+
const currentIndex = currentIndexRef.current!;
275275
const nextIndex = _animatedSnapPoints.indexOf(_toValue);
276276

277277
if (onAnimate) {

0 commit comments

Comments
 (0)