diegomura / react-pdf

📄 Create PDF files using React
https://react-pdf.org
MIT License
14.77k stars 1.17k forks source link

Under the View dynamic render the Svg element scaling will not working #1752

Open posebear1990 opened 2 years ago

posebear1990 commented 2 years ago

Describe the bug If the Svg is rendered under the render prop of the View element, then the scaling of the Svg will not working.

To Reproduce See: react-pdf REPL No matter how we set width and height, the size of svg will not change.

Expected behavior Scaling can working as expected

Screenshots

image

Desktop (please complete the following information):

stuffaboutpete commented 1 week ago

Any word on this? I'm new to the library and love it but quickly came across this bug. I've made an alternative example - toggle the boolean at the top and I believe in theory, it should be rendered identically whether it's through dynamic rendering or not.

REPL

const dynamicRendering = false;

const Image = () => (
  <Svg width="200" height="200" viewBox="-100 -100 200 250" debug>
    <Polygon points="0,0 80,120 -80,120" fill="#234236" />
    <Polygon points="0,-40 60,60 -60,60" fill="#0C5C4C" />
    <Polygon points="0,-80 40,0 -40,0" fill="#38755B" />
    <Rect x="-20" y="120" width="40" height="30" fill="#A32B2D" />
  </Svg>
);

const WrappedImage = () => (
  <View style={{ position: 'absolute', top: 0, left: 0 }}>
    <Image />
  </View>
);

const Example = () => (
  <Document>
    <Page>
      <Text>Page One</Text>
      {dynamicRendering === false && <WrappedImage />}
      {dynamicRendering === true && <View fixed render={() => <WrappedImage />}></View>}
      <Text break>Page Two</Text>
    </Page>
  </Document>
);

ReactPDF.render(<Example />);