This repository was archived by the owner on Mar 26, 2025. It is now read-only.
This repository was archived by the owner on Mar 26, 2025. It is now read-only.
Landscape and Portrait switched in Android #10
Open
Description
On iOS, everything is perfectly fine, but as soon as I use this on Android, everything is switched around? When I rotate the device and print out the orientation, it says it is Landscape, when it is actually Portrait?
Here is my custom Image class where the error exists:
using Plugin.DeviceOrientation;
using Plugin.DeviceOrientation.Abstractions;
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace Project.Custom
{
public class DSImage : Image
{
public DSImage(int phonePortrait, int phoneLandscape, int tabletPortrait, int tabletLandscape)
{
if (Device.Idiom == TargetIdiom.Phone)
{
if (CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.Portrait || CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.PortraitFlipped)
{
System.Diagnostics.Debug.WriteLine("Phone Portrait");
HeightRequest = phonePortrait;
}
else if (CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.Landscape || CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.LandscapeFlipped)
{
System.Diagnostics.Debug.WriteLine("Phone Landscape");
HeightRequest = phoneLandscape;
}
}
else if (Device.Idiom == TargetIdiom.Tablet)
{
if (CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.Portrait || CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.PortraitFlipped)
{
System.Diagnostics.Debug.WriteLine("Tablet Portrait");
HeightRequest = tabletPortrait;
}
else if (CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.Landscape || CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.LandscapeFlipped)
{
System.Diagnostics.Debug.WriteLine("Tablet Landscape");
HeightRequest = tabletLandscape;
}
}
CrossDeviceOrientation.Current.OrientationChanged += (sender, args) =>
{
if (Device.Idiom == TargetIdiom.Phone)
{
if (CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.Portrait || CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.PortraitFlipped)
{
System.Diagnostics.Debug.WriteLine("Phone Portrait");
HeightRequest = phonePortrait;
}
else if (CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.Landscape || CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.LandscapeFlipped)
{
System.Diagnostics.Debug.WriteLine("Phone Landscape");
HeightRequest = phoneLandscape;
}
}
else if (Device.Idiom == TargetIdiom.Tablet)
{
if (CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.Portrait || CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.PortraitFlipped)
{
System.Diagnostics.Debug.WriteLine("Tablet Portrait");
HeightRequest = tabletPortrait;
}
else if (CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.Landscape || CrossDeviceOrientation.Current.CurrentOrientation == DeviceOrientations.LandscapeFlipped)
{
System.Diagnostics.Debug.WriteLine("Tablet Landscape");
HeightRequest = tabletLandscape;
}
}
};
}
}
}