Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52691
Unannotated array literals are unsound in Flow right now. This diff adds in annotations and makes a few things readonly, to reduce future errors.
Changelog: [Internal]
Reviewed By: marcoww6
Differential Revision: D78519638
fbshipit-source-id: d98a7668ecf97bcc87dcb3fad25ade736d885d9a
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52388
Changelog: [Internal]
Similar to `AsyncCallback<>` (the foundation of `AsyncPromise`) we should allow `void` Promise types in C++ such as `AsyncPromise<>`
Reviewed By: rbergerjr
Differential Revision: D77712020
fbshipit-source-id: d7360df5cc1b77f1e03e5fb73b0b468f6e3a415b
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50958
In rn-tester package there are many react-native deep imports which will be deprecated in the future. It is a starter for migrating rn-tester to using root imports instead. Only deep imports that are already root exported are changed. This diff avoids using `CodegenTypes` as it causes build errors and will be resolved in next stages.
Besides import changes, `PointerEvent` type is now also exported from the root.
Changelog:
[Internal]
Reviewed By: huntie
Differential Revision: D73656526
fbshipit-source-id: 5814a3d9c6a04b1236581dbbe291cd109e2c71c0
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/49276
This diff replaces the remaining `React$` global types in the codebase, in preparation for their removal in Flow.
Changelog: [Internal]
Reviewed By: NickGerleman
Differential Revision: D69322418
fbshipit-source-id: 058a2489ce8e6bf59df2ec4e61e9708f63561671
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47109
Fixes the `lint/sort-imports` errors that are now surfaced after fixing the lint configuration.
For a couple files, I added lint suppressions instead because the unsorted import ordering is important due to interleaved calls with side effects.
Changelog:
[Internal]
Reviewed By: GijsWeterings
Differential Revision: D64569485
fbshipit-source-id: 26415d792e2b9efe08c05d1436f723faae549882
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46898
Replaces *many* `Text` component usages with `RNTesterText`: a thin wrapper around `Text` that applies color based on the color scheme chosen by the user. It makes text legible for dark mode across 41 different example files. This changes intentionally do not touch a few larger component sites that expand beyond RNTester, like `Animated` and `NewAppScreen`
Changelog: [Internal]
Reviewed By: rshest
Differential Revision: D64053464
fbshipit-source-id: 9516fef2afe1b364eb38e85e3a2dbb5c434e44db
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45944
This diff adds support having (Legacy) Native Modules with functions with parameters of type `Dynamic`.
This is currently blocking some libraries making it harder for them to migrate to New Architecture.
I've implemented it by adding a `DynamicNative` implementation of `Dynamic` which holds a reference of
the payload as a `folly::dynamic`.
Changelog:
[Android] [Added] - Add support for handling `com.facebook.react.bridge.Dynamic` as parameter type in TurboModules
Reviewed By: mdvacca, cipolleschi
Differential Revision: D60966684
fbshipit-source-id: 2e63bc53ede5277a9c12f1b19f05f6099f5f35f9
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44906
Shows a proof of concept how '*strongly typed Turbo Module scoped*' `EventEmitters` can be used in a Java Turbo Module.
## Changelog:
[Android] [Added] - Add Java Turbo Module Event Emitter example
Reviewed By: javache
Differential Revision: D57530807
fbshipit-source-id: 04261d8885760f0e3b3c8c1931e0d56a5d33a0df
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44810
Adds an example how to use the `EventEmitter` on a (C++) Turbo Module
## Changelog:
[General] [Added] - Add C++ Turbo Module Event Emitter example
Reviewed By: javache
Differential Revision: D57473949
fbshipit-source-id: 1a8d17fb83af4220ef12379e0102b5b2e233ed45
Summary:
Add synchronous JS bindings installation for TurboModules. That would help some 3rd party JSI based modules to install JS bindings easier.
https://github.com/facebook/react-native/issues/44486 for Android
## Changelog:
[Android] [ADDED] - Add BindingsInstaller for TurboModules
Pull Request resolved: https://github.com/facebook/react-native/pull/44526
Test Plan:
Added test in RN-Tester TurboModule test case
{F1660267530}
{F1660287029}
Reviewed By: javache
Differential Revision: D57223328
Pulled By: philIip
fbshipit-source-id: d4a69a16f6ce77c0a0fd63f008bea929b1964ab8
Summary:
This enables to code-gen base C++ types for custom exported JS types from a RN TM spec - which have been previously excluded from code-gen as these aren't used in any function.
The only work around so far was to ‘register’ a random function using the custom type which should be used for RCTDeviceEventEmitter events
Changelog: [Internal]
Reviewed By: rshest
Differential Revision: D56685903
fbshipit-source-id: add9ca40018b91c9fca98609ba3d1f85d3affec1
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41767
Changelog: [Internal]
Adds a simple example showing a direct recursive node in a Cxx TM.
Currently we can't auto-generate [the necessary C++ Types](https://reactnative.dev/docs/next/the-new-architecture/cxx-custom-types#struct-generator) - but we can add it later if this scenarios becomes really common.
Direct recursive nodes, can't be value types - it would require infinite memory. Hence they are nullable and managed by a smart pointer.
Reviewed By: rshest
Differential Revision: D51784136
fbshipit-source-id: f6f0710d03583bdf1e6e72ba42d8df7f8ff8d915
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41385
Changelog: Internal
Adding a Cxx TM example which adds a listener and returns a subscription to remove that listener from the TM.
You should be able to use this with React Hooks - https://legacy.reactjs.org/docs/hooks-reference.html
E.g.
```
useEffect(() => {
const subscription = NativeCxxModuleExample.setValueCallbackWithSubscription(
callbackValue => // use it
);
return subscription;
});
```
Reviewed By: shwanton
Differential Revision: D50473063
fbshipit-source-id: 4e9b92aeccff1771eb4ffad6bdaa20ba7f18435f
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/40947
This shows up as this.context shows up as 1 sometimes. Let's just hard-code this to 11, to make the test more reliable.
Changelog: [Internal]
Reviewed By: mdvacca
Differential Revision: D50253990
fbshipit-source-id: 1da75e5e5f3226676f9af67fc329a70079eed59e
Summary:
It looks like objects properties aren't guaranteed to have a stable order. Sort them, before we serializae and print them to the screen in the interop test. This should reduce interop test flakyness.
Changelog: [Internal]
Reviewed By: makovkastar
Differential Revision: D50148860
fbshipit-source-id: a6ed1433d4dd35cafa5c9f7d09c4cca194c31d81
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39690
This diff re-introduces the test for the TurboModule interop layer.
This test was originally reverted in D49200360, because it was broken.
***New:*** This test runs in Bridgeless mode, with the interop layer enabled. (Catalyst is now native mobileconfig ready).
Changelog: [Internal]
Reviewed By: makovkastar
Differential Revision: D49208528
fbshipit-source-id: 3109d7826e7024fd7a1074321d4aab8f3a489609
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38539
We will use this example to:
- Showcase legacy module support in the TurboModule system in RNTester
- E2E test legacy module support in the TurboModule system
Changelog: [Internal]
Reviewed By: NickGerleman
Differential Revision: D47529295
fbshipit-source-id: b98e315741bed7740c36997d706f48e375b0c815
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38206
This test will ensure that the TurboModule interop layer works in Catalyst.
It will navigate to the sample legacy module screen, and ensure that all methods work.
Steps:
1. Open up Catalyst
2. Navigate to the Legacy Native Module example
3. Click "Run all tests"
4. Validate that all tests match expectations.
Changelog: [Internal]
Reviewed By: NickGerleman
Differential Revision: D46917689
fbshipit-source-id: 071f9324fa3719648c1a390bde4ba00a4e687e44
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38008
Introduce a legacy module (+ example) in RNTester.
In the future, SampleLegacyModule will be used to:
- Showcase the TurboModule interop layer in RNTester, once Bridgeless mode is ready
- E2E Test the TurboModule interop layer.
The TurboModule interop layer is just an extension to the TurboModule system that allows the system to create legacy modules. Unlike regular TurboModules, these legacy modules don't need codegen for JavaScript -> native method dispatch.
Changelog: [Internal]
Reviewed By: cipolleschi
Differential Revision: D46874160
fbshipit-source-id: f9810d0bdb3bd0c0a74099fcb6f74ca547977a53
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37314
Turns out we never transitioned fbsource to an API change we made for FlatList, due to mismatched `.js` and `.js.flow` files.
Inside of RN, `$ArrayLike` in Flow, unlike `ArrayLike` in TypeScript, treats `length` as writable. So we wrap that in `$ReadOnly`. Another option might be to inline our own version, since it is not the only [case where they differ](https://fb.workplace.com/groups/flow/permalink/24328911383397481/).
In product code, the changes end up impacting:
1. `getItemLayout` is no longer typed to receive a mutable array. I changed all of the incompatible explicit type parameters from `Array<ItemT>` to `Iterable<ItemT>`.
2. Flow has a harder time inferring destructured `data` in examples that were passing `any` to FlatList, so I needed to give some type hints where `data` was previously untyped
3. Replace some `$FlowFixMe[incompatible-type]` with `$FlowFixMe[incompatible-type-arg]`
Changelog: [Internal]
Reviewed By: lunaleaps
Differential Revision: D45665199
fbshipit-source-id: 59aa908e277a27f7ca88acb48de493d2782517a9
Summary:
This PR is adding examples of Turbo Modules functions throwing runtime exceptions and asserts. This should make it easier to collaborate and develop the error reporting for a new architecture that is being discussed in the React Native New Architecture Working Group -> https://github.com/reactwg/react-native-new-architecture/discussions/122.
I'm not sure what return type should be used for the JS function returning `Promise<void>` in Cxx, I used [`AsyncPromise<jsi::Value>`](https://github.com/facebook/react-native/pull/36729/files#diff-9cebc75f48fd35fd6fef71138f98dfd0ba28a754b2aab0d6fe44fd685f74ce16R135), what would you use, I've not found `void` type to use?
### Added functions
The table shows the current behavior.
<table>
<tr>
<td> Function
<td> Description
<td> Turbo Module
<td> Cxx Module
<tr>
<td> voidFuncThrows
<td> function with return type void throws a runtime exception
<td> platform error no JS stack trace
<td> JS error no native stack trace
<tr>
<td> getObjectThrows
<td> function with return type object throws a runtime exception
<td> JS error no platform stack trace
<td> JS error no native stack trace
<tr>
<td> promiseThrows
<td> function with return type promise throws a runtime exception before settling the promise
<td> platform error no JS stack trace
<td> JS error no native stack trace
<tr>
<td> voidFuncAssert
<td> function with return type void asserts
<td> platform error no JS stack trace
<td> native error no JS stack trace
<tr>
<td> getObjectAssert
<td> function with return type object asserts
<td> JS error no platform stack trace
<td> native error no JS stack trace
<tr>
<td> promiseAssert
<td> function with return type promise asserts before settling the promise
<td> platform error no JS stack trace
<td> native error no JS stack trace
</table>
## Changelog:
<!-- Help reviewers and the release process by writing your own changelog entry.
Pick one each for the category and type tags:
[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message
For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[INTERNAL] [ADDED] - Error reporting examples in rn-tester turbo modules
Pull Request resolved: https://github.com/facebook/react-native/pull/36729
Test Plan:
This PR doesn't change any RN behavior. Only shows the current state by adding an example to rn-tester.
I'm happy to add these examples to the unit/integration test, just point me to where would be a good place.
Reviewed By: rshest
Differential Revision: D44623027
Pulled By: javache
fbshipit-source-id: d9cc04852b05d810ed11d7a94f1b2d455ef554a5
Summary:
## Changelog:
[Internal] - Refactor Android/iOS/C++ TurboModule examples
~~This makes sure that both native and pure C++ (NativeCxx) TurboModule examples could be run from the Catalyst app.~~
EDIT: See the discussion - this removes the `Playground (NativeModules)` app from Catalyst, as it's already available from the `RNTester Browser` and doesn't provide the C++ counterpart.
Also, there are some tweaks and code factoring in styles, to make it all fit on the screen nicely.
Reviewed By: javache
Differential Revision: D43605250
fbshipit-source-id: 44ee694660f3ad524b8362149ebe617ee495225e
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36030
Generate enum types in c++ turbo modules.
For enums in the ts schema file such as:
```
export enum NumEnum {
ONE = 1,
TWO = 2,
}
```
This would export enums and the relevant Bridging to js and from js code to the spec H files such as:
```
#pragma mark - SampleTurboModuleCxxNumEnum
enum SampleTurboModuleCxxNumEnum { ONE, TWO };
template <>
struct Bridging<SampleTurboModuleCxxNumEnum> {
static SampleTurboModuleCxxNumEnum fromJs(jsi::Runtime &rt, int32_t value) {
if (value == 1) {
return SampleTurboModuleCxxNumEnum::ONE;
} else if (value == 2) {
return SampleTurboModuleCxxNumEnum::TWO;
} else {
throw jsi::JSError(rt, "No appropriate enum member found for value");
}
}
static jsi::Value toJs(jsi::Runtime &rt, SampleTurboModuleCxxNumEnum value) {
if (value == SampleTurboModuleCxxNumEnum::ONE) {
return bridging::toJs(rt, 1);
} else if (value == SampleTurboModuleCxxNumEnum::TWO) {
return bridging::toJs(rt, 2);
} else {
throw jsi::JSError(rt, "No appropriate enum member found for enum value");
}
}
};
```
That code would allow us to use these enums in the cxx files like this:
```
NativeCxxModuleExampleCxxEnumInt getNumEnum(
jsi::Runtime &rt,
NativeCxxModuleExampleCxxEnumInt arg);
```
Changelog: [General] [Added] Generate enum types that would be allowed to be used as well as string/number in c++ turbo modules generators
Reviewed By: christophpurrer
Differential Revision: D42884147
fbshipit-source-id: d34d1fc7ba268b570821dc108444196f69a431b2