Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): semantic colors with alpha value #11315

Merged
merged 4 commits into from May 26, 2020

Conversation

drauggres
Copy link
Contributor

JIRA: https://jira.appcelerator.org/browse/TIMOB-27519

Test case:

Resources/app.js
const image = 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/64_365_Color_Macro_%285498808099%29.jpg/1280px-64_365_Color_Macro_%285498808099%29.jpg';
const CFG = {
    color: {}
};
const fileName = 'semantic.colors.json';
const colorsetFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, fileName);
if (colorsetFile.exists()) {
    const colorset = JSON.parse(colorsetFile.read().text);
    Object.keys(colorset).forEach(name => {
        CFG.color[name] = Ti.UI.fetchSemanticColor(name);
    });
}

const win = Ti.UI.createWindow({
    backgroundImage: image
});

const container = Ti.UI.createView({
    width: Ti.UI.FILL,
    height: Ti.UI.SIZE,
    backgroundColor: 'transparent',
    layout: 'vertical',
    center: {
        y: '50%'
    }
});

Object.keys(CFG.color).forEach(name => {
    appendView(name, CFG.color[name])
});

appendView('Not semantic', 'gray');
appendView('Not semantic', 'rgba(255, 0, 255, 0.33)');

function appendView(name, colorValue) {
    const view = Ti.UI.createView({
        backgroundColor: colorValue,
        width: Ti.UI.FILL,
        height: 30
    });
    const label = Ti.UI.createLabel({
        color: 'black',
        text: `${name}: ${colorValue}`,
        center: {x: '50%'}
    });
    view.add(label);
    container.add(view);
}

win.add(container);

win.open();
Resources/semantic.colors.json ```javascript { "green_100.0": { "light": { "color": "#00ff00", "alpha": "100.0" }, "dark": { "color": "#8000", "alpha": "100.0" } }, "blue_75.0": { "light": { "color": "#0000ff", "alpha": "75.0" }, "dark": { "color": "#80", "alpha": "75.0" } }, "cyan_50.0": { "light": { "color": "#00ffff", "alpha": "50.0" }, "dark": { "color": "#8080", "alpha": "50.0" } }, "red_25.0": { "light": { "color": "#ff0000", "alpha": "25.0" }, "dark": { "color": "#800000", "alpha": "25.0" } }, "magenta_0": { "light": { "color": "#ff00ff", "alpha": "0" }, "dark": { "color": "#800080", "alpha": "0.0" } }, "yellow_noalpha": { "light": "#ffff00", "dark": "#808000" } }
</details>

@build
Copy link
Contributor

build commented Nov 5, 2019

Messages
📖

💾 Here's the generated SDK zipfile.

📖 🎉 Another contribution from our awesome community member, drauggres! Thanks again for helping us make Titanium SDK better. 👍
📖 ✊ The commits in this PR match our conventions! Feel free to Rebase and Merge this PR when ready.
📖

✅ All tests are passing
Nice one! All 6642 tests are passing.
(There are 703 skipped tests not included in that total)

Generated by 🚫 dangerJS against c2d88b0

@sgtcoolguy
Copy link
Contributor

So I was a bit confused about this one, but there's a few points to mention:

  • There's already roughly equivalent code in the _build.js scripts for iOS/android
  • This PR deals with iOS < 13 and android at runtime fetching colors
  • You could actually hack this in using a hex with the alpha value (i.e '#00FF0080') - but I don't think the _build.js logic would handle that correctly

I've fixed the merge conflicts and unified the code used both at runtime and during the app build. A semantic.colors.json file can have a hex string value, or an object with a separate hex/alpha properties with string values. You can use an RRGGBBAA format hex string (used by iOS and CSS - but NOTE that typically Android natively uses AARRGGBB). If you use a hex string and a separate alpha, we throw an Error (which to choose?!).

When we return a value from Ti.UI.fetchSemanticColor on Android/older iOS - we return a rgba() expression - because of the aforementioned platform parity issue of iOS/Android differing in whether they expect the alpha to be first or last in 8-character hex strings. Both platforms should correctly handle rgba().

@build build added this to the 9.1.0 milestone May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants