@@ -8,7 +8,7 @@ import React, {
8
8
useRef ,
9
9
} from 'react' ;
10
10
11
- import { Canvas , ImageSVG , Skia , SkSVG } from '@shopify/react-native-skia' ;
11
+ import { Canvas , ImageSVG , Skia , SkSVG , useCanvasRef } from '@shopify/react-native-skia' ;
12
12
13
13
import { View } from 'react-native' ;
14
14
@@ -55,6 +55,7 @@ function SkiaComponent(
55
55
const [ width , setWidth ] = useState < number > ( initialWidth ?? 0 ) ;
56
56
const [ height , setHeight ] = useState < number > ( initialHeight ?? 0 ) ;
57
57
const zrenderId = useRef < number > ( ) ;
58
+ const canvasRef = useCanvasRef ( ) ;
58
59
59
60
const dispatchEvents = useCallback < DispatchEvents > (
60
61
( types , nativeEvent , eventArgs ) => {
@@ -86,6 +87,10 @@ function SkiaComponent(
86
87
setZrenderId : ( id : number ) => {
87
88
zrenderId . current = id ;
88
89
} ,
90
+ makeImageSnapshot : ( ) => {
91
+ const image = canvasRef . current ?. makeImageSnapshot ( ) ;
92
+ return image ? `data:image/png;base64,${ image . encodeToBase64 ( ) } ` : null ;
93
+ }
89
94
} ,
90
95
viewprot : { } ,
91
96
dispatchEvents,
@@ -101,7 +106,7 @@ function SkiaComponent(
101
106
102
107
return svgString ? (
103
108
< View testID = "component" style = { { ...style , width, height } } >
104
- < Canvas style = { { ...style , width, height } } pointerEvents = "auto" >
109
+ < Canvas style = { { ...style , width, height } } pointerEvents = "auto" ref = { canvasRef } >
105
110
< ImageSVG svg = { svgString } x = { 0 } y = { 0 } width = { width } height = { height } />
106
111
</ Canvas >
107
112
{ handleGesture ? (
0 commit comments