简体   繁体   English

如何在 React Native 中隐藏 Accordion 特定内容

[英]How can I hide Accordion Specific Content in React Native

In this example, I want to show and hide feature for the content of accordion.在这个例子中,我想显示和隐藏手风琴内容的特征。 This is my source code.这是我的源代码。

state = {
    check: true,
};

 renderContent = (order, _, isActive) => {
    //Accordion Content   
    return (
         <View style={styles.child}>
                   <View>
                     <Text>Hello World</Text>
                   </View>

                   <View>
                     <Text>Goodbye</Text>
                   </View>
                }
         </View>
        )
}

render() {
    return (
        <View style={styles.scrollMain}>
                <CheckBox
                    value = { this.state.check}
                    onValueChange={(newValue) => this.setState({check:newValue})}/> // this is my checkbox
                <Accordion
                    .....
                    renderContent={this.renderContent}
                    }/> 
            }
        </View>
    );

What I want to do is if I click to checkbox, it should hide this content below我想要做的是,如果我点击复选框,它应该在下面隐藏这个内容

                `<View>
                  <Text>Goodbye</Text>
                </View>`

When I uncheck checkbox it should go back.当我取消选中复选框时,它应该 go 回来。 Give me please idea how I can do it?请告诉我我该怎么做?

Hi you almost have it done, you just have to think the this.state.check condition is the one that will handle the content so you have several options to achieve this:嗨,您几乎完成了,您只需要认为this.state.check条件是处理内容的条件,因此您有多种选择来实现这一点:

  • You can create another component to handle this logic.您可以创建另一个组件来处理此逻辑。
  • Instead use a JSX block to handle this logic.而是使用JSX块来处理此逻辑。
  • Or you can use css with a class or something similar to just hide the content but the elements will always exist.或者您可以使用css和 class 或类似的东西来隐藏内容但元素将始终存在。

I think that this decision invovles your use case but a straightforward way to do it is encapsulating the logic in a JSX block我认为这个决定涉及到您的用例,但一种直接的方法是将逻辑封装在JSX块中

renderContent = (order, _, isActive) => {
    //Accordion Content   
    return (
         <View style={styles.child}>
                   <View>
                     <Text>Hello World</Text>
                   </View>

                   {
                    !this.state.check?
                     <View>
                      <Text>Goodbye</Text>
                     </View> 
                    : null
                   }
                }
         </View>
        )
}

Try this condition, if you want other behaviors just tell me试试这个条件,如果你想要其他行为就告诉我

     renderContent = (order, _, isActive) => {
    //Accordion Content   
    return (
         <View style={styles.child}>
                   <View>
                     <Text>Hello World</Text>
                   </View>

                {!this.state.check &&
                   <View>
                     <Text>Goodbye</Text>
                   </View>}
                }
         </View>
        )
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从用户位置显示/隐藏特定内容? - How can i show/hide specific content from user location? 限制 React Native Flatlist 中的手风琴内容 - Limit accordion content inside React Native Flatlist react native:如何使用平面列表显示数据内容? - react native: How can I display the data content using a flatlist? 如何防止特定状态下的 ScrollTo 做出本机反应? - How can i prevent ScrollTo in specific status react native? 我如何在React Native中从json中选择特定值? - How i can select a specific value from json in react native? 如何从 React Native 中的 html 获取特定数据? - How can I get specific data from html in React Native? 如何在特定屏幕上禁用反应本机堆栈导航器? - How can I disable react native stack navigator on specific screens? 如何使用 react-native 显示/隐藏内容? - How to show/hide content using react-native? 我正在尝试在 React 中制作折叠/手风琴。 但问题是,它不会触发我想要切换的特定内容 - I'm trying to make a collapse/accordion in React. But the problem is, it is not triggering the specific content that i want to toggle 如何在本机反应中隐藏特定屏幕上的底部导航栏? - How to hide bottom navigation bar on a specific screen in react native?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM