@@ -5,13 +5,23 @@ import * as NodeVM from "node:vm";
55
66import { describe , expect , it } from "vite-plus/test" ;
77
8+ import {
9+ THREAD_FEED_MAINTAIN_SCROLL_AT_END ,
10+ THREAD_FEED_MAINTAIN_SCROLL_AT_END_THRESHOLD ,
11+ } from "./threadFeedEndFollow" ;
12+
813const require = NodeModule . createRequire ( import . meta. url ) ;
914
10- // checkAtBottom is internal to the patched bundle; expose it from the native build as seen on iOS.
11- function loadPatchedCheckAtBottom ( ) {
15+ interface ListInternals {
16+ readonly checkAtBottom : ( ctx : unknown ) => void ;
17+ readonly settleUserScroll : ( ctx : unknown ) => void ;
18+ }
19+
20+ // The end checks are internal to the patched bundle; expose them from the native build as seen on iOS.
21+ function loadPatchedListInternals ( ) : ListInternals {
1222 const webBundlePath = require . resolve ( "@legendapp/list/react-native" ) ;
1323 const bundlePath = NodePath . join ( NodePath . dirname ( webBundlePath ) , "react-native.js" ) ;
14- const source = `${ NodeFS . readFileSync ( bundlePath , "utf8" ) } \nmodule.exports.checkAtBottom = checkAtBottom;` ;
24+ const source = `${ NodeFS . readFileSync ( bundlePath , "utf8" ) } \nmodule.exports.internals = { checkAtBottom, settleUserScroll } ;` ;
1525 const inert : object = new Proxy ( function ( ) { } , {
1626 get : ( _target , key ) => ( key === Symbol . toPrimitive ? ( ) => "" : inert ) ,
1727 apply : ( ) => inert ,
@@ -22,50 +32,59 @@ function loadPatchedCheckAtBottom() {
2232 get : ( object , key ) => ( key in object ? Reflect . get ( object , key ) : inert ) ,
2333 } ) ;
2434 const reactNative = withInertFallback ( { Platform : withInertFallback ( { OS : "ios" } ) } ) ;
25- const module = { exports : { } as { checkAtBottom ?: ( ctx : unknown ) => void } } ;
35+ const module = { exports : { } as { internals ?: ListInternals } } ;
2636 NodeVM . compileFunction ( source , [ "exports" , "require" , "module" ] , { filename : bundlePath } ) (
2737 module . exports ,
2838 ( id : string ) => ( id === "react-native" ? reactNative : inert ) ,
2939 module ,
3040 ) ;
31- const checkAtBottom = module . exports . checkAtBottom ;
32- if ( ! checkAtBottom ) throw new Error ( `checkAtBottom not found in ${ bundlePath } ` ) ;
33- return checkAtBottom ;
41+ const internals = module . exports . internals ;
42+ if ( ! internals ) throw new Error ( `list internals not found in ${ bundlePath } ` ) ;
43+ return internals ;
3444}
3545
36- const checkAtBottom = loadPatchedCheckAtBottom ( ) ;
46+ const { checkAtBottom, settleUserScroll } = loadPatchedListInternals ( ) ;
3747
3848// iPhone 17 Pro thread feed: header inset 116, composer inset 142.5, rows 693.29,
3949// so the end rests at -38.21 and the start at -116.
4050const scrollLength = 874 ;
4151const insetTop = 116 ;
4252const insetBottom = 142.5 ;
53+ const contentSize = 835.79 ;
4354
44- function isAtEnd ( scroll : number , rowsLength = 835.79 - insetBottom ) {
55+ function createFeedList ( scroll : number , rowsLength = contentSize - insetBottom ) {
4556 const values = new Map < string , unknown > ( [ [ "totalSize" , rowsLength ] ] ) ;
46- checkAtBottom ( {
57+ const ctx = {
4758 values,
4859 listeners : new Map ( ) ,
4960 scrollAxisGap : 0 ,
5061 state : {
5162 queuedInitialLayout : true ,
52- maintainingScrollAtEnd : true ,
63+ didFinishInitialScroll : true ,
5364 scroll,
5465 scrollLength,
66+ scheduledWork : { cancel : ( ) => { } , has : ( ) => false } ,
5567 props : {
5668 data : [ { } ] ,
5769 contentInset : { top : insetTop , bottom : insetBottom } ,
58- maintainScrollAtEndThreshold : 0 ,
59- onEndReachedThreshold : 0 ,
70+ maintainScrollAtEnd : THREAD_FEED_MAINTAIN_SCROLL_AT_END ,
71+ maintainScrollAtEndThreshold : THREAD_FEED_MAINTAIN_SCROLL_AT_END_THRESHOLD ,
72+ onEndReachedThreshold : 0.5 ,
6073 } ,
6174 } ,
62- } ) ;
75+ } ;
76+ return { ctx, values } ;
77+ }
78+
79+ function isAtEnd ( scroll : number , rowsLength ?: number ) {
80+ const { ctx, values } = createFeedList ( scroll , rowsLength ) ;
81+ checkAtBottom ( ctx ) ;
6382 return values . get ( "isAtEnd" ) ;
6483}
6584
66- describe ( "patched LegendList checkAtBottom " , ( ) => {
85+ describe ( "patched LegendList end detection in the thread feed " , ( ) => {
6786 it ( "does not report the start edge as the end when content overflows below the header inset" , ( ) => {
68- expect ( isAtEnd ( 835.79 - scrollLength ) ) . toBe ( true ) ;
87+ expect ( isAtEnd ( contentSize - scrollLength ) ) . toBe ( true ) ;
6988 expect ( isAtEnd ( - insetTop , 758 - insetBottom ) , "content that exactly fits" ) . toBe ( true ) ;
7089
7190 expect (
@@ -74,4 +93,15 @@ describe("patched LegendList checkAtBottom", () => {
7493 ) . toBe ( false ) ;
7594 expect ( isAtEnd ( - 114 ) , "a feed just below its start edge is 75.8pt from its end" ) . toBe ( false ) ;
7695 } ) ;
96+
97+ it ( "does not re-arm end following when a pull to the start edge is released" , ( ) => {
98+ const { ctx, values } = createFeedList ( - insetTop ) ;
99+ checkAtBottom ( ctx ) ;
100+ Object . assign ( ctx . state , { userScrollContentSize : contentSize } ) ;
101+ settleUserScroll ( ctx ) ;
102+ checkAtBottom ( ctx ) ;
103+
104+ expect ( values . get ( "isFollowingEnd" ) ) . toBe ( false ) ;
105+ expect ( values . get ( "isWithinMaintainScrollAtEndThreshold" ) ) . toBe ( false ) ;
106+ } ) ;
77107} ) ;
0 commit comments