Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/flatList/FlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const BottomSheetFlatListComponent = forwardRef(
const {
scrollableRef,
handleOnBeginDragEvent,
handleOnContentSizeChange,
handleSettingScrollable,
} = useScrollableInternal('FlatList');
const {
Expand Down Expand Up @@ -74,6 +75,7 @@ const BottomSheetFlatListComponent = forwardRef(
bounces={false}
decelerationRate={decelerationRate}
scrollEventThrottle={16}
onContentSizeChange={handleOnContentSizeChange}
onScrollBeginDrag={handleOnBeginDragEvent}
/>
</NativeViewGestureHandler>
Expand Down
2 changes: 2 additions & 0 deletions src/components/scrollView/ScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const BottomSheetScrollViewComponent = forwardRef(
const {
scrollableRef,
handleOnBeginDragEvent,
handleOnContentSizeChange,
handleSettingScrollable,
} = useScrollableInternal('ScrollView');
const {
Expand Down Expand Up @@ -72,6 +73,7 @@ const BottomSheetScrollViewComponent = forwardRef(
bounces={false}
decelerationRate={decelerationRate}
scrollEventThrottle={16}
onContentSizeChange={handleOnContentSizeChange}
onScrollBeginDrag={handleOnBeginDragEvent}
/>
</NativeViewGestureHandler>
Expand Down
2 changes: 2 additions & 0 deletions src/components/sectionList/SectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const BottomSheetSectionListComponent = forwardRef(
const {
scrollableRef,
handleOnBeginDragEvent,
handleOnContentSizeChange,
handleSettingScrollable,
} = useScrollableInternal('SectionList');
const {
Expand Down Expand Up @@ -73,6 +74,7 @@ const BottomSheetSectionListComponent = forwardRef(
bounces={false}
decelerationRate={decelerationRate}
scrollEventThrottle={16}
onContentSizeChange={handleOnContentSizeChange}
onScrollBeginDrag={handleOnBeginDragEvent}
/>
</NativeViewGestureHandler>
Expand Down
15 changes: 15 additions & 0 deletions src/hooks/useScrollableInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Scrollable, ScrollableType } from '../types';

export const useScrollableInternal = (type: ScrollableType) => {
// refs
const scrollableContentHeightRef = useRef<number>(0);
const scrollableContentOffsetYRef = useRef<number>(0);
const scrollableContentOffsetY = useValue<number>(0);
const scrollableRef = useRef<Scrollable>(null);
Expand All @@ -19,6 +20,19 @@ export const useScrollableInternal = (type: ScrollableType) => {
} = useBottomSheetInternal();

// callbacks
/**
* Reset the scrollable offset y when its size get smaller,
* this fixes #286.
*/
const handleOnContentSizeChange = useCallback(
(_, height: number) => {
if (scrollableContentHeightRef.current > height) {
scrollableContentOffsetY.setValue(0);
}
scrollableContentHeightRef.current = height;
},
[scrollableContentOffsetY]
);
const handleOnBeginDragEvent = useMemo(
() =>
event([
Expand Down Expand Up @@ -66,6 +80,7 @@ export const useScrollableInternal = (type: ScrollableType) => {
return {
scrollableRef,
handleOnBeginDragEvent,
handleOnContentSizeChange,
handleSettingScrollable,
};
};