Skip to content

Commit 6bc2979

Browse files
committed
Merge pull request #28 from nativecode-dev/development
Development
2 parents 84fef32 + e738b07 commit 6bc2979

28 files changed

+481
-99
lines changed

src/Demo/Demo.Droid/MainActivity.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class MainActivity : AppCompatFormsApplicationActivity
1616

1717
protected override void OnCreate(Bundle savedInstanceState)
1818
{
19+
this.EnableCoordinatorLayout = true;
20+
1921
base.OnCreate(savedInstanceState);
2022

2123
Forms.Init(this, savedInstanceState);

src/Demo/Demo.Droid/Resources/Resource.Designer.cs

Lines changed: 71 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Demo/Demo/App.xaml.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public App()
1616

1717
internal static INavigation Navigation { get; private set; }
1818

19+
public static INavigation Navigate()
20+
{
21+
return Navigation;
22+
}
23+
1924
public static void ShowChooser()
2025
{
2126
Current.MainPage = new ChooserView();
@@ -33,18 +38,36 @@ public static void ShowMasterDetailPatternTwo()
3338
Current.MainPage = master;
3439
}
3540

41+
public static void ShowNavigation()
42+
{
43+
Current.MainPage = CreateNavigationPage(new NestNavigationView(), false);
44+
}
45+
46+
public static void ShowTabbed()
47+
{
48+
var tabbed = new TabbedPage();
49+
tabbed.Children.Add(new LoremIpsumView { Title = "Page 1" });
50+
tabbed.Children.Add(new LoremIpsumView { Title = "Page 2" });
51+
tabbed.Children.Add(new LoremIpsumView { Title = "Page 3" });
52+
53+
Current.MainPage = CreateNavigationPage(CreateMasterDetailPage(new MenuView(), tabbed));
54+
}
55+
3656
private static MasterDetailPage CreateMasterDetailPage(Page master, Page detail)
3757
{
3858
return MasterDetail = new MasterDetailPage { Detail = detail, Master = master, MasterBehavior = GetMasterBehavior(), Title = "AppCompat Demo" };
3959
}
4060

41-
private static NavigationPage CreateNavigationPage(Page page)
61+
private static NavigationPage CreateNavigationPage(Page page, bool handleEvents = true)
4262
{
4363
var navigation = new NavigationPage(page);
4464

45-
navigation.Popped += (sender, args) => HideMenu();
46-
navigation.PoppedToRoot += (sender, args) => HideMenu();
47-
navigation.Pushed += (sender, args) => HideMenu();
65+
if (handleEvents)
66+
{
67+
navigation.Popped += (sender, args) => HideMenu();
68+
navigation.PoppedToRoot += (sender, args) => HideMenu();
69+
navigation.Pushed += (sender, args) => HideMenu();
70+
}
4871

4972
Navigation = navigation.Navigation;
5073

src/Demo/Demo/Demo.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
</Compile>
4848
<Compile Include="ViewModels\ChooserViewModel.cs" />
4949
<Compile Include="ViewModels\LoremIpsumViewModel.cs" />
50+
<Compile Include="ViewModels\NestNavigationViewModel.cs" />
5051
<Compile Include="Views\ChooserView.xaml.cs">
5152
<DependentUpon>ChooserView.xaml</DependentUpon>
5253
</Compile>
@@ -63,6 +64,9 @@
6364
<Compile Include="Views\MenuView.xaml.cs">
6465
<DependentUpon>MenuView.xaml</DependentUpon>
6566
</Compile>
67+
<Compile Include="Views\NestNavigationView.xaml.cs">
68+
<DependentUpon>NestNavigationView.xaml</DependentUpon>
69+
</Compile>
6670
</ItemGroup>
6771
<ItemGroup>
6872
<Reference Include="PropertyChanged, Version=1.50.1.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd">
@@ -118,6 +122,12 @@
118122
<SubType>Designer</SubType>
119123
</EmbeddedResource>
120124
</ItemGroup>
125+
<ItemGroup>
126+
<EmbeddedResource Include="Views\NestNavigationView.xaml">
127+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
128+
<SubType>Designer</SubType>
129+
</EmbeddedResource>
130+
</ItemGroup>
121131
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
122132
<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')" />
123133
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

src/Demo/Demo/ViewModels/ChooserViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ public ChooserViewModel()
1010
{
1111
this.MasterDetailPatternOneCommand = new Command(App.ShowMasterDetailPatternOne);
1212
this.MasterDetailPatternTwoCommand = new Command(App.ShowMasterDetailPatternTwo);
13+
this.NavigationCommand = new Command(App.ShowNavigation);
14+
this.TabbedCommand = new Command(App.ShowTabbed);
1315
}
1416

1517
public ICommand MasterDetailPatternOneCommand { get; private set; }
1618

1719
public ICommand MasterDetailPatternTwoCommand { get; private set; }
20+
21+
public ICommand NavigationCommand { get; private set; }
22+
23+
public ICommand TabbedCommand { get; private set; }
1824
}
1925
}

src/Demo/Demo/ViewModels/MenuViewModel.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@ public class MenuViewModel : ViewModel
1313
public MenuViewModel()
1414
{
1515
this.HomeCommand = new Command(App.ShowChooser);
16-
this.HomeText = "Home";
17-
1816
this.LoremIpsumCommand = new Command(async () => await App.Navigation.PushAsync(new LoremIpsumView()));
19-
this.LoremIpsumText = "Lorem Ipsum";
17+
this.NavigationCommand = new Command(async () => await App.Navigation.PushAsync(new NestNavigationView()));
2018

2119
this.Title = "Menu";
2220
}
2321

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

27-
public string HomeText { get; set; }
28-
2925
[DoNotNotify]
3026
public ICommand LoremIpsumCommand { get; private set; }
3127

32-
public string LoremIpsumText { get; set; }
28+
[DoNotNotify]
29+
public ICommand NavigationCommand { get; private set; }
3330
}
3431
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
namespace Demo.ViewModels
2+
{
3+
using System.Windows.Input;
4+
5+
using Demo.Views;
6+
7+
using Xamarin.Forms;
8+
9+
public class NestNavigationViewModel : ViewModel
10+
{
11+
public NestNavigationViewModel()
12+
{
13+
this.PopCommand = new Command(async () => await App.Navigation.PopAsync());
14+
this.PushCommand = new Command(async () => await App.Navigation.PushAsync(new NestNavigationView()));
15+
this.RootCommand = new Command(async () => await App.Navigation.PopToRootAsync());
16+
}
17+
18+
public ICommand PopCommand { get; private set; }
19+
20+
public ICommand PushCommand { get; private set; }
21+
22+
public ICommand RootCommand { get; private set; }
23+
}
24+
}

src/Demo/Demo/Views/ChooserView.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
<controls:NavigationLayout.Children>
77
<controls:NavigationLayoutMenu Command="{Binding MasterDetailPatternOneCommand}" Text="Master Detail Pattern One" />
88
<controls:NavigationLayoutMenu Command="{Binding MasterDetailPatternTwoCommand}" Text="Master Detail Pattern Two" />
9+
<controls:NavigationLayoutMenu Command="{Binding NavigationCommand}" Text="Navigation Pattern" />
10+
<controls:NavigationLayoutMenu Command="{Binding TabbedCommand}" Text="Tabbed Navigation" />
911
</controls:NavigationLayout.Children>
1012
</controls:NavigationLayout>
1113
</ContentPage>

src/Demo/Demo/Views/MenuView.xaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
x:Class="Demo.Views.MenuView" IsBusy="{Binding IsBusy}" Title="{Binding Title}">
66
<controls:NavigationLayout>
77
<controls:NavigationLayout.HeaderView>
8-
<StackLayout>
9-
<BoxView HeightRequest="150" BackgroundColor="Green" />
10-
<Label Text="Header" />
11-
</StackLayout>
8+
<ContentView>
9+
<StackLayout>
10+
<BoxView HeightRequest="150" BackgroundColor="Green" />
11+
<Label Text="Header" />
12+
</StackLayout>
13+
</ContentView>
1214
</controls:NavigationLayout.HeaderView>
1315
<controls:NavigationLayout.Children>
14-
<controls:NavigationLayoutMenu Command="{Binding HomeCommand}" Text="{Binding HomeText}" />
15-
<controls:NavigationLayoutMenu Command="{Binding LoremIpsumCommand}" Text="{Binding LoremIpsumText}" />
16+
<controls:NavigationLayoutMenu Command="{Binding HomeCommand}" Text="Home" />
17+
<controls:NavigationLayoutMenu Command="{Binding LoremIpsumCommand}" Text="Lorem Ipsum" />
18+
<controls:NavigationLayoutMenu Command="{Binding NavigationCommand}" Text="Nested Navigation" />
1619
</controls:NavigationLayout.Children>
1720
</controls:NavigationLayout>
1821
</ContentPage>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Demo.Views.NestNavigationView" IsBusy="{Binding IsBusy}" Title="{Binding Title}">
5+
<StackLayout>
6+
<Button Command="{Binding PushCommand}" Text="Push" />
7+
<Button Command="{Binding PopCommand}" Text="Pop" />
8+
<BoxView HeightRequest="1" Color="Black" />
9+
<Button Command="{Binding RootCommand}" Text="Root" />
10+
</StackLayout>
11+
</ContentPage>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Demo.Views
2+
{
3+
using Demo.ViewModels;
4+
5+
using Xamarin.Forms;
6+
7+
public partial class NestNavigationView : ContentPage
8+
{
9+
public NestNavigationView()
10+
{
11+
this.InitializeComponent();
12+
this.BindingContext = new NestNavigationViewModel();
13+
}
14+
}
15+
}

src/NativeCode.Mobile.AppCompat.Controls/NavigationLayout.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
public class NavigationLayout : Layout<NavigationLayoutMenu>
66
{
7-
public static readonly BindableProperty HeaderViewProperty = BindableProperty.Create<NavigationLayout, View>(x => x.HeaderView, default(View));
7+
public static readonly BindableProperty HeaderViewProperty = BindableProperty.Create<NavigationLayout, ContentView>(
8+
x => x.HeaderView,
9+
default(ContentView));
810

9-
public View HeaderView
11+
public ContentView HeaderView
1012
{
11-
get { return (View)this.GetValue(HeaderViewProperty); }
13+
get { return (ContentView)this.GetValue(HeaderViewProperty); }
1214
set { this.SetValue(HeaderViewProperty, value); }
1315
}
1416

src/NativeCode.Mobile.AppCompat.Renderers/NativeCode.Mobile.AppCompat.Renderers.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@
140140
<SubType>Designer</SubType>
141141
</AndroidResource>
142142
</ItemGroup>
143+
<ItemGroup>
144+
<AndroidResource Include="Resources\color\fab.xml" />
145+
</ItemGroup>
143146
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
144147
<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')" />
145148
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

src/NativeCode.Mobile.AppCompat.Renderers/Renderers/AppCompatMasterDetailRenderer.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected void UpdateHomeAsUpIndicator(bool navigable)
7777
this.actionBarDrawerToggle.DrawerIndicatorEnabled = false;
7878
this.ActionBar.SetDisplayHomeAsUpEnabled(true);
7979
}
80-
else if (!this.actionBarDrawerToggle.DrawerIndicatorEnabled)
80+
else if (!navigable && !this.actionBarDrawerToggle.DrawerIndicatorEnabled)
8181
{
8282
this.actionBarDrawerToggle.DrawerIndicatorEnabled = true;
8383
}
@@ -90,6 +90,7 @@ private void BindNavigationEventHandlers()
9090
if (navigation != null)
9191
{
9292
navigation.Popped += this.HandleNavigationPopped;
93+
navigation.PoppedToRoot += this.HandleNavigationPoppedToRoot;
9394
navigation.Pushed += this.HandleNavigationPushed;
9495
}
9596
}
@@ -101,6 +102,7 @@ private void UnbindNavigationEventHandlers()
101102
if (navigation != null)
102103
{
103104
navigation.Popped -= this.HandleNavigationPopped;
105+
navigation.PoppedToRoot -= this.HandleNavigationPoppedToRoot;
104106
navigation.Pushed -= this.HandleNavigationPushed;
105107
}
106108
}
@@ -127,6 +129,11 @@ private void HandleNavigationPopped(object sender, NavigationEventArgs e)
127129
this.UpdateHomeAsUpIndicator(canNavigateBack);
128130
}
129131

132+
private void HandleNavigationPoppedToRoot(object sender, NavigationEventArgs e)
133+
{
134+
this.UpdateHomeAsUpIndicator(false);
135+
}
136+
130137
private void HandleNavigationPushed(object sender, NavigationEventArgs e)
131138
{
132139
var canNavigateBack = ((NavigationPage)sender).Navigation.NavigationStack.Count > 1;

src/NativeCode.Mobile.AppCompat.Renderers/Renderers/NavigationLayoutRenderer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<NavigationLayou
5858
this.SetNativeControl(control);
5959

6060
this.UpdateBackgroundColor();
61-
this.UpdateHeaderView();
6261
this.UpdateMenuItems();
62+
this.UpdateHeaderView();
6363
}
6464
}
6565

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

0 commit comments

Comments
 (0)