Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27209] iOS: Be able to determine dark / light mode, as well as changes on it

GitHub Issuen/a
TypeImprovement
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2019-09-02T10:31:34.000+0000
Affected Version/sn/a
Fix Version/sRelease 8.2.0
ComponentsiOS
Labelsn/a
ReporterHans Knöchel
AssigneeVijay Singh
Created2019-07-07T15:45:55.000+0000
Updated2021-01-06T08:42:47.000+0000

Description

A developer should be able to check the current userInterfaceStyle, e.g. dark mode vs light mode.

Comments

  1. Hans Knöchel 2019-07-07

    Pull: https://github.com/appcelerator/titanium_mobile/pull/11031 Test-Case:
       
       var currentStyle = Ti.App.iOS.userInterfaceStyle;
       
       console.log('Initial style:' + formattedUserInterfaceStyle(currentStyle));
       
       var win = Ti.UI.createWindow({
           backgroundColor: '#fff'
       });
       
       var btn = Ti.UI.createButton({
           title: 'Check User Interface Style'
       });
       
       btn.addEventListener('click', function() {
           Ti.API.info('User Interface Style: ' + formattedUserInterfaceStyle(currentStyle));
       });
       
       Ti.App.iOS.addEventListener('traitcollectionchange', function (event) {
           if (currentStyle !== Ti.App.iOS.userInterfaceStyle) {
               currentStyle = Ti.App.iOS.userInterfaceStyle;
               Ti.API.info('User Interface Style changed: ' + formattedUserInterfaceStyle(currentStyle));
           }
       });
       
       win.add(btn);
       win.open();
       
       function formattedUserInterfaceStyle(style) {
           switch (style) {
               case Ti.App.iOS.USER_INTERFACE_STYLE_LIGHT: return 'Light';
               case Ti.App.iOS.USER_INTERFACE_STYLE_DARK: return 'Dark';
           }
       
           return 'Unspecified';
       }
       
  2. Satyam Sekhri 2019-08-16

    FR Passed. Can successfully determine the current mode dark/light and also the switch when it happens.
  3. Samir Mohammed 2019-09-02

    *Closing ticket*, improvement verified in SDK version 8.2.0.v20190829124255. Note* Improvement will be merged into 8_3_X at a later date. Test and other information can be found at: Pull: https://github.com/appcelerator/titanium_mobile/pull/11031

JSON Source