Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51671
Adds `flow` (or `noflow`) to all files in this directory and ensures that Flow succeeds (by adding type annotations, using minor refactors, or suppressing errors due to intentionally dynamic logic).
This will help improve type safety when making changes both in these files as well as files that these depend on.
Changelog:
[Internal]
Reviewed By: SamChou19815
Differential Revision: D75581879
fbshipit-source-id: 6dcd8cc55d0021973eeae2670c1ebceb6d69fa8f
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51669
Refactors the default mocks initialized in `packages/react-native/jest/setup.js` so that each mock is defined in its own file.
This provides several benefits, including:
- The ability to use `import` statements without worrying about eager initialization of dependencies before `globals` is setup.
- The ability to verify mocks export the same types as the actual module, using a new Flow-typed `mock` helper function.
- The ergonomic of implementing mocks with more complex logic, without having to split them out into a separate module (e.g. `mockModal`, `mockScrollView`).
As part of this migration, I also fixed any minor discrepancies to match the actual type definition. For more involved discrepancies (e.g. missing methods), I added type suppressions for now to minimize breaking changes.
Changelog:
[General][Changed] - Improved default mocking for Jest unit tests.
Reviewed By: javache
Differential Revision: D75575421
fbshipit-source-id: 98d60e10b753f1505ffdccf5f12f5d3ef306ebb5
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51674
changelog: [internal]
just a clean up of code in AnimationDriverUtils and removal of unused headers.
Reviewed By: mdvacca
Differential Revision: D75549612
fbshipit-source-id: a8ad63622478d06318b6304b886554478b43d19b
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51673
Fixes a lint warning that seems to inconsistently fire, by improving the code that it complains about.
Changelog:
[Internal]
Reviewed By: javache
Differential Revision: D75583443
fbshipit-source-id: b6df191e2e51dee688df3f3c960704dea28a4ece
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51634
Creates an example in the ViewExample setup for how onBlur/onFocus behave when using keyboard navigation
Changelog: [Internal]
Reviewed By: javache
Differential Revision: D75238317
fbshipit-source-id: e69122ca17727fc7f71e9bb7a09098a2771b098e
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51570
As the title suggests: adds support strictly to `View` components on Android for `onFocus` and `onBlur` events. This is especially helpful for apps that respond to controller or remote inputs and aligns with existing support for the `focusable` prop.
In order to make this change cross-compatible with text inputs, `TextInputFocusEvent` has been deprecated in favor of the `BlurEvent`/`FocusEvent` types now available from core. Their type signatures are identical but `BlurEvent`/`FocusEvent` should be the type going forward for all views that intend to support focus/blur. Text inputs intentionally do not forward information about their state upon focus/blur and docs specifically call out `onEndEditing` as a means of reading state synchronously when blurring. Therefore, the changes to the native side to remove the event type specifically for text inputs is not breaking.
Changelog: [Android][Added] - Support for `onFocus` and `onBlur` function calls in `View` components
Reviewed By: mdvacca
Differential Revision: D75238291
fbshipit-source-id: b991d1f24fc094ba9d5d466201ecd058f59258e9
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51666
The platforms handle this in pretty different ways right now. Let's add a test showing the differences.
Android also adds a bunch of unicode zero width spaces in there...
Changelog: [Internal]
Reviewed By: mlord93
Differential Revision: D75567210
fbshipit-source-id: 98cac7d3fd23451868b55b69478e2667a2de3716
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51654
Facsimile may or may not use a global measure cache. Adding flags to let us run experiment, to understand real-world performance impact, now that we have fixed some (but not all) of the issues which may lead to measurement invalidation in Fabric.
Also does some quick cleanup th `SimpleThreadSafeCache` to remove the cache key as part of the lambda, which is never used, and makes this change mildly less efficient, and to accept lambda by generic type instead of repacking into std::function which has runtime overhead.
Changelog: [Internal]
Reviewed By: rshest
Differential Revision: D75509799
fbshipit-source-id: 165c08d626ab1f2758f0203d3a0d527a1a5106a7
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51662
## Changes
DeviceInfo: Deafult fontScale to 1 when accessibility manager isn't available
# Analysis
**The problem:** For reasons that we don't understand, accessibility manager is sometimes nil, when deviceinfo needs it. This is a long-standing issue in react native.
```
_constants = @{
@"Dimensions" : [self _exportedDimensions],
// Note:
// This prop is deprecated and will be removed in a future release.
// Please use this only for a quick and temporary solution.
// Use <SafeAreaView> instead.
@"isIPhoneX_deprecated" : @(RCTIsIPhoneNotched()),
};
```
```
- (NSDictionary *)_exportedDimensions
{
RCTAssert(!_invalidated, @"Failed to get exported dimensions: RCTDeviceInfo has been invalidated");
RCTAssert(_moduleRegistry, @"Failed to get exported dimensions: RCTModuleRegistry is nil");
RCTAccessibilityManager *accessibilityManager =
(RCTAccessibilityManager *)[_moduleRegistry moduleForName:"AccessibilityManager"];
if (!accessibilityManager) {
return nil;
}
CGFloat fontScale = accessibilityManager ? accessibilityManager.multiplier : 1.0;
return RCTExportedDimensions(fontScale);
}
```
**The crash:** When accessibility manager is nil, device info tries to insert nil into an NSDictionary, and crashes.
We found a possible repro of this issue: [launch facebook, log out, and log back in](https://www.internalfb.com/diff/D72020801?transaction_fbid=982516293994114).
**Why this surged now:** Recently, we started initializing device info during react native init. That means this code-path just runs much more often.
# Mitigation
Remove the return nil in `[self _exportedDimensions]`. Instead, just default the fontScale to 1 when the accessibility manager isn't available.
**This should be safe:** If we assume that accessibility manager eventually becomes available, the fontScale will eventually become correct. Device info will send the updated fontScale to js when it becomes available: [native](https://www.internalfb.com/code/fbsource/[ec6fd664a9cd]/xplat/js/react-native-github/packages/react-native/React/CoreModules/RCTDeviceInfo.mm?lines=231-232), [js](https://www.internalfb.com/code/fbsource/[ec6fd664a9cd]/xplat/js/react-native-github/packages/react-native/Libraries/Utilities/Dimensions.js?lines=120-125).
# Long-term fix
Understand why accessibility manager is nil.
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D75537894
fbshipit-source-id: 921cc573fdfd7e5c340ac3a4ada268caadb9e382
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51549
This is copied from `ReactTextView`, with a comment explaining the shenanigans.
Changelog: [Internal]
Reviewed By: mdvacca
Differential Revision: D75248328
fbshipit-source-id: b325cf05e0000ee0b0c5fb82f0e7412a680e5d01
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51575
Before we were relying on absolute focus direction to determine the next focusable view inspired by Recycler View's implementation. This turned out to be inaccurate since FocusForward and FocusBackward do the ordering differently.
For FocusForward and FocusBackwards the children of the root node are ordered first from top to bottom then, row groups are created by getting views with the same vertical position and then everything else is sorted left to right.
Android creates an array with this order and then just focuses the next or previous element of this list. We don't do this but now FocusForward and FocusBackward follow the some comparisons used to build this array on Android.
Also, there was an issue with nested children within an accessible view, this just needed a bit of refactor on the focusSearch function so that we can tell when we actually need to trigger our custom focus search
Changelog: [Internal]
Reviewed By: joevilches
Differential Revision: D75301251
fbshipit-source-id: 93b708092299afa778ba5938b093c2c38209b497
Summary:
Adds `flow` (or `noflow`) to all files in this directory and ensures that Flow succeeds (by adding type annotations, using minor refactors, or suppressing errors due to intentionally dynamic logic).
This will help improve type safety when making changes both in these files as well as files that these depend on.
Changelog:
[Internal]
Pull Request resolved: https://github.com/facebook/react-native/pull/51652
Test Plan:
Ran Flow and Jest tests successfully:
```
$ yarn flow
$ yarn test
```
Ran a Jest unit test internally to make sure they work with our internal environment setup:
```
$ cd ~/fbsource
$ js1 test /View-test.js
```
Reviewed By: javache
Differential Revision: D75488160
Pulled By: yungsters
fbshipit-source-id: 536cef9699acfa1edcd3dcf61c53ebcd92f560f9
Summary:
This PR adds a new cloning method, allowing for updating multiple nodes in a single transaction. It works in two phases:
1. Find which nodes have to be cloned (i.e. nodes given on input and all their ancestors)
2. Clone nodes in the bottom up order - so that every node is cloned exactly once
So the idea is that when we want to update all the red nodes in this picture, we first find the nodes in the green area and the clone only them in the correct order (children are cloned before parents):

Adapting this method [brought a huge performance gain to reanimated](https://github.com/software-mansion/react-native-reanimated/pull/6214). I want to upstream it, so that:
1. we can optimize it further, because making it a part of the `ShadowNode` class gives us access to the parent field in `ShadowNodeFamily` so we can traverse the tree upwards, allowing for a optimal implementation of the first phase (in reanimated we repeatedly call `getAncestors`, which revisits some nodes multiple times)
2. the community can use it
A naive approach that calls `cloneTree` for every node is much slower, as it has to repeat many operations.
## Changelog:
[GENERAL] [ADDED] - Added `cloneMultiple` to `ShadowNode` class.
Pull Request resolved: https://github.com/facebook/react-native/pull/50624
Test Plan:
I tested it with the following reanimated implementation and everything works fine:
<details>
```c++
const auto callback =
[&](const ShadowNode &shadowNode,
const std::optional<ShadowNode::ListOfShared> &newChildren) {
return shadowNode.clone(
{mergeProps(shadowNode, propsMap, shadowNode.getFamily()),
newChildren
? std::make_shared<ShadowNode::ListOfShared>(*newChildren)
: ShadowNodeFragment::childrenPlaceholder(),
shadowNode.getState()});
};
return std::static_pointer_cast<RootShadowNode>(
oldRootNode.cloneMultiple(families, callback));
```
</details>
I would like to add tests for it, but I'm not sure what's the best approach for that in the repo.
Reviewed By: mdvacca
Differential Revision: D75284060
Pulled By: javache
fbshipit-source-id: 0704c4386c3041eb368adf6950d46de197479058
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51657
changelog: [internal]
Introduce a new ShadowNodeTraits: `Unstable_uncullableView` and `Unstable_uncullableTrace`. As the name suggests, this is not stable API yet.
When a shadow node sets this trait, it will be opted out of view culling together with its ancestors all the way to the root.
The trait is propagated to its parent in 4 different places:
1. When node is first created.
2. When node is cloned.
3. When child is appended.
4. When child is replaced.
we can safely do it only in those places because React constructs nodes from bottom up. We are leveraging this implementation detail here but if that changes in the future, a traversal will be required.
Alternative solution considered here was a traversal of shadow tree during commit phase to propagate `Unstable_uncullable` trait. This could be done in a separate traversal or as part of layout phase where layout information is copied out of Yoga tree. Leveraging the fact that React is cloning bottom up makes the implementation simpler.
If React changes its cloning approach in the future, this will be caught by tests.
Reviewed By: lenaic
Differential Revision: D75476847
fbshipit-source-id: f1e98804565c140c64945662af0247b1bd0e1882
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51656
This fixes an issue with the internal networking layer when `enableModuleArgumentNSNullConversionIOS` is enabled, as we'd try to pass `NSNull` as trackingName instead of omitting it.
`
Changelog: [Internal]
Reviewed By: fabriziocucci
Differential Revision: D75516619
fbshipit-source-id: 91a3bba32772fdd66edde1e24b7edd977918f727
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51639
changelog: [internal]
### Fix Crash in View Culling
This diff fixes a crash that occurs when a view is unflattened or flattened in a deep hierarchy where each node has a top offset.
The problem is that nodes passed to *calculateShadowViewMutationsFlattener* via argument *unvisitedOtherNodes* have their positions calculated in a different coordinate space and the view culling algorithm does not have the correct data to determine visibility of a node. To fix this, we pass another argument to *calculateShadowViewMutationsFlattener* which does have original view culling context with which these nodes had their position calculated.
Reviewed By: javache
Differential Revision: D75455704
fbshipit-source-id: 925f14dfdc6c2b669c89e100629291921f27cd1e
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51622
We currently support an optional 3rd params for `target_compile_reactnative_options` which allows to specify a LOG_TAG macro.
No one is actually reading that Macro. The only usage would be logging from the Android SDK which we don't explicitely use.
Here I'm updating our build to specify a LOG_TAG as `ReactNative` for all the targets without allowing to customize it as it just complicates our build setup.
Changelog:
[Internal] [Changed] -
Reviewed By: mdvacca
Differential Revision: D75445577
fbshipit-source-id: a426ce77ba6d1dfd0800e874d9f7838bfdc5b877
Summary:
RuntimeExecutor.h has sync ui thread utils:
* executeSynchronouslyOnSameThread_CAN_DEADLOCK
The ios platform has js -> ui sync calls. This util, when it executes concurrently with those sync calls, deadlocks react native.
On ios, we're going to resolve these deadlocks, which'll involve customizing this util: D74769326. Therefore, this diff forks an implementation of these sync ui thread utils for ios.
Changelog: [Internal]
Reviewed By: mdvacca
Differential Revision: D74901907
fbshipit-source-id: f502df4216e9ba57f458435c696a2f086becf24f
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51633
To fully support props diffing for a component, the component's Props implementation needs to implement the prop diffing for the derived class.
Because all Props classes extend the ViewProps, all Props classes implement the `getDiffProps` function. To support testing that the props diffing implementation support all properties of the derived Props class for the component being mounted, this diff adds the virtual function `getDiffPropsImplementationTarget` which returns the `ComponentName` that the `getDiffProps` function supports.
This removes the need for a hard-coded list of components that support props diffing and enables the use of codegen to conditionally enable props diffing.
Changelog: [Internal]
Reviewed By: javache
Differential Revision: D75465020
fbshipit-source-id: 2850a76f1036cfe930c3c69b98d478ef86a2d457
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51650
This diff adds support to diff props with Point type
changelog: [internal] internal
Reviewed By: mlord93
Differential Revision: D75469451
fbshipit-source-id: a6844b691d8e32326d04c2bd51e6509980feb611
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51642
This diff asserts that ImageRequest won't be used as prop type
changelog: [internal] internal
Reviewed By: mlord93
Differential Revision: D75469453
fbshipit-source-id: e9e46bc8806e00c104b76825445fe72779106220
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51551
This allows hit RN's hit testing to find nested spans, and click them.
This mechanism is fully separate from the one used by a11y virtual views, and ClickableSpan, such as those added for links via dataDetectorType (and also the `link` role).
When we do have a link accessibilityRole, that ClickableSpan hit test seems to prevent the React one, and we only activate the onPress once (but then add keyboard interaction, press visual, and add to the a11y tree).
Changelog: [Internal]
Reviewed By: mdvacca
Differential Revision: D75257326
fbshipit-source-id: 0c693f581ec121cf4b4e3e2040d141985118224f
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51635
Enables a feature flag by default, that reduces the memory usage of`Animated`. For more details, see: https://github.com/facebook/react-native/pull/49184
Changelog:
[General][Changed] - Enabled a feature flag that optimizes `Animated` to reduce memory usage.
Reviewed By: jehartzog
Differential Revision: D75466724
fbshipit-source-id: 3fdb57f394448bbd0530dcb558a58958010d0edd
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51514
This util can execute arbitrary runtimeWork, which can throw.
In the future, we'll also make these utils execute ui blocks posted from the javascript thread. And those will be able to throw.
Therefore, let's remove the noexcept. Otherwise, if an exception bubbles up to this util, it will just crash this app.
Changelog: [General][Changed] - RuntimeExecutor: Remove noexcept from sync ui thread utils
Reviewed By: javache
Differential Revision: D75183993
fbshipit-source-id: 6c3a319fe3a76165a265815e6343220cf9db6fde
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51429
If we use promises, I believe the code is just easier to understand.
Changelog: [Internal]
Reviewed By: javache, yungsters
Differential Revision: D74941734
fbshipit-source-id: a9bc5ac715c84a5a92f8f1c6635ebef9fe538377
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51626
This just migrates the `MapBuilder` file to Kotlin.
Users on Kotlin should still use the built-in collection extensions rather than using this class that will go away at some point in the future.
Changelog:
[Internal] [Changed] -
Reviewed By: fabriziocucci
Differential Revision: D75448739
fbshipit-source-id: 2bfa24ad9bd37bd571ea4551bd9a10e848841e0a
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51629
Changelog: [internal]
The native module will never be defined in tests, so there's no point in logging this warning there.
Reviewed By: rshest
Differential Revision: D75451414
fbshipit-source-id: cdc1f674d01fcaf58c1c2342c994d95e6b3b6847
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51623
This fix relaxes some dependencies on React-hermes that should not be in the code.
## Changelog:
[Internal] - Remove dependencies from React-Hermes when they are not needed.
Reviewed By: cortinico
Differential Revision: D75447910
fbshipit-source-id: 6d7695f0e2b6c936b4c5ed9e70261f1d3b28a3d0
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51625
This just migrates this class to Kotlin, which is also the last class in this package.
Changelog:
[Internal] [Changed] -
Reviewed By: rshest
Differential Revision: D75448161
fbshipit-source-id: d5457dd8017fd459d166d2945ff440c303943db2
Summary:
As I reviewed some examples, I noticed that this one's dark mode could be improved, and the code could be modernised a bit as well by converting its classes into functional components.
## Changelog:
[INTERNAL] - Fix InputAccessoryView example in dark mode and convert to functional components
Pull Request resolved: https://github.com/facebook/react-native/pull/51583
Test Plan:
<details>
<summary>Screenshots</summary>
| Dark | Light |
|--------|-------|
|  |  |
</details>
Reviewed By: fabriziocucci
Differential Revision: D75404561
Pulled By: cortinico
fbshipit-source-id: 3318e9869919e99055e47b59c89de0b22976f142