Commit Graph

1644 Commits

Author SHA1 Message Date
Emil Sjolander 9724eaeb42 Fix checks for already set padding
Reviewed By: ahmedre

Differential Revision: D4393371

fbshipit-source-id: 96672d0ee38b16b6f225c8a6fe0442c9b9eb9ec8
2017-01-10 02:28:28 -08:00
Emil Sjolander e3c8d80b3c Add dynamic type for javascript arguments passed over bridge with unkown type
Reviewed By: astreet

Differential Revision: D4380882

fbshipit-source-id: f1b9fb9cf727d003dcc2264626e75fc300a47dee
2017-01-08 04:43:30 -08:00
Luke Miles da9a712a9e Add a injectJavaScript method to the WebView component
Summary:
Currently, < WebView > allows you to pass JS to execute within the view. This works great, but there currently is not a way to execute JS after the page is loaded. We needed this for our app.

We noticed that the WebView had messaging support added (see #9762) . Initially, this seemed like more than enough functionality for our use case - just write a function that's injected on initial load that accepts a message with JS, and `eval()` it. However, this broke once we realized that Content Security Policy can block the use of eval on pages. The native methods iOS provide to inject JS allow you to inject JS without CSP interfering. So, we just wrapped the native methods on iOS (and later Android) and it worked for our use case. The method injectJavaScript was born.

Now, after I wrote this code, I realized that #8798 exists and hadn't been merged because of a lack of tests. I commend what was done in #8798 as it sorely solves a problem (injecting JS after the initial load) and has more features than what I'
Closes https://github.com/facebook/react-native/pull/11358

Differential Revision: D4390425

fbshipit-source-id: 02813127f8cf60fd84229cb26eeea7f8922d03b3
2017-01-06 20:29:02 -08:00
Lukas Woehrl 7cfb7b8d0f Baseline support
Summary:
Added baseline support (see #132)

You have the ability for a custom baseline function (```float(*YGBaselineFunc)(YGNodeRef node);```) to return whatever baseline you want.
Closes https://github.com/facebook/yoga/pull/317

Reviewed By: splhack

Differential Revision: D4385061

Pulled By: emilsjolander

fbshipit-source-id: cb8a59a09237c840fa3e21753ab68239997dab0c
2017-01-06 06:58:25 -08:00
Emil Sjolander ca484fa422 Use layout padding instead of style padding
Reviewed By: AaaChiuuu

Differential Revision: D4377074

fbshipit-source-id: a9abbe58e51399e123328f905b4ea8afe0502e33
2017-01-06 06:43:45 -08:00
Emil Sjolander 8105f76226 Explicitly set default scrollbarstyle value
Summary: Explicitly set default scrollbarstyle value. Previously this style was implicitly used as a side effect of how we set padding on the Scrollview. This instead makes that behavior explicit.

Reviewed By: astreet

Differential Revision: D4386861

fbshipit-source-id: 362d82136a12b75fb81287ac0d0fd58f2ee297fb
2017-01-06 06:43:45 -08:00
Emil Sjolander ef9e855692 Dont measure edittext with padding
Reviewed By: astreet

Differential Revision: D4383821

fbshipit-source-id: 9a75b7131ba8e79671f6793276a18efea10b60d1
2017-01-06 06:43:45 -08:00
Aaron Chiu 07a2a71df3 spelling clowntown
Reviewed By: shergin

Differential Revision: D4386363

fbshipit-source-id: feeeac5a3f03bdb09ce0faa3faa669563d0a6a8b
2017-01-05 20:43:27 -08:00
Emil Sjolander 0cdda4d8d9 Expose layout paddding in java api
Reviewed By: passy

Differential Revision: D4377069

fbshipit-source-id: 2e0c04104560e1be586562b27b3457576590dc18
2017-01-05 12:58:34 -08:00
Lukas Woehrl 16359ec8ee Add feature to use percentage as value unit
Summary:
Adds the feature to use percentage as a value unit.

You can use the function ```YGPx(float)``` and ```YGPercent(float)``` for convenience.

I did some benchmarks:

```
Without Percentage Feature - Release x86:

Stack with flex: median: 0.000000 ms, stddev: 0.146683 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.490101 ms
Huge nested layout: median: 23.000000 ms, stddev: 0.928291 ms

Stack with flex: median: 0.000000 ms, stddev: 0.170587 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.143384 ms
Nested flex: median: 0.000000 ms, stddev: 0.477791 ms
Huge nested layout: median: 22.000000 ms, stddev: 2.129779 ms

With Percentage Feature - Release x86:

Stack with flex: median: 0.000000 ms, stddev: 0.132951 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.489570 ms
Huge nested layout: median: 21.000000 ms, stddev: 1.390476 ms
Closes https://github.com/facebook/yoga/pull/258

Reviewed By: dshahidehpour

Differential Revision: D4361945

Pulled By: emilsjolander

fbshipit-source-id: a8f5bc63ad352eb9410d792729e56664468cd76a
2017-01-02 05:28:30 -08:00
Konstantin Raev 9bb2d25682 Fixed proxy settings for legocastle buck tests
Reviewed By: kentaromiura

Differential Revision: D4375249

fbshipit-source-id: 7fa51d41ccbf1e017cfaceb5b6160361177f0b11
2016-12-30 08:43:30 -08:00
Emil Sjolander c7c24dce84 Allow decimal measurements on java
Differential Revision: D4366605

fbshipit-source-id: 0b94ee87a03a6ed918360dd9998930e780fc865d
2016-12-29 04:58:34 -08:00
Caleb Gomer 573170699f Update Android RecyclerView Library to 23.4.0
Summary: Update the Android RecyclerView, support v4, and annotation libraries to 23.4.0.

Differential Revision: D4345649

fbshipit-source-id: 859c6555bc79358b1c8ffed0629cdf0e83408a00
2016-12-28 18:43:39 -08:00
Ahmed El-Helw e380d6d0fd Ignore touch events on layout only Nodes
Summary:
Before this patch, each Node would always generate a node
region, representing the bounds of this particular Node. This set of Nodes was
used when handling touch to figure out whether we should intercept touch (i.e.
a flat Node is catching the draw), or let Android handle touch (i.e. a Node
mounted to a View will handle the touch).

This patch modifies the list of NodeRegions to exclude any Nodes that draw
nothing at all. These Nodes, having no draw output, are effectively layout
containers used to group items, so they shouldn't handle touch.

Reviewed By: sriramramani

Differential Revision: D4369484

fbshipit-source-id: 71b41611873580631f1639f368fa8d971995874f
2016-12-28 18:43:39 -08:00
Ahmed El-Helw 008ad0200f Fix measurement of virtual nodes
Summary:
Virtual nodes do not have backing Yoga nodes, so measure
their first non-virtual parent instead of measuring them.

Reviewed By: sriramramani

Differential Revision: D4360540

fbshipit-source-id: 505d35fec74dddf67b002d29268acc29d2651b13
2016-12-21 17:58:34 -08:00
Theo Yaung e64618374b Fail-Fast on Redundant Java Callback Invocations
Reviewed By: dcaspi

Differential Revision: D4354731

fbshipit-source-id: d23351f23c8c5962da60af77340166fcb1314d78
2016-12-21 10:58:31 -08:00
Ahmed El-Helw d73746774b Fix SurfaceView not redrawing when it should
Summary:
Like its non-Nodes counterpart, FlatARTSurfaceViewShadowNode
should redraw when extra updates are collected.

Reviewed By: sriramramani

Differential Revision: D4355702

fbshipit-source-id: 6e7b90360958481f5bef9b806eca9fa888cb6a32
2016-12-20 18:28:38 -08:00
Ahmed El-Helw 3998650468 Add a README file for Nodes
Summary:
Add a README file explaining the purpose of Nodes and how to
enable it within an app.

Reviewed By: JoelMarcey, lacker

Differential Revision: D4349517

fbshipit-source-id: ec26ebb37039e7c23ecd2cf4b482fa21ca8beeda
2016-12-19 16:58:30 -08:00
Ahmed El-Helw d3d5d7b7c9 Update build scripts for Nodes 2016-12-19 13:41:07 -08:00
Ahmed El-Helw 761089211f Fix drawRect with NaN when drawing borders in Nodes
Summary:
drawRect was sometimes being called with NaN values, which caused
very strange ui behavior on some devices. This patch fixes the problem by
ensuring that we use a default value when the value is NaN.

Reviewed By: AaaChiuuu

Differential Revision: D4338453
2016-12-19 13:40:36 -08:00
Emil Sjolander e9dba410eb Update java package name to yoga
Summary: Update package name of java code to refer to yoga instead of csslayout. Still need to change the name of the folder where this code resides but that requires update github sync scripts etc so it is safer and easier to split these diffs apart.

Differential Revision: D4271420
2016-12-19 13:40:36 -08:00
Emil Sjolander 009a792804 Rename java API
Summary: Rename java api to new use yoga naming

Reviewed By: IanChilds

Differential Revision: D4265345
2016-12-19 13:40:36 -08:00
Ahmed El-Helw c5eb13facd Revert D3754778: Don't double clip images in Nodes
Summary: This reverts commit c5af305fa2b9ab15e2a31287dac4e5a3992aeb0d

Differential Revision: D3754778
2016-12-19 13:40:36 -08:00
Emil Sjolander b7c2cfcb34 Rename enums
Summary: new name, start by renaming enums

Differential Revision: D4244360
2016-12-19 13:40:35 -08:00
Emil Sjolander 75561f7f78 Remove deprecated java code
Summary: Remove deprecated java code and make use of CSSEdge instead of the now removed Spacing class.

Reviewed By: AaaChiuuu

Differential Revision: D4233198
2016-12-19 13:40:35 -08:00
Andy Street 29754eb95d BREAKING [react_native] Don't create CSSNodes for virtual shadow nodes
Summary:
@public

Virtual shadow nodes (e.g. text) don't use CSSNodes so we don't need to create them. This shows large savings in CSSNodes allocated, depending on the app.

This could be breaking if:
- You have virtual nodes that still set and get CSS properties. The setters now no-op for virtual nodes (I unfortunately couldn't remove them completely -- see the comment on LayoutShadowNode), but the getters will NPE. If you see these NPE's, you should almost definitely be using your own datastructure instead of a CSSNode as virtual nodes will not participate in the layout process (and the CSSNode is then behaving just as a POJO for you).

I do not anticipate this to be breaking for anyone, but am including breaking in the commit message since this is a change in API contract.

Reviewed By: emilsjolander

Differential Revision: D4220204
2016-12-19 13:40:35 -08:00
Andy Street 03ac82e387 Recycle CSSNodes
Summary:
@public

Adds a pool to recycle CSSNodes within UIManager. A follow-up diff will hook this up to a memory pressure listener to drop the pool on memory pressure.

Reviewed By: emilsjolander

Differential Revision: D4189532
2016-12-19 13:40:35 -08:00
Andy Street bb8d540cf7 Use markUpdated instead of dirty setPadding in nodes
Summary: setPadding already calls dirty, and we should only be calling dirty on nodes that have measure functions.

Reviewed By: emilsjolander

Differential Revision: D4205148
2016-12-19 13:40:35 -08:00
Andy Street 1d555bff22 BREAKING [react_native/css_layout] Update RN shadow nodes to hold CSSNode instead of extending CSSNode
Summary:
@public

This diff makes it so ReactShadowNode holds a CSSNode instead of extending one. This will enable us to pool and re-use CSSNodes and will allow us to keep from breaking the CSSNode api assumption that nodes that have measure functions don't have children (right now, text nodes have measure functions, but they also have raw text children).

BREAKING
This diff makes ReactShadowNode no longer extend CSSNodeDEPRECATED. If you have code that depended on that, e.g. via instanceof checks, that will no longer work as expected. Subclasses that override getChildAt/addChildAt/etc will need to update your method signatures. There should be no runtime behavior changes.

Reviewed By: emilsjolander

Differential Revision: D4153818
2016-12-19 13:40:35 -08:00
Sriram Ramasubramanian 947e885487 Make Nodes use TextLayoutBuilder's LayoutMeasureUtil
Summary:
Make Nodes use TextLayoutBuilder's LayoutMeasureUtil.
This cuts down a dependency.

Reviewed By: ahmedre

Differential Revision: D4151599
2016-12-19 13:40:35 -08:00
Emil Sjolander 3fff811c57 call super instead of self
Summary: Call super.setPadding. Calling the overriden version will cause stack overflow.

Differential Revision: D4096141
2016-12-19 13:40:35 -08:00
Emil Sjolander 242f5e9198 BREAKING - Change measure() api to remove need for MeasureOutput allocation
Summary: This is an API breaking change done to allow us to avoid an allocation during measurement. Instead we do the same trick as is done when passing measure results to C, we path them into a long.

Reviewed By: splhack

Differential Revision: D4081037
2016-12-19 13:40:35 -08:00
Ahmed El-Helw 7af3331171 Don't crash on dropping a dropped view in Nodes
Summary:
In Nodes, we sometimes get crashes when we drop an already dropped
view. For now, this catches the exception to allow things to be handled
gracefully (until we can identify the actual root cause). #accept2ship

Reviewed By: sriramramani

Differential Revision: D4059333
2016-12-19 13:40:35 -08:00
Emil Sjolander c10bbe5599 Dont create a spacing object for returning margin, padding, border, and position
Summary: The current implementation was made out of simplicity and to keep the same API as before. Now that the java version of csslayout is deprecated it is time to change the API to make the calls more efficient for the JNI version. This diff with reduce allocations as well as reduce the number of JNI calls done.

Differential Revision: D4050773
2016-12-19 13:40:35 -08:00
Jonathan Lawlor e909fc01c0 Fix path effect styling in nodes workflow
Summary:
From task:
in Nodes today, styles (dashed and dotted) only work on borders if the view has rounded corners. this is incorrect as they should work even when we're drawing rectangular borders.

Looking at the current non-nodes code (https://fburl.com/474407319) we can see that whenever there is a pathstyle effect the non-nodes code treats the border as if it was rounded (note that mBorderStyle == null || mBorderStyle == BorderStyle.SOLID means NO path effect is applied).

To bring the Nodes code in line with the non-Nodes code we can simply do the same thing: if there is a path style effect draw it as if it was rounded.

Reviewed By: ahmedre

Differential Revision: D4054722
2016-12-19 13:40:35 -08:00
Jonathan Lawlor b74667e570 Fix the drawing of borders to use drawPath when necessary
Summary:
From task:
In some cases, however, drawPath is the more correct thing to do, and this ticket is one such example - if we draw the left border and top border with different colors, Nodes draws rectangularly, whereas non-Nodes makes the edges triangular.

To solve the issue in Nodes, we use drawPath instead of drawRect only when necessary (borders intersect with different colors).

Reviewed By: ahmedre

Differential Revision: D4048685
2016-12-19 13:40:34 -08:00
Dmitry Petukhov e1b0d32bde Two ReactART TODOs implemented on Android
Summary:
Implemented 2 TODOs from ReactART for Android:
- TODO(7255985): Use TextureView and pass Surface from the view to draw on it asynchronously instead of passing the bitmap (which is inefficient especially in terms of memory usage)
- TODO(6352067): Support dashes in ARTShape

We use ReactNativeART in our Android project.
1. Our app crashes sometimes on large screen smartphones with OutOfMemoryError. Crashes happen in ARTSurfaceShadowNode where TODO(7255985) was suggested in a comment in order to use memory more efficiently.
2. We needed dashes for drawing on ARTSurface.

**Test plan (required)**

I attach a screenshot of our app which shows dashed-lines and two ARTSurfaces on top of each other rendering exactly the same as in the pervious implementation of ARTSurface.
![screenshot_2016-08-19-16-45-43](https://cloud.githubusercontent.com/assets/18415611/17811741/cafc35c4-662c-11e6-8a63-7c35ef1c5ba9.png)
Closes https://github.com/facebook/react-native/pull/9486

Differential Revision: D4021303

Pulled By: foghina
2016-12-19 13:40:34 -08:00
Emil Sjolander 698774d273 Clearly mark java CSSNode as deprecated. It will go away very soon
Summary: Clearly mark java CSSNode as deprecated. It will go away very soon.

Reviewed By: lucasr

Differential Revision: D3992775
2016-12-19 13:40:34 -08:00
Ahmed El-Helw f038ef4e0d Don't resolve root parent when dropping a view in Nodes
Summary:
In Nodes, we added logic when we dropped a view to also pass the
parent, so we could tell the parent that \"hey, this view is now dropped\"
so that it can be released. While this is fine, there are some crashes due
to the fact that the root node is not being found when we drop the child.

I've spent a lot of time thinking about how this could happen, and the only
plausible explanation I can come up with is that we first detach all views
from the root, then drop the root, and then drop one of the children that
was detached. I can't think of a good way why this would happen.

In the interest of protecting from this crash, this patch adds a check as to
whether or not the id of the parent is that of a root id, and, if so, it
doesn't run the logic that tells this view that this view was removed.

This should be safe, because the root most view should not have clipping
enabled (since it's a vanilla view group as opposed to a scrolling view).

Reviewed By: sriramramani

Differential Revision: D3991682
2016-12-19 13:40:34 -08:00
Felix Oghina ab5de9b9ae pass EventDispatcher to UIImplementation constructor
Summary:
This way `UIImplementation` can hold on to it and use it outside of calls from the `UIManagerModule`.

@public

Reviewed By: lexs

Differential Revision: D3899774
2016-12-19 13:40:34 -08:00
Andrei Coman e4129fe1b4 Modal statusbar cleanup
Summary:
@public

The hack for the status bar height is not necessary any longer, so we can remove
all code related to it

Reviewed By: lexs

Differential Revision: D3943770
2016-12-19 13:40:34 -08:00
Sriram Ramasubramanian 1297a4a82b Rename cache warmer to glyph warmer
Summary: This feels like a better name.

Reviewed By: kdelong

Differential Revision: D3943277
2016-12-19 13:40:34 -08:00
Ahmed El-Helw fc10d0d3bf Fix modals freezing on close with Nodes
Summary:
Modals were doing nothing (and sometimes crashing) when they were
being closed. The reason for this was due to the fact that the parent being
removed was not necessarily the view's parent. Consequently, trying to inform
said parent that its child was removed failed, because said parent wasn't a
view, and therefore had no record in mViewsToTags.

Reviewed By: sriramramani

Differential Revision: D3928850
2016-12-19 13:40:34 -08:00
Emil Sjolander a61766dbac BREAKING - Fix unconstraint sizing in main axis
Summary:
@public
This fixes measuring of items in the main axis of a container. Previously items were in a lot of cases measured with UNSPECIFIED instead of AT_MOST. This was to support scrolling containers. The correct way to handle scrolling containers is to instead provide them with their own overflow value to activate this behavior. This is also similar to how the web works.

This is a breaking change. Most of your layouts will continue to function as before however some of them might not. Typically this is due to having a `flex: 1` style where it is currently a no-op due to being measured with an undefined size but after this change it may collapse your component to take zero size due to the implicit `flexBasis: 0` now being correctly treated. Removing the bad `flex: 1` style or changing it to `flexGrow: 1` should solve most if not all layout issues your see after this diff.

Reviewed By: majak

Differential Revision: D3876927
2016-12-19 13:40:34 -08:00
Ahmed El-Helw f1053600d5 Support recursive clipping of subviews with Nodes
Summary:
With Nodes, we want to support recursive clipping of subviews.
Without this, surfaces like Marketplace won't properly handle subviews.

Reviewed By: sriramramani

Differential Revision: D3904721
2016-12-19 13:40:34 -08:00
Ahmed El-Helw 147989cd96 Fix a Nodes crash when double detaching a clipped view
Summary:
This fixes a crash for the case when we try to drop a view that has already been dropped.

**The Problem**

We got reports of a crash (t12912526) that occurs when the resolveViewManager method can't resolve a ViewManager for a View being dropped.

Investigating this, one thing in common between all the stack traces for this is that dropView is called from line 210 of FlatNativeViewHierarchyManager. This part of the code is specifically the part we added to remove strong references to any clipped children (from views that have subview clipping enabled).

So this is a problem specifically with Nodes and clipSubviews, which brings up some questions:

**when can this happen?**

The only situation this can possibly happen is when we drop a child (which is clipped) followed by dropping its parent in the same cycle. Consider a tree where each view only has one child, such as:  A - B - C - D. This crash would happen if D is clipped, and we removed it, followed by removing any of its parents in the same frame.

**if the removes happen in different frames, does this bug occur?**

No - the reason is that before we execute the DropView operations, we run through StateBuilder, which traverses the shadow tree and marks updates, thus removing the view going away (such that the delete in the next frame doesn't try to re-delete it).

So why doesn't this happen when we're dropping in the same frame? The reason is that manageChildren (where this all starts) asks to remove some views. We handle this by removing said Nodes and their children from the shadow tree. Consequently, when StateBuilder iterates over the shadow tree, it can't do the right thing because said nodes no longer exist.

As a more concrete example, consider A - B - C - D again, and consider that both D and B are removed. StateBuilder only sees A, and realizes that it now has 0 children (whereas before it has 1), so it removes B from its children. However, this process isn't recursive, so C never gets cleaned up.

**why doesn't this happen with Nodes without clipping containers?**

The answer to this is that NativeViewHierarchyManager's dropView method checks the existance of each child before deeply dropping that child and its subtree. So in this case, we drop D and all its children, and when we come to drop B, we try to drop C (which exists) and then its children (D, which doesn't exist because we already dropped it, so we ignore it).

**why doesn't this happen with non-Nodes?**

The reason is that non-Nodes handles removes differently - every remove is enqueued in a call to NativeViewHierarchy's manageChildren, which explicitly asks the parent to remove said child. Consequently, we never try to remove a child that is already removed.

**Fix**

The initial fix was to check whether or not the view exists, but this updated patch just does the right thing at drop time - i.e. whenever a view is dropped, we notify the parent of this fact so that it can clear the reference from clipped views.

**One last Note**

There are two reasons for switching `super.dropView` to `dropView` - first, the comment is only partially correct - calling `super.dropView` will avoid looking at clipped children (as an aside, that could cause a leak in the case of nested clipping subviews), but will look at clipped grandchildren, because of the super class's iteration across the set of children.

Reviewed By: astreet

Differential Revision: D3815485
2016-12-19 13:40:34 -08:00
Andy Street f30cc5d9a7 Add Dependency Injection, nodes support for RN/Components integration
Summary:
This should probably be two separate diffs, sorry. It takes forever to test these things on fb4a though.

The nodes GK was turned up in fb4a, so I had to make a few changes to make the existing integration work.

Reviewed By: lexs, emilsjolander

Differential Revision: D3863226
2016-12-19 13:40:33 -08:00
Emil Sjolander 173795c816 Reverted commit D3855801
Summary:
@public
Introduce `overflow:scroll` so that scrolling can be implemented without the current overflow:visible hackiness. Currently we use AT_MOST to measure in the cross axis but not in the main axis. This was done to enable scrolling containers where children are not constraint in the main axis by their parent. This caused problems for non-scrolling containers though as it meant that their children cannot be measured correctly in the main axis. Introducing `overflow:scroll` fixes this.

Reviewed By: astreet

Differential Revision: D3855801
2016-12-19 13:40:33 -08:00
Emil Sjolander 62756d8be1 BREAKING - Fix unconstraint sizing in main axis
Summary:
@public
Introduce `overflow:scroll` so that scrolling can be implemented without the current overflow:visible hackiness. Currently we use AT_MOST to measure in the cross axis but not in the main axis. This was done to enable scrolling containers where children are not constraint in the main axis by their parent. This caused problems for non-scrolling containers though as it meant that their children cannot be measured correctly in the main axis. Introducing `overflow:scroll` fixes this.

Reviewed By: astreet

Differential Revision: D3855801
2016-12-19 13:40:33 -08:00
Andy Street 57ebb98d19 Breaking: Move ReactClippingViewGroup + Helper to uimanager package
Summary:
@public

This is to be able to depend on ReactClippingViewGroup from BaseViewManager. Devs using ReactClippingViewGroup may need to update their imports when updating past this commit.

Reviewed By: lexs

Differential Revision: D3835328
2016-12-19 13:40:33 -08:00
Andrew Y. Chen 4f1549c631 Backed out changeset ce330012e84c
Summary: Fixes marketplace text rendering with nodes enabled

Reviewed By: sriramramani

Differential Revision: D3854613
2016-12-19 13:40:33 -08:00
Ahmed El-Helw 3766ec9764 Fix broken text padding on Nodes
Summary:
We were always getting LEFT explicitly, and, due to RTL support, we
should be asking for START instead.

Reviewed By: sriramramani

Differential Revision: D3836816
2016-12-19 13:40:33 -08:00
Andrei Coman 3ac0bd632c Fix Text incorrect line height
Summary:
@public
Setting the line height with the help of Android-provided StaticLayout is incorrect. A
simple example app will display the following when `setLineSpacing(50.f, 0.f)`
is set: {F62987699}. You'll notice that the height of the first line is a few
pixels shorter than the other lines.
So we use a custom LineHeightSpan instead, which needs to be applied to the text
itself, and no height-related attributes need to be set on the TextView itself.

Reviewed By: lexs

Differential Revision: D3841658
2016-12-19 13:40:33 -08:00
Ahmed El-Helw 3061606fe6 Fix TextInput padding on Nodes
Summary:
Fix TextInput padding on Nodes. We used to not call super and used
to manually do the setting of padding. This stops us from running the same
logic that non-Nodes runs (we bypassed it), so this fixes it.

Reviewed By: astreet

Differential Revision: D3825227
2016-12-19 13:40:33 -08:00
Ahmed El-Helw 558f934f44 Fix the drawing of left and right borders in Nodes
Summary:
Due to the RTL implementation, the ViewProps spacing array has START
and END, whereas Nodes should deal with RIGHT and LEFT directly (just like
non-Nodes does). This is the same implementation in use by non-Nodes.

Reviewed By: astreet

Differential Revision: D3809028
2016-12-19 13:40:33 -08:00
Ahmed El-Helw 8cff05101a Remove DrawImageWithPipeline from Nodes
Summary:
Nodes historically had two image implementations -
DrawImageWithDrawee and DrawImageWithPipeline. The drawee implementation
was the default (per request of the Fresco team). At this point, there is
no point of having two (especially since updates to one need to be made to
the other), so this patch removes pipeline.

Reviewed By: sriramramani

Differential Revision: D3755523
2016-12-19 13:40:33 -08:00
Ahmed El-Helw 82a4017ecd Don't double clip images in Nodes
Summary:
Nodes would typically clip its images, and then Fresco would then
re-clip as part of ScaleTypeDrawable - in addition to being unnecessary,
it's also incorrect, beacuse it causes the image to be smaller than it
should be.

Reviewed By: sriramramani

Differential Revision: D3754778
2016-12-19 13:40:33 -08:00
Andrei Coman 9734210f39 Reverted commit D3751097
Summary:
@public
Setting the line height with the help of Android-provided StaticLayout is incorrect. A
simple example app will display the following when `setLineSpacing(50.f, 0.f)`
is set: {F62987699}. You'll notice that the height of the first line is a few
pixels shorter than the other lines.
So we use a custom LineHeightSpan instead, which needs to be applied to the text
itself, and no height-related attributes need to be set on the TextView itself.

Reviewed By: lexs

Differential Revision: D3751097
2016-12-19 13:40:33 -08:00
Sriram Ramasubramanian 977660ed4b fbui: TextLayoutBuilder documentation fixes
Summary: TextLayoutBuilder documentation fixes.

Reviewed By: ahmedre

Differential Revision: D3767034
2016-12-19 13:40:32 -08:00
Sriram Ramasubramanian 23cb87a481 FBUI: Move TextLayout CacheWarmer to be inside textlayoutbuilder
Summary:
Move TextLayout's Cache Warmer to be inside c/f/fbui/textlayoutbuilder.
Logically feels good.

Reviewed By: ahmedre

Differential Revision: D3766463
2016-12-19 13:40:32 -08:00
Andrei Coman 66bbd78fe3 Fix Text incorrect line height
Summary:
@public
Setting the line height with the help of Android-provided StaticLayout is incorrect. A
simple example app will display the following when `setLineSpacing(50.f, 0.f)`
is set: {F62987699}. You'll notice that the height of the first line is a few
pixels shorter than the other lines.
So we use a custom LineHeightSpan instead, which needs to be applied to the text
itself, and no height-related attributes need to be set on the TextView itself.

Reviewed By: lexs

Differential Revision: D3751097
2016-12-19 13:40:32 -08:00
Ahmed El-Helw 3da695fe88 Use constant for alignment of right and left
Summary:
This is just a minor cleanup, use constants for the LEFT
and RIGHT alignments, since they are hide.

Reviewed By: sriramramani

Differential Revision: D3746019
2016-12-19 13:40:32 -08:00
Ahmed El-Helw 1f6642b34a Support RTL for Nodes
Summary: Nodes supports RTL now, just like non-Nodes does.

Differential Revision: D3727028
2016-12-19 13:40:32 -08:00
Seth Kirby d785390a35 Comment fixes.
Summary: Comments.

Reviewed By: ahmedre

Differential Revision: D3730030
2016-12-19 13:40:32 -08:00
Seth Kirby d601cc084b Add override for debug warning highlights for non-performant views and commands.
Summary: Adds a flag that can be set in FlatViewGroup to see known performance issues in Nodes objects.  This is mostly useful in internal development of Nodes, and will be a dead code path when not set.

Reviewed By: ahmedre

Differential Revision: D3732675
2016-12-19 13:40:32 -08:00
Seth Kirby 4a12efad02 Separate Node bounds and hit bounds within node region where needed.
Summary: Node region bounds are assumed to equal the underlying node bounds.  In the case of hit slop, these need to be abstracted.

Reviewed By: ahmedre

Differential Revision: D3713430
2016-12-19 13:40:32 -08:00
Seth Kirby a602891946 Use SparseArray for detached views.
Summary:
This is minor, but for our use case a SparseArray is going to be faster as long as we have less than 10,000 clipped subviews, and will also use much less memory.

Faster because of the boxing, unboxing and hash caching; less memory as it is two arrays instead of the object overhead of the HashMap.

Reviewed By: ahmedre

Differential Revision: D3704326
2016-12-19 13:40:32 -08:00
Seth Kirby b2f41e2921 Refactor DrawView to avoid extra allocates.
Summary: Previously, the first time we collected a draw view, we would make a clone, even though the draw view had never been mutated.  This refactors draw view to avoid this extra allocate.

Reviewed By: ahmedre

Differential Revision: D3719056
2016-12-19 13:40:32 -08:00
Sriram Ramasubramanian cc216b5ec3 Move TextLayoutBuilder to a better directory
Summary:
Moving TextLayoutBuilder to a better directory.
It's not a `widget`.

Reviewed By: ahmedre

Differential Revision: D3708270
2016-12-19 13:40:32 -08:00
Ahmed El-Helw f450e84942 Implement progressive image loading for Nodes
Summary: Support progressiveRenderingEnabled property for images on Nodes.

Differential Revision: D3718834
2016-12-19 13:40:31 -08:00
Ahmed El-Helw bcf2e329ed Fix RCTText not always drawing in Nodes
Summary:
In Nodes, there were certain cases where text wasn't drawn due to an
optimization that skipped measuring because the size was already known.

Reviewed By: emilsjolander

Differential Revision: D3713841
2016-12-19 13:40:31 -08:00
Seth Kirby 8600723402 Add comments to FlatViewGroup, DrawCommandManage, ElementsList and StateBuilder.
Summary: Documentate all of the things.

Reviewed By: ahmedre

Differential Revision: D3700420
2016-12-19 13:40:31 -08:00
Ahmed El-Helw 3adbf1e822 Fix measureLayout for Nodes
Summary:
For Nodes that don't mount to views, measureLayout wasn't working
because our calls for getting the width and height would return the view delta
bounds, which won't exist for Nodes. #accept2ship

Differential Revision: D3707880
2016-12-19 13:40:31 -08:00
Seth Kirby c3b4286915 Implement hit slop.
Summary: Hitslop on RTCView both virtual and non-virtual.

Reviewed By: ahmedre

Differential Revision: D3693412
2016-12-19 13:40:31 -08:00
Ahmed El-Helw 497b02ad30 Nodes should ask Fresco to resize images
Summary:
Nodes currently doesn't ask Fresco to resize images, but this is
potentially problematic (ex having a camera photo of 6000x1500 causes a crash
due to the massive size).

Differential Revision: D3687944
2016-12-19 13:40:31 -08:00
Seth Kirby a4c4a88e27 Support vertical and horizontal clipping with draw command managers.
Summary: Adds support for horizontal clipping, though the FlatViewGroup needs to be made aware still of which it is.

Reviewed By: ahmedre

Differential Revision: D3673501
2016-12-19 13:40:31 -08:00
Seth Kirby 192c99a4f6 Gather command and node region information off the UI thread.
Summary: This optimizes node region searches in clipping cases, and does position calculation for drawCommands off of the UI thread.

Reviewed By: ahmedre

Differential Revision: D3665301
2016-12-19 13:40:31 -08:00
Emil Sjolander ca79e6cf30 Add jni bindings
Summary: Add jni bindings for csslayout. First step in many of removing LayoutEngine.java and performing all layout in native.

Reviewed By: lucasr

Differential Revision: D3648793
2016-12-19 13:40:31 -08:00
Ahmed El-Helw 0c9afec7dc Remove ImageRequestHelper for Nodes
Summary:
Use ImageRequestBuilder directly in Nodes, just like we do for
non-Nodes.

Reviewed By: sriramramani

Differential Revision:
D3660610
Ninja: Sandcastle is broken. 25 denizens of the Facebook republic are affected by this unrelated issue today.
2016-12-19 13:40:31 -08:00
Ahmed El-Helw 7cc4e0364a Fix ARTSurfaceView with Nodes
Summary: ARTSurfaceView wasn't working for Nodes. This patch fixes it.

Differential Revision: D3653522
2016-12-19 13:40:30 -08:00
Seth Kirby 28654aef65 Remove logical adjustments from FlatViewGroup.
Summary: These were needed until recent changes in DrawView.

Reviewed By: ahmedre

Differential Revision: D3646707
2016-12-19 13:40:30 -08:00
Seth Kirby dfc815cb19 Rework clipPath for thread safety.
Summary: Caught a couple potential issues when digging around in DrawView.

Reviewed By: ahmedre

Differential Revision: D3646718
2016-12-19 13:40:30 -08:00
Seth Kirby e96f6fa585 Add directional clipping command manager.
Summary: Add directional aware clipping to DrawCommandManager.  Currently not attached to FlatViewGroup logic, with the plan to keep this unattached until we are clipping the way we want to in the final state.

Reviewed By: ahmedre

Differential Revision: D3622253
2016-12-19 13:40:30 -08:00
Ahmed El-Helw f850e61fdb Fix content:// uris not loading in Nodes
Summary:
In Ads Manager, images weren't loading when they were using
content:// as their uri.

Differential Revision: D3645303
2016-12-19 13:40:30 -08:00
Ahmed El-Helw 2f7da48813 Nodes should support loading file:/// uris
Summary: Non-Nodes supports file:///, and Nodes should too.

Differential Revision: D3639675
2016-12-19 13:40:30 -08:00
Seth Kirby 1d034cf91d Delay dropping root views until the drop views step of StateBuilder.
Summary: @public Make UIOperation public so that custom implementations can expose instances of it.

Reviewed By: ahmedre

Differential Revision: D3618197
2016-12-19 13:40:30 -08:00
Ahmed El-Helw 45e626a887 Default Nodes text color to black
Summary:
Nodes' default text color was NaN, which ended up being white on some
devices.

Differential Revision: D3638348
2016-12-19 13:40:30 -08:00
Ahmed El-Helw 2d8cbd70bc Support rounded clipping
Summary:
Support rounded clipping in Nodes. Before, if a view had
a radius and had overflow of hidden, its children could still draw
outside of it (specifically, in the area between the rounded rect
and square rect) - this is due to the fact that clipping is, by
default, rectangular. This patch supports this type of rounded
clipping.

Differential Revision: D3634861
2016-12-19 13:40:30 -08:00
Seth Kirby 498fc63952 Add position information for DrawViews.
Summary: Previously, we had no information about the positioning of the view until after we had attached it.  We have the position information attached to the shadow node, but this attaches it to the DrawView as well.  It also removes the need for AbstractClippingDrawCommand.

Reviewed By: ahmedre

Differential Revision: D3609092
2016-12-19 13:40:30 -08:00
Mengjue Wang ba56043715 Change the textalign setter to support RTL
Summary: @public Change the textalign setter to support RTL. In order to support text alignment according to layout style, move the textalign setter bridge function from ReactTextViewManager.java to ReactTextShadowNode.java and calculate it correctly on RCTTextUpdate.

Reviewed By: dmmiller

Differential Revision: D3597494
2016-12-19 13:40:30 -08:00
Ahmed El-Helw b8313b282b Fix ViewPager behavior with Nodes
Summary: @public Add a batch addition operation for ViewPager.

Differential Revision: D3597840
2016-12-19 13:40:29 -08:00
Ahmed El-Helw 520f70bd57 Fix measureInWindow for view-backed Nodes
Summary:
This patch fixes measureInWindow for Nodes backed by Views.
Whereas the intention was to call the super implementation when we have a
Node backed by a View, we instead called the super implementation of
measure, which doesn't measure relative to window.

Differential Revision: D3607890
2016-12-19 13:40:29 -08:00
Seth Kirby 690368fc3f Warm text cache.
Summary:
Testing impact of warming text, which shows big wins for other teams, notably Instagram.

https://our.intern.facebook.com/intern/dex/comments-rendering-in-instagram-android/

Reviewed By: ahmedre

Differential Revision: D3603846
2016-12-19 13:40:29 -08:00
Seth Kirby da8ec6fee6 Refactor FlatViewGroup to use DrawCommandManagers.
Summary: Rework FlatViewGroup to more easily transition into more complex draw command managers.

Reviewed By: ahmedre

Differential Revision: D3536262
2016-12-19 13:40:29 -08:00
Seth Kirby a848ce8efd Fix race conditions in DrawView.
Summary:
Currently we have race conditions in DrawView related to isViewGroupClipped, where we create a copy of the DrawView before we update the clipping state, and think the view is unclipped in the next iteration.

Also we are sometimes creating a DrawView with a reactTag of 0.

This fixes both, and is part of the upcoming DrawView bounds change, but is a separate issue that is live in current source.

Reviewed By: ahmedre

Differential Revision: D3598499
2016-12-19 13:40:29 -08:00
Dave Miller 72e665abb4 Set Event timestamp internally
Summary:
@public
This is pure cleanup so that we can make sure that all events are living in the same time space (currently nano seconds).

Reviewed By: foghina

Differential Revision: D3593884
2016-12-19 13:40:29 -08:00
Seth Kirby 8564fc074b Temporary low risk workaround for killing image network requests in rnfeed.
Summary:
View the comment thread for discussion:

https://www.facebook.com/groups/1505872839725322/permalink/1630102823968989

Our current behaviour of add then immediately remove if a view is clipped pretty much guarantees that we kill network requests for images in feed.  We have a better fix for that in the pipeline, but this is a low risk fix in the meantime.

Reviewed By: ahmedre

Differential Revision: D3597785
2016-12-19 13:40:29 -08:00
Mengjue Wang 70fb45393e Provide I18n Module in OSS 3/3
Summary: @public expose context for I18nManagerModule and I18nUtil

Reviewed By: dmmiller

Differential Revision: D3575706
2016-12-19 13:40:29 -08:00
Adam Comella da8759c610 Android: Fix handling of line height with inline images
Summary:
This PR was split from a commit originally in #8619. /cc dmmiller

When an inline image was larger than the specified line height,
the image would be clipped. This changes the behavior so
that the line height is changed to make room for the inline
image. This is consistent with the behavior of RN for iOS.

Here's how the change works.

ReactTextView now receives its line height from the layout thread
rather than directly from JavaScript.

The reason is that the layout thread may pick a different line height.
In the case that the tallest inline image is larger than the line
height supplied by JavaScript, we want to use that image's height as
the line height rather than the supplied line height.

Also fixed a bug where the image, which is supposed to be baseline
aligned, would be positioned at the wrong y location. To fix this,
we use `y` (the baseline) in the `draw` method rather than trying
to calculate the baseline from `bottom`. For more information
see https://code.google.com/p/andro
Closes https://github.com/facebook/react-native/pull/8907

Differential Revision: D3592781

Pulled By: dmmiller
2016-12-19 13:40:29 -08:00
Ahmed El-Helw d89e7475fb Redbox on DrawImageWithDrawee exception
Summary:
DrawImageWithDrawee has caused NPEs when using Nodes in various cases
in RNFeed. This patch explicitly throws a RuntimeException, so that we can
debug as to whether this is coming from bad sources or a bad size for the
image.

Differential Revision: D3574998
2016-12-19 13:40:29 -08:00
Seth Kirby bb5ba3d295 Test perf impact of most straightforward fix for double detach.
Summary: This is the most straightforward fix for the double detach issue.  If a view is not attached, then addViewInLayout never propagates onAttach, and adding through attachViewToParent is a no op.  We could hack something in to attach clipped FlatViewGroups in onClippingRect, but any other view that relies on onAttachedToWindow will have similar issues.

Reviewed By: ahmedre

Differential Revision: D3560565
2016-12-19 13:40:28 -08:00
Seth Kirby 95ae936aa6 Fix for ViewManager commands being run before view updates.
Summary: Since Nodes' manageChildren doesn't enqueue the child updates immediately, commands were being directed to non-updated views.  Previously we applied updates for the shadow node before dispatching the command, but we can instead wait to fire commands until after we update the view hierarchy.

Reviewed By: ahmedre

Differential Revision: D3568541
2016-12-19 13:40:28 -08:00
Seth Kirby 7df627f9be Add support for show layout bounds.
Summary: Supports show layout bounds either by override within FlatViewGroup, or if show layout bounds is set in settings.  Currently requires app restart to disable.

Reviewed By: ahmedre

Differential Revision: D3553669
2016-12-19 13:40:28 -08:00
Seth Kirby 76c2904d31 Add support for WRAP_CONTENT to react views.
Summary: Fixes needing to specify exact height of react views in Mason.  Uses a ViewTreeObserver to delay draw until we have correct bounds.

Reviewed By: sriramramani

Differential Revision: D3527122
2016-12-19 13:40:28 -08:00
Seth Kirby 6cc6cd4d44 Add removed super.dispatchDraw call in FlatViewGroup.
Summary: Accidentally pulled this when fixing comment positioning.  Re-adding now.

Reviewed By: ahmedre

Differential Revision: D3547553
2016-12-19 13:40:28 -08:00
Ahmed El-Helw b300c1979c Support TextDecorationLine in Nodes
Summary:
Nodes wasn't supporting text decorations to the line (strike through
and underline). This patch implements that.

Differential Revision: D3512711
2016-12-19 13:40:28 -08:00
Seth Kirby e674185ea1 Fix a bug with comment box positioning.
Summary: We do want to only apply updates when a view previously wasn't mounted and didn't have a backing view created.  Previously we were applying updates to the view regardless of the mount state, which resulted in positioning bugs.  Rather than revert, I cleaned up the code Ahmed fixed, since didUpdate || ensureBackingViewIsCreated() was both a bug and obscure, as the two should have a swapped order.

Reviewed By: sriramramani

Differential Revision: D3538734
2016-12-19 13:40:28 -08:00
Dave Miller 7562f9d6f5 Fix padding with Text on Android
Summary:
@public
Text was not correctly respecting padding.  We would account for it when measuring, but then not actually apply the padding to the text.  This adds support for proper padding

Reviewed By: andreicoman11

Differential Revision: D3516692
2016-12-19 13:40:28 -08:00
Ahmed El-Helw 87eb779eea Fix commands not always going through with Nodes
Summary:
Previously, to fix the issue of commands happening before the Views
were made and attached to the hierarchy, a check was added to see if a node
had not been mounted to a View, to update its hierarchy. In reality, we need
to do this irrespective, since a node could be mounted to a View, but its
children may not yet be attached, for example. Note that if there is nothing
to be done, this won't do extra work (i.e. applyUpdates recursively goes
through the tree from the node on which we did the operation to apply updates,
but if there are no updates, we stop traversing that praticular subtree).

Reviewed By: sriramramani

Differential Revision: D3511462
2016-12-19 13:40:28 -08:00
Ahmed El-Helw 4622532ca4 Fix TextInput Spannable flags
Summary:
The TextInput spannables are being set wrong by Nodes. Consequently,
when you hit space after a word, anything you type is highlighted, though it
shouldn't be.

Differential Revision: D3507516
2016-12-19 13:40:28 -08:00
Felix Oghina 1b77f1a372 extract MultiSourceHelper
Reviewed By: andreicoman11

Differential Revision: D3505224
2016-12-19 13:40:28 -08:00
Ahmed El-Helw 9a28701bd8 Fix measureInWindow when using Nodes
Summary:
The results from measureInWindow were always wrong the first time it
was called. This was due to the fact that the view in question was not
actually a view yet, so the results were incorrect. This patch uses the
existing measure functionality (which can measure virtual nodes) to measure
the view, while modifying it to properly get the results relative to the
window instead of relative to the root view.

Reviewed By: sriramramani

Differential Revision: D3501544
2016-12-19 13:40:28 -08:00
Andy Street ace1b4d78e Start creating views before end of batch for nodes
Summary:
Depends on D3120798
Depends on D3120631

Enables D3120631 for nodes. This implementation seems to work but let me know if I'm doing something really stupid.

Reviewed By: ahmedre

Differential Revision: D3120814
2016-12-19 13:40:27 -08:00
Ahmed El-Helw f8d623ca3a Fix modals when using Nodes
Summary:
Modals were broken in Nodes, because the custom measurement logic for
all the children of the ReactModalShadowNode was not being applied (because we
wrapped it in a NativeViewWrapper). This change adds a custom flat node type
for modals.

Differential Revision: D3499557
2016-12-19 13:40:27 -08:00
Ahmed El-Helw aadf4dfdc2 Fix DrawImageWithPipeline for Nodes
Summary:
Fix DrawImageWithPipeline's code for checking whether or not an image
request exists or not to be the same as DrawImageWithDrawee's.

Differential Revision: D3489532
2016-12-19 13:40:27 -08:00
Seth Kirby 298a3f947b Remove unnecessary view mounting when views are clipped.
Summary: Reduced view attaching by 93% in mountViews.

Reviewed By: ahmedre

Differential Revision: D3477555
2016-12-19 13:40:27 -08:00
Ahmed El-Helw e5c81e1c1b Fix a Nodes crash when removing children
Summary:
In manageChildren, we were assuming that the indices that
were passed in to be removed were sorted, however, they weren't.
This patch sorts the children to be removed. Note that it doesn't
explicitly sort move, since these are sorted by the MoveProxy class.

Reviewed By: astreet

Differential Revision: D3474639
2016-12-19 13:40:27 -08:00
Ahmed El-Helw f602640e5c Allow for customization of the RootViewManager
Summary:
Groups encountered a pretty major crash where, in many cases,
we would find that DrawCommands and Views were out of sync. This
turns out to be due to the fact that when we drop views from the
root view, we remove each child using removeChildAt (which ultimately
causes an invalidate and redraw). If this happens for a
FlatViewGroup, this causes issues where the Views are all removed,
but there are some DrawCommands (potentially DrawViews) that aren't
removed, hence them going out of sync.

Reviewed By: astreet

Differential Revision: D3473916
2016-12-19 13:40:27 -08:00
Ahmed El-Helw f223335dae Fix measure callback for TextInput on Nodes
Summary: @public Add a MeasureUtil class

Reviewed By: emilsjolander

Differential Revision: D3467598
2016-12-19 13:40:27 -08:00
Seth Kirby 88dfd75aa7 Clip all views when removing clipping subviews, rather than just FlatViewGroup views.
Summary: Currently only FlatViewGroup children were clipped, rather than all offscreen Android views.

Reviewed By: ahmedre

Differential Revision: D3462002
2016-12-19 13:40:27 -08:00
Ahmed El-Helw 241fd0869d Fix autoFocus for TextInput
Summary:
During the patch for fixing the order of UI operations, we apply
updates to any node receiving a ViewManager command in order to ensure that
nodes that were not yet mounted to a View and not yet attached to their parent
would be properly able to receive the event. However, if a node is already a
view, calling the update could cause unwanted things to happen (for example,
the View's bounds changing improperly), because we're only traversing that
node of the tree and down (instead of the entire tree). This fixes the issue
by only applying updates to the node if the view mount state has changed.

Reviewed By: sriramramani

Differential Revision: D3448356
2016-12-19 13:40:27 -08:00
Ahmed El-Helw f0734c141f Fix Nodes crash when text is not spanned
Summary:
A Layout's text can either be an Ellipsizer or a SpannedEllipsizer.
SpannedEllipsizer implements Spannable, but Ellipsizer doesn't. We were
casting the Layout's text directly to a Spanned without first checking as to
whether or not it was actually a Spanned.

Reviewed By: sriramramani

Differential Revision: D3435075
2016-12-19 13:40:27 -08:00
Andrei Coman fc622504de Show low res image if available in cache
Summary: Nodes version of D3392751.

Reviewed By: ahmedre

Differential Revision: D3425740
2016-12-19 13:40:27 -08:00
Andrei Coman c61aafe95d Support multiple sources
Summary:
The nodes version of D3364550. The only difference is that here we
don't get `onSizeChanged` but `onBoundsChanged`, and we need to compute the
height/width of the target image from those bounds. ahmedre please let me know
if any of these assumptions are in any way incorrect.

Reviewed By: ahmedre

Differential Revision: D3424843
2016-12-19 13:40:27 -08:00
Andrei Coman f2a6570b07 Refactor nodes to lazy-load image from source
Summary:
This is needed for the upcoming loading from multiple sources (D3364550 for the non-nodes version) and cache interrogation (D3392751 for non-nodes version).
This postpones creating the DraweeRequestHelper until the image size is known, which in the nodes universe is when `onBoundsChanged` is called.

Reviewed By: foghina, ahmedre

Differential Revision: D3413467
2016-12-19 13:40:26 -08:00
Ahmed El-Helw 4ecfa0c800 Fix touch inspector when using Nodes
Summary:
Fix touch inspector when using Nodes by implementing custom logic.
This logic now takes into account that non-View nodes need to be clickable.

Reviewed By: astreet

Differential Revision: D3433927
2016-12-19 13:40:26 -08:00
Emil Sjolander 5f3f9caceb Refactor RCTText to take advantage of learnings from components
Summary:
Made some improvements to RCTText based on some of our learnings from components for android. This now resembles diffusion/FBS/browse/master/fbandroid/java/com/facebook/components/widget/TextSpec.java

Things that have improved:
- Calculation of text width is now faster (we noticed in components that .getWith() on the layout is all that is needed and it is much faster)
- Use text layout builder to abstract away a lot of the low level details of static / boring layouts and text measurements
- Handle MeasureMode correctly, previously AT_MOST was not supported.
- Better handling of RTL text by using TextLayoutBuilder where I made changes to support RTL text in components. Specifically RTL text measured with UNSPECIFIED or AT_MOST.
- There was an incorrect assumption being made that when measure() was not called the text had to be boring. This is incorrect, Arabic text is never boring for example. Also multiline text is not boring either and may have exact sizing.

Reviewed By: ahmedre

Differential Revision: D3374752
2016-12-19 13:40:26 -08:00
Ahmed El-Helw 754d2848a4 Fix dispatchViewManagerCommand ordering for Nodes
Summary:
The dispatchViewManager command should, according to the spec, only
be executed after children are added. On Nodes, however, due to the fact that
the Views in question may not have been created until the call to the command
occurred, the dispatchViewManagerCommand may occur too early. Consequently,
ensure that we apply any state updates to the Node represented by that
reactTag before we enqueue the view manager command (this will ensure that
views are properly added to the parent, etc before sending the command).

Reviewed By: astreet

Differential Revision: D3428855
2016-12-19 13:40:26 -08:00
Andrei Coman 65f4988ddf Support multi sources for images
Summary:
@public
This adds support for specifying multiple sources for an image component, so that native can choose the best one based on the flexbox-computed size of the image.
The API is as follows: the image component receives in the `source` prop an array of objects of the type `{uri, width, height}`. On the native side, the native component will wait for the layout pass to receive the width and height of the image, and then parse the array to find the best fitting one. For now, this does not support local resources, but it will be added soon.
To see how this works and play with it, there's an example called `MultipleSourcesExample` under `ImageExample` In UIExplorer.

Reviewed By: foghina

Differential Revision: D3364550
2016-12-19 13:40:26 -08:00
Ahmed El-Helw e1ece03593 Improve removeClippedSubviews for overflowing views
Summary:
Historically, removeClippedSubviews for Nodes would not clip views
that overflowed their parent. This patch changes that, so that Nodes can
properly clip views when they are off screen (even if they have descendants
that overflow the bounds of their parent).

This is done by calculating a set of offsets from the actual width and
height of the view, and using those in the clipping calculations.

Reviewed By: sriramramani

Differential Revision: D3409859
2016-12-19 13:40:26 -08:00
Ahmed El-Helw 4bb33f93cd Promote grandchildren of certain views are Views
Summary:
As an optimization, for something like a ScrollView which contains
a FlatViewGroup containing posts, make sure that each post is explicitly
mounted to a View. This may help improve performance, especially when said
Views are otherwise inlined as DrawCommands instead of actual Views.

Reviewed By: astreet

Differential Revision: D3161232
2016-12-19 13:40:26 -08:00
Andrei Coman 0adc390a19 Align inline image in nodes text
Summary:
This is similar to https://github.com/facebook/react-native/pull/6528
for the non-nodes inline images.

Reviewed By: dmmiller

Differential Revision: D3358530
2016-12-19 13:40:26 -08:00
Ahmed El-Helw efb65e5665 Fix leak in Nodes due to removeClippedSubviews
Summary:
The removeClippedSubviews optimization often detaches views while
maintaining strong references to them (so they can be attached again later
on). However, when removing the parent view, any detached views end up not
being cleaned up or removed, thus leaking memory. This fixes this by
explicitly dropping detached views when the parent is removed.

Reviewed By: astreet

Differential Revision: D3337513
2016-12-19 13:40:26 -08:00
Ahmed El-Helw c62840c7a8 RCTVirtualText wasn't clickable in certain cases
Summary:
Text in Nodes is squashed into a single DrawCommand for drawing a
Boring or StaticLayout. Touch is handled using a TextNodeRegion subclass of
NodeRegion that knows how to identify pieces of text inside of the DrawCommand
based on spans in the text. However, we only use a TextNodeRegion on the
second call for updateNodeRegion for an RCTText. If there is only one call,
the NodeRegion will just be a normal one. This patch ensures that the
NodeRegion for an RCTText is always a TextNodeRegion, allowing for null
Layouts that are set when the DrawCommand is made.

Reviewed By: astreet

Differential Revision: D3291682
2016-12-19 13:40:26 -08:00
Ahmed El-Helw 9d67989001 Don't clip overflowing Nodes
Summary:
As of D3235050, Nodes supports the optimization of removing clipped
subviews from the hierarchy. However, because Nodes supports overflow:visible,
this could cause issues when DrawCommands overflow the bounds of their parent
container. This patch fixes this by not clipping any overflowing Nodes.

Reviewed By: astreet

Differential Revision: D3235072
2016-12-19 13:40:26 -08:00
Ahmed El-Helw 5f162ca119 Implement RemoveClippedSubviews for Nodes
Summary:
RN has an optimization in which a ScrollView (or similar ViewGroups)
can ask to remove clipped subviews from the View hierarchy. This patch
implements this optimization for Nodes, but instead of adding and removing the
Views, it attaches and detaches Views instead.

Note that this patch does not handle overflow: visible. This is addressed in a
stacked patch on top of this patch (to simplify the review process).

Reviewed By: astreet

Differential Revision: D3235050
2016-12-19 13:40:25 -08:00
Ahmed El-Helw 96cb8165c8 Fix setJSResponder Nodes crash
Summary:
Nodes crashed when setJSResponder was called on a virtual (non-View)
node, because a View could not be found using that react tag. The solution is
two fold - first, to figure out the View parent and pass that to
setJSResponder in addition to that of the virtual tag. Secondly, we weren't
mounting views that had animation properties (transform, for example) to
Views, which caused related code to fail.

Reviewed By: sriramramani

Differential Revision: D3301310
2016-12-19 13:40:25 -08:00
Ahmed El-Helw 273c2e539c Improves RCTImage loading handlers to mimic iOS behavior
Summary: This is a port of D3283011 to Nodes.

Reviewed By: sahrens

Differential Revision: D3290662
2016-12-19 13:40:25 -08:00
Dave Miller fede138786 Add setChildren to FlatUIImplementation
Summary: Add support in FlatUIImplementation for the setChildren call added in D3235369

Reviewed By: astreet

Differential Revision: D3240883
2016-12-19 13:40:25 -08:00
Ahmed El-Helw 0d21baf604 Don't save matrix when using canvas.save
Summary:
Canvas.save by default saves both the matrix (for translations,
scaling, etc) and the clip (clipRect) - in most of our cases, we really only
care to save and restore the clip, not the matrix.

Reviewed By: sriramramani

Differential Revision: D3235698
2016-12-19 13:40:25 -08:00
Emil Sjolander 118cc4b9b7 Import css-layout measure mode changes from pull request #163
Summary: See https://github.com/facebook/css-layout/pull/163

Reviewed By: lucasr

Differential Revision: D3167760
2016-12-19 13:40:25 -08:00
Emil Sjolander cd06228f7a backout update of css-layout. breaks ios <9
Summary: Backed out changeset 29fa5aef3dbcc12d63c01d211b32bb598caadd0d and 56cc13ffbc4805aa0789df62a04e19f23a438bd3.

Reviewed By: javache

Differential Revision: D3164127
2016-12-19 13:40:25 -08:00
Ahmed El-Helw 72eb547f22 Cleanup React comments and unused imports
Summary: @public Fix some typos in comments.

Reviewed By: astreet

Differential Revision: D3161278
2016-12-19 13:40:25 -08:00
Ahmed El-Helw a099869edd Don't intercept touch for Nodes after down event
Summary:
With nodes, it's possible for a touchable region to not be
explicitly mounted to a View. To work around this (and allow the region to
be the handler of the touch event), FlatViewGroup intercepts touch events
when the touch lies within any of the virtual NodeRegions.

This can sometimes be wrong - the canonical example is when touch starts
outside of a particular FlatViewGroup (so someone else, for example a
sibling) intercepts the touch event, and then the person moves over a
different FlatViewGroup, causing it to intercept the touch event when it
shouldn't. To fix this, we only allow intercepting touch events due to
NodeRegions on the down event.

Reviewed By: astreet

Differential Revision: D3160152
2016-12-19 13:40:25 -08:00
Ahmed El-Helw cbf195e165 Do less work in Nodes when clipping isn't needed
Summary:
By default, Nodes causes views to not be clipped, unless overflow is
explicitly set to hidden. Consequently, Nodes sets all the clipping bounds to
negative infinity, and does some extra work (saving the canvas layer,
clipping, etc) before drawing. This optimization skips the extra work when
it's not needed.

Reviewed By: sriramramani

Differential Revision: D3161268
2016-12-19 13:40:25 -08:00
Ahmed El-Helw 5d6e73d0eb Don't mount nodes to Views on click
Summary:
Initially, we used to mount nodes to Views anytime a node was
clicked. This was not useful, since we could still not handle touch when
a touch event was already dispatched. Later, a fix was pushed that
supported handling touch events for non-View NodeRegions. Part of the
intention was to remove this code, but it was forgotten.

Reviewed By: sriramramani

Differential Revision: D3160532
2016-12-19 13:40:25 -08:00
Emil Sjolander c1474cc671 Import css-layout measure mode changes from pull request #163
Summary: See https://github.com/facebook/css-layout/pull/163

Reviewed By: astreet

Differential Revision: D3059432
2016-12-19 13:40:24 -08:00
Emil Sjolander 7a31ca29a4 Migrate text layout code to use TextDirectionHeuristicCompat instead of forceLTR flag
Summary: This allows users of the API to have greater control over handling RTL. One example is Components which needs this greater control to correctly handle RTL.

Differential Revision: D3120721
2016-12-19 13:40:24 -08:00
Denis Koroskin f4690ef8de Make sure UIImplementation methods that touch native View has the Views created
Summary:
UIImplementation has a few methods that in the end touch native Views, such as dispatchViewManagerCommand, addAnimation, sendAccessibilityEvent etc. There are 2 cases where it is possible to have those methods called on shadow nodes that don't have backing Views created:
- backing view is scheduled to be created but not commited yet (StateBuilder accumulates createView commands into a queue and flushes it in the very end)
- shadow node doesn't mount to a View so there is no backing View

Touching View in UI thread in these 2 cases will either lead to silent error (e.g. failure callback will execute), or a native crash.

This diff is overriding all UIImplementation methods that touch Views in UI thread and makes sure that backing View is created before we do so.

Reviewed By: ahmedre

Differential Revision: D3046392
2016-12-19 13:40:24 -08:00
Denis Koroskin 68580fcab6 Fix RCTText crashing when negative width is passed to measure
Summary: In some rare cases, RCTText.measure can receive negative width which will crash with an assertion in android.text.Layout because it expects a positive value. This is a temporary fix to treat negative values as unconstrained width until the original bug is fixed.

Reviewed By: sriramramani

Differential Revision: D3038767
2016-12-19 13:40:24 -08:00