import { useEffect , useState } from 'react' ; import * as ScreenOrientation from 'expo-screen-orientation' ; see https example export function useScreenOrientationLock ( lock ? ) { const [ lockInfo , setLockInfo ] = useState < ScreenOrientation . OrientationLock > ( ) ; const [ lockError , setLockError ] = useState < Error > ( ) ; useEffect ( ( ) => { ScreenOrientation . getOrientationLockAsync ( ) . then ( setLockInfo ) ; if ( lock ) { ScreenOrientation . lockAsync ( lock ) . then ( ( ) => setLockInfo ( lock ) ) . catch ( setLockError ) ; return ( ) => { ScreenOrientation . unlockAsync ( ) ; } ; } } , [ lock ] ) ; return [ lockInfo , lockError ] ; }