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

[UWP] Fix SwipeItem NRE no setting the Text #12087

Merged
merged 4 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using Xamarin.Forms.Internals;
using Xamarin.Forms.CustomAttributes;

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

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.SwipeView)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 12079, "SwipeView crash if Text not is set on SwipeItem", PlatformAffected.UWP)]
public class Issue12079 : TestContentPage
{
const string SwipeViewId = "SwipeViewId";

protected override void Init()
{
Title = "Issue 12079";

var layout = new StackLayout
{
Margin = new Thickness(12)
};

var instructions = new Label
{
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = "Swipe to the right, if can open the SwipeView the test has passed."
};

var swipeItem = new SwipeItem
{
BackgroundColor = Color.Red,
IconImageSource = "calculator.png"
};

swipeItem.Invoked += (sender, e) =>
{
DisplayAlert("Issue12079", "Invoked", "Ok");
};

var swipeItems = new SwipeItems { swipeItem };

swipeItems.Mode = SwipeMode.Reveal;

var swipeContent = new Grid
{
BackgroundColor = Color.Gray
};

var swipeLabel = new Label
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Text = "Swipe to Right (No Text)"
};

swipeContent.Children.Add(swipeLabel);

var swipeView = new SwipeView
{
AutomationId = SwipeViewId,
HeightRequest = 60,
WidthRequest = 300,
LeftItems = swipeItems,
Content = swipeContent
};

var result = new Label();

swipeView.SwipeEnded += (sender, args) =>
{
result.Text = "Success";
};

layout.Children.Add(instructions);
layout.Children.Add(swipeView);
layout.Children.Add(result);

Content = layout;
}

#if UITEST
[Test]
[Ignore("Selenium cannot find the SwipeControl, we have to review the reason.")]
[Category(UITestCategories.SwipeView)]
public void SwipeItemNoTextWindows()
{
RunningApp.WaitForElement(SwipeViewId);
RunningApp.SwipeLeftToRight(SwipeViewId);
RunningApp.Tap(SwipeViewId);
RunningApp.WaitForElement( c => c.Marked("Success"));
RunningApp.Screenshot ("The test has passed");
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<DependentUpon>Issue11794.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue11769.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12079.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12060.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12344.xaml.cs">
<DependentUpon>Issue12344.xaml</DependentUpon>
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Forms.Platform.UAP/SwipeViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ WSwipeItems CreateSwipeItems(SwipeDirection swipeDirection)
Background = formsSwipeItem.BackgroundColor.IsDefault ? null : formsSwipeItem.BackgroundColor.ToBrush(),
Foreground = textColor.ToBrush(),
IconSource = formsSwipeItem.IconImageSource.ToWindowsIconSource(),
Text = formsSwipeItem.Text,
Text = !string.IsNullOrEmpty(formsSwipeItem.Text) ? formsSwipeItem.Text : string.Empty,
BehaviorOnInvoked = GetSwipeBehaviorOnInvoked(items.SwipeBehaviorOnInvoked)
};

Expand Down