Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27501] Android: Be able to determine dark / light theme, as well as changes on it

GitHub Issuen/a
TypeImprovement
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2020-08-03T20:42:58.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.1.0
Componentsn/a
Labelsn/a
ReporterSergey Volkov
AssigneeChristopher Williams
Created2019-10-01T16:11:31.000+0000
Updated2020-08-03T20:42:58.000+0000

Description

A developer should be able to check the current Configuration.UI_MODE_NIGHT_MASK, i.e. dark theme vs light theme.

Attachments

FileDateSize
0001-feat-android-semantic-colors-and-night-mode.patch2019-10-10T09:52:43.000+00008569

Comments

  1. Sergey Volkov 2019-10-01

    Documentation: https://developer.android.com/guide/topics/ui/look-and-feel/darktheme Sample code for the patch:
       const colorset = require('/semantic.colors.json');
       if (Ti.UI.Android) {
         const mode = Ti.UI.Android.nightModeStatus;
         if (mode === Ti.UI.Android.MODE_NIGHT_YES) {
           Ti.UI.semanticColorType = Ti.UI.SEMANTIC_COLOR_TYPE_DARK;
         } else {
           Ti.UI.semanticColorType = Ti.UI.SEMANTIC_COLOR_TYPE_LIGHT;
         }
       }
       
       Object.keys(colorset).forEach(name => {
         Alloy.CFG.color[name] = Ti.UI.fetchSemanticColor(name);
       });
       
    Also patch provides additional build step for android: color resources (xml) are generated from "semantic.colors.json" (res/values/values.xml for "light" colors and res/values-night/values-night.xml for "dark"). This allows to define colors one time in "semantic.colors.json" and then use them in android xml-theme.
  2. Christopher Williams 2020-01-28

    I've started to look into this, because the iOS side had some funkiness to it as well. We should have a cross-platform API to query for whether we're in dark/night mode versus normal/light mode. We had a property off the Ti.App.iOS namesake for iOS. We also had an API in Ti.UI.fetchSemanticColor that was problematic as it'd return different types based on OS/OS version - and one of the types was entirely undocumented. I'm in the process of trying to cleaning that up, incorporating [~s.volkov]'s PR changes for Android support, and trying to get the docs right around the previously undocumented proxy type it returns.
  3. Christopher Williams 2020-01-28

    WIP PR: https://github.com/appcelerator/titanium_mobile/pull/11457
  4. Christopher Williams 2020-01-28

    WIP PR: https://github.com/appcelerator/titanium_mobile/pull/11457
  5. Satyam Sekhri 2020-05-08

    FR Passed.
  6. Satyam Sekhri 2020-08-03

    Verified on: Mac OS: 10.15.4 SDK: 9.1.0.v20200727104531 Appc CLI: 8.1.0-master.7 JDK: 11.0.4 Node: 10.17.0 Studio: 6.0.0.202005141803 Xcode: 12.0 beta Device: iPhone X(v13.4), iOS simulator 13.5, Pixel 3(v10.0), Pixel 2 emulator(v10.0)

JSON Source