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

Way to get content height or vertically centered

Open HenrikZabel opened this issue 1 year ago • 3 comments

Feature Request

With the useBottomSheetDynamicSnapPoints hook I was able to receive the height of the bottom sheet content using animatedContentHeight. A way to receive the content height would be great.

#1054 also requested this feature over a year ago, but the issue was automatically closed.

Why it is needed

I am using the BottomSheet in a detached form for a custom alert. The alert must be centered vertically and I calculating all the insets using the animatedContentHeight because the alert does not always have the same height.

Possible implementation

🤷‍♂️

Code sample

There could be two ways:

  1. Bring back the animtedContentHeight prop
  2. Implement a method in order to center the detached BottomSheet directly e.g. prop detachedCenteredVertically

HenrikZabel avatar Jan 07 '24 00:01 HenrikZabel

I want this feature too. Has anyone found the solution yet?

ng-ha avatar Feb 05 '24 04:02 ng-ha

@ng-ha here is what I do to achieve this:

const { height: windowHeight } = useWindowDimensions();
  const ref = useRef<BottomSheetModal>(null);

  const [bottomInset, setBottomInset] = useState(0);
  const handleContentLayout = useCallback(
    ({ nativeEvent: { layout } }: LayoutChangeEvent) => {
      setBottomInset((windowHeight - layout.height) / 2);
    },
    [windowHeight],
  );

return (
    <BottomSheetModal
      ref={ref}
      detached
      enableDynamicSizing
      bottomInset={bottomInset}
      enablePanDownToClose={false}
      enableContentPanningGesture={false}
    >
      <BottomSheetView
        onLayout={handleContentLayout}
        style={[styles.contentContainer, !buttons.length && styles['contentContainer--noButtons']]}
      >
       ...
      </BottomSheetView>
    </BottomSheetModal>

not the cleanest solution, but it does its' job

kuzkokov avatar Feb 05 '24 12:02 kuzkokov

I also encountered a problem. any other ideas?

theyanniss23002 avatar Feb 06 '24 17:02 theyanniss23002

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.

github-actions[bot] avatar Mar 08 '24 09:03 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Mar 14 '24 09:03 github-actions[bot]