I am attempting to pass a shared component to a <View fixed>
element, however it appears that the output has missing style properties...
It appears that the child component's styling is preserved, but any grandchildren do not...
Further investigation shows that even hardcoding all of the <View>
, <Text>
and style
also results in nested elements being stripped...
Is there any reason why this is happening? Is there a way in which I can get the styles included?
const TableHeaders = () => (
<TableRow>
{['name', 'age', 'location'].map(label =>
<TableCell>{label}</TableCell>)}
</TableRow>
);
const TableRow = ({children}) => <View style={styles.row}>{children}</View>;
const TableCell = ({children}) => (
<View style={styles.column}>
<Text>{children}</Text>
</View>
);
const FixedHeader = () => <View fixed render={() => <TableHeaders />} />;
const HardcodedHeader = () => (
<View render={() => (
<View style={styles.row}>
{['name', 'age', 'location'].map(label => (
<View style={styles.column}>
<Text>{label}</Text>
</View>
))}
</View>
)} />
)
const HardcodedHeaderWithHardcodedStyles = () => (
<View render={() => (
<View style={{
flexDirection: 'row',
backgroundColor: 'lightblue',
borderRadius: 4,
margin: '2px 0',
padding: '10px 7px'
}}>
{['name', 'age', 'location'].map(label => (
<View style={{
margin: '0 5px',
fontSize: 10,
color: 'red'
}}>
<Text>{label}</Text>
</View>
))}
</View>
)} />
)
const Quixote = () => (
<Document>
<Page style={styles.body}>
<TableHeaders />
<FixedHeader />
<HardcodedHeader />
<HardcodedHeaderWithHardcodedStyles />
</Page>
</Document>
);
const styles = StyleSheet.create({
column: {
margin: '0 5px',
fontSize: 10,
color: 'red'
},
row: {
flexDirection: 'row',
backgroundColor: 'lightblue',
borderRadius: 4,
margin: '2px 0',
padding: '10px 7px'
},
body: {
paddingTop: 35,
paddingBottom: 65,
paddingHorizontal: 35,
}
});
ReactPDF.render(<Quixote />);