admin管理员组文章数量:1300026
I'm trying to display a flatlist with a header ponent, but can't seem to remove the first and last separators.
This is how I'm currently rendering the items.
renderSeparator = () => (
<Separator
marginTop="$unitOne"
marginBottom="$unitOne"
/>
)
render() {
const { newsData } = this.props;
return (
<Container>
{newsData.length > 0
? (
<FlatList
data={newsData}
renderItem={({ item }) => (
item.featured === null && this.renderNews(item)
)}
keyExtractor={item => item.id.toString()}
style={styles.container}
ItemSeparatorComponent={this.renderSeparator}
ListHeaderComponent={this.renderFeaturedNews}
/>
)
: <Placeholder />
}
</Container>
);
}
Any help is much appreciated. Thanks!
I'm trying to display a flatlist with a header ponent, but can't seem to remove the first and last separators.
This is how I'm currently rendering the items.
renderSeparator = () => (
<Separator
marginTop="$unitOne"
marginBottom="$unitOne"
/>
)
render() {
const { newsData } = this.props;
return (
<Container>
{newsData.length > 0
? (
<FlatList
data={newsData}
renderItem={({ item }) => (
item.featured === null && this.renderNews(item)
)}
keyExtractor={item => item.id.toString()}
style={styles.container}
ItemSeparatorComponent={this.renderSeparator}
ListHeaderComponent={this.renderFeaturedNews}
/>
)
: <Placeholder />
}
</Container>
);
}
Any help is much appreciated. Thanks!
Share Improve this question asked Jan 7, 2019 at 9:01 konicakoalakonicakoala 1202 silver badges8 bronze badges 1- Have you tried checking index? – Just code Commented Jan 7, 2019 at 9:03
2 Answers
Reset to default 7I think that will work for you;
<FlatList
data={newsData}
renderItem={({ item, index }) => (
item.featured === null && this.renderNews(item)
)}
keyExtractor={item => item.id.toString()}
style={styles.container}
ItemSeparatorComponent={(index===0 || index === newsData.length - 1) ? null : this.renderSeparator}
ListHeaderComponent={this.renderFeaturedNews}
/>
Don't know what was the situation with FlatList
when this question was asked but right now ItemSeparatorComponenet
won't be generated for last and first.
Rendered in between each item, but not at the top or bottom
Read more here
本文标签: javascriptRemove only first and last separator on react native flatlistStack Overflow
版权声明:本文标题:javascript - Remove only first and last separator on react native flatlist - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741654117a2390655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论