Cull unused files (#11029)
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
import {useEffect, useState} from 'react'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
|
||||
import {getTabState, TabState} from '#/lib/routes/helpers'
|
||||
|
||||
export function useTabFocusEffect(
|
||||
tabName: string,
|
||||
cb: (isInside: boolean) => void,
|
||||
) {
|
||||
const [isInside, setIsInside] = useState(false)
|
||||
|
||||
// get root navigator state
|
||||
let nav = useNavigation()
|
||||
while (nav.getParent()) {
|
||||
nav = nav.getParent()
|
||||
}
|
||||
const state = nav.getState()
|
||||
|
||||
useEffect(() => {
|
||||
// check if inside
|
||||
let v = getTabState(state, tabName) !== TabState.Outside
|
||||
if (v !== isInside) {
|
||||
// fire
|
||||
setIsInside(v)
|
||||
cb(v)
|
||||
}
|
||||
}, [state, isInside, setIsInside, tabName, cb])
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
import {useCallback, useEffect, useRef} from 'react'
|
||||
|
||||
/**
|
||||
* Helper hook to run persistent timers on views
|
||||
*/
|
||||
export function useTimer(time: number, handler: () => void) {
|
||||
const timer = useRef<undefined | NodeJS.Timeout>(undefined)
|
||||
|
||||
// function to restart the timer
|
||||
const reset = useCallback(() => {
|
||||
if (timer.current) {
|
||||
clearTimeout(timer.current)
|
||||
}
|
||||
timer.current = setTimeout(handler, time)
|
||||
}, [time, timer, handler])
|
||||
|
||||
// function to cancel the timer
|
||||
const cancel = useCallback(() => {
|
||||
if (timer.current) {
|
||||
clearTimeout(timer.current)
|
||||
timer.current = undefined
|
||||
}
|
||||
}, [timer])
|
||||
|
||||
// start the timer immediately
|
||||
useEffect(() => {
|
||||
reset()
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
|
||||
return [reset, cancel]
|
||||
}
|
||||
Reference in New Issue
Block a user