Commit Graph

38536 Commits

Author SHA1 Message Date
Rubén Norte c0f3e64070 Follow naming convention for NativeFantom module (#48368)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48368

Changelog: [internal]

Just a minor rename to align with the existing convention.

Reviewed By: javache

Differential Revision: D67549203

fbshipit-source-id: faa9e34cdce7c59e2c6b3f7e697c90df103699d0
2025-01-03 04:57:43 -08:00
Alex Hunt 3e0fc8899b Remove hermes-inspector-msggen (#48465)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48465

Removes the `packages/hermes-inspector-msggen` workspace. Since https://github.com/facebook/react-native/pull/39300, this is no longer referenced in React Native, and is now part of the Hermes repo.

Changelog: [Internal]

Reviewed By: cortinico, hoxyq

Differential Revision: D67791612

fbshipit-source-id: 73da135b264d8df632fefe87cc4e3101075ae98c
2025-01-03 04:29:09 -08:00
Rubén Norte f20486cc77 Improve error messages in expect().toThrow(message) (#48430)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48430

Changelog: [internal]

This expectation currently prints a very generic message that is hard to parse, so this change improves it a bit to account for more cases. E.g.:
* Before: "Expected <function> to throw"
* After: "Expected <function> to throw with message 'foo', but threw with message 'bar'"

Reviewed By: rshest

Differential Revision: D67738146

fbshipit-source-id: 690f15971cec0e8a7b038eeacc9302c9f3edc323
2025-01-03 02:16:38 -08:00
Mateo Guzmán 7e029b0dcf Modal: FLAG_SECURE not respected in modal dialog (#48317)
Summary:
Fixes https://github.com/facebook/react-native/issues/38537

Setting `WindowManager.LayoutParams.FLAG_SECURE` in the window flags is not respected in the Android Modal component, causing security issues with screenshots or screen recordings as the content in the modal is visible. The flag works correctly in the rest of the components, see the videos in the linked issue.

This PR addresses that by checking whether this flag is set in the current activity and then setting it in the dialog when creating a new one in the `ReactModalHostView`.

## Changelog:

[ANDROID][FIXED] - `FLAG_SECURE` not respected in Modal dialog

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

Test Plan:
To test this, you need a physical device as with the emulator the flags don't seem to be respected either.

The easiest way to test this in code is by setting the flags in the main activity. You can do so by adding this code snippet:

<details>
<summary>onCreate in RNTesterApplication.kt</summary>

```kt
override fun onCreate() {
    ReactFontManager.getInstance().addCustomFont(this, "Rubik", R.font.rubik)
    super.onCreate()

    ...

    registerActivityLifecycleCallbacks(
            object : ActivityLifecycleCallbacks {
              override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
                activity.window.setFlags(
                        WindowManager.LayoutParams.FLAG_SECURE,
                        WindowManager.LayoutParams.FLAG_SECURE
                )
              }

              override fun onActivityStarted(activity: Activity) {}
              override fun onActivityResumed(activity: Activity) {}
              override fun onActivityPaused(activity: Activity) {}
              override fun onActivityStopped(activity: Activity) {}
              override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
              override fun onActivityDestroyed(activity: Activity) {}
            }
    )
  }
```
</details>

Then, you can render a simple modal component:

<details>
<summary>RNTesterPlayground.js</summary>

```tsx
function Playground() {
  const [modalVisible, setModalVisible] = React.useState(false);

  return (
    <>
      <Modal
        visible={modalVisible}
        testID="playground-modal">
        <Text testID="inner-text-test-id">Hello World!</Text>
        <Button title="Close Modal" onPress={() => setModalVisible(false)} />
      </Modal>

      <Button
        title="Open Modal"
        onPress={() => {
          setModalVisible(true);
        }}
      />
    </>
  );
}
```
</details>

You can then try to record the screen or take screenshots. You will notice that before opening the modal, you won't be able to see anything in the recording, but when opening the modal, the content is visible.

I've tried my best to record the before and after the fix, but as the screen recordings will mostly show a black screen, you have to forward a bit in both videos to see the difference.

<details>
<summary>Before the fix (notice the blank screen and then content visible)</summary>

https://github.com/user-attachments/assets/fc5bbe26-d238-425b-90d3-0e43c89ccaac

</details>

<details>
<summary>After the fix (notice all the screen recording is a black screen)</summary>

https://github.com/user-attachments/assets/0d6991a0-974b-45c5-8f4a-bf4718c284e6

</details>

Reviewed By: cipolleschi

Differential Revision: D67368741

Pulled By: alanleedev

fbshipit-source-id: 9f31063a9208a6df257da424bf3096bf15a5ddcb
2025-01-02 20:40:09 -08:00
Blake Friedman 3a7aed6ed8 Follow-ups to issues earlier in the stack (#48455)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48455

This is a followup to earlier issues in the stack.

Two fixes here:
1. Make the paths more consistent esp. from the config, so everything is working out of react-native-github.
2. Just declare `__cpluscplus`, as we don't seem to care about the value in our code.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D67716883

fbshipit-source-id: 359c33210d6b66bb0d75724a177587a7d5f837b2
2025-01-02 15:58:04 -08:00
Blake Friedman 27ef13174c Add simple Objective-C/CPP api tracking (#48449)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48449

This is the simplest possible way to track changes to our public CPP / Objective-C API.

This is going to be really noisy, and there's a good chance it's not complete.

The tooling is also incomplete, as it just runs the preprocessor (then does some funky work to undo noise generated by the preprocessor).  If we want more control over this, we're going to have to jump into the guts of each of our build targets (and tooling) OR more clearer layout the repo to separate public and private header files to our users.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D67713408

fbshipit-source-id: 9578179bbc4d9be2f07d040b01f8a3ef105d7034
2025-01-02 15:58:04 -08:00
Joe Vilches 1b88c5b429 Fix case when dashed/dotted borders do not work with overflow: hidden (#48414)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48414

Was looking into https://github.com/facebook/react-native/issues/48078 which was brought to my attention due to my recent refactorings of iOS Views, especially around how overflow: hidden works. This bug was not brought on by my changes but seems to be a lingering Fabric bug (iirc this bool was not changed when I refactored things)

Anyway, dotted/dashed borders did not work with overflow: hidden. The reason why is we use core animation borders in this case which is incorrect as CA cannot do these types of borders. So I added a check to make sure that the borders are solid as well if we want to use CA to draw them.

Changelog: [iOS] [Fixed] - Dashed & dotted borders now work with overflow: hidden

Reviewed By: mdvacca

Differential Revision: D67720492

fbshipit-source-id: 5aecc15f2d7cbd71952d78d6972f6fc6b7a93ea8
2025-01-02 14:03:26 -08:00
Ruslan Shestopalyuk febf6f4a9c Convert TouchesHelper.java (#48447)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48447

# Changelog:
[Internal] -

As in the title.

Reviewed By: tdn120

Differential Revision: D67760245

fbshipit-source-id: 5054408438de7cbdfaa7c98d9f5935f03ee93760
2025-01-02 13:59:54 -08:00
Eli White 9e0a7e3263 Converge component's bespoke StringEnumTypeAnnotation into StringLiteralUnionTypeAnnotation (#48343)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48343

components store unions as 'StringEnumTypeAnnotation' even though it isn't actually a union, it's a literal.

Native Modules store these as 'StringLiteralTypeAnnotation' so this converges those and reuses the same types.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D67427656

fbshipit-source-id: e39028114285588584596012d07db40c117b4b94
2025-01-02 13:20:02 -08:00
Eli White b691122afc Share ArrayTypeAnnotation between components and modules (#48318)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48318

These structures were the same, but the component side didn't use generics and just had duplicates. Making a base one to be shared.

I need to follow up to this and constrain the types that components allow.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D67371894

fbshipit-source-id: bb1a30fcd0efe6cc567b88bc6f11e7b385bd7c41
2025-01-02 13:20:02 -08:00
Alex Hunt 697e9462d5 Convert assets-registry to Flow comment syntax (#48458)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48458

NOTE: This change is made once and is not guaranteed.

**Motivation**: Requiring Flow parsing for `react-native` and its dependencies in user space can involve friction. For the case of `react-native/assets-registry` → `react-native-web`, I believe we should do the pragmatic thing to relax this requirement.

- This is a convenience stopgap until https://github.com/facebook/react-native/pull/39542 can be stabilised.
- This package is tiny and infrequently modified — I believe it's pragmatic/safe to do a one-time conversion, with the above notice and no changelog (i.e. "experimental" for now).

Resolves https://github.com/facebook/react-native/issues/48349.

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D67764460

fbshipit-source-id: 7687fd79c6dea73c234a46e475c1cc745225830b
2025-01-02 12:23:14 -08:00
Ruslan Shestopalyuk 5ef9e1fffe TouchEventCoalescingKeyHelper -> Kotlin (#48448)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48448

# Changelog:
[Internal] -

As in the title.

Reviewed By: tdn120

Differential Revision: D67759862

fbshipit-source-id: 7a8e133962cdc43aed0bae38a89d37fb7e6031a6
2025-01-02 11:18:07 -08:00
Ruslan Shestopalyuk e8347b9854 Migrate EventCategoryDef to Kotlin (#48446)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48446

# Changelog:
[Internal] -

As in the title.

Reviewed By: tdn120

Differential Revision: D67759756

fbshipit-source-id: bc922b3062d8790ada3f9d5ee71593a08046752b
2025-01-02 11:18:07 -08:00
Alex Hunt 79c7c58656 Document monorepo build setup (#48420)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48420

Adds a long overdue README for our newer monorepo build setup.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D67740763

fbshipit-source-id: 0c7686d75272acf74c0af5a1c4c08336fb45e2a2
2025-01-02 10:33:34 -08:00
Riccardo Cipolleschi 2c338a719e Build Release version for RNTester to speed-up E2E (#48443)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48443

This change makes sure we build the Release variant of RNTester so we can store the generated app as an artifact and forward it to the E2E tests.

## Context

While looking at the recent failures of the E2E tests, I realized that the Hermes, NewArch, Debug variant often fails to build, not to test, for some misconfiguration.

I also realized that we are already building that varaint successfully once, so why not reuse it? To reuse prebuilds, we need a few steps:

1. make sure we build all the variants we need
2. store the .app file as an artifact
3. download the artifact and use it in the E2E tests

## Changelog:
[Internal] - Build release variant for RNTester

Reviewed By: cortinico

Differential Revision: D67760372

fbshipit-source-id: 02cc9ec64d5a7b4fa2ad05bca6aa91a69b2b5907
2025-01-02 09:52:22 -08:00
Alex Hunt 430f7d8b72 Update debugger-frontend from 486803f...7727db8 (#48328)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48328

NOTE: This update is significant, as it includes the frontend repo sync with `chromium/6613` (https://github.com/facebookexperimental/rn-chrome-devtools-frontend/pull/144).

Changelog: [Internal] - Update `react-native/debugger-frontend` from 486803f...7727db8

Resyncs `react-native/debugger-frontend` from GitHub - see `rn-chrome-devtools-frontend` [changelog](https://github.com/facebookexperimental/rn-chrome-devtools-frontend/compare/486803f6bf272e0629297265dee8048a2f1269dd...7727db85ac767cf41cce3e9ee54d27e97b2637f9).

Reviewed By: hoxyq

Differential Revision: D67402065

fbshipit-source-id: f32d328c5319ed25d8942e813db152921ca22ec8
2025-01-02 06:01:42 -08:00
Riccardo Cipolleschi 93117ea1b8 Move E2E scripts to js (#48419)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48419

This change moves the E2E scripts for iOS to a JS script.
This should make it much easier to modify the code in case we need to change it.

## Changelog
[Internal] - Move e2e script from bash to JS

Reviewed By: cortinico

Differential Revision: D67737950

fbshipit-source-id: d0b0411c8a4d688c10e460e70b11dbfc83aaa135
2024-12-31 09:21:18 -08:00
zhongwuzw 09995fc874 Change Image load event size info from logical size to pixel (#45198)
Summary:
Fixes https://github.com/facebook/react-native/issues/45188. This fixes old arch. fabric fix may wait until https://github.com/facebook/react-native/issues/44918.

## Changelog:

[IOS] [BREAKING] - Change Image load event size info from logical size to pixel

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

Test Plan:
Android/iOS return the same size .
```
    <Image
      style={{width: '100%', height: '100%'}}
      source={{
        uri: 'https://image-placeholder.com/images/actual-size/75x75.png',
      }}
      resizeMode={'cover'}
      onLoad={e => {
        console.log(
          `RNImage:${Platform.OS} load JPEG image from url`,
          e.nativeEvent,
        );
      }}
    />
```

Reviewed By: cortinico

Differential Revision: D67735347

Pulled By: cipolleschi

fbshipit-source-id: 72422d8c15e4cc6313215bf6d9a2c1e6b5a235ad
2024-12-31 09:03:54 -08:00
Nicola Corti b10491a3c4 Fix RN-Tester JSC instacrashing (#48418)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48418

RNTester JSC Debug is currently insta-crashing on the 0.77 release branch due to:

```
12-31 10:59:36.388 15165 15204 E ReactNativeJS: React Native version mismatch.
12-31 10:59:36.388 15165 15204 E ReactNativeJS:
12-31 10:59:36.388 15165 15204 E ReactNativeJS: JavaScript version: 0.77.0-rc.5
12-31 10:59:36.388 15165 15204 E ReactNativeJS: Native version: 1000.0.0-bb9d7ad9a
12-31 10:59:36.388 15165 15204 E ReactNativeJS:
12-31 10:59:36.388 15165 15204 E ReactNativeJS: Make sure that you have rebuilt the native code. If the problem persists try clearing the Watchman and packager caches with `watchman watch-del-all && npx react-native start --reset-cache`.
```

This is causing a `console.error` that is resulting in the crash as one of the frame in the stack doesn't have the line/column number information. Calling `.putDouble(string,double)` is forcing a conversion from `null` -> `double` which is result in the crash.

This is happening only on CI because the `set-rn-version` step on GitHub Action is executed with `--dry-run` (as this is not a release run) so the version of React Native is set back to `1000.0.0-<SHA>`. Locally this doesn't happen because the React Native version is read from the local file which is never manipulated by the `set-rn-version`.

Changelog:

[ANDROID] [FIXED] - Fix JSC Debug instacrashing

Reviewed By: cipolleschi

Differential Revision: D67735962

fbshipit-source-id: 363218385277374d33b8313cacd14159b2f17106
2024-12-31 08:24:38 -08:00
TobiasH 920867d949 Fix useWindowDimensions not updating because of delayed applicationState update on iOS devices (#46353)
Summary:
### Issue
When a real device is oriented into landscape and the user locks the screen during said orientation incase the user rotates back to previous orientation and unlocks the screen `useWindowDimensions` will not get the correctly updated values. This is due to `applicationState` being equal to UIApplicationStateInactive still when `interfaceFrameDidChange` gets called.

### Fix
`didUpdateDimensions` on iOS. Now correctly emits the dimension values after the device has been oriented and device has been locked. By adding `UIDeviceOrientationDidChangeNotification` to `NSNotificationCenter`

## Changelog:
[IOS] [FIXED] - Emit didUpdateDimensions correctly

```
  // RCTDeviceInfo.mm

  // Adds the interfaceFrameDidChange to UIDeviceOrientationDidChangeNotification
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:selector(interfaceFrameDidChange)
                                               name:UIDeviceOrientationDidChangeNotification
                                             object:nil];
```

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

Test Plan:
### ***Note***: This doesn't seem to be replicable on simulators. It only happens on real iOS devices.

### Before change:

Rotate Device > Lock Screen > Rotate back to portrait > Unlock phone
![IMG_6089](https://github.com/user-attachments/assets/5d928613-2742-45fb-97fa-d87eaf64ea97)

### After change:

Same steps as above, now emits correct values
![IMG_6091](https://github.com/user-attachments/assets/eb46ed22-c3c5-4e77-8069-4a604a21947e)

Reviewed By: cortinico

Differential Revision: D67735523

Pulled By: cipolleschi

fbshipit-source-id: 146e5d62d55eeef0f6b17f962ca84ab418a7b7f0
2024-12-31 07:49:36 -08:00
Oskar Kwaśniewski 081be01a5d feat: implement ReactNativeFactory (#46298)
Summary:
This PR implements ReactNativeFactory to encapsulate further the logic of creating an instance of React Native for iOS.

This will remove the strong coupling on the RCTAppDelegate and allow us to support Scene Delegate in the future.

The goal is to have a following API:

```objc
self.reactNativeFactory = [[RCTReactNativeFactory alloc] initWithDelegate:self];

UIView *rootView = [self.reactNativeFactory.rootViewFactory viewWithModuleName:self.moduleName
                                                               initialProperties:self.initialProps
                                                                   launchOptions:launchOptions];

// Standard iOS stuff here
```

## Changelog:

[IOS] [ADDED] - implement ReactNativeFactory

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

Test Plan: Test out all the methods of AppDelegate

Reviewed By: huntie

Differential Revision: D67451403

Pulled By: cipolleschi

fbshipit-source-id: 9e73cd996ffc27ca1e3e058b45fc899b1637bdba
2024-12-31 07:45:25 -08:00
timbocole 8b1f049879 fix: Prioritise local cpp (use default as fallback) (#48340)
Summary:
https://github.com/facebook/react-native/pull/47379 removed local cpp sources from the sources being built with the app. This resulted in a local `android/app/src/main/jni/OnLoad.cpp` file being ignored at build time. I have therefore added logic to the cmake file to prioritise local `cpp` files and fallback to `${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp` if none exist.

This resolves https://github.com/facebook/react-native/issues/48298

## Changelog:
[ANDROID] [FIXED] - Prioritise local OnLoad.cpp, falling back to default-app-setup

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

Test Plan:
- Followed the https://reactnative.dev/docs/the-new-architecture/pure-cxx-modules guide (which was broken > 0.76.1)
- Applied the patch to the reproduction repository linked to https://github.com/facebook/react-native/issues/47352 to ensure no regression

Reviewed By: cipolleschi

Differential Revision: D67736012

Pulled By: cortinico

fbshipit-source-id: 87f6b8edf1613682585a94e1d1b3e6b4b792e4f5
2024-12-31 05:30:26 -08:00
Peter Abbondanzo a3c8e21370 Enable vector drawable support by default (#48347)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48347

Vector drawable support was added behind a feature flag in https://github.com/facebook/react-native/pull/45354 and is ready to release more widely. This change is effectively the same as removing the feature flag but allows our holdout to continue until mid-January.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D67482531

fbshipit-source-id: 1733c4748f79fd4df72f531a24efcbd8a7822611
2024-12-30 14:32:55 -08:00
Ruslan Shestopalyuk 6dd4195d2d Avoid calling fmod twice in roundLayoutResultsToPixelGrid (#48404)
Summary:
X-link: https://github.com/facebook/litho/pull/1036

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

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

## Changelog:
[Internal] -

This popped up when profiling some heavy UI performance, calling `fmod` operation in Yoga's `roundLayoutResultsToPixelGrid` in `PixelGrid.cpp` can be expensive, furthermore it turns out that some of the calls were redundant.

This replaces the duplicate calls to fmod with an equivalent single round operation, which for e.g. clang compiler on Windows brings the code in question from ~50 instructions (including 4 call instructions to the fmod function) down to ~30 instructions (without any external calls), and the layout operation being **~1% more efficient** for the particular benchmark I was looking into.

Reviewed By: christophpurrer

Differential Revision: D67689065

fbshipit-source-id: 2a074a1cb81bd7f7a3c414050b9ddda2ba90180f
2024-12-30 12:38:48 -08:00
Rob Hogan 7e665d4c70 Add Changelog for 0.77.0-rc.5 (#48413)
Summary:
Changelog for 0.77.0-rc.5

## Changelog:

[Internal] Changelog for 0.77.0-rc.5

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

Test Plan: N/A

Reviewed By: christophpurrer

Differential Revision: D67718909

Pulled By: robhogan

fbshipit-source-id: df2407ec7911e01f91a340c14517f8af2dc63a21
2024-12-30 11:03:15 -08:00
Ruslan Shestopalyuk dd1cfb70e9 Improve typing of BackHandler (#48411)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48411

## Changelog:
[Internal] -

Floow-up to https://github.com/facebook/react-native/pull/48388, based on the diff discussion (D67648077).

Adds a bit better typing to `BackHandler.js`.

Reviewed By: blakef

Differential Revision: D67713236

fbshipit-source-id: 95435898d8ea87f6ae32a6db859d6641e1264972
2024-12-30 06:17:39 -08:00
Maddie Lord 85bdd75828 Add "jsEngine: hermes" to JS runtime Error prototype (#48401)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48401

This change adds a flag to JS Error's prototype to specify the jsEngine.

Reviewed By: fkgozali

Differential Revision: D67665484

fbshipit-source-id: 64b7b4bd986bcbd45d58e70c1a16de6752b05ccd
2024-12-27 16:59:49 -08:00
Riccardo Cipolleschi 9ceabd341d Fix iOS E2E Tests (#48400)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48400

A couple of days ago, the iOS CI started failing for the E2E tests on main.
This is because We were not using the hermes artifacts we were preconfiguring.

In fact, this is the log of the `test_e2e_ios_rntester`, which is not using the prebuilt.
{F1974129000}

For comparison, this is the `test_ios_rntester`, which is using the prebuilt
{F1974129001}

While investigating why this was happening, I realized that we were not testing the old architecture anymore, because we forget to update the script after the release of the New Architecture.

This change should fix both.

## Changelog:
[Internal] - Fix E2E tests for iOS and test the Old Arch

Reviewed By: robhogan

Differential Revision: D67670976

fbshipit-source-id: 7d1383a89e06c138f437a9c5f876a2e900878fb0
2024-12-27 07:38:47 -08:00
BleemIs42 44705fe11b - Fix BackHandle callback undefined cause crash issue (#48388)
Summary:
### Error message:
we got an error
```
t[n] is not a function. (In 't[n]()', 't[n]' is undefined) \n <unknown> (index.bundle:317:168:317)
```
 it related the BackHandle execute handle function.

### Investigation result
our project has screen files`App.tsx`, `Dashboard.tsx`, and `Profile.tsx`.
When launching the app, the screen order is `App.tsx` -> `Dashboard.tsx`, then user can switch to `Profile.tsx`
For `App.tsx` and `Dashboard.tsx`, we just prevent the hardware button action use `usePreventHardwareBackPressEffect()` in the first line of screen code.
```js
export const useHardwareBackPressEffect = (goBack?: () => boolean): void => {
  useEffect(() => {
    if (goBack) {
      BackHandler.addEventListener("hardwareBackPress", goBack);
      return () => {
        BackHandler.removeEventListener("hardwareBackPress", goBack);
      };
    }
    return undefined;
  }, [ goBack ]);
};
export const usePreventHardwareBackPressEffect = (): void => useHardwareBackPressEffect(() => true);
```
currently, `_backPressSubscriptions ` has 2 callback functions.
then user switch to `Profile.tsx` screen, and has the below code for hardwareback button and the second doesn't `return true`:
```js
// first one
usePreventHardwareBackPressEffect();
...

// second one
useEffect(() => {
  const backButtonListener = BackHandler.addEventListener(
    "hardwareBackPress",
    () => navigate(Navigation.Login);
  );
  return () => backButtonListener.remove();
});
```
currently, `_backPressSubscriptions ` has 4 callback functions, include previous 2 and new 2 of `Profile.tsx`.
When the user press hardwareback button, it will navigate to the login screen, so the issue occurs:
the latest callback will be executed first, then the navigation will let the screen unmount, which will destroy the effect, so the code removing 2 hardwareBackPress callback of `Profile.tsx` by executed
```js
return () => {
        BackHandler.removeEventListener("hardwareBackPress", goBack);
      };
```
After the navigation ends and the loop is restored, the init `i` is 3, then `i--`, `i` is 2, then `_backPressSubscriptions[2]` is `undefined` now and executes as a function, so the app crashes.
```js
for (let i = _backPressSubscriptions.length - 1; i >= 0; i--) {
    if (_backPressSubscriptions[i]()) {
      return;
    }
  }
```
that's the issue I met.

## Changelog:

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

Pick one each for the category and type tags:

[ANDROID] [FIXED] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[ANDROID] [FIXED] - Fix BackHandle callback undefined cause crash issue

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

Reviewed By: blakef

Differential Revision: D67648077

Pulled By: rshest

fbshipit-source-id: 5ca685b0c0c474ef11772fd803743968ec2d912e
2024-12-27 04:37:57 -08:00
zhongwuzw 8dfed7df4b RNTester: Fixes crash when app back to background (#48385)
Summary:
https://github.com/facebook/react-native/issues/48376 removed `applicationDidEnterBackground` from `RCTAppDelegate` but RNTester called it, leads to crash. cc cipolleschi can you please help to review?

## Changelog:

[INTERNAL] [FIXED] - RNTester: Fixes crash when app back to background

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

Test Plan: RNTester iOS back to background not crash.

Reviewed By: cipolleschi

Differential Revision: D67657449

Pulled By: philIip

fbshipit-source-id: e6d806b2677050fa2faa273a7468055d9d21c2a3
2024-12-27 04:16:25 -08:00
Ruslan Shestopalyuk fcf3c8cab7 Rename SystraceSection to TraceSection (#48383)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48383

## Changelog:
[Internal] -

This changes the name of `SystraceSection` class to `TraceSection`, the purpose being to make it Systrace/FBSystrace agnostic (and that it can be mapped to e.g. Perfetto instead).

It changes all the internal callsites to the RN code code, and also adds a shim include, `<cxxreact/SystraceSection.h`, for backward compatibility with the external callers for now (which will be addressed separately).

Reviewed By: javache

Differential Revision: D67621914

fbshipit-source-id: 337c63c45a7b075c6e00cfca67ecc06c298c94c0
2024-12-24 16:31:50 -08:00
Riccardo Cipolleschi 4a667e1a50 Set timeout for E2E tests. (#48381)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48381

Right now, the E2E tests for RNTester does not have a timeout.
It can happen that the emulator get stuck and the action times out.

The default timeout is 6 hours, which is definitely too much and wasteful, so let's reduce it to 1 hour.

{F1974112110}

## Changelog:
[Internal] - Set timeout for E2E tests to 1 hour

Reviewed By: robhogan, blakef

Differential Revision: D67620423

fbshipit-source-id: c507d1222fca49287fafe6da4bffe559d8687b99
2024-12-24 08:15:22 -08:00
Ruslan Shestopalyuk 17a644a230 Map SystraceSection to Perfetto instrumentation if the latter is enabled (#48379)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48379

## Changelog:
[Internal] -

We have a good portion of RN core code already instrumented with `SystraceSection` blocks, and those do the timing via fbsystrace, which may or may not be enabled in the system and generally is obsolete.

This maps the blocks to the corresponding Perfetto instrumentation, in case the latter is enabled, which will allow to get this information in Perfetto sessions without need to have fbsystrace present.

Reviewed By: javache

Differential Revision: D67619443

fbshipit-source-id: 52e5666472ad118fbec176a0e82d72a5200a358a
2024-12-24 07:47:50 -08:00
Gaspard Viot 74bdab8bd8 Reduce memory allocations when computing accessibilityLabel (#44605)
Summary:
While investigating the root cause of app hanging on older devices in Instruments, I noticed that the heaviest stack trace was pointing to `RCTRecursiveAccessibilityLabel` in RCTView.m.

<details>
  <summary>Heaviest stack trace in Instruments</summary>
<img width="473" alt="Screenshot 2024-05-17 at 4 22 48 PM" src="https://github.com/facebook/react-native/assets/849905/fab8ed01-7a2f-4113-b2ca-04e76f25cd9d">
</details>

The profiling was done on an iPad (5th generation) running iOS 16.7.4. The app is text heavy which makes the issue more visible than in RNTester for instance.

### Before
<img width="854" alt="Screenshot 2024-05-17 at 4 19 46 PM" src="https://github.com/facebook/react-native/assets/849905/5e3cc7ad-299c-4814-ab4a-031c0e677b12">

It turns out that `[NSMutableString stringWithString:@""]` is initialized in every call of the recursion even though most of the time it's only used to check the length at the end and return `nil`.

My change only initialize the mutable string if it's going to be used. I applied the same logic to the equivalent Fabric component. It's a small change that improved the accessibility label generation by 60ms in my case.

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

[IOS] [CHANGED] - Reduce memory allocations when computing accessibilityLabel

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

Test Plan:
Running the same measurements after the change, computing the accessibility label is not the heaviest stack trace anymore. And the line by line tracing shows that `[NSMutableString stringWithString:@""]` impact has been significantly reduced.

### After
<img width="769" alt="Screenshot 2024-05-17 at 4 53 04 PM" src="https://github.com/facebook/react-native/assets/849905/1ad638ac-ba7e-4dca-ac77-10df5d2dad49">

I have been using this change in production thanks to a patch-package and it effectively improved the performances when navigating between screens.

I also tested in RNTester with and without Fabric. For both architectures, I made sure the return value of `RCTRecursiveAccessibilityLabel`.

Interestingly, when there is no label, the Fabric implementation returns an empty string while the `RCTView.m` returns `nil`.

I'm open to align both implementations to return `nil` if you believe there is no underlying reason requiring the Fabric implementation to return an empty string.

Reviewed By: cipolleschi

Differential Revision: D67620818

Pulled By: javache

fbshipit-source-id: 1a6937075a5ff5a9ad03fbbf910d64b3884c0fe0
2024-12-24 07:42:33 -08:00
zhongwuzw 6d2b61691a Fabric: Fixes assert failure when surface stop before we start surface (#48213)
Summary:
Fixes https://github.com/facebook/react-native/issues/48149. Actually this issue is not caused by React 19. The underlying problem arises because we retain the surface in RCTHost at the time of its creation. Even though we call stop, there is a return check that prevents execution if the status is not running. For reference, you can view the relevant code here: [RCTFabricSurface.mm](https://github.com/facebook/react-native/blob/7d771de8a79b05e8dfed91e07de30d9f72d3c1c3/packages/react-native/React/Fabric/Surface/RCTFabricSurface.mm#L118).

To resolve this issue, we can implement a weak reference to the surface.

bt:
```
(lldb) bt
* thread https://github.com/facebook/react-native/issues/13, queue = 'com.apple.root.user-interactive-qos', stop reason = signal SIGABRT
    frame #0: 0x0000000105699008 libsystem_kernel.dylib`__pthread_kill + 8
    frame https://github.com/facebook/react-native/issues/1: 0x00000001045df408 libsystem_pthread.dylib`pthread_kill + 256
    frame https://github.com/facebook/react-native/issues/2: 0x000000018016c4ec libsystem_c.dylib`abort + 104
    frame https://github.com/facebook/react-native/issues/3: 0x000000018016b934 libsystem_c.dylib`__assert_rtn + 268
    frame https://github.com/facebook/react-native/issues/4: 0x000000010651f4b4 React_Fabric`facebook::react::SurfaceHandler::setUIManager(this=0x0000000108108620, uiManager=0x0000000000000000) const at SurfaceHandler.cpp:317:3
    frame https://github.com/facebook/react-native/issues/5: 0x00000001064c98f4 React_Fabric`facebook::react::Scheduler::unregisterSurface(this=0x0000600003500370, surfaceHandler=0x0000000108108620) const at Scheduler.cpp:252:18
    frame https://github.com/facebook/react-native/issues/6: 0x0000000104c3e8a8 RCTFabric`-[RCTScheduler unregisterSurface:](self=0x000060000212a940, _cmd="unregisterSurface:", surfaceHandler=0x0000000108108620) at RCTScheduler.mm:163:15
    frame https://github.com/facebook/react-native/issues/7: 0x0000000104c61fc4 RCTFabric`-[RCTSurfacePresenter unregisterSurface:](self=0x00000001081080d0, _cmd="unregisterSurface:", surface=0x0000000108108610) at RCTSurfacePresenter.mm:126:5
  * frame https://github.com/facebook/react-native/issues/8: 0x0000000104bc30a0 RCTFabric`-[RCTFabricSurface dealloc](self=0x0000000108108610, _cmd="dealloc") at RCTFabricSurface.mm:87:3
    frame https://github.com/facebook/react-native/issues/9: 0x0000000104b9ae44 RCTFabric`__destroy_helper_block_ea8_32s((null)=0x0000600000cb5a70) at RCTBoxShadow.mm:0
    frame https://github.com/facebook/react-native/issues/10: 0x00000001800f6edc libsystem_blocks.dylib`_call_dispose_helpers_excp + 44
    frame https://github.com/facebook/react-native/issues/11: 0x00000001800f7d24 libsystem_blocks.dylib`_Block_release + 300
    frame https://github.com/facebook/react-native/issues/12: 0x000000010760a7b8 libdispatch.dylib`_dispatch_client_callout + 16
    frame https://github.com/facebook/react-native/issues/13: 0x000000010761e608 libdispatch.dylib`_dispatch_root_queue_drain + 936
    frame https://github.com/facebook/react-native/issues/14: 0x000000010761ef7c libdispatch.dylib`_dispatch_worker_thread2 + 256
    frame https://github.com/facebook/react-native/issues/15: 0x00000001045dbb38 libsystem_pthread.dylib`_pthread_wqthread + 224
```

## Changelog:

[IOS] [FIXED] - Fabric: Fixes assert failure when surface stop before we start surface

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

Test Plan:
Please see demo in https://github.com/facebook/react-native/issues/48149. Or open RNTester and apply the patch like below:
```
 diff --git a/packages/rn-tester/RNTester/AppDelegate.mm b/packages/rn-tester/RNTester/AppDelegate.mm
index 64c5d4122e7..cf015458619 100644
 --- a/packages/rn-tester/RNTester/AppDelegate.mm
+++ b/packages/rn-tester/RNTester/AppDelegate.mm
@@ -50,7 +50,10 @@ static NSString *kBundlePath = @"js/RNTesterApp.ios";

   [[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];

-  return [super application:application didFinishLaunchingWithOptions:launchOptions];
+  [super application:application didFinishLaunchingWithOptions:launchOptions];
+  self.window.rootViewController = [UIViewController new];
+  [self.window makeKeyAndVisible];
+  return YES;
 }

 - (void)applicationDidEnterBackground:(UIApplication *)application

```

Reviewed By: javache

Differential Revision: D67335792

Pulled By: cipolleschi

fbshipit-source-id: e93aaaa60b3d204d7ed2cda6758b3b1d9dfcbc88
2024-12-24 07:41:51 -08:00
Alex Toudic adaceba546 Fix applicationDidEnterBackground not being called (#48376)
Summary:
I noticed that `AppDelegate` subscribers listening for `applicationDidEnterBackground` events in Expo projects (as documented [here](https://github.com/expo/expo/blob/238b6f57e459dd2c0b13ee158f0af709fe922460/docs/pages/modules/appdelegate-subscribers.mdx?plain=1#L56) aren't working as expected anymore.
While investigating, I discovered that the events aren't reaching the `ExpoAppDelegate` implementation ([source](https://github.com/expo/expo/blob/71f2c55ff3f11e43ab43761bb5cece2e48eae0bf/packages/expo-modules-core/ios/AppDelegates/ExpoAppDelegate.swift#L61)) because the `RCTAppDelegate` implementation of `applicationDidEnterBackground` interrupts the event chain. This appears to be affecting some legitimate use cases.
I believe we could improve this by removing the current implementation, but I'd love to hear your thoughts on this approach. I might be missing some context about why this implementation was originally needed, so any insights would be greatly appreciated!

## Changelog:

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

Pick one each for the category and type tags:

[IOS] [FIXED] - Fix applicationDidEnterBackground not being called

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[IOS] [FIXED] - Fix applicationDidEnterBackground not being called

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

Test Plan: Ran a local test after change

Reviewed By: javache

Differential Revision: D67621557

Pulled By: cipolleschi

fbshipit-source-id: 2d73711372deba867bd616c79ef4d00c79aa86d5
2024-12-24 06:56:55 -08:00
Mateo Guzmán 974fdf9a37 Migrating FpsListener to Kotlin (#48360)
Summary:
Migrating `FpsListener` to Kotlin

## Changelog:

[INTERNAL] - Migrating `FpsListener` to Kotlin

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

Test Plan:
```bash
yarn test-android
```

Reviewed By: bnalls33

Differential Revision: D67599802

Pulled By: Abbondanzo

fbshipit-source-id: 769dbe26688309ffcf15565c5d51003e23c56412
2024-12-23 15:51:14 -08:00
Ramanpreet Nara a5a3d372be Rename ParsedError to ProcessedError
Summary:
I think parsed isn't a good enough name.

React native also does a lot of processing of the error.

This also opens the door for eventually forwarding the original error in the future.

Changelog: [Internal]

Reviewed By: alanleedev

Differential Revision: D67526700

fbshipit-source-id: 895d64fa1ee4061ecbf0c1a6033c25b6fca95fd6
2024-12-23 12:42:14 -08:00
Rob Hogan 29e5de579c Add Changelog for 0.77.0-rc.4 (#48374)
Summary:
Add changelog for 0.77.0-rc.4

## Changelog:
[Internal]

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

Test Plan: N/A

Reviewed By: christophpurrer

Differential Revision: D67602257

Pulled By: robhogan

fbshipit-source-id: 79becf41cfad105e682d648f2f957f18bdbad5f6
2024-12-23 09:50:15 -08:00
Riccardo Cipolleschi e87296f356 Do not install jq as it is already installed (#48363)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48363

jq is already installed on M1 machines on GithubActions. There is no need to install it again and this is outputting a warning in CI:

{F1974100065}

## Changelog:
[Internal] - Do not install jq as it is already installed

Reviewed By: blakef

Differential Revision: D67599961

fbshipit-source-id: 1f621f796b0c67ec877fc35269137537618f47ae
2024-12-23 07:46:02 -08:00
Riccardo Cipolleschi 5b6534e727 Fix typo in configuration (#48364)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48364

The configuration to run E2E tests on maestro has a typo that was outputting a warning in CI:

{F1974100056}

## Changelog
[Internal] - Fix typo on E2E test configuration

Reviewed By: robhogan

Differential Revision: D67599849

fbshipit-source-id: 9504f821172782e188ff524176bc4c2ec48dea97
2024-12-23 07:46:02 -08:00
Riccardo Cipolleschi 27aa28b1f5 USe the debug APK instead of the release one (#48365)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48365

For a mistake, the local E2E test we use to test a release is still pointing to the release APK instead of using the debug apk.

This change fix that. The change has been manually applied to the release branches, for example [here](https://github.com/facebook/react-native/commit/385318bf6a83b124d9e8eb925932edff02115c85)

## Changelog
[Internal] - use Debug apk instead of release one to test the release

Reviewed By: robhogan

Differential Revision: D67599760

fbshipit-source-id: 224b5b8d8f664bb579b09ee68f1b92c0774a9b5e
2024-12-23 07:46:02 -08:00
Intl Scheduler 5b6e35afda translation auto-update for Apps/Wilde/scripts/intl-config.json on master
Summary:
Chronos Job Instance ID: 1125907954543643
Sandcastle Job Instance ID: 18014400108783919
allow-large-files
ignore-conflict-markers
opt-out-review
drop-conflicts

Differential Revision: D67558410

fbshipit-source-id: 98a48c02e85aa4f3481ac4800362728bfdb152db
2024-12-21 04:24:28 -08:00
Sam Zhou 66342d3ccd Deploy 0.257.1 to xplat
Summary: Changelog: [Internal]

Reviewed By: panagosg7

Differential Revision: D67548045

fbshipit-source-id: 0c983b327b54580dddf483b6250ff1261df8ce75
2024-12-20 15:58:17 -08:00
Sam Zhou 4c1dd906b0 Replace React$Node with React.Node
Summary: Changelog: [Internal]

Reviewed By: gkz

Differential Revision: D67529040

fbshipit-source-id: 09221c6f866628bbf9174293124e650b7fffa967
2024-12-20 13:00:12 -08:00
Riccardo Cipolleschi 953889da51 Stabilize Android tests adding retries for failed tests (#48324)
Summary:
Sometimes, specific E2E tests can fail. This change tries to run specific E2E tests with retries, to compensate for their flakyness.

## Changelog:
[Internal] - Add single test retry for Android E2E tests

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

Test Plan: GHA

Reviewed By: huntie

Differential Revision: D67396758

Pulled By: cipolleschi

fbshipit-source-id: 7d806fe7354bd9e826c591ea9628c73c3b258fce
2024-12-20 06:19:17 -08:00
Riccardo Cipolleschi 5443359c88 Revert "Include autolinkin.h in OnLoad.cpp only if it exists (#47875)" (#48341)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48341

We reverted [this commit](https://github.com/facebook/react-native/commit/5b2bbb84b14208905fc0dd7eade9ee6ce6e079b7) in 0.76 and 0.77 as it was not the right fix.

## Changelog
[Internal] - Revert excluding `autolinking.h` only if it exists

Reviewed By: alanleedev

Differential Revision: D67456530

fbshipit-source-id: 0f7bfc11d23f7a8fef5100784754add5b4ecda58
2024-12-20 03:15:55 -08:00
David Vacca 7b8412d66d Migrate ReactDrawableHelper to Kotlin (#48346)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48346

Migrate ReactDrawableHelper to Kotlin

changelog: [internal] internal

Reviewed By: rshest

Differential Revision: D67420410

fbshipit-source-id: 524062d0c0a0d3440bf5ac4c61e8cae53b32a0d2
2024-12-20 00:18:50 -08:00
David Vacca e9faea2f3e Migrate ReactPackageLogger to kotlin (#48345)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48345

Migrate ReactPackageLogger to kotlin

changelog: [internal] internal

Reviewed By: rshest

Differential Revision: D67420585

fbshipit-source-id: a82fc7f17828ef6ad36a666113673526eb723600
2024-12-20 00:15:54 -08:00
Krzysztof Piaskowy 23eb06f662 Static Hermes for React Native (#48327)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48327

This PR introduces necessary changes to let React Native uses latest version of static Hermes.

## Explanation

### Part 1
```cmake
append("/d2UndefIntOverflow-" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
```
It seems like this flag doesn’t exist anymore in the MSVC 16 compiler.
CI logs - https://github.com/piaskowyk/react-native/actions/runs/11815096269/job/32915591004
```
fatal error C1007: unrecognized flag '-UndefIntOverflow-' in 'p2'
```

### Part 2
```cmake
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
  # MSVC needs C++20
  set(CMAKE_CXX_STANDARD 20)
else()
  set(CMAKE_CXX_STANDARD 17)
endif()
```

Some of the new syntax in static Hermes requires the newer C++ standard on MSVC.

### Part 3
```cmake
# Changes in lib/CMakeLists.txt
```

These updates are necessary to successfully build the Hermes Framework for iOS.

### Part 4
```diff
namespace hermes {
namespace hbc {
namespace {

class BytecodeSerializer {
-  friend void visitBytecodeSegmentsInOrder<BytecodeSerializer>(
+  friend void hermes::hbc::visitBytecodeSegmentsInOrder<BytecodeSerializer>(
```

Due to additional additional anonymous namespace, the MSVC wasn't able to recognise proper symbol without explicite definition.

X-link: https://github.com/facebook/hermes/pull/1566

Test Plan: Build RNTester app from here - https://github.com/piaskowyk/react-native/tree/%40piaskowyk/build-static-hermes

Reviewed By: tmikov, cipolleschi

Differential Revision: D67316013

Pulled By: neildhar

fbshipit-source-id: cf03850f94a75acd827b68794700a8f143a90e09
2024-12-19 16:23:41 -08:00