scroll to index for flat list in react-native
Two things that I can see,
- You need not define string refs within
{}
. However React docs suggest you to make use of ref callback
Do it something like
<FlatList
ref={(list) => this.myFlatList = list}
data={data}
keyExtractor={this._keyExtractor}
renderItem={this._renderItem}
/>
- You need to bind your function to be able to refer to the correct context
Do it like
_enableTVEventHandler = () => {
this._tvEventHandler = new TVEventHandler();
this._tvEventHandler.enable(this, function(cmp, evt) {
this.myFlatList.scrollToIndex({viewPosition: 0.5, index: 2});
}.bind(this));
}
or
constructor(props) {
super(props) ;
this._enableTVEventHandler = this._enableTVEventHandler.bind(this);
}
NOI-001—《C++编程及竞赛训练》
NOI-002—《普及组竞赛强化训练课程》
NOI-003—《初级算法课程》