@shopify/react-native-skia 0.1.136 → 0.1.137
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -47
 - package/cpp/api/JsiSkMatrix.h +12 -0
 - package/lib/commonjs/renderer/components/Group.js +1 -1
 - package/lib/commonjs/renderer/components/Group.js.map +1 -1
 - package/lib/commonjs/renderer/processors/Transform.js +8 -15
 - package/lib/commonjs/renderer/processors/Transform.js.map +1 -1
 - package/lib/commonjs/skia/types/Matrix.js +17 -2
 - package/lib/commonjs/skia/types/Matrix.js.map +1 -1
 - package/lib/commonjs/skia/web/JsiSkMatrix.js +4 -0
 - package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
 - package/lib/commonjs/views/SkiaView.web.js +8 -8
 - package/lib/commonjs/views/SkiaView.web.js.map +1 -1
 - package/lib/commonjs/web/LoadSkiaWeb.js +25 -0
 - package/lib/commonjs/web/LoadSkiaWeb.js.map +1 -0
 - package/lib/commonjs/web/WithSkiaWeb.js +38 -0
 - package/lib/commonjs/web/WithSkiaWeb.js.map +1 -0
 - package/lib/commonjs/web/index.js +22 -12
 - package/lib/commonjs/web/index.js.map +1 -1
 - package/lib/module/renderer/components/Group.js +1 -1
 - package/lib/module/renderer/components/Group.js.map +1 -1
 - package/lib/module/renderer/processors/Transform.js +8 -15
 - package/lib/module/renderer/processors/Transform.js.map +1 -1
 - package/lib/module/skia/types/Matrix.js +11 -1
 - package/lib/module/skia/types/Matrix.js.map +1 -1
 - package/lib/module/skia/web/JsiSkMatrix.js +4 -0
 - package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
 - package/lib/module/views/SkiaView.web.js +8 -8
 - package/lib/module/views/SkiaView.web.js.map +1 -1
 - package/lib/module/web/LoadSkiaWeb.js +12 -0
 - package/lib/module/web/LoadSkiaWeb.js.map +1 -0
 - package/lib/module/web/WithSkiaWeb.js +22 -0
 - package/lib/module/web/WithSkiaWeb.js.map +1 -0
 - package/lib/module/web/index.js +2 -9
 - package/lib/module/web/index.js.map +1 -1
 - package/lib/typescript/src/renderer/processors/Transform.d.ts +2 -2
 - package/lib/typescript/src/skia/types/Matrix.d.ts +5 -1
 - package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +1 -0
 - package/lib/typescript/src/views/SkiaView.web.d.ts +2 -2
 - package/lib/typescript/src/web/LoadSkiaWeb.d.ts +6 -0
 - package/lib/typescript/src/web/WithSkiaWeb.d.ts +10 -0
 - package/lib/typescript/src/web/index.d.ts +2 -5
 - package/package.json +5 -1
 - package/scripts/setup-canvaskit.js +74 -0
 - package/src/renderer/components/Group.tsx +1 -1
 - package/src/renderer/processors/Transform.ts +7 -10
 - package/src/skia/types/Matrix.ts +18 -2
 - package/src/skia/web/JsiSkMatrix.ts +4 -0
 - package/src/views/SkiaView.web.tsx +8 -8
 - package/src/web/LoadSkiaWeb.tsx +18 -0
 - package/src/web/WithSkiaWeb.tsx +32 -0
 - package/src/web/index.ts +2 -15
 
| 
         @@ -52,7 +52,7 @@ export class SkiaView extends React.Component< 
     | 
|
| 
       52 
52 
     | 
    
         
             
                      // Get canvas and repaint
         
     | 
| 
       53 
53 
     | 
    
         
             
                      if (this._surface) {
         
     | 
| 
       54 
54 
     | 
    
         
             
                        this._canvas = this._surface.getCanvas();
         
     | 
| 
       55 
     | 
    
         
            -
                        this. 
     | 
| 
      
 55 
     | 
    
         
            +
                        this.redraw();
         
     | 
| 
       56 
56 
     | 
    
         
             
                      }
         
     | 
| 
       57 
57 
     | 
    
         
             
                    }
         
     | 
| 
       58 
58 
     | 
    
         
             
                  }
         
     | 
| 
         @@ -61,7 +61,7 @@ export class SkiaView extends React.Component< 
     | 
|
| 
       61 
61 
     | 
    
         | 
| 
       62 
62 
     | 
    
         
             
              componentDidMount() {
         
     | 
| 
       63 
63 
     | 
    
         
             
                // Start render loop
         
     | 
| 
       64 
     | 
    
         
            -
                this. 
     | 
| 
      
 64 
     | 
    
         
            +
                this.tick();
         
     | 
| 
       65 
65 
     | 
    
         
             
              }
         
     | 
| 
       66 
66 
     | 
    
         | 
| 
       67 
67 
     | 
    
         
             
              componentWillUnmount() {
         
     | 
| 
         @@ -83,7 +83,7 @@ export class SkiaView extends React.Component< 
     | 
|
| 
       83 
83 
     | 
    
         
             
              /**
         
     | 
| 
       84 
84 
     | 
    
         
             
               * Sends a redraw request to the native SkiaView.
         
     | 
| 
       85 
85 
     | 
    
         
             
               */
         
     | 
| 
       86 
     | 
    
         
            -
              private  
     | 
| 
      
 86 
     | 
    
         
            +
              private tick() {
         
     | 
| 
       87 
87 
     | 
    
         
             
                if (this._mode === "continuous" || this._redrawRequests > 0) {
         
     | 
| 
       88 
88 
     | 
    
         
             
                  this._redrawRequests = 0;
         
     | 
| 
       89 
89 
     | 
    
         
             
                  if (
         
     | 
| 
         @@ -106,11 +106,11 @@ export class SkiaView extends React.Component< 
     | 
|
| 
       106 
106 
     | 
    
         
             
                }
         
     | 
| 
       107 
107 
     | 
    
         
             
                // Always request a new redraw as long as we're not unmounted
         
     | 
| 
       108 
108 
     | 
    
         
             
                if (!this._unmounted) {
         
     | 
| 
       109 
     | 
    
         
            -
                  requestAnimationFrame(this. 
     | 
| 
      
 109 
     | 
    
         
            +
                  requestAnimationFrame(this.tick.bind(this));
         
     | 
| 
       110 
110 
     | 
    
         
             
                }
         
     | 
| 
       111 
111 
     | 
    
         
             
              }
         
     | 
| 
       112 
112 
     | 
    
         | 
| 
       113 
     | 
    
         
            -
              public  
     | 
| 
      
 113 
     | 
    
         
            +
              public redraw() {
         
     | 
| 
       114 
114 
     | 
    
         
             
                this._redrawRequests++;
         
     | 
| 
       115 
115 
     | 
    
         
             
              }
         
     | 
| 
       116 
116 
     | 
    
         | 
| 
         @@ -125,7 +125,7 @@ export class SkiaView extends React.Component< 
     | 
|
| 
       125 
125 
     | 
    
         
             
               */
         
     | 
| 
       126 
126 
     | 
    
         
             
              public setDrawMode(mode: DrawMode) {
         
     | 
| 
       127 
127 
     | 
    
         
             
                this._mode = mode;
         
     | 
| 
       128 
     | 
    
         
            -
                this. 
     | 
| 
      
 128 
     | 
    
         
            +
                this.tick();
         
     | 
| 
       129 
129 
     | 
    
         
             
              }
         
     | 
| 
       130 
130 
     | 
    
         | 
| 
       131 
131 
     | 
    
         
             
              /**
         
     | 
| 
         @@ -140,7 +140,7 @@ export class SkiaView extends React.Component< 
     | 
|
| 
       140 
140 
     | 
    
         
             
                _values.forEach((v) => {
         
     | 
| 
       141 
141 
     | 
    
         
             
                  this._unsubscriptions.push(
         
     | 
| 
       142 
142 
     | 
    
         
             
                    v.addListener(() => {
         
     | 
| 
       143 
     | 
    
         
            -
                      this. 
     | 
| 
      
 143 
     | 
    
         
            +
                      this.redraw();
         
     | 
| 
       144 
144 
     | 
    
         
             
                    })
         
     | 
| 
       145 
145 
     | 
    
         
             
                  );
         
     | 
| 
       146 
146 
     | 
    
         
             
                });
         
     | 
| 
         @@ -155,7 +155,7 @@ export class SkiaView extends React.Component< 
     | 
|
| 
       155 
155 
     | 
    
         
             
                  type: touchType,
         
     | 
| 
       156 
156 
     | 
    
         
             
                  timestamp: Date.now(),
         
     | 
| 
       157 
157 
     | 
    
         
             
                });
         
     | 
| 
       158 
     | 
    
         
            -
                this. 
     | 
| 
      
 158 
     | 
    
         
            +
                this.redraw();
         
     | 
| 
       159 
159 
     | 
    
         
             
              }
         
     | 
| 
       160 
160 
     | 
    
         | 
| 
       161 
161 
     | 
    
         
             
              handleTouchStart(evt: PointerEvent) {
         
     | 
| 
         @@ -0,0 +1,18 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
         
     | 
| 
      
 2 
     | 
    
         
            +
            // @ts-expect-error
         
     | 
| 
      
 3 
     | 
    
         
            +
            import CanvasKitInit from "canvaskit-wasm/bin/full/canvaskit";
         
     | 
| 
      
 4 
     | 
    
         
            +
            import type { CanvasKit as CanvasKitType } from "canvaskit-wasm";
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            declare global {
         
     | 
| 
      
 7 
     | 
    
         
            +
              var CanvasKit: CanvasKitType;
         
     | 
| 
      
 8 
     | 
    
         
            +
            }
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            export const LoadSkiaWeb = async () => {
         
     | 
| 
      
 11 
     | 
    
         
            +
              const CanvasKit = await CanvasKitInit();
         
     | 
| 
      
 12 
     | 
    
         
            +
              // The CanvasKit API is stored on the global object and used
         
     | 
| 
      
 13 
     | 
    
         
            +
              // to create the JsiSKApi in the Skia.web.ts file.
         
     | 
| 
      
 14 
     | 
    
         
            +
              global.CanvasKit = CanvasKit;
         
     | 
| 
      
 15 
     | 
    
         
            +
            };
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            // We keep this function for backward compatibility
         
     | 
| 
      
 18 
     | 
    
         
            +
            export const LoadSkia = LoadSkiaWeb;
         
     | 
| 
         @@ -0,0 +1,32 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            import type { ComponentProps, ComponentType } from "react";
         
     | 
| 
      
 2 
     | 
    
         
            +
            import React, { useMemo, lazy, Suspense } from "react";
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { Platform } from "react-native";
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            import { LoadSkiaWeb } from "./LoadSkiaWeb";
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            interface WithSkiaProps {
         
     | 
| 
      
 8 
     | 
    
         
            +
              fallback: ComponentProps<typeof Suspense>["fallback"];
         
     | 
| 
      
 9 
     | 
    
         
            +
              getComponent: () => Promise<{ default: ComponentType }>;
         
     | 
| 
      
 10 
     | 
    
         
            +
            }
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            export const WithSkiaWeb = ({ getComponent, fallback }: WithSkiaProps) => {
         
     | 
| 
      
 13 
     | 
    
         
            +
              const Inner = useMemo(
         
     | 
| 
      
 14 
     | 
    
         
            +
                () =>
         
     | 
| 
      
 15 
     | 
    
         
            +
                  lazy(async () => {
         
     | 
| 
      
 16 
     | 
    
         
            +
                    if (Platform.OS === "web") {
         
     | 
| 
      
 17 
     | 
    
         
            +
                      await LoadSkiaWeb();
         
     | 
| 
      
 18 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 19 
     | 
    
         
            +
                      console.warn(
         
     | 
| 
      
 20 
     | 
    
         
            +
                        "<WithSkiaWeb /> is only necessary on web. Consider not using on native."
         
     | 
| 
      
 21 
     | 
    
         
            +
                      );
         
     | 
| 
      
 22 
     | 
    
         
            +
                    }
         
     | 
| 
      
 23 
     | 
    
         
            +
                    return getComponent();
         
     | 
| 
      
 24 
     | 
    
         
            +
                  }),
         
     | 
| 
      
 25 
     | 
    
         
            +
                [getComponent]
         
     | 
| 
      
 26 
     | 
    
         
            +
              );
         
     | 
| 
      
 27 
     | 
    
         
            +
              return (
         
     | 
| 
      
 28 
     | 
    
         
            +
                <Suspense fallback={fallback}>
         
     | 
| 
      
 29 
     | 
    
         
            +
                  <Inner />
         
     | 
| 
      
 30 
     | 
    
         
            +
                </Suspense>
         
     | 
| 
      
 31 
     | 
    
         
            +
              );
         
     | 
| 
      
 32 
     | 
    
         
            +
            };
         
     | 
    
        package/src/web/index.ts
    CHANGED
    
    | 
         @@ -1,15 +1,2 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            import CanvasKitInit from "canvaskit-wasm/bin/full/canvaskit";
         
     | 
| 
       4 
     | 
    
         
            -
            import type { CanvasKit as CanvasKitType } from "canvaskit-wasm";
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            declare global {
         
     | 
| 
       7 
     | 
    
         
            -
              var CanvasKit: CanvasKitType;
         
     | 
| 
       8 
     | 
    
         
            -
            }
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
            export const LoadSkia = async () => {
         
     | 
| 
       11 
     | 
    
         
            -
              const CanvasKit = await CanvasKitInit();
         
     | 
| 
       12 
     | 
    
         
            -
              // The CanvasKit API is stored on the global object and used
         
     | 
| 
       13 
     | 
    
         
            -
              // to create the JsiSKApi in the Skia.web.ts file.
         
     | 
| 
       14 
     | 
    
         
            -
              global.CanvasKit = CanvasKit;
         
     | 
| 
       15 
     | 
    
         
            -
            };
         
     | 
| 
      
 1 
     | 
    
         
            +
            export * from "./LoadSkiaWeb";
         
     | 
| 
      
 2 
     | 
    
         
            +
            export * from "./WithSkiaWeb";
         
     |