-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for semantic colors
This adds a cross platfom method for loading semanitc colors, on iOS 11+ we will use the native Ti.UI.iOS.fetchSemanticColor to load the right color, in all other cases we use the Ti.UI.semanticColorType and the provided json file to obtain the correct value Fixes TIMOB-27126
- Loading branch information
1 parent
8871299
commit 064739e
Showing
6 changed files
with
191 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// Load extensions to polyfill our own APIs | ||
import './ti.blob'; | ||
import './ti.ui'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2019 by Axway, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
let colorset; | ||
let osVersion; | ||
|
||
// As Android passes a new instance of Ti.UI to every JS file we can't just | ||
// Ti.UI within this file, we must call kroll.binding to get the Titanium | ||
// namespace that is passed in with require and that deal with the .UI | ||
// namespace that is on that directly. | ||
let uiModule = Ti.UI; | ||
if (Ti.Android) { | ||
uiModule = kroll.binding('Titanium').Titanium.UI; | ||
} | ||
|
||
uiModule.SEMANTIC_COLOR_TYPE_LIGHT = 'light'; | ||
uiModule.SEMANTIC_COLOR_TYPE_DARK = 'dark'; | ||
uiModule.semanticColorType = Ti.UI.SEMANTIC_COLOR_TYPE_LIGHT; | ||
|
||
uiModule.fetchSemanticColor = function fetchSemanticColor (colorName) { | ||
if (!osVersion) { | ||
osVersion = parseInt(Ti.Platform.version.split('.')[0]); | ||
} | ||
|
||
if (Ti.iOS && osVersion >= 11) { | ||
return Ti.UI.iOS.fetchSemanticColor(colorName); | ||
} else { | ||
if (!colorset) { | ||
try { | ||
colorset = require('/semantic.colors.json'); // eslint-disable-line import/no-absolute-path | ||
} catch (error) { | ||
console.error('Failed to require colors file at /semantic.colors.json'); | ||
return; | ||
} | ||
} | ||
try { | ||
return colorset[colorName][uiModule.semanticColorType]; | ||
} catch (error) { | ||
console.log(`Failed to lookup color for ${colorName}`); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters