Граф коммитов

570 Коммитов

Автор SHA1 Сообщение Дата
Jesse Katsumata 3cebd35b95 (eslint-config): update eslint-plugin-react-native (#30350)
Summary:
Currently, installing `react-native-community/eslint-config` with projects using eslint v7 causes the following warning

```
warning "react-native-community/eslint-config > eslint-plugin-react-native@3.8.1" has incorrect peer dependency "eslint@^3.17.0 || ^4 || ^5 || ^6".
```

This PR updates the eslint-plugin-react-native module to suppress the warning

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Internal] [Changed] - update eslint-plugin-react-native for community eslint-config

Pull Request resolved: https://github.com/facebook/react-native/pull/30350

Test Plan: eslint working without error with projects using eslint v7

Reviewed By: GijsWeterings

Differential Revision: D25480912

Pulled By: nadiia

fbshipit-source-id: 2a956070e5bb75168d68501f9ec9486a34011349
2020-12-14 06:12:34 -08:00
Ron Edelstein 933cef6d9a More explicit marking of autoglob as False
Summary:
In preparation for flipping the default, marking autoglob as False in places where it isn't explicitly specified.

Changelog: [Internal]

Reviewed By: strulovich

Differential Revision: D25497305

fbshipit-source-id: 142e5caca2d67efcb3c25067a36934f7f6dd4b21
2020-12-11 16:45:55 -08:00
Ramanpreet Nara 74fd6fb1da Codemod: Migrate from bridge.eventDispatcher to RCTModuleRegistry
Summary:
All NativeModules that use the bridge to require the eventDispatcher are now instead using the RCTModuleRegistry I introduced in D25412847 (0ed81b28d3).

## What does this codemod do?
For all ObjC files that contain `synthesize bridge = _bridge`, migrate calls that access the React Native bridge from `self`, and use it to load the event dispatcher.

**Thoughts on Codemod Safety:** If we can access the bridge from self, then that means that if we synthesize the module registry, we can access the module registry from self. Therefore, this codemod is safe.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25449795

fbshipit-source-id: 2f7235d14659e73d673ae08763dc2cccdde55a19
2020-12-11 10:42:28 -08:00
Ramanpreet Nara 0ed81b28d3 Introduce RCTModuleRegistry
Summary:
## Problem
Many of our NativeModules are TurboModule-compatible. All our TurboModules currently use the bridge to require other NativeModules/TurboModules. As we migrate more surfaces to Venice, this lookup in many of these TurboModules will break, because the bridge will be nil.

## Initial Solution
We migrate all these TurboModules over to the turboModuleRegistry. In FBiOS, this will work because all NativeModules are TurboModule-compatible, and should [have the turboModuleRegistry attached to them by the TurboModuleManager](https://fburl.com/diffusion/d747fbc3). However, this solution has a few problems:
- If the TurboModule is used within a TurboModule-disabled app, it will break, because turboModuleRegistry will be nil on the module. Therefore, this solution isn't portable/flexible across apps.
- Longer term, we should deprecate synthesize bridge inside NativeModules. With this approach, we can't remove the synthesize bridge = bridge call from the NativeModule.

## Suggested Solution
Both NativeModules and TurboModules will be given access to an `RCTModuleRegistry` object. The RCTModuleRegistry object will use the TurboModuleManager when available and the Bridge when available to query for NativeModules and TurboModules. Otherwise, it'll just return nil.

When we do a lookup via this RCTModuleRegistry:
- In Venice, the bridge will be nil, so we won't search the bridge.
- In FBiOS, the bridge and the TurboModuleManager will be non-nil, so we'll first search the bridge, and then the TurboModuleManager.
- In standalone apps, the TurboModuleManager will be nil, so we'll only do a lookup on the bridge.

Long story short, RCTModuleRegistry will do the right thing in all scenarios.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D25412847

fbshipit-source-id: 13f41276158d90c68ab4925e518d71a2f369c210
2020-12-10 20:23:16 -08:00
Kevin Gozali 072896e3b7 Android: introduced uimanager/interfaces target for base symbols used by codegen output
Summary:
Some of the existing files under uimanager/ are self contained and used by the component codegen output. This commit split out those files into a dedicated uimanager/interfaces/ dir/target so that more targets can depend on it without causing dep cycle.

Also, the component codegen output doesn't need LayoutShadowNode at all, so this removed the import.

This will allow us to combine the Java codegen output for TM spec and Fabric components, simplifying build and dependency management (not in this commit yet).

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D25451409

fbshipit-source-id: 827545a3d78ebed1815cf9e52da2fa896b012aa1
2020-12-10 00:06:21 -08:00
Su Min Kim 8dddaa85f0 Add modal example (#30406)
Summary:
Add examples for Modal component in RNTester for:
- onDismiss (iOS)
  - Note: there may be an issue with onDismiss (https://github.com/facebook/react-native/issues/29455 )
- onShow
- hardwareAccelerated (Android)
- statusBarTranslucent (Android)

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Add] - Added examples for Modal component in RNTester

Pull Request resolved: https://github.com/facebook/react-native/pull/30406

Test Plan: ![Example GIF](http://g.recordit.co/mu3KFo3FMt.gif)

Reviewed By: PeteTheHeat

Differential Revision: D25399097

Pulled By: rickhanlonii

fbshipit-source-id: e688d35b0fc04cecf01d3fbc3253abae40c62b67
2020-12-09 22:53:46 -08:00
Kevin Gozali 3af21381df Codegen Android: allow generating Fabric Java component files during build time
Summary:
This commit:
* Generate Fabric component Java files along side Java NativeModule specs, when `USE_FABRIC=1` is set
* Adjust the component codegen to place output files in a subdir based on package name
* Adjust existing Buck targets to filter the right nativemodule vs component java files (this avoids duplicated symbols)
* Compiles the Java output during build time on RNTester/ReactAndroid (Gradle)

Not in this commit:
* Fabric C++ files
* Removing checked-in generated component files.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D25416614

fbshipit-source-id: fd670ead2198c9b5a65812c692b7aed9f3d7cd58
2020-12-09 09:19:33 -08:00
Evan Gilbert f52e3b3e8b Workaround for react-native-web failing to build
Summary:
There is partially compiled TurboModule code in [NativeAnimatedModule](https://fburl.com/diffusion/g91a70ng) that fails to build with:
`"File neither contains a module declaration, nor a component declaration. For module declarations, please make sure your file has an InterfaceDeclaration extending TurboModule. For component declarations, please make sure your file has a default export calling the codegenNativeComponent<Props>(...) macro"`

This diff removes react-native-web from the TurboModules logic while we work on a cleaner solution, tracked in T80868008

msdkland[metro]
Changelog: [Internal]

Reviewed By: cpojer, RSNara

Differential Revision: D25325163

fbshipit-source-id: 346abf52660073f976b0f978cbfbfc8402f4b3ee
2020-12-08 17:45:28 -08:00
Su Min Kim 84dde677d9 Add accessibility examples (#30379)
Summary:
Added examples to RNTester for the AccessibilityInfo API for:
1. SetAccessibilityFocus()
2. isReduceMotionEnabled()
3. iOS Only
   a. isBoldTextEnabled()
   b. isGrayScaleEnabled()
   c. isInvertColorsEnabled()
   d. isReduceTransparencyEnabled()

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Added] - Add new examples to the Accessibility API page

Pull Request resolved: https://github.com/facebook/react-native/pull/30379

Test Plan: ![iOS GIF](http://g.recordit.co/pmzvQXYjdD.gif)

Reviewed By: TheSavior

Differential Revision: D25245329

Pulled By: rickhanlonii

fbshipit-source-id: e9c11c775410075199b4e1011b3dac0acd972e89
2020-12-08 10:17:44 -08:00
Su Min Kim 158abfe8bf Add scrollview example (#30454)
Summary:
Add missing examples to ScrollView for RNTester.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Added] - Add missing examples to ScrollView for RNTester.

Pull Request resolved: https://github.com/facebook/react-native/pull/30454

Test Plan: There are a lot of examples that have been added that affects the UI (see RNCore Excel sheet for details).

Reviewed By: sammy-SC

Differential Revision: D25310613

Pulled By: rickhanlonii

fbshipit-source-id: 64a771aa8d3c3683eed983b0c36625078e5533fe
2020-12-05 16:04:52 -08:00
Ramanpreet Nara 898f73deef Introduce `visit(ast, visitor)` utility
Summary:
In the Codegen, we need to answer the following questions:

*Question:* What are all the calls into TurboModuleRegistry?
*Answer:* Find all CallExpressions that represent TurboModuleRegistry.get<Spec>() or TurboModuleRegisty.getEnforcing<Spec>().

*Question:* Is this a component spec?
*Answer:* Does this spec have a CallExpression where the callee is 'codegenNativeComponent'?

*Question:* Is this a module spec?
*Answer:* Does this spec have an interface that extends TurboModule?

All these answers can be implemented using the visitor pattern. Hence, this diff introduces the `visit` utility, and uses it to answer these questions.

**Motivation:** Cleaner code.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D25162617

fbshipit-source-id: 66ec95fc07ecb29aa9bf9993cb826204af283d03
2020-12-04 14:21:53 -08:00
Ramanpreet Nara 3e5779ce93 Move num(NativeModule flow interface) > 1 error into `buildModuleSchema`
Summary:
**Motivation:** After this change, we can show this ParserError using the React Native Module ESLint rule. Previously when we declared more than one NativeModule spec in a file, we incorrectly reported that there were *no* NativeModule specs in the file.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D25163299

fbshipit-source-id: 92bc09d09cdbc323e0ac1f317c40a767880f5bc2
2020-12-04 14:21:53 -08:00
Ramanpreet Nara 1de76d2842 Rename the `guard` utility to `tryParse`
Summary:
## What is `guard`?
`guard` accepts some JavaScript function that can throw a ParserError. If a ParserError is thrown by that JavaScript function, it captures and pushes the error to some global array, and returns null. If no ParserError is thrown, it simply returns the return value of the JavaScript function. This utility is used in the NativeModule spec parser to help it continue parsing even after it detects errors. Why do we want to do this? In the NativeModule spec linter, we want to display all these ParserErrors via ESLint.

## Changes
This diff renames `guard` to `tryParse` because `tryParse` more appropriately captures the intent/function of this utility: the work passed to it "tries" to parse some Flow types. A name like "guard" is a bit more ambiguous: What is it guarding against? What is the work doing? ¯\_(ツ)_/¯

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D25156185

fbshipit-source-id: 516647770579daa8613dbd67535074823f1aa848
2020-12-04 14:21:52 -08:00
Ramanpreet Nara e289366b38 Move TurboModuleRegistry validation into NativeModule Spec Parser
Summary:
## Changes
1. In the NativeModule spec parser, the moduleName is now being extracted from the TurboModuleRegistry.get<Spec>(...) call by examining the Flow ast node. Previously, we used regex parsing, which was unsafe because it could be fooled by TurboModuleRegistry.get<Spec>(...) calls in comments.
2. The logic to parse and validate the TurboModuleRegistry.get<Spec>(...) call is now centralized in the NativeModule Spec Parser (it was removed from the react-native-modules ESLint rule). The linter is now only responsible for three things:
   1. Detecting if a JavaScript file contains a TurboModuleRegistry.get<Spec> call or a TurboModule interface, and if so
   2. Running the NativeModule spec parser on it.
   3. It also validates that the Module spec's filename starts with the prefix "Native".

The React Native Modules linter now completely delegates to the NativeModules Spec parser, without doing any error checking of its own. If an error is reported by the React Native Modules linter, and that error doesn't have anything to do with the "Native" prefix, then it *must* be addressed. Otherwise, it will cause the NativeModule Spec Parser to fail on that particular spec.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D25153243

fbshipit-source-id: da74dbb66b1d8dca3a2b1952402222c6696b73d6
2020-12-04 14:21:52 -08:00
Janic Duplessis 0959ff36d1 Move hermes to a separate podspec (#30478)
Summary:
Hermes being a subspec of ReactCore causes some build issues when RN is included in 2 different targets. It also causes it to include a lot of additional dependencies that it doesn't need. This moves it to a separate podspec loosely based on other specs in ReactCommon.

## Changelog

[iOS] [Fixed] - Move hermes to a separate podspec

Pull Request resolved: https://github.com/facebook/react-native/pull/30478

Test Plan: Test that it builds and run properly in an app

Reviewed By: fkgozali

Differential Revision: D25308237

Pulled By: hramos

fbshipit-source-id: b4cc44ea2b1b854831e881dbbf9a2f30f6704001
2020-12-03 20:08:00 -08:00
Janic Duplessis 7f16ff8a05 Fix use_framework RNTester crash (#30520)
Summary:
When building RN Tester with use_frameworks it crashes on launch because of duplicate folly singletons. Seems that it is included twice because of Flipper. From what I understand flipper is not really compatible with use_frameworks so this removes it from that build variant. We also remove hardcoded SONARKIT defines in the xcodeproject, those will be added by the Flipper podspec anyway so it is not needed.

This then exposed a missing double conversion header error in Folly so this fixes the DoubleConversion podspec to add its headers path to the user project.

## Changelog

[Internal] [Fixed] - Fix use_framework RNTester crash

Pull Request resolved: https://github.com/facebook/react-native/pull/30520

Test Plan: Tested RN tester with use frameworks on and off. Also made sure flipper works still when frameworks is false.

Reviewed By: fkgozali

Differential Revision: D25307973

Pulled By: hramos

fbshipit-source-id: 17b90e871734e32f5982c4fc9c07aeea232f868f
2020-12-03 16:01:47 -08:00
Nick Gerleman 540735383d Fix RNTester Not Resizing Examples on Rotation/Resize (#30376)
Summary:
Fixes https://github.com/facebook/react-native/issues/30325

After the RNTester redesign, a style started globally caching screen width. This isn't needed, but means that width is incorrect if the device is rotated, or a window is resized. Rely on default layout which will be 100% width instead.
## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Internal] [Fixed] - Fix RNTester Not Resizing Examples on Rotation/Resize

Pull Request resolved: https://github.com/facebook/react-native/pull/30376

Test Plan: Tested viewing an example and rotating the device in iOS simulator

Reviewed By: rickhanlonii

Differential Revision: D25098642

Pulled By: appden

fbshipit-source-id: 9acdb656da7de9fda05f6091b36f8d9aa2155524
2020-12-03 09:39:17 -08:00
Héctor Ramos 5eee2f2bc0 Fix Circle CI iOS Tests: Make FBReactNativeSpec dir as needed
Summary:
Quick fix for Circle CI: Ensure FBReactNativeSpec dir exists before touching files.

Changelog:
[Internal]

Reviewed By: fkgozali

Differential Revision: D25285573

fbshipit-source-id: 8dec496856c90accc687648d7068aadfea24d72b
2020-12-02 16:13:03 -08:00
Héctor Ramos c901c1fbce Integrate Native Module codegen into Xcode build pipeline (#30449)
Summary:
Move the codegen invocation out of Podfiles and into the FBReactNativeSpec Pod itself. With this change, developers do not need to modify their existing project's Podfiles, and yet the codegen will be integrated into their projects automatically by way of the FBReactNativeSpec Pod.

This is accomplished in part by injecting a script build phase into the Pods Xcode project that is generated by CocoaPods. The build phase will save the output of the codegen script to a log in the derived files directory. The codegen will be executed if the codegen log file is not present, or if the contents of the Libraries directory has changed.

The codegen will thus be invoked in these situations:

**RNTester:**
* When `packages/rn-tester/RNTesterPods.xcworkspace` is built, if the codegen output logfile is not present or if the input files have changed.

**OSS React Native apps:**
* When `ios/AwesomeProject.xcworkspace` is built, if the codegen output file is not present or if the input files have changed. Normally, this should not happen, as we do not expect folks to update the contents of `node_modules/react-native/Libraries`.

Pull Request resolved: https://github.com/facebook/react-native/pull/30449

Changelog: [Internal] - Moved codegen invocation out of Podfile and into FBReactNativeSpec Pod

Reviewed By: fkgozali

Differential Revision: D25138896

fbshipit-source-id: 4779f822459cea2c30fd544eee19a49e8d80153d
2020-12-02 14:27:50 -08:00
Su Min Kim a4a517a09d Add example for focus and blur events to AppStateExample (#30381)
Summary:
Added an example to test focus and blur events in AppState (Android only)

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Added] - Add example for focus and blur events to AppStateExample

Pull Request resolved: https://github.com/facebook/react-native/pull/30381

Test Plan: ![Example](http://g.recordit.co/6FGnSzKQaG.gif)

Reviewed By: cpojer

Differential Revision: D25245334

Pulled By: rickhanlonii

fbshipit-source-id: 916f18a74140cc43e0d513eb4073cbcc44e41427
2020-12-02 09:04:13 -08:00
Kshitij Kotasthane 328590d2d9 Added examples for SectionList (#30390)
Summary:
`Added examples for the following missing props in SectionList`
* Prop: initialNumToRender
* Prop: ListEmptyComponent
* Prop: onEndReached

**Motivation** - Missing examples for these props in the RNTester app
## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Added] - `Added examples for the missing props in SectionList`

Pull Request resolved: https://github.com/facebook/react-native/pull/30390

Test Plan:
![empty](https://user-images.githubusercontent.com/26821140/99139935-49667000-2663-11eb-8b89-5a6b17abc3e9.png)
![end](https://user-images.githubusercontent.com/26821140/99139944-4e2b2400-2663-11eb-8e95-08e863614dec.png)

Reviewed By: cpojer

Differential Revision: D25245322

Pulled By: rickhanlonii

fbshipit-source-id: 3e44b9cf86128f1d3df535799519631cf2296a7e
2020-12-02 09:00:06 -08:00
Su Min Kim 5cf4ab8dd2 Remove filter pills from example page (#30198)
Summary:
rickhanlonii
Removes filter pills from example page in RNTester app.

## Changelog
Removed filter pills from example page by changing hideFilterPills property to true in RNTesterExampleList.js
<div>
<img src="https://user-images.githubusercontent.com/43835229/96194048-88e05600-0f17-11eb-9262-660a7a4bb170.png" width="200" height="400" style="float:left" />
<img src="https://user-images.githubusercontent.com/43835229/96194345-26d42080-0f18-11eb-9af2-bbf9fcc9518a.png" width="200" height="400" />
</div>

[Android] [Removed] - Remove filter pills
[iOS] [Removed] - Remove filter pills

Pull Request resolved: https://github.com/facebook/react-native/pull/30198

Test Plan:
RNTester app builds and runs as expected and filter pills are removed from the screen.
<div>
<img src="https://user-images.githubusercontent.com/43835229/96194077-9564ae80-0f17-11eb-821e-13da51d37581.png" width="200" height="400" style="float:left"/>
<img src="https://user-images.githubusercontent.com/43835229/96194532-8fbb9880-0f18-11eb-9ecf-48e1b4a9ac25.png" width="200" height="400" />
</div>

Reviewed By: cpojer

Differential Revision: D24395513

Pulled By: rickhanlonii

fbshipit-source-id: 7351ce8972185f973ad302d70929491cc6f56907
2020-12-01 09:06:23 -08:00
Tim Yung baa824826d RN: Call `NativeComponentRegistry` in Codegen
Summary:
Changes `react-native/babel-plugin-codegen` to generate calls to `NativeComponentRegistry` instead of `registerGeneratedViewConfig`.

The only notable changes in behavior from this will be:

1. In bridgeless mode, all components using `codegenNativeComponent` will no longer access `UIManager`.
2. In bridge mode, all components using `codegenNativeComponent` will no longer verify equivalence in production. Only in `__DEV__`. (This may improve performance slightly.)

This also changes the `ViewConfig` to be lazily allocated and drops support for `__INTERNAL_VIEW_CONFIG`, which we no longer need.

Changelog:
[Internal]

Reviewed By: JoshuaGross

Differential Revision: D25135881

fbshipit-source-id: ca2191872c02622ab2279b808102eeb1f664d207
2020-11-22 01:32:08 -08:00
Héctor Ramos e99b8bbb40 Use react-native-codegen@0.0.6 in new app template
Summary:
Use pre-built react-native-codegen library from npm in the iOS app template.
Built react-native-codegen from source when used with RNTester.
Published react-native-codegen@0.0.6.

Changelog:
[iOS][Added] - Use react-native-codegen in iOS app template
[Internal] - Bump react-native-codegen: 0.0.6

Reviewed By: fkgozali

Differential Revision: D25128036

fbshipit-source-id: f294c23b9b911aae6f404edc01b62426fb578477
2020-11-20 20:11:59 -08:00
Emily Janzer c0a2998387 Move TurboModuleManager to use RuntimeExecutor instead of jsContext (#30416)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/30416

This diff changes the constructor param for TurboModuleManager from jsContext (a long representing the `jsi::Runtime` pointer) to a RuntimeExecutor. It also updates callsites to use the new RuntimeExecutor created by CatalystInstance. This is only used for installing the TurboModule JSI binding; it's not currently used for JS invocation in TurboModules, which is handled separately by JSCallInvoker. Ultimately we may be able to implement JSCallInvoker *with* the provided RuntimeExecutor, but there's some additional logic in JSCallInvoker that we don't have here yet.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D21338930

fbshipit-source-id: 1480c328f1a1776ddf22752510c0f3b35168a489
2020-11-20 14:32:59 -08:00
Luke Walczak a7c1c5aff2 Add possibility to disable buttons in action sheet ios (#28979)
Summary:
_**Fixed**_ version of [the previous PR](https://github.com/facebook/react-native/pull/28792) after reverting [changes](c8d678abcf (commitcomment-39299254))

----

I've noticed that currently there is no option to disable button within the `ActionSheetIOS`. It can be really useful and decided to extend the API to support that functionality.

I added a new option called `disabledButtonsIndices` to `ActionSheetIOS` which is an array of button indices which should be disabled.

`ActionSheetIOS` documentation - PR https://github.com/facebook/react-native-website/pull/1898

## Changelog

[iOS] [Added] - Add disableButtonsIndices option to ActionSheetIOS component

Pull Request resolved: https://github.com/facebook/react-native/pull/28979

Test Plan:
1. Run the `RNTester`
2. Choose `ActionSheetIOS`
3. Check the fourth example `Show Action Sheet with disabled buttons`
4. `Option 1` and `Option 2` should be disabled

screenshot | gif
 --- | ---
<img width="493" alt="Screenshot 2020-04-30 at 15 16 22" src="https://user-images.githubusercontent.com/22746080/80739025-1ec52780-8b16-11ea-8b1c-30bb40ad8c99.png"> | <img src="https://user-images.githubusercontent.com/22746080/80739043-24227200-8b16-11ea-8bcb-af25eb57baac.gif" width="493" />

Reviewed By: sammy-SC

Differential Revision: D21727497

Pulled By: PeteTheHeat

fbshipit-source-id: 749b6c623eb8a44fe2bd96829ce89be5310e2368
2020-11-18 21:11:48 -08:00
Ramanpreet Nara 27cf82074d Guard against initializer interruptions in {Catalyst,Work,RNTester}TurboModuleManagerDelegate
Summary:
Migrate over to [how we load so libraries in Fb4aTurboModuleManagerDelegate](https://fburl.com/diffusion/wu0mcr8o).

## Motivation
When we migrated Twilight over to TurboModules, we used the CatalystTurboModuleManager as a template. This led to a production crash (T70918829) because we weren't loading so's this way. The fix: D24894071.

I'm updating these two TMMDelegates so that people don't fall into the same trap when migrating other Standalone apps.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24992931

fbshipit-source-id: 3ac3b8c30a67e24f79021f915abf5ae980d5b5d3
2020-11-17 00:34:48 -08:00
Kevin Gozali 58c80d4f8d Use codegen from source in default iOS template apps
Summary:
Add the `react-native-codegen` source to the `react-native` npm package.
Instead of using `react-native-codegen` from npm, the iOS app template will now build the package from source. Doing so removes the need to carefully time `react-native-codegen` npm releases to oss `react-native` releases, as the codegen and the oss release will be cut at the same time.

Changelog: [Internal] - Removed react-native-codegen dependency from iOS app template

Reviewed By: TheSavior

Differential Revision: D24904655

fbshipit-source-id: a07932bc748e2afb9359de584181bcb9dd0810ea
2020-11-12 22:30:28 -08:00
George Zahariev 6a039d7be3 Remove usage of deprecated @flow weak in Xplat
Summary:
This is the one usage of `flow weak` in Xplat - change it to normal `flow` and add a suppression where an error appears.

Changelog: [Internal]

Reviewed By: Hans-Halverson

Differential Revision: D24878970

fbshipit-source-id: 16e459c261b41e04de1555ed7ef4ecf2f5b3721e
2020-11-12 21:14:06 -08:00
Kevin Gozali 1bbcbd55ff Android OSS: fixed unbound variable error for codegen build script
Summary:
If $FBSOURCE_ENV isn't set, this failed with `/root/react-native/packages/react-native-codegen/android/../scripts/oss/build.sh: line 20: FBSOURCE_ENV: unbound variable`.

This commit fixes https://app.circleci.com/pipelines/github/facebook/react-native/7080/workflows/5cf18a1f-e6d2-4648-8217-d42e9a61fef1/jobs/176451

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24912950

fbshipit-source-id: 113e3dd7f78c75fc3adea0b21c9e38910be8c065
2020-11-11 22:39:27 -08:00
Janic Duplessis d5db2cb5d1 Build rn-codegen in a temporary directory (#30292)
Summary:
When running yarn install from the codegen directory it will reinstall all dependencies for the react-native workspace inside the react-native package. In my case this caused issues with metro because it would now have 2 copies of it (node_modules/metro and node_modules/react-native/node_modules/metro).

To avoid this copy the react-native-codegen source in a temporary directory and yarn install from there, then copy the built files back.

## Changelog

[Internal] - Build rn-codegen in a temporary directory

Pull Request resolved: https://github.com/facebook/react-native/pull/30292

Test Plan: Tested the script in an app with codegen enabled. Fresh install with rn-codegen not built, made sure no extra modules are installed under node_modules/react-native/node_modules.

Reviewed By: yungsters

Differential Revision: D24893216

Pulled By: fkgozali

fbshipit-source-id: 2c372b755632ea6f50ad5d4562248612b349a9a6
2020-11-11 19:17:12 -08:00
Nadiia D 8f5656b347 Update to eslint@7.12
Summary:
Changelog:
[Internal] - Upgrades eslint to 7.12

Reviewed By: cpojer

Differential Revision: D24552901

fbshipit-source-id: ede66ac9367702512436bfe3cf0254686300e10b
2020-11-10 00:08:44 -08:00
Kevin Gozali 803a26cb00 TM Android: Avoid creating TM instance if the module is not TM enabled
Summary:
There is a flow where TM registry is creating a module instance (as registered in the TurboReactPackage), only to discard it if it's not a TM enabled module. This may be fine for many modules, but for module like `UIManagerModule`, this may cause a race condition or other issues, including potential perf regression when accessing UIManager from JS (e.g. for getting native viewConfigs).

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D24811838

fbshipit-source-id: 6e1cce6993a6e5c9763773f175083bf52925c910
2020-11-09 02:24:41 -08:00
Ramanpreet Nara b6a72bac69 Extend babel-plugin-codegen to generate TurboModule JS codegen
Summary:
## New Functionality
- Detect if the JS file represents a NativeModule spec.
  - **Note:** A JS file is a NativeModule spec if it contains a flow `interface` that extends `TurboModule`. This logic is copied over from the OSS Codegen, here: 7ccb67a49c/packages/react-native-codegen/src/parsers/flow/index.js (L60-L75)
- For all NativeModule specs, generate the spec's schema using the OSS Codegen for Modules, and conditionally inline it into every `TurboModuleRegistry.get(Enforcing)?` call in the spec, like so:

**Before:**
```
/**
 * flow
 */

import type {TurboModule} from 'RCTExport';
export interface Spec extends TurboModule {
  //...
}

export default TurboModuleRegistry.get<Spec>('FooModule');
```

**After:**
```
/**
 * flow
 */

import type {TurboModule} from 'RCTExport';
export interface Spec extends TurboModule {
  //...
}

export default TurboModuleRegistry.get<Spec>('FooModule', __getModuleShape());

function __getModuleShape() {
  if (!(global.RN$EnableTurboModuleJSCodegen === true)) {
    return undefined;
  }

  return {...};
}
```

Changelog: [General][Added] Extend react-native/babel-plugin-codegen to generate TurboModule JS codegen

Reviewed By: TheSavior

Differential Revision: D22803845

fbshipit-source-id: 18c157a1dbfcc575012184de31c38908acd53c36
2020-11-08 14:24:05 -08:00
Ramanpreet Nara 00cfb0f919 Remove pipes from Object literal Flow types
Summary:
## Changes
{| ... |} -> { ... }

**Motivation:** In Flow, object literals are exact by default. So, there's no need for the pipes. Also: Now, the syntax for object literals is consistent across react-native-codegen.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24774771

fbshipit-source-id: 24ceb6f5876122aa8ad9e08c7e903215864ad6f5
2020-11-06 16:24:44 -08:00
Ramanpreet Nara 1ee406b9cc Pull out ReservedPropTypeAnnotation into type alias
Summary:
This type annotation was declared inline twice. Just pulling it out into a type alias in this diff.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24723191

fbshipit-source-id: 9f2061087172979ea838dfdf2533e17b9b559c71
2020-11-05 18:30:09 -08:00
Ramanpreet Nara 0de4b514be Simplify Int32EnumTypeAnnotation and StringEnumTypeAnnotation
Summary:
Int32EnumTypeAnnotation represents a union of numbers. In the corresponding type annotation, we represent options as `$ReadOnlyArray<{value: number}>`. Since each option is a number, we could instead represent options as `$ReadOnlyArray<number>` - there's no need to use an object with a singular property (i.e: 'value'). The same is could be said of StringEnumTypeAnnotation.

In this diff, we change `Int32EnumTypeAnnotation.options` to `$ReadOnlyArray<number>`, and `StringEnumTypeAnnotation.options` to `$ReadOnlyArray<string>`.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24723107

fbshipit-source-id: 4734cf72a4a29b6b321d8161bea70cf524ce0963
2020-11-05 18:30:09 -08:00
Ramanpreet Nara a31d7aa2d3 Standardize on one FunctionTypeAnnotation shape
Summary:
Commands are `FunctionTypeAnnotation`, but they don't have a return type. I this diff, I introduced a `FunctionTypeAnnotation<+P, +R>` utility type, and made the `CommandTypeAnnotation` be an instantiation of it, with the return type fixed to `VoidTypeAnnotation`.

Now, the shape of a FunctionTypeAnnotation is unified across the NativeModule and Component schemas.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24719965

fbshipit-source-id: 0089c3b23f05b0c534ba28dbe336c7f2db5866b3
2020-11-05 18:30:09 -08:00
Ramanpreet Nara 0d748cf8bb Rename NativeModulePropertySchema -> NativeModulePropertyShape
Summary:
Everywhere else in the CodegenSchema, type annotation partials are suffixed with "Shape". In the NativeModule schema, we were using the suffix "Schema". In this diff, we standardize on the "Shape" suffix.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24719395

fbshipit-source-id: 307935f5fe0681c31cd52e9cf4ae579f61c1ae68
2020-11-05 18:30:08 -08:00
Ramanpreet Nara c6b8c75b6b Remove miscellaneous exports of NativeModule Flow types in Codegen Schema
Summary:
CodegenSchema exports `NativeModuleMethodParamSchema` and `NativeModuleObjectTypeAnnotationPropertySchema`, which are partials of NativeModule type annotations. This creates unnecessary coupling between the type annotations of CodegenSchema and the files that depend on it.

**Actual Problem:** Suppose that we want to rename one of these partials. Then, all imports in all files would have to be updated, even when the actual shape of the composed type annotation wasn't changed.

This diff removes these partials, which reduces the surface area of the exports of CodegenSchema.js

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24719396

fbshipit-source-id: c822aaa252f156c524f4ef4917ebb61b1a39ff9e
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 04f235e7fb Rename Commands* -> Command*
Summary:
The names of events and props flow type annotations are singular. The names of the commands flow types are however plural. This diff renames all "Commands*" flow types to be singular.

**Motivation:** Consistency

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24708276

fbshipit-source-id: 5d5d2123426ca1139953169d0ea764b82b2f3809
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 688caa0bdc Introduce ObjectTypeAnnotation utility type
Summary:
All throughout the Codegen schema, we re-declare the following shape:
```
{
  type: 'ObjectTypeAnnotation',
  properties: $ReadOnlyArray<{
    name: string,
    optional: boolean,
    typeAnnotation: ...
  }>
}
```

This diff introduces an `ObjectTypeAnnotation<T>` utility type and replaces those re-declarations with instantiations of this type.

**Motivation:** To reduce noise in the CodegenSchema. This should be a pure refactor, and shouldn't actually change any behaviour.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24707963

fbshipit-source-id: 6b4eb711ddd041f3a041109ade5ad5644fb16924
2020-11-05 18:30:08 -08:00
Ramanpreet Nara b9f6937288 Reorganize CodegenSchema types into "use before declaration" order
Summary:
This diff re-organizes CodegenSchema to declare the larger types first, which use smaller undeclared types. The smaller types are declared further down the file, and they themselves use even smaller undeclared types.

**Motivation:** Increase the readability of CodegenSchema.js. Now, if people want to understand the shape of the Codegen Schema, they can just read the file from top to bottom.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24701424

fbshipit-source-id: 181e87bff5e32d998463221891f459b0df26ef52
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 1231db0d7f Rename ReservedFunctionValueTypeAnnotation to ReservedTypeAnnotation
Summary:
Reserved type annotations can appear in three different contexts: commands, props, and NativeModules. For now, commands and NativeModules share the same reserved type annotations. In the future, we may want to merge these reserved type annotations with the props reserved type annotations.

**Motivation:** The meaning of FunctionValue in FunctionValueTypeAnnotation isn't clear - in fact, it's downright confusing. Therefore, this diff renames this Flow type to ReservedTypeAnnotation, which I believe sufficiently captures the intent of the type annotation.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24701322

fbshipit-source-id: bde0273b4a89c9e7175c60ed3468ed870b320044
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 856bc2978c Introduce NamedShape utility type
Summary:
Our CodegenSchema is littered with types that have the following shape
```
{
  name: string,
  optional: boolean,
  typeAnnotation: ...
}
```

In all these types, the only difference is the typeAnnotation. This diff introduces a new utility type called `NamedShape`, that just creates this shape, given a type annotation. This should help reduce the amount of noise in the CodegenSchema, and make it a bit easier to read.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24701331

fbshipit-source-id: a30d3e22933116e3dabf7929615905febacecba3
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 0e46080847 Clean up EventObjectPropertyType
Summary:
All ObjectTypeAnnotation *properties* in the codegen have the following shape:
```
{
  name: string,
  optional: boolean,
  typeAnnotation: ...
}
```

EventObjectTypeProperty is a property of some ObjectTypeAnnotation, yet it doesn't follow this pattern. This diff cleans up EventObjectPropertyType. This is a part of a larger effort to clean up the Component Schema and unify the notion of a "type annotation" across the Component and Module schemas.

Reviewed By: yungsters

Differential Revision: D24701027

fbshipit-source-id: edc7dc632a217fb5a82ffd8a62aef990baf398c2
2020-11-05 18:30:07 -08:00
Christoph Nakazawa 3e77e15526 Continuous Integration cleanup
Reviewed By: yungsters

Differential Revision: D24700192

fbshipit-source-id: 239a8ad4848a41ad721a635d4ec37d990989f041
2020-11-05 06:09:36 -08:00
Kevin Gozali 8663ec4f42 Unbreak iOS build due to header import failure
Summary: Changelog: [Internal]

Reviewed By: p-sun, yungsters

Differential Revision: D24749871

fbshipit-source-id: 70692b8a32f9b7a214d7192ba444c695568e2ccf
2020-11-04 21:39:18 -08:00
Moti Zilberman 2ea7ae4b7c Remove worker param from rn_bundle() macro
Summary: Changelog: [Internal]

Reviewed By: MichaReiser

Differential Revision: D24728338

fbshipit-source-id: a4ed2ac8fdd0115872333f46f48b488af98e681b
2020-11-04 10:10:10 -08:00
Christoph Nakazawa bfb2c4be99 Rename `//xplat/js:experimental-packager` to `//xplat/js:metro-transform-worker`
Summary: Changelog: [Internal]

Reviewed By: MichaReiser

Differential Revision: D24678671

fbshipit-source-id: 7fc82f73b9f78411dd652f16260af61c18b539b2
2020-11-04 05:47:07 -08:00