d3105fa207
* chore: Upgrade a lot of dependencies for `./` * chore: Upgrade a lot of dependencies for `./example` * chore: Upgrade a lot of dependencies for `./docs` * Use new `EventEmitter` syntax (`.remove()`) * Update Podfile.lock * docs: Use watch mode * docs: Replace all relative links with absolute * Fix all links * Update docusaurus.config.js * Upgrade docusaurus-plugin-typedoc to fix docs build * Update yarn.lock * Upgrade typescript to 4.4.3 * Fix error unknown * Update package.json * Upgrade typedoc * Upgrade a few more deps * Fix deprecated sidebar syntax * Update Gemfile.lock
18 lines
516 B
TypeScript
18 lines
516 B
TypeScript
import { useState } from 'react';
|
|
import { useEffect } 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;
|
|
};
|