Improvements to notifications screen [APP-520] (#501)
* Refresh or sync notifications when the tab is navigated to * Fix to bad textnode render * Speed up initial session load * Fix lint * Restore updateSessionState() on session resumption
This commit is contained in:
parent
f2fe4abdce
commit
e02c926c8a
4 changed files with 57 additions and 10 deletions
27
src/lib/hooks/useTabFocusEffect.ts
Normal file
27
src/lib/hooks/useTabFocusEffect.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
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])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue