react-native-bottom-sheet icon indicating copy to clipboard operation
react-native-bottom-sheet copied to clipboard

[v4] enableDynamicSizing does not work

Open mstaniewski opened this issue 1 year ago • 10 comments

Bug

I need bottom sheet modals to adjust to its content height. I have found enableDynamicSizing prop in documentation and a pull request regarding dynamic sizing: https://github.com/gorhom/react-native-bottom-sheet/pull/1513

I have checked the example on how to use it here:

https://github.com/gorhom/react-native-bottom-sheet/pull/1513/files#diff-3f9ab4750993038cd43946db156ced8ad2138a75159f43862a3906e0747af3e7R52

Unfortunately bottom sheet height is not calculated properly. First modal appears good because it has snap points set. Second is displaying like content would be of height 0

https://github.com/gorhom/react-native-bottom-sheet/assets/11744682/7e8ffb53-37d3-4310-8d8e-c7b290680254

Environment info

"@gorhom/bottom-sheet": "^4.6.0", "react-native": "^0.73.2",

Library Version
@gorhom/bottom-sheet 4.6.0
react-native 0.73.2
react-native-reanimated 3.6.1
react-native-gesture-handler 2.14.0

Steps To Reproduce

Import BottomSheetModal from module, use it as presented in example and docs. Content height is not calculated

Describe what you expected to happen:

Modal appears with height adjusted to its content

Reproducible sample code

<BottomSheetModal ref={ref} enableDynamicSizing>
  <BottomSheetView>
    <View style={{height: 200, backgroundColor: 'black'}} />
  </BottomSheetView>
</BottomSheetModal>

mstaniewski avatar Jan 23 '24 22:01 mstaniewski

I tried to reproduce this not able to reproduce @mstaniewski please share details.if possible share along with snack example

MANIKANDAN1709 avatar Jan 24 '24 20:01 MANIKANDAN1709

Same issues with the bottom sheet cannot be get the correct height without set any snapPoints.

export default function Test() {
  const [item, setItem] = useState<String>();
  const bottomSheetRef = useRef<BottomSheet>(null);

  useEffect(() => {
    new Promise((resolve) => {
      resolve(setItem("Test"));
    }).then(() => bottomSheetRef.current?.expand());
  });

  return (
    <BottomSheet
      ref={bottomSheetRef}
      snapPoints={[]}
      enablePanDownToClose
      enableDynamicSizing
      animateOnMount
      index={-1}
    >
      <BottomSheetView>{item && <Text>Testing</Text>}</BottomSheetView>
    </BottomSheet>
  );
}

stewardccm avatar Feb 04 '24 13:02 stewardccm

Make sure to wrap your app/screen in BottomSheetModalProvider and provide a valid (snap point) index (e.g. 0)

VolkerLieber avatar Feb 04 '24 15:02 VolkerLieber

The app/screen is in BottomSheetModalProvider and updates the method to bottomSheetRef.current?.snapToIndex(0). Still getting the same result, is there any misunderstanding on my part?

stewardccm avatar Feb 05 '24 16:02 stewardccm

I also encountered a problem. any other ideas?

theyanniss23002 avatar Feb 06 '24 17:02 theyanniss23002

https://github.com/gorhom/react-native-bottom-sheet/issues/1573

You can find a workaround here

adelbeke avatar Feb 15 '24 08:02 adelbeke

My workaround: https://github.com/gorhom/react-native-bottom-sheet/issues/1573#issuecomment-1952993877

shamilovtim avatar Feb 19 '24 18:02 shamilovtim

I found a hacky workaround adding a minHeight or padding to BottomSheetView.

  <BottomSheetBase
      ref={bottomSheetRef}
      backdropComponent={BackdropView}
      footerComponent={Footer}
      handleComponent={handleComponent}
      enablePanDownToClose
      onClose={onClose}
      enableDynamicSizing
    >
      <BottomSheetView
        style={{ minHeight: 10 }} // <----- It works 🤷🏽‍♂️ 
      >

Still this is super hacky and should be solved 👍🏽

andrecrimb avatar Mar 12 '24 14:03 andrecrimb