UNPKG

react-native-orientation-bits

Version:

A react-native module that can listen on orientation changing of device, get current orientation, lock to preferred orientation.

21 lines (17 loc) 493 B
import { useRef, useEffect } from 'react'; import Orientation from '../orientation' export function useLockListener(callback) { const savedCallback = useRef(); useEffect(() => { savedCallback.current = callback; }, [callback]); useEffect(() => { function listener(ori) { savedCallback.current(ori); } Orientation.addLockListener(listener); return () => { Orientation.removeLockListener(listener); }; }, []); }