Commit Graph

9142 Commits

Author SHA1 Message Date
Denis Koroskin f738b598d8 Properly invalidate FlatViewGroup when hotspot Drawable invalidates
Summary: I lost FlatViewGroup.verifyDrawable(Drawable) method during one of the rebases. Re-adding it now because hotspot drawable is not working without it.

Reviewed By: ahmedre

Differential Revision: D2772460
2016-12-19 13:40:17 -08:00
Denis Koroskin 98604485c4 Remove unused imports from RCTViewManager
Summary: RCTViewManager has a few extra imports that I missed. They are removed now.

Reviewed By: ahmedre

Differential Revision: D2772438
2016-12-19 13:40:17 -08:00
Denis Koroskin 79be10428b Add support for ViewProps.NEEDS_OFFSCREEN_ALPHA_COMPOSITING to RCTView
Summary: Copied from ReactViewManager. Should provide performance improvements.

Reviewed By: ahmedre

Differential Revision: D2772832
2016-12-19 13:40:17 -08:00
Denis Koroskin 99d1c15c4d Properly implement manageChildren(), correctly handling moveFrom and moveTo
Summary: Previously, manageChildren() would throw an Exception if moveFrom != null or moveTo != null. This is obviously not correct, because no matter how rare these events are, they actually happen in practice. This diff re-implements manageChildren() to support all the cases. It does so by first removing all the elements that need to be removed. During removal, those elements that need to be moved will be temporarily put into `mNodesToMove` array. Then the next step is to add all elements (including new elements to add, and existing elements to move). There is an fast path when only one of another is present. If both types are present, they need to be sorted, first, to maintain correct orded. A similar optimization is applied to `removeChildren()`: there is a fast path when moveFrom == null and a another fast path when removeFrom == null. When both are != null, a merge sort is used (it is assumed that both moveFrom and removeFrom are sorted).

Reviewed By: ahmedre

Differential Revision: D2768689
2016-12-19 13:40:17 -08:00
Denis Koroskin 04ae4b0ba3 Dispatch OnLayoutEvent when node gets re-laid out
Summary: There is an OnLayoutEvent that needs to be dispatched when a ReactShadowNode gets re-laid out. Some applications rely on it, so we should support it. This diff adds this functionality.

Reviewed By: ahmedre

Differential Revision: D2768625
2016-12-19 13:40:17 -08:00
Denis Koroskin c144bcbc96 Implement @ReactProp nativeBackgroundAndroid in RCTView
Summary: RCTView has a property called nativeBackgroundAndroid that shows a ripple effect (or any other Drawable) when pressed and holded. This diff is adding support for the property.

Reviewed By: ahmedre

Differential Revision: D2768671
2016-12-19 13:40:17 -08:00
Denis Koroskin 381bf1b76f Implement TextNodeRegion
Summary: NodeRegion is only able to describe a rectangular region for touch, which is not good enough for text, where we want to be able to assign different touch ids to individual words (and those can span more than one line and in general have non-rectangular structure). This diff adds TextNodeRegion which inserts additional markers into text Layout to allow individual words to have unique react tags.

Reviewed By: ahmedre

Differential Revision: D2757387
2016-12-19 13:40:17 -08:00
Denis Koroskin 85cdfcd1f7 Turn FlatViewManager into ViewGroupManager
Summary: Views that can contain other Views need to have their ViewManager to extend ViewGroupManager. Otherwise, it may not remove child Views correctly when a parent View is being detached. This diff is changing FlatViewManager that create FlatViewGroups (that can have child Views) to extend from ViewGroupManager.

Reviewed By: ahmedre

Differential Revision: D2768667
2016-12-19 13:40:17 -08:00
Denis Koroskin 94052261d1 Fix RCTImageView.setBorderWidth() shadowing ShadowLayoutNode.setBorderWidths()
Summary: RCTImageView.setBorderWidth() is shadowing ShadowLayoutNode.setBorderWidths() because both are annotated with `ReactProp borderWidth`. To fix the issue, override setBorder instead (which is what LayoutShadowNode.setBorderWidths delegates to).

Reviewed By: ahmedre

Differential Revision: D2763938
2016-12-19 13:40:17 -08:00
Denis Koroskin 529390b87c Fix children of AndroidView not being re-laid out after they call requestLayout
Summary:
In ReactNative, we are fully controlling layout of all the Views, not allowing Android to layout anything for us. This is done by making onLayout() of the top-level View in the hierarchy to be empty. This works fine because we explicitly call measure/layout for all the Views when they need to be re-measured or re-laid out. There is however one case where this doesn't happen automatically: some Android Views such as DrawerLayout or ActionBar have children that don't have shadow nodes associated with them (such as a title in ActionBar). This results in situations where children of AndroidView will call requestLayout but they will never get relaid out, because shadow hierarchy doesn't know about them. Example: ActionBar has a seTitle method that will internally call TextView.setTitle() and that TextView will call requestLayout because its size may have changed. However, that TextView will never be remeasured or relaid out.

This diff is fixing it by keeping track of everyone who called requestLayout. Then, at the end of the update loop we go over the list a manually remeasure and relayout those Views.

Not a huge fan of how this is implemented (there MUST be a better way) but this works with least efforts. I'll see if I can improve it later.

Reviewed By: ahmedre

Differential Revision: D2757485
2016-12-19 13:40:16 -08:00
Denis Koroskin ad65b2a9e1 Remove referenced to dropped views
Summary:
There is currently a bug where we never release any Views that no longer display, still storing hard references in NativeViewHierarchyManager. This diff is fixing this bug, and here is how:

a) there is already logic in place to drop FlatShadowNodes (UIImplementation.removeShadowNode).
b) there is already logic in place to drop Views (NativeViewHierarchyManager.dropView(int reactTag) - used to private but needs to be protected so I can call it)
c) (the missing part) when we are about to drop a FlatShadowNode, check if it mount to a View (i.e. there is a View associated with that node), put it into a ArrayList. When we finished updates to a nodes hierarchy (which happens in non-UI thread), collect ids from those nodes and enqueue a UIOperation that will drop all the Views. We can either forward nodes as FlatShadowNode[], or only ids as int[]. Both should be fine, but as a rule of thumb we don't touch shadow node hierarchy from UI thread (as we don't touch Views from non-UI thread) so passing int[] is what this code is doing.

Reviewed By: ahmedre

Differential Revision: D2757310
2016-12-19 13:40:16 -08:00
Denis Koroskin e9753a11ae Don't collect state for virtual nodes
Summary: Virtual nodes (such as RCTRawText and RCTVirtualText) have no state or node regions, don't need to be laid out, and thus should not be checked for state.

Reviewed By: ahmedre

Differential Revision: D2757089
2016-12-19 13:40:16 -08:00
Denis Koroskin 312f04d2b7 Apply FlatShadowNode padding to View
Summary: Any padding that a FlatShadowNode is assigned by React runtime should be translated to a backing Android View so it looks correct and lays out children accordingly.

Reviewed By: sriramramani

Differential Revision: D2756562
2016-12-19 13:40:16 -08:00
Denis Koroskin dbe9cc333c Add support for custom AndroidViews
Summary: This diff adds an `AndroidView` as a proxy for custom Views in FlatUIImplementation. Any ReactShadowNode that FlatUIImplementation doesn't recognize (because they don't extend from FlatShadowNode) will be wrapped with AndroidView to ensure that it measures and displays correctly. While not perfect, this is the easiest way to support custom Views (EditTexts, DrawerLayouts, ScrollViews etc).

Reviewed By: ahmedre

Differential Revision: D2751716
2016-12-19 13:40:16 -08:00
Denis Koroskin 1da7049426 ForceMountToView when Opacity or other View-specific properties are applied to a FlatShadowNode
Summary: @public There are some properties, such as alpha or scale that we ONLY handle on a View level. This means that whenever we encounter a FlatShadowNode with this property, it should be mapped to a View. This diff is doing exactly this.

Reviewed By: ahmedre

Differential Revision: D2694495
2016-12-19 13:40:16 -08:00
Martin Kralik 0d042c2ef4 updated css-layout and fixed callsites
Summary:
This diff pulls in my changes to css-layout algorithm. (The change: https://github.com/facebook/css-layout/pull/154)
This is a breaking change, since it adds a new `height` parameter to all measure functions.

So I've fixed all existing implementations just by adding a new unused parameter `height` - it's up to owners of these functions whether they want to use it or not.

Reviewed By: foghina

Differential Revision: D2757965
2016-12-19 13:40:16 -08:00
Denis Koroskin 4fb42be0a1 Dispatch View bounds updates at the end of StateBuilder.applyUpdates()
Summary: Normally, order or `measure/layout` and `onAttachedToWindow` shouldn't matter. However, `DrawerLayout` has a `boolean mFirstLayout` flag that it resets to true in `onAttachedToWindow` that makes it ignore first layout, and it leads to bugs. To fix the issue, we need to make sure that we first call `onAttachedToWindow` and only then we call `measure/layout`. The easiest way to do it is to delay measure/layout calls until all the views are attached to their parents. This diff implements the mentioned logic.

Reviewed By: sriramramani

Differential Revision: D2694973
2016-12-19 13:40:16 -08:00
Denis Koroskin b8b4fb8a74 Apply base View properties (scale, alpha etc) to FlatShadowNode when it maps to a View
Summary: @public There are some properties that we want to handle on a View level, as opposed to a FlatShadowNode level. For example, scale or alpha, that can be done very efficiently in hardware. Once we pop FlatShadowNode to a separate View, we need to apply these properties. This is where `BaseViewManager` comes in handy.

Reviewed By: sriramramani

Differential Revision: D2694290
2016-12-19 13:40:16 -08:00
Denis Koroskin dad378e394 Add NodeRegion to allow any FlatShadowNode to respond to touch events
Summary: @public When Android dispatches `MotionEvent` to `ReactRootView`, it needs to find a correspoding react node that should receive it. To be able to do it, we need to store boundaries of every `FlatShadowNode` in `FlatViewGroup`. Then we can iterate over node boundaries and find one that contains the touch event coordinates.

Reviewed By: sriramramani

Differential Revision: D2694197
2016-12-19 13:40:16 -08:00
Denis Koroskin 8de2acd3a9 Allow FlatShadowNode mouting to its own view
Summary: @public This diff adds a `FlatShadowNode.forceMountToView()` method that will render its contents in it own `View`.

Reviewed By: sriramramani

Differential Revision: D2564502
2016-12-19 13:40:16 -08:00
Denis Koroskin 7db444c9ae Pass FlatViewGroup to DrawCommand.draw()
Summary: @public To render `View`s inside `FlatViewGroup`, we need to pass the parent to `DrawCommand.draw()` method. Used in a followup diff.

Reviewed By: sriramramani

Differential Revision: D2564478
2016-12-19 13:40:16 -08:00
Denis Koroskin f19acaed4b Implement background in FlatShadowNode
Summary: @public Similar to a `DrawBorder` patch, this diff adds `DrawBackground` and implements `ViewProps.BACKGROUND_COLOR` property in `FlatShadowNode` with it.

Reviewed By: sriramramani

Differential Revision: D2564466
2016-12-19 13:40:15 -08:00
Denis Koroskin 1c7f23c79d Implement border width, color, radius and style in RCTView
Summary: @public Initial implementation of RCTView doesn't support borders, this diff fixes it by implementing a `DrawBorder`.

Reviewed By: sriramramani

Differential Revision: D2564424
2016-12-19 13:40:15 -08:00
Denis Koroskin 71ca522c68 Support borders in RCTImageView
Summary: @public Initial RCTImageView implementation only supported 'src', 'tintColor' and 'resizeMode'. This diff adds support for the rest of the properties: 'borderColor', 'borderWidth' and 'borderRadius'. `AbstractDrawBorders` class is reused in a follow up diff to draw borders for 'RCTView'.

Reviewed By: sriramramani

Differential Revision: D2693560
2016-12-19 13:40:15 -08:00
Denis Koroskin 760422525e Add support for RCTImageView in FlatShadowHierarchyManager
Summary: @public This patch adds basic support for RCTImageView (only 'src', 'tintColor' and 'resizeMode' properties are supported for now), and a concept of AttachDetachListener that is required to support it to FlatUIImplementations.

Reviewed By: sriramramani

Differential Revision: D2564389
2016-12-19 13:40:15 -08:00
Ahmed El-Helw dfe5f9f762 Re-add Javadoc to TypefaceCache.
Summary: Accidentally removed a Javadoc in the last commit, readding it.

Differential Revision: D2750357
2016-12-19 13:40:15 -08:00
Ahmed El-Helw 1a2cf776af Support custom fonts for flat React rendering.
Summary:
Custom fonts weren't supported before, now they are when using flat
rendering in React.

Differential Revision: D2740489
2016-12-19 13:40:15 -08:00
Denis Koroskin 5b182fa0ca Extract DrawCommands tracking in StateBuilder into a helper class.
Summary: @public This is a pure refactoring diff makes `StateBuilder` code a little bit easier to read. This gets increasingly important as new features with similar logic are added to `StateBuilder`.

Reviewed By: sriramramani

Differential Revision: D2564342
2016-12-19 13:40:15 -08:00
Denis Koroskin fbe1b61fe1 Cache CustomStyleSpan in RCTVirtualText
Summary: @public `RCTVirtualText` is creating a new `CustomStyleSpan` on every `applySpans()` call, which is not very efficient. We can cache and reuse unchanged `CustomStyleSpans` for efficiency. This patch is doing just that.

Reviewed By: sriramramani

Differential Revision: D2564366
2016-12-19 13:40:15 -08:00
Denis Koroskin 007318eb52 Cache Typefaces in shadow/flat/CustomStyleSpan
Summary: @public `Typeface` handling in `shadow/flat/CustomStyleSpan` wasn't very efficient. This diff introduces `TypefaceCache` to avoid allocating duplicated `Typeface`s.

Reviewed By: sriramramani

Differential Revision: D2564363
2016-12-19 13:40:15 -08:00
Denis Koroskin 5c2f536e9a Add support for RCTText under FlatUIImplementation
Summary: @public Initial version of FlatUIImplementation lacks any primitives support (such as RCTText, RCTImageView or RCTView). This diff add the first part, RCTText (alongside with RCTVirtualText and RCTRawText).

Reviewed By: sriramramani

Differential Revision: D2693348
2016-12-19 13:40:15 -08:00
FBShipIt 44d2ee1c3f Initial commit 2016-12-19 13:40:15 -08:00
Konstantin Raev 5d4b476583 boost is downloaded from https://github.com/react-native-community/boost
Summary:
Improvement over https://github.com/facebook/react-native/pull/11469.
Depends on https://github.com/react-native-community/boost-for-react-native/issues/1, **don't merge before it is fixed**.

It would be more in line with other dependencies  to depend only on github for thirdparty bridge dependencies.

**Test plan (required)**

- Circle (testing with caches cleaned)
- ./gradlew ReactAndroid:packageReactNdkLibsForBuck (check twice to make sure caches work)
REACT_NATIVE_BOOST_PATH=./path-to-local-boost/
- ./gradlew ReactAndroid:packageReactNdkLibsForBuck (check twice to make sure caches work)
Closes https://github.com/facebook/react-native/pull/11511

Differential Revision: D4348098

fbshipit-source-id: 5c2f25cc395ae0cad19d56b7c0b2b102513580fb
2016-12-19 13:13:28 -08:00
Andrew Y. Chen 5671dc3fae Add warning for missing local image resources
Summary: Show a toast (since there isn't an easy way to show the yellow box)

Reviewed By: AaaChiuuu

Differential Revision: D4336435

fbshipit-source-id: 01b0dbdaabf51be3d23aab5c72ab2a701fcb8f80
2016-12-19 11:58:49 -08:00
Konstantin Raev 709a441ecf Disabled unit tests that need yoga libs when running
Reviewed By: hramos

Differential Revision: D4346826

fbshipit-source-id: 70855a44b27d25e49615914a845cf04fc63e322d
2016-12-19 11:43:30 -08:00
Jean Lauliac ede04abf8f packager: make output simpler, more legible
Reviewed By: cpojer

Differential Revision: D4339417

fbshipit-source-id: f174ee11bc220de5e8da1d8227e9a9ceb5319e8d
2016-12-19 10:58:32 -08:00
Pieter De Baets c92ad5f6ae Apple TV support 4: support for input (tvOS focus engine)
Reviewed By: shergin

Differential Revision: D4333546

fbshipit-source-id: 8655070e81dbb62a80ab1f00a43ef6c2d9654618
2016-12-19 06:28:40 -08:00
David Aurelio 2cc587f3f4 Improve source map quality when inserting numeric module IDs
Summary:
This changes the way that module identifiers are replaced with numeric ids so that ids are padded with spaces on the right to take up the same space as the original string literal.
By doing this, we keep the mappings for the generated source line intact.

```
// original source
const React = require('react');
// old replacement
const React = require(12 /* react */);
// new replacement
const React = require(12     ); // 12 = react
```

The remaining edge case are module names that are replaced with numeric IDs that are longer than the replaced string, e.g.:

```
const Q = require('q');
const Q = require(1234);
```

Reviewed By: cpojer

Differential Revision: D4346092

fbshipit-source-id: ef3bb879495f388c4a7448a2f810b83c204e8984
2016-12-19 06:13:29 -08:00
Cristian Carlesso a69b480cae Update RN to Jest 18
Reviewed By: cpojer

Differential Revision: D4335580

fbshipit-source-id: c48b6882b89aa20f9f58783b5a17edf94df22223
2016-12-19 04:43:30 -08:00
Pieter De Baets 88da9e658c Remove duplicate Yoga copy
Reviewed By: foghina

Differential Revision: D4346088

fbshipit-source-id: 3decfe16fe13d70a1862fc8bb8dfca30689023f8
2016-12-19 03:43:29 -08:00
Alan Norbauer 4aabf4b6b3 Replace jest.resetModuleRegistry() with jest.resetModules()
Reviewed By: cpojer

Differential Revision: D4344961

fbshipit-source-id: 45453ec7ee3211743946ab9156f51430322b5832
2016-12-18 17:13:38 -08:00
Aaron Chiu 1052d29fac create ART*ViewManager classes
Reviewed By: achen1

Differential Revision: D4050949

fbshipit-source-id: 214838c1c1cf6c66170b606ac7055e1e8790b6c9
2016-12-17 17:43:35 -08:00
Ashok Menon 6ca6b4988a Propagate Load Errors through JSExecutor API
Reviewed By: mhorowitz

Differential Revision: D4315204

fbshipit-source-id: ae282e0a0398a602dd790de3a2b1adb5fdc1f50c
2016-12-17 04:58:31 -08:00
Kevin Lacker 9f3ef48f65 Added info about a cancelable option for Alerts on Android.
Summary:
In the 8e2906ae89 commit there was implemented a cancelable option for Alerts. It wasn't clear from the docs about this option and the additional Alert method's parameter.
Closes https://github.com/facebook/react-native/pull/11292

Differential Revision: D4342707

Pulled By: lacker

fbshipit-source-id: dc243b868106e705040e77bc90d4d9b8c2dc26eb
2016-12-16 16:28:31 -08:00
Aaron Chiu c27cc9c1ac add viewManager param to @ReactModuleList
Reviewed By: achen1

Differential Revision: D4338871

fbshipit-source-id: 4ac175e0a9049d5fb08c9d01f630a3e17124e08e
2016-12-16 15:28:28 -08:00
Leland Richardson 71f32fb5a3 Fix documentation for scrollResponderScrollNativeHandleToKeyboard
Summary:
I'm pretty sure this is supposed to be "bottom" as opposed to "top", as it's the offset from the keyboard, which is at the bottom of the screen.
Closes https://github.com/facebook/react-native/pull/11446

Differential Revision: D4339957

Pulled By: lacker

fbshipit-source-id: 62dca544a0167704d76cd972c44570f277ea63aa
2016-12-16 15:13:36 -08:00
Adam Comella 1c32385344 Android: Fix native animation crash
Summary:
An exception is thrown when the native animation code attempts to play an animation on a view that hasn't been created yet. This can happen because views are created in batches. If this particular view didn't make it into a batch yet, the view won't exist and an exception will be thrown when attempting to start an animation on it.

This change eats the exception rather than crashing. The impact is that the app may drop one or more frames of the animation.

**Notes**

I'm not familiar enough with the Android native animation code to know whether or not this is a good fix. My team is using this change in our app because dropping animation frames is better than crashing the app. [This is the code](c612c61544/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java (L874-L892)) that is creating the views in batches. Hopefully my PR at least provides some insight into the cause of the bug.

This may fix #9887
Closes https://github.com/facebook/react-native/pull/10907

Differential Revision: D4340129

Pulled By: lacker

fbshipit-source-id: 69160d9e71281a96a7445d764b4715a3e54c0357
2016-12-16 14:28:34 -08:00
tychota 25cd2c5d7b Deprecate RecyclerViewBackedScrollView
Summary:
cc brentvatne

potential reviewers mkonicek and kmagiera

**Motivation for making this change.**

The previous PR was closed : #11095 but the followup actions was never done

I reopened a really similar one so it get merged
RecyclerView is no more used at Facebook (according to previous PR)

According to brentvatne, their were two motivations for RecyclerView:
* ListView with ScrollView component used to bounce back on row insert, but this is now fixed
* This made possible to implement certain performance improvements, but the maintenance cost was not worth the risk

With RN 0.37, the actual code in React Native make the app crash:
- see #10560

I spend one hour investigating this and did also require brent time at exponent slack. I think other people are struggling too.

**Test plan**

<img width="708" alt="screen shot 2016-12-13 at 23 42 22" src="https://cloud.githubusercontent.com/assets/13785185/21162483/dbeb642e-c18d-11e6-9c32-1fe73f1826c1.png">

**Code formatting**

The
Closes https://github.com/facebook/react-native/pull/11445

Differential Revision: D4340640

Pulled By: mkonicek

fbshipit-source-id: 64c5cf060f2eb035d4d6199b30f0e73afc520180
2016-12-16 12:28:36 -08:00
David Aurelio 4308b9ea2c Add `deps` param to `js_library`
Reviewed By: cpojer

Differential Revision: D4334383

fbshipit-source-id: 96f0d6ba5ed8ddab25087edd6381a6e6449ff63a
2016-12-16 11:13:35 -08:00
Steve Kellock f49093f397 Fixes launching Visual Studio Code due to args being a nested array.
Summary:
**Motivation**

Visual Studio Code appears to have been accidentally borked in RN 38 & 39.

[Here you see](a643784144 (diff-9ad1aafc931637a94d74b60c06b46871R153)) args become an array to support the new `shell-quote` support.

Problem is, `getArgumentsForLineNumber` also returns an array.

[And because we](a643784144 (diff-9ad1aafc931637a94d74b60c06b46871R161)) `push` instead of `concat`, we get hawt array-on-array action.

Surprisingly Atom works.  But Code doesn't like this at all.

**Test plan (required)**

On RN 0.38 and 0.39, what's happening when I click on the simulator stack frame, Code opens with the array as a string...

![image](https://cloud.githubusercontent.com/assets/68273/20971724/83a3d7c4-bc60-11e6-8170-a1c2a4adee60.png)

I've tested Vim, Code and Atom (all on 10.11.6) as well as all combinations of `REACT_EDITOR` both set
Closes https://github.com/facebook/react-native/pull/11345

Differential Revision: D4339963

Pulled By: lacker

fbshipit-source-id: 030cb9e3d84fd6861f28e3652bebfe2eef28dd62
2016-12-16 10:28:35 -08:00