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

[Android/iOS] Fix programmatically open right SwipeItems #10575

Merged
merged 16 commits into from
Dec 18, 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,172 @@
using System.Collections.Generic;
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.SwipeView)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 10563, "[Bug] SwipeView Open methods does not work for RightItems", PlatformAffected.Android | PlatformAffected.iOS)]
public class Issue10563 : TestContentPage
{
const string OpenLeftId = "OpenLeftId";
const string OpenRightId = "OpenRightId";
const string OpenTopId = "OpenTopId";
const string OpenBottomId = "OpenBottomId";
const string CloseId = "CloseId";

public Issue10563()
{

}

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

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

var openLeftButton = new Button
{
AutomationId = OpenLeftId,
Text = "Open Left SwipeItem"
};

var openRightButton = new Button
{
AutomationId = OpenRightId,
Text = "Open Right SwipeItem"
};

var openTopButton = new Button
{
AutomationId = OpenTopId,
Text = "Open Top SwipeItem"
};

var openBottomButton = new Button
{
AutomationId = OpenBottomId,
Text = "Open Bottom SwipeItem"
};

var closeButton = new Button
{
AutomationId = CloseId,
Text = "Close SwipeView"
};

swipeLayout.Children.Add(openLeftButton);
swipeLayout.Children.Add(openRightButton);
swipeLayout.Children.Add(openTopButton);
swipeLayout.Children.Add(openBottomButton);
swipeLayout.Children.Add(closeButton);

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

swipeItem.Invoked += (sender, e) => { DisplayAlert("SwipeView", "SwipeItem 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 any direction"
};

swipeContent.Children.Add(swipeLabel);

var swipeView = new SwipeView
{
HeightRequest = 60,
WidthRequest = 300,
LeftItems = swipeItems,
RightItems = swipeItems,
TopItems = swipeItems,
BottomItems = swipeItems,
Content = swipeContent,
Margin = new Thickness(0, 48)
};

swipeLayout.Children.Add(swipeView);

Content = swipeLayout;

openLeftButton.Clicked += (sender, e) =>
{
swipeView.Open(OpenSwipeItem.LeftItems);
};

openRightButton.Clicked += (sender, e) =>
{
swipeView.Open(OpenSwipeItem.RightItems);
};

openTopButton.Clicked += (sender, e) =>
{
swipeView.Open(OpenSwipeItem.TopItems);
};

openBottomButton.Clicked += (sender, e) =>
{
swipeView.Open(OpenSwipeItem.BottomItems);
};

closeButton.Clicked += (sender, e) =>
{
swipeView.Close();
};
}

#if UITEST && (__ANDROID__ || __IOS__)
[Test]
public void Issue10563OpenSwipeViewTest ()
{
RunningApp.WaitForElement(OpenLeftId);
RunningApp.Tap(OpenLeftId);
RunningApp.Screenshot("Left SwipeItems");
RunningApp.Tap(CloseId);

RunningApp.WaitForElement(OpenRightId);
RunningApp.Tap(OpenRightId);
RunningApp.Screenshot("Right SwipeItems");

RunningApp.Tap(CloseId);

RunningApp.WaitForElement(OpenTopId);
RunningApp.Tap(OpenTopId);
RunningApp.Screenshot("Top SwipeItems");
RunningApp.Tap(CloseId);

RunningApp.WaitForElement(OpenBottomId);
RunningApp.Tap(OpenBottomId);
RunningApp.Screenshot("Bottom SwipeItems");
RunningApp.Tap(CloseId);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,7 @@
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue12374.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12222.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue10563.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12582.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12750.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue12541.xaml.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Xamarin.Forms.Controls.GalleryPages.SwipeViewGalleries
{
public class CloseSwipeGallery : ContentPage
public class OpenCloseSwipeGallery : ContentPage
{
public CloseSwipeGallery()
public OpenCloseSwipeGallery()
{
Title = "Open/Close SwipeView Gallery";

Expand All @@ -13,14 +13,40 @@ public CloseSwipeGallery()

var openButton = new Button
{
HorizontalOptions = LayoutOptions.Start,
Text = "Open SwipeView"
};

var closeButton = new Button
{
HorizontalOptions = LayoutOptions.Start,
Text = "Close SwipeView"
};

var animatedLayout = new StackLayout
{
HorizontalOptions = LayoutOptions.Start,
Orientation = StackOrientation.Horizontal
};

var animatedCheckBox = new CheckBox
{
IsChecked = true,
VerticalOptions = LayoutOptions.Center
};

animatedLayout.Children.Add(animatedCheckBox);
animatedLayout.Children.Add(animatedCheckBox);

var animatedLabel = new Label
{
Text = "Animated",
VerticalOptions = LayoutOptions.Center
};

animatedLayout.Children.Add(animatedLabel);

swipeLayout.Children.Add(animatedLayout);
swipeLayout.Children.Add(openButton);
swipeLayout.Children.Add(closeButton);

Expand Down Expand Up @@ -65,12 +91,14 @@ public CloseSwipeGallery()

openButton.Clicked += (sender, e) =>
{
swipeView.Open(OpenSwipeItem.LeftItems);
bool animated = animatedCheckBox.IsChecked;
swipeView.Open(OpenSwipeItem.LeftItems, animated);
};

closeButton.Clicked += (sender, e) =>
{
swipeView.Close();
bool animated = animatedCheckBox.IsChecked;
swipeView.Close(animated);
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public SwipeViewGallery()
GalleryBuilder.NavButton("SwipeItem IsVisible Gallery", () => new SwipeItemIsVisibleGallery(), Navigation),
GalleryBuilder.NavButton("SwipeTransitionMode Gallery", () => new SwipeTransitionModeGallery(), Navigation),
GalleryBuilder.NavButton("Add/Remove SwipeItems Gallery", () => new AddRemoveSwipeItemsGallery(), Navigation),
GalleryBuilder.NavButton("Open/Close SwipeView Gallery", () => new CloseSwipeGallery(), Navigation),
GalleryBuilder.NavButton("Open/Close SwipeView Gallery", () => new OpenCloseSwipeGallery(), Navigation),
GalleryBuilder.NavButton("SwipeItems Dispose Gallery", () => new SwipeItemsDisposeGallery(), Navigation)
}
}
Expand Down
16 changes: 14 additions & 2 deletions Xamarin.Forms.Core/SwipeEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,26 @@ protected BaseSwipeEventArgs(SwipeDirection swipeDirection)
public SwipeDirection SwipeDirection { get; set; }
}

public class OpenSwipeEventArgs : EventArgs
public class CloseRequestedEventArgs : EventArgs
{
public OpenSwipeEventArgs(OpenSwipeItem openSwipeItem)
public CloseRequestedEventArgs(bool animated)
{
Animated = animated;
}

public bool Animated { get; set; }
}

public class OpenRequestedEventArgs : EventArgs
{
public OpenRequestedEventArgs(OpenSwipeItem openSwipeItem, bool animated)
{
OpenSwipeItem = openSwipeItem;
Animated = animated;
}

public OpenSwipeItem OpenSwipeItem { get; set; }
public bool Animated { get; set; }
}

public class SwipeStartedEventArgs : BaseSwipeEventArgs
Expand Down
13 changes: 7 additions & 6 deletions Xamarin.Forms.Core/SwipeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,19 @@ static void OnSwipeItemsChanged(BindableObject bindable, object oldValue, object
public event EventHandler<SwipeEndedEventArgs> SwipeEnded;

[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler<OpenSwipeEventArgs> OpenRequested;
public event EventHandler<OpenRequestedEventArgs> OpenRequested;

public event EventHandler CloseRequested;
[EditorBrowsable(EditorBrowsableState.Never)]
public event EventHandler<CloseRequestedEventArgs> CloseRequested;

public void Open(OpenSwipeItem openSwipeItem)
public void Open(OpenSwipeItem openSwipeItem, bool animated = true)
{
OpenRequested?.Invoke(this, new OpenSwipeEventArgs(openSwipeItem));
OpenRequested?.Invoke(this, new OpenRequestedEventArgs(openSwipeItem, animated));
}

public void Close()
public void Close(bool animated = true)
{
CloseRequested?.Invoke(this, EventArgs.Empty);
CloseRequested?.Invoke(this, new CloseRequestedEventArgs(animated));
}

void ISwipeViewController.SendSwipeStarted(SwipeStartedEventArgs args) => SwipeStarted?.Invoke(this, args);
Expand Down
Loading