diff --git a/example/src/Tests/Tests.tsx b/example/src/Tests/Tests.tsx index ef6c2279e5..47a395b3bb 100644 --- a/example/src/Tests/Tests.tsx +++ b/example/src/Tests/Tests.tsx @@ -1,13 +1,16 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import type { SkiaDomView } from "@shopify/react-native-skia"; -import { Canvas } from "@shopify/react-native-skia"; +import { Group, Canvas, Skia } from "@shopify/react-native-skia"; import React, { useEffect, useRef, useState } from "react"; -import { Text, View } from "react-native"; +import { PixelRatio, Text, View } from "react-native"; import type { SerializedNode } from "./deserialize"; -import { parseProps, parseNode } from "./deserialize"; +import { parseNode } from "./deserialize"; import { useClient } from "./useClient"; +const scale = 3 / PixelRatio.get(); +const size = 256 * scale; + export const Tests = () => { const ref = useRef(null); const client = useClient(); @@ -20,7 +23,9 @@ export const Tests = () => { client.send( JSON.stringify( // eslint-disable-next-line no-eval - eval(`(function Main(){${tree.code}})`).call(parseProps(tree.ctx)) + eval(`(function Main(){const {Skia} = this;${tree.code}})`).call({ + Skia, + }) ) ); } else { @@ -52,8 +57,8 @@ export const Tests = () => { return ( 💚 Waiting for the server to send tests - - {drawing} + + {drawing} ); diff --git a/example/src/Tests/deserialize.ts b/example/src/Tests/deserialize.ts index 50aea5a1e0..3d0f6562ac 100644 --- a/example/src/Tests/deserialize.ts +++ b/example/src/Tests/deserialize.ts @@ -21,7 +21,7 @@ export const parseNode = (serializedNode: SerializedNode): any => { ); }; -export const parseProps = (props: SerializedProps) => { +const parseProps = (props: SerializedProps) => { const newProps: SerializedProps = {}; Object.keys(props).forEach((key) => { newProps[key] = parseProp(props[key]); diff --git a/package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h b/package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h index 513bb9cb89..0dcd3b04c9 100644 --- a/package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +++ b/package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h @@ -24,9 +24,7 @@ class RNSkAndroidPlatformContext : public RNSkPlatformContext { [this]() { notifyDrawLoop(false); }); } - ~RNSkAndroidPlatformContext() { - stopDrawLoop(); - } + ~RNSkAndroidPlatformContext() { stopDrawLoop(); } void performStreamOperation( const std::string &sourceUri, diff --git a/package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h b/package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h index c0da35d66c..576097a8b2 100644 --- a/package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +++ b/package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h @@ -16,12 +16,12 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include "include/gpu/GrDirectContext.h" -#include "include/gpu/gl/GrGLInterface.h" #include "SkCanvas.h" #include "SkColorSpace.h" #include "SkPicture.h" #include "SkSurface.h" +#include "include/gpu/GrDirectContext.h" +#include "include/gpu/gl/GrGLInterface.h" #pragma clang diagnostic pop diff --git a/package/cpp/api/JsiSkPathEffectFactory.h b/package/cpp/api/JsiSkPathEffectFactory.h index c9941e7b59..8ed945462a 100644 --- a/package/cpp/api/JsiSkPathEffectFactory.h +++ b/package/cpp/api/JsiSkPathEffectFactory.h @@ -12,12 +12,12 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include "include/effects/Sk1DPathEffect.h" -#include "include/effects/Sk2DPathEffect.h" #include "SkCornerPathEffect.h" #include "SkDashPathEffect.h" #include "SkDiscretePathEffect.h" #include "SkPathEffect.h" +#include "include/effects/Sk1DPathEffect.h" +#include "include/effects/Sk2DPathEffect.h" #pragma clang diagnostic pop diff --git a/package/cpp/api/JsiSkPathFactory.h b/package/cpp/api/JsiSkPathFactory.h index 96a5c38b15..d7bccf42f8 100644 --- a/package/cpp/api/JsiSkPathFactory.h +++ b/package/cpp/api/JsiSkPathFactory.h @@ -11,9 +11,9 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" -#include #include "SkPath.h" #include "SkPathOps.h" +#include #pragma clang diagnostic pop diff --git a/package/cpp/rnskia/RNSkPlatformContext.h b/package/cpp/rnskia/RNSkPlatformContext.h index 225bfe7715..1463972093 100644 --- a/package/cpp/rnskia/RNSkPlatformContext.h +++ b/package/cpp/rnskia/RNSkPlatformContext.h @@ -188,7 +188,8 @@ class RNSkPlatformContext { } } - // default implementation does nothing, so it can be called from virtual destructor. + // default implementation does nothing, so it can be called from virtual + // destructor. virtual void startDrawLoop() {} virtual void stopDrawLoop() {} diff --git a/package/src/renderer/__tests__/e2e/Drawings.spec.tsx b/package/src/renderer/__tests__/e2e/Drawings.spec.tsx index dd8297ec77..2b8ab953c1 100644 --- a/package/src/renderer/__tests__/e2e/Drawings.spec.tsx +++ b/package/src/renderer/__tests__/e2e/Drawings.spec.tsx @@ -78,13 +78,12 @@ describe("Drawings", () => { }); it("Should do rect marshalling properly", async () => { - const { Skia } = importSkia(); const result = await surface.eval( ` -this.path.addRect({ x: 0, y: 0, width: 100, height: 100 }); -return this.path.getBounds().width; -`, - { path: Skia.Path.Make() } +const path = Skia.Path.Make(); +path.addRect({ x: 0, y: 0, width: 100, height: 100 }); +return path.getBounds().width; +` ); expect(result).toBe(100); }); diff --git a/package/src/renderer/__tests__/setup.tsx b/package/src/renderer/__tests__/setup.tsx index 752e9e64e3..c3fb65ec67 100644 --- a/package/src/renderer/__tests__/setup.tsx +++ b/package/src/renderer/__tests__/setup.tsx @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/ban-types */ /* eslint-disable @typescript-eslint/no-explicit-any */ import fs from "fs"; import path from "path"; @@ -305,7 +304,7 @@ type Assets = Map; interface TestingSurface { init(): Promise; - eval(code: string, ctx: {}): Promise; + eval(code: string): Promise; draw(node: ReactNode, assets?: Assets): Promise; dispose(): void; width: number; @@ -326,9 +325,13 @@ class LocalSurface implements TestingSurface { dispose(): void {} - eval(code: string, ctx: {}): Promise { - // eslint-disable-next-line no-eval - return Promise.resolve(eval(`(function Main(){${code}})`).call(ctx)); + eval(code: string): Promise { + return Promise.resolve( + // eslint-disable-next-line no-eval + eval(`(function Main(){const {Skia} = this;${code}})`).call({ + Skia: global.SkiaApi, + }) + ); } draw(node: ReactNode): Promise { @@ -373,19 +376,14 @@ class RemoteSurface implements TestingSurface { } } - eval(code: string, ctx: { [key: string]: any }): Promise { + eval(code: string): Promise { this.assertInit(); return new Promise((resolve) => { const client = this.client!; client!.once("message", (raw: Buffer) => { resolve(JSON.parse(raw.toString())); }); - - const newCtx: { [key: string]: any } = {}; - Object.keys(ctx).forEach((key) => { - newCtx[key] = serializeSkOjects(ctx[key], new Map()); - }); - client!.send(JSON.stringify({ code, ctx: newCtx })); + client!.send(JSON.stringify({ code })); }); }