wcoder / Xamarin.Plugin.DeviceOrientation

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

Add SetCurrentActivityResolver + Remove dependency to Plugin.CurrentActivity #27

Open thomasgalliker opened 3 years ago

thomasgalliker commented 3 years ago

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 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?