[英]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
条件是处理内容的条件,因此您有多种选择来实现这一点:
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.