Commit Graph

12270 Commits

Author SHA1 Message Date
aleqsio 61f584c3af Implement privacy manifest aggregation (#44214)
Summary:
As of now, Apple does not respect privacy manifests added as cocoapods resource bundles. This forces react-native developers to manually copy `.xcprivacy` files content for each native dependency that accesses restricted reason APIs to the root file.

This PR adds an aggregation step that crawls through pod dependencies to collect all reasons into the root privacy info file.

## Changelog:

[IOS][ADDED] – Add privacy manifest aggregation.

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

Test Plan:
When run on RNTester, it appends aggregated entries (while keeping existing ones) to existing .xcprivacy file without modifing .pbxproj:
![image](https://github.com/facebook/react-native/assets/5597580/1d07a07d-bbec-4266-a599-a8d629078971)

When run on RNTester with the xcprivacy file removed from xcode beforehand, it creates a new .xcprivacy file, and adds it to Compile Bundle Resources in the same way as in the new template:
![image](https://github.com/facebook/react-native/assets/5597580/f80a3b4e-e41a-4906-8e2f-06cca0bc225a)

When run on RNTester with an empty .xcprivacy file, it appends aggregated entries from pods AND reasons for react-native core.

When run with `privacy_file_aggregation_enabled: false` in `use_react_native`, it falls back to existing behavior:
![image](https://github.com/facebook/react-native/assets/5597580/4519bba1-c80e-4cd0-b19c-bbbebfa8493b)

Reviewed By: cipolleschi

Differential Revision: D56481045

Pulled By: philIip

fbshipit-source-id: 1841bad821511c734d0cc0fcff5065ed92af76d8
2024-04-30 18:19:28 -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
Rubén Norte cfbee0b7ec Add test for LazyShadowTreeRevisionConsistencyManager and fix bugs
Summary:
Changelog: [internal]

`LazyShadowTreeRevisionConsistencyManager` wasn't correctly updating the locked revision, because `emplace` is a no-op if there's already a value for the key in the `unordered_map`.

This fixes the issue and adds tests that actually showed it.

Reviewed By: sammy-SC

Differential Revision: D56761941

fbshipit-source-id: 340e9195b14460a591c48186bd365688c74ade04
2024-04-30 10:29:22 -07:00
Riccardo Cipolleschi 9bdd777fd7 Avoid calling abstract methods in RCTComposedViewRegistry
Summary:
`RCTComposedViewRegistry` extends `NSMutableDictionary` which is a clustered class in iOS.
NSMutableDictionary is techncially an abstract class, but when instantiated by `[NSMutableDictionary new];` the system will return one of concrete classes that inherit from `NSMutableDictionary`, opaquely from the perspective of the caller.

By calling `super`, we are actually calling the not implemented method for the abstract class. If this happen, this can crash the app.

Given that the `RCTComposedViewRegistry` is extending the dictionary only for its interface but is using other mechanisms as storage, is it fair to return `NULL`if the storages don't have the requested view.

## Changelog
[iOS][Fixed] -  Avoid calling abstract methods in RCTComposedViewRegistry

Reviewed By: cortinico

Differential Revision: D56755427

fbshipit-source-id: f5c56dc59ccc6b30c00199b4196c42eb9b021e2b
2024-04-30 08:42:42 -07:00
Nicola Corti 44e78ff74a Fix accidentally broken build_android job
Summary:
I accidentally broke build_android.
Here the two fixes:
1. Make sure the constructor of PackageList2 are actually called `PackageList2`
2. Make sure the package of `OSSLibraryExamplePackage` is `com.facebook.react.osslibraryexample`

Changelog:
[Internal] [Changed] - Fix accidentally broken build_android job

Reviewed By: dmytrorykun

Differential Revision: D56756601

fbshipit-source-id: 862597ca829d702d880624d29276193f8548715d
2024-04-30 08:02:20 -07:00
Moti Zilberman 845a879442 Lift console method bodies out of installConsoleHandler
Summary:
Changelog: [Internal]

The bodies of all `console` methods are currently written as lambdas within `installConsoleHandler` but actually capture nothing meaningful from that scope. This diff rewrites them as free functions instead.

To enable the "forwarding console methods" to be written as free functions, we also replace the runtime loop over `kForwardingConsoleMethods` with a compile-time equivalent using macros. (This technique is inspired by the Hermes source code, which uses it heavily for compile-time code generation.)

Reviewed By: huntie

Differential Revision: D56679956

fbshipit-source-id: babf368ecacb9dc426b2356a4a2091881ca1023e
2024-04-30 05:38:32 -07:00
Moti Zilberman 38f8b8e099 Remove unnecessary std::function indirection in console
Summary:
Changelog: [Internal]

Switches to constrained `auto` instead of `std::function` to represent intermediate function types in `RuntimeTargetConsole::installConsoleHandler`. This removes some indirection and potential runtime overhead.

Reviewed By: huntie

Differential Revision: D56675188

fbshipit-source-id: 76cbf8b8be9ca1a9466efbcd187bddd60c921019
2024-04-30 05:38:32 -07:00
Nicola Corti c57ca2c3b4 RNGP - Move the generateAutolinkingNewArchitectureFiles task to core autolinking
Summary:
This diff is part of RFC0759
https://github.com/react-native-community/discussions-and-proposals/pull/759

Here I'm moving the New Architecture C++ Autolinking from the CLI to core.
It follows the same logic as this:
https://github.com/react-native-community/cli/blob/73f880c3d87cdde81204364289f2f488a473c52b/packages/cli-platform-android/native_modules.gradle#L544-L550

Changelog:
[Internal] [Changed] - RNGP - Move the generateAutolinkingNewArchitectureFiles task to core autolinking

Reviewed By: cipolleschi, blakef

Differential Revision: D55475594

fbshipit-source-id: d3768d932032e8e98f992d5f1bc54c439520873d
2024-04-30 04:33:56 -07:00
Nicola Corti 0d37d0a4b7 RNGP - Move generateAutolinkingPackageList to core autolinking
Summary:
This diff is part of RFC0759
https://github.com/react-native-community/discussions-and-proposals/pull/759

Here I'm moving over the task to generate the Package List for Autolinking inside RNGP.
The logic is the same as this one:
https://github.com/react-native-community/cli/blob/73f880c3d87cdde81204364289f2f488a473c52b/packages/cli-platform-android/native_modules.gradle#L217

The class is generated as PackageList2 to avoid a duplicate class build failure with the current Autolinking from CLI.

Changelog:
[Internal] [Changed] - RNGP - Move generateAutolinkingPackageList to core autolinking

Reviewed By: cipolleschi

Differential Revision: D56637394

fbshipit-source-id: 929b42af3a0e1951cb7a0f4ace47bbbb84000780
2024-04-30 04:33:56 -07:00
Rubén Norte cc5bab83ab Use private fields in performance APIs
Summary:
Changelog: [internal]

This migrates all the classes related to performance in `react-native/src/private` to use private fields instead of regular fields prefixed with `_`.

Reviewed By: yungsters

Differential Revision: D55931659

fbshipit-source-id: e8b2018048dbb6c8d6e8a4d143357bf2ac39dd1e
2024-04-30 04:32:10 -07:00
Rubén Norte 59688a1aee Migrate a bunch of classes in react-native/src/private to use private fields
Summary:
Changelog: [internal]

Quick refactor to use private fields instead of fields with a naming convention, in classes in `react-native/src/private`.

Reviewed By: yungsters

Differential Revision: D56700382

fbshipit-source-id: ee0a7b30a9da20c31b92878be3316227b2d0a0c4
2024-04-30 04:31:00 -07:00
Rubén Norte c3a1ae3c3e Add comment to indicate how to update generated files for feature flags in ReactNativeFeatureFlags.config.js
Summary:
Changelog: [internal]

We have a comment explaining how to update all generated files everywhere but here.

Reviewed By: NickGerleman

Differential Revision: D56717344

fbshipit-source-id: cc538e37dd6ab09f67d67bb13ce4e560870d44d0
2024-04-30 03:25:59 -07:00
Nicola Corti 8f1b27001f RNGP - Autolinking - Add model classes for parsing the config output
Summary:
This diff is part of RFC0759
https://github.com/react-native-community/discussions-and-proposals/pull/759

Here I'm creating data classes that will allow us to parse the `config` JSON output.
Code is pretty straightforward and follows the structure as the `config` command output.

Changelog:
[Internal] [Changed] - RNGP - Autolinking - Add model classes for parsing the `config` output

Reviewed By: cipolleschi, blakef

Differential Revision: D55475595

fbshipit-source-id: 3457c008ff0c5bce2b47fd637c7b10a5e7427c01
2024-04-30 02:49:48 -07:00
Nicola Corti 1df1570810 RNGP - Setup the RunAutolinkingConfigTask to run the config command
Summary:
This diff is part of RFC0759
https://github.com/react-native-community/discussions-and-proposals/pull/759

Here I'm creating the `runAutolinkingConfig` task.

This task is responsible of either:
- Invoking the `npx react-native-community/cli config` command (or the one specified by the user)
- Copying the config output file specified by the user (if any).

The task re-executes only if any of the lockfile are actually changed otherwise it just returns as "UP-TO-DATE"

This allows us to

Changelog:
[Internal] [Changed] - RNGP - Setup the RunAutolinkingConfigTask to run the config command

Reviewed By: cipolleschi, blakef

Differential Revision: D55475596

fbshipit-source-id: 3c687f965c59eb82fc447546ebd936ba401f34f2
2024-04-30 02:49:48 -07:00
Danny Su 6262158c11 Pass StackTrace directly to Hermes ConsoleMessage
Summary:
Hermes' ConsoleMessage constructor now accepts StackTrace, so the construction can be done in one go.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D56738060

fbshipit-source-id: 709b47d8f9cf69994e4c5eaa4f9310e70a4d9ed0
2024-04-30 00:19:48 -07:00
Ruslan Shestopalyuk 7b3c622219 Hoist TextInput.autoCapitalize to BaseTextInputProps on C++ side
Summary:
## Changelog:
[Internal]-

Even though `TextInput.autoCapitalize` is supposed to be cross-platform, on the C++ side of the props data structures it was only exposed as an Android-specific one.

This would have it still work on the iOS side (as the corresponding prop is passed to Objective C around the C++ structs anyway), however it may also cause subtle scenarios, whereas the prop changes dynamically on the iOS side, but this doesn't get reflected on the native side.

This change fixes this problem by simply hoisting the prop into the `BaseTextInputProps`, which makes it available across all platforms, as it should be.

Differential Revision: D56726940

fbshipit-source-id: 9ba18f1f92095874e07207650b46655c331f3e91
2024-04-29 23:45:49 -07:00
Danny Su 35c7956baf Remove RuntimeAdapter.h from HermesRuntimeAgentDelegate
Summary:
RuntimeAdapter.h is only needed when using CDPHandler, which the new code path doesn't need.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D56738299

fbshipit-source-id: 8cb512a3dc8dc303851871021e04aab94aa25d1e
2024-04-29 23:41:50 -07:00
Pieter De Baets dd51b38101 Fix missing close for canceled bundle downloads
Summary:
`Response` is `Closeable`, so we must close it even if the download is no longer relevant. Found while running with StrictMode enabled and reloading quickly multiple times.

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D56629079

fbshipit-source-id: 041bf295313cbf78b7f2bb6580c50fdc2a324728
2024-04-29 21:10:28 -07:00
Edmond Chui b7de916664 move launch ID gen out of dev-middleware
Summary: Changelog: [General][Removed] `launchId` query param for `/debugger-frontend` is no longer generated automatically for each `/open-debugger` call. Caller of `/open-debugger` is now responsible for generating the `launchId`, which will be passed along to `/debugger-frontend`.

Reviewed By: robhogan

Differential Revision: D55164645

fbshipit-source-id: b83303eda77b6fb86ebf50f699d9f308676533c6
2024-04-29 11:55:28 -07:00
Edmond Chui 820d1e1ff4 add fields to launch_debugger_frontend
Summary: Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D56610268

fbshipit-source-id: 37abee41dd068f3cafa19466b914545f6460a3f0
2024-04-29 11:55:28 -07:00
Nick Vlug eb01a8f0c5 Remove duplicated use_hermes in RCTAppDelecate podspec (#44299)
Summary:
remove duplicated use hermes variable in RCTAppDelecate podsec file.

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

Test Plan:
Default setup flow (ios)

## Changelog:
[Internal] [Changed] - Remove duplicated use hermes variable in RCTAppDelecate podsec file.

Reviewed By: cipolleschi

Differential Revision: D56693121

Pulled By: arushikesarwani94

fbshipit-source-id: 2bbe4090d94cadd128be9c5d233a63499f735e68
2024-04-29 10:40:06 -07:00
Alex Hunt 548fcd8b3b Update "Open Debugger" to print extended Flipper guidance
Summary:
Supports the removal of Flipper from the template in 0.74, paried with additional blog post messaging: https://reactnative.dev/blog/2024/04/22/release-0.74#removal-of-flipper-react-native-plugin.

Changelog:
[General][Changed] - Update "Open Debugger" action to print extended Flipper guidance

Reviewed By: cipolleschi

Differential Revision: D56705236

fbshipit-source-id: d7e869625262ebb02bc2454c924f832cccfbcd31
2024-04-29 10:18:45 -07:00
Marc Rousavy 8ce4bf1893 fix: Fix missing space (#44311)
Summary:
Just a minor fix to fix a missing space in the debug message.

Fixes a missing space in the message

```
Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'MmkvPlatformContext' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":["PlatformConstants","LogBox","Timing","AppState","SourceCode","BlobModule","WebSocketModule","SettingsManager","DevSettings","RedBox","Networking","Appearance","DevLoadingView","UIManager","DeviceInfo","ImageLoader","LinkingManager"],"TurboModules":[],"NotFound":["NativePerformanceCxx","NativePerformanceObserverCxx","BugReporting","HeadlessJsTaskSupport","SoundManager","IntentAndroid","MmkvPlatformContext","MmkvCxx"]}
```

## 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] [FIXED] - Fixed missing space in TurboModule.getEnforcing error message

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

Reviewed By: christophpurrer

Differential Revision: D56702036

Pulled By: rshest

fbshipit-source-id: e339a6ee8c265b2c6d27184e8e9941f3f02e3c85
2024-04-29 09:21:23 -07:00
Ruslan Shestopalyuk ab00a453a8 Fix minor formatting issue in AppRegistry logging in non-dev builds
Summary:
## Changelog:
[Internal] -

I was looking at the logs, troubleshooting a non-dev build issue, and noticed a line:
```
I0429 15:56:42.107558 1874554880: Running "MyApplication
```
In `__DEV__` mode this usually continues with `" with ...`, but in release mode the closing quote was missing, which made me think there may be something going on garbling the log messages.

Which ultimately was a red herring, and it's just a bad formatting in the message in release mode, which this change fixes.

Reviewed By: zeyap

Differential Revision: D56704170

fbshipit-source-id: a28604fffec6be74733c8759f59ee52a67a81746
2024-04-29 08:55:22 -07:00
Moti Zilberman 8689f563ed Make inspector executor safe to destroy on any thread
Summary:
Changelog: [Internal]

Fixes a crash that may happen on Android when the `inspectorEnableModernCDPRegistry` feature flag is true, and clarifies the documentation of `HostTarget::create()` to avoid similar issues in future integrations.

## Context

The executor provided to `HostTarget::create()` ("the inspector executor") is used throughout the CDP backend to schedule work on the inspector thread. (See also D53356953.) To facilitate this, the executor is a copyable `std::function`.

On Android, the executor is backed by a Java object, to which we hold a reference from C++ using JNI. This reference is expressed as a `facebook::jni::global_ref` which gets copied as part of the executor. (`global_ref` is a RAII wrapper around the `NewGlobalRef` / `DeleteGlobalRef` JNI functions.)

## The bug

All the *calls* to the inspector executor from C++ happen on threads that are already properly [attached to the JVM](https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/invocation.html#attaching_to_the_vm) ( = the UI thread / the JS thread) and are therefore allowed to make JNI calls. However, there are cases where a copy of the inspector executor may have its *destructor* run on an unexpected thread, namely the (Hermes) JS GC thread. (This happens when the executor itself is captured in a lambda that's stored in a `jsi::HostObject` or `jsi::HostFunction`, which is in turn [destroyed on the JS GC thread](https://github.com/facebook/react-native/blob/5a0ae6e2d9d7f2357f9ea6c5dc1d573233075326/packages/react-native/ReactCommon/jsi/jsi/jsi.h#L118-L126).) In such cases, the `DeleteGlobalRef` call mentioned above will crash, because the JS GC thread is not attached to the JVM.

## The fix

First, we document that copies of the inspector executor provided to `HostTarget::create` may indeed be destroyed on arbitrary threads. This is an unavoidable consequence of the existing design. Second, we adapt the Android integration to this requirement.

`fbjni` provides the [`jni::ThreadScope`](https://github.com/facebookincubator/fbjni/blob/968e3815f92aeb0670f5d88ae975fbbd47a4b482/cxx/fbjni/detail/Environment.h#L93-L123) RAII helper to manage attaching C++ threads to the JVM. If we had any explicit control over the setup and teardown of the JS GC thread, we could create a single `jni::ThreadScope` to globally ensure the safety of JS-finalizer-to-JNI calls in React Native. However, neither JSI nor the Hermes API provides such control.

Instead, we essentially resort to creating a temporary `ThreadScope` around each `DeleteGlobalRef` call where we don't control the calling thread. We do this using a new kind of JNI reference wrapper class called `SafeReleaseJniRef`. Retaining a `SafeReleaseJniRef` instead of a plain `global_ref` is all that's needed to make a particular reference safe to destroy on any thread.

Reviewed By: huntie

Differential Revision: D56620131

fbshipit-source-id: 0b6f32a7bd6477d0384af19c42e21d9242ce623d
2024-04-29 05:24:53 -07:00
Blake Friedman c754755cd8 CLI supports ordering of tasks
Summary:
This gives Frameworks more control in selecting specific tasks and integrating the return types data in their UI.  For example piping `stdout` to the user or using packages like [Listr2](https://www.npmjs.com/package/listr2) to run tasks in parallel and show progress.

The ordering is suggestive (but also enforced by some assertions).  Frameworks are free to do what they want.

The order was implicit in the previous data structure with lists of Tasks, but made it difficult to tap into each async task.

I've also had to rework how we transpile the code if directly executed from the monorepo.  This keeps our:
- flow types valid,
- allows the core-cli-utils package to be built (to generate TypeScript types and a valid npm module), and
- allows direct transpiled execution as a yarn script.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D56242487

fbshipit-source-id: a1a18f14a4aef53a98770462c8ebdef4111f0ab4
2024-04-29 05:04:26 -07:00
Moti Zilberman fb0c856cf2 Fix use-after-move in console implementation
Summary:
Changelog: [Internal]

In the new CDP backend, calling any `console` method a second time involves a call to a moved-from `std::function`. This shouldn't work, and indeed results in an exception on some platforms, but isn't strictly an error according to the C++ standard: moving from a `std::function` leaves it in an [unspecified state](https://en.cppreference.com/w/cpp/utility/functional/function/function#:~:text=the%20call%20too.-,other,is%20in%20a%20valid%20but%20unspecified%20state%20right%20after%20the%20call.,-5), not necessarily an empty state, so (in particular) it's perfectly legal for the implementation to perform a copy instead of a move and leave the original variable intact.

(See [Compiler Explorer](https://godbolt.org/z/qoo5Mnd68) for proof that libc++ and libstdc++ differ on this - the former performs a copy, while the latter actually performs a move, resulting in a `std::bad_function_call` exception later.)

In the code in question, we're right to want to avoid a copy of the `body` function into the argument of `delegateExecutorSync` - only one copy of this function needs to exist at a time. But the correct way to avoid this copy is to capture `body` by reference, as we can do that repeatedly with no ill effects. (`delegateExecutorSync` is, as its name suggests, synchronous, so there are no lifetime issues.) Doing this also allows us to remove the use of `mutable` so the capturing is by *const* reference.

Reviewed By: sammy-SC

Differential Revision: D56673529

fbshipit-source-id: b235977b2fbc889462c4c78adfe41ae6f509e349
2024-04-29 04:04:56 -07:00
Samuel Susla bb120ff663 remove force_static from textinput module
Summary:
changelog: [internal]

force_static doesn't need to be in here, let's remove it.

I change one module per diff. It makes it easier to land it and pinpoint where build failures are coming from.

Reviewed By: christophpurrer

Differential Revision: D56678530

fbshipit-source-id: c602e065d77fdd649c66ce2d26eee83428ef5ba8
2024-04-29 03:34:14 -07:00
Samuel Susla bb2c13af53 remove force_static from componentregistry module
Summary:
Resolved Pull request: https://github.com/facebook/react-native/pull/44296

changelog: [internal]

force_static doesn't need to be in here, let's remove it.

I change one module per diff. It makes it easier to land it and pinpoint where build failures are coming from.

Reviewed By: javache

Differential Revision: D56632286

fbshipit-source-id: e942603d3c69d9eebf4d3b64e2f73ee6a5df6de4
2024-04-28 00:18:58 -07:00
Samuel Susla e2ad6696d8 make mapbuffer Android only module (#44295)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44295

changelog: [internal]

mapbuffer is only used on Android. Let's remove the option to have it compile on iOS.

Reviewed By: NickGerleman

Differential Revision: D56635289

fbshipit-source-id: 1a57c271d21b8aef81179d96b1a6832e7615dd27
2024-04-27 06:00:54 -07:00
Samuel Susla 30ba470a6f remove force_static from safeareaview module (#44283)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44283

changelog: [internal]

force_static doesn't need to be in here, let's remove it.

I change one module per diff. It makes it easier to land it and pinpoint where build failures are coming from.

Reviewed By: christophpurrer

Differential Revision: D56630625

fbshipit-source-id: 069587893dbb8866d1a08de256b4612d60bcc3b8
2024-04-27 04:37:21 -07:00
Samuel Susla 3239089f67 use forward declaration in ComponentDescriptor.h (#44284)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44284

changelog: [internal]

Employ forward declaration in ComponentDescriptor.h to avoid importing header unnecessarly.

Reviewed By: cipolleschi

Differential Revision: D56631399

fbshipit-source-id: 13878cff0683081db21656e16d70cd45d62bb71c
2024-04-27 03:35:25 -07:00
Samuel Susla d116837da2 fix a crash in <Modal /> component
Summary:
changelog: [Android][Fixed] - fix a crash in Modal component

Instance variable `propertyRequiresNewDialog` in `ReactModalHostView` controls if new dialog will be created on next `showOrUpdate` or not. It must be kept in sync with `dialog` ivar.

if `dismiss` is ever called from anywhere but `showOrUpdate`, the class gets into a state where the next `showOrUpdate` call will throw an error because dialog is set to null but `propertyRequiresNewDialog` stays false.

`dismiss` is called from three places: `showOrUpdate` (this is ok), `onDropInstance()` and `onDetachedFromWindow`.

The fix in this diff is to make sure propertyRequiresNewDialog is set to true when dialog is dismissed.

Reviewed By: alanleedev

Differential Revision: D56627522

fbshipit-source-id: e7a16cd022401a7a4a0fbf8fc71a2312d05fcb8e
2024-04-27 02:35:50 -07:00
Jorge Cabiedes Acosta 9c4ee6df08 Add support for percentage on borderRadius ViewStyle props (#44140)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44140

Why?
Previously we didn't support using percentages like:
```
style={{
  width=100,
  height=100,
  borderRadius='100%',
}}
```

These percentages refer to the corresponding dimension of the border box.

What?
Change the unit type for `BorderRadii` values to `ValueUnit`. This type allows us to have an object containing a `float`, and a `UnitType` properties. With this we conditionally calculate the corresponding point (dp) value for a given percentage (considering size). Ex:

```
result = {raw_percentage_value} / 100 * (max(height, width))
```

We know the maximum border radius for our current implementation is half the dp of the shorter side of our view, hence why we consider half our maximum view side as equivalent to 100%.

Note: We still don't support vertical/horizontal border radii

## Changelog:

[iOS][Added] - Added support for using percentages when defining border radius related properties.

Reviewed By: NickGerleman

Differential Revision: D56198302

fbshipit-source-id: 6cd510b1c7164dcb82ca5ad8a9861c5ce5c8b15b
2024-04-26 13:34:37 -07:00
Jorge Cabiedes Acosta 9204e44ef5 Fix bug with borderRadii caused by iOS 10 specific code
Summary:
Non-uniform edge insets caused issues on iOS 10. The code nowadays interferes with the rendering for large borderRadii so this diff removes it.

Since we didn't support this behavior before there are some bugs/missing features that happen:

T186810893 Incorrect border rendering with large radii
T186812303 View discoloring with overlapping border radii
T186812736 Add support for vertical and horizontal border radii

## Changelog:

[iOS][Fixed] - Removed Legacy iOS 10 code messing with border radius

Reviewed By: NickGerleman

Differential Revision: D56333637

fbshipit-source-id: 92b1bb1459d1e95476b3d768db725dfbbc1e55ae
2024-04-26 13:34:37 -07:00
Blake Friedman d18229bc92 fix Flow failure breaking yarn run build
Summary:
`flow-api-translator` can't handle `module.exports`.  Shift this to ESM style exports like the other built packages.

Changelog: [Internal] - Fixing an internal build script broken by D56243647

Reviewed By: cipolleschi

Differential Revision: D56638506

fbshipit-source-id: f5a4c7bea06b7f95300388e3d37cf0d377bc3b17
2024-04-26 12:58:04 -07:00
Nicola Corti 2455eab9df RNGP - Add autolinking fields to ReactExtensions (#44220)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44220

This diff is part of RFC0759
https://github.com/react-native-community/discussions-and-proposals/pull/759

Here we're looking into splitting the autolinking into a component that will live inside core (specifically inside the React Native Gradle Plugin - RNGP) and another component that will live inside the Community CLI.

Here I start by adding 2 fields to RNGP extension, that frameworks and templates can use to provide their autolinking config.

Changelog:
[Internal] [Changed] - RNGP - Add autolinking fields to ReactExtensions

Reviewed By: cipolleschi

Differential Revision: D55475597

fbshipit-source-id: 316d1919a113a94c57426710f487f334c6128345
2024-04-26 10:50:47 -07:00
Marlene Cota b53c4395ce Fix comparison of narrow type with wide type in loop condition in RawPropsKeyMap.cpp (#44262)
Summary:
We ran CodeQL in react-native-windows and it found a comparison of narrow type with wide type in loop condition in ReactCommon/react/renderer/core/RawPropsKeyMap.cpp

microsoft/react-native-windows#12701

## Changelog:
[INTERNAL] [SECURITY] - Fix comparison of narrow type with wide type in loop condition in RawPropsKeyMap.cpp

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

Test Plan: Tested on windows.

Reviewed By: cipolleschi

Differential Revision: D56628137

Pulled By: javache

fbshipit-source-id: 9ff3bd3cbcfd084efc1e01180ff01529d1be02eb
2024-04-26 08:47:24 -07:00
Tim Yung 452373b5bf RN: Further Optimize createAnimatedComponent
Summary:
In addition to memoizing `mergedStyle` in `createAnimatedComponent`, this avoids unnecessary object allocations by:

* Not allocating `passthroughProps`, created via a rest spread operator. It is unnecessary because we always override `style` in the JSX.
* Not allocating a new object if either `style` or `passthroughStyle` are null or undefined. Also, create an array of the two style objects instead of spreading them, which is needless.

Changelog:
[General][Changed] - Improved  performance of `Animated` components

Reviewed By: sammy-SC

Differential Revision: D56621191

fbshipit-source-id: ac863661c60d87c681284ce5ef5d6774b9c50653
2024-04-26 08:30:35 -07:00
Tim Yung 34331af9ce RN: Optimize StyleSheet.compose
Summary:
Changes two important aspects of `StyleSheet.compose`:

- Extract it from `StyleSheet` so that it can be imported from other internal modules without incurring circular dependencies. (Surprisingly, `StyleSheet` has a lot of dependencies.)
- Avoid a redundant `style1 != null` check.

Changelog:
[General][Changed] - Optimized performance of `StyleSheet.compose`

Reviewed By: sammy-SC

Differential Revision: D56621407

fbshipit-source-id: f899b50d9f13f1514485371c8513a85be78eae24
2024-04-26 08:30:35 -07:00
Blake Friedman 71c293d716 Add a custom CLI to build iOS apps (#44239)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44239

A simple CLI to build our iOS `helloworld` application.  This isn't intended for an audience other that the release team.

Some Framwork authors might be interested in it as an example of how to use our react-native/core-cli-utils to build a React Native application.

Changelog: [Internal]

I'm not going to export because it's not that interesting to folks outside / in need of scrutiny.

Reviewed By: cipolleschi

Differential Revision: D56243647

fbshipit-source-id: a5f1b6d1046bda165aa7c6848938e05f0cca2dc8
2024-04-26 08:15:04 -07:00
Jakub Piasecki 1f08799560 Fix textAlign with inline views on the new architecture on Android (#44146)
Summary:
On the new architecture on Android on the new arch, `textAlign` style was ignored (`Layout.Alignment.ALIGN_NORMAL` was always used) during the measurement of text. During this phase, the positions of attachments are also calculated, which results in inline views being always positioned as if alignment to the left was set. This PR updates the measurement logic to also take `textAlign` into account during measurement.

Fixes https://github.com/facebook/react-native/issues/41008

## Changelog:

[ANDROID] [FIXED] - Fixed `textAlign` not being taken into account when positioning views inlined in text

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

Test Plan:
<details>
<summary>I've been testing on the following code</summary>

```jsx
import { SafeAreaView, Text, View } from "react-native";

function InlineView(props) {
  return (<View style={{margin: 10}} >
    <Text style={{ textAlign: props.textAlign, backgroundColor: 'cyan' }}>
        Parent Text
        <Text style={{ fontWeight: 'bold' }}>Child Text</Text>
        <View style={{width: 50, height: 50, backgroundColor: 'red'}} />
        <Text style={{ fontWeight: 'bold' }}>Child Text</Text>
        {props.long && <Text style={{ fontWeight: 'bold' }}>aaaa a aaaa aaaaaa aaa a a a aaaaa sdsds dsdSAD asd ASDasd ASDas</Text>}
      </Text>
  </View>)
}

export default function Test() {
  return (
    <SafeAreaView style={{ flex: 1 }}>
      <Text style={{textAlign: 'center', fontSize: 20}}>BoringLayout</Text>
      <InlineView textAlign="left" />
      <InlineView textAlign="center" />
      <InlineView textAlign="right" />
      <InlineView textAlign="justify" />

      <Text style={{textAlign: 'center', fontSize: 20}}>StaticLayout</Text>
      <InlineView textAlign="left" long />
      <InlineView textAlign="center" long />
      <InlineView textAlign="right" long />
      <InlineView textAlign="justify" long/>
    </SafeAreaView>
  );
}
```

</details>

| Old architecture | New architecture |
|------------------|------------------|
| <img width="447" alt="Screenshot 2024-04-18 at 17 08 59" src="https://github.com/facebook/react-native/assets/21055725/b21848ff-3939-4dde-9f78-03ce50c9429a">            | <img width="447" alt="Screenshot 2024-04-18 at 17 04 46" src="https://github.com/facebook/react-native/assets/21055725/fb57a3c4-09e8-4db7-abc3-79747314529b">          |

Reviewed By: NickGerleman, cipolleschi

Differential Revision: D56361169

Pulled By: cortinico

fbshipit-source-id: c3002f65541774e376e315c3076a6157aa330f8d
2024-04-26 06:54:17 -07:00
David Rickard be06fd4e22 Fix memoization for Animated components when no style is passed in
Summary:
Any component wrapped via `createAnimatedComponent()` will always re-render, because it creates a new `style` object. It's impossible to memoize.

Adding `useMemo()` here ensures that the `style` object passed to the underlying object is stable: if no `style` is passed to the wrapped component, then memoization can work.

Allowing memoization to function when the `style` object is passed in will require a deeper fix. See https://fb.workplace.com/groups/rn.support/permalink/26084643474490921/

Before:
{F1496803038}

After:
{F1496805410}

## Changelog:

[General] [Fixed] - Fixed memoization for components wrapped with createAnimatedComponent

Differential Revision: D56618868

fbshipit-source-id: a0af8b1a02c34b5cf6e6d7e9f0381fb323b232cc
2024-04-26 00:38:43 -07:00
Nikolai Tillmann 5a0ae6e2d9 @DoNotStrip com.facebook.react.bridge.PromiseImpl and its constructor
Summary:
While the class and constructor are referenced from native code, the constructor is only accidentally retained on the Java side without proper keep rules. Adding explicit DoNotStrip in the code here.

Changelog: [Internal]

Reviewed By: beicy

Differential Revision: D56529943

fbshipit-source-id: 5459b7d32ada5eeb1fabff1dfc796c2f81d3bb96
2024-04-25 18:53:19 -07:00
Ramanpreet Nara b9e52f0807 Make DefaultReactHost configurable w/ cxxreactpackages
Summary:
One way we register cxx turbo modules with React Native is via cxxreactpackages.

This diff allows the application to pass in cxxreactpackages into the default react host, which allows the application to, in turn, register cxx modules with react native!

Changelog: [Android][Added] - Allow bridgeless apps to register cxx modules via cxxreactpackages

Reviewed By: cortinico

Differential Revision: D56547493

fbshipit-source-id: 4e8f02f0546c4b647a915fc65ea9687aa1592190
2024-04-25 16:28:59 -07:00
Nick Gerleman 7b44c8d1d0 Automatically disable flattening of scroll content view children when needed
Summary:
There are a couple scenarios where flattening the child of a ScrollView can cause problems.

1. `maintainVisibleContentPosition` on both Android and iOS rely on reading live positions in the view tree
2. `snapToAlignment` on Android uses live view tree, for items to snap to. iOS seems to have very different behavior, and aligns assuming that children are scroll view height, or that a snap interval has been set.

This change adds a prop `collapsableChildren` which can be used to disable children of scroll content view from being collapsed.

Differentiator is... complicated... but we can mostly just adapt the code dealing with existing traits at the surface level.

Changelog:
[General][Fixed] - Automatically disable flattening of scroll content view children when needed
[General][Added] - Add `collapsableChildren` prop

Reviewed By: javache

Differential Revision: D56226241

fbshipit-source-id: ed81f7fff5a15eac424708f763afc9b844aefa9c
2024-04-25 14:52:22 -07:00
Samuel Susla 510d2906b2 maintain correct content offset when scroll view is suspended (#44256)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44256

## Changelog:

[iOS] [Fixed] - Preserve content offset in ScrollView when the component is suspended

# The problem
On iOS, components are recycled. For ScrollView, its content offset has to be reset back to original position. When we call `[UIScrollView setContentOffset:]`, it triggers all of its delegate methods and triggers `scrollViewDidScroll` where we set native state.

So when user scrolls to position 100 and scroll view suspends. it is removed from view hierarchy and recycled. Once the suspense boundary is resolved, scroll view will be inserted back into view hierarchy. But when it was recycled, we set back its original content offset (the default is 0, 0) but this was accidentally propagated through to shadow tree.

# Solution

To avoid this, we simply need to invalidate `_state` before calling `[UIScrollView setContentOffset:]`.

Reviewed By: cipolleschi

Differential Revision: D56573370

fbshipit-source-id: c03d7d2d403af2e1649b4cf189072baeb4c286c8
2024-04-25 09:20:42 -07:00
Riccardo Cipolleschi 794aaa52d3 Fix enable hermes debugger in Bridgeless mode
Summary:
Set the proper build flags for debugging in Bridgeless mode.

This fixes [#44240](https://github.com/facebook/react-native/issues/44240)

## Changelog:
[iOS][Fixed] - Add `HERMES_ENABLE_DEBUGGER=1` flag to React-RuntimeApple

Reviewed By: cortinico

Differential Revision: D56575647

fbshipit-source-id: a0613a5d46caeb1d3e636e54ecd43428fbaf46e8
2024-04-25 08:28:26 -07:00
Kudo Chien 4e6186555e Defines module for React-jsinspector (#44252)
Summary:
Defines module for `React-jsinspector` that for swift modules to integrate with.

to fix https://github.com/expo/expo/issues/28209, any podspec depends on HermesExecutorFactory should use ` add_dependency(s, "React-jsinspector", :framework_name => 'jsinspector_modern')` to add dependency. otherwise it will encounter the header not found issue because use_frameworks will change "jsinspector-modern" to "jsinspector_modern".

to depend on React-jsinspector from expo-modules-core, we need it to define as a module.
otherwise, it will have the error
```
The Swift pod `ExpoModulesCore` depends upon `React-jsinspector`, which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.
```

## Changelog:

[IOS] [CHANGED] - Add `DEFINES_MODULE` for React-jsinspector.podspec

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

Test Plan: ci passed

Reviewed By: cortinico

Differential Revision: D56575102

Pulled By: cipolleschi

fbshipit-source-id: 9b7b4568a3e499f0a741a79a846263118ff2d112
2024-04-25 08:18:20 -07:00
Samuel Susla b40b3b31a2 delete feature flag enableCustomDrawOrderFabric (#44231)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44231

changelog: [internal]

The flag is not used and is statically set to false, let's delete it.

Reviewed By: NickGerleman

Differential Revision: D56473851

fbshipit-source-id: fe1076d20a765ffed2437f080764f2b5fe060bb6
2024-04-25 04:43:00 -07:00