react-native-true-sheet
react-native-true-sheet copied to clipboard
bug: passing scrollRef causes element being pinned to top without respecting height of nodes before the scrollview
Assume the following structure:
<TrueSheet>
<MyHeaderComponent />
<FlashList />
</TrueSheet>
All good so far. But once I pass the scrollRef (with FlashList, unlike FlatList, you need to pass the scrollableNode like so):
ref={(ref) => {
if (scrollRef) {
;(scrollRef.current as unknown) = ref?.getScrollableNode()
}
}}
It works fine. The main problem I have is that (at least on iOS; I haven't tested Android yet), there is a utility function called pinTo
, which now pins the whole view behind MyHeaderComponent
, thus not taking the element's height into account.
I've experimented with TrueSheetView
and tested adding offsets like so:
rctScrollView.pinTo(view: contentView) { constraints in
constraints.top?.constant = 50 // 50 is the height of my header
}
So this works. I think there are multiple ways to solve this problem:
- Add a HeaderComponent, similar to FooterComponent, and handle all of this under the hood.
- Ensure to run through all the siblings of TrueSheet before the actual ScrollView and automatically calculate the offset.
- Add a prop (like scrollViewOffset), and we pass a value to it, like 50
Before Patch | After Patch |
---|---|
You may ask why I don't use HeaderComponent by FlashList? Well, because it does not keep the header fixed.
My example above is just a quick "test", not a fix. The offset needs to be reflected in all calculations etc, similar to the footer.