Reputation: 979
I use 0.21.0 react native, I have one custom component.
for animated, I find solution to get height. width is get using Dimension. but height is not same.
How do I get height of my component?
Upvotes: 1
Views: 6813
Reputation: 6204
As @Chris Geirman pointed out in the comment, you can use onLayout
for this. Here an example to get the height of this component:
var CustomComponent = React.createClass({
getInitialState: function() {
return { componentHeight: 0 };
},
render: function() {
return (
<View onLayout={this._onLayoutEvent}>
<Text>This is my Custom Component</Text>
</View>
);
},
_onLayoutEvent: function(event) {
this.setState({componentHeight: event.nativeEvent.layout.height});
}
});
Now you have access to the height of the component as this.state.componentHeight
.
Upvotes: 4