Skip to content

onLayout and .measure doesn't work for nested Text components #11650

@maslianok

Description

@maslianok

Description

onLayout and .measure doesn't work for nested Text components

Reproduction

Link to demo: https://rnplay.org/apps/rSlYMg

Let's say we have next layout

<View>
  <Text onLayout={this.onRootTextLayout}>
    <Text onLayout={this.onChildTextLayout}>Text</Text>
  </Text>
</View>

onLayout for the first (outer) Text works as expected. But it doesn't work for the second (nested) component.

The same for the .measure method.

<View>
  <Text ref={el => this.rootText = el}>
    <Text ref={el => this.childText = el}>Text</Text>
  </Text>
</View>

// ...

// Works as expected
this.rootText.measure((fx, fy, width, height, px , py) => console.log('rootText offset top:' + py));

// Doesn't work. Always show 0.
this.childText.measure((fx, fy, width, height, px, py) => console.log('childText offset top:' + py));

Additional Information

  • React Native version: 0.38
  • Platform: both
  • Operating System: MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions