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.

23 lines (19 loc) 596 B
import { useRef, useEffect } from 'react'; import Orientation from '../orientation' export function useOrientationChange(callback) { const savedCallback = useRef(); useEffect(() => { savedCallback.current = callback; }, [callback]); useEffect(() => { function listener(ori) { savedCallback.current(ori); } const initial = Orientation.getInitialOrientation(); listener(initial); Orientation.addOrientationListener(listener); return () => { Orientation.removeOrientationListener(listener); }; }, []); }