Skip to content
Open
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
12 changes: 10 additions & 2 deletions src/hooks/useAutoScroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ export function useAutoScroll() {
const {
autoscrollThreshold = DEFAULT_PROPS.autoscrollThreshold,
autoscrollSpeed = DEFAULT_PROPS.autoscrollSpeed,
minScrollOffset,
} = useProps();

// Real list top (0) unless the consumer supplied a floor — see
// DraggableFlatListProps.minScrollOffset.
const DEFAULT_MIN_SCROLL_OFFSET = useSharedValue(0);
const minScrollOffsetSV = minScrollOffset || DEFAULT_MIN_SCROLL_OFFSET;

const {
scrollOffset,
scrollViewSize,
Expand All @@ -31,7 +37,9 @@ export function useAutoScroll() {
}, []);

const isScrolledUp = useDerivedValue(() => {
return scrollOffset.value - SCROLL_POSITION_TOLERANCE <= 0;
return (
scrollOffset.value - SCROLL_POSITION_TOLERANCE <= minScrollOffsetSV.value
);
}, []);

const isScrolledDown = useDerivedValue(() => {
Expand Down Expand Up @@ -103,7 +111,7 @@ export function useAutoScroll() {
const speedPct = 1 - distFromEdge / autoscrollThreshold!;
const offset = speedPct * autoscrollSpeed;
const targetOffset = isAtTopEdge.value
? Math.max(0, scrollOffset.value - offset)
? Math.max(minScrollOffsetSV.value, scrollOffset.value - offset)
: Math.min(
scrollOffset.value + offset,
scrollViewSize.value - containerSize.value
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export type DraggableFlatListProps<T> = Modify<
renderPlaceholder?: RenderPlaceholder<T>;
simultaneousHandlers?: React.Ref<any> | React.Ref<any>[];
outerScrollOffset?: Animated.SharedValue<number>;
// Floor for the built-in top-edge autoscroll (see useAutoScroll's isScrolledUp/
// scroll-target clamp) — lets a consumer whose list has non-reorderable content
// above the reorderable region (e.g. a ListHeaderComponent) tell autoscroll not
// to scroll back up into it while dragging. Defaults to 0 (the real list top).
minScrollOffset?: Animated.SharedValue<number>;
onAnimValInit?: (animVals: ReturnType<typeof useAnimatedValues>) => void;
itemEnteringAnimation?: AnimateProps<Animated.View>["entering"];
itemExitingAnimation?: AnimateProps<Animated.View>["exiting"];
Expand Down