Commit Graph

1528 Commits

Author SHA1 Message Date
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
Ahmed El-Helw aa609a46ad Revert nodes touch workaround
Summary:
Since we now have the correct fix in place, this patch is to revert
the hack we put in place to not be launch blocking.

Reviewed By: sriramramani

Differential Revision: D3019883
2016-12-19 13:40:24 -08:00
Denis Koroskin 89cf5c49b9 Make FlatViewGroup implement ReactCompoundViewGroup interface
Summary: In FlatViewGroup, we flatten some react nodes into parent while mounting others into child Views. This is causing touch events being dispatched to wrong targets because child Views are \"stealing\" touch events from flattened Views. To fix the issue, implement ReactCompoundViewGroup to provide information about both virtual and non-virtual nodes.

Reviewed By: ahmedre

Differential Revision: D3018054
2016-12-19 13:40:24 -08:00
Denis Koroskin b52928c484 Include non-virtual nodes when collecting NodeRegions
Summary: Before this patch, we only collected virtual nodes in NodeRegions, because NodeRegions are only needed to implement ReactCompoundView.reactTargetForTouch() which is only interested in virtual nodes. In the next patch, FlatViewGroup will implement ReactCompoundViewGroup interface which requires knowledge of both virtual and non-virtual children. As a step towards that, we need to include non-virtual nodes in NodeRegions. This patch is implementing that. By itself, it should have not cause any changes in application behavior: we add non-virtual nodes to NodeRegions and mark them as non-virtual, then skip all non-virtual nodes in reactTagForTouch().

Reviewed By: ahmedre

Differential Revision: D3018047
2016-12-19 13:40:24 -08:00
Denis Koroskin 8014147013 Fix order of NodeRegions
Summary: Before the patch, order of NodeRegions was inconsistent. Given parent A and 3 children B, C and D, we collect DrawCommands like this: A, B, C, D but NodeRegions were collected as B, C, D, A which neither matches draw order, nor a reverse of it. This patch changes it so that NodeRegions are collected in drawing order (A, B, C, D) and we iterate backwards to find correct touch target (in case they overlap).

Reviewed By: ahmedre

Differential Revision: D3018034
2016-12-19 13:40:24 -08:00
Ahmed El-Helw 4d25624a62 Work around nodes touch bug for Groups
Summary:
This is a hack to fix the Groups dialog bug so that we can get some
real data in production from using Nodes. This should be replaced with a
better solution in the near future.

Differential Revision: D3016859
2016-12-19 13:40:24 -08:00
Denis Koroskin c75f3b7d9f Make sure we call notifyChanged(true) when a child is added to RCTVirtualText
Summary: CSSNode.addChildAt() calls dirty() to invalidate the node and propagate dirty flag up to the root. However, ReactShadowNode overrides dirty() for virtual nodes so it does nothing. This results in bugs where an added text doesn't trigger a measure pass because RCTText is never dirtied. To fix the bug, override addChildAt() in RCTVirtualText and explicitly call notifyChanged(true) to make sure hosting RCTText is dirtied and re-measured/re-laid out.

Reviewed By: ahmedre

Differential Revision: D3016827
2016-12-19 13:40:24 -08:00
Ahmed El-Helw 272d99ed56 Revert workaround for Nodes detach
Summary:
This code reverts D3004541, since it fixes the symptom instead
of the root cause. Root cause fix is in D3011191.

Differential Revision: D3011291
2016-12-19 13:40:24 -08:00
Ahmed El-Helw 1a4d40df6c Fix commit order of operations in Nodes
Summary: @public Split dispatchViewUpdates into two methods, which enables subclasses to commit pending ui operations, even when no root node is present.

Differential Revision: D3011191
2016-12-19 13:40:23 -08:00
Ahmed El-Helw a541384621 Simplify width calculation in RCTText
Summary:
getLayoutWidth is the same as right - left, and since we have right
and left, we can save a method call.

Reviewed By: sriramramani

Differential Revision: D3010697
2016-12-19 13:40:23 -08:00
Ahmed El-Helw 9498f22439 Use layout width for BoringLayout in Nodes
Summary:
In D2980358, alignment was implemented for nodes. This unfortunately
introduced a bug, which is that when we have a BoringLayout that is set to
ALIGN_CENTER, it can't be seen. This is a result of the fact that the width
passed in to BoringLayout is Integer.MAX_VALUE. Since measure has already
been called at this point, we can just pass the layout's width as the width
of the BoringLayout.

Reviewed By: sriramramani

Differential Revision: D3004971
2016-12-19 13:40:23 -08:00
Ahmed El-Helw 45472fe400 Fix detaching dropped views in Nodes
Summary:
Groups had a crash when running with React with Nodes when returning
from a search screen. This was due to the fact that the node representing a
ShimmerFrameLayout was being dropped, and then later we were trying to detach
it. Since the view was already dropped, we shouldn't try to detach it since
it's already dropped and removed from the view hierarchy.

Reviewed By: sriramramani

Differential Revision: D3004541
2016-12-19 13:40:23 -08:00
Denis Koroskin 0b560d3d3d Don't try to remove Views that about to be removed with the root View
Summary:
We keep a list of FlatShadowNodes that mount to Views that we want to delete, and only flush it at the end of an update cycle. This results in a situation where a root view is being removed before children are removed, which results in a crash in NativeViewHierarchyManager because a View that we are trying to remove no longer exists. There are a few approaches to fix the issue:
a) make a check if a View exists before removing it. While works, it removes a bug protection when we erroneously trying to remove a View that no longer exists (such as this). I'd prefer to keep the check in place
b) flush the views-to-drop queue. This works, but does some extra work in UI thread (namely, removing Views that would be removed anyway)
c) trim the views-to-drop queue to remove any Views that will be removed anyway. This does a tiny bit of extra work in BG thread, but less work in UI thread.

This diff implements option c).

Reviewed By: ahmedre

Differential Revision: D2990105
2016-12-19 13:40:23 -08:00
Ahmed El-Helw 75117fc91a Minor code improvements for RCTTextInput
Summary: @public Expose hasUnseenUpdates in ReactShadowNode. Various text input cleanup and fixes.

Differential Revision: D2975870
2016-12-19 13:40:23 -08:00
Ahmed El-Helw df382e986c Implement alignment for nodes Text
Summary: Alignment wasn't implemented for Text, this patch supports it.

Differential Revision: D2980358
2016-12-19 13:40:23 -08:00
Denis Koroskin 848bae2e95 Fix FlatUIImplementation.manageChildren() failing when moveFrom is not sorted
Summary:
Code in FlatUIImplementation.manageChildren() incorrectly assumed that moveFrom is sorted and moveTo is not, which is actually reverse: moveFrom is not sorted, and moveTo is. This means that we need to sort moveFrom before we can traverse it, and that we no longer need to sort moveTo (we did it by moving nodes to mNodesToMove first and then sorting it).

The sorting algorithm used is borrowed from Android implementation of insertion sort used in DualPivotQuicksort.doSort() when number of elements < INSERTION_SORT_THRESHOLD(32) which is 99.999% the case in UIImplementation.manageChildren() (most of the time this array is either empty or only contains 1 element).

Another (very rare) bug this is fixing is that the code only worked for FlatShadowNodes, but not all shadow nodes are FlatShadowNodes (there are rare exceptions, such as ARTShape, ARTGroup etc). New code works with all types of shadow nodes.

Reviewed By: ahmedre

Differential Revision: D2975787
2016-12-19 13:40:23 -08:00
Denis Koroskin 42fb9a3d91 Only collect state from nodes that have been updated
Summary: We are currently traversing entire tree every time there is any update to any of the nodes, which is hugely inefficient. Instead, we can early out for nodes that are known to contain no updates. This saves a lof of CPU. This optimization can be turned off, and an Exception will be thrown if there was an unexpected update.

Reviewed By: ahmedre

Differential Revision: D2975706
2016-12-19 13:40:23 -08:00