ListView があり、renderRow に記述したカスタム コンポーネントの参照にアクセスしようとしています。カスタム コンポーネントを直接操作する必要があるため、これらの参照を取得する必要があります。
他の人もこの問題に直面しているようです。React Native: Refs in ListViewおよびhttps://github.com/facebook/react-native/issues/897の推奨事項に従ってみましたが、うまくいかないようです。提案されているように、コールバック ref メソッドを使用してみました。しかし、componentDidMount で this.refs.listView.refs を出力しようとすると、customRef が返される代わりに空になります。renderRow 関数からカスタム コンポーネントの参照を取得するにはどうすればよいですか? ありがとうございました
クラスには次の機能があります。
componentDidMount() {
console.log(this.refs.listView.refs);
},
getRef() {
return 'customRef';
},
renderRow(rowData) {
return (
<CustomComponent ref={(ref)=>this.getRef} key={rowData.key} />
);
},
render() {
return (
<ListView
ref={'listView'}
dataSource={this.state.dataSource}
renderRow={this.renderRow} />
);
}