mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix List onMomentumScrollEnd (#3759)

authored by danabra.mov and committed by

GitHub 42966fb4 28fc98d9

+43 -33
+39 -33
src/view/com/post-thread/PostThread.tsx
··· 1 1 import React, {useEffect, useRef} from 'react' 2 2 import {StyleSheet, useWindowDimensions, View} from 'react-native' 3 + import {runOnJS} from 'react-native-reanimated' 3 4 import {AppBskyFeedDefs} from '@atproto/api' 4 5 import {msg, Trans} from '@lingui/macro' 5 6 import {useLingui} from '@lingui/react' 6 7 7 8 import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped' 9 + import {ScrollProvider} from '#/lib/ScrollContext' 8 10 import {isAndroid, isNative, isWeb} from '#/platform/detection' 9 11 import { 10 12 sortThread, ··· 276 278 setMaxParents(n => n + PARENTS_CHUNK_SIZE) 277 279 } 278 280 }, []) 279 - const onMomentumScrollEnd = bumpMaxParentsIfNeeded 280 281 const onScrollToTop = bumpMaxParentsIfNeeded 282 + const onMomentumEnd = React.useCallback(() => { 283 + 'worklet' 284 + runOnJS(bumpMaxParentsIfNeeded)() 285 + }, [bumpMaxParentsIfNeeded]) 281 286 282 287 const onEndReached = React.useCallback(() => { 283 288 if (isFetching || posts.length < maxReplies) return ··· 382 387 } 383 388 384 389 return ( 385 - <List 386 - ref={ref} 387 - data={posts} 388 - renderItem={renderItem} 389 - keyExtractor={keyExtractor} 390 - onContentSizeChange={isNative ? undefined : onContentSizeChangeWeb} 391 - onStartReached={onStartReached} 392 - onEndReached={onEndReached} 393 - onEndReachedThreshold={2} 394 - onMomentumScrollEnd={onMomentumScrollEnd} 395 - onScrollToTop={onScrollToTop} 396 - maintainVisibleContentPosition={ 397 - isNative ? MAINTAIN_VISIBLE_CONTENT_POSITION : undefined 398 - } 399 - // @ts-ignore our .web version only -prf 400 - desktopFixedHeight 401 - removeClippedSubviews={isAndroid ? false : undefined} 402 - ListFooterComponent={ 403 - <ListFooter 404 - // Using `isFetching` over `isFetchingNextPage` is done on purpose here so we get the loader on 405 - // initial render 406 - isFetchingNextPage={isFetching} 407 - error={cleanError(threadError)} 408 - onRetry={refetch} 409 - // 300 is based on the minimum height of a post. This is enough extra height for the `maintainVisPos` to 410 - // work without causing weird jumps on web or glitches on native 411 - height={windowHeight - 200} 412 - /> 413 - } 414 - initialNumToRender={initialNumToRender} 415 - windowSize={11} 416 - /> 390 + <ScrollProvider onMomentumEnd={onMomentumEnd}> 391 + <List 392 + ref={ref} 393 + data={posts} 394 + renderItem={renderItem} 395 + keyExtractor={keyExtractor} 396 + onContentSizeChange={isNative ? undefined : onContentSizeChangeWeb} 397 + onStartReached={onStartReached} 398 + onEndReached={onEndReached} 399 + onEndReachedThreshold={2} 400 + onScrollToTop={onScrollToTop} 401 + maintainVisibleContentPosition={ 402 + isNative ? MAINTAIN_VISIBLE_CONTENT_POSITION : undefined 403 + } 404 + // @ts-ignore our .web version only -prf 405 + desktopFixedHeight 406 + removeClippedSubviews={isAndroid ? false : undefined} 407 + ListFooterComponent={ 408 + <ListFooter 409 + // Using `isFetching` over `isFetchingNextPage` is done on purpose here so we get the loader on 410 + // initial render 411 + isFetchingNextPage={isFetching} 412 + error={cleanError(threadError)} 413 + onRetry={refetch} 414 + // 300 is based on the minimum height of a post. This is enough extra height for the `maintainVisPos` to 415 + // work without causing weird jumps on web or glitches on native 416 + height={windowHeight - 200} 417 + /> 418 + } 419 + initialNumToRender={initialNumToRender} 420 + windowSize={11} 421 + /> 422 + </ScrollProvider> 417 423 ) 418 424 } 419 425
+4
src/view/com/util/List.tsx
··· 13 13 export type ListMethods = FlatList_INTERNAL 14 14 export type ListProps<ItemT> = Omit< 15 15 FlatListProps<ItemT>, 16 + | 'onMomentumScrollBegin' // Use ScrollContext instead. 17 + | 'onMomentumScrollEnd' // Use ScrollContext instead. 16 18 | 'onScroll' // Use ScrollContext instead. 19 + | 'onScrollBeginDrag' // Use ScrollContext instead. 20 + | 'onScrollEndDrag' // Use ScrollContext instead. 17 21 | 'refreshControl' // Pass refreshing and/or onRefresh instead. 18 22 | 'contentOffset' // Pass headerOffset instead. 19 23 > & {