Temel olarak, boyutu ayarlamak ve değişmesini istiyorsanız, aşağıdaki gibi düzende belirtin:
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, View } from 'react-native';
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'yellow',
},
View1: {
flex: 2,
margin: 10,
backgroundColor: 'red',
elevation: 1,
},
View2: {
position: 'absolute',
backgroundColor: 'orange',
zIndex: 3,
elevation: 3,
},
View3: {
flex: 3,
backgroundColor: 'green',
elevation: 2,
},
Text: {
fontSize: 25,
margin: 20,
color: 'white',
},
});
class Example extends Component {
constructor(props) {
super(props);
this.state = {
view2LayoutProps: {
left: 0,
top: 0,
width: 50,
height: 50,
}
};
}
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 });
}
render() {
return (
<View style={styles.container}>
<View style={styles.View1}>
<Text>{this.state.view2LayoutProps.height}</Text>
</View>
<View onLayout={(event) => this.onLayout(event)}
style={[styles.View2, this.state.view2LayoutProps]} />
<View style={styles.View3} />
</View>
);
}
}
AppRegistry.registerComponent(Example);
Bunu başka bir görünümde sarmalayıcı olarak kullanan başka bir bileşende kullanarak nasıl değiştirileceğine ilişkin çok daha fazla varyasyon oluşturabilir ve dokunma olayı konumunu duruma geçirebilecek bir onResponderRelease geri çağrısı oluşturabilirsiniz. onLayout güncellenmiş durumunu geçersiz kılabilen özellik olarak yerleştirerek {[styles.View2, this.state.view2LayoutProps, this.props.touchEventTopLeft]}vb.