-
-
Notifications
You must be signed in to change notification settings - Fork 716
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
Drawer scrollable with dynamic max height #1402
Drawer scrollable with dynamic max height #1402
Conversation
@gorhom can you please review this PR 🙏🏻 |
code looks neat but have you tried with the v5 whici is still alpha? |
4.4.5 is the latest version I tested this on. |
Will this help fix issues with horizontal scrolling within a ScrollView or FlatList? I have tried using both of these components imported from React Native and react-native-gesture-handler. I am unable to get either one of them to scroll horizontally. Is there a CSS attribute that will work like flex but for width that will make the scrollview/flatlist take up the entire content width? |
This will not help with the issue you said, |
@ororsatti that's great, so with web support coming in v5, I would ditch https://github.com/ammarahm-ed/react-native-actions-sheet and use this library only |
Oh you come around to test this on v5? |
not yet, will do as soon as v5 is stable. |
@ororsatti @gorhom I am still having issues getting a ScrollView or FlatList to scroll horizontally within a BottomSheet component. I am currently using a ScrollView from 'react-native-gesture-handler'. I have tried using a ScrollView and FlatList from all recommended node modules (RNGH, RN, and BottomSheet). Touch events for ScrollView/FlatList components don't seem to be working if they are set to scroll horizontally.
|
@ororsatti Could you help out? I've used your fork for a project of ours and it seems to work mostly all right, but it doesn't seem to work right with a backdrop; the backdrop seems to break the auto adjustment. I'm sure it's a matter of passing it the right number / property, but... I'm a bit lost on the subject. |
|
@fwielstra Looks to me that it works just fine. Simulator.Screen.Recording.-.iPhone.14.-.2023-07-21.at.15.26.28.mp4 |
Fixes issues described in these discussions: gorhom/react-native-bottom-sheet#658 gorhom/react-native-bottom-sheet#1363 gorhom/react-native-bottom-sheet#1402
I hope, I tried contacting him on Twitter as well after I saw the excitement around this topic |
I found some problems when using this hook with dynamic content that changes before showing the bottom sheet. The solution I opted for is: // ....
const initialSnapPoints = useMemo(() => ["CONTENT_HEIGHT"], [])
const {
animatedHandleHeight,
animatedSnapPoints,
animatedContentHeight,
handleContentLayout,
} = useBottomSheetDynamicSnapPoints(initialSnapPoints)
const maxHeightStyle = useBottomSheetMaxHeight(maxHeight)
return (
<BottomSheetModal
// .... other props
snapPoints={animatedSnapPoints as any}
handleHeight={animatedHandleHeight}
contentHeight={animatedContentHeight}
>
<BottomSheetScrollView
onLayout={handleContentLayout}
style={{
maxHeight: maxHeightStyle,
}}
>
{children}
</BottomSheetScrollView>
</BottomSheetModal>
)
// ... With the custom /*
Designed to take the specified max height, take away top safe
area inset and convert to a decimal
*/
import { useWindowDimensions } from "react-native"
import { useSafeAreaInsets } from "react-native-safe-area-context"
export const useBottomSheetMaxHeight = (maxHeight = "85%"): number => {
const { height: deviceHeight } = useWindowDimensions()
const maxHeightDecimal = parseFloat(`${maxHeight}`) / 100.0
const { top: topSafeAreaInset } = useSafeAreaInsets()
return (deviceHeight - topSafeAreaInset) * maxHeightDecimal
} |
closing this PR in favour of #1513, which it has been merged. Thanks @ororsatti |
Adding a hook to have a drawer with a max height that will dynamically change its height until reaching the limit, following this discussion of mine: #1363
Motivation
People are asking for this feature for a while now, and asked me in the discussion to share the code.
Closes: (#658 , #32)
Example:
Simulator.Screen.Recording.-.iPhone.13.-.2023-06-15.at.09.07.01.mp4