Skip to content

Commit 66c6017

Browse files
authored
Merge branch 'main' into remove/use-picture
2 parents 59d263a + 56d7ff0 commit 66c6017

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

package/src/skia/__tests__/Geometry.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,28 @@ describe("Geometry", () => {
1212
expect(result.width).toBe(140);
1313
expect(result.height).toBe(60);
1414
});
15+
16+
test("parse #hex without opacity", () => {
17+
const { Skia } = importSkia();
18+
19+
const color = Skia.Color("#808080");
20+
expect(color[0]).toBeCloseTo(0.5);
21+
expect(color[1]).toBeCloseTo(0.5);
22+
expect(color[2]).toBeCloseTo(0.5);
23+
});
24+
test("parse #hex with opacity", () => {
25+
const { Skia } = importSkia();
26+
27+
let color = Skia.Color("#80808080");
28+
expect(color[0]).toBeCloseTo(0.5);
29+
expect(color[1]).toBeCloseTo(0.5);
30+
expect(color[2]).toBeCloseTo(0.5);
31+
expect(color[3]).toBeCloseTo(0.5);
32+
33+
color = Skia.Color("#ff800080");
34+
expect(color[0]).toBeCloseTo(1);
35+
expect(color[1]).toBeCloseTo(0.5);
36+
expect(color[2]).toBeCloseTo(0);
37+
expect(color[3]).toBeCloseTo(0.5);
38+
});
1539
});

package/src/skia/web/JsiSkColor.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,17 @@ const parseCSSColor = (cssStr: string) => {
241241
return null;
242242
} // Covers NaN.
243243
return [(iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, 1];
244+
} else if (str.length === 9) {
245+
var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
246+
if (!(iv >= 0 && iv <= 0xffffffff)) {
247+
return null; // Covers NaN.
248+
}
249+
return [
250+
((iv & 0xff000000) >> 24) & 0xff,
251+
(iv & 0xff0000) >> 16,
252+
(iv & 0xff00) >> 8,
253+
(iv & 0xff) / 255,
254+
];
244255
}
245256

246257
return null;

package/src/values/web/RNSkReadonlyValue.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ export class RNSkReadonlyValue<T> implements SkiaValue<T> {
1313
}
1414

1515
protected update(nextValue: T): void {
16-
this._current = nextValue;
17-
this.notifyListeners();
16+
if (this._current !== nextValue) {
17+
this._current = nextValue;
18+
this.notifyListeners();
19+
}
1820
}
1921

2022
public readonly __typename__ = "RNSkValue";

0 commit comments

Comments
 (0)