React Native:ListView中的粘滞部分标题不粘

时间:2017-05-13 20:19:46

标签: react-native

ListView used to say中的renderSectionHeader文档"如果提供,则为此部分呈现粘性标题。粘性行为意味着它将与该部分顶部的内容一起滚动,直到它到达屏幕顶部,此时它将粘在顶部,直到它被下一部分标题推离屏幕。&# 34;

但是,它已被删除,now just says"如果提供,则会为此部分呈现标题。"

他们添加了两个道具stickyHeaderIndicesstickySectionHeadersEnabled。我对它们的启示如下:

<ListView
         style={styles.container}
         dataSource={this.state.dataSource}
         renderRow={(data) => <Row {...data} />}
         renderSeparator={(sectionId, rowId) => <View key={rowId} style={styles.separator} />}
         renderSectionHeader={(sectionData) => <SectionHeader {...sectionData} />}
         stickySectionHeadersEnabled = {true}
         stickyHeaderIndices={[0]}
       />

但是,在iOS模拟器上,我的标题并不粘。我没有尝试在设备上运行它。

2 个答案:

答案 0 :(得分:0)

可能有三个原因: -

1)我假设您正在使用行和部分克隆数据,如果没有,那么就这样做:

this.setState({
    dataSource: this.state.dataSource.cloneWithRowsAndSections(this.state.data)
})

2)第一个原因是你在scrollview中使用listView ..

3)您不必为iOS提供stickySectionHeadersEnabled = {true}。请删除并重试。

4)如果您使用的是反应原生版本0.42-0.43,请将其升级到0.44,这样就可以解决问题。 (主要是为了安卓)

5)让我们检查代码。

干杯:)

答案 1 :(得分:0)

如果您的ListView在NavigatorIOS中,则部分标题可能会在半透明导航栏后面消失。

为了解决这个问题,请将半透明= {false}添加到NagigatorIOS:

<NavigatorIOS 
  translucent={false}
  ...
/>

它比设置paddingTop更好,因为导航栏的高度可能因iPad / iPhone或方向而异。

相关问题