I cannot figure out how I can send the size of the parent view to the child component. In renderPager (), I want to calculate some parameters that depend on the size of the parent view. I know that we can do this through onLayout (). the problem is that onLayout will be called only after creating all the children (I see it in the console log). How can i do this?
onPageLayout = (event) => {
const { width, height } = event.nativeEvent.layout;
console.log("ON LAYOUT");
};
render() {
return (
<View
style={styles.root}
onLayout={this.onPageLayout}
>
{this.renderPager()}
</View>
);
}
renderPager = () => {
return (
<IndicatorViewPager
ref={(ref) => (this.viewPager = ref)}
scrollEnabled={!this.state.isDragging}
onPageScroll={this.onPageScroll}
style={styles.pageRoot}
>
{this.renderPages()}
</IndicatorViewPager>
);
};
Thank you
source
share