-
-
Notifications
You must be signed in to change notification settings - Fork 913
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Version
v5
Reanimated Version
v3
Gesture Handler Version
v2
Platforms
iOS
What happened?
The onChange callback is not firing consistently when the user manually
drags the bottom sheet to a different snap point.
After looking at the source code (BottomSheet.tsx), I found that
onChange only fires when nextIndex !== animatedCurrentIndex.get() in
the animateToPositionCompleted function. This means:
- If the user drags the sheet but it settles back to the same index,
onChangewon't fire - Even if the sheet moves during the drag, if the final position is the
same index, no callback fires
This makes it difficult to track the sheet's position reliably in my app,
especially when I need to restore the sheet's position after showing a
modal.
Example scenario:
- Sheet is at snap point index 1 (70%)
- User drags the sheet slightly but releases it, and it snaps back to
index 1 - Expected:
onChangefires with index=1 - Actual:
onChangedoes not fire
Source code reference:
https://github.com/gorhom/react-native-bottom-sheet/blob/master/src/compo
nents/bottomSheet/BottomSheet.tsx#L636-L650
const animateToPositionCompleted = useCallback(
function animateToPositionCompleted(isFinished?: boolean) {
'worklet';
if (!isFinished) {
return;
}
const { nextIndex, nextPosition } = animatedAnimationState.get();
// callbacks
if (nextIndex !== animatedCurrentIndex.get()) { // ← Only fires if
index changed!
runOnJS(handleOnChange)(nextIndex, nextPosition);
}
// ...
},
[handleOnChange, ...]
);
### Reproduction steps
```markdown
1. Create a BottomSheet with snap points `["20%", "70%", "92%"]` and
initial index 1
2. Add an `onChange` callback with `console.log`
3. Manually drag the sheet from snap point 1 (70%) upward
4. Release the finger while still near snap point 1 (70%)
5. The sheet snaps back to index 1
6. Observe that `onChange` does not fire, even though the user interacted
with the sheetReproduction sample
https://snack.expo.dev/@nonomako/nanitabe
Relevant log output
kotu-kotuo
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working