-
Notifications
You must be signed in to change notification settings - Fork 3.9k
ios react-native-draggable-flatlist patch #61380
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
patches/react-native-draggable-flatlist+4.0.1+001+listfooter-constraint.patch
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| diff --git a/node_modules/react-native-draggable-flatlist/src/components/DraggableFlatList.tsx b/node_modules/react-native-draggable-flatlist/src/components/DraggableFlatList.tsx | ||
| index 2f59c7a..a324da2 100644 | ||
| --- a/node_modules/react-native-draggable-flatlist/src/components/DraggableFlatList.tsx | ||
| +++ b/node_modules/react-native-draggable-flatlist/src/components/DraggableFlatList.tsx | ||
| @@ -51,7 +51,7 @@ const AnimatedFlatList = (Animated.createAnimatedComponent( | ||
| FlatList | ||
| ) as unknown) as <T>(props: RNGHFlatListProps<T>) => React.ReactElement; | ||
|
|
||
| -function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) { | ||
| +function DraggableFlatListInner<T>({ListFooterComponent, ...props}: DraggableFlatListProps<T>) { | ||
| const { | ||
| cellDataRef, | ||
| containerRef, | ||
| @@ -65,6 +65,7 @@ function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) { | ||
| activeCellSize, | ||
| activeIndexAnim, | ||
| containerSize, | ||
| + footerSize, | ||
| scrollOffset, | ||
| scrollViewSize, | ||
| spacerIndexAnim, | ||
| @@ -162,6 +163,14 @@ function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) { | ||
| props.onContainerLayout?.({ layout, containerRef }); | ||
| }; | ||
|
|
||
| + // make size of footer available for use in drag contraints | ||
| + const onFooterLayout = ({ | ||
| + nativeEvent: { layout }, | ||
| + }: LayoutChangeEvent) => { | ||
| + footerSize.value = props.horizontal ? layout.width : layout.height | ||
| + }; | ||
| + | ||
| + | ||
| const onListContentSizeChange = (w: number, h: number) => { | ||
| scrollViewSize.value = props.horizontal ? w : h; | ||
| props.onContentSizeChange?.(w, h); | ||
| @@ -357,6 +366,16 @@ function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) { | ||
| props.onViewableItemsChanged?.(info); | ||
| }); | ||
|
|
||
| + // Wrap the provided ListFooterComponent to add an onLayout | ||
| + const wrappedListFooterComponent = ListFooterComponent ? | ||
| + <Animated.View | ||
| + style={props.ListFooterComponentStyle} | ||
| + onLayout={onFooterLayout} | ||
| + > | ||
| + {ListFooterComponent} | ||
| + </Animated.View> | ||
| + : undefined | ||
| + | ||
| return ( | ||
| <DraggableFlatListProvider | ||
| activeKey={activeKey} | ||
| @@ -388,6 +407,7 @@ function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) { | ||
| scrollEventThrottle={16} | ||
| simultaneousHandlers={props.simultaneousHandlers} | ||
| removeClippedSubviews={false} | ||
| + ListFooterComponent={wrappedListFooterComponent} | ||
| /> | ||
| {!!props.onScrollOffsetChange && ( | ||
| <ScrollOffsetListener | ||
| diff --git a/node_modules/react-native-draggable-flatlist/src/context/animatedValueContext.tsx b/node_modules/react-native-draggable-flatlist/src/context/animatedValueContext.tsx | ||
| index 6ff1ed5..611adda 100644 | ||
| --- a/node_modules/react-native-draggable-flatlist/src/context/animatedValueContext.tsx | ||
| +++ b/node_modules/react-native-draggable-flatlist/src/context/animatedValueContext.tsx | ||
| @@ -60,6 +60,7 @@ function useSetupAnimatedValues<T>() { | ||
| const activeCellSize = useSharedValue(0); // Height or width of acctive cell | ||
| const activeCellOffset = useSharedValue(0); // Distance between active cell and edge of container | ||
|
|
||
| + const footerSize = useSharedValue(0); | ||
| const scrollOffset = useSharedValue(0); | ||
| const scrollInit = useSharedValue(0); | ||
|
|
||
| @@ -118,7 +119,7 @@ function useSetupAnimatedValues<T>() { | ||
|
|
||
| const maxTranslateNegative = -activeCellOffset.value; | ||
| const maxTranslatePositive = | ||
| - scrollViewSize.value - (activeCellOffset.value + activeCellSize.value); | ||
| + scrollViewSize.value - (activeCellOffset.value + activeCellSize.value + footerSize.value); | ||
|
|
||
| // Only constrain the touch position while the finger is on the screen. This allows the active cell | ||
| // to snap above/below the fold once let go, if the drag ends at the top/bottom of the screen. | ||
| @@ -174,6 +175,7 @@ function useSetupAnimatedValues<T>() { | ||
| placeholderOffset, | ||
| resetTouchedCell, | ||
| scrollOffset, | ||
| + footerSize, | ||
| scrollViewSize, | ||
| spacerIndexAnim, | ||
| touchPositionDiff, | ||
| @@ -197,6 +199,7 @@ function useSetupAnimatedValues<T>() { | ||
| placeholderOffset, | ||
| resetTouchedCell, | ||
| scrollOffset, | ||
| + footerSize, | ||
| scrollViewSize, | ||
| spacerIndexAnim, | ||
| touchPositionDiff, | ||
| diff --git a/node_modules/react-native-draggable-flatlist/src/types.ts b/node_modules/react-native-draggable-flatlist/src/types.ts | ||
| index d6755c8..564e3ff 100644 | ||
| --- a/node_modules/react-native-draggable-flatlist/src/types.ts | ||
| +++ b/node_modules/react-native-draggable-flatlist/src/types.ts | ||
| @@ -52,6 +52,7 @@ export type DraggableFlatListProps<T> = Modify< | ||
| layout: LayoutChangeEvent["nativeEvent"]["layout"]; | ||
| containerRef: React.RefObject<Animated.View>; | ||
| }) => void; | ||
| + ListFooterComponent?: React.ReactElement; | ||
| } & Partial<DefaultProps> | ||
| >; | ||
|
|
||
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.