tweaks
This commit is contained in:
+15
-12
@@ -1,17 +1,20 @@
|
||||
import React from 'react'
|
||||
|
||||
export const useDedupe = () => {
|
||||
export const useDedupe = (timeout: number) => {
|
||||
const canDo = React.useRef(true)
|
||||
|
||||
return React.useCallback((cb: () => unknown) => {
|
||||
if (canDo.current) {
|
||||
canDo.current = false
|
||||
setTimeout(() => {
|
||||
canDo.current = true
|
||||
}, 250)
|
||||
cb()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}, [])
|
||||
return React.useCallback(
|
||||
(cb: () => unknown) => {
|
||||
if (canDo.current) {
|
||||
canDo.current = false
|
||||
setTimeout(() => {
|
||||
canDo.current = true
|
||||
}, timeout)
|
||||
cb()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
[timeout],
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {usePalette} from '#/lib/hooks/usePalette'
|
||||
import {useScrollHandlers} from '#/lib/ScrollContext'
|
||||
import {useDedupe} from 'lib/hooks/useDedupe'
|
||||
import {addStyle} from 'lib/styles'
|
||||
import {isIOS} from 'platform/detection'
|
||||
import {updateActiveViewAsync} from '../../../../modules/expo-bluesky-swiss-army/src/VisibilityView'
|
||||
import {FlatList_INTERNAL} from './Views'
|
||||
|
||||
@@ -49,7 +50,7 @@ function ListImpl<ItemT>(
|
||||
) {
|
||||
const isScrolledDown = useSharedValue(false)
|
||||
const pal = usePalette('default')
|
||||
const dedupe = useDedupe()
|
||||
const dedupe = useDedupe(400)
|
||||
|
||||
function handleScrolledDownChange(didScrollDown: boolean) {
|
||||
onScrolledDownChange?.(didScrollDown)
|
||||
@@ -68,6 +69,7 @@ function ListImpl<ItemT>(
|
||||
onBeginDragFromContext?.(e, ctx)
|
||||
},
|
||||
onEndDrag(e, ctx) {
|
||||
runOnJS(updateActiveViewAsync)()
|
||||
onEndDragFromContext?.(e, ctx)
|
||||
},
|
||||
onScroll(e, ctx) {
|
||||
@@ -81,11 +83,14 @@ function ListImpl<ItemT>(
|
||||
}
|
||||
}
|
||||
|
||||
runOnJS(dedupe)(updateActiveViewAsync)
|
||||
if (isIOS) {
|
||||
runOnJS(dedupe)(updateActiveViewAsync)
|
||||
}
|
||||
},
|
||||
// Note: adding onMomentumBegin here makes simulator scroll
|
||||
// lag on Android. So either don't add it, or figure out why.
|
||||
onMomentumEnd(e, ctx) {
|
||||
runOnJS(updateActiveViewAsync)()
|
||||
onMomentumEndFromContext?.(e, ctx)
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user