react / react/react-native

[android] [ios] [web] `measure` returns incorrect values of `View` if its parent `View` is `scale`d using `transform` style

Open
#54,988 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs: Triage :mag:
Dominant language
C++
Stars
127k
Forks
25.3k
Avg merge
1d 23h
Merged PRs (30d)
4

Description

Description

If use measure method to calculate x, y, width, height, pageX, pageY values of View it will return incorrect values in case if parent View has styles:

transform: [
  {
    scale: 2,
  },
],

in this case width, height, pageX, pageY values from measure callback will be doubled compared to real ones.

Specs

  • It is wrong due docs as transform style prop doesnt change layout, transform is used to change appearance only:

    Transforms are style properties that will help you modify the appearance and position of your components using 2D or 3D transformations. However, once you apply transforms, the layouts remain the same around the transformed component

  • It is inconsistent with react-native-web where transform doesnt affect width, height, pageX, pageY values
  • It is inconsistent with response of onLayout callback which will return width, height NOT scaled

Problem

There are 3 different behaviors:

  • react-native-web returns real sizes
  • onLayout returns real sizes
  • measure returns size SCALED due to its parent transform style
Steps to reproduce

See example

React Native Version

0.81.5

Affected Platforms

Runtime - Android,
Runtime - iOS,
Runtime - Web

Output of npx @react-native-community/cli info
See example
Stacktrace or Logs
See example console logs on Android (or iOS)
MANDATORY Reproducer

https://snack.expo.dev/@sepu/rn-measure-bug-w-transform

Screenshots and Videos

web console logs (3rd and 4th parameters are the same) which is ok:

>>>>> useLayoutEffect measure x, y, width, height, pageX, pageY 134 351 71 39 134 351
onLayoutHandler layout.x, layout.y, layout.width, layout.height 134 351 71 39

Android / iOS console logs (3rd and 4th parameters for measure are 2x bigger than from onLayout):

>>>>> useLayoutEffect measure x, y, width, height, pageX, pageY 176 456 148 78 139 437
onLayoutHandler layout.x, layout.y, layout.width, layout.height 176 456 74 39

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the mandatory Snack reproducer and compare measure with onLayout on Android, iOS, and web. Trace the platform-specific measurement behavior shown by the reproducer; done means measure reports values consistent with the unscaled layout and the existing web and onLayout results.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.