Skip to content

Commit

Permalink
https://github.com/AndreiMisiukevich/ContextMenu/issues/5
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Sep 27, 2018
1 parent 5520cef commit 805ab45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 9 additions & 12 deletions ContextMenu/SideActionBarCell.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Xamarin.Forms;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace ContextMenu
{
public class SideActionBarCell : BaseActionViewCell
{
private static readonly Dictionary<Element, BaseActionViewCell> _cellBindings = new Dictionary<Element, BaseActionViewCell>();
public static SideActionBarCell LastOpenedCell { get; private set; }

public SideActionBarCell()
{
Expand All @@ -15,27 +16,23 @@ public SideActionBarCell()

protected virtual void OnTouchStarted(BaseActionViewCell sender)
{
if (_cellBindings.TryGetValue(Parent, out BaseActionViewCell cell))
if (LastOpenedCell == this)
{
if (cell == this)
{
return;
}
cell.ForceClose();
return;
}
_cellBindings[Parent] = this;
LastOpenedCell?.ForceClose();
LastOpenedCell = this;
}

protected override void SetContextView(View context)
=> (View as ContextMenuScrollView).ContextView = context;

protected override void OnDisappearing()
{
base.OnDisappearing();
if (_cellBindings.TryGetValue(Parent, out BaseActionViewCell cell) && cell == this)
if (this == LastOpenedCell)
{
ForceClose(false);
_cellBindings.Remove(Parent);
LastOpenedCell?.ForceClose(false);
LastOpenedCell = null;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchArch>x86_64</MtouchArch>
<MtouchLink>None</MtouchLink>
<MtouchLink>SdkOnly</MtouchLink>
<MtouchDebug>true</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
Expand Down

0 comments on commit 805ab45

Please sign in to comment.