在InitialScrollIndex

时间:2018-07-27 08:40:52

标签: react-native tvos react-native-flatlist

我在tvOS环境中使用FlatList组件处理水平列表。问题出现在3个元素的小列表上,我将initialScrollIndex设置为等于第二个或最后一个元素,选中了好项目。但是,当我尝试返回上一个项目时,会进行选择,但是没有滚动。

<FlatList
  getItemLayout={(data, index) => ({
     length: 300,
 offset: 300 * index,
      index,
  })}
  initialScrollIndex={this.props.initialScrollIndex}
  keyExtractor={this._keyExtractor}
  horizontal={this.props.horizontal}
  scrollEnabled={true}
  extraData={this.state}
  ref={list => (this.myScrollView = list)}
  data={this.finalData}
  removeClippedSubviews={false}
  renderItem={this.props.renderRow}
 />

1 个答案:

答案 0 :(得分:0)

您是否尝试过将getItemLayout中返回对象的属性从length: 300更改为width: 300。我认为这应该是width而不是length,因为您正在渲染水平FlatList。

getItemLayout={(data, index) => ({
  width: 300, //- Here
  offset: 300 * index,
    index,
  }
)}