-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
image must be initialized with a canvas instance #133
Comments
Make sure to create handleCanvas = canvas => {
const image = new CanvasImage(canvas);
} |
handleCanvas = canvas => {
const { canvasHeight, canvasWidth, imgSrc } = this.props;
const image = new CanvasImage(canvas);
canvas.height = canvasHeight;
canvas.width = canvasWidth;
const ctx = canvas.getContext("2d");
const rectX = 0;
const rectY = 0;
const rectWidth = canvasWidth;
const rectHeight = canvasHeight;
ctx.lineJoin = "round";
image.src = `${RNFS.MainBundlePath}/assets/${imgSrc}`;
image.addEventListener(
"load",
(drawImageCanvas = () => {
ctx.drawImage(image, rectX, rectY, rectWidth, rectHeight);
})
);
this.setState({ canvas: canvas });
}; |
This error show me after Actions.pop() or replace |
@iddan, please help! image.removeEventListener() not working |
|
@iddan, how can I fix this problem? |
@iddan, please, I need help |
You can implement it if you'd like: take a look at how |
Hi, @iddan, I alse have this problem. I got import Canvas, { Image as CanvasImage } from 'react-native-canvas';
import RNFS from 'react-native-fs';
const _handleCanvas = (canvas) => {
const image = new CanvasImage(canvas);
canvas.width = 500;
canvas.height = 500;
image.src = `${RNFS.MainBundlePath}/${viewerData[0].path}`;
console.log('image src: ', image.src);
// the log here is `undefined/../../images/3.jpg`
const context = canvas.getContext('2d');
image.addEventListener('load', () => {
context.drawImage(image, 0, 0, 500, 500);
});
};
return (
<View>
<Canvas ref={_handleCanvas} />
</View>
) |
Needs investigation. Currently, I'm not available. |
Canvas is not initialized when calling new CanvasImage. Something to do with render method of react-native. Seems I solved the problem with little workaround. Checking if canvas is set before CanvasImage does its own check. handleCanvas = (canvas) => {
if (!(canvas instanceof Canvas)) {
return;
}
const image = new CanvasImage(canvas); |
Oh right, refs in React can be |
The text was updated successfully, but these errors were encountered: