-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Closed
Labels
Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.
Description
I 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);
Metadata
Metadata
Assignees
Labels
Resolution: LockedThis issue was locked by the bot.This issue was locked by the bot.