首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >通过单击Button- REACT本机添加视图

通过单击Button- REACT本机添加视图
EN

Stack Overflow用户
提问于 2017-08-28 11:07:35
回答 2查看 4.5K关注 0票数 0

在React Native中,如何通过单击屏幕顶部的按钮将视图添加到屏幕底部?

EN

回答 2

Stack Overflow用户

发布于 2017-08-28 11:15:02

根据状态有条件地呈现屏幕底部的视图,并在按钮的OnPress方法中将该状态设置为true

票数 2
EN

Stack Overflow用户

发布于 2017-08-28 12:52:41

我认为更多地了解状态和道具以及react/react-native中的其他基本概念会更好:

https://facebook.github.io/react-vr/docs/components-props-and-state.html

但是您可以这样做:如果您可以将该部分视为false,则需要定义一个状态,然后当按下按钮时,将该状态的值更改为true

代码语言:javascript
运行
复制
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>
         );
      }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45911293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档