react / react/react-native

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

オープン
#54,988 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Needs: Triage :mag:
主要言語
C++
スター
127k
フォーク
25.3k
平均マージ
1日 23時間
マージ済み PR(30日)
4

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

必須の Snack 再現用コードから始め、Android、iOS、web で measure と onLayout を比較します。再現用コードで示されるプラットフォーム固有の計測動作を追跡します。完了の条件は、measure がスケールされていないレイアウトおよび既存の web と onLayout の結果と一致する値を報告することです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, react-native
領域
mobile-dev
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
50/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。