Xamarin.Plugin.DeviceOrientation icon indicating copy to clipboard operation
Xamarin.Plugin.DeviceOrientation copied to clipboard

Add SetCurrentActivityResolver + Remove dependency to Plugin.CurrentActivity

Open thomasgalliker opened this issue 3 years ago • 0 comments

Currently, Xamarin.Plugin.DeviceOrientation uses the Plugin.CurrentActivity nuget package in the Android implementation to access the current activity. This is the same behavior as many plugins use. However, since the rise of Xamarin.Essentials (which also offers access to Android's current activity), I would propose to eliminate the direct dependency to Plugin.CurrentActivity. Instead, I'd add a new static method to CrossDeviceOrientation: SetCurrentActivityResolver(Func<Activity> activityResolver) which dynamically resolves the current activity from either Plugin.CurrentActivity or Xamarin.Essentials (or another plugin).

A similar solution is successfully used in the Fingerprint plugin (https://github.com/smstuebe/xamarin-fingerprint). Check the following CrossFingerprint.Android.cs file: https://github.com/smstuebe/xamarin-fingerprint/blob/9fb42c4a8b620260c0c03eb2714e2e03a92d472b/src/Plugin.Fingerprint/Platforms/Android/CrossFingerprint.Android.cs

What do you think of this proposal for extension?

thomasgalliker avatar Nov 22 '20 20:11 thomasgalliker