Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Enable Xamarin.Forms AppTheme on legacy devices #1

Open
LuckyDucko opened this issue Aug 26, 2020 · 0 comments
Open

Enable Xamarin.Forms AppTheme on legacy devices #1

LuckyDucko opened this issue Aug 26, 2020 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@LuckyDucko
Copy link
Owner

Xamarin.Forms has a very useful markup extension for AppThemes which can be used to change the UI of your app depending on if the theme on the device is light or dark.

However, there is one small issue

The following requirements must be met for Xamarin.Forms to respond to a system theme change:
Xamarin.Forms 4.6.0.967 or greater.
iOS 13 or greater.
Android 10 (API 29) or greater.
UWP build 14393 or greater.

and considering that Android 10 only has around 25% of the android market (July 2020), that leaves a large amount of users without access to AppTheme.

I have devised a simple way to add in 'support' for these devices with the following snippet

 CrossBrightnessService.Current.Attach(() =>
            {
                if (CrossBrightnessService.Current.CheckBrightness() > 0.500)
                {
                    Application.Current.UserAppTheme = OSAppTheme.Light;
                }
                else
                {
                    Application.Current.UserAppTheme = OSAppTheme.Dark;
                }
            });

However this overrides the normal AppTheme functionality for devices that do support it.
It also cannot be built in directly into BrightnessService as it needs the Application from Xamarin forms.
It also needs the ability to allow for user manual overrides.

these are some preprocessor codes I initially thought of that outline the API's required for the normal operation of AppTheme

#if __ANDROID__
             if (Build.VERSION.SdkInt > BuildVersionCodes.P)
            {
                return;
            }
#endif
#if __IOS__
             if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
             {
                return;
             }
#endif

This issue is to track

  1. Is it possible to add this functionality into CrossBrightness in some fashion
  2. if so, is it possible to create it without the use of Xamarin.Forms
@LuckyDucko LuckyDucko added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Aug 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant