简体   繁体   中英

How to lock Orientation for a particular screen in ios in react native?

I want to lock the orientation of my camera screen.

<Stack.Screen name="Camera" component={Camera} options={{ headerShown:false,orientation:'landscape'}}/>

This works fine in android but does not work on ios devices. Is there a way to solve this problem?

You can use below plugin for that https://www.npmjs.com/package/react-native-orientation-locker

Set up plugin and configure as mention in their doc and in react native side add below code which you want to Lock Screen portrait or landscape

import Orientation from 'react-native-orientation-locker';

useEffect(()=>{
   Orientation.lockToPortrait(); //this will lock the view to Portrait
   Orientation.lockToLandscape(); //this will lock the view to Landscape
})

EDIT

One more plugin is there you can set screen wise orientation https://www.npmjs.com/package/react-native-orientation In my one of the project this is also working. Hope your issue will be resolve on this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM