Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Isolate the TemplatedView check inside Platform.cs to just RadioButto…
Browse files Browse the repository at this point in the history
…n until we can provide a more generalized fix (#13279)

* UI Test

* - Hack fix for now

* - fiix UI Test wording

* - apply to UWP

* - add UI Test for RB Templates

* - fix categories
  • Loading branch information
PureWeen committed Jan 5, 2021
1 parent 3763db8 commit cfd463f
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 17 deletions.
14 changes: 13 additions & 1 deletion Xamarin.Forms.ControlGallery.Android/_12484CustomRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ protected override void OnElementChanged(ElementChangedEventArgs<Issue12484Custo
{
base.OnElementChanged(e);

Console.WriteLine("Issue12484 Test passed.");
if(e.NewElement.Children[0] is Issue12484CustomView.Issue12484Template t &&
t.Content is StackLayout g)
{
var label = new Label
{
AutomationId = "Success",
Text = "Success",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};

g.Children.Add(label);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,16 @@ public class Issue12484Template : ContentView
{
public Issue12484Template()
{
var label = new Label
var content = new StackLayout()
{
AutomationId = "Success",
Text = "If this text appear, the test has passed.",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
Children =
{
new Label()
{
Text = "If a label with text `Success` does not show up this test has failed"
}
}
};

var content = new Grid();
content.Children.Add(label);

Content = content;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.RadioButton)]
#endif

[Preserve(AllMembers = true)]
[Issue(IssueTracker.None, 0, "RadioButton: Template From Style", PlatformAffected.All)]
public class RadioButtonTemplateFromStyle : TestNavigationPage
{
protected override void Init()
{
#if APP
PushAsync(new GalleryPages.RadioButtonGalleries.TemplateFromStyle());
#endif
}

#if UITEST
[Test]
public void ContentRenderers()
{
RunningApp.WaitForElement("A");
RunningApp.WaitForElement("B");
RunningApp.WaitForElement("C");
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewGroupTypeIssue.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11214.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13109.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RadioButtonTemplateFromStyle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ShellWithCustomRendererDisabledAnimations.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ShellFlyoutContent.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue4720.cs" />
Expand Down
18 changes: 15 additions & 3 deletions Xamarin.Forms.Platform.Android/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,23 @@ public static IVisualElementRenderer CreateRenderer(VisualElement element)

internal static IVisualElementRenderer CreateRenderer(VisualElement element, Context context)
{
IVisualElementRenderer renderer = Registrar.Registered.GetHandlerForObject<IVisualElementRenderer>(element, context)
?? new DefaultRenderer(context);
IVisualElementRenderer renderer = null;

renderer.SetElement(element);
// temporary hack to fix the following issues
// https://github.com/xamarin/Xamarin.Forms/issues/13261
// https://github.com/xamarin/Xamarin.Forms/issues/12484
if (element is RadioButton tv && tv.ResolveControlTemplate() != null)
{
renderer = new DefaultRenderer(context);
}

if (renderer == null)
{
renderer = Registrar.Registered.GetHandlerForObject<IVisualElementRenderer>(element, context)
?? new DefaultRenderer(context);
}

renderer.SetElement(element);
return renderer;
}

Expand Down
5 changes: 4 additions & 1 deletion Xamarin.Forms.Platform.UAP/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public static IVisualElementRenderer CreateRenderer(VisualElement element)

IVisualElementRenderer renderer = null;

if (element is TemplatedView tv && tv.ResolveControlTemplate() != null)
// temporary hack to fix the following issues
// https://github.com/xamarin/Xamarin.Forms/issues/13261
// https://github.com/xamarin/Xamarin.Forms/issues/12484
if (element is RadioButton tv && tv.ResolveControlTemplate() != null)
{
renderer = new DefaultRenderer();
}
Expand Down
18 changes: 15 additions & 3 deletions Xamarin.Forms.Platform.iOS/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,21 @@ public static SizeRequest GetNativeSize(VisualElement view, double widthConstrai

public static IVisualElementRenderer CreateRenderer(VisualElement element)
{
IVisualElementRenderer renderer = Internals.Registrar.Registered.GetHandlerForObject<IVisualElementRenderer>(element)
?? new DefaultRenderer();

IVisualElementRenderer renderer = null;

// temporary hack to fix the following issues
// https://github.com/xamarin/Xamarin.Forms/issues/13261
// https://github.com/xamarin/Xamarin.Forms/issues/12484
if (element is RadioButton tv && tv.ResolveControlTemplate() != null)
{
renderer = new DefaultRenderer();
}

if (renderer == null)
{
renderer = Internals.Registrar.Registered.GetHandlerForObject<IVisualElementRenderer>(element) ?? new DefaultRenderer();
}

renderer.SetElement(element);

return renderer;
Expand Down

0 comments on commit cfd463f

Please sign in to comment.