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

1717 Коммитов

Автор SHA1 Сообщение Дата
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
Kevin Gozali e612b9b0f5 TM iOS: Install TurboModule system in RNTester (pod) by default
Summary:
For CocoaPods variant only: install TurboModule binding so that sample modules can start using it. This commit only installs `global.__turboModuleProxy` - no sample module is provided.

Note: RNTester.xcodeproj will NOT have TurboModule enabled, due to complication in the .xcodeproj setup (doable, but maybe for some other time...)

To test:

```
console.error(global.__turboModuleProxy == null ? 'BOO' : 'YAY!');
```

Saw `YAY!` in RNTester pod version.

Reviewed By: cpojer

Differential Revision: D14932536

fbshipit-source-id: 3dc083da9154ec320ce6789ec7f2cef5a08fd6a7
2019-04-15 12:25:47 -07:00
David Aurelio 96cf6f821e Define all style getters/setters explicitely
Summary:
@public

For better grepping, we define all `YGNodeStyle...` accessors explicitely. This also replaces all macros with a set of templates that can easily be updated when we switch to style accessors on `YGNode`.

Transitioning to a consistent set of templates also allowed to end up with a single *needs update* / *do update* / *mark dirty* block.

The new template code also takes full advantage of the properties of `YGOptional` (constructor call with *not a number* creates an empty optional) and `detail::CompactValue` (conversions of *auto* and *undefined* are always well-formed) to get rid of some additional code:

Removed `NAN` check:
```
 _YGNodeStyleSetFlex:
 	pushq	%rbp
 	movq	%rsp, %rbp
 	movss	0x34(%rdi), %xmm1
 	ucomiss	%xmm0, %xmm1
 	jne	0x____
 	jnp	0x____
 	ucomiss	%xmm0, %xmm0
 	jnp	0x____
 	ucomiss	%xmm1, %xmm1
 	jnp	0x____
 	popq	%rbp
 	retq
-	ucomiss	%xmm0, %xmm0
-	movd	%xmm0, %eax
-	movl	$0x7fc00000, %ecx
-	cmovnpl	%eax, %ecx
-	movl	%ecx, 0x34(%rdi)
+	movss	%xmm0, 0x34(%rdi)
 	popq	%rbp
 	jmp	0x____
-	nopw	%cs:(%rax,%rax)
-	nop
+	nopw	(%rax,%rax)
```

Removed well-formedness check:
```
 _YGNodeStyleGetPosition:
 	pushq	%rbp
 	movq	%rsp, %rbp
 	movl	%esi, %eax
 	movl	0x68(%rdi,%rax,4), %ecx
+	xorl	%eax, %eax
 	movq	(%rip), %rcx
 	movl	(%rcx), %eax
 	movl	0x4(%rcx), %ecx
-	movq	%rcx, %rdx
-	shlq	$0x20, %rdx
+	shlq	$0x20, %rcx
 	movl	%eax, %eax
-	orq	%rdx, %rax
-	cmpl	$0x3, %ecx
-	je	0x____
-	testl	%ecx, %ecx
-	jne	0x____
-	movl	$0x7fc00000, %ecx
-	jmp	0x____
-	movq	%rax, %rcx
-	movabsq	$-0x100000000, %rdx
-	andq	%rax, %rdx
-	movl	%ecx, %eax
-	orq	%rdx, %rax
+	orq	%rcx, %rax
 	popq	%rbp
 	retq
 	nopw	(%rax,%rax)
```

Reviewed By: SidharthGuglani

Differential Revision: D14911973

fbshipit-source-id: db6eef65f8fdaf70875f7fe8799919ca88bd50ee
2019-04-15 10:53:50 -07:00
Sidharth Guglani 21363add69 Use only 4 edges for margin, padding, border in YGLayout
Summary:
We were using four edges for margin, padding and border. This diff changes the array size in YGLayout for margin, padding, border to reduce YGNode size and corresponding changes while we are setting values in YGLayout.
Reduces the YGNode size by 24 bytes

Reviewed By: davidaurelio

Differential Revision: D14892666

fbshipit-source-id: 94013d5183ee869901267c4c9941fd94fa05d848
2019-04-15 05:42:20 -07:00
Valentin Shergin 792585fd48 Fabric: ContextContainer was moved to `utils` module
Summary: That allows avoiding circular deps and unnecessary deps on uimanager module.

Reviewed By: PeteTheHeat

Differential Revision: D14917227

fbshipit-source-id: fe7962ee528aa659d8bd23e3e46627722551d995
2019-04-12 15:14:48 -07:00
Valentin Shergin 00243c580f Fabric: Farewell MountItem classes
Summary:
This diff replaces all MountItem classes with a bunch of static C functions that do the same job as classes did.
Seems, originally we overestimated the complexity of MountItem classes and that they ended up being notably trivial. Now, maintaining that even longer would mean paying for abstractions and allocations that we don't really need and writing a lot of tedious code.
Besides that, the one particular change that will be introduced in the coming diffs is not particularly fit very well in the existing class-based model.

This change also should save us many hundreds of allocations and atomic counters bumps, so maybe we can get a millisecond-or-two win.

This diff does not introduce any practical behavioral/logical changes in the mounting layer.

Reviewed By: mdvacca

Differential Revision: D14893764

fbshipit-source-id: 6f1247923ae36f29c12a7d358e2d496cf6c3e298
2019-04-12 09:32:55 -07:00
Kevin Gozali 65033d7078 Fabric: preserve original props when using fallback component
Summary: This fixes a minor bug where the original props (like for styling) got dropped when the system falls back to UnimplementedView.

Reviewed By: mdvacca

Differential Revision: D14898906

fbshipit-source-id: 4a07952ceac66e491a5c0bc1ffd99f21438cda31
2019-04-11 14:23:13 -07:00
David Vacca 8fcb229a2b - Integrate AndroidSwipeRefreshLayout component into Fabric Android
Summary: This diff integrates AndroidSwipeRefreshLayout component into Fabric Android

Reviewed By: shergin

Differential Revision: D14817453

fbshipit-source-id: 348db960290fbab7bedf59d046b6ba68629447f6
2019-04-10 16:18:21 -07:00
David Vacca 5850bd0785 Force Diffing algorithm to insert views Bottom Up (from children to root)
Summary:
This diff changes the way views are inserted by the diffing algorithm.
Previously the diffing algorithm inserted views top-down, now it insert views bottom-up (same order as previous version of RN).

Let say we need to create the following tree:
```

A --> B --> C
      |
      | --> D

```

Before, the diffing algorithm created the following list of instructions:
```
insert(A, B, 0)
insert(B, C, 0)
insert(B, D, 1)
```

After this diff, the insert instructions are going to be:

```
insert(B, C, 0)
insert(B, D, 1)
insert(A, B, 0)
```

Reviewed By: shergin

Differential Revision: D14817454

fbshipit-source-id: 7aac1a1e1784c53bca2747aee80a5bc8ee788e7a
2019-04-10 16:18:20 -07:00
Kevin Gozali 417adf526f Fabric iOS: allow using fallback component for unsupported ones
Summary:
This allows an unsupported component to be rendered as a "unimplemented view" for better visualization of which component is missing. It is off by default, but configurable in the component factory.

For now, the layout simply follows regular <View />, which means the width/height etc is based on the react component styling. The side effect is that components with 0 height/width won't show up at all.

Reviewed By: mdvacca

Differential Revision: D14869656

fbshipit-source-id: f31e012fb7dc1c64fcc431ea5aa45079a23a618e
2019-04-10 11:04:23 -07:00
Kevin Gozali 63343dad2e Fabric: properly convert prop value with object shape
Summary:
For props that expects a struct/object value, like scrollView's contentInset, not all keys may be present. For example:

```
<ScrollView ... contentInset={{top: 10}} />
```

In this example, `left`, `bottom`, and `right` should just default to 0 (or whatever the default is in the platform). Before this fix, an exception occured when calling `fromRawValue()` because it is assuming all 4 keys are present in the prop bag. However, only `top` key was present in this example.

To fix this, we have to loop through the available keys in the prop bag, then assign the values accordingly.

Reviewed By: JoshuaGross

Differential Revision: D14868549

fbshipit-source-id: e25208eb31f6d4061338e9cac48a93fe71859859
2019-04-10 11:04:23 -07:00
zhongwuzw 0df3cde152 Add missing react native config header in paragraph component descriptor (#24395)
Summary:
cc. shergin .
<img width="1040" alt="264CAC48-1DDB-42D1-95C2-39EA86BA09B1" src="https://user-images.githubusercontent.com/5061845/55892783-8c3fa680-5be9-11e9-970e-be321599e6db.png">

[Genernal] [Fixed] - Add missing react native config header in paragraph component descriptor
Pull Request resolved: https://github.com/facebook/react-native/pull/24395

Differential Revision: D14874388

Pulled By: cpojer

fbshipit-source-id: 660a8f177c43456f6fe1ed29efdc76630f6bc0f3
2019-04-10 10:58:53 -07:00
zhongwuzw e240ac0dc6 Update jsi podspec to support new directory structure (#24388)
Summary:
Related 094f221a0c, restructure the jsi directory, so update the podspec file either.

cc. shergin cpojer

[iOS] [Fixed] - Update jsi podspec to support new directory structure
Pull Request resolved: https://github.com/facebook/react-native/pull/24388

Differential Revision: D14869999

Pulled By: cpojer

fbshipit-source-id: 0a5df7e2ad83702c0498b2f70072735accc7f54c
2019-04-10 03:45:17 -07:00
Will Holen 5e5439a921 Update JSI from upstream
Summary: This change synchronizes the JSI API with its upstream, aiming to make this easier to automate in the future.

Reviewed By: mhorowitz

Differential Revision: D14783311

fbshipit-source-id: c180d0f728afbeb87a3e8e7331a39c06e73b907e
2019-04-09 11:44:32 -07:00
Will Holen 094f221a0c Move JSI source files into a separate directory
Summary: This will simplify updating the JSI API from upstream in the future.

Reviewed By: mhorowitz

Differential Revision: D14762674

fbshipit-source-id: fa4a86f08425943e301da4ef3df9893ebaa1493e
2019-04-09 11:44:32 -07:00
David Aurelio 32739afcc1 Fix bugs around `align-content`
Summary:
@public

Regenerating the “golden master” tests with chrome surfaced different bugs around `align-content`:

- a misunderstanding that values in `align-content` only applied *if there is only one line.* In fact, it applies *every time* a container is set to `flex-wrap: wrap`. Chrome had this wrong, and as such our tests were generated with incorrect parameters.
- empty children growing to the cross axis size of the container, even when `align-content` is different from `stretch`. This was implemented incorrectly in Chrome as well. Here, we fix it with an extra check.

Reviewed By: SidharthGuglani

Differential Revision: D14725402

fbshipit-source-id: a45bebdadb9c694dc0eb7e27cb52b3d247f81c50
2019-04-08 03:19:57 -07:00
Valentin Shergin e5feb0cee3 Fabric: Fixing const correctness in ShadowNodeFragment (and some prettification)
Summary:
Previously, all placeholders methods have return type `SomeType &` which is not correct because it allows the called to modify enclosed `static` value of the placeholders; the type should be `SomeType const &`.
Besides that this diff migrates some type aliases to the new style (which makes evething much prettier and readable).

Reviewed By: mdvacca

Differential Revision: D14819076

fbshipit-source-id: 87e68d546f16d7a9ad1fb65e1b238859f9381eb7
2019-04-06 09:15:17 -07:00
Daniel Andersson 407dca8cf0 Support experimental re-mmap wrappers
Summary: Add experimental support for reordering the pages of a file that is mmap:ed by JSBigFileString. The wrapper is auto-detected (by checking file size and magic header) and transparently reorders the pages.

Reviewed By: ridiculousfish

Differential Revision: D14721397

fbshipit-source-id: 34e095350a9eeb9b07105bed6f3379f2fe472ae6
2019-04-04 21:12:09 -07:00
Valentin Shergin ad708eb6e1 Fabric: `getDebugDescription` for `ShadowView` and `ShadowViewMutation`
Summary:
Trivial.
Now we can print actual list of mutations in case of some failure in the diffing algorithm.

Reviewed By: mdvacca

Differential Revision: D14715079

fbshipit-source-id: d0af7c756287643892d7120c199bc8028a6b3431
2019-04-04 12:38:22 -07:00
Valentin Shergin 7cf3938efb Fabric: `getDebugDescription` implementation for `shared_ptr`, `weak_ptr` and `unique_ptr`
Summary: Trivial.

Reviewed By: mdvacca

Differential Revision: D14715083

fbshipit-source-id: 92031cbbf166ea00569a6076d41575a9fd741043
2019-04-04 12:38:22 -07:00
Valentin Shergin 0fb27a7633 Fabric: *Informal* `DebugStringConvertible` interface
Summary:
Informal `DebugStringConvertible` interface serves the same purpose as `DebugStringConvertible` abstract class (providing universal pretty-printing interface) but relies on C++ static overloading instead of virtual dispatch.

This approach has some advantages and disadvantages:
Pros:
 * It's more clear and scoped. It's simpler to implement debug-printing functionality aside of normal production code.
* It's more composable.
* It allows print types that are not classes.
* For some classes using `DebugStringConvertible` means that we have to use virtual inheritance (which might be undesirable and affect *production* performance (if a compiler isn't smart enough to remove empty base class).
* For some highly lean classes (that designed to be as small as possible) adding base (even empty-in-prod) classes kinda... smells.

Cons:
The particular implementations cannot rely on dynamic dispatch which can complicate printing classes with meaningful differences between sampling classes (e.g. ShadowNode subclasses). That's why we don't remove `DebugStringConvertible` class yet.

Reviewed By: mdvacca

Differential Revision: D14715081

fbshipit-source-id: 1d397dbf81dc6d1dff0cc3f64ad09f10afe0085d
2019-04-04 12:38:21 -07:00
Valentin Shergin cabc9d1ab3 Fabric: `toString` methods were moved into `DebugStringConvertible` with an implementation in .cpp file
Summary:
They need to be in DebugStringConvertible because it depends on they (and because `debugStringConvertibleUtils` depends on `DebugStringConvertible`).
We also moved they implementation to cpp file to avoid leaking Folly's features to consumer namespace.

Reviewed By: mdvacca

Differential Revision: D14715080

fbshipit-source-id: 7277e17b39a14a2d7ba7e5a9b44a70178feb1045
2019-04-04 12:38:21 -07:00
Valentin Shergin 97e064b696 Fabric: Improvements in DebugStringConvertible
Summary:
* Small improvements in pretty-printing algorirhm (adding spaces and new-line caracters). Now it's even more pretty.
 * The `depth` parameter was integrated into `DebugStringConvertibleOptions` which simplifies evething a bit and reduce amount of arguments that `getDebugDescription` requires.

Reviewed By: sahrens

Differential Revision: D14715082

fbshipit-source-id: 3ea0b8db3c1816c5cb43f40ccec9cdc1943f33a5
2019-04-04 12:38:21 -07:00
David Aurelio b015b99fce Move `YGSetUsedCachedEntries` to internal header
Summary:
@public

In order to get out of pre-releases again, we move `YGSetUsedCachedEntries` from `Yoga.h` to `Yoga-internal.h`.
This way, it’s obvious that the function is not public, and we can remove it from future versions without breaking semver contracts.

Reviewed By: SidharthGuglani

Differential Revision: D14726029

fbshipit-source-id: 8d7e747e843bf5c4b5e1d4cfbfa37ca9d240dffb
2019-04-03 08:45:39 -07:00
Kevin Gozali 71a8944b39 TM iOS: Use weak_ptr to pass around Instance to avoid unreleased refs
Summary:
There is a timing issue when reloading the bridge (in dev mode) and the tear down of the TurboModules. This causes `Instance` to never get freed, hence the "bridge" isn't cleaning up properly. The side effect can be bogus error saying that it's unable to find a module.

To address this, JSCallInvoker should just take in weak_ptr<Instance>.

Reviewed By: RSNara

Differential Revision: D14739181

fbshipit-source-id: f9f2a55486debaeb28d3d293df3cf1d3f6b9a031
2019-04-02 18:11:18 -07:00
Daniel Andersson 2387d7d255 Make it possible to run JSBigString tests
Summary: Add a target for JSBigString tests that can be run with a normal `buck test` invocation. Also fix an issue in the test when `getenv` returns null by defaulting to `/tmp`.

Reviewed By: ridiculousfish

Differential Revision: D14716270

fbshipit-source-id: f2eb6d3aab93c32a4b41f5786aedd04a70468d75
2019-04-02 16:42:56 -07:00
Valentin Shergin b10da79fb4 Fabric: Introspection (self testing in debug mode) in ShadowTree
Summary:
We suspect that we have some error in diffing algorithm that cause some crashes in mounting layer, so we decided to write a comprehensive unit tests for that.

Writing them we realized that it would be cool to also enable that for normal app run in the debug more, so we can catch the problem in real environment when/if it happens.

Reviewed By: mdvacca

Differential Revision: D14587123

fbshipit-source-id: 6dcdf451b39489dec751cd6787de33f3b8ffb3fd
2019-04-01 10:50:50 -07:00
Valentin Shergin 3e4a8e35fe Fabric `ShadowTree` (and co) was moved to `mounting` module
Summary: Because it's kinda more logical and we will rely on this in comming diffs.

Reviewed By: mdvacca

Differential Revision: D14587124

fbshipit-source-id: 94ae9410b4ffeffd0fcb4da4a0518f0bb0d2ba63
2019-04-01 10:50:50 -07:00
Ramanpreet Nara 46944b7937 Implement auto-conversions from primitives to Objects
Summary:
If a NativeModule method requires an optional boolean argument, our codegen translates those optional booleans into `NSNumber*` instead of `BOOL`. The reason why is probably because this is the closest object analogue to `BOOL` in Objective C. The same boxing occurs with numbers. If the type of a number argument in JavaScript is optional, we'll map it to the `NSNumber*` Objective C type instead of `double`. Our existing TurboModules argument conversion code would not take this behaviour into account. Therefore, we'd try to insert a `BOOL` where the `NSInvocation` would expect a `NSNumber*`. This, in turn, would cause the app to crash. (Why would it crash at the point of NSInvocation retainArguments, I'm still not sure).

Our flow typechecking ensures that if the type of a method argument is a boolean, we pass in a boolean. Therefore, on the Native side, if we detect a boolean, we can check the type of the Native argument to see whether we should box the primitive. If the native argument type is an object, then we know it has to be an `NSNumber*` in both cases, so we simply wrap the `BOOL` or `double` in a `NSNumber*`.

Reviewed By: shergin

Differential Revision: D14679590

fbshipit-source-id: c394a878492aab8e98c71d74ec8740a94fc3a6c5
2019-03-31 02:49:35 -07:00
Valentin Shergin 8774229f66 Fabric: Removed log leftover
Summary: Trivial.

Reviewed By: mdvacca

Differential Revision: D14696997

fbshipit-source-id: 5f093ae5f343f2a2a2ee060f0574a6acf4c186d4
2019-03-30 12:21:54 -07:00
Valentin Shergin 5a418c5a5d Fabric: Fixed a bug in Diffing algorithm
Summary: Before the fix, the algorithm compares ShadowViews to make a decision should it recursively call itself or not; that didn't work properly because a ShadowView doesn't fully represent the state of the subtree tree (e.g. they don't have information about children nodes). After the fix, we compare pointers to ShadowNodes (by comparing pairs).

Reviewed By: mdvacca

Differential Revision: D14696996

fbshipit-source-id: 560d623b15a272f13b08a11745dec6be39a5dbdd
2019-03-30 12:21:54 -07:00
Kevin Gozali a43e666a34 TM iOS: force flush message queue when calling into JS from native
Summary: When calling into JS (e.g. promise resolve/reject, callback) in TurboModule, we bypass the bridge's message queue. At times this causes race condition, where there are a bunch of pending UI operations (in RCTUImanager) waiting to be flushed, but nothing adds calls to the message queue. Usually tapping the screen will trigger the flush because we're sending down touch events to JS.

Reviewed By: JoshuaGross

Differential Revision: D14656466

fbshipit-source-id: cb3a174e97542bf80f0a37b4170b6a8e6780fa35
2019-03-29 01:39:39 -07:00
Joshua Gross 1592acd4a9 Small changes to State objects to support Android
Summary: Small changes to State objects to support Android. See following diffs.

Reviewed By: mdvacca

Differential Revision: D14663470

fbshipit-source-id: 878f4dc39265991a7b8ff54ca80bdb862f1dd3de
2019-03-29 01:17:19 -07:00
Ramanpreet Nara 58cd20459f Force JS null to be translated to ObjC nil
Summary:
In D14571128, we made it so that when a JS object's property was `undefined`, we wouldn't insert that property into the corresponding NSDictionary. Here are two important observations about that diff:
1. ALL JS `null`s were now being converted to `NSNull`, and JS `undefined`s were now being converted to `nil`.
2. If a JS object's property was explicitly `null`, then we'd insert `NSNull` into the corresponding dictionary.

Considering that when a property doesn't exist in a `NSDictionary`, property access returns `nil`, I've made it so that if a JS object's property is either `null` or `undefined`, then we simply do not insert it in the corresponding `NSDictionary`. Also, I've reverted #1 and made it so that `undefined` and `null` always map to the ObjC `nil`.

This shouldn't unfix the problem that D14571128 was trying to fix.

Here's my understanding of the problem that D14571128 was trying to fix (to make sure I'm not breaking something by this diff).

This method was invoked from JS.
```
RCT_EXPORT_METHOD(logEvents:(NSDictionary *)events)
{
  RCTAssert(events, @"You should provide events for logger");
  [[NSNotificationCenter defaultCenter] postNotificationName:@"FBReactPerfLoggerDidReceiveEventsNotification"
                                                      object:nil
                                                    userInfo:@{@"FBReactPerfLoggerUserInfoPerfEventsKey" : [events copy]}];
}
```

The above dispatch calls into this method, which appends `events` into `_pendingJSPerfEvents`.

```
- (void)reactPerfLoggerDidReceiveEvents:(NSNotification *)notification
{
  NSDictionary *events = notification.userInfo[@"FBReactPerfLoggerUserInfoPerfEventsKey"];
  if (events) {
    dispatch_async(_eventQueue, ^{
      if (self->_sessionData.perfLoggerFlagId != nil) {
        if ([self processJSPerfEvents:events]) {
          [self reportMetricsIfFinished];
        }
      } else {
        [self->_pendingJSPerfEvents addObject:events];
      }
    });
  }
}
```

Then, in `_processJSPerfEvents`, we do the following (link: https://fburl.com/tr4wr2a7):
```
NSNumber *actionId = events[@"actionId"];
if (actionId) {
  self->_sessionData.actionId = actionId;
}
```

So, if `undefined` or `null` was passed in as the `actionId` property of the `events` JS object in `FBReactPerformanceLogger logEvents:`, then we'd default the `NSDictionary` to have `NSNull` in the corresponding property. This is bad because we had this line in FBReactWildePerfLogger (link: https://fburl.com/2nsywl2n):  `actionId ? [actionId shortValue] : PerfLoggerActions.SUCCESS`. Essentially, this is the same problem that my diff is trying to fix.

Reviewed By: fkgozali

Differential Revision: D14625287

fbshipit-source-id: c701d4b6172484cee62494256175e8b205b23c73
2019-03-26 14:28:23 -07:00
David Aurelio 82b27832d6 `CompactValue` overrides of `YGResolveValue`/`YGValueEqual`
Summary:
@public

I would like to get rid of implicit conversions between `YGValue` and `CompactValue`, because they don’t come for free.

That’s why I am adding `CompactValue` specific overrides for `YGResolveValue` and  `YGValueEqual`, that do explicit casts. Up the commit stack, we will be able mark both `CompactValue(const YGValue&)` and `CompactValue::operator YGValue()` as `explicit`.

Reviewed By: SidharthGuglani

Differential Revision: D14598447

fbshipit-source-id: 75dc15cefb2dddcf8def891c5fb37893cacd9d46
2019-03-26 05:22:24 -07:00
David Aurelio d1c7760ef7 Remove duplicated function declaration
Summary:
@public

Just removes a duplicated function declaration.

Reviewed By: SidharthGuglani

Differential Revision: D14598446

fbshipit-source-id: b4d8fe192f9a07f512f6a346f27d9046bb3bae23
2019-03-26 05:22:23 -07:00
Valentin Shergin cc66d36583 Fabric: Removing ShadowNode::constructAncestorPath()
Summary: We don't use it anymore.

Reviewed By: mdvacca

Differential Revision: D14523377

fbshipit-source-id: 20777d835960105e875c9e37bbe753bd925dfd78
2019-03-25 20:32:21 -07:00
Valentin Shergin af38a0cf87 Fabric: `Transform` type was moved to `graphics` module.
Summary:
We will use it inside `core` module, so we have to decouple it from `view`.
As part of this, I added some comments, changed `const Float &` to just `Float` and put the implementation into `.cpp` file.

Reviewed By: mdvacca

Differential Revision: D14593952

fbshipit-source-id: 80f7746f4fc5b95febc8df9f5a9c0386a6425c88
2019-03-25 12:04:53 -07:00
Dhaval Kapil 64f3a87c9d Refactor JSIExecutor to use runtimeInstaller for injecting the logger instance
Summary: This is based on the work done in D8686586. Removed the logger instance from JSIExecutor constructor and installed it into the runtimeInstaller at all call sites.

Reviewed By: mhorowitz

Differential Revision: D14444120

fbshipit-source-id: 0476fda4230c467573ea04102a12101bcdf36c53
2019-03-25 09:12:11 -07:00
David Aurelio 4ba34b0a26 Automatic lint fixes
Summary:
@public
A round of automatic lint fixes.

Reviewed By: SidharthGuglani

Differential Revision: D14590396

fbshipit-source-id: f0b4a0ce503a1d9d46ea7ae788f9f2eac09c2ac7
2019-03-25 05:55:21 -07:00
David Vacca ce3952faf5 Replace abort() with LOG(FATAL) when a prop-value is not found during parsing
Summary: This diff replaces usage of abort() with LOG(FATAL) when a prop-value is not found during parsing of prop values

Reviewed By: fkgozali

Differential Revision: D14591210

fbshipit-source-id: 4a8484ea6bdfec5534122ded43cc24ef80c13c1d
2019-03-23 22:53:23 -07:00
David Vacca 06c1f3c502 Fix parsing of flex-wrap='nowrap'
Summary: This diff fixes parsing of  flex-wrap='nowrap' prop in Fabric

Reviewed By: fkgozali

Differential Revision: D14591211

fbshipit-source-id: 2ece2cd03b1b78eaeb01f7fc15bf62c510f70501
2019-03-23 22:53:22 -07:00
Yuan Du 146b2839f5 Revert D14554656: [Fabric][C++] Fix parsing of flex-wrap='nowrap'
Differential Revision:
D14554656

Original commit changeset: 259b2cdaf204

fbshipit-source-id: 3bca12f204ff7be85c4901eb01894935e7857d75
2019-03-23 13:08:20 -07:00
Yuan Du 66e04347d1 Revert D14570713: [Fabric][C++] Replace abort() with LOG(FATAL) when a prop-value is not found during parsing
Differential Revision:
D14570713

Original commit changeset: 57b0f993ba26

fbshipit-source-id: 5f4eb0282b028e36d2cbb04a5ab85f469572aa37
2019-03-23 13:08:20 -07:00
Yuan Du a3296ff40f Revert D14572430: [Fabric][Android] ReactTTRCRenderFlag component in Fabric android
Differential Revision:
D14572430

Original commit changeset: 0e7c6cb5520b

fbshipit-source-id: 2cde5c9316c055c3836aab656a06c508f3e468af
2019-03-23 13:08:20 -07:00
David Vacca 819c584c46 ReactTTRCRenderFlag component in Fabric android
Summary: This diff migrates ReactTTRCRenderFlag component to Fabric android

Reviewed By: shergin

Differential Revision: D14572430

fbshipit-source-id: 0e7c6cb5520be44221939b0e711269b84f4657dc
2019-03-23 12:10:00 -07:00
David Vacca 1ceb4708f7 Replace abort() with LOG(FATAL) when a prop-value is not found during parsing
Summary: This diff replaces usage of abort() with LOG(FATAL) when a prop-value is not found during parsing of prop values

Reviewed By: sahrens

Differential Revision: D14570713

fbshipit-source-id: 57b0f993ba264a4949baf4022d807c55cdfe03b1
2019-03-23 12:09:59 -07:00
David Vacca f01a0d33ab Fix parsing of flex-wrap='nowrap'
Summary: This diff fixes parsing of  flex-wrap='nowrap' prop in Fabric

Reviewed By: fkgozali

Differential Revision: D14554656

fbshipit-source-id: 259b2cdaf2043f72c261ae7d74a80eb012883244
2019-03-23 12:09:59 -07:00
Ramanpreet Nara 8618a5824f Add support for argument conversion via RCTConvert
Summary:
With our current infra, we support automatic conversion of method arguments using `RCTConvert`.

```
RCT_EXPORT_METHOD(foo:(RCTSound*) sound)
{
  //...
}
```

```
interface RCTConvert (RCTSound)
+ (RCTSound *) RCTSound: (NSDictionary *) dict;
end

implementation RCTConvert (RCTSound)
+ (RCTSound *) RCTSound: (NSDictionary *) dict
{
  //...
}
end
```

```
export interface Spec extends TurboModule {
  +foo: (dict: Object) => void,
}
```

With this setup, when we call the foo method on the TurboModule in JS, we'd first convert `dict` from a JS Object to an `NSDictionary`. Then, because the `foo` method has an argument of type`RCTSound*`, and because `RCTConvert` has a method called `RCTSound`, before we invoke the `foo` NativeModule native method, we first convert the `NSDictionary` to `RCTSound` using `[RCTConvert RCTSound:obj]`. Essentially, if an argument type of a TurboModule method is neither a primitive type nor a struct (i.e: is an identifier), and it corresponds to a selector on `RCTConvert`, we call `[RCTConvert argumentType:obj]` to convert `obj` to the type `argumentType` before passing in `obj` as an argument to the NativeModule method call.

**Note:** I originally planned on using `NSMethodSignature` to get the argument types. Unfortunately, while the Objective C Runtime lets us know that the type is an identifier, it doesn't inform us which identifier it is. In other words, at runtime, we can't determine whether identifier represents `RCTSound *` or some other Objective C class. I figure this also the reason why the old code relies on the `RCT_EXPORT_METHOD` macros to implement this very same feature: https://git.io/fjJsC. It uses `NSMethodSignature` to switch on the argument type, and then uses the `RCTMethodInfo` struct to parse the argument type name, from which it constructs the RCTConvert selector.

One caveat of the current solution is that it won't work work unless we decorate our TurboModule methods with `RCT_EXPORT_METHOD`.

Reviewed By: fkgozali

Differential Revision: D14582661

fbshipit-source-id: 3c7dfb2059f031dba7495f12cbdf406b14f0b5b4
2019-03-22 16:23:40 -07:00
Ramanpreet Nara ef512194a6 Implement struct arguments for methods
Summary:
Before invoking TurboModule ObjC methods, we loop through all the arguments and transform them from `jsi::Value` to ObjC data structures. `jsi::Value`s that represent JS Objects get converted to `NSDictionary`s in ObjC. This isn't good enough because `NSDictionary` isn't typed. What we really need is a C/C++ struct that represents the type of the JS Object.

Therefore, for every argument of a TurboModule method that is a JS Object, this diff allows you to specify a method on `RCTCxxConvert` (which you have to declare and implement) that transforms that type of JS Object into something else. Basically, with the changes in this diff, we'll be able to transform JS Objects into C++ struct instances, which gives us type safety for JS Object method argumetns to TurboModule functions.

I modified the codegen to also create a mapping from NativeModule method name => argument num => `RCTCxxModule` conversion selector. This way, the FB codegen that generates the `RCTCxxConversion` function also informs our TurboModule system which conversion function to use before we call the method requiring complex argument. I just had to extend the `ObjCTurboModule` class to accomplish this.

The old system relies on the additional method generated by `RCT_EXPORT_METHOD` macro. It takes the written code, does string processing on it to parse the type of the struct arguments, and then replaces all instances of `::` with `_`. Super hacky. I didn't take this approach because it seemed unnecessarily hacky brittle.

The other approach I considered was to try to use reflection to infer the type of the struct at runtime. We'd have to do a bit of string processing and concat the TurboModule class name with the struct type. The solution would be simpler because it'd only modify the objective C and it wouldn't touch the Codegen system. **Edit:** I implemented it here: D14513078. The one downside of this design is that the name of the conversion function is individually constructed in two different locations in the code (i.e: no source of truth for this name). The other downside is that we have to rely on `RCTBridgeModuleNameForClass`, which we want to eliminate. This also computationally more expensive since it requires string processing/regex parsing and additional reflection. Therefore, we decided to move on with the current solution.

Reviewed By: fkgozali

Differential Revision: D14513429

fbshipit-source-id: 3d1b87e02ee908a19305686ff82b2ed624d8ac67
2019-03-21 17:37:18 -07:00
Kevin Gozali 3e8d2a18d7 iOS: undefined prop in an object shouldn't become [NSNull null] in the dictionary
Summary: [iOS] [Fixed] - The existing logic defaults `undefined` & `null` in JS to be `[NSNull null]` when converting JS object to `NSDictionary`. Let's not insert the prop to the dictionary if it's `undefined`.

Reviewed By: blairvanderhoof

Differential Revision: D14571128

fbshipit-source-id: e03c713b055672b0a001d3305d694912ee36ab36
2019-03-21 17:05:57 -07:00
Peter Ammon dd9959ab0e JSBigString to map via MAP_PRIVATE not MAP_SHARED
Summary:
JSBigString was inadvertently changed to a shared mapping. This means
that any changes to the string will be written back to the file. Ensure
we have a private (COW) mapping.

Reviewed By: kodafb

Differential Revision: D14532757

fbshipit-source-id: 6afb9635493496c90904f1432847c2f0da882c58
2019-03-21 14:27:23 -07:00
Marc Horowitz dcc40a6267 JSI es6 Symbol impl for JSCRuntime
Summary: this is an empirical hack

Reviewed By: fkgozali

Differential Revision: D14216647

fbshipit-source-id: 577ffb555c6e2f5a6456ccea5dff8e6ec757f80f
2019-03-21 13:33:32 -07:00
Marc Horowitz 7ccec333e9 sync with upstream jsi
Reviewed By: willholen

Differential Revision: D14232752

fbshipit-source-id: 2548158f2c2c8aa6e15656ef346d92d3c0937c4a
2019-03-21 13:33:32 -07:00
zhongwuzw 25a58d7bbb Consolidate shared_mutex with better::shared_mutex (#24075)
Summary:
Replace `folly::SharedMutex` with `better::shared_mutex`, consolidate the shared_mutex.
cc. shergin .

[General] [Changed] - Consolidate shared_mutex with better::shared_mutex
Pull Request resolved: https://github.com/facebook/react-native/pull/24075

Differential Revision: D14559213

Pulled By: shergin

fbshipit-source-id: 934c7cd7db9ce60031d6b007faeebb353860268f
2019-03-21 00:18:33 -07:00
Jacob Bower b7c2c82c89 Thread through-return value from evaluateJavaScript()
Summary: Pass return value through to JSI layer.

Reviewed By: mhorowitz

Differential Revision: D14118187

fbshipit-source-id: 7e44c7dc335fd19d7c0aa1edb5be72ebea7eb851
2019-03-20 23:09:54 -07:00
Valentin Shergin 9ede538b75 Fabric: Removing an assert in YogaLayoutableShadowNode
Summary: Conceptually, this assert is correct, however, sometimes a new node got allocated by same address as old parent node (which does not exist already) which makes the assert fires.

Reviewed By: mdvacca

Differential Revision: D14533070

fbshipit-source-id: 3fcc71c25e7d724180dc85aaf2457227d22ddba0
2019-03-20 18:09:16 -07:00
Valentin Shergin e3f9d7e82c Fabric: Disabling custom ("better") containers in DEBUG mode
Summary:
Custom containers are only enabled in release mode.
Using custom stuff complicates debugging process because it breaks embedded into IDE introspections mechanisms.

Reviewed By: mdvacca

Differential Revision: D14508299

fbshipit-source-id: d2dbe87764b17d75ccd544c0a4baf03dd9e0cd0b
2019-03-20 09:24:59 -07:00
Valentin Shergin ae157883eb ShadowNode: Using state value for computing ShadowView hash
Summary: Trivial.

Reviewed By: JoshuaGross

Differential Revision: D14472906

fbshipit-source-id: 014a3115c24d155a93ff24404d4f748880d53b2b
2019-03-19 00:02:30 -07:00
Valentin Shergin f24fd6e9ee Fabric: Using new shiny ShadowNode::getAncestors in LayoutableShadowNode
Summary: Same algorithm using a new API.

Reviewed By: JoshuaGross

Differential Revision: D14423509

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

Reviewed By: JoshuaGross

Differential Revision: D14416949

fbshipit-source-id: 13ef928505a60280e2a6c30c76ac87d91cee326e
2019-03-18 23:56:13 -07:00
Valentin Shergin be51d0564b Fabric: a new efficient implementation of ShadowNode::getAncestors()
Summary:
The algorithm is quite simply:
1. Get family objects of the two nodes (inner and outer).
2. Traverse the list of family objects starting from the inner one and form a reversed list of them.
3. tarting from the inner node, traverse the tree layer-by-layer choosing a next element of the path by comparing the family object of each node on the level and an object from the list.

Reviewed By: JoshuaGross

Differential Revision: D14416950

fbshipit-source-id: 23c659a9e01690f90174193650a2b0ef09eadb4d
2019-03-18 23:56:13 -07:00
Valentin Shergin 978e59aa92 Fabric: ShadowNodeFamily, maintaining a pointer to a parent family
Summary:
One of the core feature of ShadowNodeFamily is having a pointer to a parent family. This diff implements it.
I don't think there is a hard retain cycle there, but for more lean memory usage we use weak_ptr here.

Reviewed By: JoshuaGross

Differential Revision: D14416948

fbshipit-source-id: 05fd2c4833146f007228363b1d958776b4a2a9cf
2019-03-18 23:56:13 -07:00
Valentin Shergin 28e89e5081 Fabric: ShadowNodeFamily, the first steps
Summary:
ShadowNodeFamily is a new concept that allows us to implement an efficient way to solve the problem of finding a path to some ancestor node (practically reimplement ShadowNode::constructAncestorPath() in some efficient way).

This diff is the first one in the series. It introduces a new class and moves some data into it.

Reviewed By: JoshuaGross

Differential Revision: D14416947

fbshipit-source-id: c93865a8929a2128498e34d3589487696aac6283
2019-03-18 23:56:13 -07:00
Valentin Shergin e0bbdbc040 Fabric: Removed declaration of ShadowNode::clearSourceNode()
Summary: This is a leftover from the ealy days of Fabric. The mehtod does not have implementation counterpart and any usage.

Reviewed By: JoshuaGross

Differential Revision: D14402636

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

Reviewed By: JoshuaGross

Differential Revision: D14402637

fbshipit-source-id: 731a950f373e20f7d5bae3cbf6470335d3694ccc
2019-03-18 23:56:13 -07:00
Valentin Shergin 50b40a41c0 Fabric: Tightening up some ShadowNode cloning semantics
Summary: In React, things like changing `tag`, `eventTarget` or reparenting are impossible by design. Which seems like a strange limitation actually allows us to do tremendous performance optimizations (stay tuned!).

Reviewed By: JoshuaGross

Differential Revision: D14402638

fbshipit-source-id: 3b7b7edaff0d55a3ca94e2ac4c753d630d07101d
2019-03-18 23:56:13 -07:00
Valentin Shergin 9a0047f368 Fabric: Explicit dirtying Yoga nodes for Text component (and co.)
Summary:
With recent changes, simple cloning a component does not mean that underlying Yoga node will be dirtied. Autodirtying is only performed if the child nodes were dirtied and/or if the YGStyles were changed.
That's not the case for Text component which does not have direct layotable children, so we have to call `dirtyLayout` explicitly.

Reviewed By: JoshuaGross

Differential Revision: D14508277

fbshipit-source-id: 2c52d7d40da963a976c7d28a13781cc1755ef591
2019-03-18 19:21:26 -07:00
Valentin Shergin ab86085caf Fabric: Correct checking for `sealable` flag with move semantic methods
Summary: In methods which implement move semantic we have to check the source object because it's (also) being mutated.

Reviewed By: JoshuaGross

Differential Revision: D14496937

fbshipit-source-id: f3f2299d14e41c8b269f1647336dbd5b45c235f4
2019-03-18 19:21:26 -07:00
Valentin Shergin 587087c4e7 Fabric: More asserts/invariant-checking in YogaLayoutableShadowNode
Summary: More `assert`s and `ensureUnsealed` calls were added to YogaLayoutableShadowNode for simpler debugging and early failing.

Reviewed By: JoshuaGross

Differential Revision: D14496936

fbshipit-source-id: 898c6a0665aeac5d0b1995bd53046f58cec37007
2019-03-18 19:21:26 -07:00
Valentin Shergin 55eaf30740 Fabric: Checking for `HasNewLayout` before applying layout metrics to ShadowNode
Summary:
If the `HasNewLayout` flag is `false`, we should not copy the data from YGStyle/YGLayout to ShadowNode because the node can be already sealed and because it's unnecessary. Previously we workaround this case with a special check in `setLayoutMetrics` method, but that can be unreliable because of some side-effects related to pixel rounding and comparing floats.
The new approach is much more robust and explicit.

Reviewed By: JoshuaGross

Differential Revision: D14496939

fbshipit-source-id: deddb14d2206c5bd3f22154d0ea682e3c5888901
2019-03-18 19:21:26 -07:00
Valentin Shergin be6fa25d16 Fabric: Removing default implementation of some methods of LayoutableShadowNode
Summary: These default implementations are never being used. Removing them allowing to ensure that flags inside YGNode have same values as flags in YogaLayoutableShadowNode. That also saves a couple of bytes in size of ShadowNode.

Reviewed By: JoshuaGross

Differential Revision: D14496938

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

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

Reviewed By: JoshuaGross

Differential Revision: D14472751

fbshipit-source-id: 75bf62ac28991a39e5664aa71c08bd0e64fa275b
2019-03-18 19:21:25 -07:00
Valentin Shergin 72cd8716fd Fabric: Calling a base class copy constructor in YogaLayoutableShadowNode's copy constructor
Summary: That diff fixes an obvious bug that prevents internal data of LayoutableShadowNode being cloned during cloning of YogaLayoutableShadowNode.

Reviewed By: JoshuaGross

Differential Revision: D14472753

fbshipit-source-id: d07be3bf36708690dfe10de7898e2b48648aa0f4
2019-03-18 19:21:25 -07:00
Valentin Shergin 6bd67de4d3 Fabric: Being even smarter preserving dirty flag on Yoga nodes
Summary: In addition to the previous change, now we handle a situation where some node receives a new set of children and all those children have the same styles. (See the previous diff for more details.)

Reviewed By: JoshuaGross

Differential Revision: D14472754

fbshipit-source-id: 16411036e14f18e730e064e33948440b05ff51c8
2019-03-18 19:21:25 -07:00
Valentin Shergin d6d381180b Fabric: Being smarter preserving dirty flag on Yoga nodes
Summary:
After the change, YogaLayoutableShadowNode will preserve dirty flag (being false) in cases where:
* a node was cloned with same children;
* changes in props don't affect layout.

Motivation:
In Fabric we always were aggressive about dirting yoga nodes: when we clone the node, we always dirty underlying Yoga node. I think that was the case because we don't deeply understand how the system works and we always had more severe problems to fix. Now, we faced an issue that forces us to think about that problem carefully (more about that later).

(I don't expect that will improve TTI performance, but that's possible if we do a lot of changes in the hierarchy during initial load process.)

I see two main use cases where we have to be smart about dirtied yoga nodes:

Case 1. Native local commits which do *not* modify yoga styles.E.g. in a case where ScrollView updates the internal state (which has offset info) really really frequently. (It will be implemented later.) That `contentOffset` info does not or might not affect layout, so we should not pay for this.

Case 2. Legit React commits which do *not* modify yoga styles. E.g. in a case where only the background color of some view changes, we don't need to relayout anything. Unfortunately, we do this in Fabric because of two major reasons:
* We don't make a difference between any changes in Props.
* React constructs new children of cloned node iteratively, calling `appendChild`. That makes implementing optimization really challenging because we don't know when the process ends. And when it ends we have very few pieces of information about how the state looked before.

This diff stack will handle the problems of the first kind. The main motivation is: we want to have state updates to be as lean as possible.

Reviewed By: JoshuaGross

Differential Revision: D14472752

fbshipit-source-id: 68374f60cb07de9ab65bf1f6d94c828985359fa5
2019-03-18 19:21:25 -07:00
Yedidya Feldblum 508daf2c21 Upgrade mobile BUCK and .bzl files to use C++14
Summary:
Upgrade mobile `BUCK` and `.bzl` files to use C++14.

Let's see what happens.

Reviewed By: mzlee

Differential Revision: D14223329

fbshipit-source-id: ff642ca017103d9415c4d7f5beaf5ded07ef7ff1
2019-03-16 02:25:33 -07:00
ericlewis 97e6ea1371 Fabric: working podspecs & works in RNTester (#23803)
Summary:
This is the couple of hacks I used after I finished #23802 in order to get fabric working on RNTester. This is inspired from prior work by kmagiera.

The goal of this PR is to show others what I’m struggling with, and to eventually merge it sans hacks.

- Yarn Install
- Uncomment the commented out pods in RNTester's pod file
- Open RNTesterPods workspace
- Run App

- this is only for pods, the non-pod RNTester will no longer work until updated with fabric too.
- `SurfaceHostingView` & `SurfaceHostingProxyRootView` both try to start the surface immediately, this leads to a race condition due to the javascript not having loaded yet, the hack here is:
   1. Swizzle the `start` method on `RCTFabricSurface` to no-op when called.
   2. Add observer for `RCTJavaScriptDidLoadNotification`
   3. Call private method `_startAllSurfaces` on `_surfacePresenter` in AppDelegate when we receive `RCTJavaScriptDidLoadNotification`.

[General] [Added] - Use Fabric in RNTester
Pull Request resolved: https://github.com/facebook/react-native/pull/23803

Reviewed By: shergin, mdvacca

Differential Revision: D14450726

Pulled By: fkgozali

fbshipit-source-id: 8ae2d48634fecb60db539aaf0a2c89ba1f572c27
2019-03-15 23:59:22 -07:00
Joshua Gross 34499002f2 fbios BottomSheet implementation
Summary: Several things need to ironed out: 1) LocalState in Fabric C++, 2) setting dimensions of BottomSheet component to 0,0 for parent.

Reviewed By: shergin

Differential Revision: D14426167

fbshipit-source-id: 45a90a7971c87672872108a9e360926b4a6095f0
2019-03-15 14:37:39 -07:00
ericlewis 80ccbdcfa0 TurboModules: add podspec (#23927)
Summary:
Add's a podspec to allow linking / building turbomodules.

[iOS] [Added] - podspec for turbomodules
Pull Request resolved: https://github.com/facebook/react-native/pull/23927

Reviewed By: mdvacca, RSNara

Differential Revision: D14474598

Pulled By: fkgozali

fbshipit-source-id: afafce0f0af31469a3ef91616575b3b0f36055bc
2019-03-15 11:44:27 -07:00
Valentin Shergin 948398519d Fabric: Fixing usage of Folly's `hash_combine`
Summary:
Accidentally I noticed that the signature of Folly's hash_combine is different from boost's one.
The Folly's one is:
`size_t hash_combine(const T& t, const Ts&... ts)`, so the first argument is immutable and the method returns the result normally.
It means that all hashes that we compute in Fabric using `hash_combine` were `0`.
So I fixed it.

I have no idea why this difference exists, but some modern papers suggest that folly's variant has good chances to be standardized.
E.g.: http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0814r0.pdf

Technically, it should improve performance, but I doubt that it can be more than 1-2 ms per screen TTI.

Reviewed By: JoshuaGross

Differential Revision: D14430380

fbshipit-source-id: 97da999ee5780b940bb789bc3eb5bf9f89c194ca
2019-03-14 18:35:00 -07:00
ericlewis d17e061c0e Fabric: support line-through for text components (#23911)
Summary:
While the proper typographical terminology is [Strikethrough](https://en.wikipedia.org/wiki/Strikethrough), we should still support `line-through` as it goes through a deprecation phase.

[iOS] [Added] - line-through support for fabric text components
Pull Request resolved: https://github.com/facebook/react-native/pull/23911

Differential Revision: D14460610

Pulled By: shergin

fbshipit-source-id: 0dae41b765f21d166ea3618c463ebe1330607b30
2019-03-14 11:07:32 -07:00
ericlewis 28ceb0ad0b Fabric: support building for 32bit archs (#23915)
Summary:
Adds support for building on 32bit platforms, unlocking release mode for Xcode 💯

[General] [Added] - Fabric: 32bit support
Pull Request resolved: https://github.com/facebook/react-native/pull/23915

Differential Revision: D14460600

Pulled By: shergin

fbshipit-source-id: ebc487546aac05d3272ae095ac321ef58f2271f6
2019-03-14 10:14:36 -07:00
Eric Schlanger 6cc5137a07 Exclude logging functionality outside debug builds
Summary: Don't compile in YGNodePrint in production builds

Reviewed By: davidaurelio

Differential Revision: D14258269

fbshipit-source-id: 15b5e94d241a752fea74a45263aa343265071451
2019-03-13 07:39:16 -07:00
Rick Hanlon ed5ed23deb Move codegen to rn_library
Summary:
Moves rn_codgen to rn_library behind a `codegen` flag to limit the number of rules we generate

WIth this, modules with native components can enable the react-native-codegen schema parsing by just updating their buck rule to:

```
rn_library(
  name = 'lib',
  codegen = True,
  // ...
)
```

Reviewed By: TheSavior

Differential Revision: D14401263

fbshipit-source-id: 1675bc28389db64da10153c988bb4eb00d715056
2019-03-13 07:02:31 -07:00
Joshua Gross 34b7087515 Remove folly::futures targets
Summary: Remove unused BUCK targets.

Reviewed By: fkgozali

Differential Revision: D14416459

fbshipit-source-id: f9ee07c6e30dc825627cda9bdf8128ada5ef5166
2019-03-12 10:56:51 -07:00
Marco Zandonadi 756dc2f3ed Fix #import/include in SliderShadowNode
Summary: This diff is a part of an effort to resolve build errors that appear when compiling with the latest version of clang.

Reviewed By: shergin

Differential Revision: D14369797

fbshipit-source-id: e4c6f53e293f336efad18597f9d2705c025e1051
2019-03-11 12:36:28 -07:00
Valentin Shergin 2862ef3a47 Fabric: Using `small_vector` instead of regular `vector` in some hot code paths
Summary: The hope is that it will remove many unnececery allocations improving overal perfromance.

Reviewed By: mdvacca

Differential Revision: D14249198

fbshipit-source-id: f0442b3919ccead0582a3190dea0e33d517d85f6
2019-03-07 13:41:20 -08:00
Valentin Shergin c3ecae0db4 Fabric: Using small_vector for SharedShadowNodeList
Summary:
SharedShadowNodeList is one of the core collections in Fabric. Every ShadowNode has one, it's used intensivly during diffing and so on.
Usually, nodes have a very few children, so using `small_vector` instead of regular `vector` should save us a lot of memory allocations.

Reviewed By: JoshuaGross

Differential Revision: D14249201

fbshipit-source-id: 53297caa027a74099d0a1ed4a3cce78f8feb651b
2019-03-07 13:41:20 -08:00
Valentin Shergin 136666e2e7 Fabric: Using stored inside ShadowNode pointer to Descriptor instead of table lookup
Summary:
Nowadays, every ShadowNode has a reference to a ComponentDescriptor, so now there is no need to do registry lookup for that.
That should save us 0.5-1.0 ms in my non-scientific measurements.

Reviewed By: mdvacca

Differential Revision: D14348369

fbshipit-source-id: 57f6a6f2f8bf0b7e58d89a414fec20b2db8876f7
2019-03-06 20:06:08 -08:00
Valentin Shergin 393bf8aaad Fabric: Fixed a bug in ShadowViewMutation constructor
Summary:
Clowntown.
This fixes a recent regression happened becasuse wrong order of parameters in ShadowViewMutation constructor.

Reviewed By: JoshuaGross

Differential Revision: D14329164

fbshipit-source-id: 5a0dc04b889fb3357050b951d56c3e436dbeefb1
2019-03-05 14:07:20 -08:00
Rick Hanlon d48bd1759e Use codegen for Slider props + events
Summary: Use the codegen for the Slider component with the new `inferfaceOnly` option

Reviewed By: TheSavior

Differential Revision: D14295981

fbshipit-source-id: 0482572892fbcffada43c7c6fbf17e70546300b8
2019-03-05 11:53:56 -08:00
Rick Hanlon 9098bc7749 Remove activityindicator files
Summary: These were moved to the codgen

Reviewed By: TheSavior

Differential Revision: D14307470

fbshipit-source-id: 49030c245f11bd595bb97e1b2f34a7c454be5c56
2019-03-05 11:53:56 -08:00
empyrical 50d095ce32 Fabric: Remove designated initializer in LayoutMetrics.h (#23758)
Summary:
This pull request removes the designated initializer in `LayoutMetrics.h`. This will help improve the portability of this file.

[General] [Changed] - Fabric: Remove designated initializer in LayoutMetrics.h
Pull Request resolved: https://github.com/facebook/react-native/pull/23758

Differential Revision: D14320526

Pulled By: shergin

fbshipit-source-id: 076ad389d0985d5213b521a2ffaca4ca7ae31599
2019-03-05 05:34:02 -08:00
empyrical ddd5b25768 Fabric: Remove null coalescing operators in ShadowNode (#23438)
Summary:
This pull request removes the use of the GCC extension null coalescing operators (`?:`) and replaces them with ternary operators. This improves the portability of `ShadowNode.cpp` (and enables MSVC to build it)

[General] [Fixed] - Fabric: Removed null coalescing operators in `ShadowNode`
Pull Request resolved: https://github.com/facebook/react-native/pull/23438

Differential Revision: D14304958

Pulled By: shergin

fbshipit-source-id: 7d8e6778a72dabf09b1d99bc091a7578598b79c3
2019-03-04 14:47:28 -08:00
empyrical b30b10326e Fabric: Remove designated initializers in RootShadowNode (#23715)
Summary:
This pull request removes the designated initializers in `RootShadowNode.cpp`. This will help improve the portability of this file.

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

Differential Revision: D14305167

Pulled By: shergin

fbshipit-source-id: e394580f103fdb59cf078828b5d2ee6df6cc534d
2019-03-04 14:41:30 -08:00
empyrical 2ca8c94559 Fabric: Remove designated initializers in '/uimanager/' (#23717)
Summary:
This pull request removes the designated initializers under the `fabric/uimanager/` folder. This will help improve the portability of these files.

[General] [Fixed] - Removed designated initializers under the `fabric/uimanager/` folder
Pull Request resolved: https://github.com/facebook/react-native/pull/23717

Differential Revision: D14305203

Pulled By: shergin

fbshipit-source-id: 370911682e22cbb20c4bfd7382ed4da0ce1a598d
2019-03-04 12:58:59 -08:00
empyrical 2c0125995d Fabric: Remove designated initializers in ShadowNodeTest (#23714)
Summary:
This pull request removes the designated initializers in `ShadowNodeTest.cpp`. This will help improve the portability of this file.

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

Differential Revision: D14305162

Pulled By: shergin

fbshipit-source-id: 81803652ece734a9b223d7a8b462a8b62cde7d1d
2019-03-04 11:28:02 -08:00
empyrical 74870d71a6 Fabric: Remove designated initializers in ComponentDescriptorTest (#23713)
Summary:
This pull request removes the designated initializers in `ComponentDescriptorTest.cpp`. This will help improve the portability of this file.

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

Differential Revision: D14305123

Pulled By: shergin

fbshipit-source-id: 64cfc76dd7eaf74b4b4395bac18a9fc370a3b322
2019-03-04 11:13:37 -08:00
Valentin Shergin 56501dcc47 Fabric: Changing the shape of ShadowViewNodePair class
Summary:
I am not sure why it compiled before, it clearly should not, IMO. The `const` types (and references!) are not allowed inside `std::vector` because they are not assignable.
Some experiments that I did caused compilation errors here, so I am changing that to be actually correct.

Reviewed By: JoshuaGross

Differential Revision: D14249199

fbshipit-source-id: 07a22ef13f5de9dfc7ab307493419e6006994bc2
2019-03-04 10:00:01 -08:00
empyrical 9e3a1f0e70 Fabric: Remove designated initializers in View (#23440)
Summary:
This pull request removes the designated initializers in `react/components/view/**` to improve portability.

[General] [Changed] - Fabric: Remove designated initializers in View
Pull Request resolved: https://github.com/facebook/react-native/pull/23440

Differential Revision: D14298887

Pulled By: shergin

fbshipit-source-id: 074a038cdacd448911b39441d84e341a56b666cf
2019-03-03 22:43:11 -08:00
empyrical 4936a663ae Fabric: Remove designated initializers in Image (#23439)
Summary:
This pull request removes the designated initializers in `react/components/image/**` to improve portability.

[General] [Changed] - Fabric: Remove designated initializers in Image
Pull Request resolved: https://github.com/facebook/react-native/pull/23439

Differential Revision: D14298888

Pulled By: shergin

fbshipit-source-id: 9b6ad5fdcec4d3b19b8d69afac80ce18d37f31e6
2019-03-03 22:38:11 -08:00
empyrical cf2a289372 Fabric: Remove designated initializers in Events and Mounting (#23441)
Summary:
This pull request removes the designated initializers in `react/mounting/**` and `react/events/**` to improve portability.

A destructor was also defined for `ShadowView` to fix this error:

```
ShadowViewMutation.cpp:14: error: undefined reference to 'facebook::react::ShadowView::~ShadowView()'
ShadowViewMutation.cpp:24: error: undefined reference to 'facebook::react::ShadowView::~ShadowView()'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```

[General] [Changed] - Fabric: Remove designated initializers in Events and Mounting
Pull Request resolved: https://github.com/facebook/react-native/pull/23441

Differential Revision: D14298890

Pulled By: shergin

fbshipit-source-id: f5d8fc6e1f5968b94e8bb3ca0c3f0e81cf892f83
2019-03-03 22:32:37 -08:00
David Vacca 747d1f7029 Cleanup SchedulerDelegate interface
Summary: This diff removes the "isLayoutable" parameter from SchedulerDelegate.schedulerDidRequestPreliminaryViewAllocation. This now can be infered from the shadowView parameter

Reviewed By: shergin

Differential Revision: D14296481

fbshipit-source-id: b200504f9c2bef41f0a70257f1f5a274fbe97cbb
2019-03-03 15:51:32 -08:00
Valentin Shergin e93522b14b Fabric: Using better::map in Prop parsing infra
Summary: It can save us a couple of ms, hopefully.

Reviewed By: mdvacca

Differential Revision: D14249196

fbshipit-source-id: b5911bcd8b49be66de7b9d2da660df38ef7cc8cd
2019-03-03 13:50:35 -08:00
Valentin Shergin 2409fbaeba Fabric: Using better::map in ComponentDescriptorRegistry
Summary: Trivial.

Reviewed By: mdvacca

Differential Revision: D14249487

fbshipit-source-id: 6dca86d9fcf5c70e08289fc92e5c5a3fa3558238
2019-03-03 13:50:35 -08:00
Valentin Shergin 90e49d759c Fabric: Using a ref to ComponentDescriptor instead of clone function inside ShadowNode
Summary: That should reduce the size of `ShadowNode`, make an instantiation of shadowNode a bit faster, and make `clone` operation a bit faster because simple dynamic dispatch is faster than std::function invocation. It also should help a bit with code size.

Reviewed By: mdvacca

Differential Revision: D14249200

fbshipit-source-id: c1332b139d27becebf15cd894475507b5fd0eb9f
2019-03-03 13:50:35 -08:00
Valentin Shergin aed352246e Fabric: Using RootComponentDescriptor to manage RootShadowNode in ShadowTree
Summary: We need this change to migrate away `cloneFunction` (to a pointer to ComponentDescriptor) inside ShadowNode.

Reviewed By: mdvacca

Differential Revision: D14249197

fbshipit-source-id: 773edcf40e17989886e2c5d3955823a0dbf3857a
2019-03-03 13:50:35 -08:00
Valentin Shergin 0ed988f182 Fabric: `string` and `vector` were removed from better
Summary: Well, that was not so good idea to add that in the first place. Turns out that nowadays standard `string` and `vector` are good enought (but we still need small and inlined collections thought).

Reviewed By: JoshuaGross

Differential Revision: D14249202

fbshipit-source-id: a1b32b800c3f52b29a57f015e1221a0a0eb305c8
2019-03-03 13:50:35 -08:00
Valentin Shergin 24c0702818 Fabric: Text measuring: Handling the case where the string is empty
Summary: Surprisingly, we have some significant amount of text measuring requests where the string is empty. So, there is no need to go to platform specific layer to find that the size of those strings is zero.

Reviewed By: mdvacca

Differential Revision: D14297315

fbshipit-source-id: bf84cf27d5c0893262e8b27da8ff42fc77bcd6c5
2019-03-03 12:07:12 -08:00
Valentin Shergin c61398d8f9 Fabric: Using SimpleThreadSafeCache in ParagraphMeasurementCache
Summary: `ParagraphMeasurementCache` was replaced with templated version of itself.

Reviewed By: mdvacca

Differential Revision: D14296515

fbshipit-source-id: 29e370f07baf14b25430f85a06f603907aed5563
2019-03-03 12:07:12 -08:00
Valentin Shergin 17cb6a8aeb Fabric: Caching for `NSAttributedString`s in RCTTextLayoutManager
Summary:
Creation NSAttributedString from attributedString is not so cheap process, so with this simple cache we hopefully can save a couple milliseconds.
The same string is used at least two times: first time for measuring and second for drawing.

Reviewed By: mdvacca

Differential Revision: D14296514

fbshipit-source-id: 6313aa2c6e9f63d873868131750f61c02d64d2de
2019-03-03 12:07:12 -08:00
Valentin Shergin 15ee4545f4 Fabric: Introducing SimpleThreadSafeCache
Summary: SimpleThreadSafeCache is a simple thread-safe LRU cache; it's a generalized version of ParagraphMeasurementCache.

Reviewed By: mdvacca

Differential Revision: D14296516

fbshipit-source-id: 2b40ac1979ada12551848ece3642b2d99e369672
2019-03-03 12:07:12 -08:00
David Vacca 70447775f7 Update Props during pre-allocation avoiding re-updating the same props during mounting
Summary:
Update Props during pre-allocation avoiding re-updating the same props during mounting

MobileLab test showed an improvement of:
MARKETPLACE_YOU_TTI_SUCCESS: -3.34% = 58ms

Reviewed By: shergin

Differential Revision: D14252170

fbshipit-source-id: 1f4e9ad5dcecbc06651fa065135ffeed4892d984
2019-03-03 09:00:48 -08:00
David Vacca 95c414cfbf Introduce "updateProps" field InsertMutation
Summary: This diff introduces the concept of "updateProps" as part of InsertMutation and it changes the diffing algorithm to populate this field.

Reviewed By: shergin

Differential Revision: D14289608

fbshipit-source-id: 642f00d03d294a12ea7fa7482c72e701b756f3d4
2019-03-03 09:00:47 -08:00
David Vacca aa69e51096 Preallocate Image views
Summary:
This diff changes the pre-allocation of Images update the props on the ImageViews during the creation of ShadowNodes instead of during rendering.
The purpose of this change is to optimize TTI.

This was originally landed in D14214844 and then backed out in D14247897

Reviewed By: shergin

Differential Revision: D14286232

fbshipit-source-id: 8437f57f9473eb22ef98d80531b4020ee5fbb9ae
2019-03-03 09:00:47 -08:00
David Aurelio 9a2026beb9 for experimentation: configurable measure cache size
Summary:
@public

Allows to limit the number of measure cache entries used. This is purely for experimentation.

The measure cache uses about half of every `YGNode`. Reducing its size would allow us to reduce resident memory used by Yoga.

Reviewed By: SidharthGuglani

Differential Revision: D14279027

fbshipit-source-id: e0d22138230bee7fb129c193eb6e4085de02a36e
2019-03-02 12:43:01 -08:00
Valentin Shergin 6bc7ef0b19 Fabric: Props now have a revision number
Summary:
Props now have a special value that represents generation number of `Props` object, which
increases when the object was constructed with some source `Props` object.

Reviewed By: mdvacca

Differential Revision: D14293939

fbshipit-source-id: 4782bf33ccf37623d4079c09cc4d0268bb6c2690
2019-03-01 22:11:32 -08:00
Valentin Shergin ada9dbf919 Fabric: Removed `ImageNoLongerNeededException`, an old leftover
Summary: Trivial.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D14286275

fbshipit-source-id: c29961eb11877da8ae8f14cb2a71cb5eee386fe0
2019-03-01 22:11:32 -08:00
Ramanpreet Nara 8ad695b10e Broadcast TurboModule creation
Summary:
When TurboModules are created, we need to broadcast this event using `NSNotificationCenter`. This is important because a number of TurboModules/ObjC classes listen to this notification and perform side effects.

I found these using https://fburl.com/codesearch/j0a9p3dr.
- FBReactKitServerSnapshotTests: After the RCTExceptionsManager is initialized, it assigns itself as the delegate to the RCTExceptionsManager instance.
- FBProfilePictureUploadFlowController: After FBProfileFrameNativeModule is initialized, it calls `[module setFlowController: self]`
- RCTFBSession: After every NativeModule is initialized, if that NativeModule conforms to the RCTFBSessionModule protocol, assign the session to it.
- TwilightLocalMedia: Hack to figure out when the bridge is initialized.
- FBMarketplaceMenuItemHandler: After FBMarketplaceNativeModule is initialized, attach a data source obtained from the session to the module. Then, attach module to data source.
- RCTModuleInitTests: Set local state based on if certain modules are initialized (https://fburl.com/e34kezb5).
- IGReactModule: When the RCTImageLoader is initialized, set it's image cache to `[IGReactImageCache new]`.
- RCTIGUserSession: Like RCTFBSession
- FBReactModuleTracker: This keeps a list of all dispatched notifications (for some reason).
- RCTModuleInitNotificationRaceTests: Sets self.didDetectViewManagerInit to true if RCTTestViewManager is initialized.

Reviewed By: fkgozali

Differential Revision: D14281557

fbshipit-source-id: 9fcf1bb5f5650fcc3a3e50c6d93405b0b618e271
2019-03-01 12:29:34 -08:00
Kevin Gozali 29613a0364 TM iOS: convert method invocation result in JS thread instead of in the method queue
Summary: [IOS] [FIXED] - This may cause weird race condition if JSI is accessed via multiple threads within the same method invocation. Since only the objc class methods need to be executed on the right queue, we can keep the conversion to jsi::Value in the originating JS thread.

Reviewed By: RSNara

Differential Revision: D14277167

fbshipit-source-id: c506aebb71e190e2afcbf19dce05088ce2b97833
2019-03-01 11:05:00 -08:00
David Aurelio 3080265bb0 `YGNode` remove assignment operators
Summary:
@public

Having assignment operators for `YGNode` means that existing children on the node assigned to would have to be handled somehow.

Deallocating might be incorrect. Ignoring might leak.

Here, we `delete` copy assignment, and make move assignment private (it is used in `YGNode::reset()`).

Copy and move constructors *can* be implemented. The move constructor has to take ownership of the children, while the copy constructor leaves ownership untouched. Since children are copied lazily during layout, this does not expose true value semantics. We should consider removing the copy constructor, too.

Reviewed By: SidharthGuglani

Differential Revision: D14241663

fbshipit-source-id: 39ffdb07f1028bfcf2710c0674a06cdebf3bd650
2019-03-01 04:21:51 -08:00
ericlewis 58c3a4c078 Fix crash when calling substring() on a string containing emoji. (#23609)
Summary:
Fixes #23459. It is not legal to write the character array of a std::string, and can result in undefined behavior.

[General] [Fixed] - Crash when substring intersects with emoji
Pull Request resolved: https://github.com/facebook/react-native/pull/23609

Differential Revision: D14198159

Pulled By: mdvacca

fbshipit-source-id: 71060b1b99ddab89793c98c09f99ec9974479e62
2019-03-01 00:57:00 -08:00
David Aurelio ce457faafc Move reset logic to `YGNode::reset()`
Summary:
@public

Moving logic from free C functions to the C++ layer.

This will allow us to get rid of the dangerous copy / move assignment operators of `YGNode`.

Reviewed By: SidharthGuglani

Differential Revision: D14241564

fbshipit-source-id: aae9f2a7ffd23bb839f1747e4a0694578bae86ae
2019-02-28 06:30:18 -08:00
Yedidya Feldblum fc91bccd53 Add assorted missing includes in xplat
Summary: Add assorted missing includes in `xplat` that would be exposed by future changes.

Reviewed By: ispeters, nlutsenko

Differential Revision: D14213660

fbshipit-source-id: 329f133784015fe20ee99feaec8ef05e117fe3a6
2019-02-28 00:52:48 -08:00
David Vacca b3790d283f Back out "[Fabric][C++][Android] update props during pre allocation of views"
Summary:
This is a back-out of D14214844, we noticed that this regressed TTI for Marketplace You screen running in Fabric

Original commit changeset: b81005f2bf49

Reviewed By: JoshuaGross

Differential Revision: D14247897

fbshipit-source-id: de0cea92b437b2fbcd075f0d6a0066156800e3f0
2019-02-28 00:04:09 -08:00
Spencer Ahrens 189f99eccc Cleanup UITemplates / Fly logging
Summary: Kinda spammy

Reviewed By: shergin

Differential Revision: D14211415

fbshipit-source-id: a8d010f6133d8ec5e109e9d2164ade2c1d996537
2019-02-27 13:33:07 -08:00
Joshua Gross edceba9a9c Slider component - cache measurements, don't create measure manager on iOS
Summary: Small perf wins for both iOS and Android.

Reviewed By: PeteTheHeat

Differential Revision: D14237532

fbshipit-source-id: 2be114d36adfa6e8540cb8cbca5412782791d8ce
2019-02-27 12:48:26 -08:00
Valentin Shergin 802534e611 Fabric: Introducting State, an escape path from unidirectional data flow
Summary:
In React Native there are several use cases where React State is not the only input that affects the component tree. E.g., in case of a <Modal> component, the screen size directly affects the layout of components inside modal; in the case of uncontrolled <TextInput> component, the text inside the input affects the layout of the surrounding components. `State` is a special (legit!) workaround for all those similar cases. Native part of React Native maintains a special shared object between all nodes of the same family and use that during cloning and commits.

See coming commits to know how to use that.

In the near future State will fully replace LocalData concept but for simplicity they both exist for now.

Reviewed By: mdvacca

Differential Revision: D14217184

fbshipit-source-id: 6e018c5b68208d662462013bce0f4e2733d2f673
2019-02-27 00:32:25 -08:00
Valentin Shergin b9107084f7 Fabric: Small refactoring in EventQueue
Summary:
A couple of small changes:
  1. `onEnqueue` was decoupled from `enqueueEvent` for easier and unified overiding in subclasses (other methods will call `onEnqueue` soon);
  2. `flushEvents` was decoupled from `onBeat` (we will put more stuff into `onBeat` soon).

Reviewed By: mdvacca

Differential Revision: D14205769

fbshipit-source-id: 574c2b2caaa6432bc7782b2f3bc147fa1fb82bd3
2019-02-27 00:32:25 -08:00
Valentin Shergin 104ef96498 Fabric: LayoutConstraints::clamp()
Summary: `LayoutConstraints::clamp` clamps the provided `Size` between the `minimumSize` and `maximumSize` bounds of this `LayoutConstraints`.

Reviewed By: mdvacca

Differential Revision: D14205770

fbshipit-source-id: 4799608cead393451d334e47dd6906255699a1e8
2019-02-27 00:32:25 -08:00
Joshua Gross 3c1114eea7 Enable Slider component
Summary:
Enable Slider component in Fabric on Android.

{F151706188}

Reviewed By: mdvacca

Differential Revision: D14220147

fbshipit-source-id: 10b29112e950c8de98cba995839780c4f4e8d3b6
2019-02-26 14:40:58 -08:00
Valentin Shergin 9a64755a18 Fabric: `events` module was merged into `core` module
Summary: That's bummer that we have to do it, but it's actually reasonable. Files in `core` and `events` depend on each other creating circular dependencies and other similar hard problem.

Reviewed By: mdvacca

Differential Revision: D14195022

fbshipit-source-id: 96a44ae28631cc9ccd7d7de72a94526f9e0dd12a
2019-02-25 19:12:08 -08:00
David Vacca 19765c9b8c update props during pre allocation of views
Summary:
This diff changes the pre-allocation of Images update the props on the ImageViews during the creation of ShadowNodes instead of during rendering.

The purpose of this change is to optimize TTI.

Reviewed By: shergin

Differential Revision: D14214844

fbshipit-source-id: b81005f2bf494f62f421dc24846e1561e13b9a87
2019-02-25 17:21:24 -08:00
Spencer Ahrens ea54ceca13 basic useNativeDriver functionality
Summary:
Not super clean, but not terrible.

Unfortunately this still relies on the old Paper UIManager calling delegate methods to flush the operations queues. This will work for Marketplace You since Paper will be active, but we need to fix this, along with Animated Events which don't work at all yet.

Random aside: it seems like taps are less responsive in fabric vs. paper, at least on iOS. There is a sporadic delay between the touches event coming in nativly to the JS callback invoking the native module function to start the animation - this will need some debugging.

Reviewed By: shergin

Differential Revision: D14143331

fbshipit-source-id: 63a17eaafa1217d77a532a2716d9f886a96fae59
2019-02-25 12:25:34 -08:00
Valentin Shergin 53e15c9e95 Fabric: `event/primitive.h` was splitted into several files
Summary: It's handy to have all in one file but it also make it hard/impossible to fight with circular dependencies, so I had to slit it.

Reviewed By: mdvacca

Differential Revision: D14188546

fbshipit-source-id: 20809f1ea227c6f8f32922ed5760226248b718e3
2019-02-25 12:21:01 -08:00
Valentin Shergin af1808de69 Fabric: RootShadowNode::clone() fix
Summary:
The previous implementation of the method cloned the root node twice (one time at the very end of the method and one time at the end of loop body).
The new one does it once and a bit more readable.

Reviewed By: mdvacca

Differential Revision: D14187969

fbshipit-source-id: 9859deadd4b041ac115c37108188aab70200c75d
2019-02-25 12:21:01 -08:00
Valentin Shergin 30141e230d Fabric: Clone function for RootShadowNode
Summary:
RootShadowNode does not have ComponentDescriptor counterpart (because it cannot be created via UIManager) and we used to always clone it manually.
However, apparently, some algorithms (e.g. clone algorithm inside RootShadowNode, which is used by setNativeProps) require valid clone function associated with the node.
So, we implement it.

Reviewed By: JoshuaGross

Differential Revision: D14187762

fbshipit-source-id: a9b6b332a18583217ff0e4f9c15aea0ffb113ba2
2019-02-25 12:21:01 -08:00
Valentin Shergin e00f62022e Fabric: More flexible definition of ConcreteViewShadowNode
Summary:
The ConcreteViewShadowNode was changed to be independend of actual amount of template arguments of ConcreteShadowNode.
We will use it soon.

Reviewed By: JoshuaGross

Differential Revision: D14187761

fbshipit-source-id: b4c8051e2ae3803932713b0c255492466e80d3bd
2019-02-25 12:21:01 -08:00
Spencer Ahrens 37d04a5f5f fix rotation transforms
Summary:
* "rotate" is often used as shorthand for "rotateZ"
** Paper handles this here: diffusion/FBS/browse/master/xplat/js/react-native-github/React/Views/RCTConvert%2BTransform.m$89
* Sometimes react sends a string with units, e.g. "45deg", so we need to convert that to a Float.
** Paper handles this here: diffusion/FBS/browse/master/xplat/js/react-native-github/React/Views/RCTConvert%2BTransform.m$14-27

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D14154173

fbshipit-source-id: 53d7405f26c78bb470d46879309c9697d9985c1c
2019-02-22 13:35:41 -08:00
zhongwuzw 81860c59c3 Remove compiler warning (#23588)
Summary:
Fixed compiler warning, after this, seems we have no warning for framework in debug mode.
<img width="1280" alt="image" src="https://user-images.githubusercontent.com/5061845/53224564-2d14e980-36b0-11e9-85f4-46304513b18d.png">

[iOS] [Fixed] - Remove compiler warning
Pull Request resolved: https://github.com/facebook/react-native/pull/23588

Differential Revision: D14181748

Pulled By: cpojer

fbshipit-source-id: 8b633e7cdb7b3b8029f4145a1155e540ac516191
2019-02-22 01:40:09 -08:00
Ville Immonen 2321b3fd7f Split React.podspec into separate podspecs for each Xcode project (#23559)
Summary:
This PR implements the first part of [RFC0004: CocoaPods Support Improvements](353d44f649/proposals/0004-cocoapods-support-improvements.md), splitting the `React.podspec` into separate podspecs to more closely match the structure of Xcode projects.

The new structure aims to have one to one mapping between Xcode projects and podspecs. The only places where we differ from this mapping are:
* `React/React-DevSupport.podspec`: `DevSupport` is a part of `React.xcodeproj`, which corresponds to the `React-Core` pod. However, we can't include it in the `React-Core` pod because `DevSupport` depends on `React-RCTWebSocket`, which depends on `React-Core`. Pods may not have circular dependencies.
* The new pods under `ReactCommon/` don't have a corresponding `xcodeproj` because there are no `xcodproj` files in `ReactCommon/`. Those C++ modules are included in `React.xcodeproj`.

*Next steps (not in scope of this PR):*
- Start submitting the Podspecs to CocoaPods on a deploy (or turn the React Native repo into a spec repo): this is important in order to make the experience nicer for library consumers, so that it's not necessary to specify the local path of each Podspec in `Podfile`, you can just add `pod 'React', <version>`.
- Add `Podfile` to the default project template (I have a PR ready for this, but because of bugs related to subspecs, it's blocked on this PR)

[iOS] [Changed] - Split React.podspec into separate podspecs for each Xcode project
Pull Request resolved: https://github.com/facebook/react-native/pull/23559

Differential Revision: D14179326

Pulled By: cpojer

fbshipit-source-id: 397a9c30b6b5d24f86c790057c71f0d403f56c3d
2019-02-21 18:35:44 -08:00
Joshua Gross 286abc5d08 Enable profile builds by adding ObjC annotations
Summary: Currently xcode fails profile builds since these variables are unused when asserts are disabled.

Reviewed By: PeteTheHeat

Differential Revision: D14160565

fbshipit-source-id: 997352dd148d23c28fa92d4171071c1abbb742f5
2019-02-21 12:40:38 -08:00
Valentin Shergin 7b62dca921 Fabric: Removed unnecessary const_cast leftovers
Summary: Trivial. If it compiles, it works.

Reviewed By: JoshuaGross

Differential Revision: D14146579

fbshipit-source-id: 6f6895d1634709a5bde012850c5df756171320ab
2019-02-21 10:46:52 -08:00
David Aurelio 25566ef28b `setBaseLine` -> `setBaseline`
Summary:
@public

`setBaseLine` was the only place where we used a capitalised *L.* Fixed here.

Reviewed By: SidharthGuglani

Differential Revision: D14152320

fbshipit-source-id: abf54fe7d6088e03775968baa8421c4bf43d6a6e
2019-02-21 05:38:51 -08:00
David Aurelio dc7dce130b Allow to use JNI without global refs
Summary:
@public

Adds the ability to opt into avoiding global weak JNI refs via `YogaConfig`.

Note that only homogeneous trees are supported, i.e. **mixing weak-ref and non-weak-ref nodes will break!**

Not using JNI refs hopefully will help with avoiding JNI reference table overflows, and will help creating trees on multiple threads, as no lock has to be acquired at any time.

Reviewed By: SidharthGuglani

Differential Revision: D14151037

fbshipit-source-id: 56d94713d39aee080d54be4cb4cdf5e3eccb473a
2019-02-21 05:38:51 -08:00
zhongwuzw 96de12ab48 Remove __fbRequireBatchedBridge call when not get batchedBridge (#23547)
Summary:
From the git log, we added `__fbRequireBatchedBridge` in this commit  6dc3a83e88, I don't ensure wether I missed something, we actually don't define `__fbRequireBatchedBridge` on `JS` or `Native` side, so `__fbRequireBatchedBridge` getter operation itself would throw exception.

[General] [Fixed] - Remove __fbRequireBatchedBridge call when not get batchedBridge
Pull Request resolved: https://github.com/facebook/react-native/pull/23547

Differential Revision: D14160706

Pulled By: cpojer

fbshipit-source-id: df9180a9a16716a91369249333752316fb6648c5
2019-02-20 18:41:24 -08:00
Kevin Gozali 45288a0f63 TM iOS C++: don't throw if a method is not found
Summary: Let JS decide if a missing method should be treated as an error, or whether it allows optional methods (e.g. methods that are only for android or for ios).

Reviewed By: JoshuaGross

Differential Revision: D14155799

fbshipit-source-id: 1e298b46a59761cf09e98147da885b1e9a9a675a
2019-02-20 14:55:08 -08:00
David Aurelio 17a27facc5 Add support for context-aware cloning functions
Summary:
@public

Context-aware cloning functions are an internal Yoga feature that will be used for Yoga’s JNI code.

It will be possible to specify a context when calculating layout, which will be passed on to cloning functions. This will be a private feature.

Reviewed By: SidharthGuglani

Differential Revision: D14149470

fbshipit-source-id: 1d11106e65f9d872d10f191763da001f8d158a61
2019-02-20 11:59:21 -08:00
David Aurelio 57fce665fb Clone children only during layout, allow mixing shared + owned children
Summary:
@public

Limit child cloning to layout calculation. This also allows for mixing shared and owned children.

Rationale:
We do allow for shared children if the caller manages themselves. The single known use case is React Native.

So far, we have cloned children eagerly whenever child lists are mutated, or layout is run. This was to allow for a quick check of the owner of any first child, assuming that either *all* or *no* child of a node are shared.

For Yoga/Java, we want to get rid of global weak JNI refs, and these are also used to invoke clone callbacks. We can achieve that goal by switching to an alternative approach, passing additional data to the layout pass. This additional data has to be passed to any configured cloning callback. Therefore, it is desirable to **only call cloning functions during the layout pass.**

The obvious solution seems to be to not uphold the invariant of the first child determining shared/owned state of all siblings, and allow for a mix of shared and own children.

Reviewed By: shergin

Differential Revision: D14136223

fbshipit-source-id: 34490cfeeb2170c99d6ed1b9bdcbcedb316813af
2019-02-20 11:59:21 -08:00
David Aurelio 9b6bbe69d6 Move node cloning to `YGConfig`
Summary:
@public

Encapsulates node cloning within `YGConfig`.
This is necessary for allowing for context-aware cloning functions, which will ultimately allow for removal of weak global JNI references.

Reviewed By: shergin

Differential Revision: D14132608

fbshipit-source-id: 0dec114c8e172b1e34a4b7fd146c43f13c151ade
2019-02-20 11:59:21 -08:00
empyrical ff588b5087 JSI: Minor tweaks for building on MSVC (#23492)
Summary:
This is a re-submit of #23367, which was accidentally over-written in this commit:

0d7faf6f73

This pull request makes this change to `jsi.h`:

 * Tweak the call to constructor `Pointer(Runtime::PointerValue* ptr)` in the constructor for `PropNameID`. I am not sure why MSVC wasn't working with the original version, but it compiles after I tweak that.

[General] [Fixed] - Tweaked `jsi.h` to build on MSVC
Pull Request resolved: https://github.com/facebook/react-native/pull/23492

Differential Revision: D14151511

Pulled By: hramos

fbshipit-source-id: 52d726d7b978d321a0343566ee527f2ec25e93f8
2019-02-20 10:12:12 -08:00
Eric Lewis c3df673f12 Fabric: Fix dangling brace (#23540)
Summary:
This pull request fixes a dangling brace, causing Xcode to be unable to build RCTFabricSample.

[General] [Fixed] - Fabric: Xcode build issue
Pull Request resolved: https://github.com/facebook/react-native/pull/23540

Differential Revision: D14142990

Pulled By: hramos

fbshipit-source-id: d6c2313d831e2ea5d22c77543814b86bfe8a1d53
2019-02-19 21:55:18 -08:00
Héctor Ramos 2c25e34060 Use new yearless copyright header format
Summary: Use the new copyright header format used elsewhere in the React Native repository.

Reviewed By: shergin

Differential Revision: D14091706

fbshipit-source-id: b27b8e6bcdf2f3d9402886dbc6b68c305150b7d5
2019-02-19 10:35:12 -08:00
David Aurelio b5f497a005 Add support for context-aware print functions
Summary:
@public

Context-aware print functions are an internal Yoga feature that will be used for Yoga’s JNI code.

It will be possible to specify a context when calculating layout, which will be passed on to baseline and measure functions. This will be a private feature.

Reviewed By: SidharthGuglani

Differential Revision: D14131098

fbshipit-source-id: 7a9da307274ceccba9f7debba581b70c1ebf2c98
2019-02-19 09:58:27 -08:00
David Aurelio 2661e102f6 Make node printing private
Summary:
@public

Removes `YGNodeGetPrintFunc`, and encapsulates node printing within `YGNode`.
This is necessary for allowing for context-aware callback functions, which will ultimately allow for removal of weak global JNI references.

On a side node, the printing logic does not seem to be well thought through: print functions print as a side effect to whatever output they choose. Printing that uses callbacks is printing to different output streams or strings, though.

We need to consolidate Yoga debugging, and make it all more stringent.

Reviewed By: SidharthGuglani

Differential Revision: D14131024

fbshipit-source-id: 68704682dab3e7dfba61930bb03003d7d4723b80
2019-02-19 09:58:27 -08:00
David Aurelio 6e2b7c80af Allow to calculate layout with context
Summary:
publc

Adds the ability to calculate layout with a context pointer set.

The context is passed through to measure and baseline functions of individual nodes.

This will be used to remove the necessity of holding weak global JNI references for each node.

Reviewed By: SidharthGuglani

Differential Revision: D14101426

fbshipit-source-id: 25047e1e44af48feb22ea686285d70803e8961bb
2019-02-19 09:58:26 -08:00
David Aurelio 1d836e333f Add support for context-aware measure and baseline functions
Summary:
@public

Context-aware measure and baseline functions are an internal Yoga feature that will be used for Yoga’s JNI code.

It will be possible to specify a context when calculating layout, which will be passed on to baseline and measure functions. This will be a private feature.

Reviewed By: SidharthGuglani

Differential Revision: D14100509

fbshipit-source-id: acf4a030549b2e38d5ce0cd5dbe837864e5ffd81
2019-02-19 09:58:26 -08:00
David Aurelio 42d5517c7a Call measure and baseline fns within `YGNode`
Summary:
@public

Stricter encapsulation of baseline and measure callbacks withing `YGNode`.

Instead of invoking these callbacks directly (`node->getBaseline()(...)`), they are invoked via methods on `YGNode` (`node->baseline(...)`).

This change will allow us to add the concept of a *Layout Context,* where measure and baseline functions will be able to receive an additional `void *` argument if configured accordingly. This API will be used internally for Yoga’s JNI bindings, to avoid storing a weak JNI reference for each node, and avoid reference table overflows.

Changed API:

- `YGNodeGetMeasureFunc()` -> `YGNodeHasMeasureFunc()`
- `YGNodeGetBaselineFunc()` -> `YGNodeHasBaselineFunc()`
- `YGNode::getMeasure()` -> `YGNode::hasMeasureFunc()` + `YGNode::measure()`
- `YGNpde::getBaseline()` -> `YGNode::hasBaselineFunc()` + `YGNode::baseline()`

Reviewed By: SidharthGuglani

Differential Revision: D14099550

fbshipit-source-id: 2653ab36acc252a9747986bc88d21dac22d8c91b
2019-02-19 09:58:26 -08:00
David Aurelio dc55e2980e Add support for context-aware logging functions
Summary:
@public

Context-aware logging functions are an internal Yoga feature that will be used for Yoga’s JNI code.

It will be possible to specify a context when calculating layout, which will be passed on to baseline and measure functions. This will be a private feature.

Reviewed By: SidharthGuglani

Differential Revision: D14123482

fbshipit-source-id: 8ba3b6c493bf79fe09831f22d2b6da44f09e3d95
2019-02-19 09:58:26 -08:00
David Aurelio 77104b05be Call logger from within `YGConfig`
Summary:
@public

Stricter encapsulation of logging callbacks within `YGConfig`.

Instead of invoking the logging callback directly (`node->logger(...)`), callers now have to go through `YGConfig::log()`.

This change will allow us to add the concept of a *Layout Context,* where logging functions will be able to receive an additional `void *` argument if configured accordingly. This API will be used internally for Yoga’s JNI bindings, to avoid storing a weak JNI reference for each node, and avoid reference table overflows.

Changed API:

- `YGConfig::logger()` -> `YGConfig::log()`

Reviewed By: SidharthGuglani

Differential Revision: D14123483

fbshipit-source-id: 87b8bb7de0e4346b6a41e57a70ac4eb8d79b24af
2019-02-19 09:58:26 -08:00
David Aurelio e8f95dc7a1 Make logging private
Summary:
@public

Makes logging implementation internal to Yoga.

Breaking changes: removed  `YGLog` and `YGLogWithConfig`.

The upcoming changes to the JNI layer (removal of weak global refs for each node) requires adding additional parameters to the logging functions that will only be available when calculating layout.

Reviewed By: SidharthGuglani

Differential Revision: D14123390

fbshipit-source-id: 468e4a240c190342868ffbb5f8beb92324cdfdd6
2019-02-19 09:58:26 -08:00
Yuichi ONO b23676836f `flexWrap` should be kebab-case inside inline-style (#761)
Summary:
Inside css inline style, it should be spelled as `flex-wrap`.
Pull Request resolved: https://github.com/facebook/yoga/pull/761

Reviewed By: davidaurelio

Differential Revision: D14100508

Pulled By: SidharthGuglani

fbshipit-source-id: 65ebc984d959555107d58ad16ca27b2b8b4d0874
2019-02-19 04:54:43 -08:00
Kevin Gozali a1b3421d10 TM iOS: allow fallback __turbo__* methods to proxy NSDictionary types to stricter types
Summary:
Some modules may have args with types stricter than just `NSDictionary`. For now, allow these modules to manually define a __turbo__* variant of the same method that receives basic NSDictionary/NSArray typed args. That helper method can do the conversion to the stricter type as necessary. This is only needed during migration phase of TurboModule.

Without this workaround, existing methods may get unrecognized selector errors.

Reviewed By: PeteTheHeat

Differential Revision: D14115981

fbshipit-source-id: ca7fcf497490ef9cce14c3d3444991c50d3cb550
2019-02-15 20:06:15 -08:00
Peter Ammon 0d7faf6f73 Introduce prepareJavaScript jsi API
Summary:
This adds a new jsi API prepareJavaScript. This accepts the same
parameters as evaluateJavaScript() but does not evaluate anything; instead
it returns a new object PreparedJavaScript which can itself be evaluated,
via the new API evaluatePreparedJavaScript().

There is a new empty class PreparedJavaScript which may be subclassed by
each Runtime variant to store its particular prepared form.

Reviewed By: mhorowitz

Differential Revision: D10491585

fbshipit-source-id: 702b9e23f2ff03d71a8ab17efb7e154b16dd8e87
2019-02-15 01:52:00 -08:00
Peter Ammon 7a8957c0be evaluateJavaScript to accept a shared_ptr instead of unique_ptr
Summary:
This changes jsi::evaluateJavaScript() to accept a
const shared_ptr<Buffer> & instead of a unique_ptr<Buffer.

It is reasonable to want to pass the same buffer to evaluateJavaScript()
multiple times. This will also help unify the API with the upcoming
prepareJavaScript() API.

Because shared_ptr has a unique_ptr constructor, this is compatible with
all call sites.

Reviewed By: mhorowitz

Differential Revision: D14001664

fbshipit-source-id: b7a0b7ec578a3fd6a6272241d50067269d2b03e4
2019-02-15 01:52:00 -08:00
Jonathan Kim c02f278d8f xplat// -> fbsource//xplat/ for xplat/js
Reviewed By: scottrice

Differential Revision: D14076351

fbshipit-source-id: f803d2af438a5eb3f18c981793e17b6293d8ef1c
2019-02-14 23:53:32 -08:00
Valentin Shergin b3961aff2a Fabric: Fixed small perf problem in RCTImageManager
Summary:
This changes fix small perf problem in RCTImageManager (and layout!) saving (in my completly non-scientific tests) up to 2 ms.
Maybe that's not much, but it fires during layout (and ShadowNodeTree reconsiliation processes), so it has to be very performant.

Reviewed By: JoshuaGross

Differential Revision: D14072077

fbshipit-source-id: 0baa54584dc3ae6a5f43be13fd152b84801c8539
2019-02-14 20:09:16 -08:00
Valentin Shergin 5e0b5ff7cc Fabric: Introducing SharedFunction
Summary:
`SharedFunction` implements a pattern of a shared callable object that contains the same executable inside. It's similar to  `std::function` with one important difference: when the object is copied, the stored function (and captured values) are shared between instances (not copied).
`SharedFunction` can be stored inside `std::function` because it's callable.
It useful in some scenarios, such as:
 * When captured by `std::function` arguments are not copyable;
 * When we need to replace the content of the callable later on the go.

We will use it in the coming diffs.

Reviewed By: mdvacca

Differential Revision: D14072078

fbshipit-source-id: 9df4ad2d1b92394e2dfef5c283f35c7c0bd4b500
2019-02-14 20:09:16 -08:00
Valentin Shergin 13d87e9ad2 Fabric: Fixed object ownership problem in ImageManager
Summary:
Sometimes, when we deal with ImageRequest and ImageResponseObserverCoordinator we subscribe for status (or access the coordinator) without owning an ImageRequest. In those cases, we have to retain the coordinator explicitly.
For those cases, ImageRequest now exposes `ImageResponseObserverCoordinator` as a `std::shared_ptr`.

Eg, concretely in the code, `completionBlock` and `progressBlock` copied a raw pointer to the observer inside which can lead to a crash when ImageRequest is being deallocated before we received an image data.

Reviewed By: JoshuaGross

Differential Revision: D14072079

fbshipit-source-id: e10120bc05bf685e288f7b3d69092714dcd91d43
2019-02-14 00:43:03 -08:00
David Vacca 959fdf6049 ReadableNativeMap -> ReadableMap
Summary:
This diff refactors JNI methods used by the Binding.cpp class in order to use ReadableMap instead of ReadableNativeMap
This will be helpful to provide a different implementation of ReadableMap from C++

Reviewed By: shergin

Differential Revision: D14077762

fbshipit-source-id: 595b0c2d3a2d6070112257b65c1141a8af36f0e1
2019-02-14 00:07:40 -08:00
empyrical 1ec9325bae Fabric: Change naming scheme of `ShadowNodeFragment` placeholders (#23437)
Summary:
This pull request implements some suggestions made in #23414, namely:

* Rename `ShadowNodeFragment::nullSharedProps()` (and family) to `ShadowNodeFragment::propsPlaceholder()`;
* Introduce similar functions for the rest of members (tag and rootTag);

Later pull requests to remove designated initializers from Fabric (for MSVC support) will use these

I'd like to do the rename of `rootTag` to `surfaceId` as well, but would make sense to do in a separate diff as that would result in a great deal of changes.

[General] [Changed] - Changed naming scheme of `ShadowNodeFragment` placeholders, and added placeholders for remaining members
Pull Request resolved: https://github.com/facebook/react-native/pull/23437

Reviewed By: mdvacca

Differential Revision: D14072007

Pulled By: shergin

fbshipit-source-id: d5bb10a82c16d45955f417a49b503f215c4bc521
2019-02-13 22:03:01 -08:00
empyrical 1cb34cb761 Fabric/DebugStringConvertibleItem.h: Fix for MSVC (#23436)
Summary:
This pull request removes a constructor in `DebugStringConvertibleItem.h` that was causing this issue in MSVC:

```
DebugStringConvertibleItem.cpp(20): error C2600: 'facebook::react::DebugStringConvertibleItem::DebugStringConvertibleItem': cannot define a compiler-generated special member function (must be declared in the class first)
```

It was likely conflicting with the constructor that has default values for all of its arguments.

[General] [Fixed] - Fixed `DebugStringConvertibleItem` compilation on MSVC
Pull Request resolved: https://github.com/facebook/react-native/pull/23436

Reviewed By: shergin

Differential Revision: D14067760

Pulled By: mdvacca

fbshipit-source-id: 303cf9b3559932c3d06514a1f3a8739d0f6f9dc2
2019-02-13 18:59:33 -08:00
Alex Dvornikov 3c74b6ea34 Bring back the unit tests for the Cxx implementation
Reviewed By: jeanlauliac

Differential Revision: D14026623

fbshipit-source-id: 76a4089bb09b7e5152e992a91eae0427877767c0
2019-02-12 04:50:52 -08:00
Kevin Gozali 344b32bb64 TM iOS: avoid bad memory access when passing prop name to a lambda
Summary: Depending on the timing of the method call from JS to a CxxModule, we may be accessing memory that has been deallocated, causing exception to RN runtime. This fixes it.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D14033831

fbshipit-source-id: 5a77aa41223b1fc3146dcf78b7f8e93375605d6d
2019-02-11 17:29:14 -08:00
Valentin Shergin 222e650885 Fabric: Systraces are temporary disabled in Fabric C++ code
Summary: Now in BUCK file only, not in code.

Reviewed By: JoshuaGross

Differential Revision: D14019271

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

Reviewed By: mdvacca

Differential Revision: D14019272

fbshipit-source-id: 8b322b5c115efe33c15929e008b97a05220813df
2019-02-11 16:01:05 -08:00
empyrical 78be6efda9 JSI: Minor tweaks for building on MSVC (#23367)
Summary:
This pull request makes two minor changes to `jsi.h`:

 * Tweak the `JSI_EXPORT` macro to automatically set itself to an empty value if `_MSC_VER` is defined - like how was done by acoates-ms [here](8beb4bb58a/ReactCommon/cxxreact/JSBigString.h (L15-L21)).
 * Tweak the call to constructor `Pointer(Runtime::PointerValue* ptr)` in the constructor for `PropNameID`. I am not sure why MSVC wasn't working with the original version, but it compiles after I tweak that.

[General] [Fixed] - Tweaked `jsi.h` to build on MSVC
Pull Request resolved: https://github.com/facebook/react-native/pull/23367

Differential Revision: D14032507

Pulled By: cpojer

fbshipit-source-id: 701c13e3509cc244dbe0c15f92067fae4382bee2
2019-02-11 15:42:18 -08:00
Valentin Shergin 1a26f97eb0 Clang-format for all files in Fabric folder
Summary:
Trivial.
If you have troubles with rebasing on top of this revision, run this on your diff:
$ find */*.h */*.mm */*.cpp */*.m -exec clang-format -style=file -i {} \;

Reviewed By: JoshuaGross

Differential Revision: D14018903

fbshipit-source-id: fd0ce2da0e11954e683385402738c701045e727c
2019-02-11 13:07:09 -08:00
Kevin Gozali d9f34bdbb2 TM iOS: added helper to check whether a class is TurboModule compatible
Summary: Similar macro as the existing one, but this one checks for the class directly.

Reviewed By: RSNara

Differential Revision: D14016664

fbshipit-source-id: aae9a9c1cc95f56d2eff6c9021a714ed4a843db3
2019-02-08 21:08:51 -08:00
Valentin Shergin 21290b569b Fabric: Enable all Fabric tests for Android
Summary: All our C++ Fabric tests are cross-platform, so it makes sense to run them for all platforms (especially because platform may behaive differently).

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D13984574

fbshipit-source-id: e384c03c7f9839be38a1910e04ba2f7725abc378
2019-02-08 20:18:19 -08:00
David Vacca 6a71d51250 Trivial rename
Summary: Trivial rename

Reviewed By: fkgozali

Differential Revision: D14011984

fbshipit-source-id: dd2e7e0221bdad7b482c6a39b1cc877779c9704c
2019-02-08 18:55:35 -08:00
Valentin Shergin fd3b8f2000 Fabric: Introducing Better: For faster, clear and ideomatic codebase
Summary:
`Better` is a trivial collection of basic tools borrowed from other low-level general purpose libraries (like Folly, Abseil or Boost). The main goals of Better:
 - Make the codebase more portable;
 - Make the dependency list explicit (by decoupling it as a dependency list of Better);
 - Make relying on modern C++ patterns and tools in code simple and easy.
 - Make executing experiments with different dependencies easier.

 As a first example usage, this diff replaces std::unordered_map with an efficient one from folly on the one of the hottest paths.

Reviewed By: JoshuaGross

Differential Revision: D13944565

fbshipit-source-id: 5fa2c4abe6c17f7361eddcc25f968b6440d5d9db
2019-02-08 13:57:33 -08:00
David Aurelio 5319cb29a8 Move `.clang-format` to repo root (#23328)
Summary:
Moves `.clang-format` to repo root to allow for easier discoverability, and integration with auto-format plugins for editors and IDEs.
Pull Request resolved: https://github.com/facebook/react-native/pull/23328

Differential Revision: D13986715

Pulled By: davidaurelio

fbshipit-source-id: fcfda59842da10cd4bc02e4550b74782fbb59e0d
2019-02-07 04:19:49 -08:00
Valentin Shergin 9842e39019 Fabric: folly::dynamic was replaced with RawValue in prop-parsing infra
Summary:
Our long-term plan is to completely illuminate `jsi::Value`-to-`folly::dynamic` serialization step in prop parsing process improving performance and memory pressure. At the same time, we don't want to introduce a hard dependency in application code to JSI because it exposes direct access to VM and prevents parsing some data that come *NOT* from JSVM.
RawValue is an extremely light-weight (hopefully fully optimized-out) abstraction that provides limited JSON-like and C++-idiomatic interface.

The current particular implementation is still using `folly::dynamic` inside, but I have fully JSI-powered one which will replace the current one right after we figure out how to deal with folly::dynamic-specific callsites. Or we can implement RawValue in a hybrid manner if a code-size implication of that will be minimal.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D13962466

fbshipit-source-id: e848522fd242f21e9e771773f2103f1c1d9d7f21
2019-02-06 16:34:46 -08:00
Valentin Shergin b0c8275369 Fabric: Lost comment in EventQueue
Summary: Just a comment.

Reviewed By: JoshuaGross

Differential Revision: D13962465

fbshipit-source-id: 31780a8ccf02d768e3d4b91e7205ceb0ee10fedf
2019-02-06 16:34:46 -08:00
Valentin Shergin 2332cb6fe2 Fabric: A bunch of `#ifdef ANDROID`
Summary: Nothing really changed; the change is only to better express an original intent.

Reviewed By: JoshuaGross

Differential Revision: D13962464

fbshipit-source-id: f385db8ba8662f2150181e47fc6a2a981f809e96
2019-02-06 16:34:46 -08:00
Kevin Gozali 94925d5eb7 TM iOS: Verify that module class conforms to RCTTurboModule before instantiating
Summary: At times, the lookup logic may find a class that's not compliant with RCTTurboModule. If so, it shouldn't be instantiated, and we assume the module doesn't exist.

Reviewed By: JoshuaGross, RSNara

Differential Revision: D13979004

fbshipit-source-id: ac1fa9cc456715cddd101fff13f5a41f9528a74e
2019-02-06 16:10:30 -08:00
Kevin Gozali 3e9f9cfe47 TM iOS: Util to check if an id is TurboModule instance
Summary: Simple macro to do check if TurboModule is enabled and the particular object is RCTTurboModule compliant.

Reviewed By: PeteTheHeat

Differential Revision: D13978368

fbshipit-source-id: 660c7cab7bb074d80d57abead951dad19306ae73
2019-02-06 16:01:31 -08:00
Joshua Gross 550a14c216 ImageResponseObserverCoordinator does not need to be shared_ptr
Summary: Don't use shared_ptr in this case, it's not needed.

Reviewed By: shergin

Differential Revision: D13965413

fbshipit-source-id: ec98c13f53c7d558a0cb68cea0f97568dd202cd8
2019-02-06 11:51:32 -08:00
Joshua Gross b6318acbab Support image props for Slider component, feature parity with pre-Fabric Slider
Summary: The biggest change is that (1) the image proxy/observer code from the Image component has been generalized, (2) the four image props for the Slider component are fully supported, (3) a handful of props that were ignored or buggy on iOS now perform as expected.

Reviewed By: shergin

Differential Revision: D13954892

fbshipit-source-id: bec8ad3407c39a1cb186d9541a73b509dccc92ce
2019-02-05 17:31:40 -08:00
empyrical cae6beff74 JSBigString.h: Remove duplicate include of 'unistd.h' (#23297)
Summary:
This removes the accidental double include of the header `unistd.h` from `JSBigString.h`. One was added by me as part of #22330, and one by matthargett as part of #21764

[General] [Fixed] - `JSBigString.h`: Removed accidental double include of header `unistd.h`
Pull Request resolved: https://github.com/facebook/react-native/pull/23297

Differential Revision: D13961223

Pulled By: hramos

fbshipit-source-id: c0dba8a475b3c09356d34cb65b989c286793fa67
2019-02-05 12:41:46 -08:00
REDMOND\acoates 8beb4bb58a Various minor changes to allow compliation with msvc (#22182)
Summary:
This change is aiming to reduce some of the forking changes we have internally in order to use CxxReact for some additional out of tree platforms.

Some of the fixes allow more of the code to compile when using Microsoft Visual Studio Compiler. In particular the change around the default value of RN_EXPORT and some changes around how to enable the packing attribute.

Another change moves more of the code for JSBigFileString into the cpp file, so that people can share the header but replace the implementation as appropriate for other platforms.

And finally the removal of an unused header include.

This is unlikely to be the extent of the changes required for MSVC, but at least gets one of our complication blocks to work against an unforked RN.
Pull Request resolved: https://github.com/facebook/react-native/pull/22182

Differential Revision: D12967758

Pulled By: cpojer

fbshipit-source-id: a2cc018aedaa9916cd644bfbd9e3a55330cd4c52
2019-02-05 06:14:14 -08:00
David Vacca 7f27888878 Add performance counters for Fabric
Summary:
This diff adds performance loggers for Fabric in Android to be able to compare current version or RN with Fabric

This is the summary of Points and Annotations:

- **UIManager_CommitStart**: time that React starts the commit (react tree is ready to start rendering in native)
- **UIManager_LayoutTime**: this is the time it takes to calculate layout in yoga
- **UIManager_FabricFinishTransactionTime**: Time it takes transform "C++ mutationInstructions" into "Java MountItems" and cross boundaries from C++ to Java (including serialization of data) (THIS IS ONLY FABRIC)
- **UIManager_DispatchViewUpdates**: time right before RN moves the mount operations to the Queue that is going to be processed in the next tick UI thread
- **UIManager_BatchRunStart**: time right before the mountItems are going to be process in the UI Thread
- **UIManager_BatchedExecutionTime**: time it took to run batched mountItems (usually layout and prop updates on views)
- **UIManager_NonBatchedExecutionTime**: time it took to run non-batched mountItems (usually creation of views)

Reviewed By: fkgozali

Differential Revision: D13838337

fbshipit-source-id: 0a707619829e7d95ce94d9305ff434d1224afc46
2019-02-04 17:27:30 -08:00
Kevin Gozali 8ae185280d TM iOS: guard against nullptr in module lookup
Summary: Just tightened up the lookup logic to guard against nullptr.

Reviewed By: RSNara

Differential Revision: D13948001

fbshipit-source-id: 55bf46619712e60e195ea12f2b8eb799f80a3bbe
2019-02-04 14:57:18 -08:00
Ramanpreet Nara aa39cb6d9f Remove assertion on TurboModule existence
Summary:
It's okay for TurboModules to not exist. Therefore, `__turboModuleProvider(moduleName)` should return null if `moduleName` doesn't refer to an actual TurboModule. The current implementation assumes that the TurboModule must exist, and therefore, it crashes the app when it doesn't (assertion error).

This change is important because it helps us land D13887962. When we switch `I18nResources` to `TurboModuleRegistry` in D13887962, on Wilde, it won't be found in `NativeModules`. Therefore, we'll try to lookup this module in `__turboModuleProvider`, and this will crash the app. It seems like `I18nResources` is a Java-only module?

Reviewed By: fkgozali

Differential Revision: D13924589

fbshipit-source-id: 7ac7b1873e06852e5aafcaaef5c24cbc548ee444
2019-02-04 11:36:05 -08:00
David Aurelio 0e1d4ecbb7 Make `==` operator for `YGStyle` free function
Summary:
@public

Makes it work nicely with gtest.

Also allows rhs *and* lhs to offer `operator(YGStyle)()`.

Reviewed By: SidharthGuglani

Differential Revision: D13942573

fbshipit-source-id: ff8b3a9aa6f05ca1b0572eb97d0ad23b09d77871
2019-02-04 10:24:50 -08:00
David Aurelio 5184f0d7a3 User-defined literals for `YGValue`
Summary:
@public

Adds `_pt` and `_percent` user defined literals to create `YGValue` instances.

This allows to create `YGValue`s in the following form:

```
use namespace facebook::yoga::literals;

auto a = 123_pt; // == YGValue{123.0f, YGUnitPoint}
auto b = -12.5_percent; // == YGValue{-12.5f, YGUnitPercent}
```

Reviewed By: SidharthGuglani

Differential Revision: D13942100

fbshipit-source-id: ce1e2f9431c3e2a99c6e11896a712539cc535e0d
2019-02-04 10:24:50 -08:00
zhongwuzw cca1cdf9b3 Fix typo of startSurface comments (#23264)
Summary:
N/A

[iOS] [Fixed] - Fix typo of startSurface comments
Pull Request resolved: https://github.com/facebook/react-native/pull/23264

Differential Revision: D13941762

Pulled By: cpojer

fbshipit-source-id: 9ec3ef767e46428c6a67553c3275fb7b7cea16eb
2019-02-04 08:07:44 -08:00
David Vacca 842b9c106a Temporary remove systraces from Fabric core code
Summary: This is a temporary change to measure production data

Reviewed By: fkgozali

Differential Revision: D13906807

fbshipit-source-id: 2a2f71aa379c4aca63c7bb4a9644704f713cb088
2019-02-02 13:08:06 -08:00
Joshua Gross 28b8b8e370 Use feature flags in Fabric C++ core, in particular for paragraph measurement caching
Summary: The goal is to be able to use MobileConfig params inside of core React Native C++ code. This works on Catalyst iOS now and Wilde; need to add support for FB4A and Catalyst Android.

Reviewed By: fkgozali

Differential Revision: D13883007

fbshipit-source-id: 115fe6cc884d2a0b9ca26dadf867a5f0ae99f262
2019-02-01 18:19:11 -08:00
David Aurelio e2bd70afff Marker for baseline callbacks
Summary:
@public

Wraps baseline callbacks with a marker.

Reviewed By: SidharthGuglani

Differential Revision: D13896861

fbshipit-source-id: 848ec697977a0a68b9943f1159f6562d54724f89
2019-02-01 03:34:39 -08:00
David Aurelio d2b2316722 Marker for measure callbacks
Summary:
@public

Wraps measure callbacks with a marker.

Reviewed By: SidharthGuglani

Differential Revision: D13896745

fbshipit-source-id: d6e14fe93f666b06516be1aef7f8e1bfe45440a7
2019-02-01 03:34:39 -08:00
Joshua Gross 10e4a851ad Address some paragraph measure cache follow-up nits
Summary: Changing some T& to const T&, removing unnecessary shared_ptr.

Reviewed By: shergin

Differential Revision: D13845619

fbshipit-source-id: 2678f67f24445e3db105619a07534f5200e313fe
2019-01-31 19:18:55 -08:00
Matt Hargett 36916ee99d Fix portability issues to Linux, FreeBSD, and older libc++
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/21764

Differential Revision: D13902907

Pulled By: hramos

fbshipit-source-id: 640cde865b1bcc5ca43c17d00574b8e2f78ceaf4
2019-01-31 17:45:20 -08:00
Ramanpreet Nara 0ceefb40d5 Enable module lookup in TurboModules
Summary:
NativeModules are instantiated by the bridge. If they choose, they can capture the bridge instance that instantiated them. From within the NativeModule, the bridge can then be used to lookup other NativeModules. TurboModules have no way to do such a lookup.

Both NativeModules and TurboModules need to be able to query for one another. Therefore, we have four cases:
1. NativeModule accesses NativeModule.
2. NativeModule accesses TurboModule.
3. TurboModule accesses NativeModule.
4. TurboModule accesses TurboModule.

In summary, this solution extends the bridge to support querying TurboModules. It also introduces a `RCTTurboModuleLookupDelegate` protocol, which, implemented by `RCTTurboModuleManager`, supports querying TurboModules:
```
protocol RCTTurboModuleLookupDelegate <NSObject>
- (id)moduleForName:(NSString *)moduleName;
- (id)moduleForName:(NSString *)moduleName warnOnLookupFailure:(BOOL)warnOnLookupFailure;
- (BOOL)moduleIsInitialized:(NSString *)moduleName
end
```

If TurboModules want to query other TurboModules, then they need to implement this protocol and synthesize `turboModuleLookupDelegate`:

```
protocol RCTTurboModuleWithLookupCapabilities
property (nonatomic, weak) id<RCTTurboModuleLookupDelegate> turboModuleLookupDelegate;
end
```

NativeModules will continue to use `RCTBridge` to access other NativeModules. Nothing needs to change.

When we attach the bridge to `RCTTurboModuleManager`, we also attach `RCTTurboModuleManager` to the bridge as a `RCTTurboModuleLookupDelegate`. This allows the bridge to query TurboModules, which enables our NativeModules to transparently (i.e: without any NativeModule code modification) query TurboModules.

In an ideal world, all modules would be TurboModules. Until then, we're going to require that TurboModules use the bridge to query for NativeModules or TurboModules.

`RCTTurboModuleManager` keeps a map of all TurboModules that we instantiated. We simply search in this map and return the TurboModule.

This setup allows us to switch NativeModules to TurboModules without compromising their ability to use the bridge to search for other NativeModules (and TurboModules). When we write new TurboModules, we can have them use `RCTTurboModuleLookupDelegate` to do access other TurboModules. Eventually, after we migrate all NativeModules to TurboModules, we can migrate all old callsites to use `RCTTurboModuleLookupDelegate`.

Reviewed By: fkgozali

Differential Revision: D13553186

fbshipit-source-id: 4d0488eef081332c8b70782e1337eccf10717dae
2019-01-31 11:35:05 -08:00
Eric Rozell dfcbf9729f Adds fixes for react-native-windows UWP (#848)
Summary:
Specifically, updates the UWP .vcxproj for MSBuild and also exposes the UseLegacyStretchBehaviour API for use with react-native-windows.
Pull Request resolved: https://github.com/facebook/yoga/pull/848

Reviewed By: SidharthGuglani

Differential Revision: D13848609

Pulled By: davidaurelio

fbshipit-source-id: eab046ff3c47e49706f515e209d8aaf750c2198f
2019-01-31 09:35:10 -08:00
Kevin Gozali 8a50bc3ab3 iOS: Make each module implement getTurboModuleWithJsInvoker: instead of having centralized provider
Summary:
For better modularity, each module conforming to RCTTurboModule should provide a getter for the specific TurboModule instance for itself. This is a bit more extra work for devs, but simplify tooling and allow better modularity vs having a central function that provides the correct instance based on name.

Note: Android may or may not follow this new pattern -- TBD.

Reviewed By: RSNara

Differential Revision: D13882073

fbshipit-source-id: 6d5f82af67278c39c43c4f7970995690d4a82a98
2019-01-30 17:32:16 -08:00
David Aurelio c16fadb7c3 Track how much measure cache entries are used
Summary:
@public

Adds the maximum number of measure cache entries in use to the metrics for `YGMarkerLayout`

Reviewed By: SidharthGuglani

Differential Revision: D13844731

fbshipit-source-id: fa66dbf1b7a1799494f72ecc17dfaef04d0b56e4
2019-01-29 15:54:19 -08:00
David Aurelio f506019e8b count cache hits
Summary:
@public

Adds cache hit counts to layout stats.

Reviewed By: SidharthGuglani

Differential Revision: D13844022

fbshipit-source-id: 906b4ec5fe3314287911cee2c37d77c4aac76455
2019-01-29 11:41:36 -08:00
David Aurelio 0dafa0de6b Layout marker metadata
Summary:
@public

Adds marker meta data to `YGMarkerLayout`: the number of measures, and the numbers of layouts for all nodes in the tree.

Reviewed By: SidharthGuglani

Differential Revision: D13838975

fbshipit-source-id: d575c26a3d5a4f0b66834eb6bedecadc3f3ca265
2019-01-29 11:41:36 -08:00
David Aurelio fc6a4b6dbb Pass layout marker data along
Summary:
pubic

Passes layout marker data through the recursive calls of the layout algorithm, in order to allow for collecting metrics.

Reviewed By: SidharthGuglani

Differential Revision: D13819444

fbshipit-source-id: cdca04964fba6a03ca3eeaca4d169107019ba457
2019-01-29 11:41:36 -08:00
David Aurelio c723029242 Introduce first marker
Summary: @public Adds a marker section for a complete layout pass

Reviewed By: SidharthGuglani

Differential Revision: D13819447

fbshipit-source-id: 21a80f0fe3d325d804a968508761d115c50d3dc1
2019-01-29 11:41:36 -08:00
David Aurelio f1a3137b41 Add `MarkerSection`
Summary:
@public

Adds a class for triggering markers.

This calls `startMarker()` on construction, and `endMarker()` on destruction, thus being usable like a "scope guard": the object is instantiated, and automatically destroyed when going out of scope.

Reviewed By: SidharthGuglani

Differential Revision: D13817589

fbshipit-source-id: fd88884af970c1c0933d9ca6843f3f8f5d28b9e6
2019-01-29 11:41:36 -08:00
David Aurelio 52d9f2627b Remove unused constexpr
Summary:
@public

Removes unused constexpr variables from YGStyle. Not polluting the global namespace is a good thing.

Reviewed By: SidharthGuglani

Differential Revision: D13816817

fbshipit-source-id: e4c27a8f2de466ccb759bbe52cdaea6fe451b961
2019-01-29 04:11:25 -08:00
David Aurelio 43601f1a17 Add function to set marker callbacks
Summary:
@public

Adds a function to allow to configure markers. The function is declared in `YGMarker.h`

Reviewed By: SidharthGuglani

Differential Revision: D13819111

fbshipit-source-id: f9158b3d4e5727da4e151c84b523c7c7e8158620
2019-01-29 03:51:37 -08:00
David Aurelio 1db55803f1 Add `YGMarkerLayout`
Summary: @public adds a first `YGMarker`, and the accompanying data type.

Reviewed By: SidharthGuglani

Differential Revision: D13817588

fbshipit-source-id: 6007eb09d19cf4021989bad5b5e880adb16364a0
2019-01-29 03:51:37 -08:00
David Aurelio e804124e6f Rename `YGMarkerType` to `YGMarker`
Summary:
@public

this will lead to nicer enum member names.

Reviewed By: SidharthGuglani

Differential Revision: D13817587

fbshipit-source-id: 85355328f7977b4fb29a9474532f2d578a3cbf79
2019-01-29 03:51:36 -08:00
Rafael Lincoln ac90c4fd6d Fix warnings in JSI (#23201)
Summary:
His PR is related to #22609

There are still some warnings related to folly, but I plan to make the correction and send the PR to the repo of the folly.

Changelog:
[IOS][Changed] - Fix warning in JSCRuntime
Pull Request resolved: https://github.com/facebook/react-native/pull/23201

Differential Revision: D13859393

Pulled By: cpojer

fbshipit-source-id: 95df2b76b28b460f890d11e1395fddb6b1cc8fed
2019-01-29 03:31:50 -08:00
Joshua Gross 88bc80c518 Update hash functions to use folly:#️⃣:hash_combine
Summary: Following hashing best practices.

Reviewed By: shergin

Differential Revision: D13827893

fbshipit-source-id: 3786f1e42b176a973890989be7b33efce4825ac6
2019-01-28 14:36:30 -08:00
Joshua Gross a9049442f7 Fabric: Use LRU to cache results of ParagraphShadowNode::measure
Summary: Use a folly LRU implementation to cache results of ParagraphShadowNode::measure, which Yoga asks for repeatedly. Should have a substantial speed improvement on Android and iOS, or at least that's the dream.

Reviewed By: mdvacca

Differential Revision: D13795808

fbshipit-source-id: 5716af0fe0517a72716e48113c8125bb788735d7
2019-01-25 17:00:51 -08:00
Joshua Gross b905548a3b Fabric: Replace ImageLoader promise implementation with observer model
Summary: Folly promises/futures have been replaced by an observer model which keeps track of loading state. This resolves at least one crash that I can no longer repro and simplifies the code a bit (IMO).

Reviewed By: shergin

Differential Revision: D13743393

fbshipit-source-id: 2b650841525db98b2f67add85f2097f24259c6cf
2019-01-25 09:24:09 -08:00
David Aurelio f4def0062c Delete functionality for shared childen
Summary:
@public

Removes `YGNodeInsertSharedChild` / `addSharedChildAt`.

This functionality is unused, and can cause memory leaks.

Reviewed By: SidharthGuglani

Differential Revision: D13711105

fbshipit-source-id: 86206c05393b3f1a497e6b046006f94ead88c6ce
2019-01-24 06:31:00 -08:00
David Vacca 5bc709d517 Temporary render <View> for <AndroidTextInput> component
Summary: Temporary render <View> for <AndroidTextInput> component to unlock testing basic React Screens that uses TextInput

Reviewed By: sahrens

Differential Revision: D13768283

fbshipit-source-id: 9fda8c633f03ec9e88dccef3525726e1a9d60f73
2019-01-23 11:31:56 -08:00
Joshua Gross c40a782b3a Fabric: Add Fabric-compatible Slider component to iOS
Summary: Fabric-compatible Slider component, minus image support (coming soon!)

Reviewed By: shergin

Differential Revision: D13644717

fbshipit-source-id: ce3f0c1ee530be4807b875cb2080c59693b7337a
2019-01-22 17:03:08 -08:00
zhongwuzw d55558e138 Fix isBatchActive of RCTCxxBridge (#22785)
Summary:
Seems we lost handler of `isBatchActive` from [RCTBatchedBridge a86171a](a86171a482/React/Base/RCTBatchedBridge.m) to [RCTCxxBridge 5bc7e39](b774820dc2 (diff-a2a67635fffd7b690d14dc17ae563a71)).

Changelog:
----------

[iOS] [fixed] - Fix isBatchActive of RCTCxxBridge
Pull Request resolved: https://github.com/facebook/react-native/pull/22785

Reviewed By: mhorowitz

Differential Revision: D13731897

Pulled By: cpojer

fbshipit-source-id: 8d6b85bcea8fe8997a93b4e1ac8b8007422ca20e
2019-01-21 00:28:48 -08:00
Valentin Shergin 091edd2ef7 Fabric: Clear separation between `commmit` and `tryCommit`
Summary: Previously we had a single `commit` function that accepts an argument that enables auto-retry mechanism. As Spencer pointed out, that wasn't so useful and clear. So, I split the method into two with more expressive names.

Reviewed By: sahrens

Differential Revision: D13681594

fbshipit-source-id: 529f729d597206e9a0ac940f005a1569a9bef707
2019-01-16 20:22:40 -08:00
Valentin Shergin 8d83d5f8eb Fabric: Unifying retain/release logic in EventTarget
Summary:
I read my code and one thing stroke me: What if the same event emitter dispatches several events during the same event beat? In the previous implementation, only the first one will be delivered because the first `release` call consumes stored strong reference.
So, I changed the API a bit to make this more explicit: we have `retain` & `release` methods and we have a getter that works (multiple times) only if the object was successfully retained.

Reviewed By: sahrens

Differential Revision: D13668147

fbshipit-source-id: c00af5f15bc7e30aa704d46bd23584b918b6f75a
2019-01-16 20:22:40 -08:00
Valentin Shergin 7d630b92dc Fabric: Lock-free events 5/n: New implementation of `toggleEventEmitters` (which does not rely on mutations)
Summary: This diff implements a new algorithm that effectively marks `EventEmitter`s enabled or disabled. The previous implementation relied on a list of mutation instructions whereas the new one analyzes the shadow trees. The mutations-based approach didn't work well because mutations describe `ShadowView`s whereas some `ShadowNode`s are simply not views (like VirtualText), but we have to enable/disable them anyway.

Reviewed By: sahrens

Differential Revision: D13642594

fbshipit-source-id: 12169e11d5685e50bcd0d8c410498c594df744b4
2019-01-16 20:22:39 -08:00
Valentin Shergin cdb983d339 Fabric: Lock-free events 4/n: Added an assert in EventTarget
Summary: See the diff for more details.

Reviewed By: sahrens

Differential Revision: D13642593

fbshipit-source-id: 8bdcc91bcc2ea1e4093bcac03d87167b8901cbb4
2019-01-16 20:22:39 -08:00
Valentin Shergin 97f9e4082c Fabric: Lock-free events 3/n: EventEmitter::DispatchMutex is not recursive mutex anymore
Summary: The mutex is a "leaf" mutex, so the code cannot reenter that, so there is no reason to be a recursive one.

Reviewed By: sahrens

Differential Revision: D13642592

fbshipit-source-id: 0fb64d3405c5d3408251dc983c186f6747bc6ee2
2019-01-16 20:22:39 -08:00
Valentin Shergin b1814b37aa Fabric: Lock-free events 2/n: Reimagining of EventTarget
Summary:
EventTargetWrapper and EventTarget were merged into one class that controls an `instanceHandle` reference and extracting a strong reference to it.

This diff also decouples the operation of retaining a strong reference (with checking a `enabled` flag) from actual usage of this reference. This allows to wrap into a mutex only first part of this process and avoid possible deadlocks.

Reviewed By: sahrens

Differential Revision: D13616382

fbshipit-source-id: 9907bc12047386fcf027929ae2ae41c0b727cd06
2019-01-16 20:22:39 -08:00
Valentin Shergin bea80b2276 Fabric: Lock-free events 1/n: Removing WeakEventTarget trick from EventEmitter
Summary:
For some time we have had a nit trick inside `EventEmitter`: When event emitter is disabled, we switch to store `EventTarget` as a weak pointer instead of complete deleting it. Given some unpredictability of JS GC, it gave us some time to restore the pointer in case if we increment the counter right after decrementing this. Apparently, we found that it doesn't always work (obviously, sigh...), so we implement the `enableCounter_` and left this feature as it is assuming that it can nice optimization that illuminates some unnecessary constraints.
But, apparently, it's actually harmful, assuming that `jsi::WeakObject` (that thing that we use to refer to actual JS target) actually has "unsafe unretained" (not "weak") semantic.
So, we have to remove this.
This change will be particularly important for coming diffs in the stack.

Reviewed By: mdvacca

Differential Revision: D13324480

fbshipit-source-id: 4c4da2984dc6a36b94b564bc9eee144142b430b0
2019-01-16 20:22:39 -08:00
Valentin Shergin 9f71a8f26e Fabric: `ShadowTree::getRootShadowNode` was removed
Summary: Because it was not idiomatic anyway. There is no point having a pointer to RootShadowNode without any guarantees that it's the current one. Using `commit` method makes this concern explicit.

Reviewed By: sahrens

Differential Revision: D13615363

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

Reviewed By: sahrens

Differential Revision: D13615365

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

Reviewed By: sahrens

Differential Revision: D13615364

fbshipit-source-id: 13dbea1e69ef51b2679101915c01c6be7e15d859
2019-01-16 20:22:39 -08:00
Valentin Shergin 5a58ca4144 Fabric: New non-blocking treading model for ShadowTree
Summary:
Instead of the whole family of commit* and complete* methods, now we have one single `commit` method which performs pre- and post-commit operations and swap pointers in a thread-safe manner. The `commit` operation is also exposing `revision` number and allows perform multiple commit attempts.

`completeByReplacingShadowNode`, `measure` and `constraintLayout` are also going away to RootShadowNode class in the next commits.

Why?
* Nicer API;
* No more recursive_mutex, no more problems with thread jumps;
* All mutex locks are now leaf-locks, so no more deadlocks possible;
* Exposing `revision` should help with debugging races.

Reviewed By: sahrens

Differential Revision: D13613942

fbshipit-source-id: 94e797d2f7860717847e823b5d97c4f7b35f08df
2019-01-16 20:22:39 -08:00
Valentin Shergin 8f9ca2b9a0 Fabric: Even more systraces
Summary: Trivial.

Reviewed By: mdvacca

Differential Revision: D13664395

fbshipit-source-id: 3de5d65d6fcf8b68bce2636fc91492defdbe8405
2019-01-16 20:22:39 -08:00
David Vacca b421b5f4bd Open source Fabric android
Summary: This diff open sources Fabric Android implementation and it extracts ComponentDescriptorFactory into a function that can be "injected" per application

Reviewed By: shergin

Differential Revision: D13616172

fbshipit-source-id: 7b7a6461216740b5a1ad5ebbead9e37de4570221
2019-01-16 12:38:22 -08:00
Eduardo Roman cfbb2278a0 guard against INF values in CompactValue
Summary:
After this diff D13403925 that got rid of `-ffast-math` we started to have a very odd behavior on Yoga when using release builds.

After digging a while we found that certain set of conditions on O2 and O3 optimization levels was causing Origami to set some `INFINITE` values on Yoga.

We found the root of the problem and fix it on Origami side. But I'm wondering if guarding agains `INFINITE` on Yoga side would be good too. Since now Yoga it's not using `-ffast-math` anymore, and I think infinite is not a a valid value anywhere on Yoga side, it seems to support the reason to guard against it.

I'm happy to abandon this diff if you guys think this is not a good solution.

Reviewed By: davidaurelio

Differential Revision: D13679319

fbshipit-source-id: 061448fea9d1a8496362ff07dc46b546e7f1ffa3
2019-01-16 12:27:49 -08:00
David Aurelio 3cfe8d59bc Reflow comments
Summary:
@public

Repeated application and alternation of Clang Format rules has lead to unfortunate block comment formatting.

Here, we reflow comments

Reviewed By: SidharthGuglani

Differential Revision: D13677242

fbshipit-source-id: 3f1f5e38693eb15e9705f24fd363fc1618c78974
2019-01-16 08:47:15 -08:00
David Aurelio 53a28ee180 Fix URLs to CSS spec in comments
Summary:
@public

These URLs probably have been changed when CSSLayout was renamed to Yoga by search & replacing

Reviewed By: SidharthGuglani

Differential Revision: D13690829

fbshipit-source-id: 44dbd8fe256fc286006d164390609a7c3de6c4e6
2019-01-16 08:47:15 -08:00
Eli White db5528ffa9 Use Generated Switch Schema
Summary: We are now generating the native cpp files for Switch via Buck. Deleting the hand written files and switching over.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D13666672

fbshipit-source-id: 72cf6f6af9374511f2742f8f0d996fa52e1bff5b
2019-01-15 18:10:34 -08:00