-
Notifications
You must be signed in to change notification settings - Fork 171
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
Problem with resizing canvas #134
Comments
Posted as a new issue since the previous thread was already closed when I posted the comment... Sorry. |
Do you pass width and height to your component? |
Yes. I've confirmed it. The width and height are being passed.
I've also added code to restore the original image and it restores but as soon as I press to draw, it goes back to the altered canvas that I had before I restored the image to the original one.
|
I removed the need to draw the image on the react native canvas by drawing it with a regular Image component and overlaying the react-native-canvas component on top of the image by using absolute positioning. However, I can't resize the component without facing the same problems. As in, it doesn't draw anything on the canvas after having been resized. |
i'm having the same issue, any solutions? |
I'm facing the same problem as well. @iddan do you perhaps have an example where a Canvas has dimensions X, resizes to dimensions Y, draws something and it shows up? Just to rule out us doing something wrong. Edit: I looked into it more and it appears that this is expected behaviour. When the Note that this might just be me and the others their problem is slightly different. I'll update this if I find myself in the same situation as they are. That being said, this example draws a rectangle on the canvas, resizes the canvas and draws a new rectangle: https://gist.github.com/Vannevelj/eca9ab7da0d543c84964ecdbcad00879 |
Found a possible fix since it worked for me: |
(sorry if this is hijacking this issue but I think this is related) The problem with the technique @dandan-drori mentioned is that the transformation matrix is no longer the identity matrix. I confirmed this by manually exposing the
It seems this is related to my current issue where scaling/translating isn't working as expected. I think ideally the Canvas would accept a Example function passed to function handleCanvas(canvas) {
canvas.width = myCalculatedWidth;
canvas.height = myCalculatedHeight;
} I'm testing this on an iPad using Expo Go with React Native and Expo for reference. EDIT: Oh, I've just noticed autoScaleCanvas so it seems the default matrix being non-identity is intended. I'll have to see if I can work around this but it seems to still be causing issues. |
Similar to @dandan-drori , I used the Also, TypeScript was showing an error when I tried to pass in the width and height as props for some reason, so I skipped those.
|
@James-Firth Hi, I am experiencing similar issues with scaling, did you manage to find a work around? |
I've been having the same problem. This is my code:
From what is written here, it should work.
I narrowed down the problem to the resizing. It looks like resizing changes the reference to the canvas?
On my componentDidMount if I leave the canvas.width and height assignments, nothing shows up. If I comment it how, I get a canvas that's too small (300x150px instead of 300x400) but everything works.
I installed react-native-canvas 2 days ago so it should be the most up-to-date...
Originally posted by @edbrito in #94 (comment)
The text was updated successfully, but these errors were encountered: