Plugin.Maui.ScreenBrightness
Plugin.Maui.ScreenBrightness copied to clipboard
Make it easier to use without knowing the platform details
This library is already very helpful, and I use it in one of our applications, so thank you for providing it. I have two suggestions to make it easier to use:
-
At first, I was not sure what value I should use to set the brightness to the maximum. It seems that most (or even all?) platforms are using a range from 0 to 1. But it's not obvious and to be sure that I don't make a mistake I must read the documentation of each platform. It would be helpful to add properties (e.g.
IScreenBrightness.MinandIScreenBrightness.Max) with the correct values for each platform. This way I could easily increase the brightness to max (or any percentage of it by multiplying with the Max value) or add a range slider without knowing the actual min/max values of the platform. -
A common use case is to temporarily increase the brightness while showing a QR-Code or similar. For this it would also be great to have a way to do this without knowing the platform specifics. I don't know if it's possible for all platforms, but currently I am using a disposable for this.
// Android
public static IDisposable SetTemporaryBrightness(this IScreenBrightness screenBrightness, float tmpValue)
{
screenBrightness.Brightness = tmpValue;
return Disposable.Create(() =>
{
screenBrightness.Brightness = -1;
});
}
// iOS
public static IDisposable SetTemporaryBrightness(this IScreenBrightness screenBrightness, float tmpValue)
{
var prevValue = screenBrightness.Brightness;
screenBrightness.Brightness = tmpValue;
return Disposable.Create(() =>
{
screenBrightness.Brightness = prevValue;
});
}
Great suggestions, thank you!
I really love the temporary methods and how you implemented them. That is cool! If you want you can contribute to this? Or you want me to have a look?