Commit Graph

1046 Commits

Author SHA1 Message Date
Nick Gerleman c5bc3f1373 Use NSCAssert() in react_native_assert instead of C assert() (#36177)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36177

react_native_assert calls C `assert()`, where XCode does not have a built-in breakpoint navigator to hook to assertion failures (though you can add a symbolic breakpoint to "abort()" to get the effect). This changes the Apple implemented of `react_native_assert()` to use `NSCAssert` under the hood. This is safe to use in C functions, but will be trapped by the default XCode exceptions breakpoint navigator.

Changelog:
[iOS][Fixed] - Use NSCAssert() in react_native_assert instead of C assert()

Reviewed By: cipolleschi

Differential Revision: D43275024

fbshipit-source-id: 43c4e4f1ae6b99f32634d4b1880bce712c3ae8f6
2023-02-22 14:59:40 -08:00
Ruslan Shestopalyuk 407fb5c238 Implement ability to emit device events from C++ TurboModules
Summary:
[Changelog][Internal]

This adds a method, `emitDeviceEvent` to the C++ API of TurboModules, which allows to make calls to JS's `RCTDeviceEventEmitter.emit` from a C++ TurboModules.

This is a very common pattern, specifically for the VR apps, but not only for them - e.g. Desktop fork also has a [custom implementation for this](https://www.internalfb.com/code/fbsource/third-party/microsoft-fork-of-react-native/react-native-utils/RCTEventEmitter.cpp).

Note that my original intent was to actually backport the latter, however there are some complications with wiring things in a robust way, without exposing too much stuff and relying on singletons or folly::dynamic.

So I ended up adding it to the TurboModule API itself and use the scheduler/JSI facilities instead.

This approach is arguably well self-contained, uses high level APIs, and shouldn't be abusable much.

Since I was trying to avoid usage of folly::dynamic in this case, I used a kind of "value factory" pattern instead in order to send the arguments to the JS thread in a thread safe way (see [the discussion here](https://fb.workplace.com/groups/rn.fabric/permalink/1398711453593610/)).

Reviewed By: christophpurrer

Differential Revision: D43466326

fbshipit-source-id: a3cb8359d08a46421559edd0f854772863cb5c39
2023-02-21 15:15:31 -08:00
Riccardo Cipolleschi 5d175c6775 Break Circular Dependency between React-Codegen and React-Fabric (#36210)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36210

One of the circular dependencies we have in OSS was between React-Codegen and React-Fabric.

React-Codegen generates component which has to depends on React-Fabric because they need to use the files contained in the `react/renderer/view` folder.

React-Fabric contains some components that depends on RNCore, which was generated inside the React-Codegen folder.

This change generates the RNCore components inside the `ReactCommon/react/renderer/components/rncore` folder, breaking the dependency as `rncore` folder is now contained by React-Fabric itself.

**Fun Fact:** That's how it always should have been. There was already a line in the `.gitignore` to exclude the content of `ReactCommon/react/renderer/components/rncore` folder. I guess that with some of the refactoring/previous projects on Codegen, this requirements has slipped.

## Changelog:
[iOS][Breaking] -  generates RNCore components inside the ReactCommon folder and create a new pod for platform-specific ImageManager classes

Reviewed By: sammy-SC, dmytrorykun

Differential Revision: D43304641

fbshipit-source-id: ebb5033ce73dbcd03f880c3e204511fdce04b816
2023-02-20 11:50:10 -08:00
Riccardo Cipolleschi b1b2b8baaf Update podspecs with the right search paths
Summary:
Update podspecs with the right search paths to include the required framework by every module.

## Changelog:
[iOS][Changed] - Update search paths to support `use_frameworks!` with Fabric

Reviewed By: sammy-SC, dmytrorykun

Differential Revision: D43089372

fbshipit-source-id: 4bbfc4b98bd289d66ce4015429d581856d9c05b3
2023-02-20 11:50:10 -08:00
Samuel Susla 321868011b Avoid redundant copy of shared_ptr
Summary:
changelog: [internal]

Making a copy of shared_ptr is order of magnitude more expensive than moving it. This diff avoids two redundant copies in commit phase.

Reviewed By: rubennorte, cipolleschi

Differential Revision: D43306245

fbshipit-source-id: cfa942cc67b1e5c91be47803b80f7c8cda2e32d8
2023-02-16 13:42:26 -08:00
Joshua Selbo dff9f5bdef Disable Android platform for ReactCommon/react/renderer/core tests (#36176)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36176

Changelog: [Internal]

Reviewed By: IanChilds, javache

Differential Revision: D43322808

fbshipit-source-id: ad0cd88c7dc892a12438c33ee6fe2727825926a2
2023-02-16 10:32:11 -08:00
Moti Zilberman a064de151f Reduce use of assertions in parsing accessibility props
Summary:
Changelog:
[General][Fixed] - Reduce use of assertions when parsing accessibility props passed from JS

Fixes some more cases along the same lines as D43184380 (https://github.com/facebook/react-native/commit/d16c1a04d8ceaf6b6df07d734cd54d490b6c6093) and D43184994 (https://github.com/facebook/react-native/commit/ee4714e3693a3bd88215bd7a19ff805e3262b1c8).

Reviewed By: jacdebug

Differential Revision: D43324899

fbshipit-source-id: fb343203f16464009931f07592e663b06dcf20e7
2023-02-16 07:03:06 -08:00
Samuel Susla e665a0f995 Use std::shared_mutex instead of folly::shared_mutex
Summary:
changelog: [internal]

C++17 has implementation of shared_mutex in standard library. Let's use it instead of folly.

Reviewed By: cipolleschi

Differential Revision: D43275493

fbshipit-source-id: d766251226aa230110011aca94b4e697fe0d31a1
2023-02-16 06:25:26 -08:00
Nicola Corti 8486e191a1 Address New Architecture performance regressions by properly setting NDEBUG (#36172)
Summary:
It looks like we're not properly setting `NDEBUG` for "non debug" builds with CMake (the name is terrible but that's what Buck uses originally).

This configures `NDEBUG` correctly so that is set only for release variants, so that also `REACT_NATIVE_DEBUG` is set correctly (and we don't fire asserts on release builds).
This should address several performance regression we saw for New Architecture on some release scenarios (credits to sammy-SC for spotting it).

## Changelog

[ANDROID] [FIXED] - Address New Architecture performance regressions by properly setting NDEBUG

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

Test Plan:
I've tested this by checking the ninja output for the debug/release builds for the `YogaLayoutableShadowNode.cpp` file

### Debug (does not contain `-DNDEBUG`)

```
build ReactCommon/react/renderer/components/view/CMakeFiles/rrc_view.dir/YogaLayoutableShadowNode.cpp.o: CXX_COMPILER__rrc_view_Debug /Users/ncor/git/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp || cmake_object_order_depends_target_rrc_view
  DEFINES = -Drrc_view_EXPORTS
  DEP_FILE = ReactCommon/react/renderer/components/view/CMakeFiles/rrc_view.dir/YogaLayoutableShadowNode.cpp.o.d
  FLAGS = -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -frtti -stdlib=libc++ -g  -fno-limit-debug-info -fPIC -Wall -Werror -std=c++17 -fexceptions -frtti -Wpedantic -Wno-gnu-zero-variadic-macro-arguments -DLOG_TAG=\"Fabric\" -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DFOLLY_HAVE_RECVMMSG=1 -DFOLLY_HAVE_PTHREAD=1 -DFOLLY_HAVE_XSI_STRERROR_R=1
  INCLUDES = -I/Users/ncor/git/react-native/ReactCommon -I/Users/ncor/git/react-native/ReactAndroid/build/third-party-ndk/folly/. -I/Users/ncor/git/react-native/ReactAndroid/build/third-party-ndk/glog/exported -I/Users/ncor/git/react-native/ReactAndroid/build/third-party-ndk/double-conversion/. -I/Users/ncor/git/react-native/ReactAndroid/build/third-party-ndk/boost/boost_1_76_0 -I/Users/ncor/git/react-native/ReactAndroid/build/third-party-ndk/fmt/include -I/Users/ncor/git/react-native/ReactAndroid/src/main/jni/first-party/fbgloginit/. -I/Users/ncor/git/react-native/ReactCommon/jsi -I/Users/ncor/git/react-native/ReactCommon/logger/. -I/Users/ncor/git/react-native/ReactCommon/react/renderer/graphics/platform/android -I/Users/ncor/git/react-native/ReactAndroid/src/main/jni/first-party/fb/include -I/Users/ncor/git/react-native/ReactAndroid/src/main/jni/first-party/yogajni/jni -I/Users/ncor/git/react-native/ReactCommon/yoga/. -isystem /Users/ncor/.gradle/caches/transforms-3/ebdfaf25aad9044f80de924d25488688/transformed/fbjni-0.3.0/prefab/modules/fbjni/include
  OBJECT_DIR = ReactCommon/react/renderer/components/view/CMakeFiles/rrc_view.dir
  OBJECT_FILE_DIR = ReactCommon/react/renderer/components/view/CMakeFiles/rrc_view.dir
  TARGET_COMPILE_PDB = ReactCommon/react/renderer/components/view/CMakeFiles/rrc_view.dir/
  TARGET_PDB = /Users/ncor/git/react-native/ReactAndroid/build/intermediates/cxx/Debug/193k1y15/obj/arm64-v8a/librrc_view.pdb
```

### Release (does contain `-DNDEBUG`)

```
build ReactCommon/react/renderer/components/view/CMakeFiles/rrc_view.dir/YogaLayoutableShadowNode.cpp.o: CXX_COMPILER__rrc_view_RelWithDebInfo /Users/ncor/git/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp || cmake_object_order_depends_target_rrc_view
  DEFINES = -Drrc_view_EXPORTS
  DEP_FILE = ReactCommon/react/renderer/components/view/CMakeFiles/rrc_view.dir/YogaLayoutableShadowNode.cpp.o.d
  FLAGS = -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -frtti -stdlib=libc++ -O2 -g -DNDEBUG -fPIC -Wall -Werror -std=c++17 -fexceptions -frtti -Wpedantic -Wno-gnu-zero-variadic-macro-arguments -DLOG_TAG=\"Fabric\" -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DFOLLY_HAVE_RECVMMSG=1 -DFOLLY_HAVE_PTHREAD=1 -DFOLLY_HAVE_XSI_STRERROR_R=1
  INCLUDES = -I/Users/ncor/git/react-native/ReactCommon -I/Users/ncor/git/react-native/ReactAndroid/build/third-party-ndk/folly/. -I/Users/ncor/git/react-native/ReactAndroid/build/third-party-ndk/glog/exported -I/Users/ncor/git/react-native/ReactAndroid/build/third-party-ndk/double-conversion/. -I/Users/ncor/git/react-native/ReactAndroid/build/third-party-ndk/boost/boost_1_76_0 -I/Users/ncor/git/react-native/ReactAndroid/build/third-party-ndk/fmt/include -I/Users/ncor/git/react-native/ReactAndroid/src/main/jni/first-party/fbgloginit/. -I/Users/ncor/git/react-native/ReactCommon/jsi -I/Users/ncor/git/react-native/ReactCommon/logger/. -I/Users/ncor/git/react-native/ReactCommon/react/renderer/graphics/platform/android -I/Users/ncor/git/react-native/ReactAndroid/src/main/jni/first-party/fb/include -I/Users/ncor/git/react-native/ReactAndroid/src/main/jni/first-party/yogajni/jni -I/Users/ncor/git/react-native/ReactCommon/yoga/. -isystem /Users/ncor/.gradle/caches/transforms-3/ebdfaf25aad9044f80de924d25488688/transformed/fbjni-0.3.0/prefab/modules/fbjni/include
  OBJECT_DIR = ReactCommon/react/renderer/components/view/CMakeFiles/rrc_view.dir
  OBJECT_FILE_DIR = ReactCommon/react/renderer/components/view/CMakeFiles/rrc_view.dir
  TARGET_COMPILE_PDB = ReactCommon/react/renderer/components/view/CMakeFiles/rrc_view.dir/
  TARGET_PDB = /Users/ncor/git/react-native/ReactAndroid/build/intermediates/cxx/RelWithDebInfo/53pv2v65/obj/arm64-v8a/librrc_view.pdb
```

Reviewed By: sammy-SC, cipolleschi

Differential Revision: D43344120

Pulled By: cortinico

fbshipit-source-id: e0567aec2742c5dab2d008cdcf198f34d5626b65
2023-02-16 06:03:01 -08:00
Moti Zilberman ee4714e369 Consistently assign defaults when prop parsing fails (#36163)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36163

Changelog:
[General][Fixed] - Fix assertions in Fabric layout and transform prop parsing

Continues D43184380 by adding more graceful fallback paths to the prop parsing logic in Fabric.

Reviewed By: sammy-SC

Differential Revision: D43184994

fbshipit-source-id: 8f2bb6cdc23197a431b914b36523dce8a8af9b54
2023-02-15 15:40:24 -08:00
Moti Zilberman d16c1a04d8 Reduce use of assertions in prop parsing (#36164)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36164

Changelog:
[General][Fixed] - Invalid prop values no longer trigger assertion failures in Fabric

## Context

Fabric has historically been very strict about prop parsing. It originally `abort()`ed on any prop value that failed to parse according to the expected type; this was replaced with dev-only assertions in D27540903 (https://github.com/facebook/react-native/commit/cb37562f8355b624e271c5b74416c257b0e62a00). We've received feedback that C++ assertions (and other similar mechanisms in the legacy renderer) are still too aggressive and disruptive as a diagnostic for developers working on JS code.

We are changing React Native to behave more like a browser in this regard, reflecting a new principle that **bad style values are not runtime errors**. (See e.g. D43159284 (https://github.com/facebook/react-native/commit/d6e9891577c81503407adaa85db8f5bf97557db0).) The recommended way for developers to ensure they are passing correct style values is to use a typechecker (TypeScript or Flow) in conjunction with E2E tests and manual spot checks.

More broadly, values passed from JS product code should not be able to crash the app, which is why we're not strictly limiting this change to style props. From now on, if a JS developer can trigger an internal assertion in React Native simply by writing normal application code, that is a bug.

## This diff

This diff introduces a new macro called `react_native_expect` which serves as a drop-in replacement for `react_native_assert`, but logs (to glog / logcat / stdout) instead of asserting. This way we don't need to fully delete the existing call sites. This will be helpful if we decide that we want to repurpose these checks for a new, more visible diagnostic.

I'm *intentionally* opting for the simplest possible improvement here, which is to silence the assertions - not to print them to the JS console, not to convert them to LogBox warnings, etc. The hypothesis is that this is already strictly an improvement over the previous behaviour, will help us get to feature parity between renderers faster, and allow us to design improved diagnostics that are consistent and helpful.

## Next steps

1. There are still places where Fabric can hit an unguarded assertion in prop conversion code (e.g. unchecked casts from `RawValue` with no fallback code path). I will fix those in a separate diff.
2. Paper on iOS needs a similar treatment as it calls `RCTLogError` liberally during prop parsing (resulting in a native redbox experience that is nearly as bad as an outright crash). I will fix that in a separate diff.
3. I'll add some manual test cases to RNTester to cover these scenarios.
4. We will eventually need to take a clear stance on PropTypes, but since they provide reasonable, non-breaking diagnostics (recoverable JS LogBox + component stack) it is less urgent to do so.

Reviewed By: sammy-SC

Differential Revision: D43184380

fbshipit-source-id: 0c921efef297d935a2ae5acc57ff23171356014b
2023-02-15 15:40:24 -08:00
Pieter De Baets 167d52dacd Fix ComponentDescriptorProviderRegistry uninitialized fields
Summary:
`setComponentDescriptorProviderRequest` is only used on iOS for dynamic registration of additional components. This variable is not default initialized, so will point to invalid memory when a component is missing and thus crash.

Changelog: [Internal] Fix Android crash when component is missing

Reviewed By: rubennorte

Differential Revision: D43305656

fbshipit-source-id: 70dd2973d50abbfcc19e051bd24c1deb90883941
2023-02-15 08:13:23 -08:00
Riccardo Cipolleschi 0e09d6f8a6 Move files from .../textlayoutmanager/platform/ios to .../textlayoutmanager/platform/ios/react/renderer/textlayoutmanager (#36158)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36158

To properly setup the Header Search Paths for `use_frameworks!`, we need to move the files that are in the `.../textlayoutmanager/platform/ios` folder into the `.../textlayoutmanager/platform/ios/react/renderer/textlayoutmanager` folder.

This mimic the same folder structure we have also `android`

## Changelog
[iOS][Changed] Moved the files from `.../textlayoutmanager/platform/ios` to `.../textlayoutmanager/platform/ios/react/renderer/textlayoutmanager`

Reviewed By: cortinico

Differential Revision: D43088586

fbshipit-source-id: 9589fe62f36fbff2744fdfbf3475e95954424232
2023-02-15 04:17:06 -08:00
Riccardo Cipolleschi 931a4c5e23 Move files from .../imagemanager/platform/ios to .../imagemanager/platform/ios/react/renderer/imagemanager
Summary:
To properly setup the Header Search Paths for `use_frameworks!`, we need to move the files that are in the `.../imagemanager/platform/ios` folder into the `.../imagemanager/platform/ios/react/renderer/imagemanager` folder.

This mimic the same folder structure we have also `android`

## Changelog
[iOS][Changed] Moved the files from `.../imagemanager/platform/ios` to `.../imagemanager/platform/ios/react/renderer/imagemanager`

Reviewed By: cortinico

Differential Revision: D43088421

fbshipit-source-id: c3b86a95e67cc1ab9531997bb1bfbf011b7f730f
2023-02-15 04:17:06 -08:00
Riccardo Cipolleschi 5588e0fe0b Move files from .../textinput/iostextinput to .../textinput/iostextinput/react/renderer/components/iostextinput
Summary:
To properly setup the Header Search Paths for `use_frameworks!`, we need to move the files that are in the `.../textinput/iostextinput` folder into the `.../textinput/iostextinput/react/renderer/components/iostextinput` folder.

This mimic the same folder structure we have also `android`

## Changelog
[iOS][Changed] Moved the files from `.../textinput/iostextinput` to `.../textinput/iostextinput/react/renderer/components/iostextinput`

Reviewed By: cortinico

Differential Revision: D43084639

fbshipit-source-id: fe0f55d9f372bda0fbd59c6c567ac747ca308a69
2023-02-15 04:17:06 -08:00
Riccardo Cipolleschi d1e500c3b1 Move ReactCommon's .../nativemodule/xxx/platform/ios files to .../nativemodule/xxx/platform/ios/ReactCommon
Summary:
To properly setup the Header Search Paths for `use_frameworks!`, we need to move the files that are in the `.../nativemodule/xxx/platform/ios` folder into the `.../nativemodule/xxx/platform/ios/ReactCommon` folder.

We have two folders to migrate: `core` and `sample`.
As a cleanup, `sample` should be extracted from the codebase and moved to RNTester or a library as it can be used as an example to add more examples in the codebase that we ship to our users.

This mimic the same folder structure we have also in `cxx` and `android`

## Changelog
[iOS][Changed] Moved the files from `.../nativemodule/xxx/platform/ios` to `.../nativemodule/xxx/platform/ios/ReactCommon`

Reviewed By: cortinico

Differential Revision: D43082851

fbshipit-source-id: 414426274d9a5ab20cc0e76cdada0c2977264b5f
2023-02-15 04:17:06 -08:00
Riccardo Cipolleschi b5e4fea86e Move graphics' platform/ios files to graphics/platform/ios/react/renderer/graphics folder structure
Summary:
To Properly setup the Header Search Paths for `use_frameworks!`, we need to move the files that are in the `react/renderer/graphics/platform/ios` folder into the `react/renderer/graphics/platform/ios/react/renderer/graphics` folder.

This mimic the same folder structure we have also in `cxx` and `android`

## Changelog:
[iOS][Changed] - Moved the files from `.../platform/ios` to `.../platform/ios/react/renderer/graphics`

Reviewed By: sshic

Differential Revision: D43082032

fbshipit-source-id: 519d2e12eb7edd50b5f71bac5b1c618c6bf89919
2023-02-15 04:17:06 -08:00
Christoph Purrer c7597e50b3 ReactCommon > Minor BUCK clean-up (#36134)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36134

Removes unused or duplicated BUCK properties

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D43226189

fbshipit-source-id: 52806a9bde004427169b1f34600bd9d170566320
2023-02-13 10:45:14 -08:00
Samuel Susla 6439baaca1 Fix accessibilityRole and accessibilityTraits default values when node is cloned
Summary:
changelog: [internal]

There was a bug in prop parsing where `accessibilityRole` and `accessibilityTraits` had wrong default value. Instead of falling back to sourceProps, they would set role to empty and trait to none. The fix is to fall back to sourceProps.

The issue surfaces with Animated, which clones props.

Reviewed By: cipolleschi

Differential Revision: D43190775

fbshipit-source-id: ec6b48c082c1dcc5b6e81dbff4f92b3a58a41da2
2023-02-10 09:04:22 -08:00
Rubén Norte 97d90c66a8 Create synchronous method to get bounding client rect
Summary: Changelog: [internal] Added internal method in Fabric to synchronously get layout information

Reviewed By: sammy-SC

Differential Revision: D43080208

fbshipit-source-id: 8af9fe8ef9dbfe37c4b70101cc13e12905ee5b69
2023-02-09 09:36:08 -08:00
Rubén Norte 6018c19991 Fix computation of relative layouts when nodes are not displayed
Summary: Changelog: [General][Fixed] Fix computation of relative layout to return empty layout for nodes with display: none and children.

Reviewed By: sammy-SC

Differential Revision: D43045691

fbshipit-source-id: c7605cf320809ab1975e420ac1de58d72e1b8e44
2023-02-09 09:36:08 -08:00
Samuel Susla afec07aca2 Add option to make commit asynchronous
Summary:
changelog: [internal]

`useLayoutEffect` has two guarantees which React Native breaks:
- Layout metrics are ready.
- Updates triggered inside `useLayoutEffect` are applied before paint. State between first commit and update is not shown on the screen.

React Native breaks the first guarantee because it uses Background Executor. Background executor moves Yoga layout to another thread. If user core reads layout metrics in `useLayoutEffect` hook, it is a race. The information might be there, or it might not. They can even read partially update information. This diff does not affect this. We already have a way to turn off Background Executor. We haven't done this because it introduces regressions on one screen but we have a solution for that.

React Native breaks the second guarantee. After Fabric's commit phase, Fabric moves to mounting the changes right away. In this diff, we queue the mounting phase and give React a chance to change what is committed to the screen. To do that, we schedule a task with user blocking priority in `RuntimeScheduler`. React, if there is an update in `useLayoutEffect`, schedules a task in the scheduler with higher priority and stops the mounting phase.
We are not delaying mounting, this just gives React a chance to interrupt it.

Fabric commit phase may be triggered by different mechanisms. C++ state update, surface tear down, template update (not used atm), setNativeProps, to name a few. Fabric only needs to block paint if commit originates from React. Otherwise the scheduling is wrong and we will get into undefined behaviour land.

Rollout:
This change is gated behind `react_fabric:block_paint_for_use_layout_effect` and will be rolled out incrementally.

Reviewed By: javache

Differential Revision: D43083051

fbshipit-source-id: bb494cf56a11763e38dce7ba0093c4dafdd8bf43
2023-02-09 05:52:42 -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
Samuel Susla 2e3f55aced Pass MountingCoordinator by value instead of reference
Summary:
changelog: [internal]

Passing MountingCoordinator argument by value instead of reference. Using reference does not make sense since we eventually take ownership of shared_ptr anyway. This better communicates the intent.

Reviewed By: christophpurrer

Differential Revision: D43082955

fbshipit-source-id: 29e20abb9824c10a5f0d5e0ba1049ff6d67cee98
2023-02-08 15:48:17 -08:00
Samuel Susla 56cb19f419 Remove default arguments from ShadowTree::commit and ShadowTree::tryCommit
Summary:
Changelog: [Internal]

Caller needs to explicitly set commit options. This is for readability and making sure caller is aware of what are the options of the commit. This will be important in subsequent diff where we will add another commit option.

Reviewed By: christophpurrer

Differential Revision: D43082837

fbshipit-source-id: 1417205299c19430f902453c2b6d9bb9ca31707d
2023-02-08 06:58:33 -08:00
Deepak Jacob 9d98e2cb07 Revert D41273822: Add fabric support for maintainVisibleContentPosition on iOS
Differential Revision:
D41273822 (https://github.com/facebook/react-native/commit/ecf967a51d358f3759acbf7795675f52d7190280)

Original commit changeset: 7900898f2828

Original Phabricator Diff: D41273822 (https://github.com/facebook/react-native/commit/ecf967a51d358f3759acbf7795675f52d7190280)

fbshipit-source-id: 0f4b9695c805407b9a41b0fec63784bd0e84be43
2023-02-07 13:06:38 -08:00
Janic Duplessis ecf967a51d Add fabric support for maintainVisibleContentPosition on iOS (#35319)
Summary:
This adds support for the `maintainVisibleContentPosition` in iOS fabric. This was previously only implemented in the old renderer. The implementation is very similar to what we currently have.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[iOS] [Added] - Add fabric support for maintainVisibleContentPosition on iOS

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

Test Plan:
Test in RN tester example.

https://user-images.githubusercontent.com/2677334/201484543-f7944e34-6cb7-48d6-aa28-e2a7ccdfa666.mov

Reviewed By: sammy-SC

Differential Revision: D41273822

Pulled By: jacdebug

fbshipit-source-id: 7900898f28280ff01619a4af609d2a37437c7240
2023-02-07 02:54:06 -08:00
Ruslan Shestopalyuk 82a7968d09 Remove duplication of default field values in iterator-based prop parsing (#36051)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/36051

[Changelog][Internal]

This has been on my backlog for some time, submitting the diff to get it out of the way.

It makes the macro-based code in the "iterator-based property parsing" branch somewhat less horrible and less error prone (by removing duplication vs the default values in the class declaration).

Reviewed By: sammy-SC

Differential Revision: D42990595

fbshipit-source-id: e4b91160c6e09d3d1eab2ba70a58d390243bb335
2023-02-03 05:54:47 -08:00
Nicola Corti 147a1f6619 Add macro to detect circular dependencies on Cmake
Summary:
This is a prototype to add circular dependencies detection on CMake for ReactCommon and ReactAndroid.
It can be enabled per module and works as follows:

```
set(ALLOWED_HEADER_IMPORT_PATHS
        react/renderer/graphics
        react/debug)
check_for_circular_dependencies("${ALLOWED_HEADER_IMPORT_PATHS}")
```

The allowed header import path must be manually specified as libraries are exposing wrong header search paths (so can't be reused).
The CI will be red till the circular dependency on `graphics` is resolved.

Changelog:
[Internal] [Changed] - Add macro to detect circular dependencies on Cmake

Reviewed By: cipolleschi

Differential Revision: D42927036

fbshipit-source-id: b1393dfd43fd042e2ebf1d5b46b24bd9f5e20d58
2023-02-02 09:23:55 -08:00
gabrieldonadel 597a1ff60b feat: Add logical border block color properties (#35999)
Summary:
This PR implements logical border block color properties as requested on https://github.com/facebook/react-native/issues/34425. This implementation includes the addition of the following style properties

- `borderBlockColor`, equivalent to `borderTopColor` and `borderBottomColor`.
- `borderBlockEndColor`, equivalent to `borderBottomColor`.
- `borderBlockStartColor`, equivalent to `borderTopColor`.

## Changelog

[GENERAL] [ADDED] - Add logical border block color properties

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

Test Plan:
1. Open the RNTester app and navigate to the `View` page
2. Test the new style properties through the `Logical Border Color` section

<table>
<tr>
    <td>Android</td>
    <td>iOS</td>
</tr>
  <tr>
    <td><video src="https://user-images.githubusercontent.com/11707729/215384882-5b96518e-ad70-4157-a7f3-130f488cc41c.mov"  alt="1" width="360px"   />
    </td>
<td>
<video src="https://user-images.githubusercontent.com/11707729/215392728-cfc6a097-26c1-4ffe-ab0e-f0a5a71a902d.mov"2" width="360px"  />
</td>
   </tr>
</table>

Reviewed By: cipolleschi

Differential Revision: D42849911

Pulled By: jacdebug

fbshipit-source-id: 822cff5264689c42031d496105537032b5cd31ef
2023-01-31 10:58:24 -08:00
Genki Kondo d3cc48d9a6 Add codegen support for DimensionValue for components (#35953)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35953

DimensionValue is a reserved prop type that can be a number or string (such as '50%'). On Java, it will get converted to a YogaValue (converter added to this diff); on C++ it will get converted to a YGValue (converter already exists as it's used in Fabric).

Changelog:
[Internal][Added] - Add codegen support for DimensionValue for components

Reviewed By: cipolleschi

Differential Revision: D42650799

fbshipit-source-id: 1d2bc30bbd93837dedbbb4c74f814963c8140957
2023-01-26 18:52:10 -08:00
Samuel Susla 6f7428e27b Delete feature flag enable_simulate_image_props_memory_access
Summary:
changelog: [internal]

Clean up unused feature flag

Reviewed By: fkgozali

Differential Revision: D42709723

fbshipit-source-id: 289697dfb0c0378ff0369e1474150f7be68c8635
2023-01-25 05:43:38 -08:00
Samuel Susla 8863be41b1 Delete feature flag enable_crash_on_missing_component_descriptor
Summary:
changelog: [internal]

Clean up unused feature flag

Reviewed By: fkgozali

Differential Revision: D42709724

fbshipit-source-id: a124015783983dea28db31a4431183f5c30a30e7
2023-01-25 05:43:38 -08:00
Samuel Susla 51c03a0880 Delete feature flag react_fabric:enabled_skip_invalidated_key_frames_ios
Summary:
changelog: [internal]

clean up unused feature flag

Reviewed By: fkgozali

Differential Revision: D42709640

fbshipit-source-id: f64bb0eac67744dec321160c1cbe945e2dd74068
2023-01-25 05:43:38 -08:00
Samuel Susla 0a30aa3612 Enable layout animations on iOS in OSS
Summary:
changelog: Enable Layout Animations on iOS

[LayoutAnimations](https://reactnative.dev/docs/next/layoutanimation) in New Architecture have been disabled in OSS on iOS because of unresolved crash. This crash only happens rarely. Turning on LayoutAnimations in OSS should be safe and brings New Architecture to parity with old.

Reviewed By: fkgozali

Differential Revision: D42708774

fbshipit-source-id: b0f7febee3aa4f0ddac25556644198ebe79378c1
2023-01-25 05:43:38 -08:00
Ruslan Lesiutin 465e937533 internalize Slider module (#35825)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35825

Changelog:
[iOS][Removed] - removed Slider module
[Android][Removed] - removed Slider module

Reviewed By: cortinico

Differential Revision: D42394124

fbshipit-source-id: 92ba3bc50d16996a597148fa2f8178e6bd6d8eb7
2023-01-16 02:42:18 -08:00
Wojciech Lewicki 97c7c6a4b6 fix: dispatch ContentSizeChange event on Fabric on iOS (#35816)
Summary:
On Fabric, `onContentSizeChange` of `TextInput` component was never fired on `iOS`, since the logic dispatching it was implemented in `RCTBaseTextInputShadowView` on Paper: https://github.com/facebook/react-native/blob/0f8dc067ac079f7b14696cfcafa37e3ec19a0409/Libraries/Text/TextInput/RCTBaseTextInputShadowView.m#L105. This class is not used on Fabric, therefore the event was never dispatched. On Paper, it was dispatched in `dirtyLayout` method,  so I added dispatching of this event based on the change of content size in `layoutSubviews` method, since this method seems the closest one on Fabric. I am not sure if it is the best place for it though.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[IOS] [ADDED] - dispatch `onContentSizeChange` event on Fabric.

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

Test Plan:
Try to use `onContentSizeChange` callback in `TextInput` component:
```tsx
import React from 'react';
import {TextInput, SafeAreaView} from 'react-native';

const App = () => {
  return (
    <SafeAreaView style={{flex: 1, backgroundColor: 'red'}}>
      <TextInput
        multiline={true}
        placeholder="type here"
        onContentSizeChange={e => console.log(e)}
      />
    </SafeAreaView>
  );
};

export default App;

```

Reviewed By: christophpurrer

Differential Revision: D42499974

Pulled By: sammy-SC

fbshipit-source-id: 3e010ff096cf91cb3e7b87ed2753e9d0e7be9650
2023-01-13 09:34:03 -08:00
Ruslan Lesiutin ac66512eb3 Revert D41069547: Multisect successfully blamed D40984397 for test or build failures (#35789)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35789

Changelog: [Internal]

This diff is reverting D41069547 (https://github.com/facebook/react-native/commit/fee9510b2d8ff73be632dbe6f07003f001104836) D41062668 (https://github.com/facebook/react-native/commit/4c40014d43abe88b17db75aca9de9cca349ecbcc) D40984397 (https://github.com/facebook/react-native/commit/05968d16e1c4714a7ebfb08fff60ec7d5c914de1)
D40984397 (https://github.com/facebook/react-native/commit/05968d16e1c4714a7ebfb08fff60ec7d5c914de1) has been identified to be causing the following test or build failures:

We're generating a revert to back out the changes in this diff, please note the backout may land if someone accepts it.

allow-large-files

Differential Revision: D42371475

fbshipit-source-id: daa01c9215811c397f5cef958fd4620f36295b60
2023-01-06 13:06:17 -08:00
Nishan 5a912ccc09 fix: margin auto conversion in fabric (#35635)
Summary:
Auto margin is not working as expected in fabric views. Below snippet results in different outputs in fabric and non-fabric runtime.

```jsx
<View style={{ backgroundColor: "black", width: "100%", height: "100%" }}>
  <View style={{ marginLeft: "auto", width: 100, height: 100, backgroundColor: "pink" }} />
</View>
```
### Current Result | Expected Result

<div style="display: flex;">
<img width="100" alt="Screenshot 2022-12-14 at 11 00 22 AM" src="https://user-images.githubusercontent.com/23293248/207513912-633910e2-cf92-4f50-b839-c5abfa8041fb.png">

<img width="100" alt="Screenshot 2022-12-14 at 10 55 31 AM" src="https://user-images.githubusercontent.com/23293248/207513196-94650c60-ffe5-4475-9a95-2a59f8f0e9d9.png">
</div>

## Issue

This issue doesn't happen on non-fabric as it uses [YGNodeStyleSetMarginAuto](https://github.com/facebook/react-native/blob/9f9111bd7b75fb5f60b74b127b417512e29afb67/ReactCommon/yoga/yoga/Yoga.cpp#L749) to set the auto margins. In fabric, it uses the [convert function](https://github.com/intergalacticspacehighway/react-native/blob/2a15f9190266d90abbe3fc7e5437ea77e99e4290/ReactCommon/react/renderer/components/view/conversions.h#L375). The change in this PR can affect some other styles e.g. padding, borders. We could also create a different setter just for margins.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[GENERAL] [FIXED] - margin auto style conversion in fabric

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

Test Plan:
- Test above snippet in fabric and non fabric runtime.

- I think we should have test cases for RN + layouts. Maybe we can use something like https://github.com/FormidableLabs/react-native-owl

Reviewed By: sammy-SC

Differential Revision: D42080908

Pulled By: NickGerleman

fbshipit-source-id: 6715c292fc40d82c425d79867099d8a6a3663dba
2023-01-06 10:13:00 -08:00
Gabriel Donadel Dall'Agnol 4ae4984094 feat: Add logical border radius implementation (#35572)
Summary:
This PR implements logical border-radius as requested on https://github.com/facebook/react-native/issues/34425. This implementation includes the addition of the following style properties

- `borderEndEndRadius`, equivalent to `borderBottomEndRadius`.
- `borderEndStartRadius`, equivalent to `borderBottomStartRadius`.
- `borderStartEndRadius`, equivalent to `borderTopEndRadius`.
- `borderStartStartRadius`, equivalent to `borderTopStartRadius`.

## Changelog

[GENERAL] [ADDED] - Add logical border-radius implementation

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

Test Plan:
1. Open the RNTester app and navigate to the `RTLExample` page
2. Test the new style properties through the `Logical Border Radii Start/End` section

https://user-images.githubusercontent.com/11707729/206623732-6d542347-93f9-40da-be97-f7dcd5f66ca9.mov

Reviewed By: necolas

Differential Revision: D42002043

Pulled By: NickGerleman

fbshipit-source-id: a0aa9783c280398b437aeb7a00c6eb3f767657a5
2023-01-06 06:00:03 -08:00
Ruslan Shestopalyuk 7252c66292 Optimize size of an ViewProps instance by reducing enum storage sizes
Summary:
[Changelog][Internal]

The diff changes underlying storage types used by different enums that are used in ViewProps data structure, together with some eventual field rearranging to reduce padding overhead.

This **shaves off 128 bytes** from each `ViewProps` instance, which is **a ~10% improvement**.

Given that an average RN app may have thousands of shadow tree nodes, and correspondingly `ViewProps` instances in flight (e.g. Oculus Store has 2-3K of them nominally), the overall memory win is about **300K+** for this change only. Plus slightly better cache locality, which never a bad thing either.

Reviewed By: mdvacca

Differential Revision: D42372127

fbshipit-source-id: d3a832af2b2e89f50a5b8e04d24d0df92869ea4d
2023-01-05 23:35:56 -08:00
Moti Zilberman 5009ad33a6 Make MapBuffer movable
Summary:
Changelog: [Internal]

`MapBuffer` already has a move constructor but did not have a move assignment operator prior to this diff. Changing this requires removing the `const` qualifier from `bytes_`, but this seems OK in practice as it will still be treated as `const` by all the `const` accessors on `MapBuffer`.

Reviewed By: RSNara

Differential Revision: D42369493

fbshipit-source-id: f0fcce533d8e0883dcf85d7262620ea77f377644
2023-01-05 12:38:41 -08:00
fabriziobertoglio1987 dcc5dbe562 adding togglebutton to attributedstring conversions (#35632)
Summary:
fixes runtime error `E/ReactNativeJNI(24576): Unsupported AccessibilityRole value: togglebutton` when using togglebutton accessibilityRole with Text. Related https://github.com/fabriziobertoglio1987/react-native/commit/da899c0cc4372830e5ca053a096b74fff2a19cb8

## Changelog

[GENERAL] [FIXED] - Fixes crash when using togglebutton accessibilityRole with Text

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

Reviewed By: lunaleaps

Differential Revision: D42360628

Pulled By: rshest

fbshipit-source-id: afca8f540d972e1df0c390b3dff8875f07804e97
2023-01-05 12:11:46 -08:00
Ruslan Lesiutin 4c40014d43 refactor(ReactNative/Slider): moved android sources to internal
Summary:
# Changelog:
[Android][Removed] - removed android sources of Slider module

Reviewed By: NickGerleman

Differential Revision: D41062668

fbshipit-source-id: fe628527f757d4fefa8ecf2c0c952aaf8d4acec2
2023-01-05 06:12:47 -08:00
Ruslan Shestopalyuk 55db1b23ff Better event mapping handling in prop setter (#35775)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35775

[Changelog][Internal]

Follow-up to D42344715 (https://github.com/facebook/react-native/commit/f70a2f6e3857f9e9d1f2ab9b6847fe318e67bd78).

I realized that the problem that was fixed there could have been avoided, to begin with, by crafting the corresponding macro more carefully.

This gives both more readable and less fragile code.

Reviewed By: mdvacca

Differential Revision: D42345323

fbshipit-source-id: d4b6d5a95aab360ef0aac3ecb0f157d5325271b6
2023-01-05 02:59:37 -08:00
Ruslan Shestopalyuk f70a2f6e38 Fix mapping of the "onResponderMove" event via props parsing (#35772)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35772

[Changelog][Internal]

Noticed when looking into the events handling code - this looks like a copy/paste error, presumably introduced in D37050215 (https://github.com/facebook/react-native/commit/47280de85e62f33f0b97bc1ed7c83bc6ca0dc7d4).

The correct event name is `onResponderMove`, as evident from all other places in code and the documentation.

Reviewed By: sammy-SC

Differential Revision: D42344715

fbshipit-source-id: fbf1648efaee696edcc7c945ebc0e8423246138b
2023-01-04 14:09:44 -08:00
Ruslan Shestopalyuk 09ad0cc0c6 Implement reporting of events from native side to WebPerformance API (#35768)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35768

Changelog: [Internal]

This implements native side mechanics for reporting user events timing to JS  (PerformanceObserver API).

See the standard for more details: https://www.w3.org/TR/event-timing/

The events are only logged when there are any active subscriptions (via `PerformanceObserver.observe`), also we only log "discrete events" (i.e. no likes of mouse move), so the overhead is non-existing.

There are two main metrics of interest for an event lifecycle:
* Time the event is spent in the queue, i.e. the time between it's created and dispatched
* Time that is spend in the event handler on the JS side (event dispatch), or processing time

Both of these are measured, and the corresponding fields are populated.

Reviewed By: sammy-SC

Differential Revision: D42294947

fbshipit-source-id: 4fd7938c04b942400befa4057d4929fb2763cee1
2023-01-03 11:11:37 -08:00
Tomek Zawadzki 292268ea3f Eliminate double call of shadowNodeFromValue in dispatchCommand (#35695)
Summary:
This PR slightly improves the implementation of `dispatchCommand` method of `UIManagerBinding` to use existing variable `shadowNode` instead of calling `shadowNodeFromValue` again.

## Changelog

[INTERNAL] [CHANGED] - Eliminated double call of `shadowNodeFromValue` in `dispatchCommand`

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

Test Plan: Launch RNTester with Fabric enabled and check if `scrollTo` or some other command works properly.

Reviewed By: christophpurrer

Differential Revision: D42233216

Pulled By: robhogan

fbshipit-source-id: db152206060ff599962f47c43fda8ea797f2a8cb
2023-01-03 03:07:13 -08:00
Ruslan Shestopalyuk 673d7e81a2 Avoid using shared_ptr when forwarding arguments in AsyncCallback (#35731)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35731

[Changelog][Internal]

The initial intent was to try and use `unique_ptr` instead of `shared_ptr`, however turns out it complicates code more than it's worth it, so I ended up just factoring the repeated complex parts of the corresponding code to make it easier to reason about.

Reviewed By: christophpurrer

Differential Revision: D42265274

fbshipit-source-id: 105f57b449934c2e3227e592a76036ca7f61bc35
2022-12-28 10:29:23 -08:00
Samuel Susla 874881e73e Bring setNativeProps to Fabric
Summary:
changelog: [internal]

This is experimental implementation of `setNativeProps` in Fabric.

This diff brings `setNativeProps` to Fabric to make migration easier. I tried to stay as close as possible to Paper's behaviour, with all of its flaws (ready CAUTION section on https://reactnative.dev/docs/direct-manipulation)

State can't be stored in views because on iOS, eventually on Android, views are not the source of truth, shadow tree is. Fabric's implementation keeps state from setNativeProps in shadow node family in very inefficient data structure folly::dynamic. It is always reconciled with new prop updates. The performance cost is only paid in case node has used `setNativeProps` before.

Reviewed By: mdvacca

Differential Revision: D41875413

fbshipit-source-id: 453a5f7612a6f86a4cece269b13bd2ffd0c0e2d1
2022-12-24 06:40:42 -08:00