import { useEffect , useState } from 'react' ; import * as ScreenOrientation from 'expo-screen-orientation' ; see https example export function useScreenOrientationPlatformLock ( platformInfo ? ) { const [ platformLock , setPlatformLock ] = useState < ScreenOrientation . PlatformOrientationInfo > ( ) ; const [ platformLockError , setPlatformLockError ] = useState < Error > ( ) ; useEffect ( ( ) => { ScreenOrientation . getPlatformOrientationLockAsync ( ) . then ( setPlatformLock ) ; if ( platformInfo ) { ScreenOrientation . lockPlatformAsync ( platformInfo ) . then ( ( ) => setPlatformLock ( platformInfo ) ) . catch ( setPlatformLockError ) ; return ( ) => { ScreenOrientation . unlockAsync ( ) ; } ; } } , [ platformInfo ] ) ; return [ platformLock , platformLockError ] ; }