Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-28325
Browse files Browse the repository at this point in the history
  • Loading branch information
ssekhri committed Feb 3, 2021
2 parents 5b9e06e + d36c5c7 commit effd9d8
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import android.content.res.Resources;
import android.graphics.Color;

import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat;

Expand All @@ -35,6 +34,8 @@ public class TiColorHelper
"rgba\\(\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*,\\s*(\\d\\.\\d+)\\s*\\)");
static Pattern floatsPattern = Pattern.compile(
"rgba\\(\\s*(\\d\\.\\d+)\\s*,\\s*(\\d\\.\\d+)\\s*,\\s*(\\d\\.\\d+)\\s*,\\s*(\\d\\.\\d+)\\s*\\)");
static Pattern rgbaPatternFallback =
Pattern.compile("rgba\\(\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*\\)");

private static final String TAG = "TiColorHelper";
private static HashMap<String, Integer> colorTable;
Expand Down Expand Up @@ -71,13 +72,17 @@ public static int parseColor(String value)
}
// rgba(int, int, int, int)
if ((m = argbPattern.matcher(lowval)).matches()) {
return Color.argb(Integer.valueOf(m.group(4)), Integer.valueOf(m.group(1)),
Integer.valueOf(m.group(2)), Integer.valueOf(m.group(3)));
return Color.argb(Integer.valueOf(m.group(4)), Integer.valueOf(m.group(1)), Integer.valueOf(m.group(2)),
Integer.valueOf(m.group(3)));
}
// rgba(int, int, int, float)
if ((m = rgbaPattern.matcher(lowval)).matches()) {
return Color.argb(Math.round(Float.valueOf(m.group(4)) * 255f), Integer.valueOf(m.group(1)),
Integer.valueOf(m.group(2)), Integer.valueOf(m.group(3)));
Integer.valueOf(m.group(2)), Integer.valueOf(m.group(3)));
}
// rgba(int, int, int) with missing alpha value
if ((m = rgbaPatternFallback.matcher(lowval)).matches()) {
return Color.rgb(Integer.valueOf(m.group(1)), Integer.valueOf(m.group(2)), Integer.valueOf(m.group(3)));
}
// rgba(float, float, float, float)
if ((m = floatsPattern.matcher(lowval)).matches()) {
Expand Down
14 changes: 13 additions & 1 deletion build/lib/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,19 @@ async function test(platforms, target, deviceId, deployType, deviceFamily, snaps

// If we're gathering images, make sure we get them all before we move on
if (snapshotPromises.length !== 0) {
await Promise.all(snapshotPromises);
try {
await Promise.all(snapshotPromises);
} catch (err) {
// If grabbing an image fails, can we report more details about why?
// The rejected error should have stdout/stderr properties
if (err.stderr) {
console.error(err.stderr);
}
if (err.stdout) {
console.log(err.stdout);
}
throw err;
}
}

return results;
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions tests/Resources/ti.ui.view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1322,4 +1322,37 @@ describe('Titanium.UI.View', function () {
const view2 = Ti.UI.createView({ filterTouchesWhenObscured: true });
should(view2.filterTouchesWhenObscured).be.true();
});

it('rgba fallback', finish => {
if (isCI && utilities.isMacOS()) { // some of the CI mac nodes lie about their scale, which makes the image comparison fail
return finish(); // FIXME: skip when we move to official mocha package
}
win = Ti.UI.createWindow({ backgroundColor: '#fff' });
const rgbaView = Ti.UI.createView({
width: 100,
height: 100,
backgroundColor: 'rgba(255,0,0)',
left: 0
});
const rgbView = Ti.UI.createView({
width: 100,
height: 100,
backgroundColor: 'rgb(0,255,0)',
left: 100
});

win.addEventListener('postlayout', function postlayout() { // FIXME: Support once!
win.removeEventListener('postlayout', postlayout); // only run once
try {
should(rgbaView).matchImage('snapshots/rgbaView_red.png');
should(rgbView).matchImage('snapshots/rgbView_green.png');
} catch (err) {
return finish(err);
}
finish();
});
win.add(rgbaView);
win.add(rgbView);
win.open();
});
});

0 comments on commit effd9d8

Please sign in to comment.