动态调整FlatList的大小以包装内容

时间:2018-07-31 08:49:43

标签: android react-native jsx

作为序言,我已经读过this,但是它对我没有用。使用该选项使我的列表根本不会显示,但这是我想要实现的目标:

我正在使用一个注释系统,我希望最新的注释显示在底部,当您打开屏幕时,您自动位于列表的底部,因此您可以查看最新的注释。轻松,只需将您移交给列表的列表反转,然后向下滚动到onLayout和onContentSizeChange中的底部。

问题在于,注释的长度当然不一样,因此FlatList的元素是动态调整大小的,这使得向下滚动有些混乱。

另一种解决方案是使用“倒置”道具,但是在这里,当注释少于填满屏幕所需内容时,FlatList看起来像这样:

enter image description here

我将FlatList的背景涂成黑色,以查看发生了什么情况。

有什么办法可以使FlatList包装内容并扩展内容直到达到屏幕高度?

这是我的清单代码:

  <View flex={1} backgroundColor={'white'}>
        <TabHeader store={store}/>
        <FlatList
          inverted
          ref={ref => store.flatList = ref}
          data={elements}
          renderItem={({item, index}) => (
            <CommentRow
              item={item}
              index={index}
            />
          )}
          ListFooterComponent={() => <TabFooter store={store} />}
          onEndReachedThreshold ={0.1}
          onEndReached={({ distanceFromEnd }) => {
            loadNext();
          }}
          style={{backgroundColor: 'black'}}
        />
        <Row h={0.3}/>
        <TextInput
          ref={ref => store.textInput = ref}
          multiline
          blurOnSubmit
          underlineColorAndroid={'transparent'}
          onFocus={store.hideTabs}
          autoFocus={store.focusOnStart}
          onEndEditing={store.showTabs}
          onSubmitEditing={store.submitComment}
          value={store.userComment}
          onChangeText={store.changeText}
          placeholder={placeholder}
          autoCorrect={false}
          style={{marginLeft: 20}}
        />
        <Row h={0.3} />
      </View>

谢谢!

0 个答案:

没有答案
相关问题