summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradrianknight89 <adrianknight89@outlook.com>2016-12-06 06:14:38 -0600
committerRui Marinho <me@ruimarinho.net>2016-12-06 12:14:38 +0000
commit10c65d035869fdc587f6ddddc0d472033af61ee6 (patch)
tree27a0c6fe105daaef87bc7b9120335301d97de828
parent5a2cb89775e4de1fe8b8e1d4b673612e5f41f94a (diff)
downloadxamarin-forms-10c65d035869fdc587f6ddddc0d472033af61ee6.tar.gz
xamarin-forms-10c65d035869fdc587f6ddddc0d472033af61ee6.tar.bz2
xamarin-forms-10c65d035869fdc587f6ddddc0d472033af61ee6.zip
[Android] Dismiss context menu when view cell is removed (#568)
* close context action when cell is no longer available * rename method
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla36846.cs106
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Platform.Android/CellAdapter.cs11
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs9
4 files changed, 117 insertions, 10 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla36846.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla36846.cs
new file mode 100644
index 00000000..3a58f8b8
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla36846.cs
@@ -0,0 +1,106 @@
+´╗┐using System.Collections.ObjectModel;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+// Apply the default category of "Issues" to all of the tests in this assembly
+// We use this as a catch-all for tests which haven't been individually categorized
+#if UITEST
+[assembly: NUnit.Framework.Category("Issues")]
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 36846, "ActionBar does not dismiss when content which called it is removed", PlatformAffected.Android)]
+ public class Bugzilla36846 : TestNavigationPage // or TestMasterDetailPage, etc ...
+ {
+ protected override void Init()
+ {
+ PushAsync(new ListWithLongPress());
+ }
+ }
+
+ public class ListWithLongPress : ContentPage
+ {
+ public ObservableCollection<string> MyCollection { get; set; }
+
+ public ListWithLongPress()
+ {
+ MyCollection = new ObservableCollection<string>();
+ PopulateCollection();
+
+ var stackLayout = new StackLayout
+ {
+ Orientation = StackOrientation.Vertical
+ };
+
+ var listView = new ListView
+ {
+ HasUnevenRows = true,
+ ItemsSource = MyCollection,
+ ItemTemplate = new DataTemplate(() =>
+ {
+ var viewCell = new ViewCell();
+
+ var grid = new Grid
+ {
+ Padding = new Thickness(0, 5, 0, 5),
+ RowSpacing = 3
+ };
+
+ var label = new Label();
+ label.SetBinding(Label.TextProperty, new Binding("."));
+ grid.Children.Add(label);
+
+ viewCell.ContextActions.Add(new MenuItem { Text = "Edit" });
+ viewCell.ContextActions.Add(new MenuItem { Text = "Delete", IsDestructive = true });
+
+ viewCell.View = grid;
+
+ return viewCell;
+ })
+ };
+ stackLayout.Children.Add(listView);
+
+ var button1 = new Button
+ {
+ Text = "Clear list",
+ Command = new Command(() => { MyCollection.Clear(); })
+ };
+ stackLayout.Children.Add(button1);
+
+ var button2 = new Button
+ {
+ Text = "Remove last item",
+ Command = new Command(() =>
+ {
+ if (MyCollection.Count > 0)
+ MyCollection.RemoveAt(MyCollection.Count - 1);
+ })
+ };
+ stackLayout.Children.Add(button2);
+
+ var button3 = new Button
+ {
+ Text = "Load items",
+ Command = new Command(PopulateCollection)
+ };
+ stackLayout.Children.Add(button3);
+
+ Content = stackLayout;
+ }
+
+ void PopulateCollection()
+ {
+ for (var i = 0; i < 10; i++)
+ {
+ MyCollection.Add("This is a Dummy Item #" + i);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index 4c829b44..21d7a440 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -74,6 +74,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla36649.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla36559.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla36171.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla36846.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla36955.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla37462.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla37841.cs" />
diff --git a/Xamarin.Forms.Platform.Android/CellAdapter.cs b/Xamarin.Forms.Platform.Android/CellAdapter.cs
index 03957d37..7664834b 100644
--- a/Xamarin.Forms.Platform.Android/CellAdapter.cs
+++ b/Xamarin.Forms.Platform.Android/CellAdapter.cs
@@ -174,12 +174,10 @@ namespace Xamarin.Forms.Platform.Android
view.SetBackgroundResource(0);
}
- internal void CloseContextAction()
+ internal void CloseContextActions()
{
- if (_actionMode != null)
- _actionMode.Finish();
- if (_supportActionMode != null)
- _supportActionMode.Finish();
+ _actionMode?.Finish();
+ _supportActionMode?.Finish();
}
void CreateContextMenu(IMenu menu)
@@ -226,8 +224,7 @@ namespace Xamarin.Forms.Platform.Android
{
if (!cell.HasContextActions)
{
- _actionMode?.Finish();
- _supportActionMode?.Finish();
+ CloseContextActions();
return false;
}
diff --git a/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs b/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs
index 51c603c4..245c3d74 100644
--- a/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs
+++ b/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs
@@ -54,9 +54,9 @@ namespace Xamarin.Forms.Platform.Android
var platform = _listView.Platform;
if (platform.GetType() == typeof(AppCompat.Platform))
- MessagingCenter.Subscribe<AppCompat.Platform>(this, AppCompat.Platform.CloseContextActionsSignalName, p => CloseContextAction());
+ MessagingCenter.Subscribe<AppCompat.Platform>(this, AppCompat.Platform.CloseContextActionsSignalName, p => CloseContextActions());
else
- MessagingCenter.Subscribe<Platform>(this, Platform.CloseContextActionsSignalName, p => CloseContextAction());
+ MessagingCenter.Subscribe<Platform>(this, Platform.CloseContextActionsSignalName, p => CloseContextActions());
}
public override int Count
@@ -321,7 +321,7 @@ namespace Xamarin.Forms.Platform.Android
{
if (disposing)
{
- CloseContextAction();
+ CloseContextActions();
var platform = _listView.Platform;
if (platform.GetType() == typeof(AppCompat.Platform))
@@ -445,6 +445,9 @@ namespace Xamarin.Forms.Platform.Android
void OnDataChanged()
{
+ if (ActionModeContext != null && !TemplatedItemsView.TemplatedItems.Contains(ActionModeContext))
+ CloseContextActions();
+
if (IsAttachedToWindow)
NotifyDataSetChanged();
else