在React Native中,如何通过单击屏幕顶部的按钮将视图添加到屏幕底部?
发布于 2017-08-28 11:15:02
根据状态有条件地呈现屏幕底部的视图,并在按钮的OnPress方法中将该状态设置为true
发布于 2017-08-28 12:52:41
我认为更多地了解状态和道具以及react/react-native中的其他基本概念会更好:
https://facebook.github.io/react-vr/docs/components-props-and-state.html
但是您可以这样做:如果您可以将该部分视为false,则需要定义一个状态,然后当按下按钮时,将该状态的值更改为true
import React from 'react';
import {Text,View,TouchableOpacity} from 'react-native';
export default class testComponent extends React.Component {
constructor(){
super()
this.state = {
viewSection :false
}
}
renderBottomComponent(){
if(this.state.viewSection) {
return (
<View>
<Text>Hi!</Text>
</View>
)
}
}
buttonPress=()=>{
this.setState({viewSection:true})
}
render() {
return (
<View >
<TouchableOpacity onPress={this.buttonPress}>
<Text> Click Me!</Text>
</TouchableOpacity>
{this.renderBottomComponent()}
</View>
);
}
}https://stackoverflow.com/questions/45911293
复制相似问题