railbird-gql/component/video/is-foreground.tsx

17 lines
477 B
TypeScript
Raw Normal View History

2024-02-03 20:30:00 -07:00
import { useEffect, useState } from "react";
import { AppState, AppStateStatus } from "react-native";
export const useIsForeground = (): boolean => {
const [isForeground, setIsForeground] = useState(true);
useEffect(() => {
const onChange = (state: AppStateStatus): void => {
setIsForeground(state === "active");
};
const listener = AppState.addEventListener("change", onChange);
return () => listener.remove();
}, [setIsForeground]);
return isForeground;
};