question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot zoom in the same function where addImg was performed

See original GitHub issue

Thanks for a great package! I have been using react-sketch for building image processing applications, such as http://dash-canvas.herokuapp.com/. My app is a component which has a SketchField child component, as in the demo for this repo. After performing some image processing operation, I’m updating the image through props using this._sketch.addImg, but I also would like to keep the same zoom factor which was used just before firing the image processing operation. My problem is that I cannot make the canvas zoom just after addImg, in the same function: the image is updated, but no zoom is performed. Surprisingly, if I add a breakpoint between the two operations and I run the function in the debugger, the zoom operation is performed as expected. Here is the code of the componentDidUpdate function (I checked that the problem is still there if the two operations – addImg and zoom-- are in another function, no zoom is performed).

   componentDidUpdate(prevProps) {
   let sketch = this._sketch;
      if (
          (this.props.image_content !== prevProps.image_content)){
          let opts = {left:0,
                      top:0,
                      scale:this.props.scale}
          sketch.addImg(this.props.image_content, opts); // OK, the image updates
          sketch.zoom(this.props.zoom); // not OK, nothing happens, except in the debugger
      };
      };

Any idea of how I can force the zoom to be performed?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tboliscommented, Jan 11, 2019

unfortunately nothing that comes in mind right now, will take a closer look

0reactions
emmanuellecommented, Jan 12, 2019

I solved the issue by calling sketch._fc.setZoom instead of sketch.zoom. By the way, why is SketchField.zoom not calling Canvas.setZoom (of fabric.js)? I found out it’s instead modifying the scale and position of all objects of the canvas. For the record, my new code is

 componentDidUpdate(prevProps) {
    let sketch = this._sketch;
    if (
	(this.props.image_content !== prevProps.image_content)){
	sketch.clear();
	this.props.setProps({json_data: ''});
	let opts = {left:0,
	 	    top:0,
	            scale:this.props.scale}
	sketch.addImg(this.props.image_content, opts);
	sketch._fc.setZoom(this.props.zoom);
    };    
    };

and it works as I want (adding the image and setting the correct zoom).

Thanks a lot for your help, feel free to close the issue or I’ll do it later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enabling breakout rooms - Zoom Support
Breakout rooms allow you to split your Zoom meeting in up to 50 separate sessions. The meeting host can choose to split the...
Read more >
Using host and co-host controls in a meeting - Zoom Support
Host controls allow you as the host to control various aspects of a Zoom meeting, such as managing the participants. The co-host feature......
Read more >
Managing breakout rooms - Zoom Support
Breakout room participants will have the same audio, video, and screen share capabilities as allowed in the main session.
Read more >
Managing participants in a meeting - Zoom Support
Windows | macOS. Sign in to the Zoom desktop client. Start a meeting. Click Participants in the host controls to open the Participants...
Read more >
Enabling and adding a co-host - Zoom Support
The host is the only user who can assign a co-host. There is no limitation on the number of co-hosts you can have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found