Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Fix #7

Merged
merged 1 commit into from
Jan 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public class OrientationListener : OrientationEventListener
{
private readonly Action<OrientationChangedEventArgs> _onOrientationChanged;

private DeviceOrientations _cachedOrientation;

public OrientationListener(Action<OrientationChangedEventArgs> onOrientationChanged)
: base(Application.Context, SensorDelay.Normal)
{
Expand All @@ -130,10 +132,17 @@ public OrientationListener(Context context, SensorDelay rate)

public override void OnOrientationChanged(int rotationDegrees)
{
_onOrientationChanged(new OrientationChangedEventArgs
var currentOrientation = CrossDeviceOrientation.Current.CurrentOrientation;

if (currentOrientation != _cachedOrientation)
{
Orientation = CrossDeviceOrientation.Current.CurrentOrientation
});
_cachedOrientation = currentOrientation;

_onOrientationChanged(new OrientationChangedEventArgs
{
Orientation = currentOrientation
});
}
}
}
}