Skip to content

Commit 8150883

Browse files
authored
Merge branch 'main' into elliotwaite-patch-1
2 parents e79c0dc + 90db9fc commit 8150883

File tree

10 files changed

+46
-56
lines changed

10 files changed

+46
-56
lines changed

docs/docs/paint/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ export const PaintDemo = () => {
143143
};
144144
```
145145

146-
<img src={require("/static/img/paint/assignement.png").default} width="256" height="256" />
146+
<img src={require("/static/img/paint/assignement.png").default} width="256" height="256" />

docs/yarn.lock

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,8 +1805,10 @@
18051805
integrity sha512-o6aam+0Ug1xGK3ABYmBm0B1YuEKfM/5kaoZO0eHbZwSpw9UzDX4G5y4Nx/K20FHqUmJHkZmLvOUFYwN4N+HqKA==
18061806

18071807
"@shopify/react-native-skia@link:../package":
1808-
version "0.0.0"
1809-
uid ""
1808+
version "0.1.0-development"
1809+
dependencies:
1810+
canvaskit-wasm "0.36.1"
1811+
react-reconciler "^0.27.0"
18101812

18111813
"@sideway/address@^4.1.3":
18121814
version "4.1.4"
@@ -5737,9 +5739,9 @@ loader-runner@^4.2.0:
57375739
integrity sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==
57385740

57395741
loader-utils@^2.0.0:
5740-
version "2.0.2"
5741-
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.2.tgz#d6e3b4fb81870721ae4e0868ab11dd638368c129"
5742-
integrity sha512-TM57VeHptv569d/GKh6TAYdzKblwDNiumOdkFnejjD0XwTH87K90w3O7AiJRqdQoXygvi1VQTJTLGhJl7WqA7A==
5742+
version "2.0.4"
5743+
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.4.tgz#8b5cb38b5c34a9a018ee1fc0e6a066d1dfcc528c"
5744+
integrity sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==
57435745
dependencies:
57445746
big.js "^5.2.2"
57455747
emojis-list "^3.0.0"
@@ -7147,14 +7149,13 @@ react-native-reanimated@^2.4.1:
71477149
setimmediate "^1.0.5"
71487150
string-hash-64 "^1.0.3"
71497151

7150-
react-reconciler@0.26.2:
7151-
version "0.26.2"
7152-
resolved "https://registry.yarnpkg.com/react-reconciler/-/react-reconciler-0.26.2.tgz#bbad0e2d1309423f76cf3c3309ac6c96e05e9d91"
7153-
integrity sha512-nK6kgY28HwrMNwDnMui3dvm3rCFjZrcGiuwLc5COUipBK5hWHLOxMJhSnSomirqWwjPBJKV1QcbkI0VJr7Gl1Q==
7152+
react-reconciler@^0.27.0:
7153+
version "0.27.0"
7154+
resolved "https://registry.yarnpkg.com/react-reconciler/-/react-reconciler-0.27.0.tgz#360124fdf2d76447c7491ee5f0e04503ed9acf5b"
7155+
integrity sha512-HmMDKciQjYmBRGuuhIaKA1ba/7a+UsM5FzOZsMO2JYHt9Jh8reCb7j1eDC95NOyUlKM9KRyvdx0flBuDvYSBoA==
71547156
dependencies:
71557157
loose-envify "^1.1.0"
7156-
object-assign "^4.1.1"
7157-
scheduler "^0.20.2"
7158+
scheduler "^0.21.0"
71587159

71597160
react-router-config@^5.1.1:
71607161
version "5.1.1"
@@ -7573,6 +7574,13 @@ scheduler@^0.20.2:
75737574
loose-envify "^1.1.0"
75747575
object-assign "^4.1.1"
75757576

7577+
scheduler@^0.21.0:
7578+
version "0.21.0"
7579+
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.21.0.tgz#6fd2532ff5a6d877b6edb12f00d8ab7e8f308820"
7580+
integrity sha512-1r87x5fz9MXqswA2ERLo0EbOAU74DpIUO090gIasYTqlVoJeMcl+Z1Rg7WHz+qtPujhS/hGIt9kxZOYBV3faRQ==
7581+
dependencies:
7582+
loose-envify "^1.1.0"
7583+
75767584
75777585
version "2.7.0"
75787586
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.0.tgz#17151f76d8eae67fbbf77960c33c676ad9f4efc7"

package/src/dom/nodes/DrawingNode.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
import type { NodeContext } from "./Node";
1010
import { JsiDeclarationNode } from "./Node";
1111
import { PaintNode } from "./PaintNode";
12-
import { isSkPaint, JsiRenderNode } from "./RenderNode";
12+
import { JsiRenderNode } from "./RenderNode";
1313

1414
export abstract class JsiDrawingNode<P extends DrawingNodeProps, C>
1515
extends JsiRenderNode<P>
@@ -52,10 +52,8 @@ export abstract class JsiDrawingNode<P extends DrawingNodeProps, C>
5252
}
5353

5454
renderNode(ctx: DrawingContext): void {
55-
if (this.props.paint && isSkPaint(this.props.paint)) {
55+
if (this.props.paint) {
5656
this.draw({ ...ctx, paint: this.props.paint });
57-
} else if (this.props.paint && this.props.paint.current != null) {
58-
this.draw({ ...ctx, paint: this.props.paint.current.materialize() });
5957
} else {
6058
this.draw(ctx);
6159
}

package/src/dom/nodes/RenderNode.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { RefObject } from "react";
2-
31
import type {
42
SkMatrix,
53
SkRect,
@@ -21,7 +19,6 @@ import type {
2119
DrawingContext,
2220
NodeType,
2321
Node,
24-
DeclarationNode,
2522
} from "../types";
2623

2724
import { isPathDef, processPath, processTransformProps } from "./datatypes";
@@ -236,17 +233,12 @@ export abstract class JsiRenderNode<P extends GroupProps>
236233
this.clipRRect !== undefined;
237234
const shouldSave = hasTransform || hasClip || !!layer;
238235
const op = invertClip ? ClipOp.Difference : ClipOp.Intersect;
239-
240236
if (shouldSave) {
241237
if (layer) {
242238
if (typeof layer === "boolean") {
243239
canvas.saveLayer();
244-
} else if (isSkPaint(layer)) {
245-
canvas.saveLayer(layer);
246240
} else {
247-
canvas.saveLayer(
248-
layer.current ? layer.current.materialize() : undefined
249-
);
241+
canvas.saveLayer(layer);
250242
}
251243
} else {
252244
canvas.save();
@@ -274,10 +266,6 @@ export abstract class JsiRenderNode<P extends GroupProps>
274266
abstract renderNode(ctx: DrawingContext): void;
275267
}
276268

277-
export const isSkPaint = (
278-
obj: RefObject<DeclarationNode<unknown, SkPaint>> | SkPaint
279-
): obj is SkPaint => "__typename__" in obj && obj.__typename__ === "Paint";
280-
281269
const concatPaint = (
282270
parent: SkPaint,
283271
{

package/src/dom/types/Common.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ReactNode, RefObject } from "react";
1+
import type { ReactNode } from "react";
22

33
import type {
44
BlendMode,
@@ -15,8 +15,6 @@ import type {
1515
Vector,
1616
} from "../../skia/types";
1717

18-
import type { DeclarationNode } from "./Node";
19-
2018
export type SkEnum<T> = Uncapitalize<keyof T extends string ? keyof T : never>;
2119

2220
export type PathDef = string | SkPath;
@@ -86,5 +84,5 @@ export interface PaintProps extends ChildrenProps {
8684
export interface GroupProps extends PaintProps, TransformProps {
8785
clip?: ClipDef;
8886
invertClip?: boolean;
89-
layer?: RefObject<DeclarationNode<unknown, SkPaint>> | SkPaint | boolean;
87+
layer?: SkPaint | boolean;
9088
}

package/src/dom/types/Drawings.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { RefObject } from "react";
2-
31
import type {
42
FillType,
53
SkImage,
@@ -29,10 +27,9 @@ import type {
2927
SkEnum,
3028
} from "./Common";
3129
import type { DrawingContext } from "./DrawingContext";
32-
import type { DeclarationNode } from "./Node";
3330

3431
export interface DrawingNodeProps extends GroupProps {
35-
paint?: SkPaint | RefObject<DeclarationNode<unknown, SkPaint>>;
32+
paint?: SkPaint;
3633
}
3734

3835
export type ImageProps = DrawingNodeProps &

package/src/renderer/HostComponents.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { ForwardedRef } from "react";
2-
31
import { NodeType } from "../dom/types";
42
import type {
53
CircleProps,
@@ -55,7 +53,6 @@ import type {
5553
BlendProps,
5654
MorphologyImageFilterProps,
5755
} from "../dom/types/ImageFilters";
58-
import type { PaintNode } from "../dom/nodes/PaintNode";
5956

6057
import type { Container } from "./Container";
6158
import { exhaustiveCheck } from "./typeddash";
@@ -67,7 +64,7 @@ declare global {
6764
interface IntrinsicElements {
6865
skGroup: SkiaProps<GroupProps>;
6966
skLayer: SkiaProps<ChildrenProps>;
70-
skPaint: SkiaProps<PaintProps> & { ref: ForwardedRef<PaintNode> };
67+
skPaint: SkiaProps<PaintProps>;
7168

7269
// Drawings
7370
skFill: SkiaProps<DrawingNodeProps>;
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
/* eslint-disable max-len */
2-
import React, { useRef, forwardRef } from "react";
1+
import React from "react";
32

43
import type { SkiaProps } from "../processors";
54
import type { DrawingNodeProps } from "../../dom/types";
6-
import type { PaintNode } from "../../dom/nodes/PaintNode";
75

8-
export const usePaintRef = () => {
9-
console.log(`usePaintRef() is now deprecated.
10-
If you are using the layer property, simply pass the component directly: https://shopify.github.io/react-native-skia/docs/group#layer-effects.
11-
If you are using the paint property, please the following paint properties directly: https://shopify.github.io/react-native-skia/docs/paint/overview`);
12-
return useRef<PaintNode>(null);
6+
export const Paint = (props: SkiaProps<DrawingNodeProps>) => {
7+
return <skPaint {...props} />;
138
};
14-
15-
export const Paint = forwardRef<PaintNode, SkiaProps<DrawingNodeProps>>(
16-
(props, ref) => {
17-
return <skPaint ref={ref} {...props} />;
18-
}
19-
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { importSkia } from "../../renderer/__tests__/setup";
2+
3+
describe("Geometry", () => {
4+
it("should calculate the bounding box the union of multiple rectangles", () => {
5+
const { bounds, rect } = importSkia();
6+
7+
const r1 = rect(-10, -10, 30, 30);
8+
const r2 = rect(30, 30, 100, 20);
9+
const result = bounds([r1, r2]);
10+
expect(result.x).toBe(-10);
11+
expect(result.y).toBe(-10);
12+
expect(result.width).toBe(140);
13+
expect(result.height).toBe(60);
14+
});
15+
});

package/src/skia/core/Rect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const bounds = (rects: SkRect[]) => {
1212
const y = Math.min(...rects.map((r) => r.y));
1313
const width = Math.max(...rects.map((r) => r.x + r.width));
1414
const height = Math.max(...rects.map((r) => r.y + r.height));
15-
return rect(x, y, width, height);
15+
return rect(x, y, width - x, height - y);
1616
};
1717

1818
export const topLeft = (r: SkRect | SkRRect) =>

0 commit comments

Comments
 (0)