From b0742d5ef0a6e0b0d6f95774c21e251118a883d8 Mon Sep 17 00:00:00 2001 From: Hailey Date: Wed, 24 Jul 2024 18:30:49 -0700 Subject: [PATCH] patch react-native to support outside header offset in virtualized list --- ...act-native+virtualized-lists+0.74.83.patch | 48 +++++++++++++++++++ src/screens/Profile/Sections/Feed.tsx | 1 + src/view/com/posts/Feed.tsx | 3 ++ src/view/com/util/List.tsx | 3 +- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 patches/@react-native+virtualized-lists+0.74.83.patch diff --git a/patches/@react-native+virtualized-lists+0.74.83.patch b/patches/@react-native+virtualized-lists+0.74.83.patch new file mode 100644 index 0000000000..15b51317c5 --- /dev/null +++ b/patches/@react-native+virtualized-lists+0.74.83.patch @@ -0,0 +1,48 @@ +diff --git a/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.d.ts b/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.d.ts +index a4c93f5..7157d5b 100644 +--- a/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.d.ts ++++ b/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.d.ts +@@ -390,4 +390,6 @@ export interface VirtualizedListWithoutRenderItemProps + | React.ComponentType> + | null + | undefined; ++ ++ outsideHeaderOffset?: number | undefined; + } +diff --git a/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.js b/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.js +index 9f95091..db57032 100644 +--- a/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.js ++++ b/node_modules/@react-native/virtualized-lists/Lists/VirtualizedList.js +@@ -1948,9 +1948,18 @@ class VirtualizedList extends StateSafePureComponent { + return; + } + this._viewabilityTuples.forEach(tuple => { ++ // HACK ++ // Becuase our pager with header adds a header _outside_ of the VirtualizedList, the scroll metric offset dosn't ++ // know about it, and the offset provided here is inaccurate. We are able to pass in this value to the VL, and can ++ // adjust hte offset here to account for that header. ++ let adjustedOffset = this._scrollMetrics.offset; ++ if (this.props.outsideHeaderOffset) { ++ adjustedOffset -= this.props.outsideHeaderOffset; ++ } ++ + tuple.viewabilityHelper.onUpdate( + props, +- this._scrollMetrics.offset, ++ adjustedOffset, + this._scrollMetrics.visibleLength, + this._listMetrics, + this._createViewToken, +diff --git a/node_modules/@react-native/virtualized-lists/Lists/VirtualizedListProps.js b/node_modules/@react-native/virtualized-lists/Lists/VirtualizedListProps.js +index 1a956ea..2190e4f 100644 +--- a/node_modules/@react-native/virtualized-lists/Lists/VirtualizedListProps.js ++++ b/node_modules/@react-native/virtualized-lists/Lists/VirtualizedListProps.js +@@ -285,6 +285,8 @@ type OptionalProps = {| + * The legacy implementation is no longer supported. + */ + legacyImplementation?: empty, ++ ++ outsideHeaderOffset?: ?number, + |}; + + export type Props = {| diff --git a/src/screens/Profile/Sections/Feed.tsx b/src/screens/Profile/Sections/Feed.tsx index 201c8f7e07..e7ceaab0ca 100644 --- a/src/screens/Profile/Sections/Feed.tsx +++ b/src/screens/Profile/Sections/Feed.tsx @@ -79,6 +79,7 @@ export const ProfileFeedSection = React.forwardRef< headerOffset={headerHeight} renderEndOfFeed={ProfileEndOfFeed} ignoreFilterFor={ignoreFilterFor} + outsideHeaderOffset={headerHeight} /> {(isScrolledDown || hasNew) && ( JSX.Element extraData?: any savedFeedConfig?: AppBskyActorDefs.SavedFeed + outsideHeaderOffset?: number }): React.ReactNode => { const theme = useTheme() const {track} = useAnalytics() @@ -549,6 +551,7 @@ let Feed = ({ initialNumToRender={initialNumToRender} windowSize={11} onItemSeen={feedFeedback.onItemSeen} + outsideHeaderOffset={outsideHeaderOffset} /> ) diff --git a/src/view/com/util/List.tsx b/src/view/com/util/List.tsx index e1a10e4741..1b65504ba0 100644 --- a/src/view/com/util/List.tsx +++ b/src/view/com/util/List.tsx @@ -93,6 +93,7 @@ function ListImpl( } return [ (info: {viewableItems: Array; changed: Array}) => { + console.log(info.viewableItems[0]) for (const item of info.changed) { if (item.isViewable) { onItemSeen(item.item) @@ -101,7 +102,7 @@ function ListImpl( }, { itemVisiblePercentThreshold: 40, - minimumViewTime: 1.5e3, + minimumViewTime: 0, }, ] }, [onItemSeen])