Commit Graph

27 Commits

Author SHA1 Message Date
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 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
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
Samuel Susla 01805636b9 Move ShadowNode::getAncestors to ShadowNodeFamily
Summary:
Changelog: [internal]

1. Moves `ShadowNode::getAncestors` to `ShadowNodeFamily`.
2. Exposes shadowNode's family through `ShadowNode::getFamily()`.

# Why?
This is a first step in order to merge `StateCoordinator` into `ShadowNodeFamily` and use it as target for state updates.

Reviewed By: shergin

Differential Revision: D19465188

fbshipit-source-id: b5a3625aa21c040301259de02beedbf97e11f20e
2020-01-28 09:32:52 -08:00
Samuel Susla 61f7639d38 Fabric: Remove eventEmitter from ShadowNodeFragment
Summary:
As part of the plan is splitting ShadowNodeFragment into two parts. ShadowNodeFamilyFragment is already in place. This diff removes use of `ShadowNodeFragment::eventEmitter` and goes over all call sites to change it to `ShadowNodeFamilyFragment::surfaceId`.
Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D19146697

fbshipit-source-id: 22cae5404b0f3098feb86c0437a4aa256d5b773e
2019-12-19 13:48:22 -08:00
Samuel Susla 97f1c053b3 Fabric: Remove surfaceId from ShadowNodeFragment
Summary:
As part of the plan is splitting `ShadowNodeFragment` into two parts. `ShadowNodeFamilyFragment` is already in place. This diff removes use of `ShadowNodeFragment::surfaceId` and goes over all call sites to change it to `ShadowNodeFamilyFragment::surfaceId`.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D19115785

fbshipit-source-id: 5972332c3360b88ca935581ed36070f26e678b22
2019-12-19 13:48:22 -08:00
Samuel Susla f9c5bf8bee Fabric: Remove tag from ShadowNodeFragment
Summary:
As part of the plan is splitting `ShadowNodeFragment` into two parts. `ShadowNodeFamilyFragment` is already in place. This diff removes use of `ShadowNodeFragment::tag` and goes over all call sites to change it to `ShadowNodeFamilyFragment::tag`.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D19115781

fbshipit-source-id: 6ab3464a063c220d0924bf5a69b75449ca178650
2019-12-19 13:48:22 -08:00
Valentin Shergin b5080f7d77 Fabric: Fixing arbitrary-node-replacing (aka RootShadowNode::clone) algorithm
Summary:
This diff changes how arbitrary-node-replacing (aka `RootShadowNode::clone`) algorithm works.
Original implementation worked this way: We specified a node that needs to be replaced and a new replacement node. Then the algorithm finds a node with *the same family* as given the to-be-replaced node and replaced that with a given replacement.
The problem with this approach is that we are replacing a node that we have very little info about (we only know that it shares the same family as specified one). At the same time, we build the replacement based on the exact node that we have. Then imagine the case in which the "target" node can progress/change between a moment where we get a reference to it and a moment where we are trying to clone the tree. In this case, we will replace a "progressed" node with a modified version of the obsolete node.
Practically speaking, it was possible that during a state update we were replacing a node that just got new children with a bit older version of that with old children but with a new state.

How to deal with it? This diff introduces a new interface for this method that allows separating the target node and the actual act of cloning the corresponding node. Instead of specifying actual replacement, we now specify a function that performs the cloning/transformation on-demand on the very exact node that was in the tree at the moment of cloning.

This change does not change/affect any ownership-related relationships between trees and/or nodes.

Ideally, probably, the interface should accept ShadowNodeFamily instance instead of a ShadowNode instance to make the behavior very clear but that requires a bunch of low-level changes that it out of the scope of this fix.

```

                                                                   The old approach.

                     ┌─────────────────┐                          ┌─────────────────┐                          ┌─────────────────┐
                     │                 │                          │                 │                          │                 │
                     │      A(r0)      │                          │      A(r1)      │                          │      A(r2)      │
                     │                 │                          │                 │                          │                 │
                     └─────────────────┘                          └─────────────────┘                          └─────────────────┘
                              │                                            │                                            │
                              │          Let's update the                  │   Meanwhile the node B                     │
                              ▼           state of this                    ▼    gets new children.                      ▼
                     ┌─────────────────┐   node to s1.            ┌─────────────────┐                          ┌─────────────────┐
                     │                 │                          │                 │                          │                 │   Created
                     │    B(r0, s0)    │         ───────▶         │    B(r1, s0)    │         ───────▶         │    B(r2, s1)    │     from
                     │                 │                          │                 │                          │                 │    B(r0).
                     └─────────────────┘                          └─────────────────┘                          └─────────────────┘
                              │                                            │                                            │
                       ┌──────┴──────┐                       ┌─────────────┼─────────────┐                       ┌──────┴──────┐
                       │             │                       │             │             │                       │             │    What just
                       ▼             ▼                       ▼             ▼             ▼                       ▼             ▼     happe..?
                 ┌───────────┐ ┌───────────┐           ┌───────────┐ ┌───────────┐ ┌───────────┐           ┌───────────┐ ┌───────────┐
                 │           │ │           │           │           │ │           │ │           │           │           │ │           │
                 │   C(r0)   │ │   D(r0)   │           │   C(r1)   │ │   D(r1)   │ │   X(r0)   │           │   C(r0)   │ │   D(r0)   │
                 │           │ │           │           │           │ │           │ │           │           │           │ │           │
                 └───────────┘ └───────────┘           └───────────┘ └───────────┘ └───────────┘           └───────────┘ └───────────┘

                                                                   The new approach.

                     ┌─────────────────┐                          ┌─────────────────┐                           ┌─────────────────┐
                     │                 │                          │                 │                           │                 │
                     │      A(r0)      │                          │      A(r1)      │                           │      A(r2)      │
                     │                 │                          │                 │                           │                 │
                     └─────────────────┘                          └─────────────────┘                           └─────────────────┘
                              │                                            │                                             │
                              │         Let's update the                   │                                             │
                              ▼          state of this                     ▼                                             ▼
                     ┌─────────────────┐  node to s1.             ┌─────────────────┐                           ┌─────────────────┐
                     │                 │                          │                 │                           │                 │   Created
                     │    B(r0, s0)    │         ───────▶         │    B(r1, s0)    │         ───────▶          │    B(r2, s1)    │     from
                     │                 │                          │                 │                           │                 │    B(r1).
                     └─────────────────┘                          └─────────────────┘                           └─────────────────┘
                              │                                            │                                             │
                       ┌──────┴──────┐                       ┌─────────────┼─────────────┐                 ┌─────────────┼─────────────┐
                       │             │                       │             │             │                 │             │             │
                       ▼             ▼                       ▼             ▼             ▼                 ▼             ▼             ▼
                 ┌───────────┐ ┌───────────┐           ┌───────────┐ ┌───────────┐ ┌───────────┐     ┌───────────┐ ┌───────────┐ ┌───────────┐
                 │           │ │           │           │           │ │           │ │           │     │           │ │           │ │           │
                 │   C(r0)   │ │   D(r0)   │           │   C(r1)   │ │   D(r1)   │ │   X(r0)   │     │   C(r1)   │ │   D(r1)   │ │   X(r0)   │
                 │           │ │           │           │           │ │           │ │           │     │           │ │           │ │           │
                 └───────────┘ └───────────┘           └───────────┘ └───────────┘ └───────────┘     └───────────┘ └───────────┘ └───────────┘

```

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross

Differential Revision: D18229704

fbshipit-source-id: face6d0e5c240224ce49e93e783cff3172b60529
2019-10-31 09:38:39 -07:00
Valentin Shergin c5f704b8e3 Changing signature of RootShadowNode::clone() to remove a shared_from_this() call
Summary:
This is the first diff in the journey of removing `enable_shared_from_this` from `ShadowNode` class.

In general, using `enable_shared_from_this` is fine, it's a normal standard feature and there is nothing wrong with that... besides the fact that using this thing is usually an indication of overall poor design.
In Fabric, we don't really have a good reason for that, I think in all cases it can be avoided, so I think we should remove that.
Removing that is also code-size and perf win.

This particular diff changes the signature of `RootShadowNode::clone()` which allows removing the necessity  of usage `.shared_from_this()` from callsites.
The rest changes are purely cosmetical.

Changelog: [Internal] Small Fabric-specific optimization.

Reviewed By: sammy-SC

Differential Revision: D17973958

fbshipit-source-id: 5539ceff9d11b4281a6ebe8d80e90d6bd90e44d8
2019-10-21 09:44:25 -07:00
Andres Suarez 3b31e69e28 Tidy up license headers [2/n]
Summary: Changelog: [General] [Fixed] - License header cleanup

Reviewed By: yungsters

Differential Revision: D17952694

fbshipit-source-id: 17c87de7ebb271fa2ac8d00af72a4d1addef8bd0
2019-10-16 10:06:34 -07:00
Valentin Shergin ea8a57116f Fabric: A new way to compute nodes for onLayout event
Summary:
Previously we computed the list of nodes that need to be notified about layout changes using a list of mutation instructions. That was fine, but that's not really compatible with some other changes that I plan to make, so I decided to change it (make it better).

Besides the better design (debatable; fewer dependencies to unrelated moving pieces), here is why I believe the new way is more performant:

* The new approach has no `dynamic_casts`, whereas the previous has tons of them (two per a mutation). If a `dynamic_cast` takes 10 ns, for 500 nodes it can take up to 5ms only for casts. (Non-scientific assumption.)
* After removing dependency to mutation instruction, we can enable flattening for views which have `onLayout` event.

Reviewed By: mdvacca

Differential Revision: D15110725

fbshipit-source-id: 31a657ccfd02441734ad1d71a833653223163289
2019-05-01 16:27:55 -07:00
Valentin Shergin 035e0403bb Fabric: ShadowNodeFragment::rootTag was renamed to surfaceId
Summary:
Trivial.
We are replacing rootTag with surfaceId according to the plan describing here: https://fb.workplace.com/groups/rn.fabric/permalink/1374002366064519/

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D15039134

fbshipit-source-id: ec8c3044f9f3f23939488bc01c66e9b653e651dd
2019-04-29 21:21:10 -07:00
Valentin Shergin 4602bf5cc6 Fabric: Using ShadowNode::getAncestors in RootShadowNode::clone
Summary: The basic idea of the implementation is the same, but it uses the new method for finding parenting chain and it does not use `shared_from_this()` anymore.

Reviewed By: JoshuaGross

Differential Revision: D14416949

fbshipit-source-id: 13ef928505a60280e2a6c30c76ac87d91cee326e
2019-03-18 23:56:13 -07:00
Valentin Shergin b93221036a Fabric: Removed unnecessary call in RootShadowNode::clone
Summary: The removed code does nothing because we are replacing the oldChild with newChild several lines above.

Reviewed By: JoshuaGross

Differential Revision: D14402637

fbshipit-source-id: 731a950f373e20f7d5bae3cbf6470335d3694ccc
2019-03-18 23:56:13 -07:00
Valentin Shergin 32d5c7e1f3 Fabric: Checking getHasNewLayout in RootShadowNode
Summary:
As a comment above changed lines states, RootShadowNode is a special one because it layouts itself. In normal case some parent node layouts its children, and it also checks getHasNewLayout flag. So, in the case of RootShadowNode it has to check its own flag by itself.
That fix should save some resources and generally correct.

After the change, changing a state of some node does not cause relayout process. If dirtying is required, the component should call `dirtyLayout()` explicitly in the constructor or in `adopt` method.

Reviewed By: JoshuaGross

Differential Revision: D14472751

fbshipit-source-id: 75bf62ac28991a39e5664aa71c08bd0e64fa275b
2019-03-18 19:21:25 -07:00
empyrical b30b10326e Fabric: Remove designated initializers in RootShadowNode (#23715)
Summary:
This pull request removes the designated initializers in `RootShadowNode.cpp`. This will help improve the portability of this file.

[General] [Fixed] - Removed designated initializers in `RootShadowNode`
Pull Request resolved: https://github.com/facebook/react-native/pull/23715

Differential Revision: D14305167

Pulled By: shergin

fbshipit-source-id: e394580f103fdb59cf078828b5d2ee6df6cc534d
2019-03-04 14:41:30 -08:00
Valentin Shergin af1808de69 Fabric: RootShadowNode::clone() fix
Summary:
The previous implementation of the method cloned the root node twice (one time at the very end of the method and one time at the end of loop body).
The new one does it once and a bit more readable.

Reviewed By: mdvacca

Differential Revision: D14187969

fbshipit-source-id: 9859deadd4b041ac115c37108188aab70200c75d
2019-02-25 12:21:01 -08:00
Valentin Shergin 77838b5504 Fabric: Systraces are back
Summary:
It's better to comment `DWITH_FBSYSTRACE` out in BUCK files instead of removing them from the code.
I'll publish the BUCK changes as separate diff for simpler backout in the future.

Reviewed By: mdvacca

Differential Revision: D14019272

fbshipit-source-id: 8b322b5c115efe33c15929e008b97a05220813df
2019-02-11 16:01:05 -08:00
David Vacca 842b9c106a Temporary remove systraces from Fabric core code
Summary: This is a temporary change to measure production data

Reviewed By: fkgozali

Differential Revision: D13906807

fbshipit-source-id: 2a2f71aa379c4aca63c7bb4a9644704f713cb088
2019-02-02 13:08:06 -08:00
Valentin Shergin 84cf657308 Fabric: ShadowTree::completeByReplacingShadowNode was moved to RootShadowNode
Summary:
Removing additional complexity from ShadowTree should help with maintainability. Now, this class is "tricky", but short at least.
With new `commit` API, it's much more simple and expected this way.

Reviewed By: sahrens

Differential Revision: D13615365

fbshipit-source-id: 1fe851c1a2d3bdc7ac2f4a570cf0170eae3c4c67
2019-01-16 20:22:39 -08:00
Valentin Shergin c937300f5d Fabric: Layout-related methods were removed from ShadowTree
Summary: Now it's parts of RootShadowNode and Scheduler.

Reviewed By: sahrens

Differential Revision: D13615364

fbshipit-source-id: 13dbea1e69ef51b2679101915c01c6be7e15d859
2019-01-16 20:22:39 -08:00
David Vacca 3b4d6d5ef5 Add systrace to calculation of Yoga layout() in Fabric
Summary: Simple diff that adds a systrace to start measuring the calculation of Yoga layout() in Fabric

Reviewed By: shergin

Differential Revision: D13124641

fbshipit-source-id: 6bd03e9f56524221f5d91606ffde50253673c1bb
2018-11-25 17:20:59 -08:00
Valentin Shergin 94d49e544d Fabric: Codemod: All <fabric/... includes were renamed to <react/...
Summary: We are moving to more stable APIs removing all mentiones of the effort name from the codebase.

Reviewed By: mdvacca

Differential Revision: D12912894

fbshipit-source-id: 4a0c6b9e7454b8b14e62d419e9e9311dc0c56e7a
2018-11-10 14:22:15 -08:00
Héctor Ramos 1151c096da Update copyright headers to yearless format
Summary: This change drops the year from the copyright headers and the LICENSE file.

Reviewed By: yungsters

Differential Revision: D9727774

fbshipit-source-id: df4fc1e4390733fe774b1a160dd41b4a3d83302a
2018-09-11 15:33:07 -07:00
Valentin Shergin 67a79010ca Fabric: Simplified way to specialize ComponentName in ConcreteShadowNode class template
Summary:
@public
Previously, all ConcreteShadowNode subclasses had to override `getComponentName()` function to specialize a name of the component. And often it was all that those subclasses do. Now, it's a template argument; and many ShadowNode classes can be created as oneliners via *just* specializing  ConcreteShadowNode template.

Unfortunately, C++ does not allow to use `std::string`s or string literals as template arguments, but it allows to use pointers. Moreover, those pointers must point to some linked data, hence, those values must be declared in .cpp (not .h) files. For simplicity, we put those constants in Props classes, (but this is not a strong requirement).

Reviewed By: mdvacca

Differential Revision: D8942826

fbshipit-source-id: 4fd517e2485eb8f8c20a51df9b3496941856d8a5
2018-08-04 09:47:30 -07:00
Valentin Shergin e9e20e6c83 Fabric: <Root> component was decoupled from <View>
Summary:
@public
There is no reason to have it inside View; it deserves that.

Reviewed By: mdvacca

Differential Revision: D8757012

fbshipit-source-id: 881b54008b51614cd203ab97811494fa7c30e4ef
2018-07-15 16:52:26 -07:00