2016-03-22 23:02:25 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2017-03-09 21:38:06 +03:00
|
|
|
using System.ComponentModel;
|
2016-03-22 23:02:25 +03:00
|
|
|
using System.Linq;
|
|
|
|
using Xamarin.Forms.Platform;
|
|
|
|
|
2017-03-07 22:56:24 +03:00
|
|
|
namespace Xamarin.Forms.Internals
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
|
|
|
// Mark as internal until renderers are ready for release after 1.0
|
|
|
|
[RenderWith(typeof(_NavigationMenuRenderer))]
|
2017-03-09 21:38:06 +03:00
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
2017-03-07 22:56:24 +03:00
|
|
|
public class NavigationMenu : View, INavigationMenuController, IElementConfiguration<NavigationMenu>
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
|
|
|
readonly List<Page> _targets = new List<Page>();
|
|
|
|
|
2016-08-30 20:46:14 +03:00
|
|
|
readonly Lazy<PlatformConfigurationRegistry<NavigationMenu>> _platformConfigurationRegistry;
|
|
|
|
|
|
|
|
public NavigationMenu()
|
|
|
|
{
|
|
|
|
_platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<NavigationMenu>>(() => new PlatformConfigurationRegistry<NavigationMenu>(this));
|
|
|
|
}
|
|
|
|
|
2016-03-22 23:02:25 +03:00
|
|
|
public IEnumerable<Page> Targets
|
|
|
|
{
|
|
|
|
get { return _targets; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (_targets.AsEnumerable().SequenceEqual(value))
|
|
|
|
return;
|
|
|
|
|
|
|
|
foreach (Page page in value)
|
|
|
|
{
|
|
|
|
VerifyTarget(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
OnPropertyChanging();
|
|
|
|
_targets.Clear();
|
|
|
|
_targets.AddRange(value);
|
|
|
|
OnPropertyChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Add(Page target)
|
|
|
|
{
|
|
|
|
if (_targets.Contains(target))
|
|
|
|
return;
|
|
|
|
VerifyTarget(target);
|
|
|
|
|
|
|
|
OnPropertyChanging("Targets");
|
|
|
|
_targets.Add(target);
|
|
|
|
OnPropertyChanged("Targets");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Remove(Page target)
|
|
|
|
{
|
|
|
|
if (_targets.Contains(target))
|
|
|
|
{
|
|
|
|
OnPropertyChanging("Targets");
|
|
|
|
if (_targets.Remove(target))
|
|
|
|
OnPropertyChanged("Targets");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-30 20:46:14 +03:00
|
|
|
public IPlatformElementConfiguration<T, NavigationMenu> On<T>() where T : IConfigPlatform
|
|
|
|
{
|
|
|
|
return _platformConfigurationRegistry.Value.On<T>();
|
|
|
|
}
|
|
|
|
|
2017-04-11 21:02:06 +03:00
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
|
|
public void SendTargetSelected(Page target)
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
|
|
|
Navigation.PushAsync(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyTarget(Page target)
|
|
|
|
{
|
|
|
|
if (target.Icon == null || string.IsNullOrWhiteSpace(target.Icon.File))
|
|
|
|
throw new Exception("Icon must be set for each page before adding them to a Navigation Menu");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|