Open andrecrimb opened 2 years ago
I'm having the exact same problem.
I believe you have to set enablePanDownToClose prop equal to false because it is true by default.
return (
<BottomSheet
enablePanDownToClose={false}
>
{Your stuff}
</BottomSheet>
)
Thanks @OfficialDarkComet, just tested and unfortunately setting enablePanDownToClose
to false doesn't solve the issue.
Glad I'm not the only one with this problem, my temporary solution is to defer the opening of the sheet after snapPoints have changed by a render, though it still will occasionally happen
The way around solution that we come up with to snap the BS to a "fallback index", when the it closes.
const useAvoidBottomSheetUnwantedClosedState = ({
animatedIndex,
snapPoints,
snapToFallbackIndex,
}: {
animatedIndex: number;
snapToFallbackIndex: () => void;
snapPoints: number[];
}) => {
useEffect(() => {
if (animatedIndex === BottomSheetState.Closed) {
snapToFallbackIndex();
}
}, [animatedIndex, snapToFallbackIndex, snapPoints]);
};
It doesn't solve the main issue, but avoids the unwanted closed state.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
The issue is still exists
@gorhom This issue still persist. Is there any updates on this?
Persists. Extremely sad to randomly experieence content in a closed state.
Seems this happens when the content has a state change / rerender happen during the opening animation. Doesnt happen in older versions. Fixed this by loading in content after the sheet has fully opened using the onChange callback.
I have experienced this too. Glad i have found this issue.
Seems this happens when the content has a state change / rerender happen during the opening animation. Doesnt happen in older versions. Fixed this by loading in content after the sheet has fully opened using the onChange callback.
what about setting animateOnMount=false? will it also solve the problem?
The way around solution that we come up with to snap the BS to a "fallback index", when the it closes.
const useAvoidBottomSheetUnwantedClosedState = ({ animatedIndex, snapPoints, snapToFallbackIndex, }: { animatedIndex: number; snapToFallbackIndex: () => void; snapPoints: number[]; }) => { useEffect(() => { if (animatedIndex === BottomSheetState.Closed) { snapToFallbackIndex(); } }, [animatedIndex, snapToFallbackIndex, snapPoints]); };
It doesn't solve the main issue, but avoids the unwanted closed state.
little update on the solution:
// Function to reset the bottom sheet to an open state
const snapToFallbackIndex = () => {
// Assuming 'bottomSheetRef' is a reference to the bottom sheet component
bottomSheetRef.current?.snapToIndex(0);
};
// Custom hook to avoid the bottom sheet being unintentionally closed
const useAvoidBottomSheetUnwantedClosedState = ({
animatedIndex, // Represents the animated index state of the bottom sheet
snapPoints, // Snap points for the bottom sheet
snapToFallbackIndex, // Function to snap to the fallback index
}) => {
useEffect(() => {
// Check if the bottom sheet is in a closed state (animatedIndex === -1)
if (animatedIndex.value === -1) {
// If so, reset it to an open state
snapToFallbackIndex();
}
}, [animatedIndex, snapToFallbackIndex, snapPoints]); // Dependencies for useEffect
};
enablePanDownToClose={false}
yes it is correct
Bug
I'm working in a project that has a bottom sheet with 2 dynamic snapPoints (minimised, medium), when these are quickly changing, the bottom sheet snaps to -1 (closed state) and doesn't snap back. I observed that this issue mostly happens, if in one of these changes, the snapPoints aren't ascending.
Video with sample code
https://user-images.githubusercontent.com/16760718/183125068-39815443-62ce-4203-b59d-4d7382c51815.mov
Environment info
Steps To Reproduce
Use sample code provided bellow to reproduce this issue.
Describe what you expected to happen:
animatedIndex
snaps to -1Reproducible sample code