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.

Is it possible to make it fully controlled?

See original GitHub issue

Something like this

import React, { Component } from "react";

import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";

class Example extends Component {
  const [state, setState] = useState([0, 0, 1]);
  render() {
    return (
      <TransformWrapper
        positionX={state[0]}
        positionY={state[1]}
        scale={state[2]}
        onChange={(newPositionX, newPositionY, newZoom) => setState([newPositionX, newPositionY, newZoom])}
      >
        {({ zoomIn, zoomOut, resetTransform, ...rest }) => (
          <React.Fragment>
            <div className="tools">
              <button onClick={zoomIn}>+</button>
              <button onClick={zoomOut}>-</button>
              <button onClick={resetTransform}>x</button>
            </div>
            <TransformComponent>
              <img src="image.jpg" alt="test" />
              <div>Example text</div>
            </TransformComponent>
          </React.Fragment>
        )}
      </TransformWrapper>
    );
  }
}

Thanks.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
saidmoya12commented, Jul 7, 2021

What do you need? You can use onZoom and onPanning to get changes

const onChangeRZPP = (refWrapper) => {
  console.log(refWrapper.state)
}
...
<TransformWrapper
  onPanning={onChangeRZPP }
  onZoom={onChangeRZPP}

and to set transform externally you can use “useRef”

const  RWrapper = useRef()

onYourFuncionDIspatch = (...newTransform) => {
  RWrapper.current.setTransform(...newTransform)
}
...
<TransformWrapper ref={RWrapper}>
0reactions
peter-jerry-yecommented, Aug 6, 2021

Hi, I’ve tested the new API and it works well.

Here’s my sandbox link just for showing how to use a external state to unify the control if there were another controller.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Experimental implementation of fully controlled dephasing ...
Here, we demonstrate full experimental control of dephasing allowing us to implement arbitrary decoherence dynamics of a qubit.
Read more >
321.366 Acts prohibited on fully controlled-access facilities.
1. It is unlawful for a person, except a person operating highway maintenance equipment or an authorized emergency vehicle, to do any of...
Read more >
Wireless Fan Fully Controlled Using Your Phone! - Instructables
In this project, we will be creating a wireless fan that you can fully control using your phone over WiFi. You can rotate...
Read more >
CDC Updates and Shortens Recommended Isolation and ...
Individuals who have received their booster shot do not need to quarantine following an exposure, but should wear a mask for 10 days...
Read more >
Create forms that users complete or print in Word
Create forms that users complete or print in Word · Start with a form template · Start with a blank document · Insert...
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