Skip to content

Commit 17e5549

Browse files
committed
fix(web): re-apply cascade transform when vaul clobbers it
1 parent da7c106 commit 17e5549

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/TrueSheet.web.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ const TrueSheetComponent = forwardRef<TrueSheetMethods, TrueSheetProps>((props,
209209
return;
210210
}
211211

212-
const raf = requestAnimationFrame(() => {
213-
if (!parent) return;
212+
const computeTargetY = () => {
214213
const parentSnap = parseFloat(parent.style.getPropertyValue('--snap-point-height')) || 0;
215214
let targetY = parentSnap;
216215
for (const d of descendants) {
@@ -219,12 +218,29 @@ const TrueSheetComponent = forwardRef<TrueSheetMethods, TrueSheetProps>((props,
219218
const snap = parseFloat(node.style.getPropertyValue('--snap-point-height')) || 0;
220219
if (snap > targetY) targetY = snap;
221220
}
221+
return targetY;
222+
};
222223

224+
const apply = () => {
225+
const targetY = computeTargetY();
226+
const match = parent.style.transform.match(/translate3d\([^,]*,\s*(-?\d*\.?\d+)px/);
227+
const currentY = match ? parseFloat(match[1]!) : 0;
228+
if (Math.abs(currentY - targetY) < 0.5) return;
223229
parent.style.transition = transition;
224230
parent.style.transform = `translate3d(0, ${targetY}px, 0)`;
225-
});
231+
};
226232

227-
return () => cancelAnimationFrame(raf);
233+
const raf = requestAnimationFrame(apply);
234+
// Vaul re-runs snapToPoint on window resize (e.g., mobile keyboard open)
235+
// which clobbers the cascade transform. Re-apply whenever the parent's
236+
// inline style changes.
237+
const observer = new MutationObserver(apply);
238+
observer.observe(parent, { attributes: true, attributeFilter: ['style'] });
239+
240+
return () => {
241+
cancelAnimationFrame(raf);
242+
observer.disconnect();
243+
};
228244
}, [descendants, activeSnapPoint]);
229245

230246
const mergedContentStyle = useMemo<React.CSSProperties>(

0 commit comments

Comments
 (0)