wcoder / Xamarin.Plugin.DeviceOrientation

Cross-platform plugin to work with screen orientation of mobile device.
MIT License
61 stars 19 forks source link

Comparing orientations? #17

Open memmons-ntst opened 5 years ago

memmons-ntst commented 5 years ago

What is the correct way to do orientation comparisons? I've tried the following, none of which work:

bool fail1 = CrossDeviceOrientation.Current == 2;
bool fail2 = CrossDeviceOrientation.Current == DeviceOrientations.Portrait;
bool fail3 = CrossDeviceOrientation.Current.Equals(DeviceOrientations.Portrait);

Coming from Swift/Obj-C, I'm sure there is some dumb thing I am doing here. Also, would be great if you included an example like this in the docs.

wcoder commented 5 years ago

Hi @memmons-ntst

Current property has platform implementation of the plugin with interface IDeviceOrientation as a singleton, next step you will need to get CurrentOrientation value and compare with DeviceOrientations enum value:

CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.Portrait
MagicAndre1981 commented 5 years ago

@wcoder can I also do this check in pure XAML? I want to set Margin/Padding based on Idiom and Orientation status. Currently I do this in code at OnSizeAllocated but here I can't use XAML Reloader tools to see the output if I change values, here I have to compile the app again and run it again.

wcoder commented 5 years ago

@MagicAndre1981 plugin doesn't provide any solutions out of the box for support from XAML.

I think you can implement your case via Xamarin.Forms Triggers.

MagicAndre1981 commented 5 years ago

any hint how to do this via Triggers?