Unable to resize Canvas
See original GitHub issueAfter resizing the canvas, I am unable to draw any element. No error is raised, simply nothing appears on the canvas.
render() {
return (
<Canvas ref={this.renderCanvas} style={{backgroundColor: "red"}} />
)
}
renderCanvas = (canvas) => {
canvas.width = 400;
canvas.height = 600;
const context = canvas.getContext('2d');
context.globalAlpha = 1.0;
context.fillStyle = 'green';
context.fillRect(0, 130, 50, 50);
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Cannot resize Canvas in edit mode - Unity Forum
Ah yes, I knew that, but thought it was still possible to drag it around temporarily. And it is - but you have...
Read more >Resizing canvas, where's the problem? - Stack Overflow
If the pictures height becomes to big for the window then the picture should resize itself according to the height and not the...
Read more >Cannot resize canvas - Figma Community Forum
Hello, I am new to Figma and It's been quite hard to find a way to resize the canvas (like making it longer...
Read more >Unable to resize Canvas - Lucidchart Help
First, if you ensure Auto-Tiling is turned off in the Page Settings menu, tabs will appear in the corner of your document which...
Read more >Canvas size not adjusting correctly - Adobe Support Community
In the Layers panel, drag the layer out from under any Artboards so that it's out on its own. As soon as you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve had success with this by
ref
callback to store a reference to the canvas on the componentcomponentDidMount
to resize the canvas initiallycomponentDidUpdate
to draw shapes based onprops
You could do the drawing in
componentDidMount
as well, if you don’t need the canvas to redraw based on user input or whatever. Here’s an example of what I mean:@omnikron Thanks Oli, your approach worked! @iddan I still believe that this should somehow be clarified/simplified… thanks!