question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

measureLayoutRelativeToParent broken in ListView in 0.8.0-rc

See original GitHub issue

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);

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
holmesalcommented, Mar 11, 2016

Is this working for anyone? I’m still having the issue described above, where measuring a ListView cell returns 0 for x and y.

0reactions
sahrenscommented, Jul 17, 2015

reverts landed - sorry for the trouble.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found