mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-07 09:20:04 +01:00
custom content page renderer for left nav items
This commit is contained in:
parent
17060a2a1b
commit
b6e7db6ecf
56
src/iOS/Renderers/CustomContentPageRenderer.cs
Normal file
56
src/iOS/Renderers/CustomContentPageRenderer.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Bit.iOS.Renderers;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
|
||||
[assembly: ExportRenderer(typeof(ContentPage), typeof(CustomContentPageRenderer))]
|
||||
namespace Bit.iOS.Renderers
|
||||
{
|
||||
public class CustomContentPageRenderer : PageRenderer
|
||||
{
|
||||
public override void ViewWillAppear(bool animated)
|
||||
{
|
||||
base.ViewWillAppear(animated);
|
||||
if(!(Element is ContentPage contentPage) || NavigationController == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var navigationItem = NavigationController.TopViewController.NavigationItem;
|
||||
var leftNativeButtons = (navigationItem.LeftBarButtonItems ?? new UIBarButtonItem[] { }).ToList();
|
||||
var rightNativeButtons = (navigationItem.RightBarButtonItems ?? new UIBarButtonItem[] { }).ToList();
|
||||
var newLeftButtons = new List<UIBarButtonItem>();
|
||||
var newRightButtons = new List<UIBarButtonItem>();
|
||||
foreach(var nativeItem in rightNativeButtons)
|
||||
{
|
||||
// Use reflection to get Xamarin private field "_item"
|
||||
var field = nativeItem.GetType().GetField("_item", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if(field == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!(field.GetValue(nativeItem) is ToolbarItem info))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(info.Priority < 0)
|
||||
{
|
||||
newLeftButtons.Add(nativeItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
newRightButtons.Add(nativeItem);
|
||||
}
|
||||
}
|
||||
foreach(var nativeItem in leftNativeButtons)
|
||||
{
|
||||
newLeftButtons.Add(nativeItem);
|
||||
}
|
||||
navigationItem.RightBarButtonItems = newRightButtons.ToArray();
|
||||
navigationItem.LeftBarButtonItems = newLeftButtons.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
@ -112,6 +112,7 @@
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="AppDelegate.cs" />
|
||||
<Compile Include="Migration\KeyChainStorageService.cs" />
|
||||
<Compile Include="Renderers\CustomContentPageRenderer.cs" />
|
||||
<Compile Include="Renderers\HybridWebViewRenderer.cs" />
|
||||
<Compile Include="Services\DeviceActionService.cs" />
|
||||
<Compile Include="Services\iOSPushNotificationHandler.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user