diff --git a/SecondaryToolbarDemo/SecondaryToolbarDemo.sln b/SecondaryToolbarDemo/SecondaryToolbarDemo.sln new file mode 100644 index 0000000..4e2dedc --- /dev/null +++ b/SecondaryToolbarDemo/SecondaryToolbarDemo.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecondaryToolbarDemo", "SecondaryToolbarDemo\SecondaryToolbarDemo.csproj", "{FB3076A6-A168-462C-AA14-256949871D72}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecondaryToolbarDemo.iOS", "iOS\SecondaryToolbarDemo.iOS.csproj", "{A8A773B3-9652-487E-90F5-06FAD0EF9D69}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + Debug|iPhoneSimulator = Debug|iPhoneSimulator + Release|iPhone = Release|iPhone + Release|iPhoneSimulator = Release|iPhoneSimulator + Debug|iPhone = Debug|iPhone + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A8A773B3-9652-487E-90F5-06FAD0EF9D69}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator + {A8A773B3-9652-487E-90F5-06FAD0EF9D69}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator + {A8A773B3-9652-487E-90F5-06FAD0EF9D69}.Debug|iPhone.ActiveCfg = Debug|iPhone + {A8A773B3-9652-487E-90F5-06FAD0EF9D69}.Debug|iPhone.Build.0 = Debug|iPhone + {A8A773B3-9652-487E-90F5-06FAD0EF9D69}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator + {A8A773B3-9652-487E-90F5-06FAD0EF9D69}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator + {A8A773B3-9652-487E-90F5-06FAD0EF9D69}.Release|Any CPU.ActiveCfg = Release|iPhone + {A8A773B3-9652-487E-90F5-06FAD0EF9D69}.Release|Any CPU.Build.0 = Release|iPhone + {A8A773B3-9652-487E-90F5-06FAD0EF9D69}.Release|iPhone.ActiveCfg = Release|iPhone + {A8A773B3-9652-487E-90F5-06FAD0EF9D69}.Release|iPhone.Build.0 = Release|iPhone + {A8A773B3-9652-487E-90F5-06FAD0EF9D69}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator + {A8A773B3-9652-487E-90F5-06FAD0EF9D69}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator + {FB3076A6-A168-462C-AA14-256949871D72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB3076A6-A168-462C-AA14-256949871D72}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB3076A6-A168-462C-AA14-256949871D72}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {FB3076A6-A168-462C-AA14-256949871D72}.Debug|iPhone.Build.0 = Debug|Any CPU + {FB3076A6-A168-462C-AA14-256949871D72}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {FB3076A6-A168-462C-AA14-256949871D72}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {FB3076A6-A168-462C-AA14-256949871D72}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB3076A6-A168-462C-AA14-256949871D72}.Release|Any CPU.Build.0 = Release|Any CPU + {FB3076A6-A168-462C-AA14-256949871D72}.Release|iPhone.ActiveCfg = Release|Any CPU + {FB3076A6-A168-462C-AA14-256949871D72}.Release|iPhone.Build.0 = Release|Any CPU + {FB3076A6-A168-462C-AA14-256949871D72}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {FB3076A6-A168-462C-AA14-256949871D72}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/SecondaryToolbarDemo/SecondaryToolbarDemo/MainAppPage.xaml b/SecondaryToolbarDemo/SecondaryToolbarDemo/MainAppPage.xaml new file mode 100644 index 0000000..9d0cdeb --- /dev/null +++ b/SecondaryToolbarDemo/SecondaryToolbarDemo/MainAppPage.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/SecondaryToolbarDemo/SecondaryToolbarDemo/MainAppPage.xaml.cs b/SecondaryToolbarDemo/SecondaryToolbarDemo/MainAppPage.xaml.cs new file mode 100644 index 0000000..ac43db9 --- /dev/null +++ b/SecondaryToolbarDemo/SecondaryToolbarDemo/MainAppPage.xaml.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +using Xamarin.Forms; + +namespace SecondaryToolbarDemo +{ + public partial class MainAppPage : ContentPage + { + public MainAppPage () + { + InitializeComponent (); + } + } +} + diff --git a/SecondaryToolbarDemo/SecondaryToolbarDemo/Properties/AssemblyInfo.cs b/SecondaryToolbarDemo/SecondaryToolbarDemo/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..587e91b --- /dev/null +++ b/SecondaryToolbarDemo/SecondaryToolbarDemo/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("SecondaryToolbarDemo")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("Wintellect, LLC")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("2015 Wintellect, LLC")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/SecondaryToolbarDemo/SecondaryToolbarDemo/SecondaryToolbarDemo.cs b/SecondaryToolbarDemo/SecondaryToolbarDemo/SecondaryToolbarDemo.cs new file mode 100644 index 0000000..bbb25e2 --- /dev/null +++ b/SecondaryToolbarDemo/SecondaryToolbarDemo/SecondaryToolbarDemo.cs @@ -0,0 +1,21 @@ +using Xamarin.Forms; + +namespace SecondaryToolbarDemo +{ + public class App : Application + { + public Command ShareCommand { get; private set; } + + public App () + { + ShareCommand = new Command (OnShare); + MainPage = new NavigationPage (new MainAppPage { BindingContext = this }); + } + + void OnShare() + { + MainPage.DisplayAlert ("Toolbar Demo", "Hello from the toolbar!", "WHATEV"); + } + } +} + diff --git a/SecondaryToolbarDemo/SecondaryToolbarDemo/SecondaryToolbarDemo.csproj b/SecondaryToolbarDemo/SecondaryToolbarDemo/SecondaryToolbarDemo.csproj new file mode 100644 index 0000000..ae3beeb --- /dev/null +++ b/SecondaryToolbarDemo/SecondaryToolbarDemo/SecondaryToolbarDemo.csproj @@ -0,0 +1,60 @@ + + + + Debug + AnyCPU + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {FB3076A6-A168-462C-AA14-256949871D72} + Library + SecondaryToolbarDemo + SecondaryToolbarDemo + v4.5 + Profile78 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + + + + + + MainAppPage.xaml + + + + + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Core.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Xaml.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Platform.dll + + + + + + + + MSBuild:UpdateDesignTimeXaml + + + \ No newline at end of file diff --git a/SecondaryToolbarDemo/SecondaryToolbarDemo/packages.config b/SecondaryToolbarDemo/SecondaryToolbarDemo/packages.config new file mode 100644 index 0000000..192ce41 --- /dev/null +++ b/SecondaryToolbarDemo/SecondaryToolbarDemo/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/SecondaryToolbarDemo/iOS/AppDelegate.cs b/SecondaryToolbarDemo/iOS/AppDelegate.cs new file mode 100644 index 0000000..3768a6d --- /dev/null +++ b/SecondaryToolbarDemo/iOS/AppDelegate.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using Foundation; +using UIKit; + +namespace SecondaryToolbarDemo.iOS +{ + [Register ("AppDelegate")] + public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate + { + public override bool FinishedLaunching (UIApplication app, NSDictionary options) + { + global::Xamarin.Forms.Forms.Init (); + + // Code for starting up the Xamarin Test Cloud Agent + #if ENABLE_TEST_CLOUD + Xamarin.Calabash.Start(); + #endif + + LoadApplication (new App ()); + + return base.FinishedLaunching (app, options); + } + } +} + diff --git a/SecondaryToolbarDemo/iOS/Entitlements.plist b/SecondaryToolbarDemo/iOS/Entitlements.plist new file mode 100644 index 0000000..e9a3005 --- /dev/null +++ b/SecondaryToolbarDemo/iOS/Entitlements.plist @@ -0,0 +1,7 @@ + + + + + + + diff --git a/SecondaryToolbarDemo/iOS/ITunesArtwork b/SecondaryToolbarDemo/iOS/ITunesArtwork new file mode 100644 index 0000000..d0136ea Binary files /dev/null and b/SecondaryToolbarDemo/iOS/ITunesArtwork differ diff --git a/SecondaryToolbarDemo/iOS/ITunesArtwork@2x b/SecondaryToolbarDemo/iOS/ITunesArtwork@2x new file mode 100644 index 0000000..fa2ebf7 Binary files /dev/null and b/SecondaryToolbarDemo/iOS/ITunesArtwork@2x differ diff --git a/SecondaryToolbarDemo/iOS/Info.plist b/SecondaryToolbarDemo/iOS/Info.plist new file mode 100644 index 0000000..8257e41 --- /dev/null +++ b/SecondaryToolbarDemo/iOS/Info.plist @@ -0,0 +1,64 @@ + + + + + CFBundleDisplayName + iOS Secondary Toolbar Demo + CFBundleIdentifier + com.wintellect.secondaryToolbar + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + MinimumOSVersion + 7.0 + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + CFBundleIconFiles + + Icon-60@2x + Icon-60@3x + Icon-76 + Icon-76@2x + Default + Default@2x + Default-568h + Default-568h@2x + Default-Landscape + Default-Landscape@2x + Default-Portrait + Default-Portrait@2x + Icon-Small-40 + Icon-Small-40@2x + Icon-Small-40@3x + Icon-Small + Icon-Small@2x + Icon-Small@3x + + UILaunchStoryboardName + LaunchScreen + + + diff --git a/SecondaryToolbarDemo/iOS/Main.cs b/SecondaryToolbarDemo/iOS/Main.cs new file mode 100644 index 0000000..824e05e --- /dev/null +++ b/SecondaryToolbarDemo/iOS/Main.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +using Foundation; +using UIKit; + +namespace SecondaryToolbarDemo.iOS +{ + public class Application + { + // This is the main entry point of the application. + static void Main (string[] args) + { + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main (args, null, "AppDelegate"); + } + } +} + diff --git a/SecondaryToolbarDemo/iOS/PatchedNavigationRenderer.cs b/SecondaryToolbarDemo/iOS/PatchedNavigationRenderer.cs new file mode 100644 index 0000000..aec0634 --- /dev/null +++ b/SecondaryToolbarDemo/iOS/PatchedNavigationRenderer.cs @@ -0,0 +1,56 @@ +using Xamarin.Forms.Platform.iOS; +using Xamarin.Forms; +using UIKit; +using System.Linq; +using CoreGraphics; +using System; + +[assembly: ExportRenderer (typeof(NavigationPage), typeof(SecondaryToolbarDemo.iOS.PatchedNavigationRenderer))] + +namespace SecondaryToolbarDemo.iOS +{ + public class PatchedNavigationRenderer : NavigationRenderer + { + public override void ViewWillAppear (bool animated) + { + var badBar = View.Subviews.OfType ().FirstOrDefault (v => v.GetType () != typeof(UIToolbar)); + if (badBar != null) { + badBar.RemoveFromSuperview (); + } + base.ViewWillAppear (animated); + } + + public override void ViewDidLayoutSubviews () + { + base.ViewDidLayoutSubviews (); + + UIView[] subviews = View.Subviews.Where (v => v != NavigationBar).ToArray (); + var toolBarViews = subviews.Where (v => v is UIToolbar).ToArray (); + var otherViews = subviews.Where (v => !(v is UIToolbar)).ToArray (); + + nfloat toolbarHeight = 0; + + foreach (var uIView in toolBarViews) { + uIView.SizeToFit (); + uIView.Frame = new CGRect { + X = 0, + Y = View.Bounds.Height - uIView.Frame.Height, + Width = View.Bounds.Width, + Height = uIView.Frame.Height, + }; + var thisToolbarHeight = uIView.Frame.Height; + if (toolbarHeight < thisToolbarHeight) { + toolbarHeight = thisToolbarHeight; + } + } + + var othersHeight = View.Bounds.Height - toolbarHeight; + var othersFrame = new CGRect (View.Bounds.X, View.Bounds.Y, View.Bounds.Width, othersHeight); + + foreach (var uIView in otherViews) { + uIView.Frame = othersFrame; + } + } + } + +} diff --git a/SecondaryToolbarDemo/iOS/Resources/Default-568h@2x.png b/SecondaryToolbarDemo/iOS/Resources/Default-568h@2x.png new file mode 100644 index 0000000..26c6461 Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Default-568h@2x.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Default-Portrait.png b/SecondaryToolbarDemo/iOS/Resources/Default-Portrait.png new file mode 100644 index 0000000..5d0d1ab Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Default-Portrait.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Default-Portrait@2x.png b/SecondaryToolbarDemo/iOS/Resources/Default-Portrait@2x.png new file mode 100644 index 0000000..0ee2688 Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Default-Portrait@2x.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Default.png b/SecondaryToolbarDemo/iOS/Resources/Default.png new file mode 100644 index 0000000..b74643c Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Default.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Default@2x.png b/SecondaryToolbarDemo/iOS/Resources/Default@2x.png new file mode 100644 index 0000000..dbd6bd3 Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Default@2x.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Icon-60@2x.png b/SecondaryToolbarDemo/iOS/Resources/Icon-60@2x.png new file mode 100644 index 0000000..4b03c42 Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Icon-60@2x.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Icon-60@3x.png b/SecondaryToolbarDemo/iOS/Resources/Icon-60@3x.png new file mode 100644 index 0000000..b03ca1b Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Icon-60@3x.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Icon-76.png b/SecondaryToolbarDemo/iOS/Resources/Icon-76.png new file mode 100644 index 0000000..587982e Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Icon-76.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Icon-76@2x.png b/SecondaryToolbarDemo/iOS/Resources/Icon-76@2x.png new file mode 100644 index 0000000..cd4e2c8 Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Icon-76@2x.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Icon-Small-40.png b/SecondaryToolbarDemo/iOS/Resources/Icon-Small-40.png new file mode 100644 index 0000000..6acff94 Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Icon-Small-40.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Icon-Small-40@2x.png b/SecondaryToolbarDemo/iOS/Resources/Icon-Small-40@2x.png new file mode 100644 index 0000000..b833aac Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Icon-Small-40@2x.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Icon-Small-40@3x.png b/SecondaryToolbarDemo/iOS/Resources/Icon-Small-40@3x.png new file mode 100644 index 0000000..ab8654e Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Icon-Small-40@3x.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Icon-Small.png b/SecondaryToolbarDemo/iOS/Resources/Icon-Small.png new file mode 100644 index 0000000..33db7e7 Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Icon-Small.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Icon-Small@2x.png b/SecondaryToolbarDemo/iOS/Resources/Icon-Small@2x.png new file mode 100644 index 0000000..bf45e25 Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Icon-Small@2x.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/Icon-Small@3x.png b/SecondaryToolbarDemo/iOS/Resources/Icon-Small@3x.png new file mode 100644 index 0000000..7ad3891 Binary files /dev/null and b/SecondaryToolbarDemo/iOS/Resources/Icon-Small@3x.png differ diff --git a/SecondaryToolbarDemo/iOS/Resources/LaunchScreen.storyboard b/SecondaryToolbarDemo/iOS/Resources/LaunchScreen.storyboard new file mode 100644 index 0000000..a639c2f --- /dev/null +++ b/SecondaryToolbarDemo/iOS/Resources/LaunchScreen.storyboard @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SecondaryToolbarDemo/iOS/SecondaryToolbarDemo.iOS.csproj b/SecondaryToolbarDemo/iOS/SecondaryToolbarDemo.iOS.csproj new file mode 100644 index 0000000..2e2b558 --- /dev/null +++ b/SecondaryToolbarDemo/iOS/SecondaryToolbarDemo.iOS.csproj @@ -0,0 +1,127 @@ + + + + Debug + iPhoneSimulator + {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {A8A773B3-9652-487E-90F5-06FAD0EF9D69} + Exe + SecondaryToolbarDemo.iOS + Resources + SecondaryToolbarDemo.iOS + + + true + full + false + bin\iPhoneSimulator\Debug + DEBUG;ENABLE_TEST_CLOUD; + prompt + 4 + false + i386 + None + true + true + + + full + true + bin\iPhone\Release + prompt + 4 + Entitlements.plist + ARMv7, ARM64 + false + iPhone Developer + + + full + true + bin\iPhoneSimulator\Release + prompt + 4 + i386 + false + None + + + true + full + false + bin\iPhone\Debug + DEBUG;ENABLE_TEST_CLOUD; + prompt + 4 + false + ARMv7, ARM64 + Entitlements.plist + true + iPhone Developer + true + + + + + + + + ..\packages\Xamarin.TestCloud.Agent.0.14.1\lib\Xamarin.iOS10\Calabash.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll + + + ..\packages\Xamarin.Forms.1.4.4.6392\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll + + + + + {FB3076A6-A168-462C-AA14-256949871D72} + SecondaryToolbarDemo + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SecondaryToolbarDemo/iOS/ToolbarRenderer.cs b/SecondaryToolbarDemo/iOS/ToolbarRenderer.cs new file mode 100644 index 0000000..daffca0 --- /dev/null +++ b/SecondaryToolbarDemo/iOS/ToolbarRenderer.cs @@ -0,0 +1,75 @@ +using Xamarin.Forms.Platform.iOS; +using Xamarin.Forms; +using UIKit; +using System.Linq; +using CoreGraphics; +using System; +using System.Collections.Generic; +using System.Windows.Input; + +[assembly: ExportRenderer (typeof(Page), typeof(SecondaryToolbarDemo.iOS.ToolbarRenderer))] + +namespace SecondaryToolbarDemo.iOS +{ + public class ToolbarRenderer : PageRenderer + { + UIToolbar _toolbar; + List _secondaryItems; + readonly Dictionary _buttonCommands = new Dictionary (); + + protected override void OnElementChanged (VisualElementChangedEventArgs e) + { + var page = e.NewElement as Page; + if (page != null) { + _secondaryItems = page.ToolbarItems.Where (i => i.Order == ToolbarItemOrder.Secondary).ToList (); + _secondaryItems.ForEach (t => page.ToolbarItems.Remove (t)); + } + base.OnElementChanged (e); + } + + public override void ViewWillAppear (bool animated) + { + if (_secondaryItems != null && _secondaryItems.Count > 0) { + var tools = new List (); + _buttonCommands.Clear (); + foreach (var tool in _secondaryItems) { + #pragma warning disable 618 + var systemItemName = tool.Name; + #pragma warning restore 618 + UIBarButtonItem button; + UIBarButtonSystemItem systemItem; + button = Enum.TryParse (systemItemName, out systemItem) + ? new UIBarButtonItem (systemItem, ToolClicked) + : new UIBarButtonItem (tool.Text, UIBarButtonItemStyle.Plain, ToolClicked); + _buttonCommands.Add (button, tool.Command); + tools.Add (button); + } + + NavigationController.SetToolbarHidden (false, animated); + _toolbar = new UIToolbar (CGRect.Empty) { Items = tools.ToArray () }; + NavigationController.View.Add (_toolbar); + } + + base.ViewWillAppear (animated); + } + + void ToolClicked(object sender, EventArgs args) + { + var tool = sender as UIBarButtonItem; + var command = _buttonCommands [tool]; + command.Execute (null); + } + + public override void ViewWillDisappear (bool animated) + { + if (_toolbar != null) { + NavigationController.SetToolbarHidden (true, animated); + _toolbar.RemoveFromSuperview (); + _toolbar = null; + _buttonCommands.Clear (); + } + base.ViewWillDisappear (animated); + } + } +} + diff --git a/SecondaryToolbarDemo/iOS/packages.config b/SecondaryToolbarDemo/iOS/packages.config new file mode 100644 index 0000000..5f367ac --- /dev/null +++ b/SecondaryToolbarDemo/iOS/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file