如何让 ListView 部分标题固定下来

2024-01-09

我的按钮显示在屏幕顶部(使用反应本机可滚动选项卡视图)。在按钮下面,我有ListView上面有节标题。

当我滚动时,有没有办法让标题粘在选项卡视图的底部边缘?

我很难得到ListView的节标题粘在 Facebook TabBar 的底部,默认情况下粘在屏幕顶部。

当我滚动时,部分标题会滑到选项卡栏下方。

对此有什么想法吗?我应该在 FacebookTabBar.js 中更改什么才能使其正常工作吗?

顶部没有标签栏

顶部有标签栏

Note:很奇怪这个 GIF 没有正确显示完整的动画;您可以想象列表滚动了很多并且部分标题在选项卡栏下方滑动。

节标题样式

catListHeaderContainer: {
    padding: 12,
    backgroundColor: '#1F2036',
}

FacebookTabBar 样式

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 headers 不粘,你需要使用renderSectionHeader and cloneWithRowsAndSections代替cloneWithRows去做这个。

来自 React NativeListView 的文档 https://facebook.github.io/react-native/docs/listview.html#content

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
    }),
  }
},

然后,在获取数据的 API 调用期间,我将该响应数据添加到我的dataBlob目的。存储它的密钥被认为是sectionId for 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 and rowIDs.

就是这样renderListView looks:

  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 looks:

  renderSectionHeader: function(sectionData, sectionID) {
    return (
      <View style={styles.section}>
        <Text style={styles.sectionText}>{sectionID}</Text>
      </View>
      )
  },

Here's how it looks in the end: imgur

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何让 ListView 部分标题固定下来 的相关文章

随机推荐

  • 如何从 nodejs/express 向浏览器发送成功状态?

    我在我的nodeJS Expressjs服务器中编写了以下代码 app post settings function req res var myData a req param a b req param b c req param c
  • HTML/JavaScript Windows 应用商店应用程序可以在可调整大小的窗口中运行吗?

    我即将开始在 Windows 8 1 上开发应用程序 为了利用我现有的技能和经验 我更愿意使用 HTML 而不是 XAML 作为前端 我不想全屏运行应用程序 而是希望将其放在老式的 WPF WinForms 样式窗口中 该窗口可以调整大小
  • 替换嵌套 NSDictionary 中出现的 NSNull

    这个问题类似于这个问题 https stackoverflow com questions 8075147 replace all nsnull objects in an nsdictionary 但是此方法仅适用于字典的根级别 我正在寻
  • 将 Maildir 转换为 mbox

    我正在更改主机 并且需要将旧服务器上的 maildir 帐户转换为新服务器上的 mbox 关于最好的方法有什么想法吗 我找到了这个 for i in new cur do formail gt mbox done 但我真的不太明白 我有 L
  • IIS 10 错误 500.19 (0x80070021) - 锁定冲突

    我有一个应用程序 我正在尝试从 Server 2012 IIS 8 迁移到 Server 2016 IIS 10 当我最初移动所有内容时 我收到了附加的错误消息 我已经阅读了几篇堆栈交换帖子 它基本上说该部分需要解锁 我已通过命令提示符命令
  • 在 SharedPreferences 中存储数组列表对象

    该方法将新对象添加到ArrayList get text from textview time date getText toString entry d entry getText toString dayName day getText
  • Angular Material 2 中的 md-table

    我正在与角材料表 https material angular io components table overview在Html代码中 有
  • 将项目升级到 MVC 5

    我一直在寻找一种解决方案来升级当前的 MVC 4 应用程序 我必须使用新的 MVC 5 二进制文件 我在任何地方都找不到解决方案 有人有主意吗 Visual Studio 2013 只需允许 Nuget 包管理器运行更新即可自动升级项目 S
  • 调用方法一次以在 Django Rest Framework 序列化器中设置多个字段

    如何使用 Django Rest Framework 序列化程序调用同一方法一次来设置多个字段 这就是我现在所做的 但这显然调用了该方法两次 如何限制它只能被调用一次 class MyModel models Model def GetTw
  • 我应该实现 onRetainNonConfigurationInstance 吗?

    我刚刚读到有关维护 Android 应用程序状态的内容 并偶然发现了 onRetainNonConfigurationInstance 但在阅读时文档 http developer android com reference android
  • Flutter:如何将 URI 转换为文件?

    我想将路径 content media external images media 138501 转换为文件并在图像中设置 Code File imageFile File content media external images med
  • Lucene索引中“-”字符的问题

    我在使用 Lucene 索引时遇到问题 该索引已索引包含 字符的单词 它适用于某些包含 的单词 但不适用于所有单词 我找不到它不起作用的原因 我正在搜索的字段经过分析并包含带有和不带有 字符的单词版本 我正在使用分析器 org apache
  • Graphviz dot - HTML 表格中的斜体文本不是斜体

    我在用着dot版本2 26 3 下列 dot内容 digraph html results shape none margin 0 label lt table border 0 cellspacing 0 cellpadding 4 tr
  • 从 CGPoints 数组中获取最大值和最小值

    我们有一组 CGPoints let points 1234 0 1053 0 1241 0 1111 0 1152 0 1043 0 我想做的是获取数组中 x 值最高的 CGPoint 和 y 值最高的 CGPoint 我将使用这些点来创
  • 您不是该客户端的沙箱用户。错误代码igniter-Instagram api

    In my codeigniter我正在尝试使用的项目Instagram API用于登录 This https github com ianckc CodeIgniter Instagram Library是我正在使用的库 但是当进入登录页
  • Android Studio 中 make 和 build 的区别

    Android Studio Build 菜单的选项包括 Make Project Rebuild Project 我应该什么时候使用它们 大多数时候你应该使用制作项目 有时 在添加库并对项目进行重大更改后 您应该使用重建项目 如果你看一下
  • 当我将项目从一个列表框传输到另一个列表框时,如何防止页面回发

    我的应用程序中有两个列表框 单击按钮后我将项目从一个列表框推送到另一个列表框 代码工作正常 但它会导致回发 当我将项目从一个列表框移动到另一个时 整个页面正在再次加载 如何我可以阻止这一切 这将是我的 aspx 页面上的代码 div cla
  • UISearchBar 文本颜色

    浏览文档 我找不到任何可以更改 UISearchBar 颜色的内容 有人知道如何更改吗 没有任何 textColor 属性 Thx 适用于 iOS 7 及更高版本 UITextField appearanceWhenContainedIn
  • SIMD 将 12 位字段解包为 16 位

    我需要从每个 24 位输入中解压缩两个 16 位值 3 字节 gt 4 字节 我已经以幼稚的方式做到了 但我对表现不满意 例如 InBuffer 是 m128i value1 uint16 t InBuffer 0 11 bit range
  • 如何让 ListView 部分标题固定下来

    我的按钮显示在屏幕顶部 使用反应本机可滚动选项卡视图 在按钮下面 我有ListView上面有节标题 当我滚动时 有没有办法让标题粘在选项卡视图的底部边缘 我很难得到ListView的节标题粘在 Facebook TabBar 的底部 默认情