It looks like the refs of views in is hard to be directly accessed.
Now I have a list view with a cells. In the renderRow
function I have something like:
renderRowView: function(rowData){
return
<View >
<TextInput
ref="text"
/>
</View>
},
In this case, if I want to access this TextInput using ref, it will be undefined
.
I saw a thread on Github (https://github.com/facebook/react-native/issues/897) mentioned about a way to resolve this, but I still couldn't understand how to use it:
render: function() {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData, sec, i) =>
<Text ref={(row) => this.rows[sec][i] = row}>{rowData}</Text>
}
/>
);
},
Please help me understand how this ref function works, and how to use it (i.e. programmatically focus on the TextInput
in the row.). Thank you!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…