Skip to content

[Bug]: The onChange callback is not firing consistently when the user manually drags the bottom sheet to a snap point. #2534

@kotu-kotuo

Description

@kotu-kotuo

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:

  1. If the user drags the sheet but it settles back to the same index,
    onChange won't fire
  2. 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: onChange fires with index=1
  • Actual: onChange does 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 sheet

Reproduction sample

https://snack.expo.dev/@nonomako/nanitabe

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions