Skip to content

Commit 74db26d

Browse files
committed
fix: onAnimate not called with -1 when immediately closed + add source
Reapply these commits: - gorhom@d66fae4 - gorhom@2216d85
1 parent d6693b1 commit 74db26d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/components/bottomSheet/BottomSheet.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
542542
);
543543
// biome-ignore lint/correctness/useExhaustiveDependencies(BottomSheet.name): used for debug only
544544
const handleOnAnimate = useCallback(
545-
function handleOnAnimate(targetIndex: number, targetPosition: number) {
545+
function handleOnAnimate(targetIndex: number, targetPosition: number, source: ANIMATION_SOURCE) {
546546
if (__DEV__) {
547547
print({
548548
component: BottomSheet.name,
@@ -561,12 +561,16 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
561561
return;
562562
}
563563

564-
if (targetIndex !== animatedCurrentIndex.value) {
564+
if (targetIndex !== animatedCurrentIndex.value
565+
// there is a race condition when opening and immedately closing the bottom sheet, where
566+
// the animatedCurrentIndex is not updated yet. As we don't want to miss close events we always call the callback for -1 changes:
567+
|| targetIndex === -1) {
565568
_providedOnAnimate(
566569
animatedCurrentIndex.value,
567570
targetIndex,
568571
animatedPosition.value,
569-
targetPosition
572+
targetPosition,
573+
source,
570574
);
571575
}
572576
},
@@ -675,7 +679,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
675679
/**
676680
* fire `onAnimate` callback
677681
*/
678-
runOnJS(handleOnAnimate)(animatedNextPositionIndex.value, position);
682+
runOnJS(handleOnAnimate)(animatedNextPositionIndex.value, position, source);
679683

680684
/**
681685
* start animation

src/components/bottomSheet/types.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ export interface BottomSheetProps
290290
fromIndex: number,
291291
toIndex: number,
292292
fromPosition: number,
293-
toPosition: number
293+
toPosition: number,
294+
source: ANIMATION_SOURCE
294295
) => void;
295296
//#endregion
296297

0 commit comments

Comments
 (0)