From 2820555a64584715e4143b119b0d469bb08fad79 Mon Sep 17 00:00:00 2001 From: Arkadiusz Kubaczkowski Date: Wed, 19 Aug 2026 17:25:33 +0200 Subject: [PATCH] fix(swmansion): report 0 as prevIndex for the programmatic open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `lastIndexRef` seeded from the `index` state, which starts at `openIndex` for portal and inline sheets — mounting *is* the open there, and native animates in from the collapsed detent. So `expand()` emitted `onIndexChange(openIndex, openIndex)` and consumers branching on the 0 -> open transition (haptics on open, for one) never fired. Portal sheets unmount on close, so the ref reset every cycle and the transition was never observable at all; only persistent sheets (`defaultIndex: -1`, so `index` starts at 0) got it right. Seed the tracker at 0 instead: the sheet is off screen until `expand()` lands, in every mode. Co-Authored-By: Claude Opus 5 (1M context) --- src/adapters/swmansion/SwmansionSheetAdapter.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/adapters/swmansion/SwmansionSheetAdapter.tsx b/src/adapters/swmansion/SwmansionSheetAdapter.tsx index 69b85f9..a923f10 100644 --- a/src/adapters/swmansion/SwmansionSheetAdapter.tsx +++ b/src/adapters/swmansion/SwmansionSheetAdapter.tsx @@ -431,7 +431,10 @@ export const SwmansionSheetAdapter = React.forwardRef< // Last index seen, mirrored on every move — supplies `prevIndex` to // `onIndexChange`. The `index` state only swings between 0 and `openIndex`, // so it can't track snaps between non-zero detents. - const lastIndexRef = useRef(index); + // Starts at 0, not at `index`: a portal/inline sheet mounts with `index` + // already at `openIndex`, so seeding from state would report the open as + // `(openIndex, openIndex)`. + const lastIndexRef = useRef(0); if (__DEV__ && resolveDetentValue(detents[0] ?? 0) !== 0) { console.warn(