You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use a bottom sheet to show two different views, let's call them A and B. The snap points for my bottom sheet change based on this view. When switching between A and B I want to go back to the snap point I had when I last used that state.
However, when I move between A and B I can't call snapToIndex, because the index might be out of range, my bottom sheet hasn't picked up the updated snap points yet.
const snapPoints = useMemo(() => {
return aOrB === 'A' ? [...] : [...]
}, [aOrB])
useEffect(() => {
// Doesn't work, index may not exist yet.
sheetRef.current?.snapToIndex(aOrB ? priorIndexForA : priorIndexForB)
// Sort of works but has a bug.
sheetRef.current?.snapToPosition(aOrB ? priorPositionForA : priorPositionForB)
}, [aOrB])
return <BottomSheet ref={sheetRef} snapPoints={snapPoints} ...
Calling snaptoPosition sort of works but there's I can't expand my sheet unless I first make it smaller.
const snapPoints = useMemo(() => {
return aOrB === 'A' ? [...] : [...]
}, [aOrB])
useEffect(() => {
// Sort of works but has a bug.
sheetRef.current?.snapToPosition(aOrB ? priorPositionForA : priorPositionForB)
}, [aOrB])
return <BottomSheet ref={sheetRef} snapPoints={snapPoints} ...
This is caused by this logic in bottom-sheet, this might be a bug I need to spend some time understanding the logic.
/**
* if the sheet is in a temporary position and the gesture ended above
* the current position, then we snap back to the temporary position.
*/
if (
isInTemporaryPosition.value &&
context.initialPosition >= animatedPosition.value
) {
if (context.initialPosition > animatedPosition.value) {
animateToPosition(
context.initialPosition,
ANIMATION_SOURCE.GESTURE,
velocityY / 2
);
}
return;
}
Is there a way I can tell when the snap points have been updated, so that I can use snapToIndex?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I use a bottom sheet to show two different views, let's call them A and B. The snap points for my bottom sheet change based on this view. When switching between A and B I want to go back to the snap point I had when I last used that state.
However, when I move between A and B I can't call
snapToIndex
, because the index might be out of range, my bottom sheet hasn't picked up the updated snap points yet.Calling
snaptoPosition
sort of works but there's I can't expand my sheet unless I first make it smaller.This is caused by this logic in bottom-sheet, this might be a bug I need to spend some time understanding the logic.
Is there a way I can tell when the snap points have been updated, so that I can use
snapToIndex
?Beta Was this translation helpful? Give feedback.
All reactions