Commit Graph

65 Commits

Author SHA1 Message Date
Sam Zhou 0530ea3349 Migrate to suppression with error code in xplat: 1/n (#53439)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/53439

Changelog: [Internal]

Reviewed By: panagosg7

Differential Revision: D80809220

fbshipit-source-id: 6f432d8302934b9fee9780ac1d6ba6c87c0b3899
2025-08-22 10:35:39 -07:00
Sam Zhou cf664c65e2 Standardize subtyping error code into incompatible-type in react native and metro (#53312)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/53312

Changelog: [Internal]

Reviewed By: jbrown215

Differential Revision: D80400976

fbshipit-source-id: 196af69c0b9621b2a2675b232406639773e04933
2025-08-18 09:04:31 -07:00
Sam Zhou 23c8787fe2 Add annotations to fix future errors after fix for unsound array types (#52691)
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
2025-07-17 17:30:43 -07:00
Marco Wang 68650badd2 Pre-suppress errors for null_void for xplat js (#52480)
Summary:
Changelog: [Internal]

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

Reviewed By: SamChou19815

Differential Revision: D77890434

fbshipit-source-id: cc0571e0ff1c7cec3fff8614f688d46e46970cc4
2025-07-07 20:35:08 -07:00
Christoph Purrer e8709355dc C++ Turbo Module > Allow Promise<void> types (#52388)
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
2025-07-06 19:53:51 -07:00
Tim Yung 1977dd6596 RN: Sort Pragmas in Headers (#51554)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51554

Sorts pragma directives file headers in React Native.

Changelog:
[Internal]

Reviewed By: SamChou19815

Differential Revision: D75264593

fbshipit-source-id: 9e4b253dd0fc94dc2fc469d7114b93a8aae305f4
2025-05-22 21:18:53 -07:00
Dawid Małecki ddcab831b1 Migrate already root exported deep imports in rn-tester. (#50958)
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
2025-04-28 07:24:46 -07:00
Nick Gerleman a7e7651586 Use standard infra for sample legacy module example
Summary: Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D72896577

fbshipit-source-id: 5d3d10a274385e9c73eda48f841fdf58e1f0869a
2025-04-14 19:34:27 -07:00
Wu Zhong 6a3e275d14 Reland RNTester: Fixes turbo module examples error in bridgeless mode (#49329)
Summary:
Reland https://github.com/facebook/react-native/issues/48362.

## Changelog:

[IOS] [FIXED] - RNTester: Fixes turbo module examples error in bridgeless mode

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

Test Plan: RNTester turbomodule examples in bridgeless can work as expected.

Reviewed By: christophpurrer

Differential Revision: D69463612

Pulled By: cortinico

fbshipit-source-id: 8613b001ebbe64ce0d505f5515bb7a4b6a64dbe7
2025-02-11 10:56:19 -08:00
zhongwuzw 62831e740c RNTester: Fixes turbo module examples error in bridgeless mode (#48362)
Summary:
In https://github.com/facebook/react-native/issues/47598 , we removed `__turboModuleProxy ` in bridgeless mode, it would produce error in rntester turbomodule examples, fix it by change `__turboModuleProxy` to `nativeModuleProxy`. RSNara can you please help to review? :)

before:
![image](https://github.com/user-attachments/assets/bf8edc50-6dbc-4465-9936-36ec9112761b)

After:
![image](https://github.com/user-attachments/assets/2d5c1546-d758-4692-a9a7-5cf195edc015)

## Changelog:

[IOS] [FIXED] - RNTester: Fixes turbo module examples error in bridgeless mode

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

Test Plan: RNTester turbomodule examples in bridgeless can work as expected.

Reviewed By: shwanton

Differential Revision: D67603884

Pulled By: cortinico

fbshipit-source-id: d905fa0535da5fde5e7ebff1d453ea761be9f42f
2025-02-11 05:28:58 -08:00
Sam Zhou 722f5ba786 Remove global React$ type references (#49276)
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
2025-02-07 18:01:43 -08:00
Christoph Purrer 67981efa14 Fix Turbo Module example in RNTester in bridgeless mode (#49028)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/49028

## Changelog: [General] [Fixed]] - Fix Turbo Module example in RNTester in bridgeless mode

Reviewed By: cortinico, philIip

Differential Revision: D68810934

fbshipit-source-id: 5eab0e72fe383974fe02747acd1683a995300d4d
2025-01-29 11:06:49 -08:00
Dawid Małecki f36bfe5dfa Remove redundant {||} syntax (#48686)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48686

Changelog:
[Internal] - Removed redundant `{||}` syntax

Reviewed By: javache

Differential Revision: D68205038

fbshipit-source-id: f7d3271142b6443a5859c3b668b7aebd3ce3ef3f
2025-01-15 07:07:01 -08:00
Nicola Corti 13900d75b8 Remove replaceAll from RNTester sample code (#48099)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48099

This is currently breaking the Sample Module screen on RN-Tester. Let's remove it.

Changelog:
[Internal] [Changed] - Remove replaceAll from RNTester sample code

Reviewed By: cipolleschi

Differential Revision: D66764656

fbshipit-source-id: acd123374d23b37977d5506f70f29da7f5d6311f
2024-12-05 09:54:47 -08:00
Tim Yung c9ea05552f RN: Fix lint/sort-imports Errors (#47109)
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
2024-10-18 04:07:02 -07:00
Peter Abbondanzo 09682b5109 Fix dark mode text (#46898)
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
2024-10-10 11:02:18 -07:00
Christoph Purrer 6340662d4f Add C++ Turbo Module enum Event Emitter example (#46049)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46049

## Changelog:

[General] [Added] - Add C++ Turbo Module enum Event Emitter example

Reviewed By: kentwilliam

Differential Revision: D61336742

fbshipit-source-id: 81ac54020f4d88dc3c1235541d613a59235069a3
2024-08-19 08:26:20 -07:00
Nicola Corti d01f1b3214 Add support for handling com.facebook.react.bridge.Dynamic as parameter type in TurboModules (#45944)
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
2024-08-12 12:56:38 -07:00
Sam Zhou 5b96e90f77 Replace React.Element<any> and unnecessarily specific React.Element with React.MixedElement (#45923)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45923

Changelog: [Internal]

Reviewed By: gkz

Differential Revision: D60872182

fbshipit-source-id: b81fb43968c52cbfdb4a9fa57f1175aabc2a3939
2024-08-06 21:33:08 -07:00
Christoph Purrer 84a9f5e6c8 Add Java Turbo Module Event Emitter example (#44906)
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
2024-06-28 09:41:02 -07:00
Christoph Purrer 42f136d00d Turbo Module EventEmitters as functions (#44886)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44886

## Changelog:

[General] [Added] - Turbo Module EventEmitters as functions

Reviewed By: javache

Differential Revision: D58429202

fbshipit-source-id: c56793d216f5ecf981e62d3b004f715110903945
2024-06-11 23:35:36 -07:00
Christoph Purrer 6a3a305628 Add C++ Turbo Module Event Emitter example (#44810)
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
2024-06-11 21:12:33 -07:00
Kudo Chien d999e9bf1e Add BindingsInstaller for TurboModules on Android (#44526)
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
2024-05-30 20:43:27 -07:00
Christoph Purrer 1be073e832 Fix assert Turbo Module example crash the app when tap Run all tests (#44607)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44607

Same as https://github.com/facebook/react-native/pull/41521?fbclid=IwAR1X3qRAyVCZIy2w2T7tmqd1FYVCqrT2TyO-gszIgJ0XKN6F60ODkq_K3nI for the Java / ObjC Turbo Module example.

Changelog: [INTERNAL] [FIXED] - [RN-Tester] Fix assert Turbo Module example crash the app when tap `Run all tests`

Reviewed By: cortinico

Differential Revision: D57531736

fbshipit-source-id: 7cad5dfd31c306dff4763b67466664f2dde6b239
2024-05-20 10:31:17 -07:00
Christoph Purrer c96c893374 Support emitting typed RCTDeviceEmitter events
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
2024-04-30 11:16:57 -07:00
Sam Zhou 41f525ccae Pre-suppress unsafe string key access errors in xplat/js (#44221)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44221

This diff pre-suppresses errors of the following pattern, to prepare for the next Flow release.

```
declare const obj: {foo: string};
declare const key: string;
obj[key]; // error: invalid-computed-prop
```

Changelog: [Internal]

Reviewed By: alexmckenley

Differential Revision: D56477899

fbshipit-source-id: 5676b8685bd3157a519fe433cfce0fa28e003502
2024-04-23 11:36:14 -07:00
Christoph Purrer db609ff0c6 Add function properties to C++ TM complex datatyes (#41810)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41810

Changelog: [Internal]

Reviewed By: zeyap

Differential Revision: D51858746

fbshipit-source-id: e45ee68fc40e8b7ae3388ecdcedfec646d022e19
2023-12-05 23:27:06 -08:00
Christoph Purrer ead73de464 Add a BinaryTreeNode example for Cxx TMs (#41767)
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
2023-12-04 05:54:50 -08:00
Christoph Purrer 5754b4a123 Add GraphNode example for Cxx TMs (#41766)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41766

Changelog: [Internal]

Adds a simple example showing a recursive node, stored inside a collection 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.

Reviewed By: rshest

Differential Revision: D51783974

fbshipit-source-id: 7352db1a354cd7da32febc650f7cc5e10dd16d2d
2023-12-04 04:19:47 -08:00
zhongwuzw 02bb50d9ce Fix assert cxx example crash the app when tap Run all tests (#41521)
Summary:
When I tap the `Run all tests` button in CxxModuleExample, App crashed because our `assert` examples directoly.
![image](https://github.com/facebook/react-native/assets/5061845/6d3fbbc1-9d41-419a-9074-898e839ee51a)
I moved the error report examples to individual section so `Run all tests` not crash.
![image](https://github.com/facebook/react-native/assets/5061845/4b781b40-0606-4d40-a752-1cd716073e33)

## Changelog:
[INTERNAL] [FIXED] - [RN-Tester] Fix assert cxx example crash the app when tap `Run all tests`

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

Test Plan: None.

Reviewed By: christophpurrer

Differential Revision: D51423538

Pulled By: rshest

fbshipit-source-id: 1e2844aa9011de4476ec4b134d43daa3260a73d5
2023-11-17 06:10:00 -08:00
Christoph Purrer 9320174df4 Cxx TurboModules > Add example to return a JS function from Cxx to JS (#41385)
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
2023-11-09 11:38:54 -08:00
Moti Zilberman d6e0bc714a Enable lint/sort-imports everywhere (#41334)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41334

TSIA.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D51025812

fbshipit-source-id: e10d437be775a6b80946483aa96460f34927f870
2023-11-06 12:59:38 -08:00
Krystof Woldrich 7612e6601a feat(tm-android): Reject Promise if Turbo Module method throws an Error (#37484)
Summary:
### [iOS change here](https://github.com/facebook/react-native/pull/40764)

This PR builds upon the previous work done in https://github.com/facebook/react-native/pull/36925, which introduced native stack traces to the JSError for synchronous functions.

The current modifications concentrate on functions that return Promises. Prior to this PR, errors within Promise-returning functions would be thrown at the platform layer crashing the app without a link to the JS stack.

After the implementation of this PR, errors thrown within Promise-returning functions are now captured and transformed into rejected Promises. These rejected Promises contain a JS Error object that contains both the JS stack trace and the cause, along with the platform stack trace.

Additionally, this PR ensures that rejections from native functions are now linked to the JS stack trace, providing a more comprehensive view of the rejection flow.

## 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
-->

[GENERAL][ADDED] - Turbo Modules Promise-returning functions reject with JS and platform stack traces information

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

Test Plan:
| Android |
|--------|
| ![function_promise_android](https://github.com/krystofwoldrich/react-native/assets/31292499/1d1a3adf-986a-47b4-b98b-9e766176b7ae) |

Example of intentionally rejected promise on Android:

```
{
  "name": "Error",
  "message": "Exception in HostFunction: intentional promise rejection",
  "stack": "[native code]\ntryCallTwo@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:25844:9\ndoResolve@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:25975:25\nPromise@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:25863:14\n[native code]\nrejectPromise@http://10.0.2.2:8081/js/examples/TurboModule/SampleTurboModuleExample.bundle?platform=android&lazy=true&app=com.facebook.react.uiapp&modulesOnly=true&dev=true&minify=false&runModule=true&shallow=true:42:70\nonPress@http://10.0.2.2:8081/js/examples/TurboModule/SampleTurboModuleExample.bundle?platform=android&lazy=true&app=com.facebook.react.uiapp&modulesOnly=true&dev=true&minify=false&runModule=true&shallow=true:242:71\n_performTransitionSideEffects@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:51896:22\n_receiveSignal@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:51852:45\nonResponderRelease@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:51715:34\ninvokeGuardedCallbackProd@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:2962:21\ninvokeGuardedCallback@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:3048:42\ninvokeGuardedCallbackAndCatchFirstError@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:3051:36\nexecuteDispatch@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:3115:48\nexecuteDispatchesInOrder@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:3132:26\nexecuteDispatchesAndRelease@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:4856:35\nforEach@[native code]\nforEachAccumulated@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:3574:22\nrunEventsInBatch@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:4874:27\nrunExtractedPluginEventsInBatch@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:4896:25\nhttp://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:4914:42\nbatchedUpdates$1@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:14750:20\nbatchedUpdates@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:4845:36\ndispatchEvent@http://10.0.2.2:8081/js/RNTesterApp.android.bundle?platform=android&dev=true&lazy=true&minify=false&app=com.facebook.react.uiapp&modulesOnly=false&runModule=true:4907:23",
  "cause": {
    "nativeStackAndroid": [
      {
        "lineNumber": 173,
        "file": "SampleTurboModule.java",
        "methodName": "getValueWithPromise",
        "class": "com.facebook.fbreact.specs.SampleTurboModule"
      },
      {
        "lineNumber": -2,
        "file": "NativeRunnable.java",
        "methodName": "run",
        "class": "com.facebook.jni.NativeRunnable"
      },
      {
        "lineNumber": 942,
        "file": "Handler.java",
        "methodName": "handleCallback",
        "class": "android.os.Handler"
      },
      {
        "lineNumber": 99,
        "file": "Handler.java",
        "methodName": "dispatchMessage",
        "class": "android.os.Handler"
      },
      {
        "lineNumber": 27,
        "file": "MessageQueueThreadHandler.java",
        "methodName": "dispatchMessage",
        "class": "com.facebook.react.bridge.queue.MessageQueueThreadHandler"
      },
      {
        "lineNumber": 201,
        "file": "Looper.java",
        "methodName": "loopOnce",
        "class": "android.os.Looper"
      },
      {
        "lineNumber": 288,
        "file": "Looper.java",
        "methodName": "loop",
        "class": "android.os.Looper"
      },
      {
        "lineNumber": 228,
        "file": "MessageQueueThreadImpl.java",
        "methodName": "run",
        "class": "com.facebook.react.bridge.queue.MessageQueueThreadImpl$4"
      },
      {
        "lineNumber": 1012,
        "file": "Thread.java",
        "methodName": "run",
        "class": "java.lang.Thread"
      }
    ],
    "userInfo": null,
    "message": "intentional promise rejection",
    "code": "code 1"
  }
}
```

How I logged out the Errors:

```js
console.log('Error in JS:', JSON.stringify({
  name: e.name,
  message: e.message,
  stack: e.stack,
  ...e,
}, null, 2));
```

Reviewed By: RSNara

Differential Revision: D50613349

Pulled By: javache

fbshipit-source-id: b49c469118c8d8d27c43164f110dfe57ddd592d9
2023-10-27 10:20:40 -07:00
Ramanpreet Nara 04852fd6fc Interop example: Make argument to getRootTag deterministic (#40947)
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
2023-10-13 16:53:38 -07:00
Ramanpreet Nara de1fb8f7fd Sort object properties in interop test
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
2023-10-11 19:03:01 -07:00
Ramanpreet Nara 271ce7edbc Fix and re-introduce interop test (#39690)
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
2023-09-27 10:18:50 -07:00
Ramanpreet Nara 145659241a Introduce SampleLegacyModule example in RNTester (#38539)
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
2023-08-21 17:58:46 -07:00
Ramanpreet Nara 99e332e5b2 Introduce jest-e2e test for TurboModule Interop (#38206)
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
2023-07-11 11:42:43 -07:00
Ramanpreet Nara a1b64b7f15 Introduce SampleLegacyModule example in RNTester (#38008)
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
2023-06-21 18:30:09 -07:00
Nick Gerleman ea12c4c3d0 Fixup fbsource for $ArrayLike FlatList data (#37314)
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
2023-05-08 15:49:50 -07:00
Christoph Purrer f5c0606185 Add jsi::HostObject example to rn-tester (#36909)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36909

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D44978689

fbshipit-source-id: 0e31b5c37a7890744694706994ea672c3e619341
2023-04-14 13:58:39 -07:00
Krystof Woldrich 12a102b926 Add error reporting examples to rn-tester turbo modules (#36729)
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
2023-04-03 08:34:59 -07:00
Pieter De Baets 0a8164d993 Fix off-by-one error in cxx codegen (#36574)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36574

We would previously generate the following codegen for optional args

```
return static_cast<NativeAudioModuleCxxSpecJSI *>(&turboModule)->playAudio(
    rt,
    args[0].asString(rt),
    args[1].isNull() || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asString(rt)),
    args[2].isNull() || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asString(rt)),
    args[3].asNumber(),
    count < 4 || args[4].isNull() || args[4].isUndefined() ? std::nullopt : std::make_optional(args[4].asObject(rt)),
    count < 5 || args[5].isNull() || args[5].isUndefined() ? std::nullopt : std::make_optional(args[5].asObject(rt)),
    count < 6 || args[6].isNull() || args[6].isUndefined() ? std::nullopt : std::make_optional(args[6].asBool())
);
```

However, the counts checked are off-by-one, causing us to incorrectly process args.

Changelog: [General][Fixed] Issue with TurboModule C++ codegen with optional args

Differential Revision: D44299193

fbshipit-source-id: f00b9f5e09c2f524f9393137346c256d8b6b2979
2023-03-22 16:57:40 -07:00
Ruslan Shestopalyuk 95e20ed9a6 Refactor Android/iOS/C++ TurboModule examples in RNTester/Catalyst
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
2023-02-28 06:31:49 -08:00
Ruslan Shestopalyuk e106a62b1a Add device event emit test for the sample C++ TurboModule (#36278)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36278

[Changelog][Internal]

The diff creates a test clause for [TurboModule::emitDeviceEvent C++ API for TurboModules](https://www.internalfb.com/code/fbsource/[929870c905c8fe68cb330ce96bda7eb703bb6ae6]/xplat/js/react-native-github/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h?lines=90), which can be seen in either Catalyst or RNTester.

Reviewed By: cipolleschi

Differential Revision: D43466327

fbshipit-source-id: ff4c111b4beaab72b13d2bd89ed03023c9c7b3cf
2023-02-24 06:49:14 -08:00
Pieter Vanderwerff 260aab74ce Deploy presuppressions for v0.200.0 to xplat
Reviewed By: mroch

Differential Revision: D43377746

fbshipit-source-id: 288fe8639420931ccc2f1b50a5f35090a2f023c3
2023-02-17 13:36:03 -08:00
Vitali Zaidman ceb1d0dea6 Generate enum types that would be allowed to be used as well as string/number in c++ turbo modules generators (#36030)
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
2023-02-13 15:09:44 -08:00
Christoph Purrer 7c82a3fa11 Add enum example to Android/iOS rn-tester TurboModule (#35133)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35133

Add enum example to Android/iOS rn-tester TurboModule

Changelog:
[General][Added] - Add enum example to Android/iOS rn-tester TurboModule

Reviewed By: javache, cipolleschi

Differential Revision: D40711269

fbshipit-source-id: c8ad6fb7dee40b45b696660cc4d78921edafd8a1
2023-02-08 22:49:30 -08:00
Christoph Purrer 292a9904c4 react-native code-gen > C++ TurboModules enum example (#36083)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36083

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D43036612

fbshipit-source-id: fc70650bc4ba48d11f489556d1290ae9e7e58016
2023-02-08 20:24:28 -08:00
Sam Zhou ccefad049a Enable LTI in react-native
Summary: Changelog: [Internal]

Reviewed By: panagosg7

Differential Revision: D41788271

fbshipit-source-id: 8e40dc3279ee0283b2845b9559a80862fdf59a17
2022-12-06 19:34:14 -08:00