diegomura / react-pdf

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

Dynamic content not showing inside flex elements in v2.0 #1300

Open DanielBerrocal opened 3 years ago

DanielBerrocal commented 3 years ago

Describe the bug Hi, I've working with the 1.6.16 version for a couple of weeks, everything went fine. I had a couple of dynamic content renders in my code, mainly to show the page number as part of a header. I updated the library to the latest version yesterday and noticed that the page number is not showing anymore. I found out that if I delete the flex properties in the header, the page number does appear, but that messes up the whole set up of the header. Do you have any idea about why is this happening?

To Reproduce The JSX document I'm using is basically this:

 <Document>
      <Page size={LETTER} syle={styles.somePadding}>
          <View style={styles.flexRow} fixed>
              <Image source={"someImage"} />
              <Text>Some header Text</Text>
              <Text render={({pageNumber}) => (`${pageNumber}`)}  />
          </View>
      </Page>
  </Document>

"flexRow" and "somePadding" are defined as: somePadding: { padding: "72pt 72pt", },

flexRow:{ display: "flex", justifyContent: "space-between", flexDirection: "row", alignItems: "center", },

Expected behavior The page number should render, even if the containing view has flex properties

Screenshots Captura de pantalla de 2021-05-05 16-30-44 Captura de pantalla de 2021-05-05 16-31-21

Desktop (please complete the following information):

ajitbohra commented 3 years ago

Experience similar with dynamic content on view

dominikpegler commented 3 years ago

can confirm the issue.

Conditional rendering like below works only if

Not working means, that it breaks the rendering, A font size of 9 or 12 will not break the rendering, but the rendered component will not be on the PDF.

dominikpegler commented 3 years ago

Does anybody know a workaround to this?

TheoOliveira commented 2 years ago

For me, it seems remove flex attribute worked @dominikpegler

TheoOliveira commented 2 years ago

Probably something related to browser rendering issues towards flex

steven-wilson-crl commented 2 years ago

In my case, I am trying to dynamically render tabular data, but flex settings are ignored. In this case, it recognizes the flexDirection and stacks them horizontally, but with no regard to sizing each element with respect to its flex style

<View style={{ flexDirection: 'row', flexWrap: 'nowrap' }}>
  <View style={{ flex: 1 }}>
    <Text>{'Column 1'}</Text>
  </View>
  <View style={{ flex: 3 }}>
    <Text>{'Column 2'}</Text>
  </View>
  <View style={{ flex: 6 }}>
    <Text>{'Column 3'}</Text>
  </View>
</View>