@shopify/react-native-skia 0.1.120 → 0.1.123

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. package/android/CMakeLists.txt +33 -17
  2. package/android/build.gradle +81 -34
  3. package/android/cpp/jni/JniSkiaDrawView.cpp +14 -71
  4. package/android/cpp/jni/JniSkiaManager.cpp +1 -1
  5. package/android/cpp/jni/include/JniSkiaDrawView.h +18 -22
  6. package/android/cpp/jni/include/JniSkiaManager.h +4 -4
  7. package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +68 -0
  8. package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +48 -0
  9. package/android/cpp/{jni/include/JniPlatformContextWrapper.h → rnskia-android/RNSkPlatformContextImpl.h} +4 -4
  10. package/android/cpp/{jni → rnskia-android}/SkiaOpenGLRenderer.cpp +39 -54
  11. package/android/cpp/{jni/include → rnskia-android}/SkiaOpenGLRenderer.h +2 -31
  12. package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +1 -1
  13. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaViewManager.java +1 -1
  14. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +21 -28
  15. package/cpp/api/JsiSkApi.h +2 -0
  16. package/cpp/api/JsiSkColor.h +49 -0
  17. package/cpp/api/JsiSkPath.h +31 -2
  18. package/cpp/api/JsiSkPathFactory.h +96 -1
  19. package/cpp/api/third_party/CSSColorParser.h +324 -0
  20. package/cpp/rnskia/RNSkAnimation.h +4 -7
  21. package/cpp/rnskia/RNSkDrawView.cpp +77 -116
  22. package/cpp/rnskia/RNSkDrawView.h +5 -35
  23. package/cpp/rnskia/RNSkJsiViewApi.h +8 -5
  24. package/cpp/rnskia/RNSkManager.cpp +2 -2
  25. package/cpp/rnskia/RNSkManager.h +2 -2
  26. package/cpp/rnskia/RNSkPlatformContext.h +1 -1
  27. package/cpp/rnskia/values/RNSkClockValue.h +19 -11
  28. package/cpp/rnskia/values/RNSkDerivedValue.h +1 -1
  29. package/cpp/rnskia/values/RNSkReadonlyValue.h +15 -15
  30. package/cpp/utils/RNSkTimingInfo.h +13 -1
  31. package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +5 -7
  32. package/ios/RNSkia-iOS/RNSkDrawViewImpl.mm +25 -10
  33. package/ios/RNSkia-iOS/SkiaDrawView.mm +21 -15
  34. package/lib/commonjs/renderer/Canvas.js +3 -3
  35. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  36. package/lib/commonjs/renderer/components/Paint.js +1 -1
  37. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  38. package/lib/commonjs/renderer/components/shapes/Path.js +10 -2
  39. package/lib/commonjs/renderer/components/shapes/Path.js.map +1 -1
  40. package/lib/commonjs/renderer/nodes/Node.js +3 -3
  41. package/lib/commonjs/renderer/nodes/Node.js.map +1 -1
  42. package/lib/commonjs/renderer/processors/Paint.js +6 -1
  43. package/lib/commonjs/renderer/processors/Paint.js.map +1 -1
  44. package/lib/commonjs/skia/Color.js +3 -25
  45. package/lib/commonjs/skia/Color.js.map +1 -1
  46. package/lib/commonjs/skia/Image/Image.js.map +1 -1
  47. package/lib/commonjs/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
  48. package/lib/commonjs/skia/Paint/Paint.js +13 -1
  49. package/lib/commonjs/skia/Paint/Paint.js.map +1 -1
  50. package/lib/commonjs/skia/Paint/usePaint.js +2 -4
  51. package/lib/commonjs/skia/Paint/usePaint.js.map +1 -1
  52. package/lib/commonjs/skia/Path/Path.js +13 -1
  53. package/lib/commonjs/skia/Path/Path.js.map +1 -1
  54. package/lib/commonjs/skia/Shader/Shader.js.map +1 -1
  55. package/lib/commonjs/skia/Skia.js +43 -3
  56. package/lib/commonjs/skia/Skia.js.map +1 -1
  57. package/lib/module/renderer/Canvas.js +2 -2
  58. package/lib/module/renderer/Canvas.js.map +1 -1
  59. package/lib/module/renderer/components/Paint.js +2 -2
  60. package/lib/module/renderer/components/Paint.js.map +1 -1
  61. package/lib/module/renderer/components/shapes/Path.js +10 -3
  62. package/lib/module/renderer/components/shapes/Path.js.map +1 -1
  63. package/lib/module/renderer/nodes/Node.js +3 -3
  64. package/lib/module/renderer/nodes/Node.js.map +1 -1
  65. package/lib/module/renderer/processors/Paint.js +6 -1
  66. package/lib/module/renderer/processors/Paint.js.map +1 -1
  67. package/lib/module/skia/Color.js +2 -21
  68. package/lib/module/skia/Color.js.map +1 -1
  69. package/lib/module/skia/Image/Image.js.map +1 -1
  70. package/lib/module/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
  71. package/lib/module/skia/Paint/Paint.js +6 -0
  72. package/lib/module/skia/Paint/Paint.js.map +1 -1
  73. package/lib/module/skia/Paint/usePaint.js +2 -3
  74. package/lib/module/skia/Paint/usePaint.js.map +1 -1
  75. package/lib/module/skia/Path/Path.js +11 -0
  76. package/lib/module/skia/Path/Path.js.map +1 -1
  77. package/lib/module/skia/Shader/Shader.js.map +1 -1
  78. package/lib/module/skia/Skia.js +45 -2
  79. package/lib/module/skia/Skia.js.map +1 -1
  80. package/lib/typescript/src/renderer/components/shapes/Path.d.ts +3 -1
  81. package/lib/typescript/src/renderer/processors/Paint.d.ts +2 -1
  82. package/lib/typescript/src/skia/Color.d.ts +0 -1
  83. package/lib/typescript/src/skia/Image/Image.d.ts +3 -3
  84. package/lib/typescript/src/skia/ImageFilter/ImageFilterFactory.d.ts +2 -2
  85. package/lib/typescript/src/skia/Paint/Paint.d.ts +3 -2
  86. package/lib/typescript/src/skia/Path/Path.d.ts +13 -0
  87. package/lib/typescript/src/skia/Path/PathFactory.d.ts +7 -1
  88. package/lib/typescript/src/skia/Picture/Picture.d.ts +2 -2
  89. package/lib/typescript/src/skia/RuntimeEffect/RuntimeEffect.d.ts +3 -3
  90. package/lib/typescript/src/skia/Shader/Shader.d.ts +2 -2
  91. package/lib/typescript/src/skia/Shader/ShaderFactory.d.ts +9 -9
  92. package/lib/typescript/src/skia/Skia.d.ts +5 -3
  93. package/package.json +1 -1
  94. package/scripts/install-npm.js +1 -1
  95. package/src/renderer/Canvas.tsx +2 -2
  96. package/src/renderer/components/Paint.tsx +2 -2
  97. package/src/renderer/components/shapes/Path.tsx +12 -4
  98. package/src/renderer/nodes/Node.ts +3 -3
  99. package/src/renderer/processors/Paint.ts +5 -0
  100. package/src/skia/Color.ts +3 -20
  101. package/src/skia/Image/Image.ts +3 -3
  102. package/src/skia/ImageFilter/ImageFilterFactory.ts +2 -2
  103. package/src/skia/Paint/Paint.ts +9 -2
  104. package/src/skia/Paint/usePaint.ts +2 -4
  105. package/src/skia/Path/Path.ts +16 -0
  106. package/src/skia/Path/PathFactory.ts +8 -1
  107. package/src/skia/Picture/Picture.ts +2 -2
  108. package/src/skia/RuntimeEffect/RuntimeEffect.ts +4 -4
  109. package/src/skia/Shader/Shader.ts +2 -2
  110. package/src/skia/Shader/ShaderFactory.ts +9 -9
  111. package/src/skia/Skia.ts +47 -3
@@ -1 +1 @@
1
- {"version":3,"sources":["Skia.ts"],"names":["processColor","Skia","Typeface","SkiaApi","MaskFilter","RuntimeEffect","Shader","ImageFilter","PathEffect","Data","SVG","FontMgr","TextBlob","Matrix","Font","Point","XYWHRect","RRectXY","Paint","PictureRecorder","Picture","Path","ColorFilter","ContourMeasureIter","Color","color","RSXform","MakeSurface","Surface","Make","MakeImageFromEncoded","Image","MakeImage","MakeVertices"],"mappings":"AAAA;AAcA,SAASA,YAAT,QAA6B,SAA7B;AAUA,OAAO,eAAP;;AAiEA;AACA;AACA;AACA,OAAO,MAAMC,IAAI,GAAG;AAClB;AACAC,EAAAA,QAAQ,EAAEC,OAAO,CAACD,QAFA;AAGlBE,EAAAA,UAAU,EAAED,OAAO,CAACC,UAHF;AAIlBC,EAAAA,aAAa,EAAEF,OAAO,CAACE,aAJL;AAKlBC,EAAAA,MAAM,EAAEH,OAAO,CAACG,MALE;AAMlBC,EAAAA,WAAW,EAAEJ,OAAO,CAACI,WANH;AAOlBC,EAAAA,UAAU,EAAEL,OAAO,CAACK,UAPF;AAQlBC,EAAAA,IAAI,EAAEN,OAAO,CAACM,IARI;AASlBC,EAAAA,GAAG,EAAEP,OAAO,CAACO,GATK;AAUlBC,EAAAA,OAAO,EAAER,OAAO,CAACQ,OAVC;AAWlBC,EAAAA,QAAQ,EAAET,OAAO,CAACS,QAXA;AAYlB;AACAC,EAAAA,MAAM,EAAEV,OAAO,CAACU,MAbE;AAclBC,EAAAA,IAAI,EAAEX,OAAO,CAACW,IAdI;AAelBC,EAAAA,KAAK,EAAEZ,OAAO,CAACY,KAfG;AAgBlBC,EAAAA,QAAQ,EAAEb,OAAO,CAACa,QAhBA;AAiBlBC,EAAAA,OAAO,EAAEd,OAAO,CAACc,OAjBC;AAkBlBC,EAAAA,KAAK,EAAEf,OAAO,CAACe,KAlBG;AAmBlBC,EAAAA,eAAe,EAAEhB,OAAO,CAACgB,eAnBP;AAoBlBC,EAAAA,OAAO,EAAEjB,OAAO,CAACiB,OApBC;AAqBlBC,EAAAA,IAAI,EAAElB,OAAO,CAACkB,IArBI;AAsBlBC,EAAAA,WAAW,EAAEnB,OAAO,CAACmB,WAtBH;AAuBlBC,EAAAA,kBAAkB,EAAEpB,OAAO,CAACoB,kBAvBV;AAwBlB;AACAC,EAAAA,KAAK,EAAGC,KAAD,IAA+CzB,YAAY,CAACyB,KAAD,EAAQ,CAAR,CAzBhD;AA0BlBC,EAAAA,OAAO,EAAEvB,OAAO,CAACuB,OA1BC;AA2BlB;AACAC,EAAAA,WAAW,EAAExB,OAAO,CAACyB,OAAR,CAAgBC,IA5BX;AA6BlBC,EAAAA,oBAAoB,EAAE3B,OAAO,CAAC4B,KAAR,CAAcD,oBA7BlB;AA8BlBE,EAAAA,SAAS,EAAE7B,OAAO,CAAC4B,KAAR,CAAcC,SA9BP;AA+BlBC,EAAAA,YAAY,EAAE9B,OAAO,CAAC8B;AA/BJ,CAAb","sourcesContent":["/*global SkiaApi*/\nimport type { ImageFilterFactory } from \"./ImageFilter\";\nimport type { PathFactory } from \"./Path\";\nimport type { ColorFilterFactory } from \"./ColorFilter\";\nimport type { SkFont } from \"./Font\";\nimport type { SkTypeface, TypefaceFactory } from \"./Typeface\";\nimport type { ImageFactory } from \"./Image\";\nimport type { MaskFilterFactory } from \"./MaskFilter\";\nimport type { SkPaint } from \"./Paint\";\nimport type { SkRect } from \"./Rect\";\nimport type { SkRRect } from \"./RRect\";\nimport type { RuntimeEffectFactory } from \"./RuntimeEffect\";\nimport type { ShaderFactory } from \"./Shader\";\nimport type { SkColor } from \"./Color\";\nimport { processColor } from \"./Color\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { PathEffectFactory } from \"./PathEffect\";\nimport type { SkPoint } from \"./Point\";\nimport type { SkVertices, VertexMode } from \"./Vertices/Vertices\";\nimport type { DataFactory } from \"./Data\";\nimport type { SVGFactory } from \"./SVG\";\nimport type { TextBlobFactory } from \"./TextBlob\";\nimport type { FontMgrFactory } from \"./FontMgr/FontMgrFactory\";\nimport type { SurfaceFactory } from \"./Surface\";\nimport \"./NativeSetup\";\nimport type { SkRSXform } from \"./RSXform\";\nimport type { SkPath } from \"./Path/Path\";\nimport type { SkContourMeasureIter } from \"./ContourMeasure\";\nimport type { PictureFactory, SkPictureRecorder } from \"./Picture\";\n\n/**\n * Declares the interface for the native Skia API\n */\nexport interface Skia {\n Point: (x: number, y: number) => SkPoint;\n XYWHRect: (x: number, y: number, width: number, height: number) => SkRect;\n RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;\n RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;\n ContourMeasureIter: (\n path: SkPath,\n forceClosed: boolean,\n resScale: number\n ) => SkContourMeasureIter;\n Paint: () => SkPaint;\n PictureRecorder: () => SkPictureRecorder;\n Picture: PictureFactory;\n Path: PathFactory;\n Matrix: () => SkMatrix;\n ColorFilter: ColorFilterFactory;\n Font: (typeface?: SkTypeface, size?: number) => SkFont;\n Typeface: TypefaceFactory;\n MaskFilter: MaskFilterFactory;\n RuntimeEffect: RuntimeEffectFactory;\n ImageFilter: ImageFilterFactory;\n Shader: ShaderFactory;\n PathEffect: PathEffectFactory;\n /**\n * Returns an Vertices based on the given positions and optional parameters.\n * See SkVertices.h (especially the Builder) for more details.\n * @param mode\n * @param positions\n * @param textureCoordinates\n * @param colors - either a list of int colors or a flattened color array.\n * @param indices\n * @param isVolatile\n */\n MakeVertices(\n mode: VertexMode,\n positions: SkPoint[],\n textureCoordinates?: SkPoint[] | null,\n colors?: SkColor[],\n indices?: number[] | null,\n isVolatile?: boolean\n ): SkVertices;\n Data: DataFactory;\n Image: ImageFactory;\n SVG: SVGFactory;\n FontMgr: FontMgrFactory;\n TextBlob: TextBlobFactory;\n Surface: SurfaceFactory;\n}\n\n/**\n * Declares the SkiaApi as an available object in the global scope\n */\ndeclare global {\n var SkiaApi: Skia;\n}\n\n/**\n * Declares the implemented API with overrides.\n */\nexport const Skia = {\n // Factories\n Typeface: SkiaApi.Typeface,\n MaskFilter: SkiaApi.MaskFilter,\n RuntimeEffect: SkiaApi.RuntimeEffect,\n Shader: SkiaApi.Shader,\n ImageFilter: SkiaApi.ImageFilter,\n PathEffect: SkiaApi.PathEffect,\n Data: SkiaApi.Data,\n SVG: SkiaApi.SVG,\n FontMgr: SkiaApi.FontMgr,\n TextBlob: SkiaApi.TextBlob,\n // Constructors\n Matrix: SkiaApi.Matrix,\n Font: SkiaApi.Font,\n Point: SkiaApi.Point,\n XYWHRect: SkiaApi.XYWHRect,\n RRectXY: SkiaApi.RRectXY,\n Paint: SkiaApi.Paint,\n PictureRecorder: SkiaApi.PictureRecorder,\n Picture: SkiaApi.Picture,\n Path: SkiaApi.Path,\n ColorFilter: SkiaApi.ColorFilter,\n ContourMeasureIter: SkiaApi.ContourMeasureIter,\n // Here are constructors for data types which are represented as typed arrays in CanvasKit\n Color: (color: Parameters<typeof processColor>[0]) => processColor(color, 1),\n RSXform: SkiaApi.RSXform,\n // For the following methods the factory symmetry is broken to be comptatible with CanvasKit\n MakeSurface: SkiaApi.Surface.Make,\n MakeImageFromEncoded: SkiaApi.Image.MakeImageFromEncoded,\n MakeImage: SkiaApi.Image.MakeImage,\n MakeVertices: SkiaApi.MakeVertices,\n};\n"]}
1
+ {"version":3,"sources":["Skia.ts"],"names":["Platform","processColor","SkiaColor","cl","color","Skia","parseColorString","undefined","rnColor","console","warn","BLACK","OS","a","r","g","b","Typeface","SkiaApi","MaskFilter","RuntimeEffect","Shader","ImageFilter","PathEffect","Data","SVG","FontMgr","TextBlob","Matrix","Font","Point","XYWHRect","RRectXY","Paint","PictureRecorder","Picture","Path","ColorFilter","ContourMeasureIter","Color","RSXform","MakeSurface","Surface","Make","MakeImageFromEncoded","Image","MakeImage","MakeVertices"],"mappings":"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","sourcesContent":["import { Platform, processColor } from \"react-native\";\n\n/*global SkiaApi*/\nimport type { ImageFilterFactory } from \"./ImageFilter\";\nimport type { PathFactory } from \"./Path\";\nimport type { ColorFilterFactory } from \"./ColorFilter\";\nimport type { SkFont } from \"./Font\";\nimport type { SkTypeface, TypefaceFactory } from \"./Typeface\";\nimport type { ImageFactory } from \"./Image\";\nimport type { MaskFilterFactory } from \"./MaskFilter\";\nimport type { SkPaint } from \"./Paint\";\nimport type { SkRect } from \"./Rect\";\nimport type { SkRRect } from \"./RRect\";\nimport type { RuntimeEffectFactory } from \"./RuntimeEffect\";\nimport type { ShaderFactory } from \"./Shader\";\nimport type { SkMatrix } from \"./Matrix\";\nimport type { PathEffectFactory } from \"./PathEffect\";\nimport type { SkPoint } from \"./Point\";\nimport type { SkVertices, VertexMode } from \"./Vertices/Vertices\";\nimport type { DataFactory } from \"./Data\";\nimport type { SVGFactory } from \"./SVG\";\nimport type { TextBlobFactory } from \"./TextBlob\";\nimport type { FontMgrFactory } from \"./FontMgr/FontMgrFactory\";\nimport type { SurfaceFactory } from \"./Surface\";\nimport \"./NativeSetup\";\nimport type { SkRSXform } from \"./RSXform\";\nimport type { SkPath } from \"./Path/Path\";\nimport type { SkContourMeasureIter } from \"./ContourMeasure\";\nimport type { PictureFactory, SkPictureRecorder } from \"./Picture\";\nimport type { Color, SkColor } from \"./Color\";\n\n/*\n * Parse CSS colors\n */\nconst SkiaColor = (cl: Color) => {\n if (typeof cl === \"number\") {\n return cl;\n }\n const color = Skia.parseColorString(cl);\n if (color !== undefined) {\n return color;\n } else {\n // If the color is not recognized, we fallback to React Native\n let rnColor = processColor(cl);\n // 1. Neither Skia or RN could parse the color\n if (typeof rnColor !== \"number\") {\n console.warn(\"Skia couldn't parse the following color \" + cl);\n return BLACK;\n // 2. The color is recognized by RN but not by Skia\n } else {\n console.warn(\n \"Skia couldn't parse the following color \" +\n cl +\n \". The color parsing was delegated to React Native. Please file on issue with that color.\"\n );\n // On android we need to move the alpha byte to the start of the structure\n if (Platform.OS === \"android\") {\n rnColor = rnColor >>> 0;\n const a = (rnColor >> 24) & 0xff;\n const r = (rnColor >> 16) & 0xff;\n const g = (rnColor >> 8) & 0xff;\n const b = rnColor & 0xff;\n rnColor = ((a << 24) | (r << 16) | (g << 8) | b) >>> 0;\n }\n return rnColor;\n }\n }\n};\n\n/**\n * Declares the interface for the native Skia API\n */\nexport interface Skia {\n Point: (x: number, y: number) => SkPoint;\n XYWHRect: (x: number, y: number, width: number, height: number) => SkRect;\n RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;\n RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;\n Color: (color: Color) => SkColor;\n parseColorString: (color: string) => SkColor | undefined;\n ContourMeasureIter: (\n path: SkPath,\n forceClosed: boolean,\n resScale: number\n ) => SkContourMeasureIter;\n Paint: () => SkPaint;\n PictureRecorder: () => SkPictureRecorder;\n Picture: PictureFactory;\n Path: PathFactory;\n Matrix: () => SkMatrix;\n ColorFilter: ColorFilterFactory;\n Font: (typeface?: SkTypeface, size?: number) => SkFont;\n Typeface: TypefaceFactory;\n MaskFilter: MaskFilterFactory;\n RuntimeEffect: RuntimeEffectFactory;\n ImageFilter: ImageFilterFactory;\n Shader: ShaderFactory;\n PathEffect: PathEffectFactory;\n /**\n * Returns an Vertices based on the given positions and optional parameters.\n * See SkVertices.h (especially the Builder) for more details.\n * @param mode\n * @param positions\n * @param textureCoordinates\n * @param colors - either a list of int colors or a flattened color array.\n * @param indices\n * @param isVolatile\n */\n MakeVertices(\n mode: VertexMode,\n positions: SkPoint[],\n textureCoordinates?: SkPoint[] | null,\n colors?: SkColor[],\n indices?: number[] | null,\n isVolatile?: boolean\n ): SkVertices;\n Data: DataFactory;\n Image: ImageFactory;\n SVG: SVGFactory;\n FontMgr: FontMgrFactory;\n TextBlob: TextBlobFactory;\n Surface: SurfaceFactory;\n}\n\n/**\n * Declares the SkiaApi as an available object in the global scope\n */\ndeclare global {\n var SkiaApi: Skia;\n}\n\n/**\n * Declares the implemented API with overrides.\n */\nexport const Skia = {\n // Factories\n Typeface: SkiaApi.Typeface,\n MaskFilter: SkiaApi.MaskFilter,\n RuntimeEffect: SkiaApi.RuntimeEffect,\n Shader: SkiaApi.Shader,\n ImageFilter: SkiaApi.ImageFilter,\n PathEffect: SkiaApi.PathEffect,\n Data: SkiaApi.Data,\n SVG: SkiaApi.SVG,\n FontMgr: SkiaApi.FontMgr,\n TextBlob: SkiaApi.TextBlob,\n // Constructors\n Matrix: SkiaApi.Matrix,\n Font: SkiaApi.Font,\n Point: SkiaApi.Point,\n XYWHRect: SkiaApi.XYWHRect,\n RRectXY: SkiaApi.RRectXY,\n Paint: SkiaApi.Paint,\n PictureRecorder: SkiaApi.PictureRecorder,\n Picture: SkiaApi.Picture,\n Path: SkiaApi.Path,\n ColorFilter: SkiaApi.ColorFilter,\n ContourMeasureIter: SkiaApi.ContourMeasureIter,\n // Here are constructors for data types which are represented as typed arrays in CanvasKit\n Color: SkiaColor,\n parseColorString: SkiaApi.parseColorString,\n RSXform: SkiaApi.RSXform,\n // For the following methods the factory symmetry is broken to be comptatible with CanvasKit\n MakeSurface: SkiaApi.Surface.Make,\n MakeImageFromEncoded: SkiaApi.Image.MakeImageFromEncoded,\n MakeImage: SkiaApi.Image.MakeImage,\n MakeVertices: SkiaApi.MakeVertices,\n};\n\nconst BLACK = Skia.parseColorString(\"black\")!;\n"]}
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
- import type { CustomPaintProps, AnimatedProps, PathDef } from "../../processors";
2
+ import type { CustomPaintProps, AnimatedProps, PathDef, SkEnum } from "../../processors";
3
+ import { FillType } from "../../../skia";
3
4
  interface StrokeOpts {
4
5
  width?: number;
5
6
  strokeMiterlimit?: number;
@@ -10,6 +11,7 @@ export interface PathProps extends CustomPaintProps {
10
11
  start: number;
11
12
  end: number;
12
13
  stroke?: StrokeOpts;
14
+ fillType?: SkEnum<typeof FillType>;
13
15
  }
14
16
  export declare const Path: {
15
17
  (props: AnimatedProps<PathProps>): JSX.Element;
@@ -16,6 +16,7 @@ export interface CustomPaintProps extends ChildrenProps {
16
16
  strokeCap?: SkEnum<typeof StrokeCap>;
17
17
  strokeMiter?: number;
18
18
  opacity?: number;
19
+ antiAlias?: boolean;
19
20
  }
20
21
  export declare const enumKey: <K extends string>(k: K) => Capitalize<K>;
21
- export declare const processPaint: (paint: SkPaint, currentOpacity: number, { paint: paintRef, color, blendMode, style, strokeWidth, strokeJoin, strokeCap, strokeMiter, opacity, }: CustomPaintProps, children: DeclarationResult[]) => SkPaint;
22
+ export declare const processPaint: (paint: SkPaint, currentOpacity: number, { paint: paintRef, color, blendMode, style, strokeWidth, strokeJoin, strokeCap, strokeMiter, opacity, antiAlias, }: CustomPaintProps, children: DeclarationResult[]) => SkPaint;
@@ -5,6 +5,5 @@ export declare const red: (c: number) => number;
5
5
  export declare const green: (c: number) => number;
6
6
  export declare const blue: (c: number) => number;
7
7
  export declare const rgbaColor: (r: number, g: number, b: number, af: number) => number;
8
- export declare const processColorAsInt: (color?: string | number | undefined) => SkColor;
9
8
  export declare const processColor: (cl: Color, currentOpacity: number) => number;
10
9
  export declare const processColorAsUnitArray: (cl: Color, currentOpacity: number) => readonly [number, number, number, number];
@@ -1,5 +1,5 @@
1
1
  import type { TileMode } from "../ImageFilter";
2
- import type { IShader } from "../Shader";
2
+ import type { SkShader } from "../Shader";
3
3
  import type { SkMatrix } from "../Matrix";
4
4
  import type { SkJSIInstance } from "../JsiInstance";
5
5
  export declare enum FilterMode {
@@ -34,7 +34,7 @@ export interface SkImage extends SkJSIInstance<"Image"> {
34
34
  * calculated with makeCopyWithDefaultMipmaps;
35
35
  * @param localMatrix
36
36
  */
37
- makeShaderOptions(tx: TileMode, ty: TileMode, fm: FilterMode, mm: MipmapMode, localMatrix?: SkMatrix): IShader;
37
+ makeShaderOptions(tx: TileMode, ty: TileMode, fm: FilterMode, mm: MipmapMode, localMatrix?: SkMatrix): SkShader;
38
38
  /**
39
39
  * Returns this image as a shader with the specified tiling. It will use cubic sampling.
40
40
  * @param tx - tile mode in the x direction.
@@ -43,7 +43,7 @@ export interface SkImage extends SkJSIInstance<"Image"> {
43
43
  * @param C - See CubicResampler in SkSamplingOptions.h for more information
44
44
  * @param localMatrix
45
45
  */
46
- makeShaderCubic(tx: TileMode, ty: TileMode, B: number, C: number, localMatrix?: SkMatrix): IShader;
46
+ makeShaderCubic(tx: TileMode, ty: TileMode, B: number, C: number, localMatrix?: SkMatrix): SkShader;
47
47
  /** Encodes Image pixels, returning result as UInt8Array. Returns existing
48
48
  encoded data if present; otherwise, SkImage is encoded with
49
49
  SkEncodedImageFormat::kPNG. Skia must be built with SK_ENCODE_PNG to encode
@@ -1,6 +1,6 @@
1
1
  import type { SkColor } from "../Color";
2
2
  import type { SkColorFilter } from "../ColorFilter/ColorFilter";
3
- import type { IShader } from "../Shader/Shader";
3
+ import type { SkShader } from "../Shader/Shader";
4
4
  import type { SkRect } from "../Rect";
5
5
  import type { BlendMode } from "../Paint/BlendMode";
6
6
  import type { SkImageFilter, TileMode } from "./ImageFilter";
@@ -35,7 +35,7 @@ export interface ImageFilterFactory {
35
35
  * @param shader - The Shader to be transformed
36
36
  * @param input - if null, it will use the dynamic source image
37
37
  */
38
- MakeShader(shader: IShader, input: SkImageFilter | null): SkImageFilter;
38
+ MakeShader(shader: SkShader, input: SkImageFilter | null): SkImageFilter;
39
39
  /**
40
40
  * Create a filter that blurs its input by the separate X and Y sigmas. The provided tile mode
41
41
  * is used when the blur kernel goes outside the input image.
@@ -1,7 +1,7 @@
1
1
  import type { SkImageFilter } from "../ImageFilter";
2
2
  import type { IMaskFilter } from "../MaskFilter";
3
3
  import type { SkColorFilter } from "../ColorFilter";
4
- import type { IShader } from "../Shader";
4
+ import type { SkShader } from "../Shader";
5
5
  import type { SkColor } from "../Color";
6
6
  import type { IPathEffect } from "../PathEffect";
7
7
  import type { SkJSIInstance } from "../JsiInstance";
@@ -20,6 +20,7 @@ export declare enum StrokeJoin {
20
20
  Miter = 1,
21
21
  Round = 2
22
22
  }
23
+ export declare const SkiaPaint: () => SkPaint;
23
24
  export declare const isPaint: (obj: SkJSIInstance<string> | null) => obj is SkPaint;
24
25
  export interface SkPaint extends SkJSIInstance<"Paint"> {
25
26
  /**
@@ -98,7 +99,7 @@ export interface SkPaint extends SkJSIInstance<"Paint"> {
98
99
  * Sets the current shader, replacing the existing one if there was one.
99
100
  * @param shader
100
101
  */
101
- setShader(shader: IShader | null): void;
102
+ setShader(shader: SkShader | null): void;
102
103
  /**
103
104
  * Sets the geometry drawn at the beginning and end of strokes.
104
105
  * @param cap
@@ -33,6 +33,15 @@ export declare enum PathOp {
33
33
  XOR = 3,
34
34
  ReverseDifference = 4
35
35
  }
36
+ export declare enum PathVerb {
37
+ Move = 0,
38
+ Line = 1,
39
+ Quad = 2,
40
+ Conic = 3,
41
+ Cubic = 4,
42
+ Close = 5
43
+ }
44
+ export declare type PathCommand = number[];
36
45
  export declare const isPath: (obj: SkJSIInstance<string> | null) => obj is SkPath;
37
46
  export interface SkPath extends SkJSIInstance<"Path"> {
38
47
  /**
@@ -440,4 +449,8 @@ export interface SkPath extends SkJSIInstance<"Path"> {
440
449
  *
441
450
  * */
442
451
  isInterpolatable(compare: SkPath): boolean;
452
+ /**
453
+ * Serializes the contents of this path as a series of commands.
454
+ */
455
+ toCmds(): PathCommand[];
443
456
  }
@@ -1,4 +1,4 @@
1
- import type { SkPath, PathOp } from "./Path";
1
+ import type { SkPath, PathOp, PathCommand } from "./Path";
2
2
  export interface PathFactory {
3
3
  Make(): SkPath;
4
4
  /**
@@ -15,4 +15,10 @@ export interface PathFactory {
15
15
  * @param op
16
16
  */
17
17
  MakeFromOp(one: SkPath, two: SkPath, op: PathOp): SkPath | null;
18
+ /**
19
+ * Creates a new path from the given list of path commands. If this fails, null will be
20
+ * returned instead.
21
+ * @param cmds
22
+ */
23
+ MakeFromCmds(cmds: PathCommand[]): SkPath | null;
18
24
  }
@@ -2,7 +2,7 @@ import type { InputColorMatrix } from "../ColorFilter";
2
2
  import type { FilterMode } from "../Image";
3
3
  import type { TileMode } from "../ImageFilter";
4
4
  import type { SkRect } from "../Rect";
5
- import type { IShader } from "../Shader";
5
+ import type { SkShader } from "../Shader";
6
6
  export interface SkPicture {
7
7
  /**
8
8
  * Returns a new shader that will draw with this picture.
@@ -17,7 +17,7 @@ export interface SkPicture {
17
17
  * and cropping). If null, the tile rect is considered equal to the picture
18
18
  * bounds.
19
19
  */
20
- makeShader(tmx: TileMode, tmy: TileMode, mode: FilterMode, localMatrix?: InputColorMatrix, tileRect?: SkRect): IShader;
20
+ makeShader(tmx: TileMode, tmy: TileMode, mode: FilterMode, localMatrix?: InputColorMatrix, tileRect?: SkRect): SkShader;
21
21
  /**
22
22
  * Returns the serialized format of this SkPicture. The format may change at anytime and
23
23
  * no promises are made for backwards or forward compatibility.
@@ -1,4 +1,4 @@
1
- import type { IShader } from "../Shader";
1
+ import type { SkShader } from "../Shader";
2
2
  import type { SkJSIInstance } from "../JsiInstance";
3
3
  import type { SkMatrix } from "../Matrix";
4
4
  export interface SkSLUniform {
@@ -15,7 +15,7 @@ export interface IRuntimeEffect extends SkJSIInstance<"RuntimeEffect"> {
15
15
  * @param isOpaque
16
16
  * @param localMatrix
17
17
  */
18
- makeShader(uniforms: number[], isOpaque?: boolean, localMatrix?: SkMatrix): IShader;
18
+ makeShader(uniforms: number[], isOpaque?: boolean, localMatrix?: SkMatrix): SkShader;
19
19
  /**
20
20
  * Returns a shader executed using the given uniform data and the children as inputs.
21
21
  * @param uniforms
@@ -23,7 +23,7 @@ export interface IRuntimeEffect extends SkJSIInstance<"RuntimeEffect"> {
23
23
  * @param children
24
24
  * @param localMatrix
25
25
  */
26
- makeShaderWithChildren(uniforms: number[], isOpaque?: boolean, children?: IShader[], localMatrix?: SkMatrix): IShader;
26
+ makeShaderWithChildren(uniforms: number[], isOpaque?: boolean, children?: SkShader[], localMatrix?: SkMatrix): SkShader;
27
27
  /**
28
28
  * Returns the nth uniform from the effect.
29
29
  * @param index
@@ -1,3 +1,3 @@
1
1
  import type { SkJSIInstance } from "../JsiInstance";
2
- export declare const isShader: (obj: SkJSIInstance<string> | null) => obj is IShader;
3
- export declare type IShader = SkJSIInstance<"Shader">;
2
+ export declare const isShader: (obj: SkJSIInstance<string> | null) => obj is SkShader;
3
+ export declare type SkShader = SkJSIInstance<"Shader">;
@@ -3,7 +3,7 @@ import type { SkPoint } from "../Point";
3
3
  import type { SkMatrix } from "../Matrix";
4
4
  import type { SkColor } from "../Color";
5
5
  import type { BlendMode } from "../Paint/BlendMode";
6
- import type { IShader } from "./Shader";
6
+ import type { SkShader } from "./Shader";
7
7
  export interface ShaderFactory {
8
8
  /**
9
9
  * Returns a shader that generates a linear gradient between the two specified points.
@@ -20,7 +20,7 @@ export interface ShaderFactory {
20
20
  * gradients will premultiply their colors first, and then interpolate
21
21
  * between them.
22
22
  */
23
- MakeLinearGradient(start: SkPoint, end: SkPoint, colors: SkColor[], pos: number[] | null, mode: TileMode, localMatrix?: SkMatrix, flags?: number): IShader;
23
+ MakeLinearGradient(start: SkPoint, end: SkPoint, colors: SkColor[], pos: number[] | null, mode: TileMode, localMatrix?: SkMatrix, flags?: number): SkShader;
24
24
  /**
25
25
  * Returns a shader that generates a radial gradient given the center and radius.
26
26
  * See SkGradientShader.h for more.
@@ -33,7 +33,7 @@ export interface ShaderFactory {
33
33
  * @param localMatrix
34
34
  * @param flags - 0 to interpolate colors in unpremul, 1 to interpolate colors in premul.
35
35
  */
36
- MakeRadialGradient(center: SkPoint, radius: number, colors: SkColor[], pos: number[] | null, mode: TileMode, localMatrix?: SkMatrix, flags?: number): IShader;
36
+ MakeRadialGradient(center: SkPoint, radius: number, colors: SkColor[], pos: number[] | null, mode: TileMode, localMatrix?: SkMatrix, flags?: number): SkShader;
37
37
  /**
38
38
  * Returns a shader that generates a conical gradient given two circles.
39
39
  * See SkGradientShader.h for more.
@@ -47,7 +47,7 @@ export interface ShaderFactory {
47
47
  * @param localMatrix
48
48
  * @param flags
49
49
  */
50
- MakeTwoPointConicalGradient(start: SkPoint, startRadius: number, end: SkPoint, endRadius: number, colors: SkColor[], pos: number[] | null, mode: TileMode, localMatrix?: SkMatrix, flags?: number): IShader;
50
+ MakeTwoPointConicalGradient(start: SkPoint, startRadius: number, end: SkPoint, endRadius: number, colors: SkColor[], pos: number[] | null, mode: TileMode, localMatrix?: SkMatrix, flags?: number): SkShader;
51
51
  /**
52
52
  * Returns a shader that generates a sweep gradient given a center.
53
53
  * See SkGradientShader.h for more.
@@ -62,7 +62,7 @@ export interface ShaderFactory {
62
62
  * @param startAngle - angle corresponding to 0.0. Defaults to 0 degrees.
63
63
  * @param endAngle - angle corresponding to 1.0. Defaults to 360 degrees.
64
64
  */
65
- MakeSweepGradient(cx: number, cy: number, colors: SkColor[], pos: number[] | null, mode: TileMode, localMatrix?: SkMatrix | null, flags?: number, startAngleInDegrees?: number, endAngleInDegrees?: number): IShader;
65
+ MakeSweepGradient(cx: number, cy: number, colors: SkColor[], pos: number[] | null, mode: TileMode, localMatrix?: SkMatrix | null, flags?: number, startAngleInDegrees?: number, endAngleInDegrees?: number): SkShader;
66
66
  /**
67
67
  * Returns a shader with Perlin Turbulence.
68
68
  * See SkPerlinNoiseShader.h for more details
@@ -75,7 +75,7 @@ export interface ShaderFactory {
75
75
  * @param tileH - if this and tileW are non-zero, the frequencies will be modified so that the
76
76
  * noise will be tileable for the given size.
77
77
  */
78
- MakeTurbulence(baseFreqX: number, baseFreqY: number, octaves: number, seed: number, tileW: number, tileH: number): IShader;
78
+ MakeTurbulence(baseFreqX: number, baseFreqY: number, octaves: number, seed: number, tileW: number, tileH: number): SkShader;
79
79
  /**
80
80
  * Returns a shader with Perlin Fractal Noise.
81
81
  * See SkPerlinNoiseShader.h for more details
@@ -88,17 +88,17 @@ export interface ShaderFactory {
88
88
  * @param tileH - if this and tileW are non-zero, the frequencies will be modified so that the
89
89
  * noise will be tileable for the given size.
90
90
  */
91
- MakeFractalNoise(baseFreqX: number, baseFreqY: number, octaves: number, seed: number, tileW: number, tileH: number): IShader;
91
+ MakeFractalNoise(baseFreqX: number, baseFreqY: number, octaves: number, seed: number, tileW: number, tileH: number): SkShader;
92
92
  /**
93
93
  * Returns a shader that combines the given shaders with a BlendMode.
94
94
  * @param mode
95
95
  * @param one
96
96
  * @param two
97
97
  */
98
- MakeBlend(mode: BlendMode, one: IShader, two: IShader): IShader;
98
+ MakeBlend(mode: BlendMode, one: SkShader, two: SkShader): SkShader;
99
99
  /**
100
100
  * Returns a shader with a given color and colorspace.
101
101
  * @param color
102
102
  */
103
- MakeColor(color: SkColor): IShader;
103
+ MakeColor(color: SkColor): SkShader;
104
104
  }
@@ -10,8 +10,6 @@ import type { SkRect } from "./Rect";
10
10
  import type { SkRRect } from "./RRect";
11
11
  import type { RuntimeEffectFactory } from "./RuntimeEffect";
12
12
  import type { ShaderFactory } from "./Shader";
13
- import type { SkColor } from "./Color";
14
- import { processColor } from "./Color";
15
13
  import type { SkMatrix } from "./Matrix";
16
14
  import type { PathEffectFactory } from "./PathEffect";
17
15
  import type { SkPoint } from "./Point";
@@ -26,6 +24,7 @@ import type { SkRSXform } from "./RSXform";
26
24
  import type { SkPath } from "./Path/Path";
27
25
  import type { SkContourMeasureIter } from "./ContourMeasure";
28
26
  import type { PictureFactory, SkPictureRecorder } from "./Picture";
27
+ import type { Color, SkColor } from "./Color";
29
28
  /**
30
29
  * Declares the interface for the native Skia API
31
30
  */
@@ -34,6 +33,8 @@ export interface Skia {
34
33
  XYWHRect: (x: number, y: number, width: number, height: number) => SkRect;
35
34
  RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;
36
35
  RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;
36
+ Color: (color: Color) => SkColor;
37
+ parseColorString: (color: string) => SkColor | undefined;
37
38
  ContourMeasureIter: (path: SkPath, forceClosed: boolean, resScale: number) => SkContourMeasureIter;
38
39
  Paint: () => SkPaint;
39
40
  PictureRecorder: () => SkPictureRecorder;
@@ -97,7 +98,8 @@ export declare const Skia: {
97
98
  Path: PathFactory;
98
99
  ColorFilter: ColorFilterFactory;
99
100
  ContourMeasureIter: (path: SkPath, forceClosed: boolean, resScale: number) => SkContourMeasureIter;
100
- Color: (color: Parameters<typeof processColor>[0]) => number;
101
+ Color: (cl: Color) => number;
102
+ parseColorString: (color: string) => SkColor | undefined;
101
103
  RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;
102
104
  MakeSurface: (width: number, height: number) => import("./Surface").ISurface | null;
103
105
  MakeImageFromEncoded: (encoded: import("./Data").Data) => import("./Image").SkImage | null;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "React Native Skia",
7
- "version": "0.1.120",
7
+ "version": "0.1.123",
8
8
  "description": "High-performance React Native Graphics using Skia",
9
9
  "main": "lib/module/index.js",
10
10
  "files": [
@@ -9,7 +9,7 @@ const createSymlink = (p) => {
9
9
  const dstDir = path.resolve(`./android/cpp/${p}`);
10
10
 
11
11
  if (!fs.existsSync(dstDir) || !fs.lstatSync(dstDir).isSymbolicLink()) {
12
- fs.symlinkSync(srcDir, dstDir, "dir");
12
+ fs.symlinkSync(srcDir, dstDir, "junction");
13
13
  }
14
14
  };
15
15
 
@@ -23,6 +23,7 @@ import { Skia } from "../skia";
23
23
  import type { FontMgr } from "../skia/FontMgr/FontMgr";
24
24
  import { useValue } from "../values/hooks/useValue";
25
25
  import type { SkiaReadonlyValue } from "../values/types";
26
+ import { SkiaPaint } from "../skia/Paint/Paint";
26
27
 
27
28
  import { debug as hostDebug, skHostConfig } from "./HostConfig";
28
29
  // import { debugTree } from "./nodes";
@@ -112,8 +113,7 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
112
113
  ) {
113
114
  canvasCtx.current = { width, height };
114
115
  }
115
- const paint = Skia.Paint();
116
- paint.setAntiAlias(true);
116
+ const paint = SkiaPaint();
117
117
  const ctx = {
118
118
  width,
119
119
  height,
@@ -2,7 +2,7 @@ import type { ReactNode } from "react";
2
2
  import React, { useRef, useMemo, forwardRef, useImperativeHandle } from "react";
3
3
 
4
4
  import type { SkPaint } from "../../skia";
5
- import { Skia } from "../../skia";
5
+ import { SkiaPaint } from "../../skia";
6
6
  import type { CustomPaintProps, AnimatedProps } from "../processors";
7
7
  import { processPaint } from "../processors";
8
8
  import { createDeclaration } from "../nodes";
@@ -15,7 +15,7 @@ export interface PaintProps extends Omit<CustomPaintProps, "paint"> {
15
15
 
16
16
  export const Paint = forwardRef<SkPaint, AnimatedProps<PaintProps>>(
17
17
  (props, ref) => {
18
- const paint = useMemo(() => Skia.Paint(), []);
18
+ const paint = useMemo(() => SkiaPaint(), []);
19
19
  useImperativeHandle(ref, () => paint, [paint]);
20
20
  const onDeclare = useMemo(
21
21
  () =>
@@ -4,9 +4,11 @@ import type {
4
4
  CustomPaintProps,
5
5
  AnimatedProps,
6
6
  PathDef,
7
+ SkEnum,
7
8
  } from "../../processors";
8
9
  import { createDrawing } from "../../nodes";
9
- import { processPath } from "../../processors";
10
+ import { processPath, enumKey } from "../../processors";
11
+ import { FillType } from "../../../skia";
10
12
 
11
13
  interface StrokeOpts {
12
14
  width?: number;
@@ -19,16 +21,22 @@ export interface PathProps extends CustomPaintProps {
19
21
  start: number;
20
22
  end: number;
21
23
  stroke?: StrokeOpts;
24
+ fillType?: SkEnum<typeof FillType>;
22
25
  }
23
26
 
24
27
  const onDraw = createDrawing<PathProps>(
25
- ({ canvas, paint }, { start, end, stroke, ...pathProps }) => {
28
+ ({ canvas, paint }, { start, end, stroke, fillType, ...pathProps }) => {
26
29
  const hasStartOffset = start !== 0;
27
- const hasEndOffset = start !== 1;
30
+ const hasEndOffset = end !== 1;
28
31
  const hasStrokeOptions = stroke !== undefined;
29
- const willMutatePath = hasStartOffset || hasEndOffset || hasStrokeOptions;
32
+ const hasFillType = !!fillType;
33
+ const willMutatePath =
34
+ hasStartOffset || hasEndOffset || hasStrokeOptions || hasFillType;
30
35
  const pristinePath = processPath(pathProps.path);
31
36
  const path = willMutatePath ? pristinePath.copy() : pristinePath;
37
+ if (hasFillType) {
38
+ path.setFillType(FillType[enumKey(fillType)]);
39
+ }
32
40
  if (hasStrokeOptions) {
33
41
  path.stroke(stroke);
34
42
  }
@@ -40,7 +40,9 @@ export abstract class Node<P = unknown> {
40
40
  visit(ctx: DrawingContext, children?: Node[]) {
41
41
  const returnedValues: Exclude<DeclarationResult, null>[] = [];
42
42
  (children ?? this.children).forEach((child) => {
43
- if (!child.memoized) {
43
+ if (child.memoized && child.memoizable) {
44
+ returnedValues.push(child.memoized);
45
+ } else {
44
46
  const ret = child.draw(ctx);
45
47
  if (ret) {
46
48
  returnedValues.push(ret);
@@ -48,8 +50,6 @@ export abstract class Node<P = unknown> {
48
50
  child.memoized = ret;
49
51
  }
50
52
  }
51
- } else {
52
- returnedValues.push(child.memoized);
53
53
  }
54
54
  });
55
55
  return returnedValues;
@@ -32,6 +32,7 @@ export interface CustomPaintProps extends ChildrenProps {
32
32
  strokeCap?: SkEnum<typeof StrokeCap>;
33
33
  strokeMiter?: number;
34
34
  opacity?: number;
35
+ antiAlias?: boolean;
35
36
  }
36
37
 
37
38
  export const enumKey = <K extends string>(k: K) =>
@@ -50,6 +51,7 @@ export const processPaint = (
50
51
  strokeCap,
51
52
  strokeMiter,
52
53
  opacity,
54
+ antiAlias,
53
55
  }: CustomPaintProps,
54
56
  children: DeclarationResult[]
55
57
  ) => {
@@ -85,6 +87,9 @@ export const processPaint = (
85
87
  if (opacity !== undefined) {
86
88
  paint.setAlphaf(opacity);
87
89
  }
90
+ if (antiAlias !== undefined) {
91
+ paint.setAntiAlias(antiAlias);
92
+ }
88
93
  children.forEach((child) => {
89
94
  if (isShader(child)) {
90
95
  paint.setShader(child);
package/src/skia/Color.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { Platform, processColor as processColorRN } from "react-native";
1
+ import { Skia } from "./Skia";
2
2
 
3
3
  // This is the JSI color. Currently a number. This may change.
4
4
  export type SkColor = number;
5
-
5
+ // Input colors can be string or number
6
6
  export type Color = string | number;
7
7
 
8
8
  export const alphaf = (c: number) => ((c >> 24) & 255) / 255;
@@ -14,25 +14,8 @@ export const rgbaColor = (r: number, g: number, b: number, af: number) => {
14
14
  return ((a << 24) | (r << 16) | (g << 8) | b) >>> 0;
15
15
  };
16
16
 
17
- export const processColorAsInt = (color?: number | string): SkColor => {
18
- let processedColor = processColorRN(color);
19
- if (typeof processedColor !== "number") {
20
- throw new Error(`Couldn't process color: ${color}`);
21
- }
22
- // On android we need to move the alpha byte to the start of the structure
23
- if (Platform.OS === "android") {
24
- processedColor = processedColor >>> 0;
25
- const a = (processedColor >> 24) & 0xff;
26
- const r = (processedColor >> 16) & 0xff;
27
- const g = (processedColor >> 8) & 0xff;
28
- const b = processedColor & 0xff;
29
- processedColor = ((a << 24) | (r << 16) | (g << 8) | b) >>> 0;
30
- }
31
- return processedColor;
32
- };
33
-
34
17
  const processColorAsArray = (cl: Color) => {
35
- const icl = typeof cl === "string" ? processColorAsInt(cl) : cl;
18
+ const icl = typeof cl === "string" ? Skia.Color(cl) : cl;
36
19
  const r = red(icl);
37
20
  const g = green(icl);
38
21
  const b = blue(icl);
@@ -1,5 +1,5 @@
1
1
  import type { TileMode } from "../ImageFilter";
2
- import type { IShader } from "../Shader";
2
+ import type { SkShader } from "../Shader";
3
3
  import type { SkMatrix } from "../Matrix";
4
4
  import type { SkJSIInstance } from "../JsiInstance";
5
5
 
@@ -46,7 +46,7 @@ export interface SkImage extends SkJSIInstance<"Image"> {
46
46
  fm: FilterMode,
47
47
  mm: MipmapMode,
48
48
  localMatrix?: SkMatrix
49
- ): IShader;
49
+ ): SkShader;
50
50
 
51
51
  /**
52
52
  * Returns this image as a shader with the specified tiling. It will use cubic sampling.
@@ -62,7 +62,7 @@ export interface SkImage extends SkJSIInstance<"Image"> {
62
62
  B: number,
63
63
  C: number,
64
64
  localMatrix?: SkMatrix
65
- ): IShader;
65
+ ): SkShader;
66
66
 
67
67
  /** Encodes Image pixels, returning result as UInt8Array. Returns existing
68
68
  encoded data if present; otherwise, SkImage is encoded with
@@ -1,6 +1,6 @@
1
1
  import type { SkColor } from "../Color";
2
2
  import type { SkColorFilter } from "../ColorFilter/ColorFilter";
3
- import type { IShader } from "../Shader/Shader";
3
+ import type { SkShader } from "../Shader/Shader";
4
4
  import type { SkRect } from "../Rect";
5
5
  import type { BlendMode } from "../Paint/BlendMode";
6
6
 
@@ -48,7 +48,7 @@ export interface ImageFilterFactory {
48
48
  * @param shader - The Shader to be transformed
49
49
  * @param input - if null, it will use the dynamic source image
50
50
  */
51
- MakeShader(shader: IShader, input: SkImageFilter | null): SkImageFilter;
51
+ MakeShader(shader: SkShader, input: SkImageFilter | null): SkImageFilter;
52
52
  /**
53
53
  * Create a filter that blurs its input by the separate X and Y sigmas. The provided tile mode
54
54
  * is used when the blur kernel goes outside the input image.
@@ -1,10 +1,11 @@
1
1
  import type { SkImageFilter } from "../ImageFilter";
2
2
  import type { IMaskFilter } from "../MaskFilter";
3
3
  import type { SkColorFilter } from "../ColorFilter";
4
- import type { IShader } from "../Shader";
4
+ import type { SkShader } from "../Shader";
5
5
  import type { SkColor } from "../Color";
6
6
  import type { IPathEffect } from "../PathEffect";
7
7
  import type { SkJSIInstance } from "../JsiInstance";
8
+ import { Skia } from "../Skia";
8
9
 
9
10
  import type { BlendMode } from "./BlendMode";
10
11
 
@@ -25,6 +26,12 @@ export enum StrokeJoin {
25
26
  Round,
26
27
  }
27
28
 
29
+ export const SkiaPaint = () => {
30
+ const paint = Skia.Paint();
31
+ paint.setAntiAlias(true);
32
+ return paint;
33
+ };
34
+
28
35
  export const isPaint = (obj: SkJSIInstance<string> | null): obj is SkPaint =>
29
36
  obj !== null && obj.__typename__ === "Paint";
30
37
 
@@ -119,7 +126,7 @@ export interface SkPaint extends SkJSIInstance<"Paint"> {
119
126
  * Sets the current shader, replacing the existing one if there was one.
120
127
  * @param shader
121
128
  */
122
- setShader(shader: IShader | null): void;
129
+ setShader(shader: SkShader | null): void;
123
130
 
124
131
  /**
125
132
  * Sets the geometry drawn at the beginning and end of strokes.
@@ -1,8 +1,7 @@
1
1
  import type { DependencyList } from "react";
2
2
  import { useMemo } from "react";
3
3
 
4
- import { Skia } from "../Skia";
5
-
4
+ import { SkiaPaint } from "./Paint";
6
5
  import type { SkPaint } from "./Paint";
7
6
 
8
7
  /**
@@ -13,8 +12,7 @@ export const usePaint = (
13
12
  deps?: DependencyList
14
13
  ) =>
15
14
  useMemo(() => {
16
- const p = Skia.Paint();
17
- p.setAntiAlias(true);
15
+ const p = SkiaPaint();
18
16
  if (initializer) {
19
17
  initializer(p);
20
18
  }