Bluesky app fork with some witchin' additions 馃挮
witchsky.app
bluesky
fork
client
1import {useEffect, useState} from 'react'
2import {AppState, type AppStateStatus} from 'react-native'
3
4export const getCurrentState = () => AppState.currentState
5
6export function onAppStateChange(cb: (state: AppStateStatus) => void) {
7 let prev = AppState.currentState
8 return AppState.addEventListener('change', next => {
9 if (next === prev) return
10 prev = next
11 cb(next)
12 })
13}
14
15export function useOnAppStateChange(cb: (state: AppStateStatus) => void) {
16 useEffect(() => {
17 const sub = onAppStateChange(next => cb(next))
18 return () => sub.remove()
19 }, [cb])
20}
21
22export function useAppState() {
23 const [state, setState] = useState(AppState.currentState)
24 useOnAppStateChange(setState)
25 return state
26}