jfversluis / Plugin.Maui.ScreenBrightness

Plugin.Maui.ScreenBrightness provides the ability to get or set the screen brightness inside a .NET MAUI application.
MIT License
44 stars 3 forks source link

Make it easier to use without knowing the platform details #8

Open berhir opened 9 months ago

berhir commented 9 months ago

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:

1) 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.Min and IScreenBrightness.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.

2) 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;
        });
    }
jfversluis commented 7 months ago

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?