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