Skip to content

Commit 726d113

Browse files
rigdernrozele
authored andcommitted
Enable Images to have muliple <Text> ancestors (microsoft#749)
Prior to this change, Images with one <Text> ancestor were supported: ``` <Text> <Image /> </Text> ``` But Images with multiple <Text> ancestors resulted in an exception: ``` <Text> <Text> <Image /> </Text> </Text> ``` This change fixes the latter scenario. The problem was that some code assumed that it would only receive Inlines when actually it could also receive UIElements.
1 parent 9070e99 commit 726d113

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

ReactWindows/ReactNative/Views/Text/ReactSpanViewManager.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,17 @@ public void SetColor(Span view, uint? color)
5959
public void AddView(DependencyObject parent, DependencyObject child, int index)
6060
{
6161
var span = (Span)parent;
62-
var inline = (Inline)child;
63-
span.Inlines.Insert(index, inline);
62+
63+
var inlineChild = child as Inline;
64+
if (inlineChild == null)
65+
{
66+
inlineChild = new InlineUIContainer
67+
{
68+
Child = (UIElement)child,
69+
};
70+
}
71+
72+
span.Inlines.Insert(index, inlineChild);
6473
}
6574

6675
/// <summary>
@@ -87,7 +96,16 @@ public override ReactSpanShadowNode CreateShadowNodeInstance()
8796
public DependencyObject GetChildAt(DependencyObject parent, int index)
8897
{
8998
var span = (Span)parent;
90-
return span.Inlines[index];
99+
var child = span.Inlines[index];
100+
var childInlineContainer = child as InlineUIContainer;
101+
if (childInlineContainer != null)
102+
{
103+
return childInlineContainer.Child;
104+
}
105+
else
106+
{
107+
return child;
108+
}
91109
}
92110

93111
/// <summary>

0 commit comments

Comments
 (0)