Commit Graph

1697 Commits

Author SHA1 Message Date
Ramanpreet Nara 457372c87e Add native view config for {margin,padding}{block,inline} props
Summary:
The margin/padding props were introduced in this diff: D41267765

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D56846578

fbshipit-source-id: 396cab3fdd63d9c630690157a385f1ae53208bb7
2024-05-02 12:46:05 -07:00
Ramanpreet Nara 063ae7d3e8 Add native view config for inset props
Summary:
The insets props were introduced in this diff: D42193661

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D56849870

fbshipit-source-id: 7be2a5825086ac954fdb8bc3bb86b57a2fa6d326
2024-05-02 12:46:05 -07:00
Ramanpreet Nara ef1e84e425 Add native view config for collapsableChildren
Summary:
collapsableChildren was introduced in D56226241

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D56849868

fbshipit-source-id: b2b08bfc2b8a35a863a91a53e1bee0b700c50f69
2024-05-02 12:46:05 -07:00
Ramanpreet Nara 5e46712dc8 Add native view config for experimental_layoutConformance
Summary:
experimental_layoutConformance was added in this diff: D47940100

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D56849869

fbshipit-source-id: 2346a869aa9d87916d074e54306d3c1230b7a91c
2024-05-02 12:46:05 -07:00
Ramanpreet Nara 3ffdace137 Fix comments in LayoutShadowNode!
Summary: Changelog: [Internal]

Reviewed By: javache

Differential Revision: D56831755

fbshipit-source-id: 04b8c131355d711224085caeb6a26eb4c17db755
2024-05-02 12:46:05 -07:00
Arushi Kesarwani 63043b79be Fix shouldShowDevMenuOrReload in RELEASE
Summary:
In RELEASE mode, the `devSupportManager` received is ReleaseDevSupportManager for which `showDevOptionsDialog()` & `handleReloadJS()` is a no-op
https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/ReleaseDevSupportManager.java

Which is expected since this is a capability only in Dev mode(useDeveloperSupport = true). However, ATM `shouldShowDevMenuOrReload()` returns true in RELEASE as well which is a bug.

Since there is no need for `shouldShowDevMenuOrReload()` in RELEASE, changing it's logic to introduce that check, early exit and return false in case of RELEASE.

Changelog:
[Android][Fixed] shouldShowDevMenuOrReload() in RELEASE mode

Reviewed By: RSNara

Differential Revision: D56851473

fbshipit-source-id: e9e12b0bec8aead5e9227fcd676459ca54490b61
2024-05-01 21:27:58 -07:00
Arushi Kesarwani bdcc979bab Fix onKeyLongPress() in RELEASE
Summary:
In RELEASE mode, the `devSupportManager` received is ReleaseDevSupportManager for which `showDevOptionsDialog()` is a no-op
https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/ReleaseDevSupportManager.java#L66

Which is expected since this is a capability only in Dev mode(useDeveloperSupport = true). However, ATM `onKeyLongPresss()` returns true in RELEASE as well which is a bug.

Since there is no need for `onKeyLongPress()` in RELEASE, changing it's logic to introduce that check and return false in case of RELEASE.

Changelog:
[Android][Fixed] onKeyLongPress() in RELEASE mode

Reviewed By: christophpurrer, RSNara

Differential Revision: D56850466

fbshipit-source-id: 92d2c8572b32d065f5f9d54e22588bb085b9dcc9
2024-05-01 21:27:58 -07:00
Eric Rozell 67bc65df85 Add C++ header for default TurboModules and cross-platform reuse (#44361)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44361

In order to keep all platforms in sync (Android, iOS, Windows, etc.), it makes sense to consolidate all C++ TurboModules that we want available by default on all platforms to a shared C++ header / implementation.

This moves the duplicated code from Android and iOS to such a shared module provider and updates relevant build specs.

## Changelog

[Internal]

Reviewed By: christophpurrer

Differential Revision: D56835783

fbshipit-source-id: 7322ed054ded5749973885c63257e5caf23b3fc3
2024-05-01 20:16:16 -07:00
John Ward 0383669a4b Only schedule Choreographer callbacks if there's an active animation
Summary:
Changelog: [Internal]
A very similar diff was attempted with D50647971 and reverted in D51617862. The main difference here is all behavior is gated behind the feature flag. Before, we were enqueuing the extra frame callback on start_animating_node even if ondemand choreographer was disabled.

Reviewed By: javache

Differential Revision: D56085369

fbshipit-source-id: fa6335303fe98199b18fa2b4819110afb8efcc0d
2024-05-01 16:41:53 -07:00
Arushi Kesarwani dfa6519749 getJavaScriptContextHolder() in BridgelessReactContext (#44360)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44360

Support `getJavaScriptContextHolder()` in BridgelessReactContext

Changelog:
[Android][Added] - getJavaScriptContextHolder() supported in BridgelessReactContext since it's supported in ReactContext[Bridge]

Reviewed By: philIip, RSNara

Differential Revision: D56834958

fbshipit-source-id: e274adc01b0993012f36224d5afaa3918997c13c
2024-05-01 16:10:04 -07:00
Kudo Chien 539922339b fix ReactActivity.getReactDelegate().reload() (#44223)
Summary:
fixing some problem for `ReactActivity.getReactDelegate().reload()` from https://github.com/facebook/react-native/issues/43521:
- the `reload()` does not work for bridge mode on release build

## Changelog:

[ANDROID] [FIXED] - Fixed app reloading for `ReactActivity.getReactDelegate().reload()`.

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

Test Plan:
tried to temporary change toast.show as reload and test from rn-tester
```diff
 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/toast/ToastModule.kt
+++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/toast/ToastModule.kt
@@ -10,6 +10,7 @@ package com.facebook.react.modules.toast
 import android.view.Gravity
 import android.widget.Toast
 import com.facebook.fbreact.specs.NativeToastAndroidSpec
+import com.facebook.react.ReactActivity
 import com.facebook.react.bridge.NativeModule
 import com.facebook.react.bridge.ReactApplicationContext
 import com.facebook.react.bridge.UiThreadUtil
@@ -30,9 +31,11 @@ public class ToastModule(reactContext: ReactApplicationContext) :
       )

   override public fun show(message: String?, durationDouble: Double) {
-    val duration = durationDouble.toInt()
-    UiThreadUtil.runOnUiThread(
-        Runnable { Toast.makeText(getReactApplicationContext(), message, duration).show() })
+//    val duration = durationDouble.toInt()
+//    UiThreadUtil.runOnUiThread(
+//        Runnable { Toast.makeText(getReactApplicationContext(), message, duration).show() })
+    val activity = reactApplicationContext.currentActivity as? ReactActivity
+    activity?.reactDelegate?.reload()
   }

   override public fun showWithGravity(
```

tried for different mode
- [x] bridge mode + debug build
- [x] bridgeless mode + debug build
- [x] bridge mode + release build
- [x] bridgeless mode + release build

Reviewed By: fkgozali

Differential Revision: D56795975

Pulled By: arushikesarwani94

fbshipit-source-id: 895eab1927ba6db748ebb32c0fd5313f19cf9d1b
2024-05-01 15:21:44 -07:00
Pieter De Baets 90663081de Expose BaseJavaModule constructors through ViewManager
Summary:
ViewManagers are all BaseJavaModule, and thus have access to methods like `getReactApplicationContext`. We don't expose the appropriate constructors though to pass this context down from the base class.

Not a breaking change, as the no-arg constructor is still used implicitly.

Changelog: [Android][Fixed] ViewManagers can pass context to their base class.

Reviewed By: fabriziocucci

Differential Revision: D56804318

fbshipit-source-id: b0e6b15dfd7786073da058beccfaba2ff30daf5a
2024-05-01 11:49:53 -07:00
Rubén Norte c3b7aac143 Migrate enableGranularShadowTreeStateReconciliation from CoreFeatures to ReactNativeFeatureFlags
Summary:
Changelog: [internal]

Migrating this feature flag (which is currently unused) to the new system, so we can test it in production and ship it soon.

Reviewed By: NickGerleman

Differential Revision: D56766553

fbshipit-source-id: 42d44cdd163568564e789cdffe1683e78fe91b53
2024-05-01 03:41:42 -07:00
Nick Gerleman 7f5bff48dd Remove "deduplicated" Spannable path
Summary:
This removes the bulk of code added in https://github.com/facebook/react-native/pull/39630.

We're not shipping it, as it caused performance regressions.

Changelog:
[Internal]

Reviewed By: christophpurrer

Differential Revision: D56796936

fbshipit-source-id: 82f3a51cf145bc1695d70393e1f050685a1e6174
2024-04-30 22:30:05 -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
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
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
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
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 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
Samuel Susla 0dbe6f10c1 clean up interfaces for view preallocation (#44232)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44232

changelog: [internal]

surfaceId parameter is not needed `schedulerDidRequestPreliminaryViewAllocation` as it can be derived from shadow node.
Additionally, conversion to ShadowView can happen on the lower layers.

Reviewed By: NickGerleman

Differential Revision: D56350599

fbshipit-source-id: 9c38cc0df36911bbd6927fe0a0d5e64c248d87c4
2024-04-25 04:39:08 -07:00
Nizam 78ab5f4b83 img events fixes for ios and android (#43945)
Summary:
fixes Image events in new architecture
https://github.com/facebook/react-native/issues/43874

## Changelog:

[iOS] [Fixed] - Missing `source` in `onLoad` native event arguments
[iOS] [Fixed] - Missing `error`, `responseCode`, and `httpResponseHeaders` in `onError` native event arguments
[iOS] [Fixed] - Missing `loaded` and `total`  in `onProgress` native event arguments
[Android] [Fixed] - Missing `progress`  in `onProgress` native event arguments

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

Test Plan:
test using Image section of rn-tester app

before
![image](https://github.com/facebook/react-native/assets/1734518/8f7d714b-2ddf-4db0-a539-7be52e3fd948)
after
![image](https://github.com/facebook/react-native/assets/1734518/50f14906-1b65-447f-ae84-634989c1bfc7)

Reviewed By: rozele

Differential Revision: D55945341

Pulled By: NickGerleman

fbshipit-source-id: da4e0e68a78ec8566d94e6df63e17f0436972a4f
2024-04-24 16:25:37 -07:00
Samuel Susla cf926a1329 decouple commit from mount on Android (#44236)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44236

## Changelog:

[Android] [Fixed] - fix a case when view preallocation or props forwarding on Android lead to dropped props update

# What does this fix

This fixes a bug where prop change is not delivered to Android mounting layer if the prop change was initiated from state update inside of `useLayoutEffect`, `componentDidMount` or `componentDidUpdate`.
This affects android only and when batched rendering is enabled.

There are two root causes of this problem:
1. View preallocation on Android: https://fburl.com/code/r62p3vot
2. Prop forwarding on Android: https://fburl.com/code/644f1ppk

Minimal repro :
```
import React, {useLayoutEffect, useState} from 'react';
import {Button, SafeAreaView, View} from 'react-native';
function Foo() {
  const [bgColor, setBgColor] = React.useState('red');
  useLayoutEffect(() => {
    console.log('useLayoutEffect');
    setBgColor('blue');
  }, []);
  return (
    <View
      style={{
        backgroundColor: bgColor,
        width: '100%',
        height: '100%',
      }}
    />
  );
}
function RNTesterApp() {
  const [show, setShow] = useState(false);
  return (
    <SafeAreaView>
      <Button title="Toggle" onPress={() => setShow(!show)} />
      {show && <Foo />}
    </SafeAreaView>
  );
}
export default RNTesterApp;
```

# The underlaying problem
The problem is combination of view preallocation and batched rendering updates.

Here is a step by step what happens in the repro above:
1. React issues asks Fabric to create new shadow node A with background colour **red**.
2. Fabric asks Android to allocate a view for shadow node A with background colour **red**.
3. React commits tree **T1** and calls layout effects. Meanwhile Fabric waits, without trying to mount the tree **T1**, to prevent painting state that is about to be updated and prevent flickering.
4. React clones node A, changing the background colour to **blue** and commits the new tree **T2**.
5. Fabric, will now go ahead and mount the latest tree **T2**. While creating mount instructions, it will drop prop updates because it believes prop updates where delivered already as part of step 2.

# The fix

The fix is to change two things:
1. Ignore view preallocation for shadow nodes which were cloned with new props.
2. Set hasBeenMounted flag on ShadowNode later in the Fabric pipeline to fix it.

Both of these are hidden behind a single feature flag: `fixMountedFlagAndFixPreallocationClone`

## Performance implication:
I estimate that this will impact around 3% of views.

Reviewed By: rubennorte

Differential Revision: D56353589

fbshipit-source-id: 651d3cd2d0f78bfbbe9c05aa1ae1b1690c15e4ea
2024-04-24 14:54:08 -07:00
Pieter De Baets 766ece7b9b Fix PointerEvents not dispatching post-scroll (#44238)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44238

Changelog: [Android][Fixed] PointerEvents were not dispatching after a scroll event

Reviewed By: RSNara

Differential Revision: D56519337

fbshipit-source-id: 72ea6fba583f1105e6c71560fc3a06913287844f
2024-04-24 08:22:00 -07:00
Pieter De Baets 767197c9a2 Rollout enableFabricPendingEventQueue feature flag (#44208)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44208

Changelog: [Internal]

Reviewed By: rubennorte

Differential Revision: D56467342

fbshipit-source-id: 0461b16727af708769af363125bf51c0761c9505
2024-04-24 06:30:50 -07:00
Pieter De Baets 849da2146c Split scheduler commit and flush delegate methods (#44188)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44188

The current approach used for `batchRenderingUpdatesInEventLoop` is not compatible with Android due to limitations in its props processing model. The raw props changeset is passed through to Android, and must be available for the Android mounting layer to correctly apply changes.

We have some logic to merge these payloads when multiple ShadowNode clones take place but were previously assuming that a ShadowTree commit was a safe state to synchronize.

In the current implementation this means that two commits driven from layout effects (triggering states A → B → C) may cause Android to observe only the B → C props change, and miss out on any props changed in A → B.

Changelog: [Android][Fixed] Cascading renders were not mounting correctly when `batchRenderingUpdatesInEventLoop` is enabled.

Reviewed By: rubennorte

Differential Revision: D56414689

fbshipit-source-id: 7c74d81620db0f8b7bd67e640168afc795c7a1d7
2024-04-24 03:54:10 -07:00
Arushi Kesarwani e25860f07c Fixing exposing ReactDelegate through ReactActivity for reload() (#44227)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44227

In https://github.com/facebook/react-native/pull/44223/ kudo identified the incorrect return type.

Reviewed By: christophpurrer, philIip

Differential Revision: D56497700

fbshipit-source-id: 5d7fc7ef21c3d3033a2567eba51b613eb41f0a1a
2024-04-24 00:20:54 -07:00
Riccardo Cipolleschi 05f0861878 Back out "Update ColorPropConverterto support color function values" (#44225)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44225

Back out [#43031](https://github.com/facebook/react-native/pull/43031) as it makes some internal test fails.

## Changelog:
[Android][Fixed] - Revert #43031

Reviewed By: arushikesarwani94

Differential Revision: D56489260

fbshipit-source-id: bd843e6eb60fce0a1d5d8da9f3c5d2a36473ecfb
2024-04-23 13:58:25 -07:00
Samuel Susla 4928f44f70 tear down surfaces when React Native instance is destoyed (#44209)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44209

## Changelog:

[Android] [Fixed] - When React Native is destroyed, unmount all Fabric surfaces.

Previously, Fabric surfaces would not be torn down. Meaning that passive and layout effects wouldn't be unmounted and surface infra wouldn't be cleaned up.

For example:

```
useEffect(() => {
    return () => {
      console.log('unmounted');
    }
)};
```

When calling `ReactNativeHost.clear()` on Android in native code, the above effect should be unmounted.

This is a requirement for Fabric.

Reviewed By: javache

Differential Revision: D56238947

fbshipit-source-id: 5dbf5cdef520f34c78953c2b8f2d42349549e893
2024-04-23 10:18:55 -07:00
Rubén Norte ff094d80d0 Clean up feature flag for mount hooks on Android (#44206)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44206

Changelog: [internal]

We finally managed to implement mount hooks without reliability issues on Android, so we can clean up the feature flag and enable it unconditionally.

Reviewed By: cortinico

Differential Revision: D56467379

fbshipit-source-id: d797ec770b731135332bc9f39df1c1e684b3bde4
2024-04-23 08:48:06 -07:00
Riccardo Cipolleschi 0a80270187 Extend Property Processor to support long properties
Summary:
This change is a preliminary change to add support to `Long` and `long` React props that are required for supporting WideGamut color space.

## Changelog
[Android][Added] - Extend Property Processor to support long props

Reviewed By: cortinico

Differential Revision: D56461183

fbshipit-source-id: 0f70388abe2b414a09df640f04e767f1164d63ce
2024-04-23 08:37:44 -07:00
Ryan Linton 0a9891a2f2 Add isWideColorGamutEnabled to ReactActivityDelegate (#43036)
Summary:
This adds support for enabling wide color gamut mode for ReactActivity per the wide gamut color [RFC](https://github.com/react-native-community/discussions-and-proposals/pull/738).

## Changelog:

[ANDROID] [ADDED] - Add isWideColorGamutEnabled to ReactActivityDelegate

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

Test Plan:
Update RNTesterActivity.kt to enable wide color gamut:

```diff
  class RNTesterActivity : ReactActivity() {
    class RNTesterActivityDelegate(val activity: ReactActivity, mainComponentName: String) :
      // ...
      override fun getLaunchOptions() =
          if (this::initialProps.isInitialized) initialProps else Bundle()

+     override fun isWideColorGamutEnabled() = true
    }
```

Reviewed By: cortinico

Differential Revision: D55749124

Pulled By: cipolleschi

fbshipit-source-id: 44dd5631e1a2e429c86c01ed8747bbebbc8bdb3b
2024-04-23 08:37:44 -07:00
Ryan Linton fa7dbd578d Update ColorPropConverterto support color function values (#43031)
Summary:
This adds support for color function values to ColorPropConverter per the wide gamut color [RFC](https://github.com/react-native-community/discussions-and-proposals/pull/738). It updates the color conversion code so that it returns a Color instance before ultimately being converted to an Integer in preparation for returning long values as needed.

bypass-github-export-checks

## Changelog:

[ANDROID] [ADDED] - Update ColorPropConverter to support color function values

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

Test Plan:
Colors should work exactly the same as before.

Follow test steps from https://github.com/facebook/react-native/pull/42831 to test support for color() function syntax.

While colors specified with color() function syntax will not yet render in DisplayP3 color space they will not be misrecognized as resource path colors but will instead fallback to their sRGB color space values.

Reviewed By: cortinico

Differential Revision: D55749058

Pulled By: cipolleschi

fbshipit-source-id: 37659d22c1db4b1a27a9a4f88c9beb703517b01f
2024-04-23 08:37:44 -07:00
Keion Anvaripour 098454d425 Expose JSExceptionHandler to ReactNativeHost (#44172)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44172

Changelog: [Android][Added] Option to set a custom JSExceptionHandler instance

Reviewed By: javache

Differential Revision: D56382090

fbshipit-source-id: 69ad72ee34f1c9f636d95035d0463c5344cb4a37
2024-04-23 04:04:19 -07:00
Nivaldo Bondança 876914be55 Update ktfmt component on FBS:master (#44184)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44184

Reviewed By: zertosh

Differential Revision: D56421174

fbshipit-source-id: 686e23775f53d67980c2e84a17d0a5c490dbec2a
2024-04-22 12:43:18 -07:00
Arushi Kesarwani 57663f7673 Refactor ReactHostImpl to simplify logging (#44170)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44170

Addressing following logging issues with ReactHostImpl
- replacing `ReactSoftExceptionLogger.logSoftException()` directly with private `raiseSoftException()` at all call-sites
- `raiseSoftException()` already has a call to `log()`, hence removing that.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D56335797

fbshipit-source-id: 41e094b5dc25f23fa19cd391a85ea101c3ff9058
2024-04-22 11:11:22 -07:00
Jakub Piasecki b236e154a1 Fix font scaling when numberOfLines is not set on Android on the new arch (#44165)
Summary:
This is a follow-up to https://github.com/facebook/react-native/pull/44075. I've missed the fact that `ReactConstants.UNSET` is `-1` and the default value of `numberOfLines` prop is `0`. This resulted in font size being set to the minimal value when `adjustFontSizeToFit` was used without setting `numberOfLines` to a positive value.

## Changelog:

[ANDROID] [FIXED] - Fixed `adjustFontSizeToFit` when used without `numberOfLines`

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

Test Plan:
<details>
<summary>Tested on the following code</summary>

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

export default function Test() {
  return (
    <SafeAreaView style={styles.container}>
      <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}>
        <Text style={{ fontSize: 16 }}>
          Some text that fits (no adjust, unlimited height)
        </Text>
      </View>

      <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}>
        <Text style={{ fontSize: 16 }} adjustsFontSizeToFit>
          Some text that fits (adjust, unlimited height)
        </Text>
      </View>

      <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}>
        <Text style={{ fontSize: 16 }} numberOfLines={1}>
          Some text that fits (no adjust, 1 line)
        </Text>
      </View>

      <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}>
        <Text style={{ fontSize: 16 }} adjustsFontSizeToFit numberOfLines={1}>
          Some text that fits (adjust, 1 line)
        </Text>
      </View>

      <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}>
        <Text style={{ fontSize: 16 }}>
          Some longer text that doesn't fit if displayed in one line (no adjust, unlimited height)
        </Text>
      </View>

      <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}>
        <Text style={{ fontSize: 16 }} adjustsFontSizeToFit>
          Some longer text that doesn't fit if displayed in one line (adjust, unlimited height)
        </Text>
      </View>

      <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}>
        <Text style={{ fontSize: 16 }} numberOfLines={1}>
          Some longer text that doesn't fit if displayed in one line (no adjust, 1 line)
        </Text>
      </View>

      <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}>
        <Text style={{ fontSize: 16 }} adjustsFontSizeToFit numberOfLines={1}>
        Some longer text that doesn't fit if displayed in one line (adjust, 1 line)
        </Text>
      </View>

      <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}>
        <Text style={{ fontSize: 16 }}>
          Even longer text that doesn't even fit if it has as much as two entire lines for itself, what a darn shame (no adjust, unlimited height)
        </Text>
      </View>

      <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}>
        <Text style={{ fontSize: 16 }} adjustsFontSizeToFit>
          Even longer text that doesn't even fit if it has as much as two entire lines for itself, what a darn shame (adjust, unlimited height)
        </Text>
      </View>

      <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}>
        <Text style={{ fontSize: 16 }} numberOfLines={2}>
          Even longer text that doesn't even fit if it has as much as two entire lines for itself, what a darn shame (no adjust, 2 lines)
        </Text>
      </View>

      <View style={{margin: 4, borderWidth: 1, borderColor: 'black'}}>
        <Text style={{ fontSize: 16 }} numberOfLines={2} adjustsFontSizeToFit>
          Even longer text that doesn't even fit if it has as much as two entire lines for itself, what a darn shame (adjust, 2 lines)
        </Text>
      </View>
    </SafeAreaView>
  );
}
```

</details>

|Old arch|New arch (without this PR)|New arch (with this PR)|
|-|-|-|
|<img width="447" alt="a_old" src="https://github.com/facebook/react-native/assets/21055725/4822f7f1-a19c-4225-9318-0eb2fec6f925">|<img width="447" alt="a_new_no_change" src="https://github.com/facebook/react-native/assets/21055725/ff594673-b362-4a81-8837-624cb1061d28">|<img width="447" alt="a_new_changed" src="https://github.com/facebook/react-native/assets/21055725/1f29c01c-1c91-4c9f-9edd-0950338b5d39">|

Reviewed By: NickGerleman

Differential Revision: D56362020

Pulled By: cortinico

fbshipit-source-id: 2aecbe66043870cf14536850ecbfb7c3890acd72
2024-04-22 04:13:36 -07:00
Arushi Kesarwani 73b4d67a78 Delete deprecated JSIModule methods (#42115)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42115

React Native Android had a concept called JSIModules, which iOS doesn't have. The JSIModule concept was introduced in the early stages of the Fabric project to represent modules that interact with JS through JSI and they are not NativeModules.

In the new architecture this concept is not really necessary and these interfaces were only used to initialize and destroy the Fabric renderer and TurboModule Manager in react native core. Bridgeless mode doesn’t use JSIModule anymore. Also, it has an explicit list of supported JSI module types, so is not open for extension.
In order to simplify RN concepts and reduce confusion with TurboModules, which also "use JSI", deleting everything related to JSIModule. This was already deprecated in 0.74.0.

Please use ReactInstanceEventListener to subscribe for react instance events instead of getJSIModule() and we recommend using TurboModules instead of JSIModules.

Changelog:
[General][Breaking] Delete JSIModule

Reviewed By: javache, cortinico

Differential Revision: D49597702

fbshipit-source-id: bc2bc190aafaf559336b341b50ffabf413474105
2024-04-19 11:54:36 -07:00
Arushi Kesarwani ac3261ff60 Add ReactSoftException in ReactHostImpl only when onActivityResult, onNewIntent and onWindowFocusChange do not have the context (#44155)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44155

Add ReactSoftException in ReactHostImpl only when `onActivityResult`, `onNewIntent`and `onWindowFocusChange` do not have the context

Changelog:
[Android][Fixed] ReactSoftExceptions in ReactHostImpl only when Context is null

Reviewed By: cortinico

Differential Revision: D56325407

fbshipit-source-id: a9f8fd5772fc05d39e72236fb8edfe5f8a9d6a43
2024-04-19 11:54:24 -07:00
Samuel Susla cf75d032d0 disable event loop (#44169)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44169

## Changelog:
[General][Changed] Disable new event loop behavior when bridgeless (new architecture) is enabled.

# What is the problem
With event loop, specifically with `batchRenderingUpdatesInEventLoop`, prop change is not delivered to Android mounting layer if the prop change was initiated from state update inside of `useLayoutEffect`, `componentDidMount` or `componentDidUpdate`.  Note this has to be a prop change affecting mounting layer directly, not something consumed by Yoga, e.g. background colour or border colour.

This affects android only.

Minimal repro :
```
import React, {useLayoutEffect, useState} from 'react';
import {Button, SafeAreaView, View} from 'react-native';
function Foo() {
  const [bgColor, setBgColor] = React.useState('red');
  useLayoutEffect(() => {
    console.log('useLayoutEffect');
    setBgColor('blue');
  }, []);
  return (
    <View
      style={{
        backgroundColor: bgColor,
        width: '100%',
        height: '100%',
      }}
    />
  );
}
function RNTesterApp() {
  const [show, setShow] = useState(false);
  return (
    <SafeAreaView>
      <Button title="Toggle" onPress={() => setShow(!show)} />
      {show && <Foo />}
    </SafeAreaView>
  );
}
export default RNTesterApp;
```

# The underlaying problem
The problem is in batched rendering updates and how props are delivered to Android mounting layer.

Here is a step by step what happens in the repro above:
1. React issues asks Fabric to create new shadow node A with background colour **red**.
2. Fabric asks Android to allocate a view for shadow node A with background colour **red**.
3. React commits tree **T1** and calls layout effects. Meanwhile Fabric waits, without trying to mount the tree **T1**, to prevent painting state that is about to be updated and prevent flickering.
4. React clones node A, changing the background colour to **blue** and commits the new tree **T2**.
5. Fabric, will now go ahead and mount the latest tree **T2**. While creating mount instructions, it will drop prop updates because it believes prop updates where delivered already as part of step 2.

At first this might appear as a problem with view preallocation. But the underlaying trouble is that on Android, we currently have no way of knowing how to combine changesets from React into single folly::dynamic.

Reviewed By: javache, cortinico

Differential Revision: D56355863

fbshipit-source-id: f8616ee48e10fc10e129bb632c5d398842220d24
2024-04-19 11:02:54 -07:00
Jane Li 727c4040b8 Back out "Use ClassFinder inside ViewManagerPropertyUpdater" (#44152)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44152

We're seeing an increase of crashes on Twilight (https://www.internalfb.com/logview/twilight_android_crashes/d25ec89876821abdd07f98d08a729f7c?trace_tab=0&ds=%7B%22start%22%3A%22-2%20weeks%22%2C%22end%22%3A%22now%22%7D) related to setting fontWeight with Double instead of String.

Original commit changeset: a67195e98377

Original Phabricator Diff: D56191175

Changelog:
[Internal] [Changed] - Revert use ClassFinder inside ViewManagerPropertyUpdater

Reviewed By: cortinico

Differential Revision: D56311183

fbshipit-source-id: e3407ff4858f00f8dadb882221e64a2631105597
2024-04-18 18:02:55 -07:00
Alan Lee c631e93341 Remove UIManager.{show|dismiss}PopupMenu (#44096)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44096

These Android only APIs have been deprecated and are being removed for 0.75 release.

Changelog:
[Android][Removed] - UIManager.showPopupMenu() and UIManager.dismissPopupMenu() have been removed

Reviewed By: RSNara

Differential Revision: D56041827

fbshipit-source-id: e2afebf55860f33d2c8d1887e865adb4dd555e6c
2024-04-18 13:52:21 -07:00
Jane Li b580a071ca Fix logic for mKeepActivity (#44139)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44139

I added logic to make useEffect() work w/ fragment-based nav, but I mixed up some logic. Fixed it here
Changelog: [Internal]

Differential Revision: D56264138

fbshipit-source-id: b551f0cb93cb4a0291733edbd341d3508b61e392
2024-04-17 20:17:47 -07:00
Intl Scheduler 72e262eb5b translation auto-update for i18n/oculus-mirage.config.json on master
Summary:
Chronos Job Instance ID: 1125907948552357
Sandcastle Job Instance ID: 9007200506994282
allow-large-files
ignore-conflict-markers
opt-out-review

Differential Revision: D56284224

fbshipit-source-id: 9e91ccd825f78960dc0e09ff923867f544f7883d
2024-04-17 20:16:15 -07:00
Soe Lynn 41a14962fc Expose Gap Percentage to ReactNative (#44129)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44129

X-link: https://github.com/facebook/litho/pull/983

X-link: https://github.com/facebook/yoga/pull/1647

Expose the Gap Percent from Yoga to RN Layer

Changelog:
[Android][Breaking] Enable flex gap percentage value for RN.

Reviewed By: NickGerleman

Differential Revision: D56160597

fbshipit-source-id: 34c05d39a03cf013f279a2cf9eb9762772ee11de
2024-04-17 17:24:00 -07:00
Arushi Kesarwani 4595351310 Remove getJavaScriptContextHolder() from BridgelessReactContext (#44124)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44124

This API was introduced as part of Backwards Compat effort recently but now this backwards comptability is supported through BridgelessCatalystInstance. The major OSS usages are through Catalyst Instance and not through Bridgeless React Context which is why deleting this makes sense so that people do not start depending on this.

Changelog:
[Android][Removed] - Remove getJavaScriptContextHolder() from BridgelessReactContext since now it can be accessed through BridgelessCatalystInstance in Bridgeless mode

Reviewed By: RSNara

Differential Revision: D56205699

fbshipit-source-id: 175463e17c526359c2e04fec4b2104aea3949d5d
2024-04-17 09:53:35 -07:00
Arushi Kesarwani f7b9aafd10 Remove getRuntimeExecutor() from ReactContext (#44102)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44102

Remove `getRuntimeExecutor()` from ReactContext since now it can be accessed through BridgelessCatalystInstance.getRuntimeExecutor() directly

Changelog:
[Android][Removed] - Remove getRuntimeExecutor() from ReactContext since now it can be accessed through BridgelessCatalystInstance in Bridgeless mode

Reviewed By: RSNara

Differential Revision: D56151365

fbshipit-source-id: 42bb6a6a3d729339cfb83ffdd3f7cbec314b687a
2024-04-17 09:53:35 -07:00
Jakub Piasecki 747a96b7b3 Add implementation of adjustsFontSizeToFit on the new architecture on Android (#44075)
Summary:
`adjustsFontSizeToFit` prop is exposed on both platforms but is missing implementation on the new arch on Android. This Pr adds it.

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

## Changelog:

[ANDROID] [FIXED] - Fixed `adjustsFontSizeToFit`  not working on Android when using the new architecture

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

Test Plan:
Tested on the RN Tester app using the `AdjustingFontSize` test:

| Old architecture | New architecture |
|------------------|------------------|
| <video src="https://github.com/facebook/react-native/assets/21055725/9243317c-1917-4ddb-9b8a-e9e99638409d">           | <video src="https://github.com/facebook/react-native/assets/21055725/39a7a9f2-21e4-4ba7-9ceb-dfec4ca6f643">         |

Reviewed By: javache

Differential Revision: D56134348

Pulled By: cortinico

fbshipit-source-id: b8339e3bec08e307abb0c6e4bd3f5fe143303014
2024-04-17 08:57:41 -07:00