-
-
Notifications
You must be signed in to change notification settings - Fork 744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v4] BottomSheetBackdrop - appearsOnIndex of 0 fails to render backdrop (has workaround) #779
Comments
In case someone gets to this before I can put a PR together, the issue is here and the signature probably needs to be rewritten to something like: const BottomSheetBackdropComponent = ({
animatedIndex,
opacity,
appearsOnIndex,
disappearsOnIndex,
enableTouchThrough = DEFAULT_ENABLE_TOUCH_THROUGH,
pressBehavior = DEFAULT_PRESS_BEHAVIOR,
style,
children,
}: BottomSheetDefaultBackdropProps) => {
//#region defaults
opacity = opacity ?? DEFAULT_OPACITY;
appearsOnIndex = appearsOnIndex ?? DEFAULT_APPEARS_ON_INDEX;
disappearsOnIndex = disappearsOnIndex ?? DEFAULT_DISAPPEARS_ON_INDEX;
//#endregion It's only an issue because the initial value of // conditional operator for undefined value
opacity = (typeof opacity !== "undefined") ? opacity : DEFAULT_OPACITY;
// Allow explicit zero, otherwise coerce
opacity = opacity === 0 ? 0 : opacity || DEFAULT_OPACITY; |
Coercion of 0 and false result in defaults being accidentally assigned to the BottomSheetBackdrop's props. This fix uses the null coalesce operator ?? to use either a user supplied value or fall back to the built-in default. Resolves gorhom#779
Hi, any update on this issue ? 🙏 |
PR is in #793. Hopefully it gets addressed soon. In the meantime, you can create your own backdrop with the changes, which is what we did. |
Coercion of 0 and false result in defaults being accidentally assigned to the BottomSheetBackdrop's props. This fix uses the null coalesce operator ?? to use either a user supplied value or fall back to the built-in default. Resolves gorhom#779
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. |
You could write a custom backdrop component until the PR merged import { BottomSheetBackdropProps } from '@gorhom/bottom-sheet'
import React, { useMemo } from 'react'
import Animated, {
Extrapolate,
interpolate,
useAnimatedStyle,
} from 'react-native-reanimated'
const CustomBackdrop = ({ animatedIndex, style }: BottomSheetBackdropProps) => {
const containerAnimatedStyle = useAnimatedStyle(() => ({
opacity: interpolate(
animatedIndex.value,
[-1, 0],
[0, 0.5],
Extrapolate.CLAMP
),
}))
const containerStyle = useMemo(
() => [style, { backgroundColor: '#a8b5eb' }, containerAnimatedStyle],
[style, containerAnimatedStyle]
)
return <Animated.View style={containerStyle} />
}
export default CustomBackdrop |
Bug
As of
4.1.5
, theBottomSheetBackdrop
does not support a value ofappearsOnIndex={0}
. The root cause seems to be coercion to a default of1
from a falsey0
value.Environment info
Steps To Reproduce
renderBackdrop
from the exampleappearsOnIndex={0}
anddisappearsOnIndex={0}
Describe what you expected to happen:
0
Workaround Providing a
snapIndex
such assnapIndex={[1, "40%"]}
will work although technically the modal will be visible at the bottom of the screen. Alternatively, you can copy/paste theBottomSheetBackdrop
into a new component with either new defaults or fixed coercion.Reproducible sample code
Reproducible Snack: https://snack.expo.dev/@jakobo/bottomsheetbackdrop---appearsonindex-bug
The text was updated successfully, but these errors were encountered: