Commit Graph

14 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 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
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 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
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
Valentin Shergin 3ad5c9e016 Fabric: Enabling clang-format for half of Fabric modules
Summary:
All code styles are terribly ugly. We have the only choise - choise something and embrace it.
This particular code style was borrowed from a neibour Fabric-friendly project because it follows established Facebook guides and respects client-side traditions.

Reviewed By: mdvacca

Differential Revision: D10218598

fbshipit-source-id: 8c4cf6713c07768566dadef479191661c79988f0
2018-10-05 11:03:23 -07: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