item template attached, fix icon propagations (#6173)

* item template attached, fix icon propagations

* tabs
This commit is contained in:
Shane Neuville 2019-05-11 12:09:10 -07:00 коммит произвёл Samantha Houts
Родитель 6fb53b180a
Коммит 056ec1a099
13 изменённых файлов: 102 добавлений и 24 удалений

Просмотреть файл

@ -155,6 +155,12 @@
<AndroidResource Include="Resources\drawable\icon_search.png" />
<AndroidResource Include="Resources\drawable\icon_bookmark.png" />
<AndroidResource Include="Resources\drawable\button_add.png" />
<AndroidResource Include="Resources\drawable\gamesflyout.png" />
<AndroidResource Include="Resources\drawable\filmflyout.png" />
<AndroidResource Include="Resources\drawable\headphoneflyout.png" />
<AndroidResource Include="Resources\drawable\newspaperflyout.png" />
<AndroidResource Include="Resources\drawable\booksflyout.png" />
<AndroidResource Include="Resources\drawable\homeflyout.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\Icon.png" />

Просмотреть файл

@ -28,25 +28,33 @@
<Style x:Key="NewsShell" TargetType="Element" BasedOn="{StaticResource BaseStyle}">
<Setter Property="Shell.BackgroundColor" Value="#546DFE" />
</Style>
<DataTemplate x:Key="MenuItemTemplate">
<ContentView>
<Button Visual="Material" ImageSource="{Binding Icon}" Text="{Binding Text}" />
</ContentView>
</DataTemplate>
<DataTemplate x:Key="MenuItemTemplate">
<ContentView>
<Button Visual="Material" ImageSource="{Binding FlyoutIcon}" Text="{Binding Text}" />
</ContentView>
</DataTemplate>
<DataTemplate x:Key="ShellItemTemplate">
<ContentView BackgroundColor="LightBlue">
<StackLayout Orientation="Horizontal">
<Image Source="{Binding FlyoutIcon}"/>
<Label Text="{Binding Title}" />
</StackLayout>
</ContentView>
</DataTemplate>
</Shell.Resources>
<Shell.FlyoutHeader>
<local:FlyoutHeader />
</Shell.FlyoutHeader>
<ShellContent Title="Search" Route="search" ContentTemplate="{DataTemplate local:SearchHandlerPage}" />
<ShellContent Title="Search" Route="search" ContentTemplate="{DataTemplate local:SearchHandlerPage}" />
<ShellSection FlyoutDisplayOptions="AsMultipleItems" Route="apps" Title="My apps &amp; games" Icon="grid.png" Style="{StaticResource GreenShell}">
<ShellContent Route="updates" Title="Updates" ContentTemplate="{DataTemplate local:UpdatesPage}" />
<ShellContent Route="installed" Title="Installed" ContentTemplate="{DataTemplate local:InstalledPage}" />
<ShellContent Route="library" Title="Library" ContentTemplate="{DataTemplate local:LibraryPage}" />
</ShellSection>
<ShellContent Route="notifications" Style="{StaticResource BaseStyle}" Title="My notifications" Icon="bell.png" ContentTemplate="{DataTemplate local:NotificationsPage}" />
<ShellContent Route="notifications" Style="{StaticResource BaseStyle}" Title="My notifications" FlyoutIcon="homeflyout.png" Icon="bell.png" ContentTemplate="{DataTemplate local:NotificationsPage}" />
<ShellContent Route="subs" Title="Subscriptions" Icon="loop.png" ContentTemplate="{DataTemplate local:SubscriptionsPage}" />
@ -60,8 +68,8 @@
</ShellItem>
<ShellItem Route="store" x:Name="_storeItem" FlyoutDisplayOptions="AsMultipleItems">
<ShellContent Route="home" Style="{StaticResource GreenShell}" Title="Home" Icon="home.png" FlyoutIcon="homeflyout.png" ContentTemplate="{DataTemplate local:HomePage}" />
<ShellContent Route="list" Title="List" Icon="games.png" FlyoutIcon="gamesflyout.png" ContentTemplate="{DataTemplate local:DemoShellPage}" />
<ShellContent Shell.ItemTemplate="{StaticResource ShellItemTemplate}" Route="home" Style="{StaticResource GreenShell}" Title="Home" Icon="home.png" FlyoutIcon="homeflyout.png" ContentTemplate="{DataTemplate local:HomePage}" />
<ShellContent Route="list" Title="List" Icon="games.png" FlyoutIcon="gamesflyout.png" ContentTemplate="{DataTemplate local:DemoShellPage}" />
<ShellContent Route="games" Style="{StaticResource GreenShell}" Title="Games" Icon="games.png" FlyoutIcon="gamesflyout.png" ContentTemplate="{DataTemplate local:GamesPage}" />
<ShellContent Route="movies" Style="{StaticResource MoviesShell}" Title="Movies &amp; TV"
Icon="film.png" FlyoutIcon="filmflyout.png" ContentTemplate="{DataTemplate local:MoviesPage}">
@ -99,4 +107,11 @@
<ShellContent Route="settings" Title="Settings" Icon="gear.png" ContentTemplate="{DataTemplate local:SettingsPage}" />
<ShellItem Route="propagation" Title="Propagation">
<ShellContent Shell.NavBarIsVisible="false" Route="home" Style="{StaticResource GreenShell}" Title="No Nav" Icon="home.png" FlyoutIcon="homeflyout.png" ContentTemplate="{DataTemplate local:HomePage}" />
<ShellSection Shell.TabBarIsVisible="false" Route="activity" Title="No Tab" Icon="grid.png" Style="{StaticResource GreenShell}">
<ShellContent Route="sharednotab" Title="No Tabs" ContentTemplate="{DataTemplate local:UpdatesPage}" />
<ShellContent Route="Notificationstabs" Shell.TabBarIsVisible="true" Title="Yes Tabs" ContentTemplate="{DataTemplate local:LibraryPage}" />
</ShellSection>
</ShellItem>
</localTest:TestShell>

Просмотреть файл

@ -17,6 +17,7 @@ namespace Xamarin.Forms.Controls.XamStore
public StoreShell()
{
InitializeComponent();
CurrentItem = _storeItem;
}
protected override void Init()
@ -45,7 +46,6 @@ namespace Xamarin.Forms.Controls.XamStore
FlyoutIcon.SetAutomationPropertiesHelpText("This as Shell FlyoutIcon");
FlyoutIcon.SetAutomationPropertiesName("SHELLMAINFLYOUTICON");
CurrentItem = _storeItem;
Routing.RegisterRoute("demo", typeof(DemoShellPage));
Routing.RegisterRoute("demo/demo", typeof(DemoShellPage));
}

Просмотреть файл

@ -15,6 +15,12 @@ namespace Xamarin.Forms.Internals
if (propertyName == null || propertyName == VisualElement.VisualProperty.PropertyName)
Element.SetVisualfromParent(element);
if (propertyName == null || propertyName == Shell.NavBarIsVisibleProperty.PropertyName)
BaseShellItem.PropagateFromParent(Shell.NavBarIsVisibleProperty, element);
if (propertyName == null || propertyName == Shell.TabBarIsVisibleProperty.PropertyName)
BaseShellItem.PropagateFromParent(Shell.TabBarIsVisibleProperty, element);
foreach (var child in children)
{
if (child is IPropertyPropagationController view)

Просмотреть файл

@ -22,7 +22,7 @@ namespace Xamarin.Forms
{
return source.StartsWith(ImplicitPrefix, StringComparison.Ordinal);
}
internal static bool IsImplicit(Element source)
internal static bool IsImplicit(BindableObject source)
{
return IsImplicit(GetRoute(source));
}
@ -71,7 +71,7 @@ namespace Xamarin.Forms
return result;
}
public static string GetRoute(Element obj)
public static string GetRoute(BindableObject obj)
{
return (string)obj.GetValue(RouteProperty);
}

Просмотреть файл

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms
@ -133,6 +134,39 @@ namespace Xamarin.Forms
shellItem.FlyoutIcon = (ImageSource)newValue;
}
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
base.OnPropertyChanged(propertyName);
if (Parent != null)
{
if (propertyName == Shell.ItemTemplateProperty.PropertyName || propertyName == nameof(Parent))
Propagate(Shell.ItemTemplateProperty, this, Parent, true);
}
}
internal static void PropagateFromParent(BindableProperty property, Element me)
{
if (me == null || me.Parent == null)
return;
Propagate(property, me.Parent, me, false);
}
internal static void Propagate(BindableProperty property, BindableObject from, BindableObject to, bool onlyToImplicit)
{
if (from == null || to == null)
return;
if (onlyToImplicit && Routing.IsImplicit(from))
return;
if (to is Shell)
return;
if (from.IsSet(property) && !to.IsSet(property))
to.SetValue(property, from.GetValue(property));
}
void IPropertyPropagationController.PropagatePropertyChanged(string propertyName)
{
PropertyPropagationExtensions.PropagatePropertyChanged(propertyName, this, LogicalChildren);

Просмотреть файл

@ -10,6 +10,8 @@ namespace Xamarin.Forms
SetBinding(TitleProperty, new Binding("Text", BindingMode.OneWay, source: menuItem));
SetBinding(IconProperty, new Binding("Icon", BindingMode.OneWay, source: menuItem));
SetBinding(FlyoutIconProperty, new Binding("Icon", BindingMode.OneWay, source: menuItem));
Shell.SetMenuItemTemplate(this, Shell.GetMenuItemTemplate(MenuItem));
MenuItem.PropertyChanged += OnMenuItemPropertyChanged;
}

Просмотреть файл

@ -54,6 +54,12 @@ namespace Xamarin.Forms
public static DataTemplate GetMenuItemTemplate(BindableObject obj) => (DataTemplate)obj.GetValue(MenuItemTemplateProperty);
public static void SetMenuItemTemplate(BindableObject obj, DataTemplate menuItemTemplate) => obj.SetValue(MenuItemTemplateProperty, menuItemTemplate);
public static readonly BindableProperty ItemTemplateProperty =
BindableProperty.CreateAttached(nameof(ItemTemplate), typeof(DataTemplate), typeof(Shell), null, BindingMode.OneTime);
public static DataTemplate GetItemTemplate(BindableObject obj) => (DataTemplate)obj.GetValue(ItemTemplateProperty);
public static void SetItemTemplate(BindableObject obj, DataTemplate itemTemplate) => obj.SetValue(ItemTemplateProperty, itemTemplate);
public static BackButtonBehavior GetBackButtonBehavior(BindableObject obj) => (BackButtonBehavior)obj.GetValue(BackButtonBehaviorProperty);
public static void SetBackButtonBehavior(BindableObject obj, BackButtonBehavior behavior) => obj.SetValue(BackButtonBehaviorProperty, behavior);
@ -555,9 +561,6 @@ namespace Xamarin.Forms
public static readonly BindableProperty ItemsProperty = ItemsPropertyKey.BindableProperty;
public static readonly BindableProperty ItemTemplateProperty =
BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(Shell), null, BindingMode.OneTime);
public static readonly BindableProperty FlyoutIconProperty =
BindableProperty.Create(nameof(FlyoutIcon), typeof(ImageSource), typeof(Shell), null);
@ -630,8 +633,8 @@ namespace Xamarin.Forms
public DataTemplate ItemTemplate
{
get => (DataTemplate)GetValue(ItemTemplateProperty);
set => SetValue(ItemTemplateProperty, value);
get => GetItemTemplate(this);
set => SetItemTemplate(this, value);
}
public DataTemplate MenuItemTemplate

Просмотреть файл

@ -109,8 +109,9 @@ namespace Xamarin.Forms
shellContent.Route = Routing.GenerateImplicitRoute(pageRoute);
shellContent.Content = page;
shellContent.SetBinding(TitleProperty, new Binding("Title", BindingMode.OneWay, source: page));
shellContent.SetBinding(IconProperty, new Binding("Icon", BindingMode.OneWay, source: page));
shellContent.SetBinding(TitleProperty, new Binding(nameof(Title), BindingMode.OneWay, source: page));
shellContent.SetBinding(IconProperty, new Binding(nameof(Icon), BindingMode.OneWay, source: page));
shellContent.SetBinding(FlyoutIconProperty, new Binding(nameof(FlyoutIcon), BindingMode.OneWay, source: page));
return shellContent;
}

Просмотреть файл

@ -5,6 +5,7 @@ using System.Collections.Specialized;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Xamarin.Forms
{
@ -135,6 +136,8 @@ namespace Xamarin.Forms
result.SetBinding(TitleProperty, new Binding(nameof(Title), BindingMode.OneWay, source: shellSection));
result.SetBinding(IconProperty, new Binding(nameof(Icon), BindingMode.OneWay, source: shellSection));
result.SetBinding(FlyoutDisplayOptionsProperty, new Binding(nameof(FlyoutDisplayOptions), BindingMode.OneTime, source: shellSection));
result.SetBinding(FlyoutIconProperty, new Binding(nameof(FlyoutIcon), BindingMode.OneWay, source: shellSection));
return result;
}

Просмотреть файл

@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Xamarin.Forms
{
@ -197,8 +198,11 @@ namespace Xamarin.Forms
shellSection.Route = Routing.GenerateImplicitRoute(contentRoute);
shellSection.Items.Add(shellContent);
shellSection.SetBinding(TitleProperty, new Binding("Title", BindingMode.OneWay, source: shellContent));
shellSection.SetBinding(IconProperty, new Binding("Icon", BindingMode.OneWay, source: shellContent));
shellSection.SetBinding(TitleProperty, new Binding(nameof(Title), BindingMode.OneWay, source: shellContent));
shellSection.SetBinding(IconProperty, new Binding(nameof(Icon), BindingMode.OneWay, source: shellContent));
shellSection.SetBinding(FlyoutIconProperty, new Binding(nameof(FlyoutIcon), BindingMode.OneWay, source: shellContent));
return shellSection;
}

Просмотреть файл

@ -47,11 +47,15 @@ namespace Xamarin.Forms.Platform.Android
public override int GetItemViewType(int position)
{
var item = _listItems[position];
var dataTemplate = Shell.ItemTemplate ?? DefaultItemTemplate;
DataTemplate dataTemplate = null;
if (item.Element is IMenuItemController)
{
dataTemplate = Shell.GetMenuItemTemplate(item.Element) ?? Shell.MenuItemTemplate ?? DefaultMenuItemTemplate;
}
else
{
dataTemplate = Shell.GetItemTemplate(item.Element) ?? Shell.ItemTemplate ?? DefaultItemTemplate;
}
var template = dataTemplate.SelectDataTemplate(item.Element, Shell);
var id = ((IDataTemplateController)template).Id;

Просмотреть файл

@ -58,7 +58,7 @@ namespace Xamarin.Forms.Platform.iOS
}
else
{
template = _context.Shell.ItemTemplate ?? DefaultItemTemplate;
template = Shell.GetItemTemplate(context) ?? _context.Shell.ItemTemplate ?? DefaultItemTemplate;
}
var cellId = ((IDataTemplateController)template.SelectDataTemplate(context, _context.Shell)).IdString;