简体   繁体   中英

How to change device orientation on androidmanifest.xml based on device using

How to change device orientation on androidmanifest.xml based on device I'm using. Sample if i use tablet.. it would be landscape, and when i use an android phone it would be portrait.

So here in your case you cant do via android manifest. you need to dynamically change orientation based on device.

So you have to build a native module. expose it to react native RN-native modules

and use it based on your type of device. Its a very easy native module like you have to setOrientation

@ReactMethod
public void setOrientation(String type) {
  if(type == 'landscape'){
 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
  if(type == 'portrait'){
 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

}

so basically this method will be exposed to your react native side. you need to detect the type of device.

Hope it helps. feel free for any doubts.

In React-Native you can use react-native-orientation to lock the orientation of the device. Then, you can use react-native-device-info to get informations on the device and lock the orientation accordingly.

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