[TIMOB-27209] iOS: Be able to determine dark / light mode, as well as changes on it
| GitHub Issue | n/a |
|---|---|
| Type | Improvement |
| Priority | None |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2019-09-02T10:31:34.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 8.2.0 |
| Components | iOS |
| Labels | n/a |
| Reporter | Hans Knöchel |
| Assignee | Vijay Singh |
| Created | 2019-07-07T15:45:55.000+0000 |
| Updated | 2021-01-06T08:42:47.000+0000 |
Description
A developer should be able to check the current userInterfaceStyle, e.g. dark mode vs light mode.
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'; }FR Passed. Can successfully determine the current mode dark/light and also the switch when it happens.
*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