feat: add minScrollOffset so autoscroll respects non-reorderable header content - #625
Open
alhansrisuk wants to merge 1 commit into
Open
feat: add minScrollOffset so autoscroll respects non-reorderable header content#625alhansrisuk wants to merge 1 commit into
alhansrisuk wants to merge 1 commit into
Conversation
…eader content The built-in top-edge autoscroll only disables itself once the list's scroll offset reaches absolute 0 (see isScrolledUp/isAtTopEdge). That's correct for a list that's entirely reorderable, but not for one that mixes non-reorderable content (e.g. a ListHeaderComponent) with a reorderable section below it: as soon as the dragged cell's on-screen position sits near the container's top edge — which happens immediately when dragging the reorderable section's own first item, since it can sit right at the top of the viewport — the library scrolls back up into that header content, which was never part of the reorder. `minScrollOffset` (an optional SharedValue<number>, defaulting to 0 — existing behavior for anyone not passing it) lets a consumer tell autoscroll where the real top of the reorderable region is, so it stops there instead of continuing toward absolute 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
useAutoScroll'sisScrolledUp/isAtTopEdge) only disables itself once the list's scroll offset reaches absolute0. That's correct for a list that's entirely reorderable, but not for one that mixes non-reorderable content (e.g. aListHeaderComponent) with a reorderable section below it: dragging that section's own first item can put the dragged cell's on-screen position right at the container's top edge immediately, and the library scrolls back up into the header content — which was never part of the reorder.minScrollOffset, an optionalAnimated.SharedValue<number>(default0, so existing behavior is unchanged for anyone not passing it — this is purely additive/non-breaking) that lets a consumer tell autoscroll where the real top of the reorderable region is, so it stops there instead of continuing toward absolute0.outerScrollOffsetprop (an externally-suppliedSharedValuethe consumer keeps updated), so it should feel consistent with the library's existing API for this kind of thing.This came out of building a queue-reorder feature: a single
FlatListwith Recently Played/Now Playing rendered viaListHeaderComponent(not reorderable) above an "Up Next" section (reorderable). Grabbing the first Up Next item would immediately trigger the built-in autoscroll and yank the list back up into that header content mid-drag.Test plan
yarn typecheckpassesyarn test— same 3 pre-existing failures asmain(aReanimated.useEventincompatibility unrelated to this change, confirmed by running the suite on unmodifiedmain), no new failuresminScrollOffsetto the reorderable region's start stops the unwanted autoscroll/jump on grabbing the first item; omitting the prop leaves behavior unchanged from currentmain.