Home > Mobile >  How to change device orientation on androidmanifest.xml based on device using
How to change device orientation on androidmanifest.xml based on device using

Time:05-31

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.

CodePudding user response:

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.

CodePudding user response:

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 nativeRN-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.

  • Related