你有没有加上
onLayout
MyClass
React.Component
实例(如
componentDidMount
),这是一个事件
来自另一个组件
您可以通过提供
在线布局
回调
属性。这是
react-native
内置组件。
class MyClass extends Component {
onLayout(event) {
const {x, y, height, width} = event.nativeEvent.layout;
const newHeight = this.state.view2LayoutProps.height + 1;
const newLayout = {
height: newHeight ,
width: width,
left: x,
top: y,
};
this.setState({ view2LayoutProps: newLayout });
alert('ok');
}
render() {
return (
<View onLayout={e => this.onLayout(e)} />
)
}
}