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.

Single Wrapper, multiple Components

See original GitHub issue

Hi, I would like to have two images side by side that share the same TransformWrapper. The idea is that zooming or panning on one of the images also affects the scale and translation of the other. If I put two TransformComponents in the same TransformWrapper, I can only pan and zoom on the second one, although the effect are correctly applied to both components. Having a quick look at the code, it seems that it’s because a TransformWrapper only expects to have a single TransformComponent inside. Is there a way to enable the events also on the first image? The following is the pseudocode of my current approach:

      <TransformWrapper>
        <Row>
          <LeftCol>
            <TransformComponent>
              <Image1 />
            </TransformComponent>
          </LeftCol>
          <RightCol>
            <TransformComponent>
              <Image2 />
            </TransformComponent>
          </RightCol>
        </Row>
      </TransformWrapper>

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

5reactions
bmangacommented, Apr 16, 2020

@sgentry I ended up writing the following:

function SideBySideSyncView(props) {
  const [scale, setScale] = useState(1);
  const [positionX, setPositionX] = useState(0);
  const [positionY, setPositionY] = useState(0);

  function update(stats) {
    setScale(stats.scale);
    setPositionX(stats.positionX);
    setPositionY(stats.positionY);
  }

  return (
    <Row>
      <LeftCol>
        <TransformWrapper
          positionX={positionX}
          positionY={positionY}
          scale={scale}
          onZoomChange={update}
          onPanning={update}
          onPanningStop={update}
          doubleClick={{ disabled: true }}
          reset={{ disabled: true }}
          pan={{ paddingSize: 0, velocityBaseTime: 0 }}
          scalePadding={{ disabled: true }}
        >
          <TransformComponent>{props.leftComponent}</TransformComponent>
        </TransformWrapper>
      </LeftCol>
      <RightCol>
        <TransformWrapper
          positionX={positionX}
          positionY={positionY}
          scale={scale}
          onZoomChange={update}
          onPanning={update}
          onPanningStop={update}
          doubleClick={{ disabled: true }}
          reset={{ disabled: true }}
          pan={{ paddingSize: 0, velocityBaseTime: 0 }}
          scalePadding={{ disabled: true }}
        >
          <TransformComponent>{props.rightComponent}</TransformComponent>
        </TransformWrapper>
      </RightCol>
    </Row>
  );
}
0reactions
minhdongssscommented, Oct 30, 2020

you’re perfect, @bmanga ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Create Wrapper Components in React with Props
In this tutorial, you'll create wrapper components with props ... to a single prop; you can pass elements to as many props as...
Read more >
How to organize one React component with different wrapper ...
I am looking for a better, more elegant solution. I've tried sending the wrapper components to the Item but React doesn't allow to...
Read more >
How to Wrap One React Component into Another | Pluralsight
High-Level View Of HOCs. HOC design pattern is applied by many modules as a way of inserting functionality from the module into the...
Read more >
React tutorial for beginners 2021 - Understanding Wrapper ...
In this tutorial video I talk about what Wrapper Components are and how you use ... It's a lengthy video on the topic,...
Read more >
Using Wrapper Components in React | Tutorial - YouTube
In this video you will see how to use Wrapper Components in React.I hope this video can help you. ... Learn more. Switch...
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