A framework for building native macOS apps with React.
Перейти к файлу
Xin Chen 89ef5bd6f9 Add TraceUpdateOverlay to RN AppContainer
Summary:
This diff adds `TraceUpdateOverlay` native component to RN `AppContainer.js`. This will enable the overlay when the build is in DEV environment and the DevTools global hook exists. It also closed gap between the JS dev mode and native dev support flag, so that the native component will be available when used by JS.

## Update (2/13/2023)
Instead of the original approach where I put a default value to the devsupport manager flag, I did ui manager check from JS and make sure the native component exists before using it. This is cleaner.

## Problem
Since the `AppContainer` is being used by all RN apps, we need to make sure the native component is registered in UI Manager of the RN app when it's used. Currently, the native component lives in the `DebugCorePackage.java`, which is added to the RN app [when the `DevSupportManager` is used](https://fburl.com/code/muqmqbsa). However, there's no way to tell if an app is using dev support manager in JS, hence there are gaps when the JS code uses `TraceUpdateOverlay`, vs when the native code registered the native component. This issue caused test error in [ReactNativePerfTest](https://fburl.com/testinfra/j24wzh46) from the [previous diff](https://fburl.com/diff/bv9ckhm7), and it actually prevents Flipper from running this properly as shown in this video:

https://pxl.cl/2sqKf

The errors shown in Flipper indicates the RN surface from the plugin is also missing `TraceUpdateOverlay` in its UI Manager:

{F869168865}

## Solution
To fix this issue, we should find a way to expose if the app is using dev support manager in JS. Or we should set to use DevSupportManager whenever it's a dev build as claimed in JS. I will try to find some way to achieve either one of this. I am open to suggestions here for where I should add the native component to. Given that it's used in the AppContainer, and any app could be built in development mode, I don't want to make people to manually add this native component themselves.

## Alternatives
There are some other approaches that could mitigate the issue, but less ideal:

For the test issue
1) Add `setUseDeveloperSupport(true)` to [ReactNativeTestRule.java](https://fburl.com/code/7jaoamdp). That will make the related test pass by using the DevSupportPackages, which has the native component. However, it only fixes tests using that class.

2) Override the package for [ReactNativeTestRule.java](https://fburl.com/code/b4em32fa), or `addPackage` with more packages including the native component. Again this only fixes this test.

3) Add the native component to the [`MainReactPackage`](https://fburl.com/code/nlayho86), which is what I did here in this diff. This would fix more cases as this package is [recommended to be used](https://fburl.com/code/53eweuoh) for all RN app. However, it may not fix all the cases if the RN app didn't manually use it.

4) Add the native component in the [`CoreModulesPackage`](https://fburl.com/code/lfeklztl), which will make all RN apps work, but at the cost of increase package size when this feature is not needed. Or, we could argue that we want to have highlights on trace updates for production build as well?

Changelog:
[Internal] - Enable TraceUpdateOverlay to RN AppContainer

Reviewed By: rubennorte

Differential Revision: D43180893

fbshipit-source-id: a1530cc6e2a9d8c905bdfe5d622d85c4712266f8
2023-02-14 22:32:55 -08:00
.bundle Introduce Gemfile, ruby-version (#32303) 2021-10-01 21:22:26 -07:00
.circleci fix: update executor for packages publishing workflow (#36146) 2023-02-14 07:06:53 -08:00
.github Stale issues more frequently (4 times a day) (#36130) 2023-02-13 06:30:22 -08:00
IntegrationTests Upgrade to Flow 0.198.1 2023-01-23 07:38:48 -08:00
Libraries Add TraceUpdateOverlay to RN AppContainer 2023-02-14 22:32:55 -08:00
React feat: add invoking dev menu on iOS by pressing `d` in terminal (#36115) 2023-02-14 04:33:39 -08:00
ReactAndroid Deprecate LazyReactPackage.getReactModuleInfoProviderViaReflection 2023-02-14 14:31:52 -08:00
ReactCommon Remove config null check 2023-02-14 09:42:43 -08:00
android RNGP - Various improvements needed for 3rd party libs (#35496) 2022-11-29 02:56:35 -08:00
docs
flow Implement DOMRect and DOMRectReadOnly matching Web 2023-02-09 09:36:08 -08:00
flow-typed/npm RN: Normalize `flow-typed` Definitions 2022-09-30 14:28:48 -07:00
gradle Bump Gradle to 7.6 (#35481) 2022-11-28 02:14:35 -08:00
jest Provide timestamp as argument to rAF callbacks when running Jest tests (#35919) 2023-01-23 09:53:01 -08:00
keystores
local-cli Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
packages fix[virtualized-lists]: do not ship tests in npm package (#36143) 2023-02-14 04:12:39 -08:00
repo-config Deploy 0.199.1 to xplat 2023-02-03 14:25:53 -08:00
scripts Fix missing node error message not printed correctly (#36140) 2023-02-14 07:05:03 -08:00
sdks/hermes-engine Stabilize Hermes build in CI (#36137) 2023-02-13 05:51:02 -08:00
template Hardcode concurrentRootEnabled to true when Fabric is enabled (#36107) 2023-02-10 01:06:17 -08:00
third-party-podspecs Remove remaining TV_OS fragments (#35110) 2022-10-28 02:50:49 -07:00
tools Update React Native's synced sort-imports lint rule 2023-01-30 17:05:25 -08:00
types fix: remove unavailable EventEmitter TS export (#36109) 2023-02-14 10:12:34 -08:00
.babelrc react-native code-gen > C++ TurboModules enum example (#36083) 2023-02-08 20:24:28 -08:00
.buckconfig Add support for Buck oncall annotations (#35562) 2022-12-05 06:12:46 -08:00
.buckjavaargs
.clang-format
.editorconfig Revert removal of CRLF from Windows bat files (#31398) 2021-09-09 22:44:32 -07:00
.eslintignore RN: Enforce `flow-typed` Signatures 2022-09-30 14:28:48 -07:00
.eslintrc.js eslint config & plugin packages - prep for monorepo RFC (#34581) 2022-11-25 05:44:17 -08:00
.flowconfig Deploy 0.199.1 to xplat 2023-02-03 14:25:53 -08:00
.flowconfig.android Deploy 0.199.1 to xplat 2023-02-03 14:25:53 -08:00
.gitignore chore: untrack stack dumps; `*.stackdump` (#35530) 2022-12-02 04:04:51 -08:00
.node-version Bump node version from 16 to 18 (#35443) 2022-11-25 06:44:21 -08:00
.prettierrc JS: Upgrade to Prettier v2.4.1 [1/n] 2021-11-02 22:14:16 -07:00
.ruby-version Bump Circle CI macOS container to Xcode 14.0.1, Ruby to 2.7.6, CocoaPods 1.11.3 (#34884) 2022-10-11 18:27:25 -07:00
BUCK Add enum example to Android/iOS rn-tester TurboModule (#35133) 2023-02-08 22:49:30 -08:00
CHANGELOG.md add 0.71.3 changelog (#36149) 2023-02-14 06:51:38 -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 Update CONTRIBUTING.md, replace wiki links (#34035) 2022-06-21 19:30:23 -07:00
ECOSYSTEM.md Updates to ecosystem.md do clarify community roles (#34341) 2022-09-26 14:27:11 -07:00
Gemfile Bump activesupport to 6.1.7.1 to address CVE-2023-22796 2023-02-08 11:23:08 -08:00
Gemfile.lock Bump activesupport to 6.1.7.1 to address CVE-2023-22796 2023-02-08 11:23:08 -08:00
LICENSE Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
LICENSE-docs
README.md Move expo samples to a service account. 2022-11-25 08:40:46 -08:00
React-Core.podspec Restore Dynamic framework with Hermes in the Old Architecture 2023-01-30 04:25:26 -08:00
React.podspec Update .podspec license information (#35245) 2022-11-07 09:52:52 -08:00
build.gradle.kts Do not use a mixture of plugins{} and buildscript{} 2023-02-10 10:04:55 -08:00
cli.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
gradle.properties Do not specify a Kotlin version in the RN rootProject (#33589) 2022-04-08 03:44:56 -07:00
gradlew Bump Gradle to 7.6 (#35481) 2022-11-28 02:14:35 -08:00
gradlew.bat Bump Gradle to 7.6 (#35481) 2022-11-28 02:14:35 -08:00
index.js Reconnect VirtualizedList Source History 2/2 (Apply D41745930 + history, D42805202, D43063551) 2023-02-06 20:00:19 -08:00
interface.js fixed typo in interface.js (#36049) 2023-02-03 08:12:29 -08:00
jest-preset.js feat(jest): move Jest config to use a custom react-native Jest env (#34971) 2022-10-17 12:40:25 -07:00
jest.config.js Fail tests on `console.error()` or `console.warn()` 2022-12-01 06:59:04 -08:00
metro.config.js Blacklist sdks/hermes from Metro resolution (#34452) 2022-08-19 02:32:02 -07:00
package.json Upgrade react-devtools-core to 4.27.2 2023-02-13 10:49:13 -08:00
react-native.config.js Upgrade RN CLI to v8 alpha (#33610) 2022-04-12 04:17:20 -07:00
rn-get-polyfills.js refactor(react-native/polyfills): rename package to @react-native/js-polyfills and align version 2022-12-05 18:34:33 -08:00
runXcodeTests.sh Use realpath instead of readlink 2022-02-22 02:23:02 -08:00
settings.gradle.kts Setup publishing for Snapshot and Stable on Maven (#34967) 2022-10-13 03:08:22 -07:00
template.config.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
yarn.lock Upgrade react-devtools-core to 4.27.2 2023-02-13 10:49:13 -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 12.4 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.