Граф коммитов

2241 Коммитов

Автор SHA1 Сообщение Дата
Samuel Susla 678f1c4490 Fix crash in slider with custom image
Summary:
Changelog: [Internal]

# Why was it crashing?
Crash was caused by `data.getTrackImageRequest()` returning NULL. The crash happened inside `getCoordinator` method. If you look at the implementation of the method below

```
if (request) {
    return &request->getObserverCoordinator();
} else {
    return nullptr;
}
```

you might notice that we check for NULL, why is it crashing then? And why is it only crashing in production?

The reason is compiler's optimiser, which looks at `data.getTrackImageRequest()`, this method returns `ImageRequest const &` and sees that this method will always return a value, never NULL. Compiler then looks at our `getCoordinator` function, sees that we check there for nullity but since it can never be null, removes that branch.

# Solution
Create new SliderState with non null image observer.

Reviewed By: shergin

Differential Revision: D20491367

fbshipit-source-id: 17b7cf31feabbe6f8ece324a3d329902b2ef6a2d
2020-03-17 13:56:46 -07:00
Valentin Shergin 44618c80ed Revert D20464278: Make Lambda function called in NativeModule mutable to improve performance
Differential Revision:
D20464278

Original commit changeset: 846a8bc6c61c

fbshipit-source-id: 71b69687ab3c279ec4e14f633700355af2291705
2020-03-16 16:21:28 -07:00
Valentin Shergin e602b22bfb Fabric: Tests for `traitCast<>`
Summary:
Subject.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20462834

fbshipit-source-id: 13e3c3b45537e22002b948f967a2576bc52145e8
2020-03-16 10:21:41 -07:00
Valentin Shergin c6e224ee90 Fabric: Removing `yogaStyleFromLayoutConstraints` from RootShadowNode
Summary:
We don't need it anymore because the same logic is already implemented in `YogaLayoutableShadowNode::layoutTree()`.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20464175

fbshipit-source-id: 3dd2293ee102a9b67a856104720d3a7dc4103d7f
2020-03-16 10:11:11 -07:00
maschad 5290047d09 Make Lambda function called in NativeModule mutable to improve performance (#28297)
Summary:
Fixes https://github.com/facebook/react-native/issues/28271
As explained by mmallet-youilabs , if the parameters passed to the `move` function are too expensive, this can have an impact on performance. Thus making these parameters captured by value mutable, the parameters are not movable.

## Changelog

[iOS] [Fixed] - Message
Pull Request resolved: https://github.com/facebook/react-native/pull/28297

Test Plan: Steps to reproduce (and expected results) are not applicable (unless running with a profiler).

Differential Revision: D20464278

Pulled By: shergin

fbshipit-source-id: 846a8bc6c61cb4aa21fbd96b419c3775190a2c84
2020-03-15 22:54:10 -07:00
Valentin Shergin 14a174c237 Fabric: Implementation of `ViewProps::zIndex` feature in C++ core
Summary:
Now, having `orderIndex` feature in the core, we can use it for implementing `zIndex` feature. All we need to do is just to assign this `zIndex` value to `orderIndex`.
Then we will use this to remove some platform-specific code that implements `zIndex` on the mounting layer.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20432155

fbshipit-source-id: b4d62b63006f45899de38e1f40b1dfbe69550ada
2020-03-15 20:52:11 -07:00
Valentin Shergin ca35bfe597 Fabric: `traitCast` now return `nullptr` if the argument is `nullptr`
Summary:
This behavior matches the behavior of `dynamic_cast` (on which some callsites rely on).

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20456792

fbshipit-source-id: 9604da0f9f78cc7357e60ed11012756e753e4b45
2020-03-14 10:17:20 -07:00
Samuel Susla 2394108e15 Fix FindNodeAtPoint newPoint calculation
Summary:
Changelog: [Internal]

Fix newPoint calculation. This bug was revealed when testing with JS inspector.

Reviewed By: JoshuaGross, shergin, mdvacca

Differential Revision: D20369654

fbshipit-source-id: d05aac5bbd408ef5bb0e8e92f0446e287d2854a0
2020-03-14 07:35:13 -07:00
Marc Horowitz 05c17c76da Add a little headroom to the stack when converting an exception JS -> C++
Summary:
This was causing an exception cascade leading to production
errors.  Added a test which repros the problem and passes with the
fix.

Changelog: [Internal]

Reviewed By: tmikov

Differential Revision: D20408858

fbshipit-source-id: 3fa9b8669bf3bf7617bfc05ef8f23d52bc969b4e
2020-03-14 00:13:29 -07:00
David Vacca 6a6590fbdf Fix bug in TextInlineViews when using a deep nested hierarchy of Text and Images
Summary:
This fixes a bug in Android TextInlineViews that was reproducible in ActivityLog screen, see T63438920

Since Text are virtual nodes it is not necessary for these kind of views to stack views during diffing.

changelog: [internal]

Reviewed By: shergin

Differential Revision: D20448085

fbshipit-source-id: 2d852975493bf6bcc7840c80c5de5cb5f7890303
2020-03-13 22:13:57 -07:00
Valentin Shergin ee88e72c02 Fabric: Removed unused leftovers from ViewShadowNode
Summary:
This method does not have implementation and we don't use it.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20423392

fbshipit-source-id: cfb5e4a60dbeca26a968c29d20e74dd6af0bf660
2020-03-13 22:06:04 -07:00
Héctor Ramos 07def55396 fbshipit-source-id: da15f69185e724eaf7d4bc78dbc61fcdcb3074d5 2020-03-13 21:46:45 -07:00
Valentin Shergin 147f0f2eec Fabric: Unsetting `FormsStackingContext` trait for `ParagraphShadowNode` on Android
Summary:
Unsetting `FormsStackingContext` trait is essential on Android where we can't mount views inside `TextView`.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20268038

fbshipit-source-id: e754bf1631a0c3147694fb6b34bb1d9e78148894
2020-03-11 22:45:28 -07:00
Valentin Shergin 4bfe94ac9d Fabric: Specifying the max possible order index value to TextShadowNode on Android
Summary:
We need that to move all `TextShadowNode`s to the end of the list of nodes to make view indexes work for nodes that actually have views.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20396717

fbshipit-source-id: efbef47ef89ab37e83e020c029c39e1a62727fda
2020-03-11 22:45:27 -07:00
Valentin Shergin 8e3e0bd6a7 Fabric: Introducting `ShadowNode::getOrderIndex()`
Summary:
The diff introduces a new field in `ShadowNode` which defines in which order ShadowViews created from the node and its siblings will appear ShadowView tree. The feature will be used to overcome some platform limitations (e.g. on Android) on the mounting layer (it will be able to move some nodes of some time to the end (or beginning) of the list) and build features like zIndex ordering in C++ core.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20396718

fbshipit-source-id: 16aef7c2b5511c874341ab7554e5585b2cdc356f
2020-03-11 22:45:27 -07:00
Valentin Shergin 8fb0eefb78 Fabric: Using move semantic in Differentiator
Summary:
This diff changes how we pass lists of nodes to `calculateShadowViewMutations`: previously we passed that as `const &` and now we pass them as rvalue references because we will need to mute them in the future diffs.

This diff also adds a `static_assert` to ensure that the lists are movable.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20353754

fbshipit-source-id: 0c3383bff6ded8a49d1ac003fce8919d3906b5bb
2020-03-11 22:45:27 -07:00
generatedunixname89002005287564 1dc82a89d7 Daily `arc lint --take CLANGFORMAT`
Reviewed By: zertosh

Differential Revision: D20383094

fbshipit-source-id: 1dc497a98fd3b5962542735c5243d7ac9cd40da3
2020-03-11 21:41:04 -07:00
Marc Horowitz 409c276474 Remove remaining external references to JSC
Summary: Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D20319757

fbshipit-source-id: 4ac3952175fd1b78957b01de279135af122d5bf1
2020-03-11 21:13:01 -07:00
Ramanpreet Nara 99ceb6afba Introduce RCTTurboModulePerformanceLogger
Summary:
In production, we'd like to be able to track the performance metrics of TurboModules. So, I'm introducing a new protocol called `RCTTurboModulePerformanceLogger`. It allows the application to be notified at points during stages of TurboModule creation, and TurboModule method invocation.

**Why can't we use `RCTPerformanceLogger`?**

`RCTPerformanceLogger` is meant to be used to profile RN initialization. It supports a fixed list of markers. Each marker has a type, and there can only be one instance of it. This isn't suitable for logging events in the TurboModule system.

Reviewed By: mdvacca

Differential Revision: D20310976

fbshipit-source-id: a49251b325c94f912cd35ab1cd8fc010f2cfc08f
2020-03-10 19:59:34 -07:00
Ramanpreet Nara 1c1fa5b909 Make main queue setup synchronous
Summary:
This can cause a deadlock if the main thread synchronously calls into some JS that creates a TurboModule. However, this is also the behaviour of legacy NativeModules. Furthermore, this also greatly simplifies how we'll fix async method invocation in TurboModules: T55255146.

Changelog:
[Internal]

Reviewed By: fkgozali

Differential Revision: D20364251

fbshipit-source-id: d0db85665506f08c51c2f33a123e69960923e7f3
2020-03-10 19:59:33 -07:00
Valentin Shergin 0d6d58656a Fabric: EmptyLayoutMetrics does not contain invalid values anymore
Summary:
Before this change, fields of EmptyLayoutMetrics have some "invalid" values to allow us to compare equal them individually and get `false`. Turned out that having invalid values there might break some serialization layers, which is no good.
This change fixes that and adds explicit check for EmptyLayoutMetrics before running a comparison of individual fields.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20324881

fbshipit-source-id: ab8e2a402f6bdfb393fc9b6789decb526fa94dfa
2020-03-10 17:00:41 -07:00
Valentin Shergin 507379f6fa Fabric: Support for Inline Views in Paragraph component
Summary:
Final diff that implements Inline Views in `Paragraph` component.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20268045

fbshipit-source-id: 9a0093eacb9ae34890f6137b308550547a3bcb38
2020-03-10 08:16:40 -07:00
David Detlefs 07c4980267 Add unit test for multiple levels of DecoratedHostObject.
Summary:
I was unsure how, or if, DecoratedHostObjects worked.  Marc had created the linked task to make sure that things worked right with multiple levels of decorated host objects.  I decided to do that, thinking it would show a bug; instead it showed me that the pattern did work, and let me figure out how.

Changelog: [Internal]

Reviewed By: mhorowitz

Differential Revision: D20263797

fbshipit-source-id: 8bbe71cba1b6ef5b2673566759112320dd1894b8
2020-03-09 22:08:00 -07:00
Adam Ernst 0c7bd388f0 Rename get_debug_preprocessor_flags
Summary:
The new name is get_preprocessor_flags_for_build_mode.

Changelog: [Internal]

Reviewed By: d16r

Differential Revision: D20351718

fbshipit-source-id: 67628ce81e7244f0f72af2d00d92842a649ff619
2020-03-09 18:28:27 -07:00
Valentin Shergin 02f2c81240 Fabric: Proper way to specity layout constraints for root Yoga node
Summary:
This diff changes how we apply layout constraints to a root node before layout. We previously used two arguments of `YGNodeCalculateLayout` but that's not expressive enough in cases we have min & max sizes.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross, sammy-SC

Differential Revision: D20268051

fbshipit-source-id: 85aaae65326432993296c3cbc9f7fb8919b07386
2020-03-09 16:36:47 -07:00
Valentin Shergin 0d33cdf146 Fabric: New `LayoutableShadowNode::measure(...)` which measures the node "outside"
Summary:
This diff introduces a new method of `LayoutableShadowNode` called `measure`. The purpose of the method is to measure the node from an "outside" perspective (including paddings and so on). The existing method with the same name (but with slightly different signature) will be renamed to `measureContent` in future diffs.
Hense we will have two `measure*` methods:
 * `measureContent` measures nested content of the node;
 * `measure` measures the node (outside).

This diff also introduces a default implementation of a new measure that uses `layoutTree` under the hood.

Measures the node with given layoutConstraints and layoutContext.
The size of nested content and the padding should be included, the margin should *not* be included.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross, sammy-SC

Differential Revision: D20268047

fbshipit-source-id: 29c28cf16c5afe24f1bfb6e76c42816d4583a8fa
2020-03-09 16:36:47 -07:00
Valentin Shergin 90ada5abb1 Fabric: Calculating positions of attachments as part of text measurement
Summary:
This diff changes API we use to measure text. Previously, a platform-specific measure infra returned just the size of the text, now it returns the size and an array of frames that describe where attachments are placed.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20268041

fbshipit-source-id: 7c065607b6af18a36318db0aab24dad0f171d33a
2020-03-09 16:36:46 -07:00
Valentin Shergin d1ad29b7db Fabric: Introducing `ParagraphShadowNode::Content`
Summary:
`ParagraphShadowNode::Content` describes all nested content of a `Paragraph` component as a single entity allowing to reason about that as a thing that holds an invariant. Now we can store that as a single thing, copy, pass to functions, build on top of that and etc.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC, mdvacca

Differential Revision: D20268043

fbshipit-source-id: e976588ad76615259c72bc21f9ad8d923f2f3b9f
2020-03-09 16:36:46 -07:00
Valentin Shergin 2508c46a75 Fabric: More `assert`s in YogaLayoutableShadowNode
Summary:
These `assert`s must be satisfied. Having them allows us to fail early in case of bugs.
I spent a log of time debugging an issue and finally found that after adding those `assert`s.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20268046

fbshipit-source-id: 1d8ddd6de00069bd2a79e74af5e4278aa6c9131b
2020-03-09 16:36:45 -07:00
Valentin Shergin b5aaa25b9e Fabric: De-virtualizing `LayoutableShadowNode::setLayoutMetrics()`
Summary:
Removing `virtual` qualifier for `LayoutableShadowNode::setLayoutMetrics()`. Original design implied that some subclass might override that method to provide additional functionality but we never used that and seems not it does not much the overall design: we store `layoutMetrics` *inside* `LayoutableShadowNode`.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20268042

fbshipit-source-id: 2aa9b3da316b97f26493fb04d19ca8290bd5d2a6
2020-03-09 16:36:45 -07:00
Valentin Shergin 2a61c4ec53 Fabric: `roundToPixel<>()` convenience functions
Summary:
A bunch of convenience functions for rounding float values to be aligned to the device pixel grid. We had something like this on iOS, now we need to have that in xplat C++ code.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20268044

fbshipit-source-id: 980b61c793eaeafb160e2b3c1d9742402800cd47
2020-03-09 16:36:45 -07:00
Valentin Shergin e1b8841c7a Fabric: non-const `AttributedString::getFragments()`
Summary:
This diff adds a non-const method to AttributedString that allows accessing a list of fragments by reference.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20268040

fbshipit-source-id: cd0c8be126607b99686f7f596106b38fbe3da230
2020-03-09 16:36:44 -07:00
Valentin Shergin f18358dda6 Fabric: Introducing `BaseTextShadowNode::getAttributedString()`
Summary:
`BaseTextShadowNode::getAttributedString()` was replaced with simular method `BaseTextShadowNode::buildAttributedString()` which does same work with following differences:
* Besides returning `AttributedString`, it retures an array of `Attachment`s elements of which points to `ShadowNode`s that form attachments;
* Now we use single `AttributedString` to construct result instead of concatenation objects recurvily walking the tree.

We will use the array of attachments later.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20268048

fbshipit-source-id: 371c548826bdfd5c4f4b18915d68977724885ce6
2020-03-09 16:36:44 -07:00
Jesse Katsumata 42c1957aff chore: fix typo in comments (#28269)
Summary:
Fixed some typos in the comment.

## Changelog

[Internal] [Fixed] - Fixed typo in the comments
Pull Request resolved: https://github.com/facebook/react-native/pull/28269

Test Plan: Changes are only made in the comments, so test is not necessary.

Reviewed By: cpojer

Differential Revision: D20342637

Pulled By: shergin

fbshipit-source-id: f6e7dd538ee54c43e1570c35e1f8c4502054e328
2020-03-09 15:37:33 -07:00
Samuel Susla f96dc274d1 FindNodeAtPoint now accounts for scrollView offset
Summary:
Changelog: [internal]
FindNodeAtPoint was not taking transform into account.

Reviewed By: JoshuaGross

Differential Revision: D20288026

fbshipit-source-id: a8ff09bc265de983e42610c5d23837a2000f9dd2
2020-03-09 05:57:20 -07:00
Samuel Susla d6484fa180 Add TextKind trait to ParagraphShadowNode and TextInputShadowNode
Summary:
Adds `TextKind` trait to Paragraph and TextInput shadow nodes.

Later on it could cause confusion why they do not have this trait.

Changelog: [Internal]

Reviewed By: shergin, mdvacca

Differential Revision: D20254008

fbshipit-source-id: 56fb264fa4fe38a5f00f080558cdc7992fd51fea
2020-03-09 05:51:27 -07:00
Samuel Susla 138ade0117 Add transform*rect and transform*size operators
Summary:
Adding 2 `transform*rect` and `transform*size` operations.
Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D20304247

fbshipit-source-id: 7bde67c96a21ce15e9da0464bcfccc61ab8fe13d
2020-03-09 04:56:39 -07:00
Valentin Shergin a426c8dc77 Fabric: Using `(un)wrapManagedObject` in TextLayoutManager
Summary:
Investigating a crash, I spend half of an hour staring at `__bridge`, `__bridge_retained`, `CFRelease` and etc trying to understand is there a bug or not. Even if I think there was no bug there, it should not be this way. We have a nice abstraction around that madness we should use to make the code obvious.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20260917

fbshipit-source-id: 2b511ebf46a78950c4720e749099134aed1dd890
2020-03-08 21:31:54 -07:00
Jon Thysell (JAUNTY) 460c698e5f Fix MSVC build break in VS 2019 (#28253)
Summary:
Updating react-native-windows to build with Visual Studio 2019 and the v142 toolset.

## Changelog

[Internal] [Fixed] - Fix MSVC build break in VS 2019
Pull Request resolved: https://github.com/facebook/react-native/pull/28253

Test Plan: No real change, only adding a missing include for `stdexcept`.

Reviewed By: cpojer

Differential Revision: D20321273

Pulled By: shergin

fbshipit-source-id: ffe8b4d3a96ce4ed1db303020d77a806637e88bc
2020-03-08 21:18:48 -07:00
Joshua Gross c18cc76e58 Comparison of AttributedString false more often than true in TextInput, resulting in janky editing behavior
Summary:
Instead of comparing the entire AttributedString, compare just the strings and the TextAttributes of Fragments.

Concretely what I'm seeing is that the Frame of the associated parent ShadowViews are changing very frequently, making it impossible to actually modify the TextInput in some cases. However, we shouldn't forcibly reset the content of the TextInput if the frame of the parent is changing and not the actual child contents.

Changelog: [Internal] Fabric TextInput bug fix

Reviewed By: shergin

Differential Revision: D20319359

fbshipit-source-id: 2f51f521ad76fff9da6f6c8b5e795f03c33e496f
2020-03-06 19:37:27 -08:00
Joshua Gross 83c76c257c Fix T61647031 - color comparison causing TextAttribute color to not update ParagraphState
Summary:
As documented in T61647031, Text colors were sometimes not being updated because the ParagraphState was not always updating with a new AttributedString.

Turns out, it's because the equality comparator for Color had not been implemented, and so State was not being set in some cases.

The confusing part is that now color comparisons return true **more often** than before (if you're comparing two smart pointers of opaque data without a custom comparator, in theory I assume they're comparing pointer values and returning false way more often... but maybe my understanding is off). This distracted us for a while in finding an other ~fairly simple solution.

We should keep this in mind if we experience other, similar issues with text attributes not updating.

Changelog: [Internal] Fabric

Reviewed By: mdvacca

Differential Revision: D20300307

fbshipit-source-id: 13d86495f4c4ef8a0219fec66d39a49b4f7e6c2a
2020-03-06 12:39:34 -08:00
Riley Dulin 48001c597e Add call to collectGarbage for JSIExecutor::handleMemoryPressure
Summary:
Someone pointed out in this Github issue: https://github.com/facebook/react-native/issues/27532
that the memory pressure warning from Android was being ignored, when it can easily
be used to start a garbage collection on the JS runtime.

Changelog: [Internal] Add a memory pressure handler for jsi::Runtime

Reviewed By: mhorowitz

Differential Revision: D20072943

fbshipit-source-id: 869a14068aa02bd378e8b26d8c18b76a5d0f7bc0
2020-03-05 18:15:38 -08:00
Valentin Shergin 22fdb8bb05 Fabric: Fixed UI jankiness caused by changes in flattening
Summary:
It's not clear why exactly but seems in some cases, for some views the hierarchical relationship between views is required (when it should not be conceptually). Turning this feature off for Android for now.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross

Differential Revision: D20292833

fbshipit-source-id: 1aab8468cedeb5c1440a95944be7eca3216e0db0
2020-03-05 17:29:08 -08:00
generatedunixname89002005287564 d1018e0414 Daily `arc lint --take CLANGFORMAT`
Reviewed By: zertosh

Differential Revision: D20278397

fbshipit-source-id: 2188283cd01d0d9d9d5b3995bd8d3f1fd687ad55
2020-03-05 08:27:36 -08:00
Joshua Gross 43e6d9acd7 TextInput should respect previous props, paddingHorizontal, and paddingVertical
Summary:
Of course if props aren't changing, rawProps won't have paddings anymore and so padding gets reset.

Also, make sure we pay attention to paddingVertical and paddingHorizontal styles.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D20269583

fbshipit-source-id: 2903fd0f7e6178f506109467d9a8f67b6d013a25
2020-03-04 20:01:24 -08:00
Will Holen f1a9ca04f6 Support CDP returnByValue in Hermes Inspector
Summary:
This adds support for 'returnByValue' in Runtime.evaluate invocations.
If the result of the evaluation can't be serialized to JSON, the results
are undefined.

ChangeLog: [Internal] - Hermes Inspector now supports 'returnByValue' in CDP Runtime.evaluate calls

[Facebook]
This is change was made to support debug completion in VSCode for ReactVR.

Reviewed By: ArchDev

Differential Revision: D19961115

fbshipit-source-id: d20af82b35d6bde88ab74b5c5a4c07415122c142
2020-03-04 16:28:45 -08:00
Valentin Shergin 4f3e3f8cc1 Fabric: Tweaking view flattening algorithm to rely on new traits instead of `LayoutableShadowNode::isLayoutOnly()`
Summary: Now, following the previous diff, we remove `LayoutableShadowNode::isLayoutOnly()` and change the view flattening algorithm to rely on two new traits. See the previous diff to learn more about how it works.

Reviewed By: sammy-SC

Differential Revision: D20212252

fbshipit-source-id: 87a07e8bb17b2e66e5703f107dc35ca7a8e49634
2020-03-04 12:33:03 -08:00
Valentin Shergin b5117bf6ea Fabric: New two ShadowNode Traits: FormsStackingContext & FormsView
Summary:
This diff introduces two new `ShadowNodeTrait`s that we will use in the future in the new (slightly tweaked) view-flattening algorithm. (Note: this diff does not enable the new flattening, it's just preparation.)
The idea is that we split the notion of `isLayoutOnlyView` into two traits:
* `FormsView`: `ShadowNode`s with this trait must be represented as `ShadowView`s. Normal "visible" ShadowNodes will have this trait, but "layout only views" in old nomenclature will not.
* `FormsStackingContext`: `ShadowNode`s with this thread not only must be represented as `ShadowView`s but also have to form a "stacking context" which means that their children must be mounted as `ShadowView`'s children.

Our implementation does not exactly follow W3C spec in terms of sets of props that create the stacking context (because of historical reasons and mobile specifics) but ideologically it's the same. We start from the very conservative implementation where only views with background-color and borders do not form stacking context and then we probably extend that to more props.

Most importantly for us now, we will enforce the absence of ``FormsStackingContext` for `ParagraphShadowNode` and the presence of `FormsView` for `TextShadowNode` on Android where it's essential for mounting layer.

Read more about stacking context here: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20212253

fbshipit-source-id: 0fbaee214ce2c5886cb0232843a2a3c7bb20655d
2020-03-04 12:33:03 -08:00
generatedunixname89002005287564 6aa7030ce8 Daily `arc lint --take CLANGFORMAT`
Reviewed By: zertosh

Differential Revision: D20245569

fbshipit-source-id: 2fede4cfd7e0291aa6718d510bfe14ee175134df
2020-03-04 06:08:57 -08:00
Samuel Susla 899b314ca2 Back out "Pass layoutContext to Yoga's MeasureCallback"
Summary:
Passing `layoutContext` to yoga crashes fb4a-64. Until I have a solution let's back this out.

Original commit changeset: 9df7da4bef8c

Changelog: [Internal]

Reviewed By: makovkastar

Differential Revision: D20246917

fbshipit-source-id: 220744fde9f74e8157fc0714c63639b01152e4ab
2020-03-04 05:01:54 -08:00
Samuel Susla 3ee1e5312a Back out "Rename measure to measureContent and pass it LayoutContext"
Summary:
Original commit changeset: 8928b59d5194

Changelog: [Internal]

Reviewed By: makovkastar

Differential Revision: D20246918

fbshipit-source-id: 0b9142d9bc4774a07304769126411a34cc8c33c5
2020-03-04 05:01:53 -08:00
Samuel Susla 74034ba23a Back out "Font size in Text now respects preferredContentSizeCategory"
Summary:
Original commit changeset: 3965a127069a

Changelog: [Internal]

Reviewed By: makovkastar

Differential Revision: D20246919

fbshipit-source-id: d2238f279f44ac4394557949c8f148f08a60647e
2020-03-04 05:01:53 -08:00
Valentin Shergin 0baac1ccfc Fabric: Improvements in Diffing test (`messWithLayotableOnlyFlag`)
Summary:
Now we tweak more props in order to prepare for new flattening algorithm.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross

Differential Revision: D20212254

fbshipit-source-id: 7391155072f93046e78fbecf4bb4b42cb1caacdc
2020-03-03 23:35:25 -08:00
Valentin Shergin 903bf2de21 Fabric: Removing `const` qualifier from AccessibilityProps fields
Summary:
This is a part of migration staterted in D19390813.
There is no need to have those as const. The whole *Props object is usually const (and when it's not, props should not be too).
Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20212255

fbshipit-source-id: 87f3d8e7a94c6626bd9b0fc304f75e915dd73d4c
2020-03-03 23:35:25 -08:00
Valentin Shergin b8c17dd7c0 Revert D19965405: Fabric: Small improvements in Differentiator/TinyMap
Differential Revision:
D19965405

Original commit changeset: 92eedf38d55b

fbshipit-source-id: 92073ca877899e2a607f283275f0d7c894dd4720
2020-03-03 16:39:31 -08:00
Samuel Susla 58347677f9 Back out "UIManager.findNodeAtPoint now returns shadowNode instead of instanceHandle"
Summary:
Original commit changeset: bd2a1bcd26ab

changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D20196869

fbshipit-source-id: 53235dc3475d79f9e3545c9aa42171f23137be5a
2020-03-03 04:22:00 -08:00
Samuel Susla 08dda02347 Font size in Text now respects preferredContentSizeCategory
Summary:
Changelog: [Internal]

Use LayoutContext to pass `fontSizeMultiplier` down to ParagrapShadowNode.

Reviewed By: shergin

Differential Revision: D20184596

fbshipit-source-id: 3965a127069a21328ed19cb3f9732f0a2d1c4d58
2020-03-03 04:14:04 -08:00
Samuel Susla b40f0562f5 Rename measure to measureContent and pass it LayoutContext
Summary:
In order to build dynamic text sizing, `LayoutableShadowNode::measure` needs to accept `LayoutContext`

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D20184598

fbshipit-source-id: 8928b59d51948caf3654f40049212a89a91dceb6
2020-03-03 04:14:04 -08:00
Samuel Susla d98a229202 Pass layoutContext to Yoga's MeasureCallback
Summary:
In order to build dynamic text sizing, we need to pass layoutContext to `yogaNodeMeasureCallbackConnector`

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D20184597

fbshipit-source-id: 9df7da4bef8cbad3bc87d63ed0c5aa5f420dbc11
2020-03-03 04:14:04 -08:00
Valentin Shergin b41307af77 Fabric: Small improvements in Differentiator/TinyMap
Summary:
What's changed:
 * `end()` now returns the pointer to the imaginary element after the very last one (which is aligned with STL);
 * `erase()` now swaps the removing and the last elements and shrinks the size of an array.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19965405

fbshipit-source-id: 92eedf38d55be35a0d9ab6120634b51c8d6e4674
2020-03-02 23:03:01 -08:00
Valentin Shergin 11948bb4b6 Fabric: Removing `TimeUtils.h`
Summary:
We don't use it anymore (we switched to `std::chrono`).

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20201214

fbshipit-source-id: 0c464223822b78c99ed7ff60d926e84a675f2612
2020-03-02 20:11:29 -08:00
David Vacca bf0019e433 Do not flatten views with PointerEvents props
Summary:
Some of the values of pointer events should be propagated across the hierarchy of views, e.g. the pointerEvent value NONE: https://reactnative.dev/docs/view#pointerevents
That mean that we can't flatten these views (or we should propagate these values across alll the hierarchy of a view that is being flatten)
For now I'm going to prevent these views to be flatten, this behavior is consistent with the Adroid view flattening algorithm:
https://our.intern.facebook.com/intern/diffusion/FBS/browse/master/xplat/js/react-native-github/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java?commit=1144adb5b45bf9a8c8cedf4ac86a2e9ccb429815&lines=249

changelog: [internal]

Reviewed By: shergin

Differential Revision: D20180804

fbshipit-source-id: 1fe7fc99c873a28c077b3859f8a7884d38b6d4d8
2020-03-01 14:11:56 -08:00
Valentin Shergin 490e33dd88 Fabric: Fixed memory leak caused by retain cycle in BaseTextShadowNode
Summary:
Clearing `props` and `state` (which we don't use) allows avoiding retain cycles.

The memory leak was caused by a retain cycle:
AttributedString -> Fragment -> ShadowView -> PharagraphState -> TextLayoutManager -> Cache -> AttributedString.

We don't use `props` and `state` parts of `ShadowView` inside `AttributedString`.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20182791

fbshipit-source-id: 2ddc5d53a1cb594e3d1cc39933e8958eb6425389
2020-03-01 12:32:00 -08:00
David Vacca 17a62b72b7 Serialize and de-serialize text attachments for Android
Summary:
This diff implements serialization and deserialization of text attachments as part of the calculation of layout of text components
changelog: [internal]

Reviewed By: JoshuaGross

Differential Revision: D20087251

fbshipit-source-id: dbcbd22f856aadace14343205548154ea80c8464
2020-02-28 22:43:14 -08:00
Kevin Gozali 30822e3923 make RN infra labels public
Summary:
Internal build target labeling.

Changelog: [Internal]

Reviewed By: zlern2k

Differential Revision: D20152676

fbshipit-source-id: 89615a0b3a6f3994b18f2c07b86d0ae93e052327
2020-02-28 12:46:49 -08:00
Samuel Susla 85696298bf Fix yoga node owner getting out of sync with children
Summary:
Changelog: [internal]

# Problem
We have node A with N children.

Calling cloning constructor on `YogaLayoutableShadowNode` causes new `yogaNode_` to be created.
However if `fragment.children` is nil in cloning constructor, which basically says children were not changed, then the existing children's `owner` becomes invalid.

# Solution
In the clone constructor, always call `updateYogaChildren`. This updates yoga children with the new `owner`.

Reviewed By: JoshuaGross

Differential Revision: D20139582

fbshipit-source-id: 3932694d4381b601df07dd8a57887ce7c09f1582
2020-02-28 06:17:55 -08:00
Valentin Shergin 061f54e890 Fabric: `AttributedString::operator==()` now checks `layoutMetrics` for being equal
Summary:
The sizes of attachments are legit parts of `AttributedString`s identity, so we need to incorporate it into the equality test.
We need that to make measurement cache work correctly with inline views.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20151505

fbshipit-source-id: ae47c24a753eab1e497fcfaa93de557ffb30d874
2020-02-27 21:47:49 -08:00
Valentin Shergin 6f4d362887 Fabric: Providing correct `pointScaleFactor` in `YogaLayoutableShadowNode::layoutTree`
Summary:
The previous implementation didn't do it, which was incorrect.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20151493

fbshipit-source-id: ce4b916dbf8f6469b37dfa8ec3bab8cafcf87940
2020-02-27 21:47:49 -08:00
Valentin Shergin dbc35267a0 Fabric: Removing unnecessary code fragments
Summary:
Those `true &&` code fragments don't look intentional.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D20135541

fbshipit-source-id: a7f2a99b2cbcd82023ec40c6b6211ad4f91d65a4
2020-02-27 09:46:29 -08:00
Héctor Ramos 8ae3174873 Run clang-format and apply patches
Summary:
Run clang-format and add .clang-tidy with `clang-diagnostic-*` to several more directories in order to catch any problems.

Changelog:
[Internal]

Reviewed By: shergin

Differential Revision: D19860169

fbshipit-source-id: 7785aab010c8e6945cc6b5c9b68cb8ee0cdbb7fa
2020-02-27 08:29:30 -08:00
Nick Gerleman 427ba359e0 Stamp React Native Version Into C++ Code (#28036)
Summary:
The PlatformConstants native module exposes the ability to query the React
Native version used to build native code. This is managed on iOS and Android by
a version bumping script, which replaces module code based on a template.

It is currently difficult to accurately determine this version for out-of-tree C++
platforms (I.e. React Native Windows). The version of upstream react-native we resolve to is ultimately
dependent on the version of react-native chosen a peer dependency, which is not
neccesarily constant given a build of react-native-windows.

We could try to hack around this, and make our native build try to reason about
the resolved pacakge for react-native using a lockfile, but a much cleaner
solution is to embed version into C++ code, similar to what is done for Android
and iOS. This change does that, adding a header with React Native version and
updating the build stamping script to write to it.

Usage sample:

```c++
  constants["reactNativeVersion"] = folly::dynamic::object();
  constants["reactNativeVersion"]["major"] = ReactNativeVersion.Major;
  constants["reactNativeVersion"]["minor"] = ReactNativeVersion.Minor;
  constants["reactNativeVersion"]["patch"] = ReactNativeVersion.Patch;
```
## Changelog

[General] [Added] - Stamp React Native Version Into C++ Code
Pull Request resolved: https://github.com/facebook/react-native/pull/28036

Test Plan: Validated that the bumping script will accurately update the header, can compile under both MSVC and Clang.

Differential Revision: D19865992

Pulled By: hramos

fbshipit-source-id: 9e0b8e9519015bb62c60b9935a234cd367a1926a
2020-02-27 06:42:14 -08:00
Valentin Shergin 1aab70d0e2 Fabric: `RootShadowNode::clone` was renamed/moved to `ShadowNode::cloneTree`
Summary:
Cloning subtrees is not something specific to a RootNode, so it makes sense to have it in ShadowNode. Soon we will use that to clone subtrees inside Paragraph component to implement Inline Views.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20090666

fbshipit-source-id: 0a64ef9bda438cd55d5fd21d3ad83b36221fa89e
2020-02-26 22:08:22 -08:00
Valentin Shergin 011b470961 Fabric: Introducing `LayoutableShadowNode::layoutTree`
Summary:
All logic that is performed on the root node only was moved from `layout` to a separate methods `layoutTree`. That makes the code simpler and allows reusing `layoutTree` in InlineViews feature.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20052025

fbshipit-source-id: 3070a1cca4e322c6d077ede751ea80359c96a600
2020-02-26 22:08:22 -08:00
Valentin Shergin 1801d63de2 Fabric: Deleting `YogaLayoutableShadowNode::getYogaLayoutableChildren`
Summary:
We don't use it anymore.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20052019

fbshipit-source-id: b829e7bbf0768588c2f0f28c59bf8f85054408b7
2020-02-26 22:08:22 -08:00
Valentin Shergin 6a88e94326 Fabric: `YogaLayoutableShadowNode::updateYogaChildren`
Summary:
Similar to a previous diff but for `setChildren`.
`YogaLayoutableShadowNode::setChildren()` was renamed to `YogaLayoutableShadowNode::updateYogaChildren()`. Now we don't need to pass an argument to this function because the object is already initialized. The new name also disambiguates this method with `getChildren()` from `ShadowNode` (which does something completely different). The rest of the changes is just type adjustments.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20052031

fbshipit-source-id: 6157cad9b55d4cdd97ce04e1278ac1369bfb96bc
2020-02-26 22:08:21 -08:00
Valentin Shergin 191d65ec4e Fabric: `YogaLayoutableShadowNode::setProps()` was replaced with `updateYogaProps()`
Summary:
`YogaLayoutableShadowNode::setProps()` was renamed to `YogaLayoutableShadowNode::updateYogaProps()`. Now we don't need to pass an argument to this function because the object is already initialized. The new name also disambiguates this method with `getProp()` from `ShadowNode` (which does something completely different).

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20052018

fbshipit-source-id: 4d9651bb4452408708fa1b36bb5c5c8639f7d1bb
2020-02-26 22:08:21 -08:00
Valentin Shergin 124c20b2b1 Fabric: Removing `ConcreteShadowNode::getChildrenSlice`
Summary:
We don't use it anymore.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC, mdvacca

Differential Revision: D20052028

fbshipit-source-id: 22c46b90d87b55465d3549c6de24393c33375833
2020-02-26 22:08:21 -08:00
Valentin Shergin 33bf310920 Fabric: YogaStylableProps now inherits Props
Summary:
How we can finally make `ViewProps` inherit `YogaStylableProps` and remove `dynamic_cast`. This overall change is aligned with D19963353.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20052026

fbshipit-source-id: 1066f9a259b50d4672111c9c03a71c2590d59aca
2020-02-26 22:08:20 -08:00
Valentin Shergin 6d10310733 Fabric: Removing a couple of (ViewProps and YogaStylableProps) constructors
Summary:
Here we delete several constructors that were needed only because `YogaLayoutableShadowNode::yogaStyle` was private (which is not true anymore).

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC, mdvacca

Differential Revision: D20052033

fbshipit-source-id: c2afcaf2fdebb65cdcde6c214c8b78aa35d45e91
2020-02-26 22:08:20 -08:00
Valentin Shergin cdbc21132b Fabric: Refinement of `BaseTraits` chain
Summary:
Here we refine the `ShadowNode::BaseTraits` static method. Before this change, ConcreteViewShadowNode<> enforces Layoutable and YogaLayoutable traits. This change moves that responsibility to LayoutableShadowNode and YogaLayoutableShadowNode which makes overall logic more coherent.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20052027

fbshipit-source-id: fd25264204b0232b1dbbff6f9dfefd9fbcb146c4
2020-02-26 22:08:20 -08:00
Valentin Shergin 0c50ba5376 Fabric: Moving logic from `ConcreteViewShadowNode` constructors to `YogaLayoutableShadowNode` constructors
Summary:
Now we can move custom to `YogaLayoutableShadowNode` code from `ConcreteViewShadowNode<>` template to `YogaLayoutableShadowNode` itself reducing the amount of templated code and reduce overall complexity.

Note, here we have to do `dynamic_cast` for now, we will address that in coming diffs.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20052021

fbshipit-source-id: dac5969a97b75e54c7728a1ca8161922bd2245ca
2020-02-26 22:08:19 -08:00
Valentin Shergin 6f08c37633 Fabric: `getLayoutableChildNodes` was de-virtualized and moved to `LayoutableShadowNode`
Summary:
The fact that `LayoutableShadowNode` now inherits `ShadowNode` allows us to de-virtualize `getLayoutableChildNodes` and move that to `LayoutableShadowNode`. Less code, less virtual dispatch, less complexity.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20052032

fbshipit-source-id: 580e86b5a746028e470788e00027f247bf77126c
2020-02-26 22:08:19 -08:00
Valentin Shergin 5bf6726bae Fabric: Stop using `getChildrenSlice` in ConcreteViewShadowNode
Summary:
D19963353 mentioned the infrastructure that re-routes methods calls related to adding and cloning children between YogaLayoutableShadowNode and ShadowNode. `cloneAndReplaceChild` is exactly this. It was implemented as a virtual method that is called from `ConcreteViewShadowNode`. The whole process requires building a list of children of some class and passing that as a list of pointers. Now we don't need it all that because we can call directly and statically. That change will allow us to simplify that infra even more in the future diffs.

With all previous changes, now we can implement `getYogaLayoutableChildren` inside `YogaLayoutableShadowNode` and call that statically. Eventually, that will allow us to remove templated `getChildrenSlice`. Previously the call for that method must be in `ConcreteViewShadowNode`, now it's not true anymore which we will use later to even better goodness.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20052020

fbshipit-source-id: e5c819a4d21b2dbcd08f3439e1783e3a9cba5ef4
2020-02-26 22:08:18 -08:00
Valentin Shergin 7953c3e854 Fabric: Devirtualizing `LayoutableShadowNode::cloneAndReplaceChild`
Summary:
D19963353 mentioned the infrastructure that re-routes methods calls related to adding and cloning children between YogaLayoutableShadowNode and ShadowNode. `cloneAndReplaceChild` is exactly this. It was implemented as a virtual method that is called from `ConcreteViewShadowNode`. The whole process requires building a list of children of some class and passing that as a list of pointers. Now we don't need it all that because we can call directly and statically. That change will allow us to simplify that infra even more in the future diffs.
 Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20052022

fbshipit-source-id: ddf341c112edd8a2f79eaf74465a9a360a168541
2020-02-26 22:08:18 -08:00
Valentin Shergin 1090b05e61 Fabric: Using `traitCast` in UIManager
Summary:
This is another perf-critical place where using traitCast should help with perf.
After this change we practically will not have any `dynamic_cast`s (except those which will be delited (with methods where they are used) in the future diffs).

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20052029

fbshipit-source-id: 63b589d3c3322f0afd72f18b4701fe31d0e05c2f
2020-02-26 22:08:18 -08:00
Valentin Shergin 3400135487 Fabric: Using `traitCast` in `layoutMetricsFromShadowNode`
Summary:
We use this function in Diffing, and Diffing is one of the hottest pieces of Fabric. Removing `dynamic_cast` here should improve perf. See the previous diff for more details.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20052023

fbshipit-source-id: d6427ebf076d7f8244f0aeaf16407efa2368957e
2020-02-26 22:08:17 -08:00
Valentin Shergin b9e5ebd640 Fabric: Using `traitCast` in Differentiator
Summary:
The Diffing is one of the hottest pieces of Fabric. Removing dynamic_cast here should improve perf. See the previous diff for more details.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20052030

fbshipit-source-id: 27fd9f34f2a1f9d22b9da6b1e3c1a2982045c07a
2020-02-26 22:08:17 -08:00
Valentin Shergin fa773a1446 Fabric: Introducing ShadowNode `traitCast`s
Summary:
`traitCast` is a special form of static_cast that checks additional requirements (similar to `dynamic_cast`) before performing the cast. We will use that in many places in the coming diffs.

Restructuring the class hierarchy in the previous diff finally allows us to do static casts among ShadowNode and LayoutableShadowNode and other classes (previously it wasn't allowed because of lack of common base class).

Why we don't want to use `dynamic_cast`:
* It's expensive (and we need to do the cast on the hottest fragments of the framework). (See: (1) http://www.stroustrup.com/fast_dynamic_casting.pdf and (2) https://www.youtube.com/watch?v=ARYP83yNAWk Herb Sutter & proposal of `down_cast`).
* It's code-size inefficient, whereas `static_cast` has zero runtime and code-size overhead.
* Removing `dynamic_cast` will allow us finally to opt-out `RTTI` (additional code size and perm wins).

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D20052024

fbshipit-source-id: d293c1cf80deb7817d333d5306d6b32bf3abdb27
2020-02-26 22:08:17 -08:00
Valentin Shergin 432b434b55 Fabric: LayoutableShadowNode now inherits ShadowNode
Summary:
This is a very crucial change, everything else in this stack depends on it.
Here is the set of constraints that we have for ShadowNode-based class hierarchy:
* `ShadowNode` is a base class that defines basic operations on the nodes. It does not have virtual methods by design (virtual dispatch hurts performance; we want to limit and centralize that in `ComponentDescriptor`s).
* `ConcreteShadowNode<>` template *statically* wires particular `ShadowNode` and particular `Props` establishing a type-safe relationship between them ensured on compile time.
* Not all `ShadowNode`s are "layoutable", not all "layoutable" `ShadowNode`s use Yoga to do layout.
* Layotability (and YogaLayotability) feature is implemented as two classes `LayoutableShadowNode` and `YogaLayoutableShadowNode`. These classes essentially need to know something about the ShadowNode nature of the object (get the list of children or replace some children).

Before the change, `LayoutableShadowNode` and `YogaLayoutableShadowNode`classes did not inherit `ShadowNode` because we don't want to use *virtual inheritance* for `ShadowNode`: `ConcreteShadowNode<>` already inherits `ShadowNode`, so if we make `LayoutableShadowNode` inherits `ShadowNode`, we will have to somehow flatten this inheritance hierarchy (and the virtual inheritance is an answer to that). (Yes, C++ supports multiple inheritance and virtual inheritance.)
Before this change, we solved this dilemma this way: We have a subclass-template `ConcreteViewShadowNode<>` that inherits `ConcreteShadowNode<>` and `YogaLayoutableShadowNode`. Then, we had a bunch of methods that implement the rerouting of some functionality from `YogaLayoutableShadowNode` to `ShadowNode` and vise-versa. (See the diagram "Before".)

That worked fine, except the caveats:
* That wiring is nasty, complex, hard to reason about and overall limiting.
* There is no way to statically cast `LayoutableShadowNode` to `ShadowNode` (because there is no common base class). That forces us to use dynamic_cast on some perf critical paths (including layout, diffing and so on).
* Adding features that rely on interop between `LayoutableShadowNode` and `ShadowNode` is a nightmare.

It should be a better way to deal with this dilemma, and this diff implements a different approach: We can have a base class of `ConcreteShadowNode<>` as a template parameter. With this approach, we can make `LayoutableShadowNode` inherit `ShadowNode` and when we need to instantiate a `ConcreteShadowNode<>` that needs to be layoutable, we can just specify `YogaLayoutableShadowNode` as a base class. (See the diagram "After".)

This simple change will allow us to simplify a lot of things. The rest of the stack is about getting rid of unnecessary moving parts. Which will finally allow us to build "Inline Views" feature.

```
╭──────────────────────╮
│ ◎ ○ ○ ░░░░░░░░░░░░░░░│
├──────────────────────┤
│                      │
│                      │
│        Before        │
│                      │              ┌────────────────────────────┐       ┌────────────────────────────┐
│                      │              │                            │       │                            │
│                      │              │         ShadowNode         │       │    LayoutableShadowNode    │
└──────────────────────┘              │                            │       │                            │
                                      └────────────────────────────┘       └────────────────────────────┘
                                                     ▲                                    ▲
                                                     │                                    │
                                      ╔════════════════════════════╗       ┌────────────────────────────┐
                                      ║                            ║       │                            │
                            ┌────────�║    ConcreteShadowNode<>    ║       │  YogaLayoutableShadowNode  │
                            │         ║                            ║       │                            │
                            │         ╚════════════════════════════╝       └────────────────────────────┘
                            │                        ▲                                    ▲
                            │                        │                                    │
                            │                        │                                    │
                            │                        │                                    │
                            │                        │     ╔════════════════════════════╗ │
                            │                        │     ║                            ║ │
                            │                        └─────║  ConcreteViewShadowNode<>  ║─┘
                            │                              ║                            ║
                            │                              ╚════════════════════════════╝
                            │                                             ▲
                            │                                             │
                            │                              ┌──────────────┴───────────────┐
                            │                              │                              │
                            │                              │                              │
                            │                              │                              │
             ┌────────────────────────────┐ ┌────────────────────────────┐ ┌────────────────────────────┐
             │                            │ │                            │ │                            │
             │       TextShadowNode       │ │       ViewShadowNode       │ │    ParagraphShadowNode     │
             │                            │ │                            │ │                            │
             └────────────────────────────┘ └────────────────────────────┘ └────────────────────────────┘

╭──────────────────────╮
│ ◎ ○ ○ ░░░░░░░░░░░░░░░│
├──────────────────────┤
│                      │                           ┌────────────────────────────┐
│                      │                           │                            │
│        After         │                           │         ShadowNode         │
│                      │                           │                            │
│                      │                           └────────────────────────────┘
│                      │                                          ▲
└──────────────────────┘     ┌────────────────────────────────────┤
                             │                                    │
                             │                     ╔════════════════════════════╗
              ┌────────────────────────────┐       ║     ConcreteShadowNode     ║
              │                            │       ║     <Base: ShadowNode>     ║
              │    LayoutableShadowNode    │       ║                            ║
              │                            │       ╚════════════════════════════╝
              └────────────────────────────┘                      ▲
                             ▲                                    │
                             │                     ┌────────────────────────────┐
              ┌────────────────────────────┐       │                            │
              │                            │       │       TextShadowNode       │
              │  YogaLayoutableShadowNode  │       │                            │
              │                            │       └────────────────────────────┘
              └────────────────────────────┘
                             ▲
                             │
              ╔════════════════════════════╗
              ║     ConcreteShadowNode     ║
              ║           <Base:           ║
              ║ YogaLayoutableShadowNode>  ║
              ╚════════════════════════════╝
                             ▲
                             │
              ╔════════════════════════════╗
              ║                            ║
              ║  ConcreteViewShadowNode<>  ║
              ║                            ║
              ╚════════════════════════════╝
                             ▲
                             ├─────────────────────────────────────┐
                             │                                     │
              ┌────────────────────────────┐        ┌────────────────────────────┐
              │                            │        │                            │
              │    ParagraphShadowNode     │        │       ViewShadowNode       │
              │                            │        │                            │
              └────────────────────────────┘        └────────────────────────────┘

```

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19963353

fbshipit-source-id: b65c8a5064bdb54ab64f08a8e546aa9e2b5a486b
2020-02-26 22:08:16 -08:00
Joshua Gross 5be86695a3 AndroidTextInput uses default padding from Android theme
Summary:
For backwards-compatibility with Paper, we're implementing a feature in Fabric that will allow TextInputs to use the default padding from the theme in Android.

Note that this uses some pretty ugly hacks that probably shouldn't be used inside of components at all: looking directly at rawProps, overriding props/Yoga styles in the component descriptor, etc. I would (personally) really like to kill this feature entirely unless and until we can find a more elegant solution.

Changelog: [Internal]

TextInputs are still not pixel-perfect with Paper, but they're much closer, and the underline visual glitchiness is no longer an issue.

Reviewed By: mdvacca

Differential Revision: D20109605

fbshipit-source-id: 543282843e0a9f03a504d72d7a014431099bd64c
2020-02-26 13:46:57 -08:00
Samuel Susla c7f9a9e49b UIManager.findNodeAtPoint now returns shadowNode instead of instanceHandle
Summary:
Changelog: [Internal]

As agreed in https://fb.quip.com/Oh2mAaTAbBj6, `findNodeAtPoint` now calls callback with `shadowNode` instead of `instanceHandle`.

Reviewed By: shergin

Differential Revision: D20097269

fbshipit-source-id: bd2a1bcd26ab2510f16c3e73f628be4b1f7dacfc
2020-02-26 04:47:43 -08:00
Samuel Susla f936b65883 Creating new state should now correctly increment state revision
Summary:
Changelog: [Internal]

# Problem

Calling `UIManager::updateState` does not increment state revision because it calls `ConcreteComponentDescriptor::createState` which creates new state with state revision 1.

# How did this propagate?

This error propagated itself in TextInput when trying to input a value, you would be only allowed to type in 1 character.

Reviewed By: JoshuaGross

Differential Revision: D20072844

fbshipit-source-id: 37b8173307e1d91d6e9c41b5ff2e185dde31cc38
2020-02-26 03:32:19 -08:00
Valentin Shergin ede2c5031f Codemod: Clang-format for all files in `ReactCommon` directory
Summary:
We are moving towards 100%-prettified files. That's the first step when we apply Clang Format for `ReactCommon`.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D20110895

fbshipit-source-id: 0a0ce4997cf1c3721b0b07ef78c1a57ce87d20f9
2020-02-25 19:52:27 -08:00
Gabriel Nunes 8ad67de59e Update documentation for Function::call to reflect how 'this' behaves in non-strict mode
Summary: The `Function::call` method says it leaves the JS `this` object undefined. According to my tests, that's not completely true: if the function is defined to use strict mode via `"use strict"` either inside itself or in the file it was defined in, it does leave it `undefined`, but if the function is defined in non-strict mode, it sets `this` to the global object instead. This diff updates the documentation to reflect this.

Reviewed By: mhorowitz

Differential Revision: D19613483

fbshipit-source-id: 4b9ecf81c6318592be05a216748dcb22e32989f8
2020-02-25 13:02:32 -08:00
Marc Horowitz afc77bd843 make JSCRuntime SystemJSCAPITestFactory build only on apple platforms
Summary: Changelog: [Internal]

Reviewed By: jbower-fb

Differential Revision: D19874225

fbshipit-source-id: ca730391ea4734bdc98f91d8307bd9d622f27772
2020-02-24 19:14:29 -08:00
David Vacca 6aea6256a6 Unify measure functions in Fabric Android
Summary:
Until now, there were two measure functions that differ in only one parameter (rootTag). The rootTag is used to use the context associated to the tag as part of the calculation of layout, otherwise it just uses the ReactApplicationContext.
This diff unifies both method into an unique method that

changelog: [internal]

Reviewed By: JoshuaGross

Differential Revision: D20081281

fbshipit-source-id: b1f6a6cedbf78f36f36fd0f93407c23c6996d76b
2020-02-24 18:18:32 -08:00
Rachel Nabors c0d8c1db90 Updating the URLs to point at new domain name reactnative.dev
Summary:
We recently updated React Native's docs site to have its own domain reactnative.dev and needed to update the URLs in the source code

CHANGELOG:
[INTERNAL]

Reviewed By: hramos

Differential Revision: D20072842

fbshipit-source-id: 1970d9214c872a6e7abf697d99f8f5360b3b308e
2020-02-24 13:09:11 -08:00
Radek Pietruszewski 24e0bad8be Make JSCRuntime::createValue 35% faster (#27016)
Summary:
JSC does some sort of thread safety locking on every single JSC API call, which makes them ridiculously expensive for a large number of calls (such as when passing a large array over the RN bridge). It would be great if we could lock and unlock once for an entire sequence of JSC calls… but in the meantime, the less we call JSC the better.

![unknown](https://user-images.githubusercontent.com/183747/67624956-08bd6e00-f838-11e9-8f65-e077693f113d.png)

In my benchmark environment (https://github.com/Nozbe/WatermelonDB/pull/541), the time spent in JSCRuntime::createValue went down from 1.07s to 0.69s by changing JSValueIsXXXX calls to a single JSValueGetType call.

The underlying implementation does the same thing: https://github.com/WebKit/webkit/blob/master/Source/JavaScriptCore/API/JSValueRef.cpp#L58

## Changelog

[General] [Fixed] - Make JSCRuntime::createValue faster
Pull Request resolved: https://github.com/facebook/react-native/pull/27016

Reviewed By: RSNara

Differential Revision: D18769047

Pulled By: mhorowitz

fbshipit-source-id: 9d1ee28840303f7721e065c1b3c347e354cd7fef
2020-02-20 10:33:16 -08:00
Janette Cheng a793ed7598 Unbreak the build
Summary:
build-break
overriding_review_checks_triggers_an_audit_and_retroactive_review

fbshipit-source-id: 316b879368503114ea1af16276643301601bcca8
2020-02-20 08:30:46 -08:00
Samuel Susla 60c15073bf Fix crash in state reconciliation
Summary:
Changelog: [internal]

Repro steps:

1. Go to fbsource/fbobjc.
2. Run following focus command P124860753.
3. Enable Address Sanitizer in Xcode.
3. Run the app from Xcode.
5. Make sure `react_fabric.enable_marketplace_home_ios` and `react_fabric.enabled_state_reconciliation_ios` Mobile Config flags are set to true.
6. Navigate to Marketplace Home and observe use of freed memory exception. You have to wait until second page of marketplace home feed is loaded.

{F228880980}

# Root cause

`ChangedShadowNodePairs` being a vector of pairs of references.
Those `shared_ptr` do not outlive the the run of `reconcileStateWithTree` (that's what I originally thought when I made them references).

This was introduced in D19814500.

Reviewed By: JoshuaGross

Differential Revision: D19977784

fbshipit-source-id: 8c4a381137baa08a6af9d3c1cb295fe6c2b2bf95
2020-02-19 14:31:22 -08:00
Samuel Susla 145151ef0f Fix ignored initial value of TextInput
Summary: Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D19922731

fbshipit-source-id: b06f1d98d97a4ea46c60e07a89452ee77acded8d
2020-02-19 07:03:22 -08:00
Samuel Susla aa0a50c518 Introducing RCTBlockingImageManager, an image manager for tests in Fabric
Summary:
Changelog: [Internal]

This allows to block queue until image is fetched.

In paper, the photo of dog will not appear unless the network request is "fast enough".

{F228670428}

Reviewed By: shergin

Differential Revision: D19907906

fbshipit-source-id: 98d68abf1255388f9b97fb9da367d8f583a4220d
2020-02-18 16:51:00 -08:00
Moti Zilberman 011cf3f884 JSStringToSTLString: truncate string on conversion failure
Summary:
[A recent change to JSStringToSTLString](https://github.com/facebook/react-native/pull/26955) causes a crash when the function is invoked with invalid UTF-16 data. The old behaviour, restored here, was to truncate the string before the first invalid character.

Here's how [the original code](aee88b6843/ReactCommon/jsi/JSCRuntime.cpp (L287)) handled this case:
```
std::string JSStringToSTLString(JSStringRef str) {
  size_t maxBytes = JSStringGetMaximumUTF8CStringSize(str);
  // ^ maxBytes >= 1 regardless of str's contents
  std::vector<char> buffer(maxBytes);
  // ^ vector is zero initialised
  JSStringGetUTF8CString(str, buffer.data(), maxBytes);
  // ^ writes '\0' at the first invalid character and returns early (see JSC source code)
  return std::string(buffer.data());
  // ^ copies the string up to the first '\0'
}
```

See the JSC implementations of [`JSStringGetUTF8CString`](https://opensource.apple.com/source/JavaScriptCore/JavaScriptCore-7600.8.7/API/JSStringRef.cpp.auto.html) and [`convertUTF16ToUTF8`](https://opensource.apple.com/source/WTF/WTF-7600.7.2/wtf/unicode/UTF8.cpp.auto.html).

Based on the fact that `JSStringGetUTF8CString` *always* null-terminates the buffer - even when it bails out of converting an invalid string - here we're able to both

1. keep the fast path (not zero-initialising, not scanning for the null terminator) for the common case when the data is valid and JSStringGetUTF8CString returns a nonzero length; and
2. return the truncated string when JSStringGetUTF8CString returns an error code of 0, by scanning for the null terminator.

Changelog: [General] [Fixed] - Fix crash when passing invalid UTF-16 data from JSC into native code

Differential Revision: D19902751

fbshipit-source-id: 06bace2719800e921ec115ad6a29251eafd473f6
2020-02-14 12:04:22 -08:00
Valentin Shergin 5703abd953 Fabric: Getting rid of `static_pointer_cast` in `ConcreteShadowNode`
Summary:
`std::static_pointer_cast` has perf overhead where as `static_cast` does not.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19837695

fbshipit-source-id: 4a257e66813a4a3c757c8ea15ea6ae5e192d1390
2020-02-13 21:07:30 -08:00
Valentin Shergin 967c9dc7b1 Fabric: `ConcreteShadowNode::getProps()` was renamed to `getConcreteProps()` and got new return type.
Summary:
Having the overridden function that returns a different type is apparently not a good idea (and might cause bugs and unexpected behavior), so it was renamed. The function also got a new return type (`const &` instead of `std::shared_ptr`) for simplicity, better performance, and smaller code size.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross

Differential Revision: D19837694

fbshipit-source-id: b7a96424bd040409371724907b3fb3931cd8a2e8
2020-02-13 21:07:30 -08:00
Haozhun Jin c55521aac0 Allow non-ASCII std::string argument to detail::toValue
Summary:
In all other areas of JSI, std::string is treated as potentially
containing UTF-8 bytes (instead of ASCII). This fixes the inconsistency.

Changelog: [Internal]

Reviewed By: mhorowitz

Differential Revision: D19871520

fbshipit-source-id: c703f07e10bedbf2518d0bec903f85f43bbcbdf5
2020-02-13 19:26:49 -08:00
David Detlefs 14ac53363e Make synth trace write incrementally to a file.
Summary:
If we're using synth traces in production, we probably don't want to accumulate the trace in memory, and write it to a file in one big step when an error happens.  Rather, we'd like to write the trace incrementally, to a file: file system space is less scarse than memory, and doing it incrementally means less to do in the error handler.

This diff is the first step towards writing the synth trace incrementally.  The most difficult aspect of this is that in the existing code, on Android, the trace is written in the handler of an Intent.  Java-level operations on the Intent yielded a temporary filename under the application (so if the application is uninstalled, these temporary files are deleted).  We must do something similar, but choose the filename within native code, on construction of the SynthTrace object.  We copy what profiling does for this: assume the tmp dir is /data/data/<app>, where <app> can be found from reading /proc/self/cmdLine.

The SynthTrace constructor now takes a new argument: a unique_pointer to a stream.  If null, no trace file is written, and the SynthTrace just accumulates records in memory.  (This functionality is used during trace replay.) . If non-null, the trace is written to that stream.

The "write{BridgeTraffic}Trace..." methods become "flushAndDisable{BridgeTrafficTrace}" methods.

This diff is the first step towards incremental traces: the trace is still written at the end, but we've arranged that the place to write it is available at construction of the SynthTrace object.  Later diffs will move recording of static things (e.g., the RuntimeConfig) into the ctor, then actually make us write the trace to the file incrementally.

For ReactNative:

Changelog: [Internal]

Reviewed By: haozhun, dulinriley

Differential Revision: D19471297

fbshipit-source-id: c1de4d2d9f44a87c7ff6fea38a1ce67de593940c
2020-02-13 13:01:06 -08:00
Valentin Shergin 78b826fcf7 Fabric: Improvements in StubView pretty-printing
Summary:
Fixed typos, includes, and other misc.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross, sammy-SC

Differential Revision: D19840967

fbshipit-source-id: e13d555ffc49c9ac8e202b9b481b13eb0938663e
2020-02-13 12:05:28 -08:00
Valentin Shergin e737535f18 Fabric: Small optimization in RCTNSAttributedStringFromAttributedString
Summary:
With new logic we save one attributed string copy operation.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19844371

fbshipit-source-id: 62f6b0f9c8514a1b55224ccaa52c8fa89c06c9e7
2020-02-13 12:05:27 -08:00
Jason Safaiyeh dc6c57ce0d Resolve React-cxxreact warnings (#28047)
Summary:
Resolve Xcode warnings from React-cxxreact.

## Changelog

[iOS] [Fixed] - Resolve Xcode warnings from React-cxxreact.
Pull Request resolved: https://github.com/facebook/react-native/pull/28047

Test Plan: React-cxxreact should no longer throw `... creates a copy from type...` warnings

Differential Revision: D19874043

Pulled By: hramos

fbshipit-source-id: 15a4a810adee268e6ede459d6d4917ccfa83c157
2020-02-12 23:49:15 -08:00
Riley Dulin 9b7958c2f2 Have heap snapshots throw std::system_error instead of return a bool
Summary:
Instead of returning a `bool` which gives no information about the cause of the error,
return `void` and throw when there's some error.

Another alternative is returning `std::error_code`, but that's less flexible than throwing, and
this API already supports throwing.

Changelog: [Internal]

Reviewed By: jbower-fb

Differential Revision: D19170033

fbshipit-source-id: 870cd996a1a53c94524455f31765c1da99f57a1d
2020-02-12 17:11:46 -08:00
Josh Leibsly ca431c2179 Remove product/platform/infra layers from ios supermodules
Summary:
Context: https://fb.workplace.com/groups/2116332615111503/permalink/2773825422695549/

build-break
overriding_review_checks_triggers_an_audit_and_retroactive_review
allow-large-files
allow_many_files

Differential Revision:
D19858113
Ninja: master broken

fbshipit-source-id: d9e531f9579bfe7ef87097f0d50512722eb1de5e
2020-02-12 10:25:27 -08:00
Valentin Shergin c0c644cdd6 Fabric: Fixed compilation error in RawPropsBenchmark
Summary:
Subject.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D19840558

fbshipit-source-id: 74f04df4bbf347390aa623b89da3aa4fd6acf32e
2020-02-11 22:04:42 -08:00
Samuel Susla acdaf512e5 Apply small style adjustments to reconcileStateWithTree
Summary:
Changelog: [Internal]

There shouldn't be any logical changes to the code.

Reviewed By: JoshuaGross

Differential Revision: D19814500

fbshipit-source-id: 2be492eebb284c7e241662d9d78117badcb2eee4
2020-02-10 15:35:36 -08:00
Samuel Susla bfa00a5d62 Fix ShadowNode.stateRevision value assignment
Summary:
# Problem

We calculate `stateRevision_` in constructor from children, but children change after shadowNode is initialised and before it is sealed. So the `stateRevision_` we calculate in constructor can be incorrect.

# Solution

Recalculate `stateRevision_` whenever children change. This can happen in two methods `ShadowNode::replaceChild` and `ShadowNode::appendChild`. This diff implements this solution.

Changelog: [Internal]

Reviewed By: JoshuaGross

Differential Revision: D19813840

fbshipit-source-id: 8fc3b6601e4618f4ee5b322eebc230e0bbb92e3a
2020-02-10 15:35:36 -08:00
Valentin Shergin 887ba8f044 Fabric: Support for `State` in `Element<>`
Summary:
Before this change the Element<> API didn't allow to specify state objects and crashed during instantiation of non-null states.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross

Differential Revision: D19816358

fbshipit-source-id: 95ba5e03ea98c0260593462146e8523c95245e2b
2020-02-10 12:43:26 -08:00
empyrical ca81037a0a Fabric: Fix various includes (#27947)
Summary:
This pull request fixes a few `#include`s in the Fabric source:

 * Changes `<Glog/logging.h>` to `<glog/logging.h>` in two files, which was an issue for case-sensitive file systems
 * In `ParagraphProps.cpp`, changes the include of `attributedstring/primitives.h` from a relative style to a more absolute style.

## Changelog

[Internal] [Fixed] - Fabric: Fix various includes
Pull Request resolved: https://github.com/facebook/react-native/pull/27947

Test Plan: Fabric compiles perfectly, and the Fabric test suite passes.

Reviewed By: shergin

Differential Revision: D19788148

Pulled By: sammy-SC

fbshipit-source-id: 30a297e8aea50c7c7fd5f48745edf04811a6bdbd
2020-02-10 06:42:50 -08:00
empyrical 37f012c04e Fabric: Fix CXX Stub for TextLayoutManager (#27948)
Summary:
This pull request fixes the CXX stub for `TextLayoutManager`. The signature for `TextLayoutManager::measure` changed slightly, and this patch updates the stub to reflect that.

## Changelog

[Internal] [Fixed] - Fabric: Fix CXX Stub for TextLayoutManager
Pull Request resolved: https://github.com/facebook/react-native/pull/27948

Test Plan: Fabric compiles, and the Fabric test suite passes.

Reviewed By: shergin

Differential Revision: D19788207

Pulled By: sammy-SC

fbshipit-source-id: 8f42cca0be99022b038742728ad4fec6c04d5cf0
2020-02-10 04:15:11 -08:00
Valentin Shergin 91540d74b1 Fabric: Fixing a retain cycle in between State and ShadowNodeFamily
Summary:
This change removes the concept of `StateTarget`, replacing its role with `ShadowNodeFamily`.
When `StateTarget` was built, we didn't have a concept of `Family`, and when we added it we introduced a retain-cycle: ShadowNode -> Family -> StateTarget -> ShadowNode. This diff fixes that.

This change does not change conceptually how the state behaves, it just adjusts internal machinery.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19799013

fbshipit-source-id: c1360bfbf6b8ac34e2a856a40047eafeb50ed070
2020-02-09 22:28:40 -08:00
Valentin Shergin 085c6d2675 Fabric: Storing data as a shared pointer inside State object
Summary:
Before this change, the concrete component-specific data/payload object associated with a State was stored inside a templated subclass as a normal instance variable; after the change, it's stored as a shared pointer inside the base class. The original motivation was that storing that inside subclass saves us one shared pointer and one heap allocation.

This approach overcomplicated a lot of things and all possible savings are probably compensated with additional complexity (we have to have templated state-update lamdas in subclasses and so on). And to update the data in the previous approach we need to create a shared pointer to data anyway.

This change will allow future improvements in the coming diff.

 Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross

Differential Revision: D19799014

fbshipit-source-id: 287ed939353ba58d9e434d1502ecfbb208c6daa5
2020-02-09 22:28:39 -08:00
Joshua Gross c525ab5e04 Only use State Reconciliation during certain commits from ReactJS, not during State commits or others
Summary:
Only use State Reconciliation during certain commits from ReactJS, not during State commits or others

The idea is that this will have better perf, since many types of commits don't need State Reconciliation at all.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D19794999

fbshipit-source-id: 336325f225d993a6aae9f55cb95a7a2b38a6d853
2020-02-08 11:33:43 -08:00
Joshua Gross 27981ad991 Core: Add "state reconciliation" to commit phase, pre-layout
Summary:
This implements proposal #2 in our State architecture doc: https://fb.quip.com/bm2EAVwL7jQ5

Problem description: see the text in the comment of TreeStateReconciliation.h

Solution: see also comments in TreeStateReconciliation.h.

Changelog: [internal]

Reviewed By: mdvacca

Differential Revision: D19617329

fbshipit-source-id: 845fb5fe27f2591be433b6d77799707b3516fb1a
2020-02-08 11:33:43 -08:00
Valentin Shergin 6e7369e1fd Fabric: Enabling `WITH_FBSYSTRACE` for Fabric code
Summary:
Systraces were disabled a year ago in D14019272 because we suspected they can negatively affect perf. We don't think this is the case anymore.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D19786284

fbshipit-source-id: 185ed45b134fdcadf131cfddfcf8faf37537a684
2020-02-07 10:14:10 -08:00
Valentin Shergin 8fe6883fea Fabric: Fixed double-application of `opacity` and `background-color` props on TextInput
Summary:
These props are applied to `View`, therefore they most not be a part of base text attributes, so we reset them.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D19764144

fbshipit-source-id: a0d2900e3161c47b83114360c843fa85a4389f8a
2020-02-06 08:16:37 -08:00
Joshua Gross 6be37d8c0a Use a mutex to guard access to lastLayoutMetrics_ in ViewEventEmitter
Summary:
Of course, compare_exchange_strong didn't actually do what I wanted.

Using a mutex is simpler and actually has the semantics we want: atomically get the current value, compare, and bail if the value is the same, or swap and continue.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D19754451

fbshipit-source-id: 6b0aef217b235959af683ec5e31b07a0dd7bb040
2020-02-05 18:46:09 -08:00
Christoph Purrer 014bc95135 Make YGValue.h compile with Clang on Windows
Summary:
- We use a fork of Microsoft's react-native-windows which uses a fork of Facebook's react-native
- YGValue.h does not compile with Clang on Windows
- This change should fix that
- I want to put the change here so that it bubbles back to our fork > https://our.intern.facebook.com/intern/diff/D19656093/

#Changelog:
[General][Fixed] Make YGValue.h compile with Clang on Windows

Reviewed By: SidharthGuglani

Differential Revision: D19717489

fbshipit-source-id: ad867ecaf910bb64a777a06c656a1867bb15484b
2020-02-05 13:37:38 -08:00
Pieter De Baets 46dcce0031 Remove unused callFunctionReturnResultAndFlushedQueue
Summary: Changelog: [Internal] Remove unused BatchedBridge.callFunctionReturnResultAndFlushedQueue

Reviewed By: sammy-SC

Differential Revision: D19740946

fbshipit-source-id: 9919d52074180d0fcfb7c0929005f0d925578912
2020-02-05 13:02:06 -08:00
Gabriel Nunes 399bda5284 Fix errors in documentation for Function::callWithThis
Summary:
The documentation in two out of the three variants of `Function::callWithThis` incorrectly stated that the `this` value was to be `undefined` instead of set to `jsThis`, which contradicts the point of the `callWithThis` method existing in the first place. This diff fixes that issue.

Changelog: [General] [Fixed] - Fix documentation comments for HermesJS's `Function::callWithThis` method to accurately reflect how `this` is handled.

Reviewed By: jbower-fb

Differential Revision: D19714074

fbshipit-source-id: 123688c1f7e578d6356bec54604fb6e30f06b0b1
2020-02-04 19:26:02 -08:00
Joshua Gross 928fe129db Core: ViewEventEmitter should not emit duplicate onLayout events
Summary:
Simple hack to prevent duplicate onLayout events from being emitted to JS.

Because of the addition of State Reconciliation to the Fabric lifecycle (see previous diff), in certain circumstances entire subtrees can be relayed-out many, many times even though they aren't changing. For JS product code that responds to every onLayout and forces a ReactJS tree commit (see: some usages of VirtualizedList) this can cause an async infinite loop of commits and layouts even though the tree and the LayoutMetrics aren't actually changing. Even though nothing is changing, it can still cause serious performance regressions and even some bugs since the internals of various state machines may assume onLayout won't be called many times.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D19715280

fbshipit-source-id: d879e24f1c7b1f710ad430b7473aa9293d093dea
2020-02-04 17:28:24 -08:00
Emily Janzer bf32023e50 The life-changing magic of clang-tidying up
Summary:
Adding a `.clang-tidy` to a bunch of dirs under `react-native-github/ReactAndroid` and `react-native-github/ReactCommon`.

I don't want to add a single `.clang-tidy` at the root because we'll need more fine-grained control over what checks are enabled in different parts of the codebase; for example, fabric will and TM will probably have more checks enabled than older parts of the codebase that we're not actively modernizing, and the Hermes team probably wants its own config to be consistent with the rest of their codebase.

Starting off each `.clang-tidy` by only enabling clang-diagnostic; this is just to test that it's working. In the future, we'll work with the community to gradually enable more checks.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D19705749

fbshipit-source-id: 979cea053b645ac4a9790340033bfcfb49ca0f97
2020-02-04 11:09:30 -08:00
Samuel Susla 595e954b13 Use ShadowNodeFamily in state updates
Summary:
Changelog: [internal]

`ShadowNodeFamily` can be used as target in state updates instead of `ShadowNode`.

Reviewed By: shergin

Differential Revision: D19517428

fbshipit-source-id: 6831357e749239d5afec1dfd2d44a26ca6553e51
2020-02-03 06:25:26 -08:00
Samuel Susla 1041ad5651 Delete StateCoordinator
Summary:
StateCoordinator isn't used anymore.

Changelog: [internal]

Reviewed By: shergin

Differential Revision: D19500103

fbshipit-source-id: 6beb94b03ed04d17d58a8939626458c76eaa7e7e
2020-02-03 06:25:25 -08:00
Samuel Susla d418750359 Merge StateCoordinator into ShadowNodeFamily
Summary:
Changelog: [internal]

Merges all of responsibilities of `StateCoordinator` into `ShadowNodeFamily`.

Reviewed By: shergin

Differential Revision: D19500104

fbshipit-source-id: f31ffded5a840e722fd898eef6a9f52cd2186df7
2020-02-03 06:25:25 -08:00
Valentin Shergin facf5db260 Fabric: Test for reseting (and preserving) Yoga dirty flag during ShadowNode cloning
Summary:
This is a quite fragile and important part of the render engine. We need to dirty Yoga node only in cases where a change affects layout. In the case of over-dirtying, we can kill performance. In the case of under-dirtying, we can produce an incorrect layout.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19596279

fbshipit-source-id: 9f2ac67c44cb35c8ba44be1025b94b7921b74e17
2020-01-31 21:39:26 -08:00
Valentin Shergin 72d40f85b3 Fabric: Making `YogaStylableProps::yogaNode` public
Summary:
This is aligned with all simular changes that we do for `*Props` types (see D19583582 and D19390813).

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19596281

fbshipit-source-id: 283b89c65504e20a461b12c2d1218325c6621dd8
2020-01-31 21:39:26 -08:00
Valentin Shergin 4ae9ec128d Fabric: `RootShadowNode::layoutIfNeeded`
Summary:
Reasons:
 * The name of the method now better represent what it's doing;
 * It exposes information about "dirty" state of the node without opening actual `LayoutableShadowNode` protected APIs;
 * It's a tiny bit faster now because it checks the flag before calling Yoga.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19596282

fbshipit-source-id: 3d87d9d5ba20bb8e360683f149b5ebf90beecd65
2020-01-31 21:39:25 -08:00
Ramanpreet Nara cc50879f55 Clear all held jsi::Functions when jsi::Runtime is deleted
Summary:
After D19565499, the `LongLivedObjectCollection` will be cleared on the JS thread when the jsi::Runtime is deleted. This diff makes it so that we never hold strong references to `CallbackWrapper`s in our Android TurboModules infra. Therefore, we can leverage the changes in D19565499 to ensure that our `jsi::Function`s are deleted before the `jsi::Runtime`.

## Caveat
If you delete a TurboModule by itself, it's jsi::Functions that haven't been invoked won't be released. This is also the case for iOS. I plan to fix this for both iOS and Android at a later point in time.

Changelog:
[Android][Fixed] - Refactor jsi::Function cleanup in TurboModules

Reviewed By: mdvacca

Differential Revision: D19589151

fbshipit-source-id: efa3cc6c83634014159ac7500dcf6bef9c925762
2020-01-31 10:04:40 -08:00
Valentin Shergin b39c75f20e Fabric: `Element<>` now returns (and accepts) mutable (non const) shared pointers
Summary:
It makes perfect sense because `Builder` builds totally new shadow trees, so those are not sealed or used by anyone yet.
Assigning it to const shared pointer will do logical sealing (and it does not requires const-cast).
Fewer const-casts in the code, fewer bugs.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19596284

fbshipit-source-id: 75d1c706034958ba7e4bc80a68af75a57c46eb6f
2020-01-30 19:45:39 -08:00
Valentin Shergin d64bf2c4f8 Fabric: `Element<X>::children()` now accepts children of any `Element<>` type
Summary:
Before this change `Element<X>` cannot have children of `Element<Y>` which was wrong because we don't have such limitation in Fabric.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19596283

fbshipit-source-id: 9002f5dd42b3d05e7cf492499499399c97b58152
2020-01-30 19:45:39 -08:00
Valentin Shergin 42be1aad82 Fabric: Making ComponentBuilder copyable and movable
Summary:
It's useful property to have.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19596280

fbshipit-source-id: 5b60cc4f7c65c3458ff35ffa2dfaafce79dc985a
2020-01-30 19:45:38 -08:00
Joshua Gross 1c83e5a917 Includes in alphabetical order
Summary:
Formatting done by `arc f`

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D19653112

fbshipit-source-id: 4857e6d5a5f20e09de10c7fe0f9d9e12a312003c
2020-01-30 17:39:35 -08:00
Joshua Gross 74026041ba Fix AndroidTextInput C++ debugging code
Summary:
Fixes debug output for AndroidTextInput. Failed to compile (in special "Fabric debug mode") before.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D19653093

fbshipit-source-id: 887916892a78a4e40bb4f6154f474add9672edfb
2020-01-30 17:39:35 -08:00
Samuel Susla fdd133e214 Prevent getRelativeLayoutMetrics to measure across ShadowNode which is root
Summary:
Changelog: [Internal]

# Analysis
Measure returns following values for `frame.y` when tapping item in bottom sheet.

Fabric 412.33331298828125.
Paper 49.

In Paper, the frame.y returned is the position of tapped item in bottom sheet relative to the bottom sheet itself, which is correct.

This can happen in both BottomSheet and Modal.

# Why it happens?
In [UIManager.getRelativeLayoutMetrics](https://our.intern.facebook.com/intern/diffusion/FBS/browse/master/xplat/js/react-native-github/ReactCommon/fabric/uimanager/UIManager.cpp?commit=a372cf516ba1245ad9462e68376ee759c118a884&lines=172-181) if `ancestorShadowNode` is nullptr we populate `ancestorShadowNode` with `rootShadowNode` for the surface.
Problem is that BottomSheet that is presented, is not a separate surface. This means that we climb up the shadow node hierarchy all the way to root shadow node and keep adding offsets. Even though we should stop when we hit shadow node representing BottomSheet.

# How could be this fixed?

I think we should add a new shadow node trait that would mark node as root node. As we are traversing the shadow node tree upwards and adding offset of that node, once we hit a node that is "anchor",  we would immediately stop the traversal.
This solution is inspired by Paper where the node representing BottomSheet has a special flag which marks it as "root" node.

accepttoship

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D19640454

fbshipit-source-id: bde623b1f41a9745a41f0aada7221bf924fad453
2020-01-30 15:30:39 -08:00
Ramanpreet Nara 9ae95582e7 Clear all held jsi::Functions when jsi::Runtime is deleted
Summary:
## Description
You're not supposed to hold on to JSI objects (ex: `jsi::Function`) past the point where their `jsi::Runtime` is deleted. Otherwise, we get a dangling pointer crash, like this: T60262810! Historically, this cleanup problem has always been really tricky to get right. With this diff, I hope to fix that problem once and for all by deleting all `jsi::Function`s when we delete the global `__turboModuleProxy` function.

## Current Setup
- The TurboModules infra uses weak references to `CallbackWrapper`s to hold on to the `jsi::Function`s passed from JS to ObjC.
- The LongLivedObjectCollection holds on to strong references to `CallbackWrapper`s. This ensures that the `jsi::Function`s aren't deleted prematurely. This also means that we can use `LongLivedObjectCollection` to delete all `CallbackWrappers`.
- `TurboModuleBinding` is the abstraction we use to install the global `__turboModuleProxy` function. It is owned by `TurboModuleManager`, and `TurboModuleManager` uses it to clear all references to `jsi::Function`s, when we delete all NativeModules.

## Solution
1. Transfer ownership of `TurboModuleBinding` from `TurboModuleManager` to the `__turboModuleProxy` function.
2. Clear the `LongLivedObjectCollection` when `TurboModuleBinding` is deleted.

Changelog:
[iOS][Fixed] - Clear all held jsi::Functions when jsi::Runtime is deleted

Reviewed By: JoshuaGross

Differential Revision: D19565499

fbshipit-source-id: e3510ea04e72f6bda363a8fc3ee2be60303b70a6
2020-01-30 15:15:09 -08:00
Moti Zilberman 7001dc3fe0 Format JSCRuntime.cpp
Summary:
Formats `JSCRuntime.cpp`.

Changelog: [Internal]

Reviewed By: makovkastar

Differential Revision: D19602009

fbshipit-source-id: 4bcb0e4101e743d85e132319dcb2e35e341904ae
2020-01-30 10:29:15 -08:00
Samuel Susla 12b43ef418 Implement RCTFabricSurface.synchronouslyWaitForStage
Summary:
Changelog: [Internal]

Exposes `synchronouslyWaitForStage` to `RCTFabricSurface`.

This is a first step towards having screenshot tests rendered with Fabric.

Reviewed By: shergin

Differential Revision: D19603837

fbshipit-source-id: 26c14cf3bbd67fea96319ff08d3321557ddcdd9c
2020-01-30 10:11:12 -08:00
Pasquale Anatriello c3bde6ef0c Swap child Yoga
Summary:
Changelog: [Internal]

Expose the replaceChild Yoga call to Java

Reviewed By: SidharthGuglani

Differential Revision: D19497193

fbshipit-source-id: 153243cc1d8c23dcaf2c772ca794bd59a230f652
2020-01-30 03:43:47 -08:00
David Vacca 3c711600b6 Deprecate SharedShadowNode in favor of ShadowNode::Shared
Summary:
We are deprecating SharedShadowNode in favor of ShadowNode::Shared, the previous diff already removed most of the usages of SharedShadowNode

changelog: [internal]

Reviewed By: shergin

Differential Revision: D19217718

fbshipit-source-id: 1b7cd1af0ecdc6112befdc45c1dd0fca5012ab21
2020-01-29 21:06:55 -08:00
David Vacca 4bfe8937b6 Replace usage of SharedShadowNode for ShadowNode::Shared
Summary:
ShadowNode::Shared and SharedShadowNode represent the exact same type. Nowadays we use ShadowNode::Shared instead of SharedShadowNode.
This diff replaces usages of SharedShadowNode for ShadowNode::Shared in the fabric folder.

Changelog: [internal]

Reviewed By: shergin

Differential Revision: D19217717

fbshipit-source-id: 112331b22251aa3a3d5e183395c54f2ca0f56e47
2020-01-29 21:06:55 -08:00
Valentin Shergin b549d0ea9e Fabric: Test for ShadowNode trees Diffing algorithm
Summary:
Here is a mutation test for the Diffing algorithm that we use to diff ShadowNode trees and flatten them. As a side-effect, it also "tests" that Concurrent Yoga does not crash and produces decent cloning requests.

The test works this way:
1. We create a random ShadowNode tree;
2. We create a View tree from that that we continue to maintain;
3. We apply random mutation on this;
4. We layout the tree;
5. We generate the mutation instruction comparing a previous tree with a new one;
6. We apply mutations on the first tree;
7. We generate a new tree from scratch;
8. We compare the new tree with the tree updated with mutations and expect equivalence;
9. Repeat a million times.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D19357714

fbshipit-source-id: 04765ede87d91180952ae650ff0d505dfac2ed8e
2020-01-28 22:37:17 -08:00