我有一个SectionList,其中第一个和第二个部分是水平可滚动的.我已经通过在这些部分中嵌套了一个FlatList来做到这一点.然而,将水平填充添加到FlatList,使其从左侧开始16px,也会从右侧删除16px.

我试着把horizontalPadding: 16换成paddingLeft: 16&paddingStart: 16,但结果是一样的.

下面的插图或预期与实际

visual example

代码

  <SectionList
    sections={sections}
    renderSectionHeader={({ section }) => {
      const type = section.type;
      switch (type) {
        case "one":
          return (
            <FlatList
              style={{
                paddingHorizontal: 16,
                marginBottom: 16,
              }}
              data={section.data}
              horizontal
              renderItem={({ item }) => <Card1 item={item} />}
              ItemSeparatorComponent={() => (
                <View style={{ width: 8 }}></View>
              )}
              showsHorizontalScrollIndicator={false}
            />
          );
        case "two":
          return (
            <FlatList
              style={{ flex: 1, paddingLeft: 16, marginBottom: 24 }}
              data={section.data}
              horizontal
              renderItem={({ item }) => (
                <Card2 item={item} onPress={offerDetails} />
              )}
              ItemSeparatorComponent={() => (
                <View style={{ width: 16 }}></View>
              )}
              showsHorizontalScrollIndicator={false}
            />
          );
        case "three":
          return (
            <Text
              style={{
                fontSize: 21,
                fontWeight: "bold",
                paddingHorizontal: 16,
                marginBottom: 12,
              }}
            >
              {section.title}
            </Text>
          );
      }
    }}
    renderItem={({ item, section }) => {
      if (section.horizontal) {
        return null;
      }
      return <Card3 item={item} onPress={offerDetails} />;
    }}
    stickySectionHeadersEnabled={false}
    showsVerticalScrollIndicator={false}
  />

推荐答案

使用FlatList组件时,可以通过使用contentContainerStyles属性将样式应用于滚动视图内容容器.此属性允许您指定将应用于包装所有子视图的容器的样式.

React-native相关问答推荐

如何重复使用expo 音频对象S录音?

如何在Reaction Native中将身体分成三部分

类似Snapchat的Reaction Native筛选器

为什么我的expoav视频不会自动播放?

任务:react-native-async-storage_async-storage:generateReleaseRFile FAILED

我可以在状态内有一个函数来响应吗?

'React native run android' 在模拟器中启动应用程序后立即停止

Invariant Violation:Chrome 不支持在本机模块上调用同步方法

react-native 中的layout-only view removal优化是什么?

如何在react-native中淡化视图的边缘?

迷失在 Ionic、Cordova 等混合应用程序框架中

如何在 React Native 中访问原生 UI 组件的实例方法

如何渲染多行文本组件,行间有白色间隙

当 textInput 聚焦时,第一次touch flatList 不起作用,但是第二次起作用

从数据源添加/删除列表视图项时为它们设置动画

在 React Native App 中禁用屏幕捕获/ScreenShot

Animated.View 的样式props的Typescript定义

如何知道 FlatList 中的滚动状态?

无法解析模块react-native-reanimated

如何隐藏 React Native NavigationBar