自定义节样式在sectionList REACT NATIVE中

2024-01-23

你知道如何在React-native的sectionList组件中制作水平部分(特定的)吗?我想让第二部分水平,我尝试使用 flex:1 和 flexDirection: 'row' 修改 renderItem 中的项目样式,但不起作用。任何人都知道如何在部分上设置自定义样式或制作水平部分? (红圈内)

        <View>
        <SectionList
          renderItem={({item, index, section}) => <CellMainNews isFirst={index===0 ? true: false} data={ item } onPress = {item.onPress } />}
          renderSectionHeader={({section: {title}}) => (
            <Text style={{fontWeight: 'bold'}}>{title}</Text>
          )}
          sections={[
            {title: 'Top post', data: this.props.featured.top, renderItem: overrideRenderItem },
            // this section
            {title: 'Featured posts', data: this.props.featured.secundary, renderItem: overrideRenderItemTwo },
            {title: 'Stories', data: this.props.stories},
          ]}
          keyExtractor={(item, index) => item + index}
            />

            {this.props.loading &&
                <View>
                    <ActivityIndicator size={100} color="red" animating={this.props.loading} />
                </View>
            }
        </View>

问候。


自从那以后有点难SectionList不会在其部分上放置容器视图,但您可以通过传递包含所述元素上所有项目的单个元素数组来实现它。

您可以使用您偏好的组件按照您想要的方式呈现该部分上的所有项目。

我建议使用FlatList

<View>
    <SectionList
      renderItem={({item, index, section}) => <CellMainNews isFirst={index===0 ? true: false} data={ item } onPress = {item.onPress } />}
      renderSectionHeader={({section: {title}}) => (
        <Text style={{fontWeight: 'bold'}}>{title}</Text>
      )}
      sections={[
        {title: 'Top post', data: this.props.featured.top, renderItem: overrideRenderItem },
        {title: 'Featured posts', data: [this.props.featured.secundary], renderItem: overrideRenderItemTwo }, // Passing here the single element array 
        {title: 'Stories', data: this.props.stories},
      ]}
      keyExtractor={(item, index) => String(index)}
        />

        {this.props.loading &&
            <View>
                <ActivityIndicator size={100} color="red" animating={this.props.loading} />
            </View>
        }
</View>

和你的 overrideRenderItemTwo

const overrideRenderItemTwo = ({ item, index, section: { title, data } }) => {
  return (
    <FlatList
      showsHorizontalScrollIndicator={false}
      pagingEnabled={true}
      horizontal={true}
      data={item}
      keyExtractor={(item, index) => String(index)}
      renderItem={(
        ({item}) => (<CellMainNews isSecundary={true} isFirst={index===0 ? true: false} data={ item } onPress = {item.onPress } />)
      )}
    />
  );
}

这样做的好处是您可以为特定部分的容器视图使用您想要的样式

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

自定义节样式在sectionList REACT NATIVE中 的相关文章

随机推荐

  • Windows 批处理:从文本文件设置变量

    我目前正在寻找一种通过 txt 文档中的链接在 Windows 批处理文件中设置变量的方法 例如 如果文本文件读取为 http website1 com http website2 com http website3 com 我希望可以将它
  • PHP-EWS“Soap 客户端返回状态 404”

    所以 我正在使用php ews http jamesarmes com php ews库连接到我的 Microsoft Office 365 Exchange 电子邮件帐户以阅读电子邮件 我已成功连接到它 并设法检索我需要的电子邮件列表 现
  • 可以拆分PHP配置文件php.ini吗?

    任何使用 php 的人都知道 php ini 是一个大文件 当您需要更改 ssh 时可能会让人头疼 例如我可以使用更改 nginx confinclude指令将启用站点的目录下的所有文件加载到主 nginx conf 中 所以我的问题很简单
  • 如何计算字符串的 CRC32

    如何计算 NET 中字符串的 CRC32 循环冗余校验和 这家伙似乎已经给你答案了 https damieng com blog 2006 08 08 calculate crc32 in c and net https damieng c
  • MVVM 中的数据绑定 ObservableCollection

    我有一个带有数据模板的 ListView 其中包含电影列表 它被数据绑定到 ObservableCollection 但每当我编辑 Movie Name 时 即使在我的 PropertyChangedEventHandler 中使用 Nam
  • 在 SSLContext 中使用硬件支持的密钥

    我想在 Android 上使用硬件支持的密钥进行客户端双向 TLS 钥匙应该通过生物识别技术解锁 我找到了如何在 Android 上生成硬件支持的密钥对 KeyPairGenerator keyGenerator KeyPairGenera
  • 如何调整 meSpeak.js 以获得更好的声音?

    我是新来的meSpeak js http www masswerk at mespeak 我不能接受他们在演示中的默认声音 我尝试使用他们拥有的选项 但这并没有多大区别 我想知道如何调整它 以使声音接近 Siri 的水平 而不是像他们的演示
  • 如何在vue中创建警报确认框

    我想在删除文件之前显示一个对话框 我如何用vue做到这一点 这是我尝试的 我的删除文件按钮 a href Delete a 这是我的删除方法 DeleteUser id index axios delete api artist id th
  • 无法实例化片段确保类名存在

    android app Fragment InstantiationException 无法实例化 片段 确保类名存在 是公共的并且有一个空 构造函数是公共的 我意识到有很多关于同一错误的问题 但到目前为止没有一个对我有帮助 我正在从一本书
  • 将 Mercurial 与 Cygwin 一起使用?

    我们一直在尝试将 Mercurial 与 Cygwin 在 Windows 上 一起使用 但遇到错误 因为 Cygwin 使用正斜杠 而 Mercurial 似乎需要反斜杠 有解决方法吗 问题示例 hg status M src myfil
  • 自动运行可移动驱动器

    自动运行在 Windows 中被禁用 我正在寻找替代方案 我得到了这个 AutoIt 脚本 DBT DEVICEARRIVAL 0x00008000 WM DEVICECHANGE 0x0219 GUICreate GUIRegisterM
  • Knockout.js 模板未更新 dependentObservable 上的 UI 绑定

    该应用程序是在 vs2010 中使用 ASP NET MVC 3 编写的 我有一个淘汰赛模板 它使用 a 更新一些 css 和可见绑定 依赖的可观察的 仅当我绑定时才会出现此问题 选择元素的值 间隔ID 如果这没有被绑定 UI 按预期更新
  • 如何链接“并行”类层次结构?

    我有一个小的类层次结构 其中每个类对应于某个 TComponent 后代 例如基类 TDefaultFrobber 及其后代 TActionFrobber 和 TMenuItemFrobber 分别对应于 TComponent TCusto
  • 软件/硬件支持的 Android 密钥库的使用以及可能的安全/可用性缺陷

    我目前正在研究在 Android 应用程序中存储 使用密钥的可能性 我发现了尼古拉 埃连科夫的博客 http nelenkov blogspot com关于这个主题非常有帮助 我学到了很多关于 Android 密钥库和一些基于硬件的实现的知
  • Jetty默认是非阻塞的吗?

    请告诉我 Jetty 默认情况下是否是非阻塞 Web 服务器 例如 下面的代码将 Jetty 作为非阻塞 Web 服务器运行 Server server new Server 8080 ServletContextHandler conte
  • “正在缓存中间结果”是什么意思?

    我有一套n向量存储在3 x n matrix z 我发现外部产品使用np einsum 当我使用以下方法计时时 timeit v np einsum i j gt ij z z 我得到了结果 The slowest run took 7 2
  • 如何将子节点附加到特定位置

    如何将 childNode 附加到 javascript 中的特定位置 我想将 childNode 添加到 div 中的第三个位置 它后面还有其他节点需要向后移动 3变成4等 您可以使用 insertBefore https develop
  • 使用 regex 或 ToDicitionary 获取 url

    我怎样才能获取 oauth verifier RN9vtxDFfozW51CSTuls0J4C oauth token 4 2F3uYq 3vYUSjXaFXtS74B laW2V4d RN9vtxDFfozW51CSTuls0J4C an
  • VS-code 中分支名称旁边的 * 是什么意思?

    我不知道为什么会有 在 Visual Studio 代码中我的 git 分支名称旁边 有什么我应该警惕的吗 大多数 shell 着色插件和 IDE 通常使用 对于分支名称表示当前分支有已修改的文件 或者有时仅表示本地存储库有已创建的文件 但
  • 自定义节样式在sectionList REACT NATIVE中

    你知道如何在React native的sectionList组件中制作水平部分 特定的 吗 我想让第二部分水平 我尝试使用 flex 1 和 flexDirection row 修改 renderItem 中的项目样式 但不起作用 任何人都