measureLayoutRelativeToParent broken in ListView in 0.8.0-rc
See original GitHub issueI was using UIManager.measureLayoutRelativeToParent
to get the scroll offset of an element contained in a ListView (click on the element, and the view would scroll so the element was at the top of the screen). This stopped working between 0.7.1
and 0.8.0-rc
(I can’t find exactly which commit).
Here’s some code showing it. Click on an element and it should log the Y offset - it works in 0.7.1
, but always returns the first element’s offset in 0.8.0-rc
. Also, it works as expected in 0.8.0-rc
if it’s a ScrollView, not a ListView.
var React = require('react-native');
var UIManager = require('NativeModules').UIManager;
var { AppRegistry, StyleSheet, ListView, Text, TouchableOpacity,} = React;
var Row = React.createClass({
measure: function () {
var handle = React.findNodeHandle(this.refs['scrolly']);
UIManager.measureLayoutRelativeToParent(handle, () => {}, (x, y) => {
// Should be the y offset of the element.
// Works correctly in 0.7.1,
// always returns the first element offset in 0.8.0-rc.
console.log(y);
});
},
render: function() {
return (<TouchableOpacity ref={`scrolly`} onPress={this.measure}>
<Text style={styles.row}>{this.props.txt}</Text>
</TouchableOpacity>);
}
});
var dataSource = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
dataSource = dataSource.cloneWithRows([...new Array(50)].map((_, i) => {{txt: 'txt' + i}}));
var test = React.createClass({
render: function() {
return (<ListView
dataSource={dataSource}
renderRow={row => <Row txt={'test'} />}>
</ListView>);
}
});
var styles = StyleSheet.create({
row: { fontSize: 30, textAlign: 'center', margin: 10, },
});
AppRegistry.registerComponent('test', () => test);
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
react-native-codegen | Yarn - Package Manager
Fix a broken input for the Korean alphabet in TextInput (1a83dc36ce by ... Hermes 0.8.1. ... measureLayoutRelativeToParent (e42009b784 by @mdvacca) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Is this working for anyone? I’m still having the issue described above, where measuring a ListView cell returns
0
forx
andy
.reverts landed - sorry for the trouble.