react-native-macos/ReactCommon
Xin Chen 0975e96d53 Fix transform when calculate overflowInset
Summary:
This diff fixes overflowInset calculation when a shadow node has transform matrix from a transfrom prop in JS. Specifically, this fixed the use case when transform directly used on a view component. When using Animated.View, it will create an invisible wrapper which will behave correctly with existing logic. This diff bring both use cases to work properly.

When a shadow node has transform on it, it will affect the overflowInset values for its parent nodes, but won't affect its own or any of its child nodes overflowInset values. This is obvious for translateX/Y case, but not for scale case. Take a look at the following case:

```
     ┌────────────────┐                 ┌────────────────┐                      ┌────────────────┐
     │Original Layout │                 │  Translate AB  │                      │    Scale AB    │
     └────────────────┘                 └────────────────┘                      └────────────────┘
                                                        ─────▶           ◀─────                  ─────▶
┌ ─ ─ ─ ┬──────────┐─ ─ ─ ─ ┐     ┌ ─ ─ ─ ┬──────────┐─ ─ ─ ─ ─ ┐      ┌ ─ ─ ─ ─ ─ ┬──────────┐─ ─ ─ ─ ─ ┐
        │ A        │                      │ A        │                             │ A        │
│       │          │        │     │       │          │          │      ├ ─ ─ ─ ─ ─ ┼ ─ ─┌─────┤─ ─ ─ ─ ─ ┤
 ─ ─ ─ ─│─ ─ ─┌───┐┼ ─ ─ ─ ─              │          │                   ◀─ ─ ─    │    │AB   │  ─ ─ ─▶
│       │     │AB ││        │     │ ┌ ─ ─ ┼ ─ ─ ─ ┬──┴┬ ─ ─ ─ ─ ┤      │           │    │     │          │
        └─────┤   ├┘                      └───────┤AB │                            └────┤     │
│             │┌──┴─────────┤     │ │             │   │         │      │ │              │ ┌───┴──────────┤
              ││ABC         │                     │┌──┴─────────┐                       │ │ABC           │
│             │└──┬─────────┤   │ │ │             ││ABC         │    │ │ │              │ │              │
┌───ABD───────┴─┐ │             │                 │└──┬─────────┘    │   ▼              │ └───┬──────────┘
├─────────────┬─┘ │         │   │ │ ├───ABD───────┴─┐ │         │    │ ├────────────────┴──┐  │          │
 ─ ─ ─ ─ ─ ─ ─└───┘─ ─ ─ ─ ─    ▼   └─────────────┬─┘ │              ▼ │      ABD          │  │
                                  └ ┴ ─ ─ ─ ─ ─ ─ ┴───┴ ─ ─ ─ ─ ┘      ├────────────────┬──┘  │          │
                                                                        ─ ─ ─ ─ ─ ─ ─ ─ ┴─────┴ ─ ─ ─ ─ ─
```

For the translate case, only view A has change on the overflowInset values for `right` and `bottom`. Note that the `left` and `top` are not changed as we union before and after transform is applied.

For the scale case, similar things are happening for view A, and both `left`, `right`, and `bottom` values are increased. However, for View AB or any of its children, they only *appear* to be increased, but that is purely cosmetic as it's caused by transform. The actual values are not changed, which will later be converted during render phase to actual pixels on screen.

In summary, overflowInset is affected from child nodes transform matrix to the current node (bottom up), but not from transform matrix on the current node to child nodes (top down). So the correct way to apply transform is to make it only affect calculating `contentFrame` during layout, which collects child nodes layout information and their transforms. The `contentFrame` is then used to decide the overflowInset values for the parent node. The current transform matrix on parent node is never used as it's not affecting overflowInset for the current node or its child nodes.

This diff reflects the context above with added unit test to cover the scale and translate transform matrix.

Changelog:
[Android/IOS][Fixed] - Fixed how we calculate overflowInset with transform matrix

Reviewed By: sammy-SC

Differential Revision: D34433404

fbshipit-source-id: 0e48e4af4cfd5a6dd32a30e7667686e8ef1a7004
2022-03-01 14:33:04 -08:00
..
butter Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
callinvoker Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
cxxreact Remove FBREMAP experiment 2022-01-27 12:02:19 -08:00
hermes Implement Runtime.getHeapUsage for hermes chrome inspector (#33173) 2022-03-01 10:09:05 -08:00
jsengineinstance The life-changing magic of clang-tidying up 2020-02-04 11:09:30 -08:00
jsi Add PropNameID::fromSymbol 2022-02-14 22:29:16 -08:00
jsiexecutor Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
jsinspector Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
libraries/fbcore/src/test/java/com/facebook/powermock Explicitly set autoglob (long tail) 2020-12-17 19:35:29 -08:00
logger Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
microprofiler Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
react Fix transform when calculate overflowInset 2022-03-01 14:33:04 -08:00
reactperflogger Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
runtimeexecutor Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
yoga Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
React-Fabric.podspec Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
React-rncore.podspec Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
ReactCommon.podspec Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
common.mk Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00