@shopify/react-native-skia 1.9.1 → 1.10.0

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.
Files changed (80) hide show
  1. package/lib/commonjs/index.d.ts +1 -1
  2. package/lib/commonjs/index.js +8 -8
  3. package/lib/commonjs/index.js.map +1 -1
  4. package/lib/commonjs/renderer/Canvas.d.ts +9 -10
  5. package/lib/commonjs/renderer/Canvas.js +67 -59
  6. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  7. package/lib/commonjs/renderer/CanvasOld.d.ts +11 -0
  8. package/lib/commonjs/renderer/CanvasOld.js +96 -0
  9. package/lib/commonjs/renderer/CanvasOld.js.map +1 -0
  10. package/lib/commonjs/sksg/Container.js +11 -6
  11. package/lib/commonjs/sksg/Container.js.map +1 -1
  12. package/lib/commonjs/sksg/HostConfig2.d.ts +19 -0
  13. package/lib/commonjs/sksg/HostConfig2.js +159 -0
  14. package/lib/commonjs/sksg/HostConfig2.js.map +1 -0
  15. package/lib/commonjs/sksg/Recorder/Core.js +1 -0
  16. package/lib/commonjs/sksg/Recorder/Core.js.map +1 -1
  17. package/lib/commonjs/sksg/Recorder/Player.js +2 -2
  18. package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
  19. package/lib/commonjs/sksg/Recorder/Recorder.js +0 -1
  20. package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
  21. package/lib/module/index.d.ts +1 -1
  22. package/lib/module/index.js +1 -1
  23. package/lib/module/index.js.map +1 -1
  24. package/lib/module/renderer/Canvas.d.ts +9 -10
  25. package/lib/module/renderer/Canvas.js +65 -55
  26. package/lib/module/renderer/Canvas.js.map +1 -1
  27. package/lib/module/renderer/CanvasOld.d.ts +11 -0
  28. package/lib/module/renderer/CanvasOld.js +87 -0
  29. package/lib/module/renderer/CanvasOld.js.map +1 -0
  30. package/lib/module/sksg/Container.js +11 -6
  31. package/lib/module/sksg/Container.js.map +1 -1
  32. package/lib/module/sksg/HostConfig2.d.ts +19 -0
  33. package/lib/module/sksg/HostConfig2.js +152 -0
  34. package/lib/module/sksg/HostConfig2.js.map +1 -0
  35. package/lib/module/sksg/Recorder/Core.js +1 -0
  36. package/lib/module/sksg/Recorder/Core.js.map +1 -1
  37. package/lib/module/sksg/Recorder/Player.js +2 -2
  38. package/lib/module/sksg/Recorder/Player.js.map +1 -1
  39. package/lib/module/sksg/Recorder/Recorder.js +0 -1
  40. package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
  41. package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +2 -2
  42. package/lib/typescript/lib/commonjs/renderer/CanvasOld.d.ts +3 -0
  43. package/lib/typescript/lib/commonjs/sksg/HostConfig2.d.ts +44 -0
  44. package/lib/typescript/lib/module/index.d.ts +1 -1
  45. package/lib/typescript/lib/module/renderer/Canvas.d.ts +1 -3
  46. package/lib/typescript/lib/module/renderer/CanvasOld.d.ts +3 -0
  47. package/lib/typescript/lib/module/sksg/HostConfig2.d.ts +43 -0
  48. package/lib/typescript/src/index.d.ts +1 -1
  49. package/lib/typescript/src/renderer/Canvas.d.ts +9 -10
  50. package/lib/typescript/src/renderer/CanvasOld.d.ts +11 -0
  51. package/lib/typescript/src/sksg/HostConfig2.d.ts +19 -0
  52. package/package.json +1 -1
  53. package/src/index.ts +1 -1
  54. package/src/renderer/Canvas.tsx +80 -78
  55. package/src/renderer/CanvasOld.tsx +126 -0
  56. package/src/sksg/Container.ts +6 -2
  57. package/src/sksg/HostConfig2.ts +247 -0
  58. package/src/sksg/Recorder/Core.ts +1 -0
  59. package/src/sksg/Recorder/Player.ts +2 -2
  60. package/src/sksg/Recorder/Recorder.ts +0 -1
  61. package/lib/commonjs/renderer/Canvas2.d.ts +0 -10
  62. package/lib/commonjs/renderer/Canvas2.js +0 -104
  63. package/lib/commonjs/renderer/Canvas2.js.map +0 -1
  64. package/lib/commonjs/renderer/Canvas2.web.d.ts +0 -3
  65. package/lib/commonjs/renderer/Canvas2.web.js +0 -9
  66. package/lib/commonjs/renderer/Canvas2.web.js.map +0 -1
  67. package/lib/module/renderer/Canvas2.d.ts +0 -10
  68. package/lib/module/renderer/Canvas2.js +0 -97
  69. package/lib/module/renderer/Canvas2.js.map +0 -1
  70. package/lib/module/renderer/Canvas2.web.d.ts +0 -3
  71. package/lib/module/renderer/Canvas2.web.js +0 -3
  72. package/lib/module/renderer/Canvas2.web.js.map +0 -1
  73. package/lib/typescript/lib/commonjs/renderer/Canvas2.d.ts +0 -3
  74. package/lib/typescript/lib/commonjs/renderer/Canvas2.web.d.ts +0 -2
  75. package/lib/typescript/lib/module/renderer/Canvas2.d.ts +0 -1
  76. package/lib/typescript/lib/module/renderer/Canvas2.web.d.ts +0 -1
  77. package/lib/typescript/src/renderer/Canvas2.d.ts +0 -10
  78. package/lib/typescript/src/renderer/Canvas2.web.d.ts +0 -3
  79. package/src/renderer/Canvas2.tsx +0 -128
  80. package/src/renderer/Canvas2.web.tsx +0 -6
@@ -1 +1 @@
1
- {"version":3,"names":["NodeType","isSharedValue","isColorFilter","isImageFilter","isPathEffect","isShader","CommandType","Recorder","constructor","_defineProperty","Set","cursors","push","commands","getRecording","paintPool","animationValues","processProps","props","animatedProps","hasAnimatedProps","key","prop","add","value","undefined","command","length","saveGroup","children","type","Group","restoreGroup","pop","savePaint","SavePaint","restorePaint","RestorePaint","restorePaintDeclaration","RestorePaintDeclaration","materializePaint","MaterializePaint","pushPathEffect","pathEffectType","Error","PushPathEffect","pushImageFilter","imageFilterType","PushImageFilter","pushColorFilter","colorFilterType","PushColorFilter","pushShader","shaderType","Blend","PushShader","pushBlurMaskFilter","PushBlurMaskFilter","composePathEffect","ComposePathEffect","composeColorFilter","ComposeColorFilter","composeImageFilter","ComposeImageFilter","saveCTM","SaveCTM","restoreCTM","RestoreCTM","drawPaint","DrawPaint","saveLayer","SaveLayer","saveBackdropFilter","SaveBackdropFilter","drawBox","boxProps","shadows","forEach","shadow","DrawBox","drawImage","DrawImage","drawCircle","DrawCircle","drawPoints","DrawPoints","drawPath","DrawPath","drawRect","DrawRect","drawRRect","DrawRRect","drawOval","DrawOval","drawLine","DrawLine","drawPatch","DrawPatch","drawVertices","DrawVertices","drawDiffRect","DrawDiffRect","drawText","DrawText","drawTextPath","DrawTextPath","drawTextBlob","DrawTextBlob","drawGlyphs","DrawGlyphs","drawPicture","DrawPicture","drawImageSVG","DrawImageSVG","drawParagraph","DrawParagraph","drawAtlas","DrawAtlas"],"sources":["Recorder.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport { NodeType } from \"../../dom/types\";\nimport type {\n BlurMaskFilterProps,\n CircleProps,\n CTMProps,\n ImageProps,\n PaintProps,\n PointsProps,\n PathProps,\n RectProps,\n RoundedRectProps,\n OvalProps,\n LineProps,\n PatchProps,\n VerticesProps,\n DiffRectProps,\n TextProps,\n TextPathProps,\n TextBlobProps,\n GlyphsProps,\n PictureProps,\n ImageSVGProps,\n ParagraphProps,\n AtlasProps,\n BoxProps,\n BoxShadowProps,\n} from \"../../dom/types\";\nimport type { AnimatedProps } from \"../../renderer\";\nimport { isSharedValue } from \"../utils\";\nimport { isColorFilter, isImageFilter, isPathEffect, isShader } from \"../Node\";\nimport type { SkPaint } from \"../../skia/types\";\n\nimport { CommandType } from \"./Core\";\nimport type { Command } from \"./Core\";\n\nexport interface Recording {\n commands: Command[];\n paintPool: SkPaint[];\n}\n\ninterface AnimationValues {\n animationValues: Set<SharedValue<unknown>>;\n}\n\nexport class Recorder {\n commands: Command[] = [];\n cursors: Command[][] = [];\n animationValues: Set<SharedValue<unknown>> = new Set();\n\n constructor() {\n this.cursors.push(this.commands);\n }\n\n getRecording(): Recording & AnimationValues {\n return {\n commands: this.commands,\n paintPool: [],\n animationValues: this.animationValues,\n };\n }\n\n private processProps(props: Record<string, unknown>) {\n const animatedProps: Record<string, SharedValue<unknown>> = {};\n let hasAnimatedProps = false;\n\n for (const key in props) {\n const prop = props[key];\n if (isSharedValue(prop)) {\n this.animationValues.add(prop);\n props[key] = prop.value;\n animatedProps[key] = prop;\n hasAnimatedProps = true;\n }\n }\n\n return {\n props,\n animatedProps: hasAnimatedProps ? animatedProps : undefined,\n };\n }\n\n private add(command: Command) {\n if (command.props) {\n const { animatedProps } = this.processProps(\n command.props as Record<string, unknown>\n );\n if (animatedProps) {\n command.animatedProps = animatedProps;\n }\n }\n this.cursors[this.cursors.length - 1].push(command);\n }\n\n saveGroup() {\n const children: Command[] = [];\n this.add({ type: CommandType.Group, children });\n this.cursors.push(children);\n }\n\n restoreGroup() {\n this.cursors.pop();\n }\n\n savePaint(props: AnimatedProps<PaintProps>) {\n this.add({ type: CommandType.SavePaint, props });\n }\n\n restorePaint() {\n this.add({ type: CommandType.RestorePaint });\n }\n\n restorePaintDeclaration() {\n this.add({ type: CommandType.RestorePaintDeclaration });\n }\n\n materializePaint() {\n this.add({ type: CommandType.MaterializePaint });\n }\n\n pushPathEffect(pathEffectType: NodeType, props: AnimatedProps<unknown>) {\n if (!isPathEffect(pathEffectType)) {\n throw new Error(\"Invalid color filter type: \" + pathEffectType);\n }\n this.add({\n type: CommandType.PushPathEffect,\n pathEffectType,\n props,\n });\n }\n\n pushImageFilter(imageFilterType: NodeType, props: AnimatedProps<unknown>) {\n if (!isImageFilter(imageFilterType)) {\n throw new Error(\"Invalid color filter type: \" + imageFilterType);\n }\n this.add({\n type: CommandType.PushImageFilter,\n imageFilterType,\n props,\n });\n }\n\n pushColorFilter(colorFilterType: NodeType, props: AnimatedProps<unknown>) {\n if (!isColorFilter(colorFilterType)) {\n throw new Error(\"Invalid color filter type: \" + colorFilterType);\n }\n this.add({\n type: CommandType.PushColorFilter,\n colorFilterType,\n props,\n });\n }\n\n pushShader(shaderType: NodeType, props: AnimatedProps<unknown>) {\n if (!isShader(shaderType) && !(shaderType === NodeType.Blend)) {\n throw new Error(\"Invalid color filter type: \" + shaderType);\n }\n this.add({ type: CommandType.PushShader, shaderType, props });\n }\n\n pushBlurMaskFilter(props: AnimatedProps<BlurMaskFilterProps>) {\n this.add({ type: CommandType.PushBlurMaskFilter, props });\n }\n\n composePathEffect() {\n this.add({ type: CommandType.ComposePathEffect });\n }\n\n composeColorFilter() {\n this.add({ type: CommandType.ComposeColorFilter });\n }\n\n composeImageFilter() {\n this.add({ type: CommandType.ComposeImageFilter });\n }\n\n saveCTM(props: AnimatedProps<CTMProps>) {\n this.add({ type: CommandType.SaveCTM, props });\n }\n\n restoreCTM() {\n this.add({ type: CommandType.RestoreCTM });\n }\n\n drawPaint() {\n this.add({ type: CommandType.DrawPaint });\n }\n\n saveLayer() {\n this.add({ type: CommandType.SaveLayer });\n }\n\n saveBackdropFilter() {\n this.add({ type: CommandType.SaveBackdropFilter });\n }\n\n drawBox(\n boxProps: AnimatedProps<BoxProps>,\n shadows: {\n props: BoxShadowProps;\n animatedProps?: Record<string, SharedValue<unknown>>;\n }[]\n ) {\n shadows.forEach((shadow) => {\n if (shadow.props) {\n if (shadow.props) {\n const { animatedProps } = this.processProps(\n shadow.props as unknown as Record<string, unknown>\n );\n if (animatedProps) {\n shadow.animatedProps = animatedProps;\n }\n }\n }\n });\n this.add({ type: CommandType.DrawBox, props: boxProps, shadows });\n }\n\n drawImage(props: AnimatedProps<ImageProps>) {\n this.add({ type: CommandType.DrawImage, props });\n }\n\n drawCircle(props: AnimatedProps<CircleProps>) {\n this.add({ type: CommandType.DrawCircle, props });\n }\n drawPoints(props: AnimatedProps<PointsProps>) {\n this.add({ type: CommandType.DrawPoints, props });\n }\n\n drawPath(props: AnimatedProps<PathProps>) {\n this.add({ type: CommandType.DrawPath, props });\n }\n\n drawRect(props: AnimatedProps<RectProps>) {\n this.add({ type: CommandType.DrawRect, props });\n }\n\n drawRRect(props: AnimatedProps<RoundedRectProps>) {\n this.add({ type: CommandType.DrawRRect, props });\n }\n\n drawOval(props: AnimatedProps<OvalProps>) {\n this.add({ type: CommandType.DrawOval, props });\n }\n\n drawLine(props: AnimatedProps<LineProps>) {\n this.add({ type: CommandType.DrawLine, props });\n }\n\n drawPatch(props: AnimatedProps<PatchProps>) {\n this.add({ type: CommandType.DrawPatch, props });\n }\n\n drawVertices(props: AnimatedProps<VerticesProps>) {\n this.add({ type: CommandType.DrawVertices, props });\n }\n\n drawDiffRect(props: AnimatedProps<DiffRectProps>) {\n this.add({ type: CommandType.DrawDiffRect, props });\n }\n\n drawText(props: AnimatedProps<TextProps>) {\n this.add({ type: CommandType.DrawText, props });\n }\n\n drawTextPath(props: AnimatedProps<TextPathProps>) {\n this.add({ type: CommandType.DrawTextPath, props });\n }\n\n drawTextBlob(props: AnimatedProps<TextBlobProps>) {\n this.add({ type: CommandType.DrawTextBlob, props });\n }\n\n drawGlyphs(props: AnimatedProps<GlyphsProps>) {\n this.add({ type: CommandType.DrawGlyphs, props });\n }\n\n drawPicture(props: AnimatedProps<PictureProps>) {\n this.add({ type: CommandType.DrawPicture, props });\n }\n\n drawImageSVG(props: AnimatedProps<ImageSVGProps>) {\n this.add({ type: CommandType.DrawImageSVG, props });\n }\n\n drawParagraph(props: AnimatedProps<ParagraphProps>) {\n this.add({ type: CommandType.DrawParagraph, props });\n }\n\n drawAtlas(props: AnimatedProps<AtlasProps>) {\n this.add({ type: CommandType.DrawAtlas, props });\n }\n}\n"],"mappings":";;;AAEA,SAASA,QAAQ,QAAQ,iBAAiB;AA4B1C,SAASC,aAAa,QAAQ,UAAU;AACxC,SAASC,aAAa,EAAEC,aAAa,EAAEC,YAAY,EAAEC,QAAQ,QAAQ,SAAS;AAG9E,SAASC,WAAW,QAAQ,QAAQ;AAYpC,OAAO,MAAMC,QAAQ,CAAC;EAKpBC,WAAWA,CAAA,EAAG;IAAAC,eAAA,mBAJQ,EAAE;IAAAA,eAAA,kBACD,EAAE;IAAAA,eAAA,0BACoB,IAAIC,GAAG,CAAC,CAAC;IAGpD,IAAI,CAACC,OAAO,CAACC,IAAI,CAAC,IAAI,CAACC,QAAQ,CAAC;EAClC;EAEAC,YAAYA,CAAA,EAAgC;IAC1C,OAAO;MACLD,QAAQ,EAAE,I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EAAExB,WAAW,CAACiG,QAAQ;MAAErF;IAAM,CAAC,CAAC;EACjD;EAEAsF,YAAYA,CAACtF,KAAmC,EAAE;IAChD,IAAI,CAACK,GAAG,CAAC;MAAEO,IAAI,EAAExB,WAAW,CAACmG,YAAY;MAAEvF;IAAM,CAAC,CAAC;EACrD;EAEAwF,YAAYA,CAACxF,KAAmC,EAAE;IAChD,IAAI,CAACK,GAAG,CAAC;MAAEO,IAAI,EAAExB,WAAW,CAACqG,YAAY;MAAEzF;IAAM,CAAC,CAAC;EACrD;EAEA0F,UAAUA,CAAC1F,KAAiC,EAAE;IAC5C,IAAI,CAACK,GAAG,CAAC;MAAEO,IAAI,EAAExB,WAAW,CAACuG,UAAU;MAAE3F;IAAM,CAAC,CAAC;EACnD;EAEA4F,WAAWA,CAAC5F,KAAkC,EAAE;IAC9C,IAAI,CAACK,GAAG,CAAC;MAAEO,IAAI,EAAExB,WAAW,CAACyG,WAAW;MAAE7F;IAAM,CAAC,CAAC;EACpD;EAEA8F,YAAYA,CAAC9F,KAAmC,EAAE;IAChD,IAAI,CAACK,GAAG,CAAC;MAAEO,IAAI,EAAExB,WAAW,CAAC2G,YAAY;MAAE/F;IAAM,CAAC,CAAC;EACrD;EAEAgG,aAAaA,CAAChG,KAAoC,EAAE;IAClD,IAAI,CAACK,GAAG,CAAC;MAAEO,IAAI,EAAExB,WAAW,CAAC6G,aAAa;MAAEjG;IAAM,CAAC,CAAC;EACtD;EAEAkG,SAASA,CAAClG,KAAgC,EAAE;IAC1C,IAAI,CAACK,GAAG,CAAC;MAAEO,IAAI,EAAExB,WAAW,CAAC+G,SAAS;MAAEnG;IAAM,CAAC,CAAC;EAClD;AACF","ignoreList":[]}
1
+ {"version":3,"names":["NodeType","isSharedValue","isColorFilter","isImageFilter","isPathEffect","isShader","CommandType","Recorder","constructor","_defineProperty","Set","cursors","push","commands","getRecording","paintPool","animationValues","processProps","props","animatedProps","hasAnimatedProps","key","prop","add","undefined","command","length","saveGroup","children","type","Group","restoreGroup","pop","savePaint","SavePaint","restorePaint","RestorePaint","restorePaintDeclaration","RestorePaintDeclaration","materializePaint","MaterializePaint","pushPathEffect","pathEffectType","Error","PushPathEffect","pushImageFilter","imageFilterType","PushImageFilter","pushColorFilter","colorFilterType","PushColorFilter","pushShader","shaderType","Blend","PushShader","pushBlurMaskFilter","PushBlurMaskFilter","composePathEffect","ComposePathEffect","composeColorFilter","ComposeColorFilter","composeImageFilter","ComposeImageFilter","saveCTM","SaveCTM","restoreCTM","RestoreCTM","drawPaint","DrawPaint","saveLayer","SaveLayer","saveBackdropFilter","SaveBackdropFilter","drawBox","boxProps","shadows","forEach","shadow","DrawBox","drawImage","DrawImage","drawCircle","DrawCircle","drawPoints","DrawPoints","drawPath","DrawPath","drawRect","DrawRect","drawRRect","DrawRRect","drawOval","DrawOval","drawLine","DrawLine","drawPatch","DrawPatch","drawVertices","DrawVertices","drawDiffRect","DrawDiffRect","drawText","DrawText","drawTextPath","DrawTextPath","drawTextBlob","DrawTextBlob","drawGlyphs","DrawGlyphs","drawPicture","DrawPicture","drawImageSVG","DrawImageSVG","drawParagraph","DrawParagraph","drawAtlas","DrawAtlas"],"sources":["Recorder.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport { NodeType } from \"../../dom/types\";\nimport type {\n BlurMaskFilterProps,\n CircleProps,\n CTMProps,\n ImageProps,\n PaintProps,\n PointsProps,\n PathProps,\n RectProps,\n RoundedRectProps,\n OvalProps,\n LineProps,\n PatchProps,\n VerticesProps,\n DiffRectProps,\n TextProps,\n TextPathProps,\n TextBlobProps,\n GlyphsProps,\n PictureProps,\n ImageSVGProps,\n ParagraphProps,\n AtlasProps,\n BoxProps,\n BoxShadowProps,\n} from \"../../dom/types\";\nimport type { AnimatedProps } from \"../../renderer\";\nimport { isSharedValue } from \"../utils\";\nimport { isColorFilter, isImageFilter, isPathEffect, isShader } from \"../Node\";\nimport type { SkPaint } from \"../../skia/types\";\n\nimport { CommandType } from \"./Core\";\nimport type { Command } from \"./Core\";\n\nexport interface Recording {\n commands: Command[];\n paintPool: SkPaint[];\n}\n\ninterface AnimationValues {\n animationValues: Set<SharedValue<unknown>>;\n}\n\nexport class Recorder {\n commands: Command[] = [];\n cursors: Command[][] = [];\n animationValues: Set<SharedValue<unknown>> = new Set();\n\n constructor() {\n this.cursors.push(this.commands);\n }\n\n getRecording(): Recording & AnimationValues {\n return {\n commands: this.commands,\n paintPool: [],\n animationValues: this.animationValues,\n };\n }\n\n private processProps(props: Record<string, unknown>) {\n const animatedProps: Record<string, SharedValue<unknown>> = {};\n let hasAnimatedProps = false;\n\n for (const key in props) {\n const prop = props[key];\n if (isSharedValue(prop)) {\n this.animationValues.add(prop);\n animatedProps[key] = prop;\n hasAnimatedProps = true;\n }\n }\n\n return {\n props,\n animatedProps: hasAnimatedProps ? animatedProps : undefined,\n };\n }\n\n private add(command: Command) {\n if (command.props) {\n const { animatedProps } = this.processProps(\n command.props as Record<string, unknown>\n );\n if (animatedProps) {\n command.animatedProps = animatedProps;\n }\n }\n this.cursors[this.cursors.length - 1].push(command);\n }\n\n saveGroup() {\n const children: Command[] = [];\n this.add({ type: CommandType.Group, children });\n this.cursors.push(children);\n }\n\n restoreGroup() {\n this.cursors.pop();\n }\n\n savePaint(props: AnimatedProps<PaintProps>) {\n this.add({ type: CommandType.SavePaint, props });\n }\n\n restorePaint() {\n this.add({ type: CommandType.RestorePaint });\n }\n\n restorePaintDeclaration() {\n this.add({ type: CommandType.RestorePaintDeclaration });\n }\n\n materializePaint() {\n this.add({ type: CommandType.MaterializePaint });\n }\n\n pushPathEffect(pathEffectType: NodeType, props: AnimatedProps<unknown>) {\n if (!isPathEffect(pathEffectType)) {\n throw new Error(\"Invalid color filter type: \" + pathEffectType);\n }\n this.add({\n type: CommandType.PushPathEffect,\n pathEffectType,\n props,\n });\n }\n\n pushImageFilter(imageFilterType: NodeType, props: AnimatedProps<unknown>) {\n if (!isImageFilter(imageFilterType)) {\n throw new Error(\"Invalid color filter type: \" + imageFilterType);\n }\n this.add({\n type: CommandType.PushImageFilter,\n imageFilterType,\n props,\n });\n }\n\n pushColorFilter(colorFilterType: NodeType, props: AnimatedProps<unknown>) {\n if (!isColorFilter(colorFilterType)) {\n throw new Error(\"Invalid color filter type: \" + colorFilterType);\n }\n this.add({\n type: CommandType.PushColorFilter,\n colorFilterType,\n props,\n });\n }\n\n pushShader(shaderType: NodeType, props: AnimatedProps<unknown>) {\n if (!isShader(shaderType) && !(shaderType === NodeType.Blend)) {\n throw new Error(\"Invalid color filter type: \" + shaderType);\n }\n this.add({ type: CommandType.PushShader, shaderType, props });\n }\n\n pushBlurMaskFilter(props: AnimatedProps<BlurMaskFilterProps>) {\n this.add({ type: CommandType.PushBlurMaskFilter, props });\n }\n\n composePathEffect() {\n this.add({ type: CommandType.ComposePathEffect });\n }\n\n composeColorFilter() {\n this.add({ type: CommandType.ComposeColorFilter });\n }\n\n composeImageFilter() {\n this.add({ type: CommandType.ComposeImageFilter });\n }\n\n saveCTM(props: AnimatedProps<CTMProps>) {\n this.add({ type: CommandType.SaveCTM, props });\n }\n\n restoreCTM() {\n this.add({ type: CommandType.RestoreCTM });\n }\n\n drawPaint() {\n this.add({ type: CommandType.DrawPaint });\n }\n\n saveLayer() {\n this.add({ type: CommandType.SaveLayer });\n }\n\n saveBackdropFilter() {\n this.add({ type: CommandType.SaveBackdropFilter });\n }\n\n drawBox(\n boxProps: AnimatedProps<BoxProps>,\n shadows: {\n props: BoxShadowProps;\n animatedProps?: Record<string, SharedValue<unknown>>;\n }[]\n ) {\n shadows.forEach((shadow) => {\n if (shadow.props) {\n if (shadow.props) {\n const { animatedProps } = this.processProps(\n shadow.props as unknown as Record<string, unknown>\n );\n if (animatedProps) {\n shadow.animatedProps = animatedProps;\n }\n }\n }\n });\n this.add({ type: CommandType.DrawBox, props: boxProps, shadows });\n }\n\n drawImage(props: AnimatedProps<ImageProps>) {\n this.add({ type: CommandType.DrawImage, props });\n }\n\n drawCircle(props: AnimatedProps<CircleProps>) {\n this.add({ type: CommandType.DrawCircle, props });\n }\n drawPoints(props: AnimatedProps<PointsProps>) {\n this.add({ type: CommandType.DrawPoints, props });\n }\n\n drawPath(props: AnimatedProps<PathProps>) {\n this.add({ type: CommandType.DrawPath, props });\n }\n\n drawRect(props: AnimatedProps<RectProps>) {\n this.add({ type: CommandType.DrawRect, props });\n }\n\n drawRRect(props: AnimatedProps<RoundedRectProps>) {\n this.add({ type: CommandType.DrawRRect, props });\n }\n\n drawOval(props: AnimatedProps<OvalProps>) {\n this.add({ type: CommandType.DrawOval, props });\n }\n\n drawLine(props: AnimatedProps<LineProps>) {\n this.add({ type: CommandType.DrawLine, props });\n }\n\n drawPatch(props: AnimatedProps<PatchProps>) {\n this.add({ type: CommandType.DrawPatch, props });\n }\n\n drawVertices(props: AnimatedProps<VerticesProps>) {\n this.add({ type: CommandType.DrawVertices, props });\n }\n\n drawDiffRect(props: AnimatedProps<DiffRectProps>) {\n this.add({ type: CommandType.DrawDiffRect, props });\n }\n\n drawText(props: AnimatedProps<TextProps>) {\n this.add({ type: CommandType.DrawText, props });\n }\n\n drawTextPath(props: AnimatedProps<TextPathProps>) {\n this.add({ type: CommandType.DrawTextPath, props });\n }\n\n drawTextBlob(props: AnimatedProps<TextBlobProps>) {\n this.add({ type: CommandType.DrawTextBlob, props });\n }\n\n drawGlyphs(props: AnimatedProps<GlyphsProps>) {\n this.add({ type: CommandType.DrawGlyphs, props });\n }\n\n drawPicture(props: AnimatedProps<PictureProps>) {\n this.add({ type: CommandType.DrawPicture, props });\n }\n\n drawImageSVG(props: AnimatedProps<ImageSVGProps>) {\n this.add({ type: CommandType.DrawImageSVG, props });\n }\n\n drawParagraph(props: AnimatedProps<ParagraphProps>) {\n this.add({ type: CommandType.DrawParagraph, props });\n }\n\n drawAtlas(props: AnimatedProps<AtlasProps>) {\n this.add({ type: CommandType.DrawAtlas, props });\n }\n}\n"],"mappings":";;;AAEA,SAASA,QAAQ,QAAQ,iBAAiB;AA4B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AAC;MAAEM,IAAI,EAAEvB,WAAW,CAAC4G,aAAa;MAAEhG;IAAM,CAAC,CAAC;EACtD;EAEAiG,SAASA,CAACjG,KAAgC,EAAE;IAC1C,IAAI,CAACK,GAAG,CAAC;MAAEM,IAAI,EAAEvB,WAAW,CAAC8G,SAAS;MAAElG;IAAM,CAAC,CAAC;EAClD;AACF","ignoreList":[]}
@@ -1,3 +1,3 @@
1
1
  export const __esModule: boolean;
2
- export const Canvas: any;
3
- export function useCanvasRef(): any;
2
+ export const Canvas: _react.ForwardRefExoticComponent<_react.RefAttributes<any>>;
3
+ import _react = require("react");
@@ -0,0 +1,3 @@
1
+ export const __esModule: boolean;
2
+ export const CanvasOld: any;
3
+ export function useCanvasRef(): any;
@@ -0,0 +1,44 @@
1
+ export const __esModule: boolean;
2
+ export namespace sksgHostConfig {
3
+ let supportsMutation: boolean;
4
+ let isPrimaryRenderer: boolean;
5
+ let supportsPersistence: boolean;
6
+ let supportsHydration: boolean;
7
+ let scheduleTimeout: typeof setTimeout;
8
+ let cancelTimeout: typeof clearTimeout;
9
+ let noTimeout: number;
10
+ function appendChildToContainer(container: any, child: any): void;
11
+ function appendChild(parent: any, child: any): void;
12
+ function getRootHostContext(_rootContainerInstance: any): null;
13
+ function getChildHostContext(_parentHostContext: any, _type: any, _rootContainerInstance: any): null;
14
+ function shouldSetTextContent(_type: any, _props: any): boolean;
15
+ function createTextInstance(_text: any, _rootContainerInstance: any, _hostContext: any, _internalInstanceHandle: any): never;
16
+ function createInstance(type: any, propsWithChildren: any, _container: any, _hostContext: any, _internalInstanceHandle: any): {
17
+ type: any;
18
+ props: any;
19
+ children: never[];
20
+ };
21
+ function appendInitialChild(parentInstance: any, child: any): void;
22
+ function finalizeInitialChildren(parentInstance: any, _type: any, _props: any, _rootContainerInstance: any, _hostContext: any): boolean;
23
+ function commitMount(): void;
24
+ function prepareForCommit(_containerInfo: any): null;
25
+ function resetAfterCommit(container: any): void;
26
+ function getPublicInstance(node: any): any;
27
+ function prepareUpdate(_instance: any, type: any, oldProps: any, newProps: any, rootContainerInstance: any, _hostContext: any): any;
28
+ function commitUpdate(instance: any, _updatePayload: any, type: any, prevProps: any, nextProps: any, _internalHandle: any): void;
29
+ function commitTextUpdate(_textInstance: any, _oldText: any, _newText: any): void;
30
+ function clearContainer(container: any): void;
31
+ function preparePortalMount(): void;
32
+ function removeChild(parent: any, child: any): void;
33
+ function removeChildFromContainer(container: any, child: any): void;
34
+ function insertInContainerBefore(container: any, child: any, before: any): void;
35
+ function insertBefore(parent: any, child: any, before: any): void;
36
+ function getCurrentEventPriority(): number;
37
+ function beforeActiveInstanceBlur(): void;
38
+ function afterActiveInstanceBlur(): void;
39
+ function detachDeletedInstance(): void;
40
+ function getInstanceFromNode(_node: any): null;
41
+ function prepareScopeUpdate(_scopeInstance: any, _instance: any): void;
42
+ function getInstanceFromScope(_scopeInstance: any): null;
43
+ }
44
+ export function debug(...args: any[]): void;
@@ -1,7 +1,7 @@
1
1
  export { JsiSkImage } from "./skia/web/JsiSkImage";
2
2
  export * from "./renderer";
3
+ export * from "./renderer/CanvasOld";
3
4
  export * from "./renderer/Canvas";
4
- export * from "./renderer/Canvas2";
5
5
  export * from "./renderer/Offscreen";
6
6
  export * from "./views";
7
7
  export * from "./skia";
@@ -1,3 +1 @@
1
- export function useCanvasRef(): React.MutableRefObject<null>;
2
- export const Canvas: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
- import React from "react";
1
+ export const Canvas: import("react").ForwardRefExoticComponent<import("react").RefAttributes<any>>;
@@ -0,0 +1,3 @@
1
+ export function useCanvasRef(): React.MutableRefObject<null>;
2
+ export const CanvasOld: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
+ import React from "react";
@@ -0,0 +1,43 @@
1
+ export function debug(...args: any[]): void;
2
+ export namespace sksgHostConfig {
3
+ let supportsMutation: boolean;
4
+ let isPrimaryRenderer: boolean;
5
+ let supportsPersistence: boolean;
6
+ let supportsHydration: boolean;
7
+ let scheduleTimeout: typeof setTimeout;
8
+ let cancelTimeout: typeof clearTimeout;
9
+ let noTimeout: number;
10
+ function appendChildToContainer(container: any, child: any): void;
11
+ function appendChild(parent: any, child: any): void;
12
+ function getRootHostContext(_rootContainerInstance: any): null;
13
+ function getChildHostContext(_parentHostContext: any, _type: any, _rootContainerInstance: any): null;
14
+ function shouldSetTextContent(_type: any, _props: any): boolean;
15
+ function createTextInstance(_text: any, _rootContainerInstance: any, _hostContext: any, _internalInstanceHandle: any): never;
16
+ function createInstance(type: any, propsWithChildren: any, _container: any, _hostContext: any, _internalInstanceHandle: any): {
17
+ type: any;
18
+ props: any;
19
+ children: never[];
20
+ };
21
+ function appendInitialChild(parentInstance: any, child: any): void;
22
+ function finalizeInitialChildren(parentInstance: any, _type: any, _props: any, _rootContainerInstance: any, _hostContext: any): boolean;
23
+ function commitMount(): void;
24
+ function prepareForCommit(_containerInfo: any): null;
25
+ function resetAfterCommit(container: any): void;
26
+ function getPublicInstance(node: any): any;
27
+ function prepareUpdate(_instance: any, type: any, oldProps: any, newProps: any, rootContainerInstance: any, _hostContext: any): any;
28
+ function commitUpdate(instance: any, _updatePayload: any, type: any, prevProps: any, nextProps: any, _internalHandle: any): void;
29
+ function commitTextUpdate(_textInstance: any, _oldText: any, _newText: any): void;
30
+ function clearContainer(container: any): void;
31
+ function preparePortalMount(): void;
32
+ function removeChild(parent: any, child: any): void;
33
+ function removeChildFromContainer(container: any, child: any): void;
34
+ function insertInContainerBefore(container: any, child: any, before: any): void;
35
+ function insertBefore(parent: any, child: any, before: any): void;
36
+ function getCurrentEventPriority(): number;
37
+ function beforeActiveInstanceBlur(): void;
38
+ function afterActiveInstanceBlur(): void;
39
+ function detachDeletedInstance(): void;
40
+ function getInstanceFromNode(_node: any): null;
41
+ function prepareScopeUpdate(_scopeInstance: any, _instance: any): void;
42
+ function getInstanceFromScope(_scopeInstance: any): null;
43
+ }
@@ -1,8 +1,8 @@
1
1
  import "./skia/NativeSetup";
2
2
  export { JsiSkImage } from "./skia/web/JsiSkImage";
3
3
  export * from "./renderer";
4
+ export * from "./renderer/CanvasOld";
4
5
  export * from "./renderer/Canvas";
5
- export * from "./renderer/Canvas2";
6
6
  export * from "./renderer/Offscreen";
7
7
  export * from "./views";
8
8
  export * from "./skia";
@@ -1,11 +1,10 @@
1
- import React from "react";
2
- import type { RefObject, ReactNode, FunctionComponent } from "react";
3
- import { SkiaDomView } from "../views";
4
- import type { SkiaBaseViewProps } from "../views";
5
- export declare const useCanvasRef: () => React.RefObject<SkiaDomView>;
6
- export interface CanvasProps extends SkiaBaseViewProps {
7
- ref?: RefObject<SkiaDomView>;
8
- children: ReactNode;
9
- mode?: "default" | "continuous";
1
+ import type { ViewProps } from "react-native";
2
+ import type { SharedValue } from "react-native-reanimated";
3
+ import type { SkSize } from "../skia/types";
4
+ export interface CanvasProps extends ViewProps {
5
+ debug?: boolean;
6
+ opaque?: boolean;
7
+ onSize?: SharedValue<SkSize>;
8
+ mode?: "continuous" | "default";
10
9
  }
11
- export declare const Canvas: FunctionComponent<CanvasProps & React.RefAttributes<SkiaDomView>>;
10
+ export declare const Canvas: import("react").ForwardRefExoticComponent<CanvasProps & import("react").RefAttributes<unknown>>;
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import type { RefObject, ReactNode, FunctionComponent } from "react";
3
+ import { SkiaDomView } from "../views";
4
+ import type { SkiaBaseViewProps } from "../views";
5
+ export declare const useCanvasRef: () => React.RefObject<SkiaDomView>;
6
+ export interface CanvasOldProps extends SkiaBaseViewProps {
7
+ ref?: RefObject<SkiaDomView>;
8
+ children: ReactNode;
9
+ mode?: "default" | "continuous";
10
+ }
11
+ export declare const CanvasOld: FunctionComponent<CanvasOldProps & React.RefAttributes<SkiaDomView>>;
@@ -0,0 +1,19 @@
1
+ import type { HostConfig } from "react-reconciler";
2
+ import type { NodeType } from "../dom/types";
3
+ import type { Container } from "./Container";
4
+ import type { Node } from "./Node";
5
+ export declare const debug: (message?: any, ...optionalParams: any[]) => void;
6
+ type Instance = Node<unknown>;
7
+ type Props = object;
8
+ type TextInstance = Node<unknown>;
9
+ type SuspenseInstance = Instance;
10
+ type HydratableInstance = Instance;
11
+ type PublicInstance = Instance;
12
+ type HostContext = null;
13
+ type UpdatePayload = Container;
14
+ type ChildSet = unknown;
15
+ type TimeoutHandle = NodeJS.Timeout;
16
+ type NoTimeout = -1;
17
+ type SkiaHostConfig = HostConfig<NodeType, Props, Container, Instance, TextInstance, SuspenseInstance, HydratableInstance, PublicInstance, HostContext, UpdatePayload, ChildSet, TimeoutHandle, NoTimeout>;
18
+ export declare const sksgHostConfig: SkiaHostConfig;
19
+ export {};
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "setup-skia-web": "./scripts/setup-canvaskit.js"
8
8
  },
9
9
  "title": "React Native Skia",
10
- "version": "1.9.1",
10
+ "version": "1.10.0",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "react-native": "src/index.ts",
package/src/index.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import "./skia/NativeSetup";
2
2
  export { JsiSkImage } from "./skia/web/JsiSkImage";
3
3
  export * from "./renderer";
4
+ export * from "./renderer/CanvasOld";
4
5
  export * from "./renderer/Canvas";
5
- export * from "./renderer/Canvas2";
6
6
  export * from "./renderer/Offscreen";
7
7
  export * from "./views";
8
8
  export * from "./skia";
@@ -1,32 +1,24 @@
1
- import React, {
2
- useEffect,
1
+ import {
2
+ forwardRef,
3
3
  useCallback,
4
+ useEffect,
5
+ useImperativeHandle,
4
6
  useMemo,
5
- forwardRef,
6
7
  useRef,
7
8
  } from "react";
8
- import type {
9
- RefObject,
10
- ReactNode,
11
- MutableRefObject,
12
- ForwardedRef,
13
- FunctionComponent,
14
- } from "react";
15
- import type { LayoutChangeEvent } from "react-native";
9
+ import type { LayoutChangeEvent, ViewProps } from "react-native";
10
+ import type { SharedValue } from "react-native-reanimated";
16
11
 
17
- import { SkiaDomView } from "../views";
12
+ import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
13
+ import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
14
+ import type { SkRect, SkSize } from "../skia/types";
15
+ import { SkiaSGRoot } from "../sksg/Reconciler";
16
+ import { Skia } from "../skia";
18
17
  import type { SkiaBaseViewProps } from "../views";
19
18
 
20
- import { SkiaRoot } from "./Reconciler";
21
-
22
- export const useCanvasRef = () => useRef<SkiaDomView>(null);
23
-
24
- export interface CanvasProps extends SkiaBaseViewProps {
25
- ref?: RefObject<SkiaDomView>;
26
- children: ReactNode;
27
- mode?: "default" | "continuous";
28
- }
19
+ const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
29
20
 
21
+ // TODO: no need to go through the JS thread for this
30
22
  const useOnSizeEvent = (
31
23
  resultValue: SkiaBaseViewProps["onSize"],
32
24
  onLayout?: (event: LayoutChangeEvent) => void
@@ -46,39 +38,40 @@ const useOnSizeEvent = (
46
38
  );
47
39
  };
48
40
 
49
- export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
41
+ export interface CanvasProps extends ViewProps {
42
+ debug?: boolean;
43
+ opaque?: boolean;
44
+ onSize?: SharedValue<SkSize>;
45
+ mode?: "continuous" | "default";
46
+ }
47
+
48
+ export const Canvas = forwardRef(
50
49
  (
51
50
  {
52
- children,
53
- style,
51
+ mode,
54
52
  debug,
55
- mode = "default",
56
- onSize: _onSize,
53
+ opaque,
54
+ children,
55
+ onSize,
57
56
  onLayout: _onLayout,
58
- ...props
59
- },
60
- forwardedRef
57
+ ...viewProps
58
+ }: CanvasProps,
59
+ ref
61
60
  ) => {
62
- const onLayout = useOnSizeEvent(_onSize, _onLayout);
63
- const innerRef = useCanvasRef();
64
- const ref = useCombinedRefs(forwardedRef, innerRef);
65
- const redraw = useCallback(() => {
66
- innerRef.current?.redraw();
67
- }, [innerRef]);
68
- const getNativeId = useCallback(() => {
69
- const id = innerRef.current?.nativeId ?? -1;
70
- return id;
71
- }, [innerRef]);
61
+ const rafId = useRef<number | null>(null);
62
+ const onLayout = useOnSizeEvent(onSize, _onLayout);
63
+ // Native ID
64
+ const nativeId = useMemo(() => {
65
+ return SkiaViewNativeId.current++;
66
+ }, []);
72
67
 
73
- const root = useMemo(
74
- () => new SkiaRoot(redraw, getNativeId),
75
- [redraw, getNativeId]
76
- );
68
+ // Root
69
+ const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);
77
70
 
78
- // Render effect
71
+ // Render effects
79
72
  useEffect(() => {
80
73
  root.render(children);
81
- }, [children, root, redraw]);
74
+ }, [children, root]);
82
75
 
83
76
  useEffect(() => {
84
77
  return () => {
@@ -86,41 +79,50 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
86
79
  };
87
80
  }, [root]);
88
81
 
82
+ const requestRedraw = useCallback(() => {
83
+ rafId.current = requestAnimationFrame(() => {
84
+ root.render(children);
85
+ if (mode === "continuous") {
86
+ requestRedraw();
87
+ }
88
+ });
89
+ }, [children, mode, root]);
90
+
91
+ useEffect(() => {
92
+ if (mode === "continuous") {
93
+ console.warn("The `mode` property in `Canvas` is deprecated.");
94
+ requestRedraw();
95
+ }
96
+ return () => {
97
+ if (rafId.current !== null) {
98
+ cancelAnimationFrame(rafId.current);
99
+ }
100
+ };
101
+ }, [mode, requestRedraw]);
102
+ // Component methods
103
+ useImperativeHandle(ref, () => ({
104
+ makeImageSnapshot: (rect?: SkRect) => {
105
+ return SkiaViewApi.makeImageSnapshot(nativeId, rect);
106
+ },
107
+ makeImageSnapshotAsync: (rect?: SkRect) => {
108
+ return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);
109
+ },
110
+ redraw: () => {
111
+ SkiaViewApi.requestRedraw(nativeId);
112
+ },
113
+ getNativeId: () => {
114
+ return nativeId;
115
+ },
116
+ }));
89
117
  return (
90
- <SkiaDomView
91
- ref={ref}
92
- style={style}
93
- root={root.dom}
94
- onLayout={onLayout}
118
+ <NativeSkiaPictureView
119
+ collapsable={false}
120
+ nativeID={`${nativeId}`}
95
121
  debug={debug}
96
- mode={mode}
97
- {...props}
122
+ opaque={opaque}
123
+ onLayout={onLayout}
124
+ {...viewProps}
98
125
  />
99
126
  );
100
127
  }
101
- ) as FunctionComponent<CanvasProps & React.RefAttributes<SkiaDomView>>;
102
-
103
- /**
104
- * Combines a list of refs into a single ref. This can be used to provide
105
- * both a forwarded ref and an internal ref keeping the same functionality
106
- * on both of the refs.
107
- * @param refs Array of refs to combine
108
- * @returns A single ref that can be used in a ref prop.
109
- */
110
- const useCombinedRefs = <T,>(
111
- ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>
112
- ) => {
113
- const targetRef = React.useRef<T>(null);
114
- React.useEffect(() => {
115
- refs.forEach((ref) => {
116
- if (ref) {
117
- if (typeof ref === "function") {
118
- ref(targetRef.current);
119
- } else {
120
- ref.current = targetRef.current;
121
- }
122
- }
123
- });
124
- }, [refs]);
125
- return targetRef;
126
- };
128
+ );
@@ -0,0 +1,126 @@
1
+ import React, {
2
+ useEffect,
3
+ useCallback,
4
+ useMemo,
5
+ forwardRef,
6
+ useRef,
7
+ } from "react";
8
+ import type {
9
+ RefObject,
10
+ ReactNode,
11
+ MutableRefObject,
12
+ ForwardedRef,
13
+ FunctionComponent,
14
+ } from "react";
15
+ import type { LayoutChangeEvent } from "react-native";
16
+
17
+ import { SkiaDomView } from "../views";
18
+ import type { SkiaBaseViewProps } from "../views";
19
+
20
+ import { SkiaRoot } from "./Reconciler";
21
+
22
+ export const useCanvasRef = () => useRef<SkiaDomView>(null);
23
+
24
+ export interface CanvasOldProps extends SkiaBaseViewProps {
25
+ ref?: RefObject<SkiaDomView>;
26
+ children: ReactNode;
27
+ mode?: "default" | "continuous";
28
+ }
29
+
30
+ const useOnSizeEvent = (
31
+ resultValue: SkiaBaseViewProps["onSize"],
32
+ onLayout?: (event: LayoutChangeEvent) => void
33
+ ) => {
34
+ return useCallback(
35
+ (event: LayoutChangeEvent) => {
36
+ if (onLayout) {
37
+ onLayout(event);
38
+ }
39
+ const { width, height } = event.nativeEvent.layout;
40
+
41
+ if (resultValue) {
42
+ resultValue.value = { width, height };
43
+ }
44
+ },
45
+ [onLayout, resultValue]
46
+ );
47
+ };
48
+
49
+ export const CanvasOld = forwardRef<SkiaDomView, CanvasOldProps>(
50
+ (
51
+ {
52
+ children,
53
+ style,
54
+ debug,
55
+ mode = "default",
56
+ onSize: _onSize,
57
+ onLayout: _onLayout,
58
+ ...props
59
+ },
60
+ forwardedRef
61
+ ) => {
62
+ const onLayout = useOnSizeEvent(_onSize, _onLayout);
63
+ const innerRef = useCanvasRef();
64
+ const ref = useCombinedRefs(forwardedRef, innerRef);
65
+ const redraw = useCallback(() => {
66
+ innerRef.current?.redraw();
67
+ }, [innerRef]);
68
+ const getNativeId = useCallback(() => {
69
+ const id = innerRef.current?.nativeId ?? -1;
70
+ return id;
71
+ }, [innerRef]);
72
+
73
+ const root = useMemo(
74
+ () => new SkiaRoot(redraw, getNativeId),
75
+ [redraw, getNativeId]
76
+ );
77
+
78
+ // Render effect
79
+ useEffect(() => {
80
+ root.render(children);
81
+ }, [children, root, redraw]);
82
+
83
+ useEffect(() => {
84
+ return () => {
85
+ root.unmount();
86
+ };
87
+ }, [root]);
88
+
89
+ return (
90
+ <SkiaDomView
91
+ ref={ref}
92
+ style={style}
93
+ root={root.dom}
94
+ onLayout={onLayout}
95
+ debug={debug}
96
+ mode={mode}
97
+ {...props}
98
+ />
99
+ );
100
+ }
101
+ ) as FunctionComponent<CanvasOldProps & React.RefAttributes<SkiaDomView>>;
102
+
103
+ /**
104
+ * Combines a list of refs into a single ref. This can be used to provide
105
+ * both a forwarded ref and an internal ref keeping the same functionality
106
+ * on both of the refs.
107
+ * @param refs Array of refs to combine
108
+ * @returns A single ref that can be used in a ref prop.
109
+ */
110
+ const useCombinedRefs = <T,>(
111
+ ...refs: Array<MutableRefObject<T> | ForwardedRef<T>>
112
+ ) => {
113
+ const targetRef = React.useRef<T>(null);
114
+ React.useEffect(() => {
115
+ refs.forEach((ref) => {
116
+ if (ref) {
117
+ if (typeof ref === "function") {
118
+ ref(targetRef.current);
119
+ } else {
120
+ ref.current = targetRef.current;
121
+ }
122
+ }
123
+ });
124
+ }, [refs]);
125
+ return targetRef;
126
+ };
@@ -14,7 +14,7 @@ const drawOnscreen = (Skia: Skia, nativeId: number, recording: Recording) => {
14
14
 
15
15
  const rec = Skia.PictureRecorder();
16
16
  const canvas = rec.beginRecording();
17
- // const start = performance.now();
17
+ //const start = performance.now();
18
18
 
19
19
  const ctx = createDrawingContext(Skia, recording.paintPool, canvas);
20
20
  replay(ctx, recording.commands);
@@ -87,13 +87,17 @@ class ReanimatedContainer extends Container {
87
87
  commands: record.commands,
88
88
  paintPool: record.paintPool,
89
89
  };
90
+ const { nativeId, Skia, recording } = this;
90
91
  if (animationValues.size > 0) {
91
- const { nativeId, Skia, recording } = this;
92
92
  this.mapperId = Rea.startMapper(() => {
93
93
  "worklet";
94
94
  drawOnscreen(Skia, nativeId, recording!);
95
95
  }, Array.from(animationValues));
96
96
  }
97
+ Rea.runOnUI(() => {
98
+ "worklet";
99
+ drawOnscreen(Skia, nativeId, recording!);
100
+ })();
97
101
  }
98
102
  }
99
103