-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get refs to ListView rows #897
Comments
+1 |
One could just add a simple function that writes the ref of each list element to the _visibleRows property. Proposal: ( part of the ListView's render function ) for (var rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) {
var rowID = rowIDs[rowIdx];
var comboID = sectionID + rowID;
var shouldUpdateRow = rowCount >= this.state.prevRenderedRowsCount &&
dataSource.rowShouldUpdate(sectionIdx, rowIdx);
var row =
<StaticRenderer
key={'r_' + comboID}
ref={ function(rowRef) { this._visibleRows[comboID] = rowRef; } }
shouldUpdate={!!shouldUpdateRow}
render={this.props.renderRow.bind(
null,
dataSource.getRowData(sectionIdx, rowIdx),
sectionID,
rowID
)}
/>;
bodyComponents.push(row);
totalIndex++;
if (++rowCount === this.state.curRenderedRowsCount) {
break;
}
} |
+1 |
You should be able to put a function ref in renderRow: render: function() {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData) =>
<Text ref={(row, sec, i) => this.rows[sec][i] = row}>{rowData}</Text>
}
/>
);
}, or similar. |
@spicyj Thanks you directed me on the right path 👍 This worked for me: render: function() {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData, sec, i) =>
<Text ref={(row) => this.rows[sec][i] = row}>{rowData}</Text>
}
/>
);
}, |
Hey @lukasreichart getting stuck on this. How do you access the row once you set the ref. this.rows and this.props.rows, and this.props.refs all return undefined |
@lukasreichart thanks to your code 👍 |
I am getting an error undefined is not an object (evaluating '_this2.rows')
|
HI @senthilsivanath . I'm running in to the same issue, did you have any luck in resolving? |
Hi @brianfoody and @senthilsivanath I am also running into the same issue. Were you able to resolve it? |
No luck since @samdturner |
@spicyj @lukasreichart - the solution with refs does not work for me all the time - specifically for "long" lists where children are not yet rendered (due to |
Sometimes a null gets supplied to a callback |
After trying the REFS way and it being not a very good approach, I noticed the onChangedVisibleRows params ( visibleRows and changedRows ) are hashes. They must have done this for a reason. It then made sense to assign the row rendered its sectionId and rowId and also an event emitter defined from the parent. The parent then does an emit change event when onChangedVisibleRows occurs, passing in visibleRows and changedRows. Since each row has props defined for sectionId and rowId, each row can then do a quick lookup in the hashes to see if its visible or not. |
I have gone through all the solutions but the way i found working is this:
Later you can access this like
|
HI
I have a ListView and need to measure the layout of one row. I searched, but did not find a way to access a ListViews rows. ( ListView._visibleRows seems to be an empty object ).
Is there a way to do this?
If not I'd suggest to add a "ref" prop, based on the sectionID and rowID to every element created in, ListView.render ...
The text was updated successfully, but these errors were encountered: