[TIMOB-28369] Android: Add Ti.UI.overrideUserInterfaceStyle property
| GitHub Issue | n/a |
|---|---|
| Type | New Feature |
| Priority | Medium |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2021-06-10T17:17:43.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 10.0.1 |
| Components | Android, iOS, Mac |
| Labels | android, iOS, theme |
| Reporter | Joshua Quick |
| Assignee | Joshua Quick |
| Created | 2021-02-25T03:57:15.000+0000 |
| Updated | 2021-06-10T17:17:43.000+0000 |
Description
*Summary:*
We should add a new writable
Ti.UI.overrideUserInterfaceStyle property that allows you to force the app to use a dark or light theme instead of using the system assigned theme. If this property is assigned the [Ti.UI.USER_INTERFACE_STYLE_UNSPECIFIED](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI-property-USER_INTERFACE_STYLE_UNSPECIFIED) constant (the default), then the app will use the system theme instead.
The existing read-only [Ti.UI.userInterfaceStyle](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI-property-userInterfaceStyle) property needs to be its own property. If the overrideUserInterfaceStyle is set to unspecified, then the userInterfaceStyle property will reveal if the system is using the dark or light theme.
*Native Implementation:*
On iOS, this can be implemented via the native [UIView.overrideUserInterfaceStyle](https://developer.apple.com/documentation/uikit/uiview/3238086-overrideuserinterfacestyle?language=objc) property.
On Android, this can be implemented via the Java [AppCompatDelegate.setNightMode()](https://developer.android.com/reference/androidx/appcompat/app/AppCompatDelegate#setDefaultNightMode(int)) method.
*Android Example:*
!AndroidExample.gif!
Attachments
| File | Date | Size |
|---|---|---|
| AndroidExample.gif | 2021-02-27T05:44:51.000+0000 | 4318999 |
| ThemeOverrideTest.js | 2021-02-25T04:49:44.000+0000 | 1914 |
PR (master): https://github.com/appcelerator/titanium_mobile/pull/12353
FR Passed, waiting on Jenkins build and Backport.
merged to master and 10_0_X for 10.0.0 release target.
This change didn't get back-ported and is missing in the 10_0_X branch. We'll have to back-port the following commit. https://github.com/appcelerator/titanium_mobile/pull/12353/commits/40166f6ffbafd8a82a21ea3e4a4108aff8e22b3e
PR (10_0_X): https://github.com/appcelerator/titanium_mobile/pull/12876