作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在屏幕顶部显示按钮(使用 react-native-scrollable-tab-view )。在按钮下方,我有 ListView
上面有节标题。
Is there a way to get the header to stick to the bottom edge of the tab-view when I am scrolling?
ListView
的部分标题贴在 Facebook TabBar 的底部,它的默认值是贴在屏幕的顶部。
Any thoughts on this? Is there anything I should change in FacebookTabBar.js to make this work?
catListHeaderContainer: {
padding: 12,
backgroundColor: '#1F2036',
}
var styles = StyleSheet.create({
tab: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingBottom: 10,
},
tabs: {
height: 60,
flexDirection: 'row',
paddingTop: 5,
borderWidth: 0,
borderTopWidth: 0,
borderLeftWidth: 0,
borderRightWidth: 0,
borderBottomColor: 'rgba(0,0,0,0)',
},
activeTabTitle: {
marginTop: 40,
color: '#3B5998',
},
nonActiveTabTitle: {
marginTop: 40,
color: '#BDBDBD',
},
});
最佳答案
ListView 标题不粘,你需要使用 renderSectionHeader
和 cloneWithRowsAndSections
而不是 cloneWithRows
去做这个。
来自 React Native documentation on ListView
renderSectionHeader function
(sectionData, sectionID) => renderable
If provided, a sticky header is rendered for this section. The sticky behavior means that it will scroll with the content at the top of the section until it reaches the top of the screen, at which point it will stick to the top until it is pushed off the screen by the next section header.
getInitialState
:
getInitialState: function() {
return {
dataBlob: {},
dataSource: new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2,
sectionHeaderHasChanged: (s1, s2) => s1 !== s2
}),
}
},
dataBlob
目的。存储它的 key 被认为是
sectionId
为
ListView.DataSource
.在这种情况下,该
sectionId
将是我检索的帖子的日期:
getAllPosts: function() {
api.getAllPosts()
.then((responseData) => {
var tempDataBlob = this.state.dataBlob;
var date = new Date(responseData.posts[0].day).toDateString();
tempDataBlob[date] = responseData.posts;
this.setState({
dataBlob: tempDataBlob
});
;
}).then(() => {
this.setState({
dataSource: this.state.dataSource.cloneWithRowsAndSections(this.state.dataBlob),
loaded: true
})
})
.done();
},
cloneWithRowsAndSections
接受
dataBlob
(在我的例子中,一个对象)作为它的第一个参数,以及
sectionIDs
的可选参数和
rowIDs
.
renderListView
看起来:
renderListView: function() {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderPostCell}
renderSectionHeader={this.renderSectionHeader}
renderFooter={this.renderFooter}
onEndReached={() => {this.getAllPosts(this.state.currentDay)}}
onEndReachedThreshold={40}
style={styles.postsListView} />
)
},
renderSectionHeader
看起来:
renderSectionHeader: function(sectionData, sectionID) {
return (
<View style={styles.section}>
<Text style={styles.sectionText}>{sectionID}</Text>
</View>
)
},
关于react-native - 如何让 ListView 部分标题保持不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31066437/
我是一名优秀的程序员,十分优秀!