Commit Graph

1781 Commits

Author SHA1 Message Date
Pieter De Baets c2e080419b Fix crash on reload when useImmediateExecutorInAndroidBridgeless is enabled (#45162)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45162

Previously we would crash in ReactInstance#callFunctionOnModule (P1443291303) when reloading (due to the onHostPause call) because we removed a source of synchronization by using the immediate executor.

Workaround it by making sure we always null out references to `mReactInstance` before we actually start destroying it.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D59002404

fbshipit-source-id: 3ee14cd1fe7d423bb6158356bb99b3d2d6af8d6f
2024-06-27 03:25:39 -07:00
Alex Hunt 5f60ad65ca Rename set-rn-version script, mark as deprecated (#45184)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45184

This is a follow-up to D59055522.

> NOTE:This diff will be followed up by a merge of the set-rn-version script into set-version. (I had considered a rename to version-rn-artifacts, intentionally keeping this script separate and distinct from a future [lerna version + this script] setup — however the current UX and confusion with this naming would be too confusing. It can move into a util 👍🏻.)

- Rename `set-rn-version` to `set-rn-artifacts-version` (more accurate).
- Mark this script as deprecated.
    - For now, there are too many references to this script in CI test jobs to refactor away this entry point, so I am avoiding this — these should later be standardised to `set-version`.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D59058085

fbshipit-source-id: 4123ac73b5c7a2e07a1d1b6da61e0ad94fc31f84
2024-06-26 10:14:12 -07:00
Peng Jiang b9ec0e5a1a use view.getPaddingStart() directly (#45150)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45150

As the androidx.core 1.13.1 change, ViewCompact.getPaddingStart and getPaddingEnd are deprecated.

based on the suggestion from https://developer.android.com/reference/kotlin/androidx/core/view/ViewCompat#getPaddingStart(android.view.View), use: view.getPaddingStart and view.getPaddingEnd directly.
 {F1717102270}

Changelog: [Internal] - Migrating deprecated APIs with AndroidX.Core 1.13.1

Reviewed By: alanleedev

Differential Revision: D58955567

fbshipit-source-id: b84377e1ded0d94e9035dcfa4dbd9c463396a322
2024-06-26 01:47:24 -07:00
Peng Jiang 71f8d7608f use view.LAYOUT_DIRECTION_RTL directly (#45152)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45152

As the androidx.core 1.13.1 change, ViewCompat.LAYOUT_DIRECTION_RTL is deprecated. Based on the suggestion from https://developer.android.com/reference/androidx/core/view/ViewCompat#LAYOUT_DIRECTION_RTL(), use view LAYOUT_DIRECTION_RTL directly and they have the same value.
 {F1716960190}

Changelog: [Internal] - Migrating deprecated APIs with AndroidX.Core 1.13.1

Reviewed By: alanleedev

Differential Revision: D58953460

fbshipit-source-id: 938200d1d0b1c7cc167f0119cc20ba72d16351a4
2024-06-26 01:47:24 -07:00
Jingbo Yang 8bd9952eaf Replace YogaConstants.UNDEFINED with Float.NaN (#45141)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45141

Reviewed By: javache, NickGerleman

Differential Revision: D58915391

fbshipit-source-id: 73ebee6abaced092366abdfc0ff41a66e7ff6c03
2024-06-25 18:48:15 -07:00
Ramanpreet Nara 7522336412 Bridgeless: Allow js bundle configuration via filepaths
Summary:
## Summary
Right now, the only way to load the javascript bundle is through the assets:// directory.

But, legacy react native also supports loading bundles via regular file urls.

If present, those file urls override the assets:// bundle urls.

This diff implements that support in bridgeless.

Changelog: [Android][Added] Allow js bundle file urls

Reviewed By: christophpurrer

Differential Revision: D58977143

fbshipit-source-id: 6f1a170546c8bbeac3a1b9d2dd5633177e33a688
2024-06-25 07:13:39 -07:00
Ramanpreet Nara 80e1dd70b0 ReactHost: Make ReactInstanceEventListener APIs public
Summary:
The ReactInstanceManager allows applications to register a ReactInstanceEventListener with itself.

Exposing a similar functionality to ReactHost. So, applications can do the same in bridgeless.

Changelog: [Android][Added] - Make ReactInstanceEventListener available on ReactHost

Reviewed By: christophpurrer

Differential Revision: D58890092

fbshipit-source-id: c18ee8a45d274c5cba859c6a5b4049904f1d308a
2024-06-25 07:13:39 -07:00
Moti Zilberman 4a8f0ee58a Keep HostTarget registered until ReactHostImpl/ReactInstanceManager is invalidated (#45146)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45146

Changelog: [Internal]

Currently, on Android, we destroy the Fusebox `HostTarget` when we receive the `onHostDestroy` event, which (counterintuitively) does not mean the ReactHost/InstanceManager ("Java Host") is being destroyed. This can lead to situations where the `HostTarget` is destroyed too soon (e.g. when a single Java Host is reused across multiple Activities).

Now that we have the `invalidate()` method on the Java Host classes, we can tie `HostTarget`'s destruction to that instead.

Since calling `invalidate()` is explicitly optional, we also need to account for the case where the caller just lets go of the Java Host reference and expects GC to handle cleanup. This includes:

* Breaking the retain cycle between the Java Host and its C++ part. We achieve this using `WeakReference` to reference the Java Host.
* Making the C++ part of the Host safe to destroy from any thread (and in particular the finalizer thread). We achieve this by scheduling `HostTarget`'s unregistration (in C++) on the executor supplied by the Java Host.

Reviewed By: hoxyq

Differential Revision: D58284590

fbshipit-source-id: 4ee4780354fb81137b891d5891d6138ac215cbff
2024-06-24 14:35:53 -07:00
Moti Zilberman 986cf18dd2 Migrate ReactHost / ReactInstanceManager destroy() call sites to use invalidate() (#45082)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45082

Changelog: [Android][Breaking] `ReactNativeHost` invalidates the instance manager on `clear()`

Changes `ReactNativeHost.clear()` to invalidate the underlying `ReactInstanceManager`, rather than merely destroying the instance.

This is technically a **breaking change** because the underlying `ReactInstanceManager` may have escaped (via `ReactNativeHost.getReactInstanceManager()`) before the `clear()` call. In my reading of the API and of usages like [this one in Expo](https://github.com/expo/expo/blob/23a905b17065703882ebeda1fc9f65a05cc69fa7/packages/expo-dev-menu-interface/android/src/main/java/expo/interfaces/devmenu/ReactHostWrapper.kt#L117), this should rarely occur in practice.

The plan:
1. D58811090: Add the basic `invalidate()` functionality.
2. **[This diff]**: Add `invalidate()` call sites where it makes sense in core.
3. [Upcoming diff]: Keep the Fusebox debugging target registered until the Host is explicitly invalidated.

Reviewed By: javache

Differential Revision: D58811091

fbshipit-source-id: 5dfebad46a2bdf3601642b3c3fe3e79e8695e193
2024-06-24 09:14:01 -07:00
Moti Zilberman a3db352e25 Add invalidate() method to ReactHost and ReactInstanceManager (#45081)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45081

Changelog: [Android][Added] Add `invalidate()` method to ReactHost and ReactInstanceManager

Adds an `invalidate()` method to both `ReactHost` (Bridgeless) and `ReactInstanceManager` (Bridge). This method is an *optional* signal that the application is about to permanently stop using the Host, and that the Host can therefore fully clean up any resources it's holding.

Reusing a Host after it's invalidated is illegal and will trigger a Java assertion.

The plan:
1. **[This diff]**: Add the basic `invalidate()` functionality.
2. [Upcoming diff]: Add `invalidate()` call sites where it makes sense in core
3. [Upcoming diff]: Keep the Fusebox debugging target registered until the Host is explicitly invalidated.

Reviewed By: tdn120

Differential Revision: D58811090

fbshipit-source-id: 79b607dcc74de38b85fc0ebb4c640b9654595c9a
2024-06-24 09:14:01 -07:00
Jorge Cabiedes Acosta d11a7b0d18 Add DropShadow effect on Android (#44937)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44937

Continuing CSS filters support efforts for Android this diff implements support for dropShadow.

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D58488573

fbshipit-source-id: 393e43ba1e24705d8f1fc4ba3df8e12272d874b3
2024-06-24 08:45:51 -07:00
Nicola Corti e7d1708701 Fix broken unableToAddHandledRootView (#45101)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45101

This test broke after I merged
https://github.com/facebook/react-native/pull/34785
yesterday.

Just fixing it in a similar way as the test above.

Changelog:
[Internal] [Changed] - Fix broken unableToAddHandledRootView

Reviewed By: rubennorte, blakef

Differential Revision: D58864166

fbshipit-source-id: 4f48dbfd5238a2811564ce02199af7fc284d39b4
2024-06-21 03:41:40 -07:00
psionic12 3429dc1ccf Log a SoftException on SurfaceMountingManager.addRootView (#34785)
Summary:
Follow the same solution (do not throw a crash when view ID is set already) used in `ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java` for `ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java`

## Changelog

[Android] [Changed] - Log a SoftException on SurfaceMountingManager.addRootView

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

Test Plan: None

Reviewed By: cipolleschi

Differential Revision: D40022263

Pulled By: cortinico

fbshipit-source-id: d565d2831e2833ccea55f28ea16083b7bae0ed32
2024-06-20 13:16:32 -07:00
Jakub Piasecki 2eaf0b0848 Add an overload for createLayout to reduce code duplication (#45083)
Summary:
Adds an overload for `createLayout` method that also handles extracting paragraph attributes and scaling font size if necessary.

## Changelog:

[ANDROID] [CHANGED] - Extracted common parts related to calculating text layout to a helper

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

Test Plan: Tried out on RNTester

Reviewed By: robhogan

Differential Revision: D58818560

Pulled By: cortinico

fbshipit-source-id: a42b5de04c4a70edb88cdd734387d7e4cee94032
2024-06-20 11:09:15 -07:00
Alan Lee 8a3ffb6d23 fix TextInput 'contextMenuHidden' prop (#45014)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45014

`TextInput`'s `contextMenuHidden` prop isn't working working as expected.
It should hide the context menu (copy/paste/...) that pops up from input text.

Reference: [Android doc](https://developer.android.com/reference/android/widget/TextView#setCustomSelectionActionModeCallback(android.view.ActionMode.Callback))
> Returning false from `ActionMode.Callback.onCreateActionMode(ActionMode, android.view.Menu)` will prevent the action mode from being started.

**Changelog:** [Android][Fixed] - TextInput's `contextMenuHidden` prop bug fix

Reviewed By: javache

Differential Revision: D58684366

fbshipit-source-id: 328c267ed0e896a78e114578e3a00adf41f2e095
2024-06-20 10:38:58 -07:00
Pieter De Baets 51e464f50f Remove unnecessary synchronized collections from ReactHostImpl (#45026)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45026

All callsites for these containers already explicitly synchronize using these objects, so there's no need to use a synchronized collection wrapper here.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D58724044

fbshipit-source-id: 5151ebb0ceda8656b6039d9984cc32a843051abd
2024-06-19 05:05:00 -07:00
Jorge Cabiedes Acosta d8739e1d37 Add unit tests for BorderRadiusStyle (#44964)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44964

Testing property priority and correct setting percentages for business logic of `BorderRadiusStyle.kt`

To prevent issues like the one fixed by D57473482

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D58705515

fbshipit-source-id: 74e9a68fc0e3d1e88b8eebbb34a1ca8c29052c21
2024-06-18 10:46:23 -07:00
Rubén Norte 404f323359 Set up experiment to fix the mapping of event priorities between Fabric and React (#45013)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/45013

Changelog: [internal]

## Context

We recently realized that in the majority of events dispatched to React from Fabric, passive effects were being mounted synchronously, blocking paint instead of in a separate task after paint.

The reason for that is that in React, passive effects for discrete events are mounted synchronously by design (see https://github.com/reactwg/react-18/discussions/128), and Fabric is currently assigning the discrete event priority to most current events (including things like layout events).

## Changes

This creates a feature flag to opt into a more granular control over event priorities in React Native. Instead of assigning the discrete event priority to events by default, this would assign the "default" event priority by default, except for events dispatched during continuous events that would also be considered continuous.

This would also fix the priority for continuous events, that it was currently being assigned as "default" incorrectly.

Reviewed By: christophpurrer, javache, sammy-SC

Differential Revision: D58677191

fbshipit-source-id: c65a8dc2118ed028e1e895adec54f9072b7e55a6
2024-06-18 05:24:57 -07:00
Josh Katz 5df5ed1a88 Revert D58602799: Add unit tests for BorderRadiusStyle
Differential Revision:
D58602799

Original commit changeset: 605bc384267d

Original Phabricator Diff: D58602799

fbshipit-source-id: e843aa25f0cb37344a423e886b4e4a2878d89eec
2024-06-17 16:41:33 -07:00
Jorge Cabiedes Acosta 8c7c6f35e3 Add unit tests for BorderRadiusStyle (#44964)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44964

Testing property priority and correct setting percentages for business logic of `BorderRadiusStyle.kt`

To prevent issues like the one fixed by D57473482

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D58602799

fbshipit-source-id: 605bc384267d9f4ae5a051e76c1a4d862fe54039
2024-06-17 12:09:00 -07:00
Alan Lee 4792671e4d extract ParsedError handling to helper (#44922)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44922

extract ParsedError handling code into `StackTraceHelperTest`.

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D58512611

fbshipit-source-id: 959978d80907f2afba96ef249c2fddd351d099ff
2024-06-17 10:39:22 -07:00
Alan Lee fe7e7a015f add default early JS error handler (#44884)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44884

Removing JavaScript error handler supplied to ReactHostImpl.java which is just a stub and creating a default handler in ReactInstance.java which uses NativeExceptionHandler TurboModule to handle error.

Changelog: [Android][BREAKING]  Removing `ReactJsExceptionHandler` param from ReactHostImpl() constructor and providing a default private implementation

Reviewed By: javache, cortinico

Differential Revision: D58385767

fbshipit-source-id: 46548677df936b7c2f584084a2c9769c27e6a963
2024-06-17 10:39:22 -07:00
Samuel Susla a6b862d427 clean up systrace for systrace View preallocation (#44956)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44956

changelog: [internal]

do not show systrace logs for flattened views.

Reviewed By: rubennorte

Differential Revision: D58587946

fbshipit-source-id: 6ef12feb352b9c79db6b91767c2d77906bba9cdc
2024-06-17 06:51:24 -07:00
Robert Pasiński abfadc6083 feat: Implement requestIdleCallback (#44636) (#44759)
Summary:
Implements `requestIdleCallback` and `cancelIdleCallback`

### Notes

Proposed implementation does yet cover all WHATWG eventloop requirements.
 - Deadline computation is not implemented and is polyfilled by giving each callback `50ms`, rather than it being shared between other idle callbacks.
 - The requested callbacks are called with lowest priority by the scheduler as of now, but the execution is not as described in the standard.

## Changelog:

- [GENERAL] [ADDED] - Implemented `requestIdleCallback` and `cancelIdleCallback`

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

Reviewed By: javache, sammy-SC

Differential Revision: D58415077

Pulled By: rubennorte

fbshipit-source-id: 46189d4e3ca1d353fa6059a904d677c28c61b604
2024-06-17 04:22:43 -07:00
Ramanpreet Nara 2f8d4f0c25 Ensure redbox shows up after reloads fail (#44959)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44959

If a react instance create fails, ReactHost [calls handleHostException](https://www.internalfb.com/code/fbsource/[bf94dae8c8b7527653145fdd799f6f47b1f8b284]/xplat/js/react-native-github/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java?lines=784-793%2C956-959%2C966%2C979-980%2C982%2C985-986). This method uses the dev support manager to show the redbox: line 789.

https://www.internalfb.com/code/fbsource/[bf94dae8c8b7527653145fdd799f6f47b1f8b284]/xplat/js/react-native-github/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java?lines=784-793

But, if react instance reload fails, react host does everything in handleHostException, **except** call into dev support manager to show the redbox.

https://www.internalfb.com/code/fbsource/[bf94dae8c8b7527653145fdd799f6f47b1f8b284]/xplat/js/react-native-github/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java?lines=457-466

Hence, the redbox doesn't show.

## Thoughts
These two code-paths do really similar things. I'm thinking about how to unify them.

Changelog: [Android][Fixed] Show RedBox after reloads fail (bridgeless)

Reviewed By: alanleedev

Differential Revision: D58592928

fbshipit-source-id: 37a7adc1845a8b28917fcd9acbaae1484478e4e6
2024-06-14 16:33:55 -07:00
Ramanpreet Nara ce2e4263bd Make soft exceptions easier to spot in logcat (#44958)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44958

Now, all soft exception methods will have raiseSoftException(...)

## Before

```
BridgelessReact: ReactHost{0}.getOrCreateDestroyTask(): handleHostException(message = "Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'RNTesterBundle.js' is packaged correctly for release.")
```

## After
```
BridgelessReact: ReactHost{0}.raiseSoftException(getOrCreateDestroyTask()): handleHostException(message = "Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'RNTesterBundle.js' is packaged correctly for release.")
```

Changelog: [Internal]

Reviewed By: alanleedev

Differential Revision: D58593609

fbshipit-source-id: 171a872cd41e4ffe9c2e9654c563a6f3af342ad9
2024-06-14 16:32:34 -07:00
Ramanpreet Nara e78742a9d8 Allow native module loads during react instance init
Summary:
## Context
Right now, the ReactInstance construtor eagerly initializes native modules.

## Problem
When these modules initialize, they may load other modules. But, all those loads will fail, because the react instance is in the process of being constructed.

## Changes
Eagerly initialize modules after the react instance is created. That way, these native module requires work.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D58537536

fbshipit-source-id: d0e424df708ec35b014f5cecda11e8756e8f4346
2024-06-14 09:17:32 -07:00
Ramanpreet Nara 74d030de70 Attach react instance to react host immediately
Summary:
## Changes
1. Store the react instance inside a private property (vs in the mReactInstanceTaskRef)
2. Attach the react instance to that property immediatley, after create

## Problems resolved
1. React host apis that use the instance (like ReactContext.getNativeModule()) will now also work **during** react native init. (see T191972567).
2. If exceptions get thrown during react instance init, the react instance will now get cleaned up (see test plan).

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D58537535

fbshipit-source-id: fddf44d45b214b52a950e33d67ac6612a50ddcba
2024-06-14 09:17:32 -07:00
Rubén Norte 49a911fab4 Back out "Revert D58459930: [react-native][PR] Add ReactMarkerConstants.CONTENT_APPEARED support on Android"
Summary:
Changelog: [ANDROID] [ADDED] - Add the ReactMarkerConstants.CONTENT_APPEARED support on Android in bridgeless mode.

This re-applies https://github.com/facebook/react-native/pull/43620 which was reverted because a CI job started failing because we forgot to update `packages/react-native/ReactAndroid/api/ReactAndroid.api`.

Reviewed By: cortinico

Differential Revision: D58535868

fbshipit-source-id: 9eec33c5e798850a7434a6c391abf2fc3fc9d0a6
2024-06-13 12:49:25 -07:00
Moti Zilberman e3a76c5155 Expose DevSettings.openDebugger method to JS (#44934)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44934

Resubmission of D57681447 with an updated `ReactAndroid.api`.

 ---

Changelog: [Internal]

Adds a private API that gives JS the ability to trigger the same "open debugger" action as in the Dev Menu. This is in preparation for changes to LogBox.

For simplicity, this method operates on a best-effort basis - i.e. it doesn't report the success or failure (or failure reason) of the launch.

Reviewed By: huntie

Differential Revision: D58529832

fbshipit-source-id: e5510f529a19e0149d8dce04fa610e6c2371cc79
2024-06-13 12:22:48 -07:00
Sergei Rybalkin 726a4a1e5e Revert D57681447: Expose DevSettings.openDebugger method to JS
Differential Revision:
D57681447

Original commit changeset: ddb1fbd0f1c8

Original Phabricator Diff: D57681447

fbshipit-source-id: 94bf94227bcc9fab8282bd68ddf3f4f1df64656b
2024-06-13 07:20:18 -07:00
Sergei Rybalkin 7e0f894d3a Revert D58459930: Add ReactMarkerConstants.CONTENT_APPEARED support on Android
Differential Revision:
D58459930

Original commit changeset: 4498a3623c50

Original Phabricator Diff: D58459930

fbshipit-source-id: 8bc5ef3c8b1e42a4085ee6d2834bf6906c936c0d
2024-06-13 07:19:45 -07:00
Moti Zilberman 1fb5a4b283 Expose DevSettings.openDebugger method to JS (#44647)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44647

Changelog: [Internal]

Adds a private API that gives JS the ability to trigger the same "open debugger" action as in the Dev Menu. This is in preparation for changes to LogBox.

For simplicity, this method operates on a best-effort basis - i.e. it doesn't report the success or failure (or failure reason) of the launch.

Reviewed By: hoxyq

Differential Revision: D57681447

fbshipit-source-id: ddb1fbd0f1c8d07bfa57d65c54e3a34bb7a470a8
2024-06-13 04:01:25 -07:00
Kudo Chien 5da9fdf8f1 Add ReactMarkerConstants.CONTENT_APPEARED support on Android (#43620)
Summary:
Add the `ReactMarkerConstants.CONTENT_APPEARED` support on Android in bridgeless mode. This is an important marker for TTI measurement.

## Changelog:

[ANDROID] [ADDED] - Add the `ReactMarkerConstants.CONTENT_APPEARED` support on Android in bridgeless mode.

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

Test Plan:
adding this on RNTesterActivity to see if the log is executed

```kotlin
ReactMarker.addListener { name, tag, instanceKey ->
  if (name == ReactMarkerConstants.CONTENT_APPEARED) {
    Log.i("XXX", "XXX")
  }
}
```

Reviewed By: cortinico

Differential Revision: D58459930

Pulled By: rubennorte

fbshipit-source-id: 4498a3623c506d228aea995c8aeafdb51fcc5b96
2024-06-13 03:57:16 -07:00
Peter Abbondanzo 0ad107b988 Add Clipboard module to base packages (#44881)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44881

Updates the companion object for `ClipboardModule` to re-export the generated parent's `NAME`.

Changelog: [Internal]

Differential Revision: D58426185

fbshipit-source-id: a60462a990003413f9b0c646a97026217a64b418
2024-06-12 17:06:27 -07:00
Peter Abbondanzo b6c3433537 Hybrid image aliasing (#44803)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44803

This change introduces a new prop to the Android `Image` component: `resizeMultiplier`. This prop can be used when the `resizeMethod` is set to `resize`, and it directly modifies the resultant bitmap generated in memory from Fresco to be larger (or smaller) depending on the multiplier. A default of 1.0 means the bitmap size is designed to fit the destination dimensions. A multiplier greater than 1.0 will set the `ResizeOptions` provided to Fresco to be larger that the destination dimensions, and the resulting bitmap will be scaled from the hardware size.

This new prop is most useful in cases where the destination dimensions are quite small and the source image is significantly larger. The `resize` resize method performs downsampling and significant image quality is lost between the source and destination image sizes, often resulting in a blurry image. By using a multiplier, the decoded image is slightly larger than the target size but smaller than the source image (if the source image is large enough).

It's important to note that Fresco still chooses the closest power of 2 and will not scale the image larger than its source dimensions. If the multiplier yields `ResizeOptions` greater than the source dimensions, no downsampling occurs.

Here's an example:
If you have a source image with dimensions 200x200 and destination dimensions of 24x24, a `resizeMultiplier` of `2.0` will tell Fresco to downsample the image to 48x48. Fresco picks the closest power of 2 (so, 50x50) and decodes the image into a bitmap of that size. Without the multiplier, the closest power of 2 would be 25x25, which is half the quality.

## Changelog

[Android][Added] - Adds a new `Image` prop `resizeMultiplier` to help increase quality of small images on low DPI devices

Reviewed By: javache

Differential Revision: D58120352

fbshipit-source-id: e0ebf4bd899170134825a29f72a68621447106c0
2024-06-12 12:57:53 -07:00
Peter Abbondanzo 297ded90aa Fall back to app AlertDialog for non AppCompat themes (#44495)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44495

## Summary
Migrates the `AlertFragment` from `android.app.AlertDialog` to `androidx.appcompat.app.AlertDialog`. This backports tons of fixes that have gone into the AlertDialog component over the years, including proper line wrapping of button text, dark mode support, alignment of buttons, etc.

This change provides a fallback to the original `android.app.AlertDialog` if the current activity is not an AppCompat descendant.

## For consideration
- Alert dialog themes may no longer need the `android` namespace, meaning themes can now be specified as `alertDialogTheme` rather than `android:alertDialogTheme`.

## Changelog:

[Android] [Changed] - Migrated `AlertFragment` dialog builder to use `androidx.appcompat`

Reviewed By: zeyap

Differential Revision: D57113950

fbshipit-source-id: ba5109c9d79b6ceb042ff93eebe796a2d14ebd63
2024-06-12 11:24:56 -07:00
Peter Abbondanzo 600d3f6ff1 Migration RN Alert Dialog to androidx (#44494)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44494

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

Migrates the `AlertFragment` from `android.app.AlertDialog` to `androidx.appcompat.app.AlertDialog`. This backports tons of fixes that have gone into the AlertDialog component over the years, including proper line wrapping of button text, alignment of buttons, etc.

## For consideration
- Alert dialog themes may no longer need the `android` namespace, meaning themes can now be specified as `alertDialogTheme` rather than `android:alertDialogTheme`.
- This change requires all implementing activities to have a theme that inherits from `Theme.AppCompat`. Creation of any activities which do not have a descendant of this style will result in an `IllegalStateException`: https://www.internalfb.com/intern/signalinfra/exception_owners/?mid=5ee93f6ecd59f3d8ad82a78c213ea016&result_id=16044073705339118.281475102518721.1715097866

## Changelog:

[Android] [Changed] - Migrated `AlertFragment` dialog builder to use `androidx.appcompat`

Reviewed By: zeyap

Differential Revision: D57019423

fbshipit-source-id: 84d8f69d896d32e72434149c0e31735d358370a9
2024-06-12 11:24:56 -07:00
Alex Hunt 28ded2c6cd Move SessionMetadata to HostTargetDelegate (#44878)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44878

A refactor moving `SessionMetadata` (now renamed as `HostTargetMetadata`) out of `inspectorTarget->connect()` calls into a `HostTargetDelegate::getMetadata` method. This provides a cleaner interface and location for extending metadata fields in future.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D58288491

fbshipit-source-id: 67e8b9a3fb6d0b7966187fa98d9852222f242b9d
2024-06-12 09:39:08 -07:00
Samuel Susla 18be49e7bb split trace blocks inside of IntBufferBatchMountItem by type of operation (#44897)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44897

changelog: [internal]

To get better understanding of where the time is spent, let's split IntBufferBatchMountItem systrace section into individual types.

Reviewed By: javache

Differential Revision: D58080444

fbshipit-source-id: d71dcc74a042c6c40270ca6f1dc7a8735c0471b8
2024-06-12 08:32:26 -07:00
Pieter De Baets c92f31d834 Fix include directive to solve redefinition error (#44891)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44891

Changelog: [Internal]

Reviewed By: cortinico, fabriziocucci, cipolleschi

Differential Revision: D58459144

fbshipit-source-id: a07280de01c9ff4333e5140c6b741d88c1c5d89a
2024-06-12 07:24:40 -07:00
Fabrizio Cucci 33aa83a0e6 Stop ReactSurface in ReactDelegate::onHostDestroy (bridgeless) (#44873)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44873

Changelog:
[Android][Fixed] - Unmount React root when activity is destroyed on bridgless

Reviewed By: javache

Differential Revision: D58411605

fbshipit-source-id: ff9940efd4cf5da5887d79d99bcf3721e16d6725
2024-06-12 05:38:02 -07:00
Nick Gerleman bfb3b7008d Support clipping to children everywhere using ReactViewBackgroundManager (#44734)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44734

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

This integrates functionality for clipping content to padding box into `ReactViewBackgroundManager`, to be shared between several ViewManagers. In practice, this means:

1. `overflow: hidden` now works on `Text` and `TextInput`
2. ScrollView children are now clipped to the interior of borders, included curved ones via borderRadius

This will be made more generic, then start being used in ReactViewGroup, and eventually ReactImage. That abstraction will then hide away extra background management we will use for shadows.

Different places in code currently do clipping in any of `draw()`, `onDraw()`, or `dispatchDraw()`. The distinction between these, is that `draw()` allows code to run before drawing background even, `onDraw()` is invoked before drawing foreground, and `dispatchDraw()` is before drawing children. We don't want to clip out borders/shadows, but do want to clip foreground content like text, so I used `onDraw()` here.

Changelog:
[Android][Fixed] - Better overflow support for ScrollView, Text, TextInput

Reviewed By: rozele

Differential Revision: D57953429

fbshipit-source-id: ca3b788deb4b32706df7db958877d18f525c039c
2024-06-11 16:13:28 -07:00
Wojciech Lewicki 8a15e0d97a fix: singletonMap for module events (#42354)
Summary:
Sometimes the events map can be a of type `SingletonMap` which will cause this code to throw exception when adding keys to it, so we change it to normal `HashMap`. Creating `SingletonMap` can especially happen in Kotlin when there is only one event added to a map, see:
https://github.com/plaid/react-native-plaid-link-sdk/blob/5ffab5eef576163528f0da504181162da3bef08b/android/src/main/java/com/plaid/PLKEmbeddedViewManager.kt#L21
## Changelog:

[ANDROID] [FIXED] - Cover SingletonMap when parsing events exported by module

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

Test Plan: Create `getExportedCustomBubblingEventTypeConstants` as `SingletonMap` in some example module and see that the code does not throw.

Reviewed By: cipolleschi

Differential Revision: D58417266

Pulled By: cortinico

fbshipit-source-id: 6c46398ddf4d044386a36d0c1663bd071d642fb6
2024-06-11 12:20:07 -07:00
Alex Hunt 3303dd35ed Expose unstable_loadFusebox API on Android (#44858)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44858

- Enables an opt-in to the Fusebox stack on Android for both architectures in open source.
- Templates use of this opt-in in RNTester.

Changelog: [Internal]

Reviewed By: rubennorte

Differential Revision: D58359907

fbshipit-source-id: d565dc8e00747dff56d3060e36e7f59e7dd2aec5
2024-06-11 06:11:35 -07:00
Soe Lynn 0d345698d8 Measure with transform bugfix (#44821)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44821

Changelog: [Internal]

- Originally D37994809 was attempted to fix `Inverted FlatList` but was put behind Feature Toggle because it was causing problems in other scenarios.
- Later, D45866231 which was trying to fix scaling transform issue helped solve the issue attempted by the original diff.
- But after that points, Unit test around `computeRelativeLayoutMetrics` was having two variants where Feature Toggle for D37994809 was checked in with a wrong expected value.
- This diff revert D37994809 changes and clean up the unit test.

Reviewed By: NickGerleman

Differential Revision: D58197918

fbshipit-source-id: d8ae552018617e785e4010bc5805c53a875e02a3
2024-06-10 21:03:45 -07:00
Nicola Corti e686b4330d Tentative fix for NPE JavaTimerManager$IdleCallbackRunnable.cancel (#44852)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44852

This attempts to fix #44842 by capturing the accessed field in a new variable.
We don't have a way to reproduce this & this is a best guess fix.

Changelog:
[Android] [Fixed] - Tentative fix for NPE `JavaTimerManager$IdleCallbackRunnable.cancel`

Reviewed By: javache

Differential Revision: D58356826

fbshipit-source-id: d016df9a52f81a8d645a0a100c6bc6111841e24e
2024-06-10 13:39:27 -07:00
Pieter De Baets fdb2427a86 Add getNativeModule(String) to ReactContext interface (#44851)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44851

This method is available on the (deprecated) CatalystInstance interface, but not on ReactContext, even though it is trivially supported.

Changelog: [Android][Added] - Added getNativeModule(name) to ReactContext

Reviewed By: cortinico

Differential Revision: D58355135

fbshipit-source-id: 0cc76bb2da2b49510dc626cb8b3a3e93db5a16b0
2024-06-10 09:02:05 -07:00
Peter Abbondanzo 0b8222a854 Fix status bar height calculation for all cutout sizes (#44805)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44805

Google has discouraged attempting to read the `status_bar_height` resource [since 2017](https://youtu.be/_mGDMVRO3iE?si=qGQd7gLa_qTmfLGL&t=1079). With the introduction of display cutouts there can be a mismatch between the resource value and the true status bar size (and issues like [this one](https://github.com/facebook/react-native/issues/33612) popped up). The recommended approach is to instead call `getInsets` with the proper status bar and navigation flags provided by `WindowInsets`. On older APIs where `getInsets` is not supported, we have access to `systemWindowInsetTop`.

Changelog:
[Android][Fixed] - Fixed StatusBar.currentHeight calculations to honor all cutout sizes

Reviewed By: tdn120

Differential Revision: D58088036

fbshipit-source-id: 9c035a79cbb96db1cf3b5b5c36242df7453fe205
2024-06-10 08:25:33 -07:00
Nicola Corti 8ce450c435 Convert MountingManagerTest to Kotlin (#44837)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44837

As the title says.

Changelog:
[Internal] [Changed] - Convert MountingManagerTest to Kotlin

Reviewed By: javache

Differential Revision: D58290597

fbshipit-source-id: a5c499fbffcaeef4e21ebbca1904b22803c35270
2024-06-07 10:40:36 -07:00