React-native-reanimated-bottom-sheet: Updating sheet position after snapPoints change

Created on 16 Jul 2019  路  5Comments  路  Source: osdnk/react-native-reanimated-bottom-sheet

It doesn't appear that the position of the sheet changes if the snapPoints props are changed. Is there any way to make this work? Or is that not supported?

It would be nice to have the positions be dynamic based on content heights, where the snapPoints are defined from state values set in onLayout callbacks of the sheet elements.

Most helpful comment

@osdnk is there a recommended way to do this? Seems like dynamic snapPoint support would be an awesome addition to this

All 5 comments

As a workaround you can set the key to a value changes with the snapPoints. This will force a re-render.

For example:

const BottomSheetContainer = ({ snapPointHeight }) => {
  return (
    <BottomSheet
      key={snapPointHeight}
      renderContent={() => <BottomSheetContent />}
      renderHeader={() => <BottomSheetHeader />}
      snapPoints={[snapPointHeight, 400]}
    />
  )
}

@osdnk is there a recommended way to do this? Seems like dynamic snapPoint support would be an awesome addition to this

@EricPKerr @osdnk In my project I don't know in advance the height of the content which is passed to BottomSheet's renderContent, is it possible to snap by percentage of the 'contentHeight' not the 'screenHeight'?

As a workaround you can set the key to a value changes with the snapPoints. This will force a re-render.

For example:

const BottomSheetContainer = ({ snapPointHeight }) => {
  return (
    <BottomSheet
      key={snapPointHeight}
      renderContent={() => <BottomSheetContent />}
      renderHeader={() => <BottomSheetHeader />}
      snapPoints={[snapPointHeight, 400]}
    />
  )
}

When I set the key, the app just freezes

I actually look forward to this update. My issue is when device orientation changes, let say i have snapPoinst is like this: ['70%', '45%, '25%']. When it was initialized at Portrait mode, snap points are correctly calculated. However, once rotate to landscape mode, you can see the snap points are no longer going to the right places even when i am not having a dynamic snapPoint and only using a static % values. When i said right places, means that the alignments are different between initialized at Portrait mode first and rotate vs. initialized at Landscape mode first and rotate. Because of this, the sheet often went overboard and I can't close it because I have a header as well. :(

So then i tried to solve it with dynamic snapPoints, yet, no luck. So I would appreciate if the next update has this fix. It's a great component so far! 馃憤

Was this page helpful?
0 / 5 - 0 ratings