Replies: 1 comment
-
I have the same issue. When user tap and hold, triggers - "onStart" but no "onActive" on move, immediately after start moving triggers "onEnd" android simulator - 34 API version import { Canvas, Path, Skia, useCanvasRef, useTouchHandler } from '@shopify/react-native-skia';
import React, { forwardRef, useEffect, useImperativeHandle } from 'react';
const activePath = Skia.Path.Make();
export const SignaturePad = forwardRef<SignaturePad, SignaturePadProps>(({ height, width, onUpdate }, ref) => {
const canvasRef = useCanvasRef();
useEffect(() => {
return () => {
activePath.reset();
};
}, []);
useImperativeHandle(ref, () => ({
clear: () => {
activePath.reset();
onUpdate?.('');
},
}));
const onTouch = useTouchHandler({
onStart: ({ x, y }) => {
activePath.moveTo(x, y);
},
onActive: ({ x, y }) => {
activePath.lineTo(x, y);
},
onEnd: () => {
console.log('END', Date.now());
},
});
return (
<Canvas ref={canvasRef} style={{ height, width, backgroundColor: 'white' }} onTouch={onTouch}>
<Path path={activePath} />
</Canvas>
);
});
type SignaturePadProps = {
width: number;
height: number;
onUpdate?: (img: string) => void;
};
export type SignaturePad = {
clear: () => void;
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm using canvas to be able to draw a signature, but on Android it can't work. Canvas can't draw strokes on Android, but when I use const
image = refCanvas.current?.makeImageSnapshot();
andconst base64 = image?.encodeToBase64();
I still get the image I drew.Here is my code:
<Canvas ref={refCanvas} onTouch={touchHandler} style={styles.vCanvas}> {paths.map((path, index) => { const findStroke = PStroke?.find(elm => elm.index === index); return ( <Path key={index?.toString()} path={path} style="stroke" strokeCap="round" color={findStroke?.valueColor || selectStroke.color} strokeWidth={findStroke?.valueWidth || selectStroke.width.value} /> ); })} </Canvas>
It's very basic but it can't be displayed, on IOS it works normally.
IOS:
Screen.Recording.2024-01-11.at.15.05.55.mov
Android:
Screen.Recording.2024-01-11.at.15.03.29.mov
Beta Was this translation helpful? Give feedback.
All reactions