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

Allow to use SwipeItem only with text or icon #8822

Merged
merged 2 commits into from
Jan 31, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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, 8777, "SwipeView crash if Text not is set on SwipeItem", PlatformAffected.iOS | PlatformAffected.Android)]
public class Issue8777 : TestContentPage
{
protected override void Init()
{
Title = "Issue 8777";

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("SwipeView", "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
{
HeightRequest = 60,
WidthRequest = 300,
LeftItems = swipeItems,
Content = swipeContent
};

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

Content = layout;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue8973.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7924.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8461.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue8777.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down
4 changes: 2 additions & 2 deletions Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ AView CreateSwipeItem(SwipeItem formsSwipeItem)
var swipeButton = new AButton(_context)
{
Background = new ColorDrawable(formsSwipeItem.BackgroundColor.ToAndroid()),
Text = formsSwipeItem.Text
Text = formsSwipeItem.Text ?? string.Empty
};

var textColor = GetSwipeItemColor(formsSwipeItem.BackgroundColor);
Expand All @@ -616,7 +616,7 @@ AView CreateSwipeItem(SwipeItem formsSwipeItem)
swipeButton.SetCompoundDrawables(null, drawable, null, null);
});

var textSize = !string.IsNullOrEmpty(formsSwipeItem.Text) ? (int)swipeButton.TextSize : 0;
var textSize = !string.IsNullOrEmpty(swipeButton.Text) ? (int)swipeButton.TextSize : 0;
var buttonPadding = (contentHeight - (iconSize + textSize + 6)) / 2;
swipeButton.SetPadding(0, buttonPadding, 0, buttonPadding);
swipeButton.SetOnTouchListener(null);
Expand Down