Skip to content

Commit 8f82159

Browse files
authored
Merge branch 'main' into fix/skia-value-name
2 parents 8431591 + 5b88808 commit 8f82159

File tree

9 files changed

+40
-64
lines changed

9 files changed

+40
-64
lines changed

example/src/Examples/API/Data.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ for (let x = 0; x < 256 * 4; x++) {
2020
}
2121
}
2222
const data = Skia.Data.fromBytes(pixels);
23-
const img = Skia.MakeImage(
23+
const img = Skia.Image.MakeImage(
2424
{
2525
width: 256,
2626
height: 256,

example/src/Examples/Aurora/Aurora.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { CoonsPatchMeshGradient } from "./components/CoonsPatchMeshGradient";
44

55
export const Aurora = () => {
66
return (
7-
<CoonsPatchMeshGradient rows={3} cols={3} colors={palette.otto} play />
7+
<CoonsPatchMeshGradient
8+
rows={3}
9+
cols={3}
10+
colors={palette.otto}
11+
lines
12+
handles
13+
/>
814
);
915
};
1016

example/src/Examples/Aurora/components/CoonsPatchMeshGradient.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from "react";
22
import type { CubicBezierHandle, SkiaValue } from "@shopify/react-native-skia";
33
import {
4+
Skia,
5+
isEdge,
46
Group,
57
useClockValue,
68
add,
@@ -21,6 +23,7 @@ import { Curves } from "./Curves";
2123
import { useHandles } from "./useHandles";
2224

2325
const { width, height } = Dimensions.get("window");
26+
const window = Skia.XYWHRect(0, 0, width, height);
2427

2528
const rectToTexture = (
2629
vertices: CubicBezierHandle[],
@@ -127,12 +130,7 @@ export const CoonsPatchMeshGradient = ({
127130
.flat();
128131
const meshNoise = useDerivedValue(() => {
129132
return defaultMesh.map((pt, i) => {
130-
const isEdge =
131-
pt.pos.x === 0 ||
132-
pt.pos.y === 0 ||
133-
pt.pos.x === Math.fround(width) ||
134-
pt.pos.y === Math.fround(height);
135-
if (isEdge) {
133+
if (isEdge(pt.pos, window)) {
136134
return pt;
137135
}
138136
const noisePos = new SimplexNoise(`${i}-pos`);
@@ -166,7 +164,7 @@ export const CoonsPatchMeshGradient = ({
166164

167165
const meshGesture = useValue(defaultMesh);
168166

169-
const onTouch = useHandles(meshGesture, defaultMesh, width, height);
167+
const onTouch = useHandles(meshGesture, defaultMesh, window);
170168
const mesh = play ? meshNoise : meshGesture;
171169
if (image === null) {
172170
return null;
@@ -190,9 +188,7 @@ export const CoonsPatchMeshGradient = ({
190188
})}
191189
</Group>
192190
{defaultMesh.map(({ pos }, index) => {
193-
const edge =
194-
pos.x === 0 || pos.y === 0 || pos.x === width || pos.y === height;
195-
if (edge || !handles) {
191+
if (isEdge(pos, window) || !handles) {
196192
return null;
197193
}
198194
return (

example/src/Examples/Aurora/components/useHandles.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import type {
22
SkiaMutableValue,
33
CubicBezierHandle,
4+
SkRect,
45
} from "@shopify/react-native-skia";
5-
import { sub, useTouchHandler, useValue } from "@shopify/react-native-skia";
6+
import {
7+
isEdge,
8+
sub,
9+
useTouchHandler,
10+
useValue,
11+
} from "@shopify/react-native-skia";
12+
613

714
import { inRadius, symmetric } from "./Math";
815

@@ -14,8 +21,7 @@ type TouchSelection = null | {
1421
export const useHandles = (
1522
mesh: SkiaMutableValue<CubicBezierHandle[]>,
1623
defaultMesh: CubicBezierHandle[],
17-
width: number,
18-
height: number
24+
window: SkRect
1925
) => {
2026
const selection = useValue<TouchSelection>(null);
2127
return useTouchHandler({
@@ -37,9 +43,7 @@ export const useHandles = (
3743
}
3844
} else {
3945
defaultMesh.every(({ pos: p }, index) => {
40-
const edge =
41-
p.x === 0 || p.y === 0 || p.x === width || p.y === height;
42-
if (!edge) {
46+
if (!isEdge(p, window)) {
4347
const { pos, c1, c2 } = mesh.current[index];
4448
const c3 = symmetric(c1, pos);
4549
const c4 = symmetric(c2, pos);

example/src/Examples/Vertices/Vertices.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import {
77
useDerivedValue,
88
Vertices,
99
useImage,
10+
Skia,
11+
isEdge,
1012
} from "@shopify/react-native-skia";
1113
import cdt2d from "cdt2d";
1214
import SimplexNoise from "simplex-noise";
1315

1416
import "./cdt2d.d";
1517

1618
const { width, height } = Dimensions.get("window");
19+
const window = Skia.XYWHRect(0, 0, width, height);
1720
const N = 3;
1821
const n = new Array(N + 1).fill(0).map((_, i) => i);
1922
const hSize = width / N;
@@ -34,15 +37,14 @@ export const Demo = () => {
3437
const clock = useClockValue();
3538
const vertices = useDerivedValue(
3639
() =>
37-
defaultVertices.map(({ x, y }, i) => {
38-
const isEdge = x === 0 || y === 0 || x === width || y === height;
39-
if (isEdge) {
40-
return { x, y };
40+
defaultVertices.map((vertex, i) => {
41+
if (isEdge(vertex, window)) {
42+
return vertex;
4143
}
4244
const noise = new SimplexNoise(i);
4345
return {
44-
x: x + AX * noise.noise2D(clock.current / F, 0),
45-
y: y + AY * noise.noise2D(0, clock.current / F),
46+
x: vertex.x + AX * noise.noise2D(clock.current / F, 0),
47+
y: vertex.y + AY * noise.noise2D(0, clock.current / F),
4648
};
4749
}),
4850
[clock]

package/src/renderer/processors/Rects.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { SkRect, SkRRect } from "../../skia";
33
import { Skia } from "../../skia";
44

5+
import type { Vector } from "./math/Vector";
56
import { vec } from "./math/Vector";
67
import type { Radius } from "./Radius";
78
import { processRadius } from "./Radius";
@@ -22,6 +23,9 @@ export const bounds = (rects: SkRect[]) => {
2223
return rect(x, y, width, height);
2324
};
2425

26+
export const isEdge = (pos: Vector, b: SkRect) =>
27+
pos.x === b.x || pos.y === b.y || pos.x === b.width || pos.y === b.height;
28+
2529
export const topLeft = (r: SkRect | SkRRect) =>
2630
isRRect(r) ? vec(r.rect.x, r.rect.y) : vec(r.x, r.y);
2731
export const topRight = (r: SkRect | SkRRect) =>

package/src/skia/Skia.ts

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*global SkiaApi*/
2-
import type { SkiaApi as SkSkiaApi } from "./types";
2+
import type { Skia as SkSkiaApi } from "./types";
33

44
/**
55
* Declares the SkiaApi as an available object in the global scope
@@ -8,39 +8,4 @@ declare global {
88
var SkiaApi: SkSkiaApi;
99
}
1010

11-
/**
12-
* Declares the implemented API with overrides.
13-
*/
14-
export const Skia = {
15-
// Factories
16-
Typeface: SkiaApi.Typeface,
17-
MaskFilter: SkiaApi.MaskFilter,
18-
RuntimeEffect: SkiaApi.RuntimeEffect,
19-
Shader: SkiaApi.Shader,
20-
ImageFilter: SkiaApi.ImageFilter,
21-
PathEffect: SkiaApi.PathEffect,
22-
Data: SkiaApi.Data,
23-
SVG: SkiaApi.SVG,
24-
FontMgr: SkiaApi.FontMgr,
25-
TextBlob: SkiaApi.TextBlob,
26-
// Constructors
27-
Matrix: SkiaApi.Matrix,
28-
Font: SkiaApi.Font,
29-
Point: SkiaApi.Point,
30-
XYWHRect: SkiaApi.XYWHRect,
31-
RRectXY: SkiaApi.RRectXY,
32-
RuntimeShaderBuilder: SkiaApi.RuntimeShaderBuilder,
33-
Paint: SkiaApi.Paint,
34-
PictureRecorder: SkiaApi.PictureRecorder,
35-
Picture: SkiaApi.Picture,
36-
Path: SkiaApi.Path,
37-
ColorFilter: SkiaApi.ColorFilter,
38-
ContourMeasureIter: SkiaApi.ContourMeasureIter,
39-
Color: SkiaApi.Color,
40-
RSXform: SkiaApi.RSXform,
41-
// For the following methods the factory symmetry is broken to be comptatible with CanvasKit
42-
MakeSurface: SkiaApi.Surface.Make,
43-
MakeImageFromEncoded: SkiaApi.Image.MakeImageFromEncoded,
44-
MakeImage: SkiaApi.Image.MakeImage,
45-
MakeVertices: SkiaApi.MakeVertices,
46-
};
11+
export const Skia = SkiaApi;

package/src/skia/core/Image.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ import { useRawData } from "./Data";
77
* Returns a Skia Image object
88
* */
99
export const useImage = (source: DataSource, onError?: (err: Error) => void) =>
10-
useRawData(source, Skia.MakeImageFromEncoded, onError);
10+
useRawData(source, Skia.Image.MakeImageFromEncoded, onError);

package/src/skia/types/Skia.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ import type {
3232
/**
3333
* Declares the interface for the native Skia API
3434
*/
35-
export interface SkiaApi {
35+
export interface Skia {
3636
Point: (x: number, y: number) => SkPoint;
3737
XYWHRect: (x: number, y: number, width: number, height: number) => SkRect;
3838
RuntimeShaderBuilder: (rt: SkRuntimeEffect) => SkRuntimeShaderBuilder;
3939
RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;
4040
RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;
4141
Color: (color: Color) => SkColor;
42-
parseColorString: (color: string) => SkColor | undefined;
4342
ContourMeasureIter: (
4443
path: SkPath,
4544
forceClosed: boolean,

0 commit comments

Comments
 (0)