react-native-web icon indicating copy to clipboard operation
react-native-web copied to clipboard

onLayout event.nativeEvent.layout.x value incorrect when container has transform scale

Open miketheanimal opened this issue 9 years ago • 1 comments

react 15.4.2 react-native-web 0.0.68 (running in Chrome 55.0.2883.87) react-native 0.40.0

rendering:

  <View ref="container" style={{ flexDirection: 'row', width: WIDTH, transform: transform }}>
      <Node ...... />
      <Text onLayout={ this.onLayout }></Text>
  </View>

WIDTH is a large value (10000) chosen to be larger than the content is ever going to be. <Node/> renders as a bunch of stuff. The <Text/> element is used so I can get the width of the stuff rendered by <Node/> (the reason for all this is so that I can measure the width and then adjust the transform to get <Node/> to just fill the parent <View/>).

transform is set like [ { scale: somescalevalue }, { translate: sometranslation } ]

With react native, the value of event.nativeEvent.layout.x in the call to this.onLayout is the width of <Node/> were there to be no scaling; with react-native-web it is the width when the scaling is applied. So in react native in this.onLayout I have:

    let width = event.nativeEvent.layout.x ;

while in react native web I need:

    let width = event.nativeEvent.layout.x / somescalevalue ;

In neither case do I need to take into account some translation.

Hope this makes sense Regards Mike

miketheanimal avatar Jan 16 '17 22:01 miketheanimal

I believe the same applies to hight. Regards Mike

miketheanimal avatar Jan 18 '17 13:01 miketheanimal