Skip to content
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

[Bug]: More snapPoints then specified #1982

Closed
mbpictures opened this issue Oct 17, 2024 · 1 comment
Closed

[Bug]: More snapPoints then specified #1982

mbpictures opened this issue Oct 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mbpictures
Copy link

mbpictures commented Oct 17, 2024

Version

v5

Reanimated Version

v3

Gesture Handler Version

v2

Platforms

iOS, Android

What happened?

In some situations, the modal snaps to more snap points then specified. So e.g. I provide two snapPoints (one above the bottom bar, one higher), but since v5 I can snap the modal to more than 2 points (one slightly above the bottom bar, one above the bottom bar and one higher).

Reproduction steps

    const insets = useSafeAreaInsets();
    const realHeight = useAppSelector(selectRealHeight);
    const bottomInsets = Platform.select({android: insets.bottom, default: 0});
    const snapPoints = useMemo(() => [BOTTOM_NAVIGATION_HEIGHT + 45 + 24, realHeight - MINIMIZED_TOP_HEIGHT], [realHeight]);

    // workaround https://github.com/gorhom/react-native-bottom-sheet/issues/1053#issuecomment-1824132757
    useEffect(() => {
        // Check if the bottom sheet is in a closed state (animatedIndex === -1)
        if (position?.value === -1) {
            // If so, reset it to an open state
            bottomSheetRef.current?.snapToIndex(0);
        }
    }, [position, snapPoints]);
    return (
        <BottomSheet
            backgroundStyle={{
                backgroundColor: theme.colors.inverseSurface
            }}
            handleComponent={null}
            ref={bottomSheetRef}
            index={0}
            snapPoints={snapPoints}
            style={{
                zIndex: 21
            }}
            topInset={MINIMIZED_TOP_HEIGHT}
            bottomInset={bottomInsets}
            animatedIndex={position}
            enableContentPanningGesture={true}
            enableOverDrag={false}
            enablePanDownToClose={false}
        >
            <BottomSheetView style={{flex: 1, paddingBottom: BOTTOM_NAVIGATION_HEIGHT + bottomInsets}}>
                <View style={{width: "100%", alignItems: "center"}}>
                    <ModalHandle onPress={() => bottomSheetRef.current?.snapToIndex(0)} />
                </View>
                <TabsProvider
                    defaultIndex={0}
                    onChangeIndex={(i) => {
                        if (!open || tabIndex.current === null) {
                            tabIndex.current = i;
                            return;
                        }
                        tabIndex.current = i;
                        bottomSheetRef.current?.snapToIndex(1);
                    }}
                >
                    <Tabs disableSwipe uppercase tabLabelStyle={{
                        fontSize: theme.fonts.bodyMedium.fontSize,
                        fontFamily: theme.fonts.bodyMedium.fontFamily,
                        fontWeight: theme.fonts.bodyMedium.fontWeight,
                        letterSpacing: theme.fonts.bodyMedium.letterSpacing,
                        color: theme.colors.inverseOnSurface
                    }} style={{backgroundColor: theme.colors.inverseSurface, maxHeight: 50, marginTop: -5}}>
                        <TabScreen label={t("next-title")}>
                            <PlaylistScene/>
                        </TabScreen>
                        <TabScreen label={t("lyrics")}
                                   disabled={typeof song?.lyrics === "undefined" || song?.lyrics?.length === 0}>
                            <LyricsScene lyrics={song?.lyrics}/>
                        </TabScreen>
                        <TabScreen label={t("sheets")} disabled={typeof pdfFile === "undefined"}>
                            <SheetScene pdfFile={pdfFile}/>
                        </TabScreen>
                    </Tabs>
                </TabsProvider>
            </BottomSheetView>
        </BottomSheet>
    );

Reproduction sample

https://snack.expo.dev/@franamu/bottom-sheet---issue-reproduction-template

Relevant log output

When passing these two snapPoints: [139, 777.2571341378348], BottomSheet logs these animatedSnapPoints: 702.0951995849609, 638.142822265625, 0

@mbpictures mbpictures added the bug Something isn't working label Oct 17, 2024
@mbpictures
Copy link
Author

My bad! I forgot to disable enableDynamicSizing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant