Skip to content

Commit 3c04bfc

Browse files
nicklockwoodfacebook-github-bot-3
authored andcommitted
Added support for #rgba and #rrggbbaa colors
Summary: public Added support for #rgba and #rrggbbaa colors, which are now officially recognized in the css spec, and supported by WebKit: http://trac.webkit.org/changeset/192023 Reviewed By: davidaurelio Differential Revision: D2631386 fb-gh-sync-id: 207a14f77f94bac8088568dc1bbe2bb29f0176c3
1 parent c6532a9 commit 3c04bfc

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

Examples/UIExplorer/BorderExample.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ var styles = StyleSheet.create({
8282
},
8383
border7: {
8484
borderWidth: 10,
85-
borderColor: 'rgba(255,0,0,0.5)',
85+
borderColor: '#f007',
8686
borderRadius: 30,
8787
overflow: 'hidden',
8888
},

Libraries/vendor/tinycolor/tinycolor.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ tinycolor.prototype = {
4747
//
4848
// "red"
4949
// "#f00" or "f00"
50+
// "#f00f" or "f00f"
5051
// "#ff0000" or "ff0000"
51-
// "#ff000000" or "ff000000"
52+
// "#ff0000ff" or "ff0000ff"
5253
// "rgb 255 0 0" or "rgb (255, 0, 0)"
5354
// "rgb 1.0 0 0" or "rgb (1, 0, 0)"
5455
// "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
@@ -389,6 +390,11 @@ function convertToPercentage(n) {
389390
return n;
390391
}
391392

393+
// Converts a hex value to a decimal
394+
function convertHexToDecimal(h) {
395+
return (parseIntFromHex(h) / 255);
396+
}
397+
392398
var matchers = (function() {
393399
// <http://www.w3.org/TR/css3-values/#integers>
394400
var CSS_INTEGER = "[-\\+]?\\d+%?";
@@ -413,7 +419,9 @@ var matchers = (function() {
413419
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
414420
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
415421
hex3: /^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
422+
hex4: /^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
416423
hex6: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
424+
hex8: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
417425
};
418426
})();
419427

@@ -454,6 +462,15 @@ function stringInputToObject(color) {
454462
if ((match = matchers.hsva.exec(color))) {
455463
return { h: match[1], s: match[2], v: match[3], a: match[4] };
456464
}
465+
if ((match = matchers.hex8.exec(color))) {
466+
return {
467+
r: parseIntFromHex(match[1]),
468+
g: parseIntFromHex(match[2]),
469+
b: parseIntFromHex(match[3]),
470+
a: convertHexToDecimal(match[4]),
471+
format: named ? "name" : "hex"
472+
};
473+
}
457474
if ((match = matchers.hex6.exec(color))) {
458475
return {
459476
r: parseIntFromHex(match[1]),
@@ -462,6 +479,15 @@ function stringInputToObject(color) {
462479
format: named ? "name" : "hex"
463480
};
464481
}
482+
if ((match = matchers.hex4.exec(color))) {
483+
return {
484+
r: parseIntFromHex(match[1] + '' + match[1]),
485+
g: parseIntFromHex(match[2] + '' + match[2]),
486+
b: parseIntFromHex(match[3] + '' + match[3]),
487+
a: convertHexToDecimal(match[4] + '' + match[4]),
488+
format: named ? "name" : "hex"
489+
};
490+
}
465491
if ((match = matchers.hex3.exec(color))) {
466492
return {
467493
r: parseIntFromHex(match[1] + '' + match[1]),

0 commit comments

Comments
 (0)