fix: stream actions not working

Multiple sheets compete with each other and cause silent failure on ios.
This commit is contained in:
talksik
2026-04-30 16:53:48 -07:00
parent 6832c273cd
commit a6a4757a8e
2 changed files with 40 additions and 4 deletions
+22 -2
View File
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import {
Dimensions,
KeyboardAvoidingView,
@@ -30,6 +30,13 @@ const ANIMATION_MS = 240;
interface BottomSheetProps {
open: boolean;
onClose: () => void;
/**
* Fires after the close animation completes and the underlying Modal has
* unmounted. Use this to chain a follow-up sheet/Alert without stacking
* iOS Modals — presenting a second Modal while another is still mounted
* silently fails on iOS and leaves the app looking frozen.
*/
onClosed?: () => void;
/** When true, wrap content in KeyboardAvoidingView so the sheet floats above the keyboard. */
avoidKeyboard?: boolean;
/**
@@ -49,6 +56,7 @@ interface BottomSheetProps {
export function BottomSheet({
open,
onClose,
onClosed,
avoidKeyboard = false,
maxHeight = "85%",
children,
@@ -58,6 +66,18 @@ export function BottomSheet({
const [mounted, setMounted] = useState(false);
const translateY = useSharedValue(SCREEN_HEIGHT);
// Latest onClosed in a ref so the worklet→JS bridge always invokes the
// current callback even if the parent re-rendered with a new closure.
const onClosedRef = useRef(onClosed);
useEffect(() => {
onClosedRef.current = onClosed;
}, [onClosed]);
const handleClosed = useCallback(() => {
setMounted(false);
onClosedRef.current?.();
}, []);
useEffect(() => {
if (open) {
setMounted(true);
@@ -73,7 +93,7 @@ export function BottomSheet({
SCREEN_HEIGHT,
{ duration: ANIMATION_MS, easing: Easing.in(Easing.cubic) },
(finished) => {
if (finished) runOnJS(setMounted)(false);
if (finished) runOnJS(handleClosed)();
},
);
}