Commit Graph

1760 Commits

Author SHA1 Message Date
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
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
Ahmed El-Helw 7055c52288 Fix screenshot tests for React with nodes
Summary:
Fix screenshot tests for React with nodes. It was broken due to
calling clipRect with bounds of [-∞, ∞], which, due to a bug in Canvas that
appeared in screenshot tests, caused the view not to draw. Since this is a
no-op anyway, this patch just doesn't call clipRect when we have infinite
bounds.

Differential Revision: D2975494
2016-12-19 13:40:23 -08:00
Denis Koroskin b9e3ef2d5f Add @Nullable annotation to FlatShadowNode.obtainLayoutEvent()
Summary: Lint tool raised a warning. This diff is fixing it.

Reviewed By: sriramramani

Differential Revision: D2977649
2016-12-19 13:40:23 -08:00
Denis Koroskin ca7a3519cf Store \"dirty\" and \"dirty descendant\" flags in every node instead of only marking root node as invalid
Summary: Right now invalidate always tell the root node that the tree is dirty, and next update will traverse the entire tree in search of changes. While this works correctly, it's not the most efficient implementation. It is more efficient to store dirty flag in every node, and skip entire subtrees if this node and all descendants are already up to date. This diff is a first step towards that optimization.

Reviewed By: ahmedre

Differential Revision: D2955197
2016-12-19 13:40:22 -08:00
Ahmed El-Helw 4c92a0b962 Support setText in RCTTextInput
Summary:
Examples that use defaultValue as part of their declaration (such as
those examples under UIExplorerApp's TextInput) were being ignored. This patch
supports having text set directly on RCTTextInput and handles it properly.
Note that this patch depends on D2962643 and D2964847, without which the
TextInput example will look wrong.

Differential Revision: D2968002
2016-12-19 13:40:22 -08:00
Denis Koroskin a9c88bce14 Fix 2 bugs in FlatUIImplementation.removeChild()
Summary:
There are 2 issues in removeChild() implementation.

a) There is a chance that a node that we are removing will be mounting to a View, but the create view request has not be created  so there is no backing View for it yet. In that case, FlatNativeViewHierarchyManager.dropView() will throw an Exception failing to find the View. The fix is to only dropView() if one was (requested to be) created.
b) If the shadow node that we are removing doesn't mount to a View, but one or more of its children do, those Views will leak because noone is removing them. The fix is to recursively call removeChild() until we find a node that mounts to a View.

Reviewed By: ahmedre

Differential Revision: D2974938
2016-12-19 13:40:22 -08:00
Denis Koroskin 5305f3b68e Fix OnLayoutEvent dispatching wrong x/y coordinates
Summary:
OnLayoutEvent was incorrectly dispatching x/y coordinates relative to native View instead of relative to parent. This was causing issues in many cases, such as when Node was mounting to a View, in which case x/y would always be 0. This diff is fixing it.

This diff also caches last OnLayoutEvent to avoid dispatching the event on every layout even when layout didn't chance.

Reviewed By: ahmedre

Differential Revision: D2955087
2016-12-19 13:40:22 -08:00
Denis Koroskin c36d4593fd Revert \"[react-native][nodes] Split StateBuilder.ensureBackingViewIsCreated into 2 different methods\"
Summary: Reverts D2916697 that landed twice.

Differential Revision: D2974199
2016-12-19 13:40:22 -08:00
Ahmed El-Helw 827989f572 Fix TextInput text color not applying
Summary:
Setting the color for a TextInput with nodes was broken. The text color was
not being applied due to an optimization that prevented setting spans if
begin and end were the same (which is the case for an empty TextInput).
This patch depends on D2962643.

Differential Revision: D2962394
2016-12-19 13:40:22 -08:00
Ahmed El-Helw b4100ef246 Fix spannable flags in RCTVirtualText
Summary:
The spannable flags for RCTVirtualText were always being set to
INCLUSIVE_EXCLUSIVE - this is different than the behavior that is found in
ReactTextShadowNode, which sets EXCLUSIVE_INCLUSIVE as the default flag
unless the text is at the beginning.

This is needed to fix various problems with TextInput, including the handling
of empty spans (see also D2962394 which depends on this patch), and making the
behavior consistent when styled children of a TextInput are changed.

Differential Revision: D2962643
2016-12-19 13:40:22 -08:00
Ahmed El-Helw 055b31a165 Implement measure for nodes TextInput
Summary:
Implement measure for RCTTextInput. This is (almost) the same as
the one implemented for ReactTextInputShadowNode.

Differential Revision: D2964847
2016-12-19 13:40:22 -08:00
Denis Koroskin 64e050793e Split StateBuilder.ensureBackingViewIsCreated into 2 different methods
Summary:
There are 2 reasons why someone would call StateBuilder.ensureBackingViewIsCreated():
1) to make sure a View is created, because we are going to use it NOW
2) make sure react styles are applied to View, which doesn't really need the View to be created immediately

This diff is splitting the method into 2, without changing behavior. Difference between the methods' signatures is coming from the fact that 1) never takes styles and 2) possibly takes styles.

This is a pure refactoring diff and should have no change in functionality or behavior.

Reviewed By: ahmedre

Differential Revision: D2916697
2016-12-19 13:40:22 -08:00
Denis Koroskin ada5234b0e Lazily create/update views
Summary:
There is a rare case in React Native when a hierarchy is created and then *immediately* discarded all in one transaction. This is causing a View leak, because a View is created and then never attached to a hierarchy because it shadow node got detached. Since we never attached the View to the hierarchy, we cannot do a detach either and the View is kept in NativeViewHierarchyManager forever, causing a View leak. To fix the issue, don't create a backing View whenever a shadow node mounts to a View. Instead, put the create request into a queue and ONLY execute it if a shadow node is still attached to a hierarchy. This is fixing the View leak because will not create a View unless it's going to be attached somewhere.

The same logic applies to View style update (we don't want to update a View that is going to be detached from a hierarchy).

Reviewed By: ahmedre

Differential Revision: D2916826
2016-12-19 13:40:22 -08:00
Denis Koroskin bb04967986 Split StateBuilder.ensureBackingViewIsCreated into 2 different methods
Summary:
There are 2 reasons why someone would call StateBuilder.ensureBackingViewIsCreated():
1) to make sure a View is created, because we are going to use it NOW
2) make sure react styles are applied to View, which doesn't really need the View to be created immediately

This diff is splitting the method into 2, without changing behavior. Difference between the methods' signatures is coming from the fact that 1) never takes styles and 2) possibly takes styles.

This is a pure refactoring diff and should have no change in functionality or behavior.

Reviewed By: ahmedre

Differential Revision: D2916697
2016-12-19 13:40:22 -08:00
Denis Koroskin 44b6200392 Round ShadowNode layout coordinates to a pixel boundary
Summary:
When layout happens, left/top/right/bottom coordinates (and thus clip-*, too) are sometimes not at a pixel boundary for 2 reasons:
a) width/height in Flexbox are floats, and can contain any value, not just a whole pixel. E.g. style={{width: 3.1415926}} is perfectly valid
b) floating point arithmetics sometimes leads to values barely outside of pixel boundaries (width 18.0f can become 18.000001f when a sibling/child size changes).

a) is \"breaking\" screenshot tests, which slightly but differ from reference implementation
b) causes extra View updates/redraws for no reason

This patch is rounding DrawCommand bounds to a whole pixel to avoid these 2 issues.

Reviewed By: ahmedre

Differential Revision: D2934401
2016-12-19 13:40:22 -08:00
Andrei Coman addd233d31 Use nanoTime instead of currentTimeMillis for events
Summary:
Public
We wanted to do this before, but couldn't because touch events had timestamps
set by the system (and matched System.currentTimeMillis), but now we set those
timestamps! The idea behind this change is that System.currentTimeMillis is
unreliable, but nanoTime isn't, and it also guarantees that we will never have two events with the same
timestamp.
We're still seeing crashes with touch events not ending correctly in JS, this
might be the cause of that.

Reviewed By: foghina

Differential Revision: D2953917
2016-12-19 13:40:21 -08:00
Denis Koroskin 3e30b70e29 Don't pass tag alongside node in StateBuilder methods
Summary:
Many of StateBuilder methods take a lot of arguments, which makes it hard to read. This patch is doing a bit of cleanup by removing tag from the method signatures, because tag can be easily obtained from the node itself.

This is a pure refactoring diff and should have no functional changes.

Reviewed By: ahmedre

Differential Revision: D2915815
2016-12-19 13:40:21 -08:00
Denis Koroskin 3b63d7c3bc Extract rect clipping logic into AbstractClippingDrawCommand
Summary: Both DrawView and AbstractDrawCommand have clipping logic, this diff is moving out logic into a common base class. This also reverts the screenshot tests fix, which was causing issues with overflow: visible.

Reviewed By: ahmedre

Differential Revision: D2933780
2016-12-19 13:40:21 -08:00
Ahmed El-Helw f0535152ab Make AndroidView an interface
Summary:
The current AndroidView stipulates that the backing shadow node can't
be a FlatShadowNode. In some cases, however, we want to apply some of the same
logic (ex not adding NodeRegions, etc) to other ViewManagers that have a
FlatShadowNode backing (and that don't necessarily create a FlatViewGroup).
This commit renames AndroidView to NativeViewWrapper, and re-introduces
AndroidView as an interface, so that logic for padding, NodeRegions, etc can
be shared.

Differential Revision: D2942387
2016-12-19 13:40:21 -08:00
Denis Koroskin b461c70b76 Fix StateBuilder incorrectly casting a child to FlatShadowNode
Summary: Not every CSSNode in a hierarchy is a FlatShadowNode, some virtual nodes can be ReactShadowNodes for compatibility with ART nodes. This diff fixes StateBuilder unconditionally casting a node to FlatShadowNode, which is causing a crash in Groups.

Reviewed By: nickholub

Differential Revision: D2941031
2016-12-19 13:40:21 -08:00
Denis Koroskin d1ccb6d23d Finalize many of FlatShadowNode methods
Summary: These methods (mostly getters/setters) are not meant to be overriden, so let's make them final. Hopefully, they will inline better, too.

Reviewed By: ahmedre

Differential Revision: D2933869
2016-12-19 13:40:21 -08:00
Ahmed El-Helw 99d95d8168 Fix TextInput in React Nodes
Summary:
@public Relax the constraint on ReactTextInputManager.
The TextInput Advanced screen looked different with and without
nodes, namely child Text items were not being rendered on the Nodes version.
This patch fixes that.

Differential Revision: D2930800
2016-12-19 13:40:21 -08:00
Denis Koroskin 253cb8c2b5 Add @Override to FlatUIImplementation.handleCreateView
Summary: FlatUIImplementation.handleCreateView was missing an Override annotation. This diff fixes it.

Reviewed By: sriramramani

Differential Revision: D2919596
2016-12-19 13:40:21 -08:00
Denis Koroskin 8702a75b96 Don't wrap unknown virtual nodes with AndroidView
Summary: Currently, we wrap all unknown shadow nodes with AndroidView. This works great, except when the shadow node is virtual, i.e. it *doesn't* mount to a View. In this case, we just need to keep it in the hierarchy as is. Fixes ARTSurfaceView not working correctly in groups.

Reviewed By: ahmedre

Differential Revision: D2933325
2016-12-19 13:40:21 -08:00
Denis Koroskin 4bff818706 Workaround for a bug in software Canvas that incorrectly computed clip boundaries (fixes screenshot tests)
Summary: Software Canvas uses ints to represents boundaries (because it is backed by Bitmap that has scalar size), whereas Hardware Canvas uses floats to represent boundaries. This results in a bug in Software Canvas where clipping with floats close to or outside of int range results in int overflows and incorrect clipping. To fix the issue, compute the clip boundaries manually instead of using Canvas.clipRect() method (that contains the bug).

Reviewed By: sriramramani

Differential Revision: D2919509
2016-12-19 13:40:21 -08:00
Denis Koroskin 44c814c94d Fix border not drawing when there is a background color set
Summary: There is a bug in border drawing code that will not draw the border if the element has a background color. This diff fixes it.

Reviewed By: sriramramani

Differential Revision: D2919549
2016-12-19 13:40:21 -08:00
Denis Koroskin 0b6436b637 Add support for data: Uri scheme to RCTImageView (e.g. base64-encoded images)
Summary: ImageRequestHelper was not handling data: scheme correctly, which resulted in images failing to load. This diff is fixing it by considering \"data:\" as a Uri resource, and piping it appropriately.

Reviewed By: sriramramani

Differential Revision: D2919403
2016-12-19 13:40:20 -08:00
Denis Koroskin 88ebce0512 Fix RCTImageView always clipping to bounds even if overflow is visible
Summary: Previously, RCTImageView/DrawCommand would always clip for specific scale types (such as CENTER_CROP), but this is incorrect if we want to allow overflow: visible on RCTImageView (which iOS allows). This patch tweaks the clipping condition from paddingLeft/paddingTop < 0 (i.e. image wants to draw outside of its bounds) to actual image rect being outside of clip rect. Previously, that would mean exact same thing, but now that clip rect is aware of overflow: visible, it matters, allowing RCTImage to not clip when we want it to draw outside of the boundaries.

Reviewed By: ahmedre

Differential Revision: D2873350
2016-12-19 13:40:20 -08:00
Denis Koroskin 674e74a963 Only clip node against its own boundaries IFF clipToBounds() is set to true (i.e. overflow is visible)
Summary:
Previously, every node would be clipped by its own boundaries. This made sense, because
a) RCTView cannot draw outside of its bounds, so clipping is harmless
b) all other node types were not allowed to control overflow behavior, and for them overflow was implicitly set to hidden, which means it should clip.

This diff changes the logic so that overflow can be set on any node (image, text, view etc).

The change has an important implication that make the diff a little trickier that it could be: AbstractDrawCommand clipping logic needs to be relaxed. Previously, clip bounds were *always* intersected with node bounds, which means that clip rect was always within node rect. This is no longer true, and thus shouldClip() logic needs to be modified.

Because of the above, RCTText no longer needs to artificially clip bounds against layout width/height.

Note: RCTImage is still not working with overflow: visible correctly (it still always clips). This is fixed in a follow up diff.

Reviewed By: ahmedre

Differential Revision: D2867849
2016-12-19 13:40:20 -08:00
Denis Koroskin 05e8ff1fe0 Remove bogus assert
Summary:
There is an assert in FlatViewGroup.reactTagForTouch() that says that TouchTargetHelper should not allow returning getId() when pointer events are BOX_NONE. This is not entirely accurate.

This acturally method is invoked in 2 different contexts. Main context is to find a touch target, and in that context the method indeed should never return getId() if pointer events are BOX_NONE. There is however a TouchTargetHelper which actually expects that reactTagForTouch() *may* return getId(), in which case it will perform logic to not all this method be invoked again from main context.

In other words, this assert needs to be removed because it is entirely possible to return getId() when pointer events are BOX_NONE. Ideally, these would be 2 different methods, but ReactCompoundView interface only defines a single reactTagForTouch() method.

Reviewed By: ahmedre

Differential Revision: D2873931
2016-12-19 13:40:20 -08:00
Denis Koroskin d9ed1a84c5 Apply padding to RCTText
Summary: When padding is applied to RCTText, the text it renders should be offset by that padding. This is what iOS is doing.

Reviewed By: sriramramani

Differential Revision: D2872039
2016-12-19 13:40:20 -08:00
Ahmed El-Helw d854a17d2a Support fade for remote images in React with nodes.
Summary:
Support fade for DrawImageWithPipeline so that images are faded in
when they are remotely fetched.

Differential Revision: D2804997
2016-12-19 13:40:20 -08:00
Denis Koroskin 74c72111f1 Rename mIsOverflowVisible to a more descriptive mClipToBounds
Summary: A simple refactoring diff that should make code a little easier to read. No functional changes.

Reviewed By: ahmedre

Differential Revision: D2867718
2016-12-19 13:40:20 -08:00
Denis Koroskin a52c89b01d Extract UIImplementationProvider for Nodes into a helper class
Summary: Exact same class is needed for Groups, and probably for other apps that want to work with Nodes, too, so let's extract it into a helper class to simplify coding.

Reviewed By: sriramramani

Differential Revision: D2873943
2016-12-19 13:40:20 -08:00
Denis Koroskin 461871364b Manually assign id of the top-level View to match top-level react tag
Summary:
Nodes create a FlatViewGroup for a root node element, and NativeViewHierarchyManager assigns it an id that matches root node it. Now this top-level FlatViewGroup is added to a ReactRootView. In non-nodes, this ReactRootView has an id that matches root View id, and when this ReactRootView gets detached from Window, it sends an event to NativeViewHierarchyManager that says that all the children of this View must be removed recursively. This works great in non-Nodes, but fails in Nodes because ReactRootView has no id (-1) and NativeViewHierarchyManager fails to find a corresponding ReactShadowNode, throwing an Exception. To fix the issue and make it work again we need to assign this View id of the top level shadow node. This creates a minor issue, where 2 Views (ReactRootView and its only child) share the same id, but that is not a problem because we don't enforce uniqueness of the ids, and don't rely on getViewById().

This was originally implemented, but then I removed it because I thought it wasn't truly needed. Turns out, it is needed.

Reviewed By: sriramramani

Differential Revision: D2873995
2016-12-19 13:40:20 -08:00
Martin Konicek 0b79d44dcf Less Catalyst, more React
Summary:
Catalyst is the old project name. Rename a few files.

@public

Reviewed By: bestander

Differential Revision: D2859553
2016-12-19 13:40:20 -08:00
Denis Koroskin 59fe71caff Add support for ImageLoadEvents to RCTImageView
Summary: This diff implements ImageLoadEvents (ON_LOAD, ON_LOAD_END and ON_LOAD_START) in RCTImageView. ON_ERROR and ON_PROGRESS are easy to implement, too, but these 2 are supposed to carry extra information (error message and progress) but ImageLoadEvent doesn't support a payload yet (I'll add them in a separate patch).

Reviewed By: ahmedre

Differential Revision: D2824772
2016-12-19 13:40:20 -08:00
Denis Koroskin 76abec8894 Add support for shadows to RCTVirtualText
Summary: React provides properties to support shadows for Text, this diff implements it for Nodes.

Reviewed By: ahmedre

Differential Revision: D2817212
2016-12-19 13:40:20 -08:00
Denis Koroskin f98a288c2a Don't create an instance of FontStylingSpan until any of the properties changed
Summary: Minor optimization/cleanup: instead of creating an instance of FontStylingSpan for every RCTVirtualText, start with a global immutable instance of use copy-on-write when any of the properties change.

Reviewed By: ahmedre

Differential Revision: D2817156
2016-12-19 13:40:19 -08:00
Denis Koroskin c43d8409c0 Fix RTCText incorrectly clipping its background
Summary: Wrong order or top/right -> right/top means that clipping can be incorrect. I didn't notice it because visual result in many cases would still be the same (especially with overflow: visible being default and clipping being mostly disabled). Also only background was clipped incorrectly, and most texts don't have a background.

Reviewed By: ahmedre

Differential Revision: D2816432
2016-12-19 13:40:19 -08:00
Denis Koroskin 03637dc70d Don't add empty NodeRegion, because it will never receive touch events anyway
Summary: Small optimization that prevents empty NodeRegions from being collected. Those will never receive touch events anyway, so why bother allocating memory and iterating over them?

Reviewed By: ahmedre

Differential Revision: D2816355
2016-12-19 13:40:19 -08:00
Denis Koroskin 584cbd3b99 Update/Add NodeRegion after collectState()
Summary: RCTText may modify its DrawCommand on collectState(), which updateNodeRegion() relies on. This means that order of the two is important: call collectState() first, followed by updateNodeRegion(). This fixes the bug where am RCTText may sometimes not respond to clicks (because its NodeRegion would be empty).

Reviewed By: ahmedre

Differential Revision: D2816295
2016-12-19 13:40:19 -08:00
Denis Koroskin e7d8d2c3ab Don't use NodeRegion to update View bounds
Summary: NodeRegions are touch regions within hosting View, and while in most cases they are the same as View boundaries, there is one case where it's not true: TextNodeRegion. When mounted to a View, TextNodeRegion will have a bounds of (0,0,width,height) which is clearly different from (left,top,right,bottom). Initially I assumed they would always be the same so we could use information stored in NodeRegion (should probably be called TouchRegion) to update node's View boundaries, but it breaks RCTTextView when it mount to a View (because it would either contain incorrect bounds, or View will be laid out incorrectly). Right now touch is not working on RCTView that mounts to a View. To fix the issue, separate the 2 concepts.

Reviewed By: ahmedre

Differential Revision: D2816268
2016-12-19 13:40:19 -08:00
Denis Koroskin 2fb7ebfb7b Reset NodeRegion when a node gets mounted to a View
Summary: Small optimization. Once we mount a Node to a View, its NodeRegion is not used anymore with RCTText being an exception, but it will correct itself automatically upon updateNodeRegion call. This patch allows the dead object to get garbage collected.

Reviewed By: ahmedre

Differential Revision: D2816331
2016-12-19 13:40:19 -08:00
Denis Koroskin 7075744b94 Implement DrawImage using Drawee
Summary: Alternative implementation of DrawImage using DraweeHierarchy instead of ImagePipeline directly. Yields same results, but potentially more stable. We'll run tests to measure performance of both.

Reviewed By: ahmedre

Differential Revision: D2746197
2016-12-19 13:40:19 -08:00
Alexander Blom 2daf696064 Move UIManager annotations to separate package
Summary:
Moves ReactProp and ReactPropGroup to `com.facebook.react.uimanager.annotations`. This is needed
so that future annotation processor can run on code inside the com.facebook.react.uimanager package.

@public

Reviewed By: astreet

Differential Revision: D2754842
2016-12-19 13:40:19 -08:00
Denis Koroskin 2e773a2cb1 Properly invalidate FlatViewGroup with width or height equal to 0
Summary: View.invalidate() will not actually invalidate a View if it has width or height equal to 0. This is causing problems with overflow: visible. A quick fix applied here is to invalidate slightly larger region that the View bounds to bypass the optimization.

Reviewed By: ahmedre

Differential Revision: D2800920
2016-12-19 13:40:19 -08:00
Denis Koroskin b10474c333 Disallow mounting virtual nodes to Views
Summary: Virtual shadow nodes, such as RCTRawText, RCTTextInlineImage etc cannot be mounted to a View (ViewManager will throw an Exception if we ever try to). This diff is adding a check to make sure that Exception is never thrown.

Reviewed By: ahmedre

Differential Revision: D2800869
2016-12-19 13:40:19 -08:00
Denis Koroskin 05544f6bca Make FlatUIImplementation.measure() work with virtual views (shadow nodes that don't map to a View)
Summary: UIImplementation.measure() can only measure shadow nodes that map to native Views. As a result of this, every time we tried to measure a shadow node that doesn't map to a View, we trigger callback with no data (to indicate an error). To fix this issue, walk up until we find a node that maps to a View, then measure that View and adjust for the bounds of a virtual child.

Reviewed By: ahmedre

Differential Revision: D2800960
2016-12-19 13:40:19 -08:00
Denis Koroskin b321ea98d3 Properly clip child Views in FlatViewGroup
Summary:
Everything (but Views) are drawn using AbstractDrawCommand (or its derivative, like DrawBorder or DrawBackgroundColor) and supports clipping properly. Views however are drawn using an assumption that Android will clip them manually. This is however not always true. One example is if an element A mounts to a View, and its parent B doesn't but has overflow: hidden and thus should clip the child.

There are 2 ways to fix this:
- pop every element that has overflow: hidden to its own View. In this case, its children will always be correctly clipped. This is however very inefficient, especially if overflow: hidden is default (which it is!) which means that almost every React element must be backed by an Android View.
- add clipping information to DrawView, similar to how AbstractDrawCommand has it.

This diff implements the latter approach.

Reviewed By: ahmedre

Differential Revision: D2792375
2016-12-19 13:40:18 -08:00
Denis Koroskin 3d6464d0e1 Properly mark root shadow node as mounting to a View
Summary: RootFlatShadowNode always mounts to a (top-level) View but was never marked as one that mounts to a View. This diff fixes it. Nothing in the code relied on it being marked as mounting to a View, so it worked fine. A follow up path that implements UIImplementation.measure() for nodes that don't mount to a View goes up until it finds first mounting node, and it was crashing with NPE because it tried to access RootFlatShadowNode's parent (and there isn't one).

Reviewed By: sriramramani

Differential Revision: D2800818
2016-12-19 13:40:18 -08:00
Denis Koroskin 31d2443dd4 Implement RCTTextInlineImage with Nodes
Summary:
React allows nesting <Image> inside <Text>, in which case it turns into an RCTTextInlineImage element. RNFeed is using it in a few places and thus we need to support it, too.

This diff implements it with InlineImageSpan (WithPipeline, and WithDrawee separately).

Reviewed By: ahmedre

Differential Revision: D2792569
2016-12-19 13:40:18 -08:00
Denis Koroskin 28efab0670 Fix Android Views not clipping their content
Summary: D2768643 disabled View clipping of FlatViewGroup's children by calling setClipChildren(false). Turns out, instead of disabling clipping on the View this method is called on, it disables clipping on the children, instead. While we want the clipping disabled on all children that are FlatViewGroups, it also means that everyone else gets the clipping disabled as well. This has issues with ScrollView that stopped clipping its scrolling content, resulting in visual glitches. To fix the issue, manually clip all the Views that are not FlatViewGroups.

Reviewed By: ahmedre

Differential Revision: D2792411
2016-12-19 13:40:18 -08:00
Denis Koroskin 0f2a5cffa7 Extract ImageRequest creation into a helper class
Summary: This diff add an ImageRequestHelper class to reuse code that creates ImageRequest in both RCTImageView and (upcoming) RCTTextInlineImage

Reviewed By: ahmedre

Differential Revision: D2792548
2016-12-19 13:40:18 -08:00
Denis Koroskin 368e0361dd Rename BitmapRequestHelper to PipelineRequestHelper
Summary: Minor cleanup; renames BitmapRequestHelper to PipelineRequestHelper and adds BitmapUpdateListener interface. I plan reusing these classes in an upcoming RCTTextInlineImage implementation.

Reviewed By: ahmedre

Differential Revision: D2792535
2016-12-19 13:40:18 -08:00
Denis Koroskin fd3e213593 Update RCTText.PAINT's text size to ensure that ellipsis is measured correctly
Summary: placeholder

Reviewed By: ahmedre

Differential Revision: D2786310
2016-12-19 13:40:18 -08:00
Denis Koroskin e3abc51dd7 RCTText should clip when the creates Layout is wider than requested
Summary: AbstractDrawCommand's bounds are supposed to be the rectangle that the DrawCommand will draw into, so that it can compare bounds against clip rect bounds and reliable skip clipping when it's not needed. It is however not true for RCTText that can create text Layout that in some cases can go out of it's requested bounds (happens with TextView, too). To fix the issue, instead of passing requested bounds, pass the actual ones. In this case, AbstractDrawCommand will make sure to clip DrawTextLayout if for some reason it draws outside of the allowed boundaries.

Reviewed By: ahmedre

Differential Revision: D2786306
2016-12-19 13:40:18 -08:00
Denis Koroskin d23f86e47b Implement touch intercepting in RCTView
Summary:
@public React allows excluding certain elements from touch handling by assigning `PointerEvents` filter to them, such as BOX_NONE - this element will not receive touch but its children will, BOX_ONLY - only this element will receive pointer event and not children, NONE - neither this element nor its children will receive pointer events, and AUTO - pointer events are allowed for both this element and its children.

This diff adds PointerEvents support to flat RCTView. Most of the implementation is copied from ReactViewManager/ReactViewGroup. One small change is made to TouchTargetHelper to ensure that it works correctly with virtual nodes when their parent has PointerEvents set to PointerEvents.BOX_NONE.

Reviewed By: ahmedre

Differential Revision: D2784208
2016-12-19 13:40:18 -08:00
Denis Koroskin ff77456f26 Fix DrawBorder now updating color for left border, drawing it with old color
Summary: There is a small bug in DrawBorder where we forget updating color for a left border, which makes the border draw with whatever color was previously set to the Paint. This diff fixes it by updating the color.

Reviewed By: ahmedre

Differential Revision: D2779511
2016-12-19 13:40:18 -08:00
Denis Koroskin f6b4dc68de Make sure shadow node that we set JSResponder to mounts to a View
Summary: When setJSResponder() is called on a shadow node that doesn't mount to a View, React runtime will crash in NativeViewHierarchyManager because it will fail to find a corresponding View. To fix the issue, make sure we forceMountToView() before we call enqueueSetJSResponder().

Reviewed By: ahmedre

Differential Revision: D2779523
2016-12-19 13:40:18 -08:00
Ahmed El-Helw 12023b7953 Implement numberOfLines support in React flat rendering.
Summary: Support numberOfLines in React with flat rendering.

Differential Revision: D2746855
2016-12-19 13:40:17 -08:00
Denis Koroskin c5d0cb70d7 Fixed a build failure due to a missing import
Summary: D2772438 removed some unused imports, and a parallel build landed that uses one of the imports. Both diffs landed and now master is broken. This diff is fixing it.

Reviewed By: ahmedre

Differential Revision: D2779442
2016-12-19 13:40:17 -08:00
Denis Koroskin 6f06f76e38 Implement overflow:visible/hidden attribute (defaults to visible)
Summary:
Prior to this patch DrawCommands weren't get clipped by parent DrawCommands at all. For example, a <View> element with size 200x200 with overflow:hidden should clip its child which is 400x400, but this didn't happen. However, if parent <View> would mount to an Android View, it would clip the child regardless of the overflow attribute value (because Android Views always clip whatever is drawing inside that View against its boundaries).

This diff is fixing these issue, implementing overflow attribute support and making clipping behavior consistent between nodes that mount to View and nodes that don't.

Reviewed By: ahmedre

Differential Revision: D2768643
2016-12-19 13:40:17 -08:00
Denis Koroskin f738b598d8 Properly invalidate FlatViewGroup when hotspot Drawable invalidates
Summary: I lost FlatViewGroup.verifyDrawable(Drawable) method during one of the rebases. Re-adding it now because hotspot drawable is not working without it.

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

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

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

Reviewed By: ahmedre

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

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

Reviewed By: sriramramani

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

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

Reviewed By: foghina

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

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

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

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

**Test plan (required)**

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

Differential Revision: D4348098

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

Reviewed By: AaaChiuuu

Differential Revision: D4336435

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

Differential Revision: D4346826

fbshipit-source-id: 70855a44b27d25e49615914a845cf04fc63e322d
2016-12-19 11:43:30 -08:00
Aaron Chiu 1052d29fac create ART*ViewManager classes
Reviewed By: achen1

Differential Revision: D4050949

fbshipit-source-id: 214838c1c1cf6c66170b606ac7055e1e8790b6c9
2016-12-17 17:43:35 -08:00
Aaron Chiu c27cc9c1ac add viewManager param to @ReactModuleList
Reviewed By: achen1

Differential Revision: D4338871

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

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

**Notes**

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

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

Differential Revision: D4340129

Pulled By: lacker

fbshipit-source-id: 69160d9e71281a96a7445d764b4715a3e54c0357
2016-12-16 14:28:34 -08:00
Andrew 00449b2654 Little docs correction
Summary:
Comma out
Closes https://github.com/facebook/react-native/pull/11491

Differential Revision: D4339939

Pulled By: lacker

fbshipit-source-id: 4945d9804e39809a10e92f42f60434fe69552782
2016-12-16 10:13:37 -08:00
Konstantin Raev 0579efea8c Switched to npm hosted boost lib
Summary:
Boost is officially hosted on SourceForge which has ab SSL problem that Gradle complains about and also it is sometimes unavailable.
I switched to using npm hosted (yarnpkg mirrored for performance) boost lib exactly the same as from Source Forge.

Other alternatives considered:
- CDN e.g. mirror.nienbo.com started responding with 4XX code when requested by Gradle
- File sharing like DropBox are not for mass anonymous downloads
- Github is not good for binary files and is throttled for anonymous raw file downloads
- S3 or similar. Requires amazon account for maintenance and does not expose semver API and other nice features that npm has

In the future I'd like to try Yarn as dependency management tool for bridge builds, this could be the first step.

**Test plan (required)**

- Circle (testing with caches cleaned)
- `./gradlew ReactAndroid:packageReactNdkLibsForBuck` (check twice to make sure caches work)
- `REACT_NATIVE_BOOST_PATH=./bridge-dependencies/node_modules/boost-react-native-bundle ./
Closes https://github.com/facebook/react-native/pull/11469

Differential Revision: D4339446

Pulled By: mkonicek

fbshipit-source-id: ccc9196e9b675c16a235a318c4861aaa4e263d6e
2016-12-16 06:43:33 -08:00
Emil Sjolander 45fdcdc93a YGNodeChildCount -> YGNodeGetChildCount for consistency
Reviewed By: gkassabli

Differential Revision: D4333480

fbshipit-source-id: 17058f18fa9e26b3e02f7a1651f7295cae59acad
2016-12-16 04:44:18 -08:00
Adam Comella c0ea23cfb0 Android: Expose textBreakStrategy on Text and TextInput
Summary:
Android has a text API called breakStrategy for controlling how paragraphs are broken up into lines. For example, some modes support automatically hyphenating words so a word can be split across lines while others do not.

One source of complexity is that Android provides different defaults for `breakStrategy` for `TextView` vs `EditText`. `TextView`'s default is `BREAK_STRATEGY_HIGH_QUALITY` while `EditText`'s default is `BREAK_STRATEGY_SIMPLE`.

In addition to exposing `textBreakStrategy`, this change also fixes a couple of rendering glitches with `Text` and `TextInput`. `TextView` and `EditText` have different default values for `breakStrategy` and `hyphenationFrequency` than `StaticLayout`. Consequently, we were using different parameters for measuring and rendering. Whenever measuring and rendering parameters are inconsistent, it can result in visual glitches such as the text taking up too much space or being clipped.

This change fixes these inconsistencies by setting `breakStrategy` and `hyphenat
Closes https://github.com/facebook/react-native/pull/11007

Differential Revision: D4227495

Pulled By: lacker

fbshipit-source-id: c2d96bd0ddc7bd315fda016fb4f1b5108a2e35cf
2016-12-16 01:28:45 -08:00
Steven Goff 4394419b60 Android Text component allowFontScaling
Summary:
The reason for this change is to implement `allowFontScaling` on the Android's React Native Text component.  Prior to this PR `allowFontScaling` only works for iOS.

The following link contains images of `allowFontScaling` working in Android on small, normal, large, and huge system fonts (from native Android display settings)

http://imgur.com/a/94bF1

The following link is a video of the same thing working on an Android emulator

https://youtu.be/1jTlZhPdj9Y

Here is the sample code snippet driving the video/images
```
render() {
    const size = [12, 14, 16, 18];
    return (
      <View style={{backgroundColor: 'white', flex: 1}}>
        <Text>
          Default size no allowFontScaling prop (default true)
        </Text>
        <Text allowFontScaling={true}>
          Default size allowFontScaling: true
        </Text>
        <Text style={{ marginBottom: 10, }} allowFontScaling={false}>
          Default size allowFontScaling: false
        </Text>

        { size.map(
Closes https://github.com/facebook/react-native/pull/10898

Differential Revision: D4335190

Pulled By: lacker

fbshipit-source-id: 0480809c44983644ff2abfcaf4887569b2bfede5
2016-12-15 17:43:35 -08:00
Delyan Kratunov 1f78ea326e Remove unnecessary project_config
Differential Revision: D4326949

fbshipit-source-id: d0e8d7c3a046a89e5794be602a406ea914de50d1
2016-12-15 09:29:16 -08:00
John Shelley f3c8158773 Android - ReactNativeHost getUseDeveloperSupport to public
Summary:
Currently React Native is opinionated in that the easiest approach is to extend ReactActivity. However to more easily allow integrating with existing application, we should allow some of the methods in ReactNativeHost to be public, and this is a very good first step.
* There is no harm in making this public from what I can tell.
* This allows `ReactNativeHost` to be more easily used outside of the `ReactActivity` and `ReactActivityDelegate` ecosystem. (A `ReactFragment` would be a good example)

_No issues found_

**Test plan (required)**

* Run any sample app and verify it still works.

Make sure tests pass on both Travis and Circle CI.
Closes https://github.com/facebook/react-native/pull/11329

Differential Revision: D4287429

Pulled By: AaaChiuuu

fbshipit-source-id: 8cb76f3226aae3737af5f5bd6010d3eea8df9bfe
2016-12-15 04:13:37 -08:00
Üstün Ergenoglu 3785db2fb1 Add property to force HW acceleration on Android for modal windows
Summary:
When using React Native on Android on top of a game as an overlay, dialog windows sometimes get created with hardware acceleration disabled. This causes the UI to be unresponsive and anything that uses a TextureView stops working. Added a property for the modal view to make sure hardware acceleration flag is enabled when it's set to true.

**Test plan (required)**

set `hardwareAccelerated` property for Modal to force hardware acceleration on dialog windows on Android. Does nothing on iOS.
Closes https://github.com/facebook/react-native/pull/11421

Differential Revision: D4312912

Pulled By: andreicoman11

fbshipit-source-id: 9db6b2eca361421b92b24234b3501b5de0eecea7
2016-12-14 10:28:33 -08:00
Kirwan Lyster 14dfb525a2 Use ScaleType.getTransform() instead of util method
Summary: This changes ReactImageView to pull the transform matrix for rounding from the scale type itself instead of a utility method that forwards to the same thing.

Reviewed By: lambdapioneer

Differential Revision: D4326549

fbshipit-source-id: 82e59e3c20f83beb1d454743e6dbbce8666de8a3
2016-12-14 07:43:32 -08:00
Kevin Lacker affd5ac681 Improve Android testing scripts
Summary:
The goal of this pull request is to make it easier for contributors to run Android tests locally, specifically the unit tests and integration tests. I added a bunch of checks to the local testing scripts that will warn you if your environment is misconfigured, and tell you how to fix it. I also updated the testing docs, so that the regular "Testing" page should be a decent resource to point people to when you are telling them "hey this pull request needs a test." Just Android, though, I haven't gotten to the iOS parts yet.

I also disabled a couple tests that seemed quite flaky while running on a local machine, and don't seem to be providing much value. In particular, the `TestId` test just hangs on my emulator a lot and has been flaky on CI in the past, so I removed about half of its test cases to make the sample app smaller. The testMetions test appears to be dependent on screen size so I commented it out.
Closes https://github.com/facebook/react-native/pull/11442

Differential Revision: D4323569

Pulled By: bestander

fbshipit-source-id: 9c869f3915d5c7cee438615f37986b07ab251f8c
2016-12-13 17:13:35 -08:00
Aaron Chiu a76547f7ac force crash if a Java Module isn't lazifi-able in a Lazified app
Reviewed By: achen1

Differential Revision: D4317878

fbshipit-source-id: 61ee4b24f0de206f53d6f4b3801d81aa6f3ab36c
2016-12-13 03:58:32 -08:00
Lukas Piatkowski de82931931 Fix SamplingProfiler and HeapCapture for apps that lazy load react modules
Reviewed By: cwdick

Differential Revision: D4291903

fbshipit-source-id: 684ced8d6370494191cdb182a8e172680d69d17b
2016-12-07 10:43:48 -08:00
Don Yu bfe551d2d1 Implement onViewAppear by creating a new EventListener on ReactRootView listening for when it's attached to a RN Instance
Reviewed By: AaaChiuuu

Differential Revision: D4269272

fbshipit-source-id: 6dd54f8ab7befebd54e82ef355119ba302b9bfe5
2016-12-07 09:58:33 -08:00
Emil Sjolander 7f8c2985a8 Rename directories
Reviewed By: gkassabli

Differential Revision: D4284681

fbshipit-source-id: f0c6855c2c6e4389b7867f48f72cbb697830fc5a
2016-12-07 05:14:12 -08:00
John Shelley d21aa92480 Android - Fix Overlay for Marshmallow 23+
Summary:
Currently any React Native apps that target API 23 or greater will crash on the first initial debug/dev build due to the overlay permission.

Sadly there isn't a concrete "request permission" baked into the Marshmallow permission system.
However, we can launch the overlay screen without starting the react app and once its turned on start the app.

 - https://github.com/facebook/react-native/issues/10454 - targetSdkVersion 23 lead crash / App crash for targeting 23+
 - https://github.com/facebook/react-native/pull/10479 - Add the overlay permission information / Larger discussion around targeting API 23+
- Intent to Overlay permission goes directly to the app in question, rather then the general full listing of applications. This allows a developer who is not familiar with the system to easily toggle the overlay without getting confused.

**Test plan (required)**
* Ran UIExplorer App on fresh install with Target 23
```
cd react-native
./gradlew :Examples:UI
Closes https://github.com/facebook/react-native/pull/11316

Differential Revision: D4286351

fbshipit-source-id: 024e97c08c40ee23646dd153794fcde7127b2308
2016-12-06 12:43:36 -08:00
Emil Sjolander 86e0f39863 Fix last missing reference to libcsslayout
Reviewed By: bestander

Differential Revision: D4279530

fbshipit-source-id: 809a6317f02bc2a770f50c8cb048aa3e2dfcf33f
2016-12-05 15:13:28 -08:00
Martin Konicek 70f07b1e4e Revert to downloading Boost from SourceForge for now
Summary: The unpkg mirror started returning HTTP 403 Forbidden for some reason.

Reviewed By: mkonicek

Differential Revision:
D4278637
Ninja: OSS only, tests already broken

fbshipit-source-id: 7dbfce40e8246f2a021ebe2592d24fa86c12bf21
2016-12-05 11:58:34 -08:00
Emil Sjolander 097d3173e9 Fix library name of yogacore
Reviewed By: bestander

Differential Revision: D4276884

fbshipit-source-id: c791aa3bb27fcf4b48d84427011eae6119fe6edf
2016-12-05 07:43:29 -08:00
Emil Sjolander b8708edf0f Update java package name to yoga
Differential Revision: D4271420

fbshipit-source-id: b3cf150569a2331868410339cd19e5c694f2059e
2016-12-05 02:58:32 -08:00
David Aurelio f9f32eb426 Load Indexed RAM format on android
Reviewed By: javache

Differential Revision: D4268243

fbshipit-source-id: fc969cfc69810d0477c926ffc79c23584fcbd7eb
2016-12-04 16:13:30 -08:00
Emil Sjolander fd2fb6cd65 Update yoga library name
Reviewed By: bestander

Differential Revision: D4273387

fbshipit-source-id: 91373c6ef1e94b330fa249235ba97fec480e17c7
2016-12-04 05:28:29 -08:00
Emil Sjolander b9cedaefa6 Rename java API
Reviewed By: IanChilds

Differential Revision: D4265345

fbshipit-source-id: 69ecfd8fac214f86b8b70647b9b909acd83d78b5
2016-12-03 04:44:10 -08:00
Emil Sjolander 85ac5fc354 Rename C api
Differential Revision: D4259190

fbshipit-source-id: 26c8b356ca464d4304f5f9dc4192bff10cea2dc9
2016-12-03 04:44:10 -08:00
Ben Clayton 833961e05d <Text> Expose Android's includeFontPadding property to JavaScript.
Summary:
By default Android will put extra space above text to allow for upper-case accents or other ascenders. With some fonts, this can make text look slightly misaligned when centered vertically.

We have found that the effect is very noticeable with certain custom fonts on Android. On iOS the font aligns vertically as expected.

Android exposes a property `includeFontPadding` that will remove this extra padding if set to false. This PR exposes that to JS, and adds it to the documentation and UIExplorer.
Closes https://github.com/facebook/react-native/pull/9323

Differential Revision: D4266713

Pulled By: lacker

fbshipit-source-id: f9711254bc26c09b4586a865f0e95ef4bf77cf3f
2016-12-02 12:58:36 -08:00
Emil Sjolander 779508c0ba Rename enums
Differential Revision: D4244360

fbshipit-source-id: c9fcbdd231098c9ff230a6055676bbc7cbd11001
2016-12-02 05:58:45 -08:00
Emil Sjolander 476973e789 Remove force_static
Reviewed By: gkassabli

Differential Revision: D4258293

fbshipit-source-id: 053f9e607503707830e3766b1f268ab31d3081ff
2016-12-02 05:13:32 -08:00
Emil Sjolander bed9087191 Revert D4248487: [yoga] Remove force_static
Differential Revision: D4248487

fbshipit-source-id: c826eb6543ff6b8d512bf688fbd395e9766df2fb
2016-11-30 12:28:32 -08:00
Yann Pringault fb230000a8 Call handleUpdateLayout even if the content didn't change
Summary:
This PR fixes #11096.

I don't know enough the ReactAndroid's source code so I don't know if this is correct but I hope it is.

In a recent commit (d4b8ae7a8a), the `dispatchUpdates` method now returns a boolean to dispatch or not the `onLayout` event. This works well but if the content is unchanged, the line `nativeViewHierarchyOptimizer.handleUpdateLayout(this);` is never called. I don't know if it was intended but it was this which introduces my issue. I called this again even if the content didn't change. This was the behaviour before 0.38 so I guess I didn't break anything.

**Test plan (required)**

I tested my pretty big app with this fix and every screen is ok.
Closes https://github.com/facebook/react-native/pull/11222

Differential Revision: D4252101

Pulled By: astreet

fbshipit-source-id: 551559234631ac37245a854d81ba568f0ddb02dd
2016-11-30 11:43:34 -08:00
Emil Sjolander 4902a03380 Fix usage of weak references to check for null
Reviewed By: lexs

Differential Revision: D4251133

fbshipit-source-id: 2d8949252b31447ce54bc16a35cb25fabe72230b
2016-11-30 10:13:36 -08:00
Emil Sjolander 89a380abc8 Remove force_static
Reviewed By: gkassabli

Differential Revision: D4248487

fbshipit-source-id: e5127a02561b145745cf5393a0188661469ec79b
2016-11-30 08:28:33 -08:00
Adam Comella 911c05a89b Android: Decrease cost of reflection
Summary:
This change suppresses access checking during reflection which makes reflection faster by decreasing its overhead.

**Test plan (required)**

My team uses this change in our app.

Adam Comella
Microsoft Corp.
Closes https://github.com/facebook/react-native/pull/11204

Differential Revision: D4250790

Pulled By: astreet

fbshipit-source-id: 0ee2f40dcadccc695980fcae14fafe1050acb52f
2016-11-30 03:58:29 -08:00
Adam Comella 528a3c776a Android: Keep ScrollView content visible after edits
Summary:
Suppose that the user is scrolled to the bottom of a ScrollView. Next, the ScrollView's content is edited such that the height of the content changes and the current scroll position is larger than the new height of the content. Consequently, the user sees a blank ScrollView. As soon as the user interacts with the ScrollView, the ScrollView will jump to its max scroll position.

This change improves this scenario by ensuring that the user is never staring at a blank ScrollView when the ScrollView has content in it. It does this by moving the ScrollView to its max scroll position when the scroll position after an edit is larger than the max scroll position of the ScrollView.

Here are some pictures to illustrate how this PR improves the scenario described above:

![image](https://cloud.githubusercontent.com/assets/199935/20408839/0e731774-accc-11e6-9f0a-3d77198645e9.png)

![image](https://cloud.githubusercontent.com/assets/199935/20408844/12877bb6-accc-11e6-8fe2-1c1bb26569cc.png)

**Test plan (require
Closes https://github.com/facebook/react-native/pull/11000

Differential Revision: D4250792

Pulled By: astreet

fbshipit-source-id: 940fff6282ad29c796726f68b4519cbdabbfe554
2016-11-30 03:58:29 -08:00
Adam Comella aac8daf378 Android: Enable ad-hoc dependencies to be pre-downloaded
Summary:
ReactAndroid/build.gradle downloads a number of ad-hoc dependencies from the internet such as boost, JSC headers, and folly. Having the build depend on the internet is problematic. For example, if the site hosting the JSC headers was to go down, then CI builds would start failing.

This change introduces the environment variable REACT_NATIVE_DEPENDENCIES which refers to a path. Developers can pre-download all of the ad-hoc dependencies into that path and then the build process will grab the dependencies from that local path rather than trying to download them from the internet. This solution is in the spirit of the existing REACT_NATIVE_BOOST_PATH hook.

**Test plan (required)**

This change is used by my team's app.

Adam Comella
Microsoft Corp.
Closes https://github.com/facebook/react-native/pull/11195

Differential Revision: D4247080

Pulled By: mkonicek

fbshipit-source-id: 7c4350339c8d509a829e258d8f1bf320ff8eef64
2016-11-29 14:28:34 -08:00
Emil Sjolander b58c8ad916 Remove deprecated java code
Reviewed By: AaaChiuuu

Differential Revision: D4233198

fbshipit-source-id: 736d79be266e1b9f2d62e5fe6d901de47123cdc1
2016-11-29 12:28:55 -08:00
Emil Sjolander 065af66deb Remove Style prefix in java and cs apis
Reviewed By: splhack

Differential Revision: D4232920

fbshipit-source-id: 6e2ff21bbb7e0e441892023c14df579d1bc7aa49
2016-11-29 09:13:28 -08:00
Emil Sjolander f1a5233fd2 Always use soloader. Catching exception and re-trying hides errors
Reviewed By: lexs

Differential Revision: D4243906

fbshipit-source-id: e4d691c9c49f3b9316f67e39b9f277657d78fb3c
2016-11-29 04:43:30 -08:00
Venryx c4046d62a7 * Reduce emit overhead to ~50% of prior, by caching class-name of java-script module/interface.
Summary:
Made modification to react-native code that reduces the communication channel overhead to ~50% of prior, in some cases, by caching the class-name of the java-script module/interface.

For me it reduced the run-time of the RCTDeviceEventEmitter.emit function from 1438ms to 715ms, over a period of 8 seconds in my Android app. My project requires many emit calls, as I'm transferring real-time EEG data from a Muse headband to my react-native UI to be graphed, so this optimization was very helpful in my case.
Closes https://github.com/facebook/react-native/pull/11118

Reviewed By: astreet

Differential Revision: D4232794

Pulled By: javache

fbshipit-source-id: 25ca1cfc170a343e71ff8915c3fa7e38884a402b
2016-11-29 02:58:34 -08:00
Ryan Gomba 97887c2a52 Remove unused var in NativeAnimatedNodesManager
Summary:
Should have been removed in 6f5433febe (commitcomment-19793695).

Simple enough fix.

cc/ janicduplessis
Closes https://github.com/facebook/react-native/pull/11178

Differential Revision: D4239876

fbshipit-source-id: f96e220ffdab042bded27ff16d2395741c70b61f
2016-11-28 14:13:33 -08:00
Emil Sjolander 28275836c9 Dont strip class names referenced from native
Reviewed By: lexs

Differential Revision: D4237790

fbshipit-source-id: 1bd0780d965efbb8334917011ffd65896670ece1
2016-11-28 09:28:28 -08:00
Adam Comella 8b199a7fd0 Android: Enable apps to provide a custom configuration to Fresco
Summary:
The `FrescoModule` supports providing a custom image pipeline configuration. This module is created by `MainReactPackage` but `MainReactPackage` doesn't expose any way to customize the Fresco configuration. This change adds a parameter to `MainReactPackage`'s constructor so that the `FrescoModule`'s configuration can be customized by the app. A couple of design choices were made in this change:
  - `MainReactPackage`'s new constructor parameter is a `MainPackageConfig`. Introducing `MainPackageConfig` enables `MainReactPackage` to nicely support new optional configuration options in the future. Imagine the alternative of each optional configuration being a separate parameter to the `MainReactPackage` constructor.
  - `FrescoModule` exposes its default configuration as a builder object through the `getDefaultConfigBuilder` method. This enables app's to start with `FrescoModule`'s default configuration and then modify it.

**Test plan (required)**

Verified that passing a custom config based on React Nati
Closes https://github.com/facebook/react-native/pull/10906

Differential Revision: D4237054

Pulled By: mkonicek

fbshipit-source-id: 8a62a6f0e77ca5f6d35238950094686756262196
2016-11-28 03:43:32 -08:00
Vishal Kakadiya fea1428d99 Imported "com.facebook.react.ReactPackage" twice
Summary:
"com.facebook.react.ReactPackage" is imported twice so fixed it to once.
Closes https://github.com/facebook/react-native/pull/11165

Differential Revision: D4236961

Pulled By: mkonicek

fbshipit-source-id: 84765dd9f8731b978972959f3825bf3c9c0684e3
2016-11-28 02:58:23 -08:00
Janic Duplessis 552c601921 Don't dismiss keyboard when tapping another text input
Summary:
When using text inputs inside a ScrollView with `keyboardShouldPersistTaps=false` (default behavior) tapping another text input dismisses the keyboard instead of keeping it open and focusing the new text input which I think is the better and expected behavior.

See #10628 for more discussion about that. Note that this affects nothing but the behavior with text inputs unlike #10628.

cc satya164 MaxLap ericvicenti
Closes https://github.com/facebook/react-native/pull/10887

Differential Revision: D4178474

Pulled By: ericvicenti

fbshipit-source-id: 0c62ea2fac0017d559d1f8674b0a686a5e1b3d2d
2016-11-25 05:43:30 -08:00
Connor McEwen 51efaab120 Handle "Never Ask Again" in permissions and add requestMultiplePermissions
Summary:
In order to get featured in the Google Play Store, we had to handle a few specific cases with permissions based on feedback from the editorial team.

First, which was previously possible with this permissions module was bumping the sdk to version 23.

The second is requesting multiple permissions at one time. In order for the camera + upload to work, we needed to request both camera permissions + media storage in one flow.

The last is handling the case where the user checks the "Never Ask Again" box. This will only appear after a user denies a permission once and is then prompted again. The logic for handling this case is taken from here: http://stackoverflow.com/questions/31928868/how-do-we-distinguish-never-asked-from-stop-asking-in-android-ms-runtime-permis/35495372#35495372

We were also seeing a few crashes similar to #10009 due to `onRequestPermissionsResult` being called before `onResume` (http://stackoverflow.com/questions/35205643/why-is-onresume-called-after-onrequestpermissionsresult), so I delaye
Closes https://github.com/facebook/react-native/pull/10221

Differential Revision: D4232551

fbshipit-source-id: fee698d1c48a2d86623cb87996f3d17f4c10a62e
2016-11-24 22:43:28 -08:00
Benoit Lemaire 6fef014295 Remove Jackson dependency
Summary:
This PR removes dependency to Jackson third-party library in Android React Native.

Looking at some older PRs that got merged, it seems like some work had already been done to move away from Jackson.

Anyway, there was only two classes left with a dependency on Jackson. I refactored the code to use android built-in `JsonReader` and `JsonWriter` classes instead.

Prep work was done in https://github.com/facebook/react-native/pull/10516 introducing a few unit tests around serialization, to make sure that refactoring around serialization would not break things.

All references to Jackson in build systems files (BUCK files & build.gradle) have also been removed now that no code depend anymore on this third-party library.

Motivation behind this work is that third-party dependencies in Android React Native can prove to be a pain when trying to integrate React Native components into an already existing large Android application (I know this is not the most common use case for react-native ... yet ;P), that might a
Closes https://github.com/facebook/react-native/pull/10521

Differential Revision: D4226705

Pulled By: mkonicek

fbshipit-source-id: e3a7430a79dd00c871ba3c6a705b0b0c3ec3a701
2016-11-23 08:59:50 -08:00
Emil Sjolander 5850165795 Add support for aspectRatio style prop
Summary:
Expose aspectRatio style prop from css-layout to React Native.

This means the following will now work:

    <View style={{backgroundColor: 'blue', aspectRatio: 1}}/>

Reviewed By: javache

Differential Revision: D4226472

fbshipit-source-id: c8709a7c0abbf77089a4e867879b42dcd9116f65
2016-11-23 07:43:28 -08:00
Martin Konicek 1488725db3 Use a CDN to download Boost
Summary:
Downloading from the CDN is much faster than from SourceForge, both on my home WiFi and at the office.

I checked using the `diff` utility that both files are identical.

**Test Plan**

Circle CI build on this PR.
Closes https://github.com/facebook/react-native/pull/11087

Differential Revision: D4226538

fbshipit-source-id: a30ec1d94fe3228342c4a198bf65df7a95e0c005
2016-11-23 06:58:27 -08:00
Adam Comella 1b870d2019 Android: Add disableExtractUI prop to TextInput on Android
Summary:
On Android, if there is a small amount of space available around a text input (e.g. landscape orientation on a phone), Android may choose to have the user edit the text inside of a full screen text input mode. This behavior isn't always desirable. For example, if your app offers some UI controls for controlling the formatting of the text, you want the controls to be visible while the user is editing the text. This Android feature conflicts with that desired experience because the UI controls would be hidden while the text is being edited.

The `disableExtractUI` prop enables developers to choose whether or not Android's full screen text input editing mode is enabled. When this prop is true, Android's `IME_FLAG_NO_EXTRACT_UI` flag is passed to the `setImeOptions` method.

**Test plan (required)**

Verified `disableExtractUI` works for both `true` and `false` values in a test app.

My team is also using this change in our app.

Adam Comella
Microsoft Corp.
Closes https://github.com/facebook/react-native/pull/10900

Differential Revision: D4226483

Pulled By: mkonicek

fbshipit-source-id: 8f1055f6e612b05bafabe6f07a3705dd8788e3da
2016-11-23 06:43:50 -08:00
Janic Duplessis b49e7afe47 Dispatch native handled events to JS
Summary:
When native events where handled they were not sent to JS as an optimization but this caused some issues. One of the major one is touches are not handled properly inside a ScrollView with an Animated.event because it doesn't receive scroll events so it can't cancel the touch if the user scrolled.
Closes https://github.com/facebook/react-native/pull/10981

Differential Revision: D4226403

Pulled By: astreet

fbshipit-source-id: 41278d3ed4b684af142d9e273b11b974eb679879
2016-11-23 05:43:35 -08:00
Emil Sjolander dad520476e Fixup recent fix to flex basis and put it behind an experimental flag
Reviewed By: gkassabli

Differential Revision: D4222910

fbshipit-source-id: d693482441fcc4d37a288e2e3529057a04f60541
2016-11-23 05:28:48 -08:00
Andy Street 68c6d71cea BREAKING [react_native] Don't create CSSNodes for virtual shadow nodes
Summary:
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

fbshipit-source-id: b8dc083fff420eb94180f669dd49389136111ecb
2016-11-23 05:13:28 -08:00
Pandiarajan Nagarajan eaccd7e82e Android datepicker mode configurations added
Summary:
Currently, The **DatePickerAndroid** component opens the native date picker with default mode. We can't able to change the mode via configurations. To support android **[date-picker mode](https://developer.android.com/reference/android/widget/DatePicker.html)**, existing component needs to be changed.

**For Android >= 5.0**, The DatePickerDialog doesn't provide the default method to change the mode of a date picker.  So I have added custom theme which will support two kinds of **mode('spinner','calendar')** ref:https://developer.android.com/reference/android/R.attr.html#datePickerStyle.

**For Android < 5.0,** The DatePickerDialog provides the default method to change the mode of a date picker. ref:https://developer.android.com/reference/android/widget/DatePicker.html#setCalendarViewShown(boolean).

With the help of **Build.VERSION.SDK_INT** I have done the above functionality with limited lines of code changes and also I have added the example to UIExplorer.

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

Differential Revision: D4176089

Pulled By: ericvicenti

fbshipit-source-id: 7dfa9101214501ac2124bda7ee273a538f04e7cf
2016-11-23 04:58:31 -08:00
Adam Comella 35e75c8cdf Android: Fix WebView crash for links of unknown schemes
Summary:
When tapping on a link in a WebView with an unknown scheme, the app would crash. For example, if you have the link "something://example/" but your device doesn't have anything to handle the "something" scheme, the app would crash when the user clicks on the link. This change handles the exception to prevent the app from crashing. Instead, the click is a no-op and the WebView doesn't navigate anywhere.

**Test plan (required)**

Verified the app no longer crashes when clicking on unknown schemes in a test app. Also, my team uses this change in our app.

Adam Comella
Microsoft Corp.
Closes https://github.com/facebook/react-native/pull/10903

Differential Revision: D4226371

Pulled By: mkonicek

fbshipit-source-id: a6d3957806c6063e74fe055b0979cb9d1ce40e51
2016-11-23 04:43:26 -08:00
Adam Comella ea913e4691 Android: Update coalesce to prefer newest event
Summary:
The only callsite of `coalesce` looks like this:

```
newEvent.coalesce(oldEvent);
```

The default `coalesce` implementation returns the event with the most recent timestamp. When the events have the same timestamp then, using the variable names from above, `coalesce` returns `oldEvent`.

This change updates `coalesce`'s implementation to make it explicit that it returns `this` (`newEvent` in the variable names from above) in the case of a tie.

The motivation for this change is related to scroll events. In my team's app, we were seeing scroll events being emitted with the same timestamp and the coalescing logic was causing the oldest scroll event to be chosen. This was causing our JavaScript code to receive stale scroll information and the way the JavaScript code utilized this stale scroll information resulted in the ScrollView settling on the wrong scroll position.

**Test plan (required)**

Verified that scroll events work properly in a ScrollView in a test app. Also, my team's app uses this
Closes https://github.com/facebook/react-native/pull/11080

Differential Revision: D4226152

Pulled By: andreicoman11

fbshipit-source-id: d28a2569225ca95de662f2239a0fa14de0540a7d
2016-11-23 02:13:30 -08:00
Adam Comella aa85408f56 Android: Fix inconsistency with fractional TextInput padding
Summary:
TextInput rounds padding down with `floor` when measuring. However, it rounds padding up with `ceil` when rendering.

This change makes things consistent by moving TextInput's rendering code to use `floor` as well. It looks like this is the intended behavior because commit bdff10b moved measuring from `ceil` to `floor`. It looks like TextInput's rendering code was just overlooked in that commit.

**Test plan (required)**

Verified TextInput padding works in a test app. Also, my team uses this change in our app.

Adam Comella
Microsoft Corp.
Closes https://github.com/facebook/react-native/pull/11003

Differential Revision: D4220855

Pulled By: mkonicek

fbshipit-source-id: 95349867ef89c021a8441b383a09052ca0dd569c
2016-11-22 10:58:24 -08:00
Lukas Woehrl 1c69b61c26 Added feature to use rounded values
Summary:
Added an experimental feature to allow to use only rounded values. See #184. It's not a perfect solution and definitely  can be further improved. I'm looking forward to your ideas.
Closes https://github.com/facebook/css-layout/pull/256

Reviewed By: splhack

Differential Revision: D4214168

Pulled By: emilsjolander

fbshipit-source-id: 6293352d479b7b4dad258eb3f9e0afaa11cf7236
2016-11-22 05:43:26 -08:00
Michał Gregorczyk 2ca507bf9e Remove supported platforms from JSC and all the things that depends on it
Reviewed By: bnham

Differential Revision: D4213580

fbshipit-source-id: 3830c15b0097030a4e4611aac814b12e1d6ae696
2016-11-21 16:43:31 -08:00
Michał Gregorczyk b1bdae99c0 Use jni int types rather than uint64/32/16_t in JSCPerfLogging.cpp
Reviewed By: bnham

Differential Revision: D4213497

fbshipit-source-id: 47e0e7d72891e1070c350a60fb7d3597e99d49a1
2016-11-21 16:43:31 -08:00
Emil Sjolander e1df3c8782 Add aspectRatio style property
Reviewed By: gkassabli

Differential Revision: D4211458

fbshipit-source-id: f8d0d318369c7b529ee29e61a52b17d0cf3b396d
2016-11-21 10:13:34 -08:00
Andy Street 48bb3648c5 Drop CSSNode pool on low memory when app is backgrounded
Summary:
Depends on D4189532

Drops the CSSNodePool when memory gets low.

Reviewed By: emilsjolander

Differential Revision: D4190264

fbshipit-source-id: 94cd36d877372e0d6ebdd989661af74bde41486d
2016-11-21 09:13:37 -08:00
Andy Street bd8745b1fd Recycle CSSNodes
Summary: 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

fbshipit-source-id: 46583546f71a8c59853e1dd124de31657b3c617b
2016-11-21 09:13:37 -08:00
Andy Street d63ba47b59 BREAKING [react_native] Move to new C-based implementation of css-layout in RN Android
Summary:
Moves from CSSNodeDEPRECATED to CSSNode. This has shown to be a huge performance win for layout time within FB.

This is BREAKING because CSSNode contains bug fixes that were not migrated to CSSNodeDEPRECATED which may change the way your layout appears. The most common of these by far involves `flex: 1`.

Previously, developers had to put `flex: 1` in many places it didn't belong in order to work around a bug in css-layout. Now `flex: 1` is treated properly and, unfortunately, this means that your layout may no longer look correct. Specifically, you may see that your layout looks collapsed, or children don't render. The fix is to simply remove `flex: 1` from those containers.

Reviewed By: emilsjolander

Differential Revision: D3992787

fbshipit-source-id: 7a3a2a34a8941c0524e6ba3c5379e434d3e03247
2016-11-21 06:28:30 -08:00
Emil Sjolander 15f848e8d8 Only skip updating computed flex basis within the same generation
Reviewed By: dshahidehpour

Differential Revision: D4207106

fbshipit-source-id: fc1063ca79ecf75f6101aadded53bca96cb0585d
2016-11-20 05:13:28 -08:00
Pieter De Baets 892231545b Remove duplicate definition of nativeLoggingHook
Reviewed By: lexs

Differential Revision: D4160267

fbshipit-source-id: 8e23ea355095f1f94610068010b7cdf385d69e40
2016-11-18 06:28:48 -08:00
leeight 1604f10889 Cleanup import *
Summary:
Cleanup import * from some java files.

**Test plan (required)**

manually run `./scripts/run-android-local-unit-tests.sh`
Closes https://github.com/facebook/react-native/pull/11009

Differential Revision: D4204415

Pulled By: javache

fbshipit-source-id: 52579c05f44471988671e7dcdcf6109203e20929
2016-11-18 05:58:25 -08:00
Kazuki Sakamoto 2af1de283c CSSNodeCopyStyle API for Java and C#
Reviewed By: emilsjolander

Differential Revision: D4189954

fbshipit-source-id: 10759fdb27bf67350d3151614f7815aa09bf7e04
2016-11-17 09:13:32 -08:00
Michał Gregorczyk 32670371e4 Evacuate unpacking logic from RN
Reviewed By: amnn

Differential Revision: D4186902

fbshipit-source-id: 02d8fe176940a678dc8f8d9c0bcf43732f45bde5
2016-11-17 03:13:44 -08:00
Emil Sjolander a07abe7188 Correctly translate nowrap -> NO_WRAP
Summary: The java enum was recently changed from NOWRAP -> NO_WRAP so the translation from js failed. This fixes that.

Reviewed By: limichaelc

Differential Revision: D4186869

fbshipit-source-id: fe35211a6632d80356d35a01a079279ef4bd7006
2016-11-15 18:58:37 -08:00
Andrew Jack c2a55baf80 Prevent hitslop crash on Android
Summary:
**Motivation**
Currently to use the `hitSlop` property on Android you must define the object properties `left`, `top`, `right`, and `bottom` or it will crash. iOS allows omitting object properties from the hitSlop.

This change guards and allows the `hitSlop` object properties to be optional like iOS.

**Test plan (required)**

Run the [example](f930270b00/Examples/UIExplorer/js/TouchableExample.js (L318)) and omit a hitslop property and check it does not crash.
Closes https://github.com/facebook/react-native/pull/10952

Differential Revision: D4182815

Pulled By: ericvicenti

fbshipit-source-id: 07d7aca67b5739d5d1939b257476c24dcb10cbb0
2016-11-15 09:29:06 -08:00