Skip to content

Development #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 27, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Demo/Demo.Droid/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class MainActivity : AppCompatFormsApplicationActivity

protected override void OnCreate(Bundle savedInstanceState)
{
this.EnableCoordinatorLayout = true;

base.OnCreate(savedInstanceState);

Forms.Init(this, savedInstanceState);
Expand Down
93 changes: 71 additions & 22 deletions src/Demo/Demo.Droid/Resources/Resource.Designer.cs

Large diffs are not rendered by default.

31 changes: 27 additions & 4 deletions src/Demo/Demo/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public App()

internal static INavigation Navigation { get; private set; }

public static INavigation Navigate()
{
return Navigation;
}

public static void ShowChooser()
{
Current.MainPage = new ChooserView();
Expand All @@ -33,18 +38,36 @@ public static void ShowMasterDetailPatternTwo()
Current.MainPage = master;
}

public static void ShowNavigation()
{
Current.MainPage = CreateNavigationPage(new NestNavigationView(), false);
}

public static void ShowTabbed()
{
var tabbed = new TabbedPage();
tabbed.Children.Add(new LoremIpsumView { Title = "Page 1" });
tabbed.Children.Add(new LoremIpsumView { Title = "Page 2" });
tabbed.Children.Add(new LoremIpsumView { Title = "Page 3" });

Current.MainPage = CreateNavigationPage(CreateMasterDetailPage(new MenuView(), tabbed));
}

private static MasterDetailPage CreateMasterDetailPage(Page master, Page detail)
{
return MasterDetail = new MasterDetailPage { Detail = detail, Master = master, MasterBehavior = GetMasterBehavior(), Title = "AppCompat Demo" };
}

private static NavigationPage CreateNavigationPage(Page page)
private static NavigationPage CreateNavigationPage(Page page, bool handleEvents = true)
{
var navigation = new NavigationPage(page);

navigation.Popped += (sender, args) => HideMenu();
navigation.PoppedToRoot += (sender, args) => HideMenu();
navigation.Pushed += (sender, args) => HideMenu();
if (handleEvents)
{
navigation.Popped += (sender, args) => HideMenu();
navigation.PoppedToRoot += (sender, args) => HideMenu();
navigation.Pushed += (sender, args) => HideMenu();
}

Navigation = navigation.Navigation;

Expand Down
10 changes: 10 additions & 0 deletions src/Demo/Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
</Compile>
<Compile Include="ViewModels\ChooserViewModel.cs" />
<Compile Include="ViewModels\LoremIpsumViewModel.cs" />
<Compile Include="ViewModels\NestNavigationViewModel.cs" />
<Compile Include="Views\ChooserView.xaml.cs">
<DependentUpon>ChooserView.xaml</DependentUpon>
</Compile>
Expand All @@ -63,6 +64,9 @@
<Compile Include="Views\MenuView.xaml.cs">
<DependentUpon>MenuView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\NestNavigationView.xaml.cs">
<DependentUpon>NestNavigationView.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Reference Include="PropertyChanged, Version=1.50.1.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd">
Expand Down Expand Up @@ -118,6 +122,12 @@
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Views\NestNavigationView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Import Project="..\..\packages\Xamarin.Forms.1.4.2.6359\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.1.4.2.6359\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
6 changes: 6 additions & 0 deletions src/Demo/Demo/ViewModels/ChooserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ public ChooserViewModel()
{
this.MasterDetailPatternOneCommand = new Command(App.ShowMasterDetailPatternOne);
this.MasterDetailPatternTwoCommand = new Command(App.ShowMasterDetailPatternTwo);
this.NavigationCommand = new Command(App.ShowNavigation);
this.TabbedCommand = new Command(App.ShowTabbed);
}

public ICommand MasterDetailPatternOneCommand { get; private set; }

public ICommand MasterDetailPatternTwoCommand { get; private set; }

public ICommand NavigationCommand { get; private set; }

public ICommand TabbedCommand { get; private set; }
}
}
9 changes: 3 additions & 6 deletions src/Demo/Demo/ViewModels/MenuViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ public class MenuViewModel : ViewModel
public MenuViewModel()
{
this.HomeCommand = new Command(App.ShowChooser);
this.HomeText = "Home";

this.LoremIpsumCommand = new Command(async () => await App.Navigation.PushAsync(new LoremIpsumView()));
this.LoremIpsumText = "Lorem Ipsum";
this.NavigationCommand = new Command(async () => await App.Navigation.PushAsync(new NestNavigationView()));

this.Title = "Menu";
}

[DoNotNotify]
public ICommand HomeCommand { get; private set; }

public string HomeText { get; set; }

[DoNotNotify]
public ICommand LoremIpsumCommand { get; private set; }

public string LoremIpsumText { get; set; }
[DoNotNotify]
public ICommand NavigationCommand { get; private set; }
}
}
24 changes: 24 additions & 0 deletions src/Demo/Demo/ViewModels/NestNavigationViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Demo.ViewModels
{
using System.Windows.Input;

using Demo.Views;

using Xamarin.Forms;

public class NestNavigationViewModel : ViewModel
{
public NestNavigationViewModel()
{
this.PopCommand = new Command(async () => await App.Navigation.PopAsync());
this.PushCommand = new Command(async () => await App.Navigation.PushAsync(new NestNavigationView()));
this.RootCommand = new Command(async () => await App.Navigation.PopToRootAsync());
}

public ICommand PopCommand { get; private set; }

public ICommand PushCommand { get; private set; }

public ICommand RootCommand { get; private set; }
}
}
2 changes: 2 additions & 0 deletions src/Demo/Demo/Views/ChooserView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<controls:NavigationLayout.Children>
<controls:NavigationLayoutMenu Command="{Binding MasterDetailPatternOneCommand}" Text="Master Detail Pattern One" />
<controls:NavigationLayoutMenu Command="{Binding MasterDetailPatternTwoCommand}" Text="Master Detail Pattern Two" />
<controls:NavigationLayoutMenu Command="{Binding NavigationCommand}" Text="Navigation Pattern" />
<controls:NavigationLayoutMenu Command="{Binding TabbedCommand}" Text="Tabbed Navigation" />
</controls:NavigationLayout.Children>
</controls:NavigationLayout>
</ContentPage>
15 changes: 9 additions & 6 deletions src/Demo/Demo/Views/MenuView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
x:Class="Demo.Views.MenuView" IsBusy="{Binding IsBusy}" Title="{Binding Title}">
<controls:NavigationLayout>
<controls:NavigationLayout.HeaderView>
<StackLayout>
<BoxView HeightRequest="150" BackgroundColor="Green" />
<Label Text="Header" />
</StackLayout>
<ContentView>
<StackLayout>
<BoxView HeightRequest="150" BackgroundColor="Green" />
<Label Text="Header" />
</StackLayout>
</ContentView>
</controls:NavigationLayout.HeaderView>
<controls:NavigationLayout.Children>
<controls:NavigationLayoutMenu Command="{Binding HomeCommand}" Text="{Binding HomeText}" />
<controls:NavigationLayoutMenu Command="{Binding LoremIpsumCommand}" Text="{Binding LoremIpsumText}" />
<controls:NavigationLayoutMenu Command="{Binding HomeCommand}" Text="Home" />
<controls:NavigationLayoutMenu Command="{Binding LoremIpsumCommand}" Text="Lorem Ipsum" />
<controls:NavigationLayoutMenu Command="{Binding NavigationCommand}" Text="Nested Navigation" />
</controls:NavigationLayout.Children>
</controls:NavigationLayout>
</ContentPage>
11 changes: 11 additions & 0 deletions src/Demo/Demo/Views/NestNavigationView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Demo.Views.NestNavigationView" IsBusy="{Binding IsBusy}" Title="{Binding Title}">
<StackLayout>
<Button Command="{Binding PushCommand}" Text="Push" />
<Button Command="{Binding PopCommand}" Text="Pop" />
<BoxView HeightRequest="1" Color="Black" />
<Button Command="{Binding RootCommand}" Text="Root" />
</StackLayout>
</ContentPage>
15 changes: 15 additions & 0 deletions src/Demo/Demo/Views/NestNavigationView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Demo.Views
{
using Demo.ViewModels;

using Xamarin.Forms;

public partial class NestNavigationView : ContentPage
{
public NestNavigationView()
{
this.InitializeComponent();
this.BindingContext = new NestNavigationViewModel();
}
}
}
8 changes: 5 additions & 3 deletions src/NativeCode.Mobile.AppCompat.Controls/NavigationLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

public class NavigationLayout : Layout<NavigationLayoutMenu>
{
public static readonly BindableProperty HeaderViewProperty = BindableProperty.Create<NavigationLayout, View>(x => x.HeaderView, default(View));
public static readonly BindableProperty HeaderViewProperty = BindableProperty.Create<NavigationLayout, ContentView>(
x => x.HeaderView,
default(ContentView));

public View HeaderView
public ContentView HeaderView
{
get { return (View)this.GetValue(HeaderViewProperty); }
get { return (ContentView)this.GetValue(HeaderViewProperty); }
set { this.SetValue(HeaderViewProperty, value); }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\color\fab.xml" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="..\packages\Xamarin.Forms.1.4.2.6359\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.1.4.2.6359\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected void UpdateHomeAsUpIndicator(bool navigable)
this.actionBarDrawerToggle.DrawerIndicatorEnabled = false;
this.ActionBar.SetDisplayHomeAsUpEnabled(true);
}
else if (!this.actionBarDrawerToggle.DrawerIndicatorEnabled)
else if (!navigable && !this.actionBarDrawerToggle.DrawerIndicatorEnabled)
{
this.actionBarDrawerToggle.DrawerIndicatorEnabled = true;
}
Expand All @@ -90,6 +90,7 @@ private void BindNavigationEventHandlers()
if (navigation != null)
{
navigation.Popped += this.HandleNavigationPopped;
navigation.PoppedToRoot += this.HandleNavigationPoppedToRoot;
navigation.Pushed += this.HandleNavigationPushed;
}
}
Expand All @@ -101,6 +102,7 @@ private void UnbindNavigationEventHandlers()
if (navigation != null)
{
navigation.Popped -= this.HandleNavigationPopped;
navigation.PoppedToRoot -= this.HandleNavigationPoppedToRoot;
navigation.Pushed -= this.HandleNavigationPushed;
}
}
Expand All @@ -127,6 +129,11 @@ private void HandleNavigationPopped(object sender, NavigationEventArgs e)
this.UpdateHomeAsUpIndicator(canNavigateBack);
}

private void HandleNavigationPoppedToRoot(object sender, NavigationEventArgs e)
{
this.UpdateHomeAsUpIndicator(false);
}

private void HandleNavigationPushed(object sender, NavigationEventArgs e)
{
var canNavigateBack = ((NavigationPage)sender).Navigation.NavigationStack.Count > 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<NavigationLayou
this.SetNativeControl(control);

this.UpdateBackgroundColor();
this.UpdateHeaderView();
this.UpdateMenuItems();
this.UpdateHeaderView();
}
}

Expand All @@ -68,8 +68,7 @@ private void UpdateHeaderView()
if (this.Element.HeaderView != null)
{
// TODO: It's adding it, but it never shows up in the XML in monitor.
var renderer = this.Element.HeaderView.GetRenderer();
this.Control.AddHeaderView(renderer.ViewGroup);
this.Control.AddHeaderView(this.Element.HeaderView.GetNativeView());
}
}

Expand Down
Loading