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

[v4] Backdrop component with opacity appears at the bottom when bottomInset is set to BottomSheetModal #1816

Open
sofi-algoritcom opened this issue Apr 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@sofi-algoritcom
Copy link

Bug

If I set a backdrop component with opacity and set bottomInset prop to the BottomSheetModal using useSafeAreaInsets hook ('react-native-safe-area-context'), when the BottomSheetModal is presented, the backdrop component appears at the bottom using the bottomInset height.

Environment info

Trying it with the Expo App SDK 50, iPhone 15 Pro (iOS Version 17.4.1)

Library Version
@gorhom/bottom-sheet 4.6.1
react-native 0.73.6
react-native-reanimated 3.6.2
react-native-gesture-handler 2.14.0

Steps To Reproduce

  1. Present the BottomSheetModal and see the error at the bottom of the screen.

Describe what you expected to happen:

  1. The bottomInset space should be filled with the BottomSheetModal background, not the BackdropComponent's one.

Reproducible sample code

import { useMemo, useRef, useCallback } from 'react';
import { View, StyleSheet } from 'react-native';
import { enableLogging, BottomSheetBackdrop,
  BottomSheetBackdropProps, BottomSheetModal } from '@gorhom/bottom-sheet';
import List from './components/List';
import SearchHandle from './components/SearchHandle';
import Button from './components/Button';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

enableLogging();

const App = () => {
  // refs
  const bottomSheetRef = useRef(null);
  const insets = useSafeAreaInsets();

  // variables
  const snapPoints = useMemo(() => [200], []);

  // callbacks
  const handleExpandPress = useCallback(() => {
    bottomSheetRef.current?.expand();
  }, []);
  const handleCollapsePress = useCallback(() => {
    bottomSheetRef.current?.collapse();
  }, []);
  const handleClosePress = useCallback(() => {
    bottomSheetRef.current?.close();
  }, []);

   const backdropComponent = useCallback(
    (props: BottomSheetBackdropProps) => (
      <BottomSheetBackdrop
        {...props}
        appearsOnIndex={0}
        disappearsOnIndex={-1}
        opacity={0.48}
      />
    ),
    []
  );

  return (
    <View style={styles.container}>
      <Button onPress={handleExpandPress} title="Expand" />
      <Button onPress={handleCollapsePress} title="Collapse" />
      <Button onPress={handleClosePress} title="Close" />
      <BottomSheetModal
        backgroundStyle={{ backgroundColor: colors.background }}
        backdropComponent={backdropComponent}
        bottomInset={insets.bottom}
        ref={bottomSheetRef}
        snapPoints={snapPoints}
        keyboardBehavior="interactive"
        handleComponent={SearchHandle}
        animateOnMount={true}
        android_keyboardInputMode="adjustPan">
        <List type="FlatList" />
      </BottomSheetModal>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    paddingVertical: 64,
    justifyContent: 'flex-start',
    backgroundColor: '#222',
  },
});

export default App;
@sofi-algoritcom sofi-algoritcom added the bug Something isn't working label Apr 26, 2024
@sofi-algoritcom sofi-algoritcom changed the title [v4] | [v2] Backdrop component with opacity appears at the bottom when bottomInset is set to BottomSheetModal [v4] Backdrop component with opacity appears at the bottom when bottomInset is set to BottomSheetModal Apr 26, 2024
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