[BEEEP] [PS-940] Support for dark theme selection while using Default (System) theme#1959
[BEEEP] [PS-940] Support for dark theme selection while using Default (System) theme#1959
Conversation
| _vm = BindingContext as OptionsPageViewModel; | ||
| _vm.Page = this; | ||
| _themePicker.ItemDisplayBinding = new Binding("Value"); | ||
| _autoDarkThemePicker.ItemDisplayBinding = new Binding("Value"); |
There was a problem hiding this comment.
Maybe I'm unaware of some issue but wouldn't it be possible to put the binding on the xaml page? (as well as the others)
There was a problem hiding this comment.
Tbh I'm not sure - I'm following the established pattern since we're going to rebuild Settings at some point anyway and I didn't want to create new issues before then.
| else | ||
| { | ||
| _themePicker.On<iOS>().SetUpdateMode(UpdateMode.WhenFinished); | ||
| _autoDarkThemePicker.On<iOS>().SetUpdateMode(UpdateMode.WhenFinished); |
There was a problem hiding this comment.
The On<iOS> here is redundant to put it on the else (given that we only have Android and iOS as platforms).
We could just remove the else and let the code be there as is, or remove the On<iOS>. (I'd just remove the else). BTW, this can also be done on xaml if we'd want to here the how to.
Maybe we should look into all the places where it's used; but we could just add a custom control CustomPicker or something like that, that we can use to set this update mode by default and just use it like that. I see that there are a lot of places where this is being set up. Also, we could you the CustomPickerRenderer of iOS to set this up as well globally. But we need to be careful maybe there are some specific places where we don't want update mode when finished.
There was a problem hiding this comment.
Same comment here (following existing pattern for safety/sanity until we rebuild Settings)
| AutoDarkThemeOptions = new List<KeyValuePair<string, string>> | ||
| { | ||
| new KeyValuePair<string, string>("dark", AppResources.Dark), | ||
| new KeyValuePair<string, string>("black", AppResources.Black), | ||
| new KeyValuePair<string, string>("nord", "Nord"), | ||
| }; |
There was a problem hiding this comment.
I think we should use Tuple instead of KeyValuePair here you have a gist with performance comparison. There are some caveats regarding allocation where KeyValuePair is better but in this case we don't care much given that there are just a few items.
It doesn't matter much with these few items but I also think it's more readable with Tuples.
What do you think?
There was a problem hiding this comment.
KeyValuePair seems more appropriate to me here since that's what the values are, vs Tuple which doesn't suggest a relation among the values. If the data set was larger maybe it would be worth the change, but as is I don't see the benefit.
| additionalPropertyNames: new[] { nameof(ShowAutoDarkThemeOptions) }) | ||
| ) | ||
| { | ||
| var task = SaveThemeAsync(); |
There was a problem hiding this comment.
here there's no need to assign the returned Task to a variable. And I've checked there's no try catch on SaveThemeAsync so if any exceptions are raised are going to be swollen by the Task. So either we add the try catch or just call fire and forget here: SaveThemeAsync().FireAndForget() (just be careful if it switches to a background thread and maybe when calling it and there are things on SaveThemeAsync that may need to be marshalled to the Main thread, so test it a few times just in case)
| DisableFavicon = (await _stateService.GetDisableFaviconAsync()).GetValueOrDefault(); | ||
| var theme = await _stateService.GetThemeAsync(); | ||
| ThemeSelectedIndex = ThemeOptions.FindIndex(k => k.Key == theme); | ||
| var autoDarkTheme = await _stateService.GetAutoDarkThemeAsync() ?? "dark"; |
There was a problem hiding this comment.
I'd really like if theme strings (like "dark", "nord", and so on) would be consts (or an Enum even better) in ThemeManager that can be referenced. So that there is less chance of misspelling and if for some reason we change any of them it's easier to replace.
Maybe not for this PR, but we should keep this in mind.
What do you think?
| var autoDarkTheme = AutoDarkThemeOptions[AutoDarkThemeSelectedIndex].Key; | ||
| await _stateService.SetAutoDarkThemeAsync(autoDarkTheme); |
There was a problem hiding this comment.
Could we inline these?
await _stateService.SetAutoDarkThemeAsync(AutoDarkThemeOptions[AutoDarkThemeSelectedIndex].Key);Or is it too long?
src/App/Resources/AppResources.resx
Outdated
| <data name="AutoDarkTheme" xml:space="preserve"> | ||
| <value>Default Dark Theme</value> | ||
| </data> |
There was a problem hiding this comment.
IMO, resource strings keys should be the same (when not too long) as the value to be easier to read in the code without the need to go to the resx file to check what is the value. So here I'd use DefaultDarkTheme as the key.
Furthermore if for some reason in the future we have a value "Auto Dark Theme" we couldn't use the key as it'd be used here.
src/App/Resources/AppResources.resx
Outdated
| <data name="AutoDarkThemeDescription" xml:space="preserve"> | ||
| <value>Choose the dark theme to use when using Default (System) theme while your device's dark mode is enabled</value> | ||
| </data> |
There was a problem hiding this comment.
Even though, here I think it's ok to have a key like this, if we change the above this should change to DefaultDarkThemeDescription
Type of change
Objective
Now you can select which dark theme to use when using the
Default (System)(automatic light/dark) theme. (Previously only the "Dark" theme was used).When
Default (System)is the selected theme, a newDefault Dark Themeoption appears immediately below theThemeoption. It defaults to "Dark" but allows "Black" and "Nord" to be selected as well. When the device/OS is in dark mode, the selected dark theme becomes active. This section is only visible while theDefault (System)theme is selected.Code changes
Optionsscreen withinSettingsautoDarkThemearg & logicAutoDarkThemeAutoDarkThemeKeyfor storageScreenshots
System/OS in light mode with
Default (System)theme & custom default dark themes selected:System/OS in dark mode with
Default (System)theme & custom default dark themes selected:Light & dark themes selected,
Default Dark Themesection not visibleBefore you submit
dotnet tool run dotnet-format --check) (required)