Commit Graph

9142 Commits

Author SHA1 Message Date
Andy Street 1d555bff22 BREAKING [react_native/css_layout] Update RN shadow nodes to hold CSSNode instead of extending CSSNode
Summary:
@public

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

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

Reviewed By: emilsjolander

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

Reviewed By: ahmedre

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

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

Reviewed By: splhack

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

Reviewed By: sriramramani

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

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

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

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

Reviewed By: ahmedre

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

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

Reviewed By: ahmedre

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

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

**Test plan (required)**

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

Differential Revision: D4021303

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

Reviewed By: lucasr

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

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

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

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

Reviewed By: sriramramani

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

@public

Reviewed By: lexs

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

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

Reviewed By: lexs

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

Reviewed By: kdelong

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

Reviewed By: sriramramani

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

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

Reviewed By: majak

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

Reviewed By: sriramramani

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

**The Problem**

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

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

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

**when can this happen?**

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

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

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

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

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

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

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

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

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

**Fix**

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

**One last Note**

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

Reviewed By: astreet

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

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

Reviewed By: lexs, emilsjolander

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

Reviewed By: astreet

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

Reviewed By: astreet

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

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

Reviewed By: lexs

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

Reviewed By: lexs

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

Reviewed By: astreet

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

Reviewed By: astreet

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

Reviewed By: sriramramani

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

Reviewed By: sriramramani

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

Reviewed By: lexs

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

Reviewed By: lexs

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

Reviewed By: sriramramani

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

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

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

Reviewed By: emilsjolander

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

Reviewed By: ahmedre

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

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

Reviewed By: ahmedre

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

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

Reviewed By: ahmedre

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

Reviewed By: ahmedre

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

Reviewed By: lucasr

Differential Revision: D3648793
2016-12-19 13:40:31 -08:00