所以我想以一种非正统的方式使用 RN Section list。
我希望部分列表将渲染传递给组件,因为渲染不会很统一。
我想使用部分列表,以便在滚动时仍然可以看到标题。
我制作了一个组件,它接收孩子并将它们呈现在一个部分列表中,如下所示:
class SomeSectionList extends Component {
render() {
let sections = React.Children.map(this.props.children, (Child, index) => {
return {title: Child.type.title, data: [''], renderItem: () => Child, index }
});
return (
<SectionList
renderSectionHeader={({section}) => {
return <Text style={{ fontWeight: "bold" }}>{section.title}</Text>
}}
sections={sections}
keyExtractor={(item, index) => item + index}
/>
);
}
}
用法如下:
<SomeSectionList>
<Comp1 />
<Comp2 />
</SomeSectionList>
但是,我的问题是。假设在这种情况下 Comp1 不会从它的组件中渲染任何东西,我希望能够从部分列表中隐藏它的部分。
组件怎么会SomeSectionList
知道它没有渲染任何东西或没有数据来渲染任何东西,所以它可以隐藏它的部分和标题?
任何建议都会很棒。我觉得为此使用 SectionList 有点矫枉过正(但它可以更好地显示标题),因此也对替代方案持开放态度。