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

Commit 01e31d5

Browse files
authored
Merge pull request #7 from wcoder/bugfixes/6-event-hell
Fix
2 parents a77c4c6 + 4bc8b44 commit 01e31d5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/DeviceOrientation/Plugin.DeviceOrientation.Android/DeviceOrientationImplementation.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public class OrientationListener : OrientationEventListener
107107
{
108108
private readonly Action<OrientationChangedEventArgs> _onOrientationChanged;
109109

110+
private DeviceOrientations _cachedOrientation;
111+
110112
public OrientationListener(Action<OrientationChangedEventArgs> onOrientationChanged)
111113
: base(Application.Context, SensorDelay.Normal)
112114
{
@@ -130,10 +132,17 @@ public OrientationListener(Context context, SensorDelay rate)
130132

131133
public override void OnOrientationChanged(int rotationDegrees)
132134
{
133-
_onOrientationChanged(new OrientationChangedEventArgs
135+
var currentOrientation = CrossDeviceOrientation.Current.CurrentOrientation;
136+
137+
if (currentOrientation != _cachedOrientation)
134138
{
135-
Orientation = CrossDeviceOrientation.Current.CurrentOrientation
136-
});
139+
_cachedOrientation = currentOrientation;
140+
141+
_onOrientationChanged(new OrientationChangedEventArgs
142+
{
143+
Orientation = currentOrientation
144+
});
145+
}
137146
}
138147
}
139148
}

0 commit comments

Comments
 (0)