A framework for building native macOS apps with React.
Перейти к файлу
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
.bundle Introduce Gemfile, ruby-version (#32303) 2021-10-01 21:22:26 -07:00
.circleci Remove `find-node.sh` script (#33146) 2022-02-21 03:23:40 -08:00
.github ci: Bump actions-apply-version-label to 0.0.3 (#32979) 2022-01-28 06:10:35 -08:00
IntegrationTests Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
Libraries Migrate dev method codegenNativeComponent to be Bridgeless compatible 2022-03-01 13:30:55 -08:00
React Use @synthesize viewRegistry_DEPRECATED for Keyframes to remove RCTWeakViewHolder hack 2022-02-25 13:45:22 -08:00
ReactAndroid Ship enableNestedTextOnPressEventFix 2022-03-01 12:07:36 -08:00
ReactCommon Fix transform when calculate overflowInset 2022-03-01 14:33:04 -08:00
bots RN: Upgrade `bots/` Dependencies 2022-02-16 00:23:59 -08:00
docs Generate doc info for RN components 2019-09-19 18:36:25 -07:00
flow Deprecate nonstandard Promise.prototype.done 2022-02-17 09:15:03 -08:00
flow-typed/npm RN: Remove DeprecatedPropTypes 2022-01-20 18:17:03 -08:00
gradle Allow to setup a Gradle Enterprise instance via an external script 2022-02-16 06:37:56 -08:00
jest Remove `@babel/plugin-transform-object-assign` from preprocessor 2022-02-11 06:11:05 -08:00
keystores Use fb_native_wrapper for all targets 2018-10-31 11:47:42 -07:00
local-cli Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
packages Migrate dev method codegenNativeComponent to be Bridgeless compatible 2022-03-01 13:30:55 -08:00
repo-config Upgrade Metro dependencies to 0.69.0 2022-02-28 08:28:10 -08:00
scripts Add script for bumping Hermes version for a release 2022-02-25 10:52:55 -08:00
template Update usages of default ReactNativeConfig (#33196) 2022-02-28 14:45:09 -08:00
third-party-podspecs Include folly fabric headers in source files (#33188) 2022-02-28 04:56:36 -08:00
tools/build_defs Fix OSS BUCK codegen (#33197) 2022-02-28 20:21:35 -08:00
.buckconfig Add kotlin_home and related JARs for OSS Buck Kotlin build (#33168) 2022-02-24 03:10:05 -08:00
.buckjavaargs limiting BUCK's memory for CI 2016-02-01 10:49:33 -08:00
.clang-format Moving ObjC specific clang-format rules to the common config 2019-02-11 13:07:09 -08:00
.editorconfig Revert removal of CRLF from Windows bat files (#31398) 2021-09-09 22:44:32 -07:00
.eslintignore Lint: fix few "no-unused-var" warnings for imports (#30157) 2020-10-26 17:19:14 -07:00
.eslintrc Rename eslint-plugin-codegen to eslint-plugin-specs (#32698) 2021-12-02 20:47:12 -08:00
.flowconfig chore(deps): bump CLI version to 7.0.3 to address web debugging issue (#33156) 2022-02-23 05:23:43 -08:00
.flowconfig.android chore(deps): bump CLI version to 7.0.3 to address web debugging issue (#33156) 2022-02-23 05:23:43 -08:00
.gitignore Bundle Hermes source code in react-native npm package 2022-02-22 12:23:49 -08:00
.prettierrc JS: Upgrade to Prettier v2.4.1 [1/n] 2021-11-02 22:14:16 -07:00
.ruby-version Introduce Gemfile, ruby-version (#32303) 2021-10-01 21:22:26 -07:00
BUCK Use @synthesize viewRegistry_DEPRECATED for Keyframes to remove RCTWeakViewHolder hack 2022-02-25 13:45:22 -08:00
CHANGELOG.md Changelog for 0.67.3 (#33162) 2022-02-22 08:23:40 -08:00
CODE_OF_CONDUCT.md docs: add new version convenant contribuitor guide link (#32107) 2021-08-30 10:18:11 -07:00
CONTRIBUTING.md fix: Updated releases/changelog links (#32551) 2021-11-08 09:25:47 -08:00
ECOSYSTEM.md docs: fix url for chainreactconf (#30199) 2020-10-19 07:35:37 -07:00
Gemfile Introduce Gemfile, ruby-version (#32303) 2021-10-01 21:22:26 -07:00
Gemfile.lock iOS Ruby Updates (#32456) 2021-10-21 15:58:18 -07:00
LICENSE Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
LICENSE-docs More licenses 2015-03-24 19:59:10 -07:00
README.md fix: Updated releases/changelog links (#32551) 2021-11-08 09:25:47 -08:00
React-Core.podspec Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
React.podspec Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
build.gradle.kts build: Bump AGP to 7.1.1 and fix bundle inclusion in release mode (#33057) 2022-02-21 06:23:31 -08:00
cli.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
gradle.properties Increase max heap size for template gradle build 2022-02-02 12:56:54 -08:00
gradlew bump gradle to 7.3 (#32588) 2021-11-15 06:47:39 -08:00
gradlew.bat Re-sync with internal repository (#32212) 2021-09-15 10:45:06 +01:00
index.js Move the `SegmentedComponentIOS` away from React Native Core (#33140) 2022-02-21 05:23:16 -08:00
interface.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
jest-preset.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
jest.config.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
metro.config.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
package.json Upgrade Metro dependencies to 0.69.0 2022-02-28 08:28:10 -08:00
react-native.config.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
react.gradle build: Bump AGP to 7.1.1 and fix bundle inclusion in release mode (#33057) 2022-02-21 06:23:31 -08:00
rn-get-polyfills.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
runXcodeTests.sh Use realpath instead of readlink 2022-02-22 02:23:02 -08:00
settings.gradle.kts Allow to setup a Gradle Enterprise instance via an external script 2022-02-16 06:37:56 -08:00
template.config.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
yarn.lock Upgrade Metro dependencies to 0.69.0 2022-02-28 08:28:10 -08:00

README.md

React Native

Learn once, write anywhere:
Build mobile apps with React.

React Native is released under the MIT license. Current CircleCI build status. Current npm package version. PRs welcome! Follow @reactnative

Getting Started · Learn the Basics · Showcase · Contribute · Community · Support

React Native brings React's declarative UI framework to iOS and Android. With React Native, you use native UI controls and have full access to the native platform.

  • Declarative. React makes it painless to create interactive UIs. Declarative views make your code more predictable and easier to debug.
  • Component-Based. Build encapsulated components that manage their state, then compose them to make complex UIs.
  • Developer Velocity. See local changes in seconds. Changes to JavaScript code can be live reloaded without rebuilding the native app.
  • Portability. Reuse code across iOS, Android, and other platforms.

React Native is developed and supported by many companies and individual core contributors. Find out more in our ecosystem overview.

Contents

📋 Requirements

React Native apps may target iOS 11.0 and Android 5.0 (API 21) or newer. You may use Windows, macOS, or Linux as your development operating system, though building and running iOS apps is limited to macOS. Tools like Expo can be used to work around this.

🎉 Building your first React Native app

Follow the Getting Started guide. The recommended way to install React Native depends on your project. Here you can find short guides for the most common scenarios:

📖 Documentation

The full documentation for React Native can be found on our website.

The React Native documentation discusses components, APIs, and topics that are specific to React Native. For further documentation on the React API that is shared between React Native and React DOM, refer to the React documentation.

The source for the React Native documentation and website is hosted on a separate repo, @facebook/react-native-website.

🚀 Upgrading

Upgrading to new versions of React Native may give you access to more APIs, views, developer tools, and other goodies. See the Upgrading Guide for instructions.

React Native releases are discussed in this discussion repo.

👏 How to Contribute

The main purpose of this repository is to continue evolving React Native core. We want to make contributing to this project as easy and transparent as possible, and we are grateful to the community for contributing bug fixes and improvements. Read below to learn how you can take part in improving React Native.

Code of Conduct

Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Contributing Guide

Read our Contributing Guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to React Native.

Open Source Roadmap

You can learn more about our vision for React Native in the Roadmap.

Good First Issues

We have a list of good first issues that contain bugs which have a relatively limited scope. This is a great place to get started, gain experience, and get familiar with our contribution process.

Discussions

Larger discussions and proposals are discussed in @react-native-community/discussions-and-proposals.

📄 License

React Native is MIT licensed, as found in the LICENSE file.

React Native documentation is Creative Commons licensed, as found in the LICENSE-docs file.