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

Shell hamburger #5961

Merged
merged 4 commits into from Apr 25, 2019
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
2 changes: 0 additions & 2 deletions Xamarin.Forms.Platform.Android/PickerManager.cs
Expand Up @@ -79,8 +79,6 @@ public void OnClick(global::Android.Views.View v)
renderer1.OnClick();
else if (picker?.Parent?.Parent?.Parent is IPickerRenderer renderer2)
renderer2.OnClick();
else
throw new System.Exception("Renderer not found temp check for Shane things");
}
}
}
Expand Down
50 changes: 47 additions & 3 deletions Xamarin.Forms.Platform.iOS/Renderers/ShellPageRendererTracker.cs
@@ -1,4 +1,5 @@
using CoreGraphics;
using Foundation;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
Expand Down Expand Up @@ -54,13 +55,15 @@ public Page Page
UISearchController _searchController;
SearchHandler _searchHandler;
Page _page;
NSCache _nSCache;

BackButtonBehavior BackButtonBehavior { get; set; }
UINavigationItem NavigationItem { get; set; }

public ShellPageRendererTracker(IShellContext context)
{
_context = context;
_nSCache = new NSCache();
}

public async void OnFlyoutBehaviorChanged(FlyoutBehavior behavior)
Expand Down Expand Up @@ -247,14 +250,55 @@ async Task SetDrawerArrowDrawableFromFlyoutIcon()
}
item = item?.Parent;
}
if (image == null)
image = "3bar.png";
var icon = await image.GetNativeImageAsync();

UIImage icon = null;

if (image != null)
icon = await image.GetNativeImageAsync();
else
icon = DrawHamburger();


var barButtonItem = new UIBarButtonItem(icon, UIBarButtonItemStyle.Plain, OnMenuButtonPressed);

barButtonItem.AccessibilityIdentifier = "OK";
NavigationItem.LeftBarButtonItem = barButtonItem;
}

UIImage DrawHamburger()
{
const string hamburgerKey = "Hamburger";
UIImage img = (UIImage)_nSCache.ObjectForKey((NSString)hamburgerKey);

if (img != null)
return img;

var rect = new CGRect(0, 0, 23f, 23f);

UIGraphics.BeginImageContextWithOptions(rect.Size, false, 0);
var ctx = UIGraphics.GetCurrentContext();
ctx.SaveState();
ctx.SetStrokeColor(UIColor.Blue.CGColor);

float size = 3f;
float start = 4f;
ctx.SetLineWidth(size);

for(int i = 0; i< 3; i++)
{
ctx.MoveTo(1f, start + i * (size * 2));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Just like LOGO writer.

ctx.AddLineToPoint(22f, start + i * (size * 2));
ctx.StrokePath();
}

ctx.RestoreState();
img = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();

_nSCache.SetObjectforKey(img, (NSString)hamburgerKey);
return img;
}

void OnMenuButtonPressed(object sender, EventArgs e)
{
_context.Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, true);
Expand Down
Binary file removed Xamarin.Forms.Platform.iOS/Resources/3bar.png
Binary file not shown.
Binary file removed Xamarin.Forms.Platform.iOS/Resources/3bar@2x.png
Binary file not shown.
6 changes: 0 additions & 6 deletions Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj
Expand Up @@ -40,9 +40,6 @@
<Reference Include="Xamarin.iOS" />
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup>
<BundleResource Include="Resources\3bar%402x.png" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)ContextActionCell.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ContextScrollViewDelegate.cs" />
Expand Down Expand Up @@ -266,8 +263,5 @@
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<BundleResource Include="Resources\3bar.png" />
</ItemGroup>
<ItemGroup />
</Project>