简体   繁体   English

React Native FlatList 不会滚动到 header 组件的末尾

[英]React Native FlatList won't scroll to the end of the header component

I'm having trouble getting my FlatList to scroll to the end of the header. This is what my component's styles are right now:我无法让我的 FlatList 滚动到 header 的末尾。这就是我组件的 styles 现在的样子:

    <View style={styles.mainView}>
      <View style={{flex: 1}}>
        <FlatList
          ListHeaderComponent={
            <>
              <View style={{minHeight: '40%'}}>
                <MapView
                  region={region}
                  showsUserLocation={true}
                  showsCompass={false}
                  style={styles.map}
                  provider={PROVIDER_DEFAULT}
                  scrollEnabled={true}
                  maxDelta={0.5}
                />
              </View>

              <View>
                <TextInput placeholder="Street address" />
                <TextInput placeholder="Apt/Sut/Bldg" />
                <TextInput placeholder="City" />
                <TextInput placeholder="State" />
                <TouchableOpacity>
                  <Text>Save</Text>
                </TouchableOpacity>
              </View>
            </>
          }
        />
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  mainView: {
    height: devDims.height,
    width: devDims.width,
    backgroundColor: '#ffffff',
  },
  map: {
    ...StyleSheet.absoluteFillObject,
    maxHeight: devDims.height,
    alignItems: 'center',
    justifyContent: 'flex-end',
  },
});

I've tried switching to a ScrollView but the same problem occurs.我试过切换到 ScrollView 但出现了同样的问题。 Basically, I can scroll to the bottom of the header and see the content, but when I release my finger it immediately scrolls back to the top.基本上,我可以滚动到 header 的底部并查看内容,但是当我松开手指时,它会立即滚动回顶部。 What could be wrong with my styling?我的造型可能有什么问题?

It should be noted that devDims is simply the dimensions of the device.应该注意的是, devDims只是设备的尺寸。

When you use any scrollview or faltlist, you have to use {{flexGrow:1}} property of style which can cover all screen.当您使用任何 scrollview 或 faltlist 时,您必须使用{{flexGrow:1}}可以覆盖所有屏幕的样式属性。

 <ScrollView contentContainerStyle={{flexGrow:1}}>
  </ScrollView>

or或者

 <FlatList contentContainerStyle={{flexGrow:1}}>
  </FlatList >

flexGrow 灵活成长

contentcontainerstyle 内容容器风格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM