Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any way to prevent the orientation change? #13

Open
kxgonzalez opened this issue May 18, 2018 · 8 comments
Open

Is there any way to prevent the orientation change? #13

kxgonzalez opened this issue May 18, 2018 · 8 comments
Assignees

Comments

@kxgonzalez
Copy link

Hi,
I want to prevent the app to be rotated to portrait mode in certain scenarios, but I need it available so I can't disable it completely.
I know we have the OrientationChanged event but it fires after the orientation changes.

In other words; I want the app to be available in landscape and landscape flipped mode.
How can I achieve this?

I'm currently using Xamarin.Forms with PCL.

@rakeshostwal
Copy link

Hi @kxgonzalez , were you able to fix this?

@wcoder
Copy link
Owner

wcoder commented May 21, 2018

Hi @kxgonzalez

Try to use LockOrientation method, for example:

CrossDeviceOrientation.Current.LockOrientation(DeviceOrientations.Landscape);

@rakeshostwal
Copy link

rakeshostwal commented May 21, 2018

@wcoder - DeviceOrientations.Landscape keeps device window on horizontal left orientation only, but I want app to rotate horizontally to left as well as right. Is it possible with this plugin?

@wcoder
Copy link
Owner

wcoder commented May 21, 2018

Currently, there is no such functionality.

But you can setup platform manifests "supported device orientation" https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/device-orientation?tabs=vswin
for allow only landscape orientation

@rakeshostwal
Copy link

rakeshostwal commented May 21, 2018

Yes, but that would set it on a complete application, right? I want to set only horizontal orientation on a specific screen.

@kxgonzalez
Copy link
Author

I'm in the same situation.
I have a multipurpose app; one mode has views designed to be vertical. I have no problem with this.
The other mode is designed to be horizontal, so I want to be able to rotate it landscape and landscape inverted.
I tried with some logic but it fires after the rotation and animation happens.

@wcoder
Copy link
Owner

wcoder commented May 22, 2018

Currently, this plugin supported lock of device orientation only for one direction.

This situation (more than one direction) will good enhancement for next version of the plugin.

I can propose the workaround for yours:

Manual override these methods on each platform:

Android

MainActivity.cs

public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig) {}

iOS

AppDelegate.cs

public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, UIWindow forWindow){}

In these methods, you can lock the device orientation for the required page.

@wcoder wcoder self-assigned this May 22, 2018
@kxgonzalez
Copy link
Author

Nice, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants