Commit Graph

8924 Commits

Author SHA1 Message Date
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