Skip to content

Commit 67cf0d5

Browse files
authored
fix(ViewProps): Update layout-only view props (microsoft#1153)
* With these view props missing from the layout-only list, extra views are being created that are truly layout-only. * Views with `pointerEvents` prop values of `box-none` and `auto` can be collapsed.
1 parent 2cc6978 commit 67cf0d5

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

ReactWindows/ReactNative.Shared/UIManager/NativeViewHierarchyOptimizer.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#define ENABLED
2-
3-
using System;
4-
using System.Collections.Generic;
1+
using System.Collections.Generic;
2+
#if !DISABLE_NATIVE_VIEW_HIERARCHY_OPTIMIZER
53
using System.Linq;
4+
#endif
65

76
namespace ReactNative.UIManager
87
{
@@ -80,7 +79,7 @@ public void HandleCreateView(
8079
ThemedReactContext themedContext,
8180
ReactStylesDiffMap initialProperties)
8281
{
83-
#if !ENABLED
82+
#if DISABLE_NATIVE_VIEW_HIERARCHY_OPTIMIZER
8483
_uiViewOperationQueue.EnqueueCreateView(
8584
themedContext,
8685
node.ReactTag,
@@ -115,7 +114,7 @@ public void HandleCreateView(
115114
/// <param name="props">The properties.</param>
116115
public void HandleUpdateView(ReactShadowNode node, string className, ReactStylesDiffMap props)
117116
{
118-
#if !ENABLED
117+
#if DISABLE_NATIVE_VIEW_HIERARCHY_OPTIMIZER
119118
_uiViewOperationQueue.EnqueueUpdateProperties(node.ReactTag, className, props);
120119
#else
121120
var needsToLeaveLayoutOnly = node.IsLayoutOnly && !IsLayoutOnlyAndCollapsible(props);
@@ -151,10 +150,10 @@ public void HandleUpdateView(ReactShadowNode node, string className, ReactStyles
151150
/// </remarks>
152151
public void HandleManageChildren(ReactShadowNode nodeToManage, int[] indexesToRemove, int[] tagsToRemove, ViewAtIndex[] viewsToAdd, int[] tagsToDelete)
153152
{
154-
#if !ENABLED
153+
#if DISABLE_NATIVE_VIEW_HIERARCHY_OPTIMIZER
155154
_uiViewOperationQueue.EnqueueManageChildren(
156155
nodeToManage.ReactTag,
157-
indicesToRemove,
156+
indexesToRemove,
158157
viewsToAdd,
159158
tagsToDelete);
160159
#else
@@ -188,7 +187,7 @@ public void HandleManageChildren(ReactShadowNode nodeToManage, int[] indexesToRe
188187
/// <param name="childrenTags">The children tags.</param>
189188
public void HandleSetChildren(ReactShadowNode nodeToManage, int[] childrenTags)
190189
{
191-
#if !ENABLED
190+
#if DISABLE_NATIVE_VIEW_HIERARCHY_OPTIMIZER
192191
_uiViewOperationQueue.EnqueueSetChildren(
193192
nodeToManage.ReactTag,
194193
childrenTags);
@@ -210,7 +209,7 @@ public void HandleSetChildren(ReactShadowNode nodeToManage, int[] childrenTags)
210209
/// <param name="node">The node.</param>
211210
public void HandleUpdateLayout(ReactShadowNode node)
212211
{
213-
#if !ENABLED
212+
#if DISABLE_NATIVE_VIEW_HIERARCHY_OPTIMIZER
214213
_uiViewOperationQueue.EnqueueUpdateLayout(
215214
node.Parent.ReactTag,
216215
node.ReactTag,
@@ -246,7 +245,7 @@ public void HandleRemoveNode(ReactShadowNode node)
246245
node.RemoveAllNativeChildren();
247246
}
248247

249-
#if ENABLED
248+
#if !DISABLE_NATIVE_VIEW_HIERARCHY_OPTIMIZER
250249
private void AddNodeToNode(ReactShadowNode parent, ReactShadowNode child, int index)
251250
{
252251
var indexInNativeChildren = parent.GetNativeOffsetForChild(parent.GetChildAt(index));
@@ -518,7 +517,7 @@ private bool IsLayoutOnlyAndCollapsible(ReactStylesDiffMap props)
518517

519518
foreach (var key in props.Keys)
520519
{
521-
if (!ViewProps.IsLayoutOnly(key))
520+
if (!ViewProps.IsLayoutOnly(props, key))
522521
{
523522
return false;
524523
}

ReactWindows/ReactNative.Shared/UIManager/ViewProps.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using Newtonsoft.Json.Linq;
2+
using System.Collections.Generic;
23

34
namespace ReactNative.UIManager
45
{
@@ -57,6 +58,9 @@ public static class ViewProps
5758

5859
public const string AspectRatio = "aspectRatio";
5960

61+
// Props that sometimes may prevent us from collapsing views
62+
public static string PointerEvents = "pointerEvents";
63+
6064
// Properties that affect more than just layout
6165
public const string Disabled = "disabled";
6266
public const string BackgroundColor = "backgroundColor";
@@ -138,10 +142,15 @@ public static class ViewProps
138142
AlignSelf,
139143
Collapsible,
140144
Flex,
145+
FlexBasis,
141146
FlexDirection,
147+
FlexGrow,
148+
FlexShrink,
142149
FlexWrap,
143150
JustifyContent,
144151
Overflow,
152+
AlignContent,
153+
Display,
145154

146155
/* position */
147156
Position,
@@ -180,13 +189,24 @@ public static class ViewProps
180189
/// <summary>
181190
/// Checks if the property key is layout-only.
182191
/// </summary>
183-
/// <param name="key">The key.</param>
192+
/// <param name="props">The prop collection.</param>
193+
/// <param name="prop">The prop name.</param>
184194
/// <returns>
185195
/// <b>true</b> if the property is layout-only, <b>false</b> otherwise.
186196
/// </returns>
187-
public static bool IsLayoutOnly(string key)
197+
public static bool IsLayoutOnly(ReactStylesDiffMap props, string prop)
188198
{
189-
return s_layoutOnlyProperties.Contains(key);
199+
if (s_layoutOnlyProperties.Contains(prop))
200+
{
201+
return true;
202+
}
203+
else if (PointerEvents == prop)
204+
{
205+
var value = props.GetProperty(prop).Value<string>();
206+
return value == "auto" || value == "box-none";
207+
}
208+
209+
return false;
190210
}
191211
}
192-
}
212+
}

0 commit comments

Comments
 (0)