Fix List onMomentumScrollEnd (#3759)
parent
28fc98d942
commit
42966fb49e
|
@ -1,10 +1,12 @@
|
||||||
import React, {useEffect, useRef} from 'react'
|
import React, {useEffect, useRef} from 'react'
|
||||||
import {StyleSheet, useWindowDimensions, View} from 'react-native'
|
import {StyleSheet, useWindowDimensions, View} from 'react-native'
|
||||||
|
import {runOnJS} from 'react-native-reanimated'
|
||||||
import {AppBskyFeedDefs} from '@atproto/api'
|
import {AppBskyFeedDefs} from '@atproto/api'
|
||||||
import {msg, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped'
|
import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped'
|
||||||
|
import {ScrollProvider} from '#/lib/ScrollContext'
|
||||||
import {isAndroid, isNative, isWeb} from '#/platform/detection'
|
import {isAndroid, isNative, isWeb} from '#/platform/detection'
|
||||||
import {
|
import {
|
||||||
sortThread,
|
sortThread,
|
||||||
|
@ -276,8 +278,11 @@ export function PostThread({
|
||||||
setMaxParents(n => n + PARENTS_CHUNK_SIZE)
|
setMaxParents(n => n + PARENTS_CHUNK_SIZE)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
const onMomentumScrollEnd = bumpMaxParentsIfNeeded
|
|
||||||
const onScrollToTop = bumpMaxParentsIfNeeded
|
const onScrollToTop = bumpMaxParentsIfNeeded
|
||||||
|
const onMomentumEnd = React.useCallback(() => {
|
||||||
|
'worklet'
|
||||||
|
runOnJS(bumpMaxParentsIfNeeded)()
|
||||||
|
}, [bumpMaxParentsIfNeeded])
|
||||||
|
|
||||||
const onEndReached = React.useCallback(() => {
|
const onEndReached = React.useCallback(() => {
|
||||||
if (isFetching || posts.length < maxReplies) return
|
if (isFetching || posts.length < maxReplies) return
|
||||||
|
@ -382,6 +387,7 @@ export function PostThread({
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<ScrollProvider onMomentumEnd={onMomentumEnd}>
|
||||||
<List
|
<List
|
||||||
ref={ref}
|
ref={ref}
|
||||||
data={posts}
|
data={posts}
|
||||||
|
@ -391,7 +397,6 @@ export function PostThread({
|
||||||
onStartReached={onStartReached}
|
onStartReached={onStartReached}
|
||||||
onEndReached={onEndReached}
|
onEndReached={onEndReached}
|
||||||
onEndReachedThreshold={2}
|
onEndReachedThreshold={2}
|
||||||
onMomentumScrollEnd={onMomentumScrollEnd}
|
|
||||||
onScrollToTop={onScrollToTop}
|
onScrollToTop={onScrollToTop}
|
||||||
maintainVisibleContentPosition={
|
maintainVisibleContentPosition={
|
||||||
isNative ? MAINTAIN_VISIBLE_CONTENT_POSITION : undefined
|
isNative ? MAINTAIN_VISIBLE_CONTENT_POSITION : undefined
|
||||||
|
@ -414,6 +419,7 @@ export function PostThread({
|
||||||
initialNumToRender={initialNumToRender}
|
initialNumToRender={initialNumToRender}
|
||||||
windowSize={11}
|
windowSize={11}
|
||||||
/>
|
/>
|
||||||
|
</ScrollProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,11 @@ import {FlatList_INTERNAL} from './Views'
|
||||||
export type ListMethods = FlatList_INTERNAL
|
export type ListMethods = FlatList_INTERNAL
|
||||||
export type ListProps<ItemT> = Omit<
|
export type ListProps<ItemT> = Omit<
|
||||||
FlatListProps<ItemT>,
|
FlatListProps<ItemT>,
|
||||||
|
| 'onMomentumScrollBegin' // Use ScrollContext instead.
|
||||||
|
| 'onMomentumScrollEnd' // Use ScrollContext instead.
|
||||||
| 'onScroll' // Use ScrollContext instead.
|
| 'onScroll' // Use ScrollContext instead.
|
||||||
|
| 'onScrollBeginDrag' // Use ScrollContext instead.
|
||||||
|
| 'onScrollEndDrag' // Use ScrollContext instead.
|
||||||
| 'refreshControl' // Pass refreshing and/or onRefresh instead.
|
| 'refreshControl' // Pass refreshing and/or onRefresh instead.
|
||||||
| 'contentOffset' // Pass headerOffset instead.
|
| 'contentOffset' // Pass headerOffset instead.
|
||||||
> & {
|
> & {
|
||||||
|
|
Loading…
Reference in New Issue