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

1759 Коммитов

Автор SHA1 Сообщение Дата
Valentin Shergin 2111f205ae Fabric: Removing `SharedYogaStylableProps` and small codestyle changes
Summary: Trivial. We don't use it.

Reviewed By: sammy-SC

Differential Revision: D16139556

fbshipit-source-id: bac282c1aa228c10d27ebd636cf71fcc33b322e9
2019-07-08 21:10:47 -07:00
Ashok Menon 424f93022d Use iosfwd instead of iostream
Summary:
The instrumentation header only needs the forward declarations for ostream, so
we can use just include `iosfwd`, as suggested by Riley in an earlier diff.

Reviewed By: kodafb

Differential Revision: D16152451

fbshipit-source-id: 2afbc40e623b180dfc5917fc8093ab15bf647968
2019-07-08 14:56:44 -07:00
Samuel Susla faf9130560 fabric: Migrate ModalHostView
Summary: Implements `ModalHostView` in Fabric.

Reviewed By: shergin

Differential Revision: D16090949

fbshipit-source-id: fe2c87063863e7f3c6c8dcc934a2cdb0b1aedaac
2019-07-08 03:56:31 -07:00
Valentin Shergin 06ce568155 Fabric: Use state in Paragraph component
Summary:
All props to Eric Lewis! cc ericlewis

This revert of revert of land of changes originally published in #24873 (with some slight fixes). The change removes usage of LocalData from the `<Text>` component.

After this change we only have ---one (maybe two)--- three components left using LocalData.

Reviewed By: mdvacca

Differential Revision: D15962376

fbshipit-source-id: 19f41109ce9d71ce30d618a45eb2b547a11f29a2
2019-07-07 22:46:21 -07:00
David Vacca d07ab35bfb Expose LayoutDirection to Fabric android
Summary: This diff exposes LayoutDirection as part of UpdateLayoutMountItem

Reviewed By: JoshuaGross

Differential Revision: D16060521

fbshipit-source-id: 163bf2a0bdca62dcecb03a8aaa2f4bf595b18c8f
2019-07-02 14:47:21 -07:00
David Vacca 3c2395212c Update parsing of textAlign prop for Text
Summary: This fixes the parsing of textAlign prop in BaseTextProps class. The name is textAlign and not alignment.

Reviewed By: JoshuaGross

Differential Revision: D16057477

fbshipit-source-id: a00a472af4c7df0a6cd3d6efb17b30cd9134907b
2019-07-02 14:47:21 -07:00
Uladzislau Paulovich ce9c47f34b Remove incorrect constexpr specifier in YGLayout (#25430)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/25430

Pull Request resolved: https://github.com/facebook/litho/pull/561

Pull Request resolved: https://github.com/facebook/yoga/pull/910

* According to C++ standard values which produce undefined behavior cannot be declared as `constexpr`.
* Expressions which evaluate to `nan, infinity, etc` are undefined behavior.

For more details you can checkout this Stackoverflow answer: https://stackoverflow.com/a/46373136

Reviewed By: davidaurelio

Differential Revision: D16055108

fbshipit-source-id: ee85ba63a714b18bfb8aa8c0770652e184454f74
2019-07-01 08:51:41 -07:00
Valentin Shergin 902541e874 Fabric: Fixing a concurrency issue in RawProp parsing infra
Summary:
Previously, we stored `keyIndex_` in a Parser object which is incorrect because it makes the parsing process thread-unsafe (the Parser is shared between parsing processes).

That worked previously most of the time because we never parsed props concurrently but we actually do this in the native animation library.

Reviewed By: yungsters

Differential Revision: D16064557

fbshipit-source-id: 211f4301d0746e0f5126a1dcdd59f1ae9a420aa9
2019-06-28 22:53:45 -07:00
David Aurelio 0d89653dd6 Move `YG_ENABLE_EVENTS` checks to `event.h`
Summary:
Instead of checking whether `YG_ENABLE_EVENTS` is defined for every publish, we simply wrap the body of the `publish` function macro that delegates to the method that actually publishes the event.

This way we get

1. easier to write code where we publish events
2. more type safety when editing, enabling editors/IDEs to show errors without knowing about `YG_ENABLE_EVENTS`

Reviewed By: SidharthGuglani

Differential Revision: D16049888

fbshipit-source-id: cbf362d6f7be5053c3f377125d303b7137d6a241
2019-06-28 09:59:06 -07:00
David Aurelio 792f715178 Stop recording measure callback duration
Summary: Removes time measurements for measure callbacks. This functionality should not be part of Yoga/core, and can now be done by event subscribers themselves, as we have two events per measure callback.

Reviewed By: SidharthGuglani

Differential Revision: D16049812

fbshipit-source-id: e16556f3854e42f4bada39a97a668e718719b22c
2019-06-28 09:59:05 -07:00
David Aurelio 2985ddbc33 Publish two events for measure callbacks
Summary: Publishing two events will allow us to replace marker functionality completely with events. This also allows us to remove measuring time spent from Yoga itself.

Reviewed By: SidharthGuglani

Differential Revision: D16049810

fbshipit-source-id: 98628a92ed3c94d479e9fbcd53fac90c5f524087
2019-06-28 09:59:05 -07:00
Ashok Menon 14686259d9 Create Snapshot From Stream
Summary:
Adding an instrumentation endpoint that allows us to write a snapshot out to an
arbitrary output stream.  This is in addition to `createSnapshotFromFile`.  I
reserve the right to replace the latter with the former in a later diff.

This is necessary to allow snapshots to be requested over the chrome debugger
protocol.  The protocol sends the snapshot over the wire in chunks so we need
to be able to use an output stream that can do the chunking.

Because LLVM types are not available at the JSI layer, we accept a
`std::ostream` reference which we wrap with `llvm::raw_os_ostream` within
Hermes.  We should not incur the static initializer cost (or other code bloat)
of using ostreams as a result.

Reviewed By: cwdick

Differential Revision: D16016319

fbshipit-source-id: 2d0b4848fd5cbe9ddee371d856cd8eb19dd80396
2019-06-28 06:15:33 -07:00
David Aurelio 18eba792dd Remove duplicate declaration of `YGRoundValueToPixelGrid` from `Yoga-internal.h`
Summary:
@public

Removes the declaration of `YGRoundValueToPixelGrid` from `Yoga-internal.h`, as it is already declared in `Yoga.h`. `Yoga.h` is included from `Yoga-internal.h`

Reviewed By: SidharthGuglani

Differential Revision: D16047832

fbshipit-source-id: 72d9d2510372c983eedacc5d7af406b9346f18e6
2019-06-28 05:17:51 -07:00
Ashok Menon bbf093a03b Remove const_cast in createSnapshotFromFile wrapper.
Summary:
The function is not annotated with `const` so `plain()` will return a non-const
reference to the undecorated Runtime already.  Seems like the const_cast was a
hold-over from a previous iteration.

Reviewed By: mhorowitz

Differential Revision: D16016320

fbshipit-source-id: 3dfa1e9acf2fc5c1ad61c9a8cd27c3c2e42036d3
2019-06-27 10:02:26 -07:00
Kevin Gozali b25d22aae6 Use YOGA_CXX_TARGET alias for Buck deps
Summary: Proper abstraction to make BUCK files more OSS friendly.

Reviewed By: shergin

Differential Revision: D15998817

fbshipit-source-id: cad2498f62a8774037e754e8b52200f0dcc5af59
2019-06-26 11:19:34 -07:00
Valentin Shergin 543c5a0164 Fabric: ShadowNode::getMostRecentState()
Summary: In some cases, we cannot retrieve the "committed" state because no one state was mounted yet. The whole concept of "confirmed" or "legit at the moment" is kinda overstatement. The actual meaning of this is "the last vision of the state to which we advanced so far"; it does not have any relation to the actual "commit" phase or "mounting" process.

Reviewed By: sammy-SC

Differential Revision: D16002127

fbshipit-source-id: 95465e632525f873ae67f6db320a89562b62ba29
2019-06-26 10:05:34 -07:00
dattc2 1dbc38ad93 make yoga threadsafe (#852)
Summary:
Continuing https://github.com/facebook/yoga/pull/791
nokia6686 is a former member of our team, so we are trying to pick up what he left and carry out the pull request.
# Solution
Improved from previous solution with jpap's suggestions.
2. Passing ```gDepth``` and ```gCurrentGenerationCount``` (renamed to **_depth_** and **_generationCount_** respectively) between function calls that stem from ```YGNodeCalculateLayout```.
In ```YGNodeCalculateLayout```, pass ```depth``` as value 0, to indicate the root depth.
Pull Request resolved: https://github.com/facebook/yoga/pull/852

Reviewed By: SidharthGuglani

Differential Revision: D15537450

Pulled By: davidaurelio

fbshipit-source-id: 338f51383591ba27702ebe759f6c47c2dede3530
2019-06-26 10:05:32 -07:00
Valentin Shergin b491e8725a Fabric: ShadowNode::getCommitedState() does not crash now in case if there is no comited state
Summary: `Target` inside the Stage can be empty; in this case, we should not try to extract `ShadowNode` from it.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D15982479

fbshipit-source-id: 83a4bebadc88b59d7fe77acbdf07e8ce9f2f6be1
2019-06-26 10:05:30 -07:00
Sidharth Guglani 055b28b4f4 pass cachedLayout and cachedMeasure measures to plugin
Summary: Passing whether layout cache or measure cache was used or not

Reviewed By: davidaurelio

Differential Revision: D15920937

fbshipit-source-id: a6728e7af07ea228a285f824fbdfddc8130c5990
2019-06-24 08:35:34 -07:00
Sidharth Guglani 4332a28750 Move event NodeLayout to end of NodeLayout step
Summary:
Added event NodeLayoutEnd and this is being used now instead of NodeLayout
It will be used later to add more information about caches

Reviewed By: davidaurelio

Differential Revision: D15920935

fbshipit-source-id: c9f5e193bc8cc70d26ff5d84882d483c9b09f67d
2019-06-24 08:35:34 -07:00
Valentin Shergin 27b672993d Fabric: Unification of ShadowView's default constructor
Summary:
The previous version of a set of default values of `ShadowView`'s fields has a bug:
```
  ComponentName componentName = "";
```

Initalizing `char const *` with a string literal in .h file makes the default constructor of the object produces different values across binary units (because a pointer to empty string can be defined differently). Now it's just a null pointer.

Reviewed By: sammy-SC

Differential Revision: D15911452

fbshipit-source-id: 16bcfb5f78ea802c0833135c486e3fbb8b7acaa6
2019-06-23 21:33:18 -07:00
Valentin Shergin bca4e4c8a4 Fabric: Additional static asserts in Differentiator
Summary: I am about to change the definition of ShadowView a bit, so I think we need to ensure that we don't regress move semantic.

Reviewed By: JoshuaGross, sammy-SC

Differential Revision: D15911453

fbshipit-source-id: ce2cd4cb2375ecb76295948a1e9b5d2e7fb80f38
2019-06-23 21:33:18 -07:00
Valentin Shergin bd19f3bd13 Fabric: ShadowNode::getCommitedState() now returns by value
Summary: Returning a shared pointer by const reference in this context is not correct/safe because the object (the ShadowNode) doesn't own the object, so the caller cannot reason about the lifetime (esp. in a multithreaded environment).

Reviewed By: mdvacca

Differential Revision: D15958737

fbshipit-source-id: 8f03e6530d07d63ece5f955055c5c67c204b8223
2019-06-22 18:50:33 -07:00
Kevin Gozali 01a42bc368 TM iOS: Prevent module cache invalidation race
Summary: There are still race condition during bridge invalidation. Some modules may be accessing other modules during invalidation, but it's racing with the TM manager clearing the cache.

Reviewed By: JoshuaGross

Differential Revision: D15947488

fbshipit-source-id: 3bd51382264f538a03ca565b0f099da40c3daadf
2019-06-21 15:54:01 -07:00
zhongwuzw af59323d81 TM: Backward compatibility of calling invalidate on module's method queue (#25264)
Summary:
Backward compatibility for `invalidate` method, because for the old module system, we ensure call all methods of modules on `methodQueue`, we also need to keep this rule to avoid some race condition in module.

## Changelog

[iOS] [Fixed] - Backward compatibility of calling invalidate on module's method queue
Pull Request resolved: https://github.com/facebook/react-native/pull/25264

Test Plan: Ensure `invalidate` method of `module` be called on `methodQueue`.

Reviewed By: PeteTheHeat, JoshuaGross

Differential Revision: D15944532

Pulled By: fkgozali

fbshipit-source-id: e260792bc6b86a48cdf376282063cbabccbf26f0
2019-06-21 15:54:01 -07:00
David Vacca 4f4d3857ea Back out "[Fabric][C++] Backout Force Diffing algorithm to insert views Bottom Up"
Summary: Original commit changeset: 455034ce7b70

Reviewed By: JoshuaGross

Differential Revision: D15900818

fbshipit-source-id: c197aaedde1ab32e2e1a5764eb400600ab46b840
2019-06-21 11:52:56 -07:00
David Aurelio 52e4c8df6c Replace relative include
Summary: Replaces the relative include to `YGEnums.h` in `yoga/event/event.h` with `#include <yoga/YGEnums.h>

Reviewed By: SidharthGuglani

Differential Revision: D15778634

fbshipit-source-id: 2bceeb58f26c0d9d0df6c0e7ea20b8ddf68a1ee5
2019-06-21 04:09:52 -07:00
Sidharth Guglani fc82c59be7 Send measure pass duration
Summary: Send measure callback duration time to yoga plugin

Reviewed By: davidaurelio

Differential Revision: D15917548

fbshipit-source-id: 2c947f14ddbc5932cedd0aab8622260478ec29a6
2019-06-21 02:33:02 -07:00
Valentin Shergin 044176925b Fabric: Disabling RN_SHADOW_TREE_INTROSPECTION
Summary:
It's unclear why, but the introspection infra is enabled somehow in prod.
It must be some kind of misconfiguration somewhere. Until we figure it now, we have to disable it completly.

Reviewed By: mdvacca

Differential Revision: D15908765

fbshipit-source-id: 2b17c61938731d43eaef51b070a4ec1ae9e5e1df
2019-06-19 18:07:11 -07:00
Valentin Shergin 6f97733bb8 Fabric: Changing `ComponentName` type alias from `std::string` to `char *`
Summary:
ComponentName is used by many core component of React Native, such as ComponentDescriptor, ShadowNode, ShadowView and so on. In all those cases this value represents the actual name of the component which came from `concreteComponentName` template parameter of ConcreteShadowNode. In all of those cases, it's raw `char const *` type. So, we don't need to use owning representation of the string (std::string) in all those places.

The only exception from this is a part where we receive the name of the component from JS side. In this case, the source string comes from JS and has to be analyzed as a character sequence to find corresponding ComponentDescriptor.

In my experiments, 20% of the time during diffing is spent on copying (this) `std::string`.

Reviewed By: mdvacca

Differential Revision: D15844407

fbshipit-source-id: a2e71505e22d09107e001bdf661d4a826bcf2dea
2019-06-18 11:31:20 -07:00
Valentin Shergin 5d18e9aa16 Fabric: Workaround for weird crash in RCTImageManager
Summary: Seems RCTImageLoader is not thread-safe, so we need to compensate for this for now. Classic RN mostly accesses the loader from the main thread (non-concurrently), so it mostly works for Paper.

Reviewed By: mdvacca

Differential Revision: D15867574

fbshipit-source-id: 4aad5570b57a136aa0bbe31d65f1afe2ae6e380e
2019-06-17 21:18:54 -07:00
David Aurelio 853c667eb5 Allow to end markers early
Summary:
Adds the ability to `MarkerSection` to end the marker before it goes out of scope.

This unlocks two scenarios:
- reuse the data associated with a marker after ending it.
- end markers in the middle of a function without adding arbitrary blocks.

Reviewed By: SidharthGuglani

Differential Revision: D15837840

fbshipit-source-id: c0afaeeabd169c65189b5028be54ea7dac3e3b84
2019-06-15 10:19:33 -07:00
David Aurelio 3ce9ac6eed Count the number measure callback invocations
Summary: Counts how many times measure callbacks have been invoked during a layout pass. This is made available via the marker and event APIs.

Reviewed By: SidharthGuglani

Differential Revision: D15836983

fbshipit-source-id: 3835bef94e497375821c9f2ad8209447b4f11518
2019-06-15 10:19:33 -07:00
Kevin Gozali 72e276a0f0 TM iOS: Keep LongLivedObject longer past invalidation
Summary:
There can be a race condition between bridge invalidation (hence TM binding invalidation) with pending Promise reject/resolve invocation. If invalidation happens first, invoking the resolve/reject from ObjC class might end up accessing destroyed PromiseWrapper, causing hard crash randomly.

The proper fix is to switch the objc promise resolve/reject block (objc block) to use C++ PromiseWrapper directly, such that the lifecycle of the shared_ptr<> can be correct.

Reviewed By: RSNara

Differential Revision: D15801403

fbshipit-source-id: 9b0c7d323b18d94e920ea3eafc3a6916dadba247
2019-06-13 09:13:51 -07:00
Ramanpreet Nara e908f7a3fe Fix TurboCxxModules::get
Summary: Make `TurboCxxModule::get` return `undefined` when trying to access methods that don't exist. This is what `TurboModule::get` does. So, it makes sense that this behaviour is preserved in TurboCxxModule.

Reviewed By: mdvacca

Differential Revision: D15780044

fbshipit-source-id: 13aeae081655735ef634f1dc09c0dc70a3a3a893
2019-06-13 09:07:24 -07:00
Valentin Shergin 874f656435 Fabric: Rethinking of prop parsing infra
Summary:
This diff reimplements the prop parsing infrastructure in a part where it interacts with RawProps value.

Local synthetic tests show that the new way is 3x faster but the actual production result is quite unpredictable. MobileLab tests show some improvements about 10-20 ms on iPhone 6.

In short, the new way is faster because it inverts the lookup order and heavily relies on actual data types (and their properties) that we use. The old approach required about 130 hash-map lookups (where the key is `std::string`) to parse a single *Props object.
The new approach prepares concrete-props-specific tables with indexes of coming values ahead of time,  iterates over raw data and puts it into those tables, and then performs a lookup in a very efficient manner.

Reviewed By: JoshuaGross

Differential Revision: D15752968

fbshipit-source-id: 847106e652eb7fc7ef7b99884a6f819ea3b9fd06
2019-06-12 21:35:21 -07:00
Valentin Shergin 4d35e4d92c Fabric: Make RootProps constructible from RawProps
Summary: Even though it makes no sense to construct RootProps from RawProps, we need to support that (even if it's no-op) to be able to call this once from generic `ConcreteComponentDescriptor`. We will need it in the coming diff.

Reviewed By: mdvacca

Differential Revision: D15752970

fbshipit-source-id: b75a4023c5d0425a8dbe0f104a36a0f265eb6084
2019-06-12 21:35:20 -07:00
Valentin Shergin 4a4fabf835 Fabric: `LIKELY/UNLIKELY` annotations in props convertion infra
Summary:
In theory, those annotations can help the compiler to emit more optimized code and/or code that suggest CPU the proper way to utilize the instruction pipeline after the coming branch.
TBH, it's not clear how exactly beneficial those annotations are (esp. on target architectures) but they certainly don't hurt (in all cases here the favorite code branch is obvious).

Reviewed By: mdvacca

Differential Revision: D15752969

fbshipit-source-id: 8adf25a48107ffde828f735fb1386b30dbe63ede
2019-06-12 21:35:20 -07:00
Valentin Shergin 1b4c765099 Fabric: Using `char const *` instead of `std::string` in prop parsing infra
Summary:
Previously we used `std::string` as a type behind all prop names (and name fragments). Even if `std::string` converted from `char const *` should be heavily optimized by STL and compiler, we still concatenate and copy those strings a lot. Switching to `char const *` allows avoiding tons of copying and inefficient equality checks.
Besides that, the future, more sophisticated optimization will rely on this.

Reviewed By: mdvacca

Differential Revision: D15511493

fbshipit-source-id: 9f509d18f0c737f7f77d4fea192d2ed1872e3731
2019-06-12 21:35:20 -07:00
Valentin Shergin 69e8816bbe Fabric: Prop parsing tweek: `RawProps::isEmpty()`
Summary: This is a small perf tweak that alone does not give much improvement but the coming diffs will rely on the possibility to construct empty RawProps object.

Reviewed By: mdvacca

Differential Revision: D15511494

fbshipit-source-id: 39dec9336e6b5cf6ad33b1f3a06ca1c096ece628
2019-06-12 21:35:20 -07:00
Valentin Shergin dbbdf72248 Fabric: Codestyle changes
Summary: Trivial.

Reviewed By: mdvacca

Differential Revision: D15756619

fbshipit-source-id: 1bd45e5ec479ecf0d5b83d5f0ecf57f997380f30
2019-06-12 21:18:55 -07:00
Valentin Shergin c34e554275 Fabric: Fixes UB/broken font weight management on iOS
Summary:
Address Sanitizer told me that I have UB in `RCTUIFontWeightFromFloat` and it was right. After a short investigation, I find out that the original assumption that `UIFontWeight` values are practically numbers from 100 to 900 was incorrect. In my simulator, it's something like from `-1` to `+1` (irregularly!). So, the whole subsystem worked only by accident.
This diff fixes that; now we never assume which actual values `UIFontWeight` constants have.

I will publish code style fixes as a separate diff (otherwise it will be really hard to review).

Reviewed By: JoshuaGross

Differential Revision: D15756620

fbshipit-source-id: d7f888e85815d863487c6b68a960e39fd473e095
2019-06-12 21:18:55 -07:00
Aditya Kumar 43df288b2c Update oncalls
Summary:
Changelog:
[BUCK] [Oncall] - Add oncall

Reviewed By: jdthomas

Differential Revision: D15782528

fbshipit-source-id: 21dac8a6a62dcec3149cc38fe1872ea29f17ab6e
2019-06-12 14:08:28 -07:00
David Vacca c603e55ed4 Backout Force Diffing algorithm to insert views Bottom Up
Summary: This is a temporary backout of D14817454, to verify if this is related T45503571

Reviewed By: JoshuaGross

Differential Revision: D15780018

fbshipit-source-id: 455034ce7b7096101db93a8604b77e1233db1137
2019-06-12 07:35:13 -07:00
Sidharth Guglani 38adb8ecd2 pass measure callback data from c++ to java
Summary:
Passing Measure callback data - width, widthMeasureMode, height, heightMeasureMode, measuredWidth and measuredHeight along with NodeMeasure event
This data is then propagated to java layer in this diff

Reviewed By: davidaurelio

Differential Revision: D15697523

fbshipit-source-id: 615463da237175ff88abef3f6528b55333ccd915
2019-06-12 00:30:13 -07:00
David Aurelio 9d13af53ce Pass layout context for `Event::LayoutPassStart`
Summary: Adds the layout context pointer when publishing `Event::LayoutPassStart`.

Reviewed By: SidharthGuglani

Differential Revision: D15754425

fbshipit-source-id: 6295ae1ebec9eab72a79c43bc1cb0e05a6d7ae68
2019-06-11 01:41:22 -07:00
Kevin Gozali c0bf53b716 TM iOS: attempt to convert number args using RCTConvert as well
Summary: Some native modules methods expects number-based args like `NSDate`. For backward compatibility, the incoming numbers should be converted using RCTConvert, just like object args.

Reviewed By: mdvacca

Differential Revision: D15748968

fbshipit-source-id: 4db2cb0c41eda1bbe8cde7b0365d9c3d675f5fb5
2019-06-10 18:41:22 -07:00
Kevin Gozali 7225daf98d TM iOS: Support @synthesize methodQueue auto queue creation
Summary: Some native modules defined `synthesize methodQueue` which will ask the bridge to create a new serial queue for them. TM system needs to preserve this behavior for backward compatibility. In the future though, this magic shall be removed.

Reviewed By: mdvacca

Differential Revision: D15748198

fbshipit-source-id: 66a4b60a2769ac967a8d3bb00c4c635a68daebbc
2019-06-10 18:41:22 -07:00
Sidharth Guglani b6dc9587e6 add node layout event and pass it java layer
Summary: Listen to NodeLayout event and passes this event callback to java layer along with the information whether layout or measure was done in this pass

Reviewed By: davidaurelio

Differential Revision: D15696021

fbshipit-source-id: 8c5ca69330a9baca26b77052d4965cc67fe97c75
2019-06-10 01:48:59 -07:00
Joshua Gross e5c96a85fc Fix layoutTime calculation
Summary: LayoutTime calculation is also trivially wrong. Quick fix.

Reviewed By: shergin

Differential Revision: D15725167

fbshipit-source-id: b06672b9df9cbaa6c54aa97a4c0b58a43f70d5b2
2019-06-07 17:20:26 -07:00
Valentin Shergin 12c09a2d6c Fabric: Bunch of code style changes
Summary: Code style only.

Reviewed By: sahrens

Differential Revision: D15681737

fbshipit-source-id: 24cc2e9b9434448026e7cb3cfd274ea14bd835a2
2019-06-07 12:03:58 -07:00
Valentin Shergin 205de0538c Fabric: New names for ContextContainer methods
Summary:
... and slighly new behaviour for one of them.

The method does nothing if given `key` already exists in the container.

This diff finishes the transition of ContextContainer from an internal bag of things with unclear yet ownership into a legit dedicated dependency injection container for the product code.

The original names of methods imply that the container can have only one object of a given type which is no longer true. The new API is much more generic and idiomatic to C++, it mimics `std:map` API which is intuitive to anyone who familiar with C++ containers.

Besides the naming, `insert` method changed the semantic a bit; now it does nothing in case of inserting an object with a key that already exists. That might seem counterintuitive for "normal" people, but C++ has some wired reasons for that and, hopefully, it's expected behavior in the C++ community.

Fun fact: We need this to fix hot-reload.

Reviewed By: sahrens

Differential Revision: D15681736

fbshipit-source-id: 194f342528446a911eaf072ba3a94a5d8af3cb52
2019-06-07 12:03:57 -07:00
Valentin Shergin a19cfc2273 Fabric: Scheduler-specific dependencies were moved to a separate class from ContextContainer
Summary: ContextContainer should contain only product/component-specific dependencies and stay unchanged during VM/Scheduler reloading.

Reviewed By: JoshuaGross

Differential Revision: D15636656

fbshipit-source-id: fe5de1b6c92f659b28d31eba901c04c5b23fe1d1
2019-06-07 12:03:57 -07:00
Sidharth Guglani 348c3ebefa add node measure event and passing the callback to java layer
Summary: Adds measure event and its listener initial code structure

Reviewed By: davidaurelio

Differential Revision: D15600738

fbshipit-source-id: d15764e0b64edb170fcb15e0912ecce5f7e53595
2019-06-06 21:03:04 -07:00
Sidharth Guglani c44b221e13 moved PtrJNode map to YGJtypes.h and passing layout context as data in LayoutPassEnd Event
Summary: Move PtrJNodeMap to header file so that it can be accessed in events subscribers outside yoga

Reviewed By: davidaurelio

Differential Revision: D15619629

fbshipit-source-id: 1bf213efd38ec7bcac6a38070f21fa837c5f17da
2019-06-06 21:03:04 -07:00
Rain ⁣ 14f249178e standardize C-like MIT copyright headers throughout fbsource
Summary:
`/*` is the standard throughout open source code. For example, Firefox uses single /*: https://hg.mozilla.org/mozilla-central/file/21d22b2f541258d3d1cf96c7ba5ad73e96e616b5/gfx/ipc/CompositorWidgetVsyncObserver.cpp#l3

In addition, Rust considers `/**` to be a doc comment (similar to Javadoc) and having such a comment at the beginning of the file causes `rustc` to barf.

Note that some JavaScript tooling requires `/**`. This is OK since JavaScript files were not covered by the linter in the first place, but it would be good to have that tooling fixed too.

Reviewed By: zertosh

Differential Revision: D15640366

fbshipit-source-id: b4ed4599071516364d6109720750d6a43304c089
2019-06-06 19:40:32 -07:00
Kevin Gozali 360e999937 TM iOS: reduce the scope of cache access lock
Summary: We just need to protect access to the cache, we don't need to protect the entire module lookup, because a module initialization may try to lookup another module, causing deadlocks.

Reviewed By: RSNara

Differential Revision: D15690645

fbshipit-source-id: cbb780db8699a94f2c9a2e121b35ddad2b125b65
2019-06-06 09:40:21 -07:00
Tim Yung 664646055a RN: Restore Debug Bridge Description (iOS)
Summary: Restores the bridge description in the debug menu on iOS.

Reviewed By: fkgozali

Differential Revision: D15680775

fbshipit-source-id: c17ad44f2287e03bb2039b4aa4b1311e7ec9106b
2019-06-05 19:00:32 -07:00
zhongwuzw 68bca1fbd0 Excluded tests file from JSI pod (#25151)
Summary:
Tests file exposed in 608b1b5ea2. This break e2e tests, so let's excluded them from JSI pod.

## Changelog

[iOS] [Fixed] - Excluded tests file from JSI pod
Pull Request resolved: https://github.com/facebook/react-native/pull/25151

Differential Revision: D15645046

Pulled By: cpojer

fbshipit-source-id: 19c712e4307cf712b8377d721661a2b476151732
2019-06-05 05:12:19 -07:00
Joshua Gross 920d9dea21 Fix typo in layout time
Summary: Fix typo.

Reviewed By: shergin

Differential Revision: D15639194

fbshipit-source-id: 1e1d029aab2a7016c630c7429815531e63f71333
2019-06-04 19:21:24 -07:00
Valentin Shergin a4cc519a52 Fabric: Synthetic benchmarks for prop parsing infra
Summary:
And, btw, the tests show that performance of that is not so great:
```
Running /Users/shergin/fbsource/fbobjc/buck-out/cells/fbsource/gen/xplat/js/react-native-github/ReactCommon/fabric/core/benchmarks
Run on (12 X 2900 MHz CPU s)
CPU Caches:
  L1 Data 32K (x6)
  L1 Instruction 32K (x6)
  L2 Unified 262K (x6)
  L3 Unified 12582K (x1)
--------------------------------------------------------------------------------------------
Benchmark                                                     Time           CPU Iterations
--------------------------------------------------------------------------------------------
propParsingUsingComponentDescriptor                       79630 ns      77991 ns       8864
propParsingUsingComponentDescriptorWithNoSourceProps      70200 ns      69099 ns       8362
```

Which means 70ms per 1000 prop parsing processes.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D15608677

fbshipit-source-id: ed4feca489e1243adc73de4741c287256c3aaec3
2019-06-04 15:34:34 -07:00
Valentin Shergin 15302284cc Fabric: Enable CXX (aka Default) platfrom fravour for all C++ Fabric targets
Summary:
First of all, seems it's the right thing to do. Fabric C++ code is cross-platfrom and should run on *all* platforms including Windows, Linux, and Mac.
While we don't have a real *production* use cases where we need compilation for desktops, having CXX target is really handy for two reasons:
* It simplifies local test running process. Instead of going to `/fbandroid/` and executing something like `buck test fbsource//xplat/js/react-native-github/ReactCommon/fabric/core:coreAndroid` (note the suffix). We can just do `buck test fbsource//xplat/js/react-native-github/ReactCommon/fabric/core:core` everywhere and it works now out of the box. Running tests with "Apple" flavor never worked for me.
* It allows creating synthetic benchmark tests (using Google Benchmark) that can be used as a rough approximation of code micro-optimizations.

Reviewed By: JoshuaGross

Differential Revision: D15608678

fbshipit-source-id: d2449035685dbca6ab983480f5334ec4ac11cd35
2019-06-04 15:34:34 -07:00
Will Holen 608b1b5ea2 Include testlib files in JSI
Summary: This adds the testlib.cpp/h files to external JSI. They're in a `test/` subdirectory so that build scripts using globs like `*.cpp` won't include them.

Reviewed By: mhorowitz

Differential Revision: D15582281

fbshipit-source-id: 1785ee5071fcf98e92fbf3a11eddb21fe84b3799
2019-06-04 14:40:39 -07:00
Joshua Gross 43d7664308 Revert D15602627: [yoga] moved PtrJNode map to YGJtypes.h and passing layout context as data in LayoutPassEnd Event
Differential Revision:
D15602627

Original commit changeset: bb5bd5bbf8dc

fbshipit-source-id: 5ae08826eb706c3794c36738cb9625f82b58641e
2019-06-03 19:58:08 -07:00
Emily Janzer 738dd65967 Use SurfaceRegistry instead of AppRegistry
Summary: Right now we render a surface by calling `AppRegistry.runApplication`, but the way we do this relies on the batched bridge. For Venice (bridgeless RN) I created a new module for registering a surface called SurfaceRegistry, which uses a global variable instead of registering itself as a callable module on the bridge. If that global variable exists, we can use that to start the surface instead of calling AppRegistry.

Reviewed By: sahrens

Differential Revision: D15502241

fbshipit-source-id: 0b8d4677f1df41f46d84444567a30e40e21fed3d
2019-06-03 19:24:05 -07:00
Ramanpreet Nara a44ab2957c Protect access to RCTTurboModuleCache
Summary: The `_rctTurboModuleCache` `std::unordered_map` can be accessed by multiple threads at the same time via the `provideRCTTurboModule` method. Since `provideRCTTurboModule` both reads and writes to `_rctTurboModuleCache`, this is really bad because we could end up reading from `_rctTurboModuleCache` while it's in an invalid state. Therefore, in this diff, I'm making it so that only one thread at a time can enter `provideRCTTurboModule`.

Reviewed By: fkgozali

Differential Revision: D15609987

fbshipit-source-id: e24e1f5cc2351d8cbb820b7a97074aacd06eec9d
2019-06-03 16:16:09 -07:00
Sidharth Guglani d3cf756613 moved PtrJNode map to YGJtypes.h and passing layout context as data in LayoutPassEnd Event
Summary: Move PtrJNodeMap to header file so that it can be accessed in events subscribers outside yoga

Reviewed By: davidaurelio

Differential Revision: D15602627

fbshipit-source-id: bb5bd5bbf8dcb279f5f87a4fd7287909d4e895d8
2019-06-03 16:02:47 -07:00
REDMOND\acoates 7f489b63f2 Move unistd.h include to cpp where its used (#25107)
Summary:
unistd.h isn't a header available in the windows SDK, so we can't include it from react-native-windows.

I moved the usage of dup, to JSBigString.cpp in a previous PR, so this header should only be needed in the cpp file, not the header.  (And react-native-windows doesn't use the cpp file)

## Changelog

[Internal] [Fixed] - Header cleanup
Pull Request resolved: https://github.com/facebook/react-native/pull/25107

Differential Revision: D15602265

Pulled By: cpojer

fbshipit-source-id: 6a62bf8fe6758e400810f37834e8646485120d71
2019-06-03 08:45:32 -07:00
Dratwas d8fa1206c3 fix indexed RAM bundle (#24967)
Summary:
Co-Authored: zamotany
With React Native 0.59.8 the app keeps crashing with indexed RAM bundle on Android with the following error:

```
2019-05-09 11:58:06.684 2793-2856/? E/AndroidRuntime: FATAL EXCEPTION: mqt_js
    Process: com.ramtestapp, PID: 2793
    com.facebook.jni.CppException: getPropertyAsObject: property '__fbRequireBatchedBridge' is not an Object

    no stack
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:193)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
        at java.lang.Thread.run(Thread.java:764)
```

After investigation we found that when using any bundle, let it be non-ram, FIle RAM bundle or Index RAM bundle, the `CatalystInstanceImpl.java` is always using `loadScriptsFromAsset`, which is calling `CatalystInstanceImpl::jniLoadScriptFromAssets` in C++. This method when checking if bundle is a RAM bundle, uses `JniJSModulesUnbundle::isUnbundle` which only check for js-modules/UNBUNDLE - file generated when building File RAM bundle. There is no other logic to handle Indexed RAM bundle, so it figures that the bundle is not RAM, cause there is no js-modules/UNBUNDLE file and tries to load as regular bundle and fails.

In this PR we added check if it is indexed RAM bundle in `jniLoadScriptFromAssets` and handle it if it is.
## Changelog
[Android] [Fixed] fix indexed RAM bundle

Solves https://github.com/facebook/react-native/issues/21282
Pull Request resolved: https://github.com/facebook/react-native/pull/24967

Differential Revision: D15575924

Pulled By: cpojer

fbshipit-source-id: 5ea428e0b793edd8242243f39f933d1092b35260
2019-06-03 07:14:25 -07:00
David Vacca 9a053fc4db Create base MapBuffer class and tests
Summary: This diff creates the base classes for MapBuffer and its tests

Reviewed By: shergin

Differential Revision: D15550730

fbshipit-source-id: a5a47edebd7c3e1b8b2c3ad2006aee0f8bdb7866
2019-06-02 16:04:18 -07:00
Valentin Shergin 5a8cdb4bb7 Fabric: Additional temporary checks in prop parsing infra
Summary:
While ViewConfig infra isn't perfect we need to check that for correcness.
See the task for more details.

Reviewed By: JoshuaGross

Differential Revision: D15578675

fbshipit-source-id: c99c2be9c215e6b9d7ee8e6e50d85e822c1f007e
2019-06-01 12:47:40 -07:00
David Aurelio fd607b1304 Back out "[Yoga] Remove comparison to `YGUndefined` *and* `0.0f`"
Summary: Original commit changeset: 13c8f24e1bc8

Reviewed By: fabiomassimo

Differential Revision: D15583502

fbshipit-source-id: efc6175f6c4925a383fea723195c073f49e2eff1
2019-05-31 15:56:28 -07:00
David Aurelio a1bfb284ee Use atomic list for event subscribers
Summary:
Replace the *copy on write* vector with an atomic pointer to a linked list.

This allows to publish without locking a mutex, at the cost of the slower traversal of a linked list (a vector has better locality).

At the moment, the typical use case is to have one subscriber, meaning that the afforementioned slower traversal is not a problem.

Adding subscribers is implemented as atomic *compare and swap.*

Reviewed By: SidharthGuglani

Differential Revision: D15546964

fbshipit-source-id: 41bfa41f1ac6be5c9b6bf4288ea3271ee995877e
2019-05-31 01:24:44 -07:00
David Aurelio 6677f405a2 Deprecate `YGNode::setConfig`
Summary:
We want to phase out usage of config pointers on nodes. Setting configs is no longer needed, as a config is unly used during construction.

Here we deprecate the setter, as it is no longer working as it used to (e.g. changing `useWebDefaults` after a node is constructed).

Reviewed By: SidharthGuglani

Differential Revision: D15416474

fbshipit-source-id: a2cc06cad0c5148cecce056ece5f141b3defe9a9
2019-05-29 07:44:04 -07:00
David Vacca 12b735a378 Create structure of mapbuffer project
Summary: Create structure of C++ side of mapbuffer project

Reviewed By: shergin

Differential Revision: D15529650

fbshipit-source-id: b563d3fbcfddcf46802ccb202e372233baad123d
2019-05-28 17:29:38 -07:00
Emily Janzer 298f59c5d3 Use startSurface on Android
Summary:
We currently have two different codepaths for actually rendering a surface with Fabric on iOS and Android: on iOS we use Fabric's `UIManagerBinding.startSurface` to call `AppRegistry.runApplication`, but on Android we don't; instead we use the same codepath as paper, calling `ReactRootView.runApplication`.

This diff does a few different things:
1. Unify iOS and Android by removing the `#ifndef` for Android so that we call `startSurface` for both
2. Pass through the JS module name on Android so that this actually works (it currently passes in an empty string)
3. Remove the call to `ReactRootView.runApplication` for Fabric so that we don't end up doing this twice
4. Copy over some logic that we need from `ReactRootView.runApplication` (make sure that root layout specs get updated, and that content appeared gets logged)

Reviewed By: mdvacca

Differential Revision: D15501666

fbshipit-source-id: 5c96c8cf036261cb99729b1dbdff0f7c09a32d76
2019-05-28 12:23:00 -07:00
Michal Sienkiewicz a0f2bfa120 Sync worker requirement mismatches
Summary:
Syncing worker requirement mismatches to improve remote build time.

Created actions:
MEDIUM: 5

Differential Revision: D15510246

fbshipit-source-id: b8454b4acf2810251d2a4a4515fc0ce2c1a2b327
2019-05-26 01:39:01 -07:00
Valentin Shergin 9990010b2c Fabric: Disabling sync and unbatched event queues
Summary:
We are not sure yet how exactly this should work semantically (e.g. should unbatched events flash previously dispatched batched or not).
So, let's disable that until we have all answers.

Reviewed By: mdvacca

Differential Revision: D15498191

fbshipit-source-id: 77f07c5e86bfbfd212505df8cc6530e39531b5ef
2019-05-24 12:25:52 -07:00
Valentin Shergin 83f23982ca Fabric: Touch and TouchEvent got own files and support for debug printing
Summary: That's essential for debugging touch events.

Reviewed By: mdvacca

Differential Revision: D15498192

fbshipit-source-id: 4a8e0a2b84a1935722518fdce03c10ba277f5702
2019-05-24 12:25:52 -07:00
Valentin Shergin 6dbd809df5 Fabric: Support for debug printing `std::unordered_set<>`
Summary: Quite trivial.

Reviewed By: mdvacca

Differential Revision: D15498190

fbshipit-source-id: 512c121c6629e65bef7dd0c86898506e0fe861a9
2019-05-24 12:25:51 -07:00
David Vacca bbf1a7d085 Back out "[Venice][Fabric] Use startSurface on Android"
Summary: Original commit changeset: 4a506a589108

Reviewed By: ejanzer

Differential Revision: D15497094

fbshipit-source-id: 47e5d0c3c69cc56cc3dd56d28e23e1db5b562fa4
2019-05-24 11:30:29 -07:00
Emily Janzer f23da3aeb0 Use startSurface on Android
Summary:
Right now calling FabricUIManager.addRootView() doesn't actually start running the application on Android. This diff:

1. Removes the #ifndef so that we actually call UIManagerBinding.startSurface() on Android
2. Passes through the JS module name from addRootView so we can render the surface (falls back to an empty string if not provided, which is the current behavior)
3. Adds an option for starting the surface using `RN$SurfaceRegistry` instead of `AppRegistry`, if that global property has been defined in JS. This is used for Venice (bridgeless RN)

Reviewed By: shergin

Differential Revision: D15366200

fbshipit-source-id: 4a506a589108905d4852b9723aac6fb0fad2d86e
2019-05-23 13:47:30 -07:00
zhongwuzw 3616941ef8 Add NAN check for text font sizeMultiplier (#24966)
Summary:
Set `sizeMultiplier` to `1.0` if default value is `NAN`, otherwise, text cannot show properly.

## Changelog

[iOS] [Fixed] - Add NAN check for text font sizeMultiplier
Pull Request resolved: https://github.com/facebook/react-native/pull/24966

Differential Revision: D15466559

Pulled By: shergin

fbshipit-source-id: 6f8b47eb8e521cb120d7f351cba02dbf1c5411fd
2019-05-22 22:53:25 -07:00
Ramanpreet Nara e1102b43ff Implement Android Cxx TurboModule support
Summary:
## Summary
This diff does a bunch of things:
1. The TurboModule resolution algorithm on Android now supports C++ TurboModules.
2. `SampleTurboCxxModule` is moved from `ReactCommon/turbomodule/samples/platform/ios/` to `ReactCommon/turbomodule/samples` so that both iOS and Android can share it.
3. `CatalystTurboModuleManagerDelegate::getTurboModule(std::string, JSCallInvoker)` now understands and returns `SampleTurboCxxModule`.

Reviewed By: mdvacca

Differential Revision: D15253477

fbshipit-source-id: 3def91911b091f8cf93be17decd245a0499ed718
2019-05-22 13:16:13 -07:00
David Aurelio 07398592f2 Remove comparison to `YGUndefined` *and* `0.0f`
Summary: Removes a check introduced in D6969537, comparing `totalFlexGrowFactors` and `resolveFlexGrow` to both `0.0` *and* undefined.

Reviewed By: SidharthGuglani

Differential Revision: D15431425

fbshipit-source-id: 13c8f24e1bc8c49496097a6aa78e20ee5d3964a7
2019-05-22 09:43:02 -07:00
Valentin Shergin 592e6c5e7d Fabric: Restoring the original purpose of StateData class
Summary:
This diff restores the original role of StateData as a dummy class that has only one purpose - designate that there is no state associated with the node.

I believe having an abstract StateData class for all data types is not necessary and actually slightly harmful. And here the reasons:
* Having virtual dispatch enabled for classes introduces some overhead, and it should be used only if it is absolutely necessary. In this case, we don't need to have virtual dispatch enabled for Data classes because it's already enabled for State classes; therefore all virtual resolution is done there and that's sufficient. No need to pay for what we don't need.
* Continuing the previous point, yes, we expect some API being exposed for Data classes (such as `getDynamic`), but introducing a base abstract class for that is *not* an idiomatic C++ solution; in C++ it's by design that most of the template contracts are actually duck-typed. This is a well-known design issue/concern that will be addressed with an effort called "Concepts" in C++20. Anyway, we should not use abstract classes as *only*  indication of conformance to some interface.
* StateData does not introduce any convenience. As it is clear from several subclass implementations, we don't really use base methods from it.
* The previous issue actually happens especially because of the interface of StateData class. Consider constructor that accepts `folly::dynamic` and does nothing, it actually useless because it's impossible to use it unless it's called inside superclass's constructor. That's the case because C++ does not support virtual dispatch for constructors (for good).
* Avoiding subclassing StateData counter-intuitively enforces the desired conformance to imaginary interface: it does not compile otherwise.

Reviewed By: JoshuaGross

Differential Revision: D15342338

fbshipit-source-id: 1f04f7fc5247499e7cfc09cd4b3cccffdc0b6b06
2019-05-21 23:12:23 -07:00
David Aurelio 80258b530d Remove `YGNode::setAndPropogateUseLegacyFlag`
Summary:
`YGNode::setAndPropogateUseLegacyFlag` was only used for debugging purposes.
Here, we replace it with a free function in `Yoga.cpp`.

Now that we have events, the diffing functionality should go into a separate debugging package and be implemented in terms of an event listener. Let's do that as soon as we can support multiple listeners.

Reviewed By: SidharthGuglani

Differential Revision: D15316863

fbshipit-source-id: db929eba7c2de8aa1550e362dd2c175929c0070e
2019-05-21 06:08:07 -07:00
Valentin Shergin 3c464782e0 Revert D15410979: [react-native][PR] [Fabric] use state in paragraph component
Differential Revision:
D15410979

Original commit changeset: 3c9517d2495a

fbshipit-source-id: 2e2fc860dd657b2b2159bd245896a4e8a25d5734
2019-05-20 14:35:12 -07:00
David Aurelio 19a88d7f4a `YGNode`: Field for web defaults
Summary:
In order to remove the config pointer from nodes, we have to keep track of whether the node is using web defaults.
This information fits into one bit that we can place in padding (i.e. no extra memory needed).

This allows us to get rid of config usage withing `YGNode` with some exceptions:

- `iterChildrenAfterCloningIfNeeded` -- this function will simply receive the configuration, or the cloning callback.
- `setAndPropogateUseLegacyFlag` -- will be removed in D15316863
- in `YGNode::reset` -- will go away utomatically once we remove the config pointer

Reviewed By: SidharthGuglani

Differential Revision: D15391536

fbshipit-source-id: 0fa0d0805c6862bd741fe4a7d9b637ed534f56a4
2019-05-20 10:52:28 -07:00
Eric Lewis 6ec19aba4e use state in paragraph component (#24873)
Summary:
Updates the paragraph component to use State instead of Local Data, part of the path to a Fabric TextInput 💯

## Changelog

[General] [Changed] - Fabric: Use State instead of Local Data for Paragraph
Pull Request resolved: https://github.com/facebook/react-native/pull/24873

Differential Revision: D15410979

Pulled By: shergin

fbshipit-source-id: 3c9517d2495a64c4dbd213b6efb5ff55287900e3
2019-05-20 09:49:39 -07:00
Sidharth Guglani fb8a7c3cc5 mutex lock while accessing event subscribers vector for thread safety
Summary: Using Mutex lock_guard mechanism when writing to subscribers and when accessing them in publish to make a copy

Reviewed By: davidaurelio

Differential Revision: D15391679

fbshipit-source-id: 16713ff28ce1762a5ca4c48c152897a92417e80b
2019-05-19 23:32:38 -07:00
Valentin Shergin f02feb8d38 Fabric: Codegen for PullToRefresh component
Summary:
Straightforward.
Rick, I rename some stuff, I hope you are cool with that.

Reviewed By: mdvacca

Differential Revision: D15403306

fbshipit-source-id: 1dbd34060052a9bd39ed4211010f14b76fffcde6
2019-05-19 17:44:40 -07:00
Valentin Shergin e8b2145263 Fabric: Standard PullToRefresh component
Summary: This is implementation of standard PullToRefresh component that uses standard iOS component and modern integration approach.

Reviewed By: mdvacca

Differential Revision: D15403308

fbshipit-source-id: 5c877f7c18af9f5ac40e15a4ba44118614ba80bc
2019-05-19 17:44:40 -07:00
David Aurelio c3c3c3c655 `YGNode`: one byte of private storage
Summary:
Adds one byte of private storage to `YGNode`, intended to be used by Yoga itself.

This is in previously unused alignment space, and won’t cause more memory to be allocated.

Reviewed By: SidharthGuglani

Differential Revision: D15296732

fbshipit-source-id: 3caf0a3cd506e4e324e51c31869c69be5781d476
2019-05-16 11:47:58 -07:00
David Aurelio ec82e05e9a Fix style property bits
Summary: Style bits had overlap, because `dimensionBit` was set with an incorrect increment.

Reviewed By: SidharthGuglani

Differential Revision: D15335134

fbshipit-source-id: 370e1a73547d76b0e26bc6ab67acb96d33ddf180
2019-05-16 11:47:58 -07:00
zhongwuzw a352ecfabd TM iOS: Remove retainArguments && do retain by us explicitly (#24849)
Summary:
This is a TODO, we met crash if we don't call `retainArguments` when return type is like `NSDictionary`, the reason is `getReturnValue` don't retain the return value, so we need to using `__bridge` to transfer ownership to OC type.
Also add `resolveBlock` and `rejectBlock` to `retainedObjectsForInvocation`.

cc. cpojer

## Changelog

[iOS] [Fixed] - Remove retainArguments && do retain by us explicitly
Pull Request resolved: https://github.com/facebook/react-native/pull/24849

Differential Revision: D15369209

Pulled By: fkgozali

fbshipit-source-id: 8431d03705d8476f38c8b5d29630489a545d373a
2019-05-15 21:50:40 -07:00
Kevin Gozali 8662d9d3b0 TM iOS: Added backward-compatible ObjC invalidation logic
Summary:
Some ObjC NativeModules conform to `RCTInvalidating` protocol and implements `invalidate` method. This is typically used to clean things up during bridge teardown or reload. In TurboModule system the invalidate method can be replaced by pure destructors, but for backward compatibility, we call existing invalidate method on each module during teardown.

This also cleans up all existing LongLivedObject's.

Reviewed By: mdvacca, RSNara

Differential Revision: D15365655

fbshipit-source-id: 802844b39b5b7adb54970ea541f4d744bbf9e480
2019-05-15 17:36:05 -07:00
RCiesielczuk cd2f8c567b Introduce TurboModule Setup Metric (#24732)
Summary:
With the introduction of TurboModules, it would be beneficial to measure the setup time of these modules, as we currently have it in place for NativeModules.

The instantiation of the TMs occurs in the `RCTTurboModuleManager`. In order to successfully measure the time it took to setup the module, we need to ensure that we don't take into account cached modules. As such, we need to:

1. Check if module is in `_turboModuleCache`
  a. Start mark for `RCTPLTurboModuleSetup` tag if not found
2. Get the TM via `[self provideTurboModule:]`
3. Check if module is in `_turboModuleCache`
   a. Stop mark for `RCTPLTurboModuleSetup` if we did not find module in cache prior to **step 2** and if it's now present in the cache.
   b. Notify about setup time if the above is true.
4. Return TM

## Changelog

[iOS] [Added] - Gain insights on the the turbo module setup times by observing `RCTDidSetupModuleNotification`. The userInfo dictionary will contain the module name and setup time in milliseconds. These values can be extracted via `RCTDidSetupModuleNotificationModuleNameKey` and `RCTDidSetupModuleNotificationSetupTimeKey`.
Pull Request resolved: https://github.com/facebook/react-native/pull/24732

Differential Revision: D15362088

Pulled By: RSNara

fbshipit-source-id: e6a8044e4aba5a12ae63e9c7dbf707a17ec00180
2019-05-15 15:28:10 -07:00
zhongwuzw 36f9a4aca7 TM iOS: Consolidate RCTDidInitializeModuleNotification sender to batchedBridge (#24866)
Summary:
Consolidate sender of notification to `batchedBridge` for TM and old module system, old module implementation can see dc893756b8/React/Base/RCTModuleData.mm (L191-L193).

## Changelog

[iOS] [Fixed] - Conlidate RCTDidInitializeModuleNotification sender to batchedBridge
Pull Request resolved: https://github.com/facebook/react-native/pull/24866

Differential Revision: D15357566

Pulled By: RSNara

fbshipit-source-id: 479575c1e9781d8aea9fa3aea9e0283d24df7e81
2019-05-15 12:31:30 -07:00
Valentin Shergin 197c644f7a Fabric: Make measuring ScrollView::contentOffset-aware
Summary:
This is the final piece of change that makes measuring (`LayoutableShadowNode::getRelativeLayoutMetrics()`) take ScrollView content offset into account (on iOS).

It works pretty simply: at the end of scrolling (or zooming) action ScrollView updates the state which later can be used for computing `transform` which measuring uses to adjust values in LaoutMetrics.

Reviewed By: mdvacca

Differential Revision: D15323688

fbshipit-source-id: fdf86c6cd9bdfd56caddd4b39bdd1185760b9f94
2019-05-15 10:30:29 -07:00
Valentin Shergin cd231da27a Fabric: Migrate ScrollView from LocalData to State
Summary: Seems we need this now to enable future improvements in ScrollView such as correct measure, pull-to-refresh and so on.

Reviewed By: mdvacca

Differential Revision: D15323687

fbshipit-source-id: fae37431ccbbf2faec9c84752396153689b873ef
2019-05-15 10:30:29 -07:00
Valentin Shergin 4001ffb7ce Fabric: Refinements in State management infra
Summary: A couple of new methods in ConcreteShadowNode allows us to deal with State in more LocalData-like manner.

Reviewed By: mdvacca

Differential Revision: D15323686

fbshipit-source-id: ede4aa1f1d0ad6f876bd963e57a00a0ad470c1c0
2019-05-15 10:30:28 -07:00
Sidharth Guglani 37c8771bc6 use shared_ptr for subscribers vector in event system
Summary:
using shared_ptr for vector of subscribers
Further changes in commit stack support the mutiple subscribers in event system

Reviewed By: davidaurelio

Differential Revision: D15352512

fbshipit-source-id: fac7f4268abf9ca4277734aca2f21cd711eb7d6e
2019-05-15 09:02:16 -07:00
Sidharth Guglani 44659d253e use vector for subscribers in event system
Summary:
Replaced global event subscriber with a vector of subscriber functions
Further changes in commit stack support the mutiple subscribers in event system

Reviewed By: davidaurelio

Differential Revision: D15352451

fbshipit-source-id: 7ca6f0943735bf1f76a906c23e15e14ae3c5f42c
2019-05-15 09:02:15 -07:00
Joshua Gross 04782ff57a Send ReactNative C++ State to Android `measure` API
Summary:
The `measure` API receives LocalData and Props, it should also receive State.

This will also be used in future diffs.

Reviewed By: mdvacca

Differential Revision: D15325182

fbshipit-source-id: 6cb46dd603ce7d46673def16f0ddb517e2cf0c4f
2019-05-14 14:22:10 -07:00
Emily Janzer c35d1af6fa Add `override` to BridgeJSCallInvoker
Summary: In D15252375 I made JSCallInvoker an abstract class and extended it in BridgeJSCallInvoker, but I forgot to add the `override` keyword for overridden methods.

Reviewed By: fkgozali

Differential Revision: D15328292

fbshipit-source-id: 3e75faf1b4a968b80643b8a97071ab2e122fd643
2019-05-14 12:11:05 -07:00
Valentin Shergin 4105450c7e Fabric: Collect typenames instead of typehashes to ensure safety in ContextContainer
Summary:
In ContextContainer, only in Debug mode, we store type information alongside with data to detect typemismatch in runtime. We used type hashes before, but seems they are not so stable and can cause some false negative crashes.
This diff changes that to store mangled typenames instead of hashes, so it should be much more reliable now.

Reviewed By: JoshuaGross

Differential Revision: D15325728

fbshipit-source-id: 3a0f1116e1336af79adb51f38ce83c37aee4cad1
2019-05-14 10:05:54 -07:00
Emily Janzer c75f062a77 Change JSCallInvoker to be an abstract class
Summary: The existing implementation of JSCallInvoker holds a reference to Instance (aka the bridge). This diff makes JSCallInvoker an abstract base class that's extended by BridgeJSCallInvoker, which is what's returned by CatalystInstance to initialize TurboModules. This will allow us to add another class that derives from JSCallInvoker that doesn't rely on the bridge.

Reviewed By: shergin

Differential Revision: D15252375

fbshipit-source-id: 75eee2ca149235a63e2a2cd8cdd361b163d1d1ab
2019-05-13 12:04:33 -07:00
David Aurelio bd959700db Publish events for layout pass
Summary:
Adds `LayoutPassStart` and `LayoutPassEnd` events.

The existing `NodeLayout` event in isolation is not as useful as it could be. Having events that mark start and end of a layout pass are a useful addition.

Differential Revision: D15305467

fbshipit-source-id: 14af6f65e698fb1e3112eb2ffd87a74d31df4840
2019-05-10 19:04:15 -07:00
David Vacca ac9195a506 Include pointScaleFactor into the equality method of LayoutMetrics
Summary:
Previously the pointScaleFactor field was not being compared properly in LayoutMetrics equality method.
This diff fixes that

Reviewed By: shergin

Differential Revision: D15303555

fbshipit-source-id: 8863e9e1fbad15b43400afc32b97bf6d252cbe55
2019-05-10 16:32:01 -07:00
Valentin Shergin 184073813e Fabric: Making `YogaStylableProps.yogaStyle` protected
Summary: `YogaStylableProps.yogaStyle` is designed to be consumed by Yoga only. Making it `protected` allows us to avoid confusion and misuse of this props.

Reviewed By: JoshuaGross

Differential Revision: D15296474

fbshipit-source-id: cf9e416afee99fb426d72765557b34d303a63dbe
2019-05-10 15:34:25 -07:00
David Vacca 5f9bb72bb3 Replace abort() with assert() when a prop-value is not found during parsing
Summary: This diff replaces usage of abort() with assert() when a prop-value is not found during parsing of prop values

Reviewed By: shergin

Differential Revision: D14563338

fbshipit-source-id: c799420e6b49df35e1d7ccdbd4bc4845067d33cc
2019-05-09 16:24:13 -07:00
Valentin Shergin 8c0ba25f19 Fabric: Storing ImageLoader (instead of ImageManager) in ContextConteiner
Summary:
ImageLoader is an actual external dependency, not a ImageManager.
That change allows to remove dependency on ImageManager from SurfacePresenter and make some other code simpler.

Reviewed By: mdvacca

Differential Revision: D15242047

fbshipit-source-id: 8622d15b8fdb5c3a7e25091adf7be1108f87ecd5
2019-05-09 15:49:18 -07:00
Valentin Shergin 335c81ec31 Fabric: Optimizations in view flattening algorithm
Summary:
This diff changes the condition in `ViewShadowNode::isLayoutOnly()` removing checking for `onLayout` event listener.
We needed that before because the mechanism of emitting events was based on analyzing mutation instructures (we needed those to be generated for nodes with `onLayout`).
Recenly we changed that algorithm deeply integrating in layout infra, so we don't need this anymore.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D15273491

fbshipit-source-id: 2d43f00d1b87369d5993fe5ba70c2de36b8ce0c5
2019-05-09 10:56:44 -07:00
Sidharth Guglani 12fb97d9e9 move event files to yoga/events folder
Summary: Moved events files to yoga/events for better code structure

Reviewed By: davidaurelio

Differential Revision: D15198566

fbshipit-source-id: 74d451011841d59fae5a1c637f9c33a7d2d1f87e
2019-05-09 07:47:05 -07:00
David Aurelio 6ccdf85cef Publish event when visiting nodes during layout
Summary:
@public

Publish an event when visiting nodes during layouts.

Reviewed By: SidharthGuglani

Differential Revision: D15206965

fbshipit-source-id: c201f084b1d4186bc64560b8033be965f2549236
2019-05-09 04:22:43 -07:00
David Aurelio 7d44113bee **breaking:** remove `YGNodeGetInstanceCount`
Summary:
@public

`YGNodeGetInstanceCount` was only ever meant for tests, and caused data races in multi-threaded environments.

It was completely replaced with event-based counting for tests.

Here we remove public API around the counter, and the counter itself.

Reviewed By: SidharthGuglani

Differential Revision: D15174857

fbshipit-source-id: 228e85da565bac9e8485121e956a2e41910b11c8
2019-05-09 04:22:42 -07:00
David Aurelio 03bf17898a Add test utilities for C++ and Java
Summary:
@public

Test utility on top of the new event system that maintains a counter of instantiated nodes. Meant to replace the global node counter.

Reviewed By: SidharthGuglani

Differential Revision: D15174855

fbshipit-source-id: 6998472f95a09b8da652257a26596164bdcf43d6
2019-05-09 04:22:42 -07:00
David Aurelio d1411cc92f Publish events for node allocation and deallocation
Summary:
@public

Publish two events, `NodeAllocation` and `NodeDeallocation`, in the same places where the global node counter is changed.

Reviewed By: SidharthGuglani

Differential Revision: D15174858

fbshipit-source-id: 6e4e9add88513b9e987189ca5035d76da2a1de55
2019-05-09 04:22:42 -07:00
David Aurelio 71c3c23862 Reduce measure cache size to 8
Summary:
@public

Reduces measure cache size to a number that is enough for 95% of nodes, according to our (FB-internal) measurements.

Node size: 776b -> 584b

Reviewed By: SidharthGuglani

Differential Revision: D15183567

fbshipit-source-id: 9ae8cc78074271a015e7618b931ba0356de87a0c
2019-05-09 03:26:03 -07:00
Valentin Shergin d8677752f8 Fabric: Enable `useLegacyStretchBehaviour` for Yoga in Fabric
Summary: Apparently, Yoga has a "quirks mode" and we have to enable that for Fabric. Which is probably a mistake that we have to make one more time.

Reviewed By: davidaurelio

Differential Revision: D15267852

fbshipit-source-id: 88a910fafc9ff64fb19376f4b74a2f2fd5827eba
2019-05-08 17:56:16 -07:00
Kevin Gozali 0436f81595 TM iOS: Fixed mixed-up module lookup from native side
Summary:
There are 2 issues:
* RCTTurboModuleManager may be initialized too late, so the module lookup from native via `[bridge moduleForClass:]` may end up going to the old system incorrectly
* In the case where JS is asking for a nativemodule, we may be incorrectly registering modules that are marked as RCTTurboModule - they should be ignored instead

Reviewed By: mmmulani, RSNara

Differential Revision: D15247632

fbshipit-source-id: 4e0fae33923810c74966b38276b206ac00723012
2019-05-07 19:29:16 -07:00
Valentin Shergin 3238d3d3b4 Fabric: Fixing a typo/error in ConcreteState
Summary: I don't recall why the mutation function return rvalue reference, but it is totally incorrect (the function cannot own the object, so returning a reference introducing a dungling pointer and will crash).

Reviewed By: mdvacca

Differential Revision: D15156312

fbshipit-source-id: 497d10de22a41906efe71cd10139e3710ae11a79
2019-05-07 19:15:43 -07:00
Dmitry Dushkin b79d7db9db Consistent reporting native module name on crash on native side (#24741)
Summary:
_Reopened PR_ https://github.com/facebook/react-native/pull/24704#issuecomment-490017599
PR https://github.com/facebook/react-native/pull/24633 introduced some inconsistency in crash messaging, this PR fix it. Asked by mhorowitz

[General] [Added] - Consistent reporting native module name on crash on native side
Pull Request resolved: https://github.com/facebook/react-native/pull/24741

Differential Revision: D15242415

Pulled By: cpojer

fbshipit-source-id: 8346ffd7c74070ec676aa006c9791a4729946204
2019-05-07 14:57:20 -07:00
Zeyad Salloum fdd8fadea8 Revert D15237424: [react-native][PR] Consistent reporting native module name on crash on native side
Differential Revision:
D15237424

Original commit changeset: ded8db45b2a2

fbshipit-source-id: 99d176e1ee796dbbe9957eda08992a8a76ba109b
2019-05-07 02:48:14 -07:00
Dmitry Dushkin d6c33f915d Consistent reporting native module name on crash on native side (#24704)
Summary:
PR https://github.com/facebook/react-native/pull/24633 introduced some inconsistency in crash messaging, this PR fix it. Asked by mhorowitz

[General] [Added] - Consistent reporting native module name on crash on native side
Pull Request resolved: https://github.com/facebook/react-native/pull/24704

Differential Revision: D15237424

Pulled By: cpojer

fbshipit-source-id: ded8db45b2a2ec9998ff33fdbecef3f12c19578f
2019-05-07 02:15:58 -07:00
Valentin Shergin b2756eb051 Fabric: Farewell kFloatUndefined
Summary: Apparently it's not used anymore. And that a good this.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D15219258

fbshipit-source-id: e3258d851d1eec5955d86f99a0b0d8a1b0304cb4
2019-05-06 17:06:41 -07:00
Valentin Shergin b5d0b6fc2a Fabric: Fixed parsing of `backfaceVisibility` prop
Summary: I have noticed that `backfaceVisibility` example crashes (because actual value is a string/enum, not a boolean), so I fixed it.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D15219261

fbshipit-source-id: 27f76cd10903794d597adacb9da7300a42813f8e
2019-05-06 17:06:41 -07:00
Valentin Shergin fb85e90487 Fabric: Using `LayoutableShadowNode::getTransform` in measuring
Summary: After this change, all measuring operations based on `LayoutableShadowNode::getRelativeLayoutMetrics` will take into account the transformation matrices provided by shadow nodes. This will allow implementing scroll-offset-aware and custom-transform-aware measuring.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D15219259

fbshipit-source-id: 1d7cd8c0ee4406f4dd0002cd442dc0679391922b
2019-05-06 17:06:40 -07:00
Valentin Shergin 40bf82898f Fabric: Applying a transformation matrix to a point
Summary: The diff implements a function that applies given transformation to a point.

Reviewed By: JoshuaGross

Differential Revision: D15219263

fbshipit-source-id: 4cc0595b0dda38c1ede1f2885b800cbe57f54243
2019-05-06 17:06:40 -07:00
Valentin Shergin 0e35406e4e Fabric: LayoutableShadowNode::getTransform
Summary:
`LayoutableShadowNode::getTransform` returns a transform object that represents transformations that will/should
be applied on top of regular layout metrics by mounting layer.

Reviewed By: mdvacca

Differential Revision: D15219262

fbshipit-source-id: e7aeb85b5f7e2fce3f8faf9dfcaee5dae3217d36
2019-05-06 17:06:40 -07:00
Valentin Shergin 0f2a09d1f6 Fabric: MountingCoordinator - the new way to ensure ordering of mount transaction
Summary:
TBD.
This thing fixes flickering during appearing of Fabric screens on iOS.

Reviewed By: mdvacca

Differential Revision: D15116079

fbshipit-source-id: 95ed0ba94667cad67fe4317025128d01b34f69c5
2019-05-03 15:11:35 -07:00
Valentin Shergin 4803cab8c4 Fabric: MountingTelemetry and refinments in TimeUtils
Summary: This diff implements encapsulating all time metrics in a single class for better extensibility and readability.

Reviewed By: JoshuaGross

Differential Revision: D15179835

fbshipit-source-id: 62bdf94435a0d37a87ad9bad613cc8e38043a235
2019-05-03 15:11:34 -07:00
Ramanpreet Nara 913ff9f5ae Fix OSS build
Summary: iOS TurboModules work in OSS. I pulled out JSCallInvoker from `React-turbomodule-core`, as a part of D15055511. In this diff, I'm adding it back in.

Reviewed By: mdvacca

Differential Revision: D15195007

fbshipit-source-id: 64ee294a68c0a63ba400b8a829864c6619d3311a
2019-05-03 13:31:21 -07:00
Ramanpreet Nara d77adcadbe Fix OSS build
Summary:
`CatalystInstanceImpl.cpp` now depends on `JSCallInvoker` and `JavaJSCallInvokerHolder`. Therefore, we need to correctly adjust the OSS builds to include these dependencies into the `libreactnativejni.so` file.

I made `ReactCommon/turbomodule/jscallinvoker` a static library `libjscallinvoker.a`. I then made `ReactAndroid/src/main/jni/react/jni`'s `libreactnativejni.so` depend on that static library. Also, because the Android NDK build system doesn't support header namespaces, I had to use the filesystem to simulate them. This is why all the `.cpp` and `.h` files for `JSCallInvoker` were moved to a `jsireact` folder.

Reviewed By: mdvacca

Differential Revision: D15194821

fbshipit-source-id: 0cee682e41db53d0619f56ad017d5882f6d554aa
2019-05-03 13:31:20 -07:00
Ramanpreet Nara cba205b82c Introduce TurboModuleManagerDelegate
Summary:
`TurboModuleManagerDelegate` is an abstract base class with the following API:

```
  public TurboModule getModule(String name, ReactApplicationContext reactApplicationContext);
  public CxxModuleWrapper getLegacyCxxModule(String name, ReactApplicationContext reactApplicationContext);
```

```
  std::shared_ptr<TurboModule> getTurboModule(std::string name, jni::global_ref<JTurboModule> turboModule, std::shared_ptr<JSCallInvoker> jsInvoker) override;
  std::shared_ptr<TurboModule> getTurboModule(std::string name, std::shared_ptr<JSCallInvoker> jsInvoker) override;
```

On the C++ side, when asked to provide a TurboModule with name `name`:

1. First, is this a CxxModule? If so:
    1. Create the CxxModule and return
2. Otherwise:
    1. Somehow get a Java instance of the TurboModule
    2. If this Java object represents a CxxModule, like `FbReactLibSodiumModule`:
        1. Grab the C++ part of this object, and wrap it in a `TurboCxxModule.cpp` and return.
    3. Otherwise:
        1. Wrap the Java object in a C++ HostObject and return.

This pseudocode demonstrates how we'd use `TurboModuleManagerDelegate` to implement `__turboModuleProxy`.
```
__turboModuleProxy(name, jsCallInvoker):
  let cxxModule = TurboModuleManagerDelegate::getTurboModule(name, jsCallInvoker)
  if (!cxxModule) {
    return cxxModule;
  }

  // JNI Call that forwards to TurboModuleManagerDelegate.getLegacyCxxModule
  let javaCxxModule : CxxModuleWrapper = TurboModuleManager.getLegacyCxxModule(name)

  if (!javaCxxModule) {
    return std::shared_ptr<react::TurboCxxModule>(javaCxxModule.getModule())
  }

  // JNI Call that forwards to TurboModuleManagerDelegate.getModule
  let javaModule : TurboModule = TurboModuleManager.getModule(name)

  if (!javaCxxModule) {
    return TurboModuleManagerDelegate::getTurboModule(name, javaModule, jsCallInvoker)
  }

  return null
```

Reviewed By: mdvacca

Differential Revision: D15111335

fbshipit-source-id: c7b0aeda0e4565e3a2729e7f9604775782b6f893
2019-05-03 13:31:20 -07:00
Ramanpreet Nara ef4955fefe Make async calls work
Summary:
JSCallInvoker requires a `std::weak_ptr<Instance>` to create. In our C++, `CatalystInstance` is responsible for creating this `Instance` object. This `CatalystInstance` C++ initialization is separate from the `TurboModuleManager` C++ initialization. Therefore, in this diff, I made `CatalystInstance` responsible for creating the `JSCallInvoker`. It then exposes the `JSCallInvoker` using a hybrid class called `JSCallInvokerHolder`, which contains a `std::shared_ptr<JSCallInvoker>` member variable. Using `CatalystInstance.getJSCallInvokerHolder()` in TurboModuleManager.java, we get a handle to this hybrid container. Then, we pass it this hybrid object to `TurboModuleManager::initHybrid`, which retrieves the `std::shared_ptr<JSCallInvoker>` from the `JavaJSCallInvokerHandler`.

There were a few cyclic dependencies, so I had to break down the buck targets:
- `CatalystInstanceImpl.java` depends on `JSCallInvokerHolderImpl.java`, and `TurboModuleManager.java` depends on classes that are packaged with `CatalystInstanceImpl.java`. So, I had to put `JSCallInvokerHolderImpl.java` in its own buck target.
- `CatalystInstance.cpp` depends on `JavaJSCallInvokerHolder.cpp`, and `TurboModuleManager.cpp` depends on classes that are build with `CatalystInstance.cpp`. So, I had to put `JavaJSCallInvokerHolder.cpp` in its own buck target. To make things simpler, I also moved `JSCallInvoker.{cpp,h}` files into the same buck target as `JavaJSCallInvokerHolder.{cpp,h}`.

I think these steps should be enough to create the TurboModuleManager without needing a bridge:
1. Make `JSCallInvoker` an abstract base class.
2. On Android, create another derived class of `JSCallInvoker` that doesn't depend on Instance.
3. Create `JavaJSCallInvokerHolder` using an instance of this new class somewhere in C++.
4. Pass this instance of `JavaJSCallInvokerHolder` to Java and use it to create/instatiate `TurboModuleManager`.

Regarding steps 1 and 2, we can also make JSCallInvoker accept a lambda.

Reviewed By: mdvacca

Differential Revision: D15055511

fbshipit-source-id: 0ad72a86599819ec35d421dbee7e140959a26ab6
2019-05-03 13:31:20 -07:00
Valentin Shergin 01523ae660 Fabric: TinyMap in Differentiator
Summary: Diffing algorithm uses a small map for every layer of shadow tree; that's a lot of maps. Luckily, it does not need a complex feature-full map (which is not free to allocate and use), it needs a tiny map with a dozen values. Why do we need to pay for what we don't use? This diff introduces a trivial map optimized for constraints that we have here. (See more details in the code.)

Reviewed By: mdvacca

Differential Revision: D15200495

fbshipit-source-id: d859b68b9543253840b403e7430f945a0b76d87b
2019-05-03 12:36:29 -07:00
Valentin Shergin c5f0969fba Fabric: Code style changes in Differentiator
Summary: Trivial. Code style-only changes.

Reviewed By: mdvacca

Differential Revision: D15200497

fbshipit-source-id: 00b5f2e6ce7491e80e03ceb7f433571f397c2392
2019-05-03 12:36:29 -07:00
Valentin Shergin f8c5fa37d9 Fabric: `insertedPairs` in `calculateShadowViewMutations` now stores pointers (not values)
Summary:
This is a small micro-optimization in Diffing algorithm.
Seems we don't need to store full ShadowView objects in `insertedPairs` map, we can store only pointers to them. That can save memory and CPU cycles because we will not need to store full objects and copy shared pointers (which is somewhat expensive).

Reviewed By: mdvacca

Differential Revision: D15200498

fbshipit-source-id: 2a268c3ee80755555bff3317e10e679be1cf9830
2019-05-03 12:36:28 -07:00
Valentin Shergin 30c3ea5c3f Fabric: Using move semanic in Differentiator
Summary: Diffing is already pretty fast, but using move semantic should make it even faster. ShadowViews have shared pointers, so moving them can save us atomic counter bumps.

Reviewed By: mdvacca

Differential Revision: D15200496

fbshipit-source-id: 6fb0eb79e07cd6ae9b3100713497c634f306bc18
2019-05-03 12:36:28 -07:00
Joshua Gross 4a1d532674 Convert FabricUIManager.measure params to floats
Summary: Convert FabricUIManager.measure params to floats. Currently we convert parameters to ints across the JNI boundary, and then back to floats several times in Java. This is unnecessary and actually makes measurements trickier. The new implementation uses floats across the JNI boundary and uses Float.POSITIVE_INFINITY to represent unconstrained values, which is consistent with Fabric C++ as well.

Reviewed By: shergin, mdvacca

Differential Revision: D15176108

fbshipit-source-id: cf849b3773007637f059279460163872f300a4aa
2019-05-03 12:36:28 -07:00
Ramanpreet Nara 7a8de7db46 Replace throwIfJNIReportsPendingException
Summary: Looks like FBJNI exports a C Macro that does exactly what `throwIfJNIReportsPendingException` does. Therefore, I'm replacing `throwIfJNIReportsPendingException` with calls to `FACEBOOK_JNI_THROW_PENDING_EXCEPTION()`.

Reviewed By: mdvacca

Differential Revision: D15174820

fbshipit-source-id: 9dfb519352cbd5f37527675323cbabad05e31d4a
2019-05-03 12:00:19 -07:00
Ramanpreet Nara a9650709e3 Fix multiple invocations of getConstants
Summary:
`jclass` in `JNI` is just a regular local reference. Therefore, it's unsafe to keep a static reference to it. Link: http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/refs.html.

This bug made it so that when you clicked on `getConstants` twice in the TurboModule playground, the app would crash.

Reviewed By: mdvacca

Differential Revision: D15174821

fbshipit-source-id: 13b2b8726473acc9b07306558044d26bed0db92d
2019-05-03 12:00:19 -07:00
Ramanpreet Nara c9006ce5fb Refactor getConstants implementation
Summary: Previously, we'd override the `TurboModule::get` method inside the `JavaTurboModule` class to return a special `jsi::Function` in the case that the property being accessed was "getConstants". We really don't need to do this because we can simply special-case the invocation of the `getConstants` method inside the `JavaTurboModule::invokeJavaMethod` method.

Reviewed By: mdvacca

Differential Revision: D15174822

fbshipit-source-id: 0ee705be841757d3870c908da911c3872b977a9f
2019-05-03 12:00:18 -07:00
David Aurelio 2fd381caf5 Remove API to constrain measure cache size
Summary: We conducted an experiment with different measure cache sizes. This has now been deallocatedi (D15183473). Remove the necessary APIs.

Reviewed By: SidharthGuglani

Differential Revision: D15183486

fbshipit-source-id: a38fa5a3ab0321c2521265f7d1cd6b495efd76cf
2019-05-03 05:54:49 -07:00
David Aurelio 7df10d3839 Fix `YGConfig` constructors
Summary:
@public

`YGConfig::YGConfig(YGConfig*)` was not initializing the same fields as the default constructors.

Here, we make the default constructor delegate to the more specialized one to remove duplication.

Reviewed By: SidharthGuglani

Differential Revision: D15164599

fbshipit-source-id: 27247709091b7664386057d09ac67d481877871f
2019-05-03 04:59:47 -07:00
Kevin Gozali 0708e28caf TM: removed unused virtual invokeMethod() and invalidate()
Summary:
* invokeMethod() ends up not useful because each platform has its own way of invoking the platform methods
* invalidate() is not necessary because there's already the destructor of each C++ class

Reviewed By: mdvacca

Differential Revision: D15187833

fbshipit-source-id: 9478ed1e6288da30c67179e03a7bc7da6043280b
2019-05-02 14:12:34 -07:00
David Aurelio 29d77ec251 Add foundations for event system
Summary:
@public

We want to enable tooling, instrumentation, and statistics within Yoga without coupling these functionalities to our core code.

This commit introduces the foundations of a simple, global event system.
For the time being, we will only support a single subscriber. Should we require more than one, we can add support for it later.

Reviewed By: SidharthGuglani

Differential Revision: D15153678

fbshipit-source-id: 7d96f4c8def646a6a1b3908f946e7f81a6dba9c3
2019-05-01 17:07:15 -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 b273516b02 Making UITemplateProcessorTest not instrumentation
Summary: Instrumentation tests are expensive and flaky. Luckly this one does not need to be instrumentation one.

Reviewed By: mdvacca

Differential Revision: D15158985

fbshipit-source-id: 3c88e5a0d82db2cd00f5866c3f9956409cc8fc7f
2019-05-01 10:47:11 -07:00
David Aurelio 0c7376c7ce `YGStyle`: Make getters/setters template args of `BitfieldRef`
Summary:
@public

Makes bitfield getters/setters part of the bitfield ref template.
Since we introduced the tracking bit as template parameter in D14933022, every bitfield ref is an individual class anyway, and having function pointers doesn’t potentially lead to less code generation anyway.

Furthermore, this change can (in the absence of tracking bits) avoid less specialized templates dealing with refs, and to dynamic dispatch as a consequence.

Reviewed By: SidharthGuglani

Differential Revision: D15085495

fbshipit-source-id: 0dd70fa05e9d43a29e38a619cddb642c9ca3f7ab
2019-05-01 06:50:56 -07:00
David Aurelio 0e17af907e Track which style properties have been set on `YGStyle`
Summary:
@public

In order to optimise property storage, we have to know how style properties are used in our apps.
Here, we add a bitmask that allows us to track which properties are set explicitely, and use that for our analysis.

Reviewed By: SidharthGuglani

Differential Revision: D14933022

fbshipit-source-id: 1ab8af562b14baba1d02057e527aa36d5c9a7823
2019-05-01 06:50:56 -07:00
David Aurelio a7e4ce0f0d Deduplicate `updateStyle` overloads
Summary:
@public

The extra overload of `updateStyle` introduced in D15078961 can also handle `BitfieldRef`.
That means that we can remove the more specific implementation previously introduced for `BitfieldRef`

Reviewed By: SidharthGuglani

Differential Revision: D15081069

fbshipit-source-id: 98f1f3478627974c5273c85d268ca07350f303d7
2019-05-01 06:50:56 -07:00
David Aurelio 1069b7b4d3 `YGStyle`: mutable accessors return `Ref` instances
Summary:
@public

Change style property accessors to return `Ref` instances instead of references to `CompactValue`.

This will allow to track assignments to properties later on, e.g. for instrumentation or dynamic property storage.

Reviewed By: SidharthGuglani

Differential Revision: D15078961

fbshipit-source-id: 259f05f7d30f093c04bf333c5bd4fb3601b8e933
2019-05-01 06:50:56 -07:00
David Vacca 5200ea8a1a Expose first implementation of the legacy method UIManager.measureInWindow on Fabric
Summary: This diff exposes the Legacy method UIManager.measureInWindow as part of Fabric

Reviewed By: shergin

Differential Revision: D15110795

fbshipit-source-id: 2b4bf47452f7272fd3edc4e580e65ae7ec2f2622
2019-04-30 23:49:20 -07:00
Valentin Shergin 1d65244376 Changes in float-family conversion infra
Summary:
Different frameworks use different kinds of floats, optional floats, and floats with assigned unit names. All those approaches use different ways to represent undefined and empty values. To deal with it we need to have some helper functions.

So, this diff changes some ways that we convert some corner values (like NaN and empty value). That change is motivated by recent personal discoveries in this field that shifted my vision on that. E.g. ComponentKit does not use `CGFloatMax` value as `Infinite` value. UIKit is also (surprisingly to me) okay with using `Infitite` instead of `CGFloatMax`. And, in general, seems using really conceptually appropriate values (instead of UIKit-inspired ones) it's the right thing to do.

Reviewed By: mdvacca

Differential Revision: D15155189

fbshipit-source-id: 33e15141f1ca3efb400a7160811224335de34ba1
2019-04-30 16:38:26 -07:00
Valentin Shergin 0196654f29 Fabric: Using `Infinity` instead of `Undefined` in LayoutConstraints
Summary: `kFloatUndefined` means "no value here", but in this particular case, we have to have `Infinity` value that represents maximum available space.

Reviewed By: mdvacca

Differential Revision: D15155190

fbshipit-source-id: d2de20681ad04da7444331eff44b93d2bd0200e3
2019-04-30 16:38:26 -07:00
Valentin Shergin 181b42bfce Fabric: Inlining (and removing) kFloatMax and kFloatMin constants
Summary:
We don't need to have those constants because this functionality is available in STL via `std::numeric_limits<YourParticularFloatType>::infinity()` (or `::min()` and `::max()`).
At the same time usage of `kFloatMax` was replaced with `Infinity` (which is a different value). Using `max` instead of `Infinity` was an attempt to mimic iOS/UIKit model where `Infinity` and `NaN` values usually are not being used. However, now this does not seem like a good idea. This concept is not used anywhere else (even in CK which is totally incompatible with it) and de-facto in RN we use it only in few places. So, let's use Infinity in places where it's logically appropriate.

Reviewed By: mdvacca

Differential Revision: D15155191

fbshipit-source-id: 4d24350c7540cec074a8b040d7c13f257aa812e7
2019-04-30 16:38:25 -07:00
David Vacca 5b73b6771e Expose measureLayout in UIManagerBinding.cpp
Summary: This diff exposes the Legacy method UIManager.measureLayout as part of Fabric

Reviewed By: shergin

Differential Revision: D15103117

fbshipit-source-id: 4cf7ab3776f6a541cf0d6a00789420a0bb008fae
2019-04-30 15:05:02 -07:00
David Vacca 532afbde6e Add support for Modal in Android
Summary: This diff implements Modal for Android in Fabric

Reviewed By: JoshuaGross

Differential Revision: D15069863

fbshipit-source-id: 4171c9590a4a7a1f4f80cf9b08ea9a9e94b9097a
2019-04-30 15:05:01 -07:00
Kevin Gozali 694bf7104c TM iOS optimization: codegen @selector for each method call.
Summary: This adds support for specifying the exact selector name for each exposed ObjC method. This allows us to avoid dynamic method lookup every time a method is called from JS.

Reviewed By: RSNara

Differential Revision: D15141611

fbshipit-source-id: ed2820782ab013369e4e1f22dbce31d9838a17bb
2019-04-30 13:58:35 -07:00
Valentin Shergin a0523da53d Fabric: Moving RNWrapManagedObject to `react/utils` module
Summary: Apparently we can/should not have in RCTConversions because it creates unnecessary dependency to core iOS module.

Reviewed By: mdvacca

Differential Revision: D15055325

fbshipit-source-id: 507f5a40c03b5c261967de4504297d31ecd02783
2019-04-29 21:21:11 -07:00
Valentin Shergin 718ffe5038 Fabric: `ContextContainer::findInstance` returns an optional intead of throwing an exception
Summary: Sometimes we don't know for sure if `ContextContainer` has a value or not (and that's perfectly legit use case). In those cases now we can use `findInstance` method that returns an optional intead of throwing an exeption.

Reviewed By: JoshuaGross

Differential Revision: D15039137

fbshipit-source-id: 95ba8cc7b76e37d1bd17e18c0098e56350ff3fef
2019-04-29 21:21:11 -07:00
Valentin Shergin 6d9f0a7d2a Fabric: Using full `ShadowNodeFragment` (not just `Props`) during construction of initial state
Summary: It turns out that just only props is not enought to build an initial state value in some cases for some component. Seems we need at least `surfaceId` and `eventEmitter` in some cases (which seems totally reasonable). So, seems using the whole `ShadowNodeFragment` for that purpose is a good choise.

Reviewed By: mdvacca

Differential Revision: D15039135

fbshipit-source-id: d9a5f47f971ccf6cdb2f888bd31f7948b37b67ef
2019-04-29 21:21:11 -07:00
Valentin Shergin 2a55939f20 Fabric: `ShadowNodeFragment::Value` - owning counterpart of `ShadowNodeFragment`
Summary:
`ShadowNodeFragment` is very cheap by design because it does not own stuff it contains, so it's great. But... sometimes we need to own the stuff (e.g. to pass it on the other thread), in those cases we can use `ShadowNodeFragment::Value` now.
`ShadowNodeFragment::Value` cannot be used alone, it needs to be constructed from `ShadowNodeFragment` and then used as opaque object and then it can be converted to ``ShadowNodeFragment`.

We will need it soon.

Reviewed By: mdvacca

Differential Revision: D15039136

fbshipit-source-id: d40875cac05f4088358d8d418007d17df9ff14f4
2019-04-29 21:21:11 -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
Joshua Gross 3c7d8e0cc1 Remove paragraph_measure_cache experiment code
Summary: QE expired a while ago. Remove the experiment code.

Reviewed By: fkgozali

Differential Revision: D15133830

fbshipit-source-id: 562c3998cc7860497eefa9899dfb6bfcee4fe210
2019-04-29 17:52:08 -07:00
David Aurelio 110a382b59 Expose the value type used by `YGStyle` as `ValueRepr`
Summary:
@public

Adds `YGStyle::ValueRepr` to make code depending on the actual type easier to write.

So far, we have treated `yoga::detail::CompactValue` as an implementation detail, and that’s what it’s supposed to stay.

React Native Fabric has one value conversion overload that depends on that type, though, and used `decltype(YGStyle{}.margin()[0])` until now.
That’s problematic for two reasons:

- we want to constrain the parameter of `operator[](...)` to enum types, making the `0` unsuitable
- we want to return the non-const overload of the operator to return a custom `Ref` type, which is not the type needed by Fabric.

Making the storage type explicit allows to write more forward-compatible code.

Reviewed By: SidharthGuglani

Differential Revision: D15078960

fbshipit-source-id: 932c27ef2f2cdc6ce965b79894268170f0ccdce5
2019-04-29 09:22:31 -07:00
David Aurelio 98eabbe61c More constness
Summary:
@public

Some `YGNode*` passed as `const YGNode*`, some const refs to sub-objects introduced.
This helps selecting the desired methods in more places, i.e. `const` overloads of accessors on `YGStyle`.

Reviewed By: SidharthGuglani

Differential Revision: D15078963

fbshipit-source-id: 5013721d6edcc68f42f4504f5c331da647a294bd
2019-04-29 09:22:31 -07:00
David Aurelio cd4270d372 `YGFloatOptional`: Move binary operators to free functions
Summary:
@public

Having binary operators as member functions has disadvantages:

- the left hand side cannot be converted to `YGFloatOptional` implicitly (which we need for `YGStyle` refs)
- Operators are not necessarily commutative.

By moving these operators into free functions, and adding overloads for both variants if one operand is `float`, we get these properties.

Reviewed By: SidharthGuglani

Differential Revision: D15078962

fbshipit-source-id: 2e228a2ef90a8083c91788caa9eedfd4d140677f
2019-04-29 09:22:31 -07:00
Dmitry Dushkin 6ab249f220 Report native module name on crash when native module has failed to load (#24633)
Summary:
After upgrading RN from 0.57 to 0.59.4 we've received a lot of crash reports like `Exception in HostObject::get: <unknown>`  with no clue what native module caused the crash. This commit adds native module name on crash in this situations. Related to https://github.com/facebook/react-native/issues/24607.

[General] [Added] - Report native module name on crash when native module has failed to load
Pull Request resolved: https://github.com/facebook/react-native/pull/24633

Differential Revision: D15120225

Pulled By: cpojer

fbshipit-source-id: cf8e3e5953548a58f1d010eb70343da5ee946ae8
2019-04-29 03:36:17 -07:00
Estevão Lucas ca9a55e28b Remove `accessibilityTraits` prop (accessibility) (#24643)
Summary:
`accessibilityTraits` and `accessibilityComponentType` were removed on #24344. This PR removes `accessibilityTraits` prop from Fabric as well.

[General] [Removed] - Remove `accessibilityTraits` prop from Fabric.
Pull Request resolved: https://github.com/facebook/react-native/pull/24643

Differential Revision: D15120193

Pulled By: cpojer

fbshipit-source-id: 98440ac447569c26205fc38b93ce2591ccf1a3cf
2019-04-29 03:17:58 -07:00
David Aurelio ffc0986a38 `YGNodeToString`: take const ref to node style
Summary:
@public

Takes a const reference to the style of the printed node once, instead of using repeated calls to `node->getStyle()`.
Makes the code a bit shorter, and ensures that we are operating on `const YGStyle&`, which helps selecting the correct methods further up the stack.

Reviewed By: SidharthGuglani

Differential Revision: D14999094

fbshipit-source-id: 814f06b7e3179ac8cfb43d79fbec48ee4115d6e3
2019-04-26 02:13:34 -07:00
Ramanpreet Nara e7a8b26f22 Fix ObjCTurboModule::getArgumentTypeName
Summary: In `ObjCTurboModule::getArgumentTypeName`, I replaced all instances of `':'` with `''` to transform the selector into a TurboModule methodName. This transformation works when the method has 0 or 1 argument, however, it breaks when the method has more than 1 argument. In all cases, we just want to get the substring until the first `':'`.

Reviewed By: fkgozali

Differential Revision: D15056937

fbshipit-source-id: 3a7dce1ce62ca9758e46c0af951b269166d68454
2019-04-23 17:52:21 -07:00
Valentin Shergin 11439eabfc Fabric: Using `#ifndef NDEBUG` instead of `#ifdef DEBUG`
Summary:
Trivial.
Apparently, `DEBUG` is non-standard feature and using `assert` with `DEBUG` is practically asking for bugs. So, if your `assert` relies on some variable which is only defined when `DEBUG` is set, it's easy to get invalid code because NDEBUG and DEBUG can be unsync.
So, we have to use clunky double negative `#ifndef NDEBUG` everywhere where we used DEBUG.

Reviewed By: JoshuaGross

Differential Revision: D15031328

fbshipit-source-id: 036f573e68925741ca46384261885766c87db1e3
2019-04-23 15:13:36 -07:00
David Aurelio 7e9d6ea51d Introduce `YGNodeConstRef`
Summary:
@public

Introduces `YGNodeConstRef` as `const YGNode*`, i.e. a pointer to a constant `YGNode`.
We also use it for all style getters, which will avoid casts to `const YGNode*` in diffs up the stack.

We should use this pointer type for all functions that do not modify the underlying node.

Reviewed By: SidharthGuglani

Differential Revision: D14999095

fbshipit-source-id: 61cc53bb35e787a12ae12e70438d84c0a4983752
2019-04-23 10:14:06 -07:00
David Aurelio 54af7fc645 `YGStyle`: wrap all fields into accessors
Summary:
@public

In order to encapsulate property access on `YGStyle`, as a first measure we wrap all fields with accessors.

This will e.g. enable dynamic property storage and instrumentation in the future.

All accessors have a `const` version that allows direct access via `const&`. For mutation, bit fields are wrapped with a custom reference object.

This style allows for the least amount of changes in client code. Property access simply needs appended parens, eg `style.direction` becomes `style.direction`.

Reviewed By: shergin

Differential Revision: D14999096

fbshipit-source-id: fbf29f7ddab520513d4618f5e70094c4f6330b30
2019-04-23 08:12:35 -07:00
David Aurelio af84193df4 `Yoga.h`: clean up `const` / `extern`
Summary:
@public

Remove unnecessary `const` and `extern` specifiers from `Yoga.h`.

- Function declarations are `extern` by default
- The removed `const` specifiers for pass-by-valye parameters are only meaningful for the *definition* of functions, not for the declaration.
In this specific case, I found `const YGNodeRef` particularly confusing, as it is a `typedef` for a pointer type. `const` does not refer to the pointed-to object, but to the parameter itself, i.e. `const YGNodeRef` is `YGNode * const`, and not `const YGNode *`.

Reviewed By: SidharthGuglani

Differential Revision: D14999097

fbshipit-source-id: 8350870cb67f4a34722f796c4f4a2fc7dde41b99
2019-04-23 08:12:35 -07:00
Ramanpreet Nara c9c8f8d5b3 Remove jClassName_ member
Summary: `jClassName_` is unnecessary because you can use `JNIEnv::GetObjectClass` to get the TurboModule's Java class.

Reviewed By: fkgozali

Differential Revision: D14937480

fbshipit-source-id: 2c1c9be53217331152270dbac3d13f372a2ed818
2019-04-22 15:33:06 -07:00
Valentin Shergin b4044e5b1b Fabric: Fixed overlapping border radii
Summary:
UAs must adjust border radius values to fit a content box:
>>> Corner curves must not overlap: When the sum of any two adjacent border radii exceeds the size of the border box, UAs must proportionally reduce the used values of all border radii until none of them overlap.

This diff implements that.

Reviewed By: mdvacca

Differential Revision: D15028325

fbshipit-source-id: 368232ffa2fa0409d13759bbbe7fe10f8474c400
2019-04-22 09:04:54 -07:00
Valentin Shergin 2688780394 Fabric: DEBUG-only check for type match in ContextContainer
Summary: Additional check verifies that requested type matches the type of a stored value.

Reviewed By: mdvacca

Differential Revision: D14944336

fbshipit-source-id: 6d3a1654d9b9a64ced83f553236093f02f2c97c7
2019-04-22 08:36:08 -07:00
Valentin Shergin 758eb9fa7b Fabric: Fixed incorrect assert condition in MountingTransactionSynchronizer
Summary: Trivial, a classic negative logic trap.

Reviewed By: cpojer

Differential Revision: D15027218

fbshipit-source-id: c17c9b39c7ee7fff817edf15b2b537e53422595d
2019-04-21 10:10:14 -07:00
Valentin Shergin 94969edf7c Fabric: Say hello to `MountingTransactionSynchronizer`
Summary:
ShadowTree commits happen concurrently with limited synchronization that only ensures the correctness of the commit from ShadowTree perspective.
At the same time artifacts of the commit () needs to be delivered (also concurrently) to the proper thread and executed in order (not-concurrently). To achieve this we need some synchronization mechanism on the receiving  (mounting) side. This class implements this process.

Practically, this diff fixes a problem with glitching UI during the very first render of Fabric screen.

Reviewed By: JoshuaGross

Differential Revision: D15021794

fbshipit-source-id: 62982425300c515e92b91e1e660b45455a5446e9
2019-04-20 10:53:16 -07:00
Valentin Shergin af0daaf583 Fabric: Introducing MountingTransaction
Summary:
`MountingTransaction` encapsulates all artifacts of `ShadowTree` commit, particularly list of mutations and meta-data.
We will rely on this heavily in the coming diffs.

Reviewed By: JoshuaGross

Differential Revision: D15021795

fbshipit-source-id: 811da7afd7b929a34a81aa66566193d46bbc34f8
2019-04-20 10:53:16 -07:00
Valentin Shergin c257a57e8e Fabric: Quick and diry fix for `UnimplementedNativeView`
Summary: We have to figure out a different way to request for a fallback component in ComponentDescriptorRegistry and in general, in public APIs. But now, to stop crashing here the fix.

Reviewed By: JoshuaGross

Differential Revision: D15021796

fbshipit-source-id: a60c66838e76ace990f2eb764c86c29d24db2141
2019-04-20 10:53:16 -07:00
Joshua Gross c31602acdc `getContextContainer` should be marked as const
Summary: `getContextContainer` should be marked as const so that const instances can call it.

Reviewed By: shergin

Differential Revision: D14969981

fbshipit-source-id: 8812f24ecf0642a38496580689943fbd43cddad1
2019-04-19 02:27:50 -07:00
zhongwuzw 12d58d431a Update rncore podspec to exclude codegen test files (#24513)
Summary:
Related bddd9c7d59. Exclude these tests files from podspec.

cc. cpojer

[iOS] [Fixed] - Update rncore podspec to exclude codegen test files
Pull Request resolved: https://github.com/facebook/react-native/pull/24513

Differential Revision: D14996897

Pulled By: rickhanlonii

fbshipit-source-id: 28b29f24f482ed678f15c44c5c579ced97ea651f
2019-04-18 09:30:51 -07:00
Valentin Shergin 832164169d Fabric: Unification of registration process of `ComponentView`s and `ComponentDescriptor`s
Summary:
Registries, providers, providers of registries, registres of providers. All that can be really confusing, but that represents best the constraints and desires that we have:
* We need to be able to register components on-the-fly (so we need a mechanism that will propagate changes);
* We don't want to register ComponentDescriptors separately from ComponentView classes;
* C++ not always gives us abstractions that we want (e.g. pointers to constructors).

After the change, we can remove the whole Buck target that has a bunch of handwritten boilerplate code.

There is a still room for polish and removing some concepts, types or classes but this diff is already huge.

Reviewed By: JoshuaGross

Differential Revision: D14983906

fbshipit-source-id: ce536ebea0c905059c7a4d644dc25233e2809761
2019-04-17 22:44:20 -07:00
Valentin Shergin 00eab3d6fb Fabric: Introducing ComponentDescriptorProvider
Summary:
ComponentDescriptorProvider represents unified way to create a particular descriptor.
Now all ComponentViews (which support RCTComponentViewProtocol) expose a `ComponentDescriptorProvider` which will allow creating and registering ComponentDescriptor instances for all visual components automatically as a part of ComponentView registration process.
Don't panic, everything is still being as explicit as it always was, no magic involved; we just will have only one registration step instead of two parallel.

That also opens a way to register components on the fly.

Reviewed By: JoshuaGross

Differential Revision: D14963488

fbshipit-source-id: 9e9d9166fabaf7b30b35b8647faa6e3a19cd2435
2019-04-17 22:44:20 -07:00
Marc Horowitz 0735873fbc Make isInspectable safe to call from any thread
Summary: The bridge was not properly isolating isInspectable onto the JS thread.

Reviewed By: fkgozali

Differential Revision: D14991970

fbshipit-source-id: 92a06c90bade8f92bfa81fa3b7dfb23b17db6117
2019-04-17 21:23:19 -07:00
Kevin Gozali 1149d85b9f iOS RNTester: install SampleTurboModule regardless
Summary: This installs the sample module to the RNTester.xcodeproj without using any TurboModule infra. This is possible because SampleTurboModule is backward compatible with the existing NativeModules system. This also fixes CI test failure: https://circleci.com/gh/facebook/react-native/84752

Reviewed By: RSNara

Differential Revision: D14987572

fbshipit-source-id: f5f2c4330c7f6558c7d4beeb43198869090dee02
2019-04-17 16:37:49 -07:00
Valentin Shergin 45ae1e4411 Fabric: `[]`-family of methods was removed from ComponentDescriptorRegistry
Summary:
Motivation:
 * We don't use them much, and we already have `at`-methods, which are better.
* We don't want to expose `ComponentDescriptor`s as shared pointers (because it's not clear, not so performant, and because we don't want to store them as shared pointer in the future);
* In idiomatic C++ `[]` operator has mutating semantic, that's not what we want to communicate via the interface of the class.

Reviewed By: sahrens

Differential Revision: D14963487

fbshipit-source-id: dbfddee2ba90d70c3bb8dcf1959d553571c47bab
2019-04-17 13:39:20 -07:00
Ramanpreet Nara 129aeacf48 Add exception handling to method invocations
Summary:
If you call into a Java method (from C++ using JNI) that raises an exception, the JNI call won't actually raise a C++ error. Instead, the `JNIEnv` will record the pending Java exception and the C++ will continue executing as normal. This is bad because the next time you call into JNI, the app will actually crash, unless you explicitly cleared the exception using `JNIEnv::ExceptionClear()` before the JNI call.

With respect to TurboModules, we need to make sure that RedBoxes show up whenever a native methods raise an exception. We also don't want the app to crash when a JNI method call fails because of a raised exception. Therefore, in this diff, I raise a C++ exception if `JNIEnv::ExceptionCheck()` is true.

Reviewed By: mdvacca

Differential Revision: D14738540

fbshipit-source-id: 4c3063aa93ae7aef025bd2dab6b45059bb8fb409
2019-04-16 09:18:14 -07:00
Ramanpreet Nara d1c35aaa84 Add support for Promises
Summary:
If the return type of a TurboModule method is `Promise`, the infra should create a `com.facebook.react.bridge.Promise` object and pass it as the final argument of the TurboModule Java method call. The Java TurboModule method can then do some work asynchronously and either resolve or reject the promise at some point in time.

**Note:** I stacked a diff for error handling on top of this one.

Reviewed By: mdvacca

Differential Revision: D13653156

fbshipit-source-id: 4c30c3223ad8f47c6ba7f1236527aaced01c8ae8
2019-04-16 09:18:14 -07:00
Valentin Shergin 1f5af2a6f1 Fabric: ComponentDescriptor now contains ContextContainer and EventDispatcher refs
Summary:
Turns out that storing and using ContextContainer in custom subclasses is a huge pain. At the same time seems that a lot of custom components need some DI instrument, so we need this instrument anyway.

Moving stuff from the template to the base class should also help with codesize a bit.

Reviewed By: JoshuaGross

Differential Revision: D14921356

fbshipit-source-id: 4dbb961fe32bd66c73513d7e053bbed229860a31
2019-04-16 07:35:07 -07:00
Valentin Shergin 184cfd5594 Fabric: Bunch of small changes in ContextContainer
Summary:
So, changes:
* Correctness checks only in debug mode (codesize win?);
* `registerInstance` marked as const (because it's thread safe);
* ContextContainer::Shared also enforces constness;
* Using faster better::map;
* Using shared/RW mutex instead of regular one;
* SharedContextContainer got removed.

Reviewed By: sahrens

Differential Revision: D14920284

fbshipit-source-id: f0f8d970e7fae79a1abe3bc32827db9fd2d17e13
2019-04-16 07:35:07 -07:00
David Aurelio cdf3343dd0 Code formatting: allow short inline methods on one line
Summary:
@public

This allows short methods defined in class declarations to occupy a single line.
The change makes class declarations more readable.

Reviewed By: SidharthGuglani

Differential Revision: D14950012

fbshipit-source-id: 1321949475184181c6cceb86613f730e430763e2
2019-04-16 07:14:12 -07:00
Kevin Gozali 4da6e4a042 TM iOS: Install SampleTurboModule in RNTester (pods)
Summary: This sets up RCTSampleTurboModule (and other variants) in RNTester when built with cocoapods. There's no call site yet though. And RNTester.xcodeproj doesn't support it.

Reviewed By: cpojer

Differential Revision: D14932535

fbshipit-source-id: db8eafd6777cbec8f3592dafdccbdd7cf44e38bc
2019-04-15 12:25:48 -07:00
Kevin Gozali a2aba45067 TM iOS: Move SampleTurboModule to OSS
Summary:
This provides various versions of SampleTurboModule, that are:
* compatible with existing NativeModule
* TurboModule compliant

Variants:
* RCTSampleTurboModule (traditional objc module)
* RCTSampleTurboCxxModule (objc++ module using CxxModule)
* SampleTurboModule (pure C++ impl of a TurboModule, no ObjC)

As noted in some files, they need to be codegen'ed based on the `NativeSampleTurboModule.js` (Flow type). The codegen script is not yet usable in OSS (we'll work on it some time in H2 2019). For now, these files need to be manually synced with Flow type.

Reviewed By: cpojer

Differential Revision: D14932539

fbshipit-source-id: fb887192384e5e6e4dff4cac68b4e037a4783cd9
2019-04-15 12:25:47 -07:00