Skip to content

Commit 7f42fe7

Browse files
author
Michael Pham
committed
Minor refactorings.
1 parent c32247b commit 7f42fe7

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

src/Demo/Demo/Views/MenuView.xaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
</StackLayout>
1212
</controls:NavigationLayout.HeaderView>
1313
<controls:NavigationLayout.Children>
14-
<controls:NavigationMenu Command="{Binding HomeCommand}" Text="{Binding HomeText}" />
15-
<controls:NavigationMenu Command="{Binding LoremIpsumCommand}" Text="{Binding LoremIpsumText}" />
14+
<controls:NavigationLayoutMenu Command="{Binding HomeCommand}" Text="{Binding HomeText}" />
15+
<controls:NavigationLayoutMenu Command="{Binding LoremIpsumCommand}" Text="{Binding LoremIpsumText}" />
1616
</controls:NavigationLayout.Children>
1717
</controls:NavigationLayout>
1818
</ContentPage>

src/NativeCode.Mobile.AppCompat.Controls/NativeCode.Mobile.AppCompat.Controls.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<Compile Include="FloatingButtonSize.cs" />
4040
<Compile Include="ICommandProvider.cs" />
4141
<Compile Include="NavigationLayout.cs" />
42-
<Compile Include="NavigationMenu.cs" />
42+
<Compile Include="NavigationLayoutMenu.cs" />
4343
<Compile Include="Platforms\IUserNotifier.cs" />
4444
<Compile Include="Properties\AssemblyInfo.cs" />
4545
</ItemGroup>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
using Xamarin.Forms;
44

5-
public class NavigationLayout : Layout<NavigationMenu>
5+
public class NavigationLayout : Layout<NavigationLayoutMenu>
66
{
77
public static readonly BindableProperty HeaderViewProperty = BindableProperty.Create<NavigationLayout, View>(x => x.HeaderView, default(View));
88

src/NativeCode.Mobile.AppCompat.Controls/NavigationMenu.cs renamed to src/NativeCode.Mobile.AppCompat.Controls/NavigationLayoutMenu.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
using Xamarin.Forms;
66

7-
public class NavigationMenu : View, ICommandProvider
7+
public class NavigationLayoutMenu : View, ICommandProvider
88
{
9-
public static readonly BindableProperty CommandProperty = BindableProperty.Create<NavigationMenu, ICommand>(x => x.Command, default(ICommand));
9+
public static readonly BindableProperty CommandProperty = BindableProperty.Create<NavigationLayoutMenu, ICommand>(x => x.Command, default(ICommand));
1010

11-
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create<NavigationMenu, object>(
11+
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create<NavigationLayoutMenu, object>(
1212
x => x.CommandParameter,
1313
default(object));
1414

15-
public static readonly BindableProperty IconProperty = BindableProperty.Create<NavigationMenu, ImageSource>(x => x.Icon, default(ImageSource));
15+
public static readonly BindableProperty IconProperty = BindableProperty.Create<NavigationLayoutMenu, ImageSource>(x => x.Icon, default(ImageSource));
1616

17-
public static readonly BindableProperty TextProperty = BindableProperty.Create<NavigationMenu, string>(x => x.Text, default(string));
17+
public static readonly BindableProperty TextProperty = BindableProperty.Create<NavigationLayoutMenu, string>(x => x.Text, default(string));
1818

1919
public ICommand Command
2020
{

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Renderers
1313

1414
public class AppCompatMasterDetailRenderer : MasterDetailRenderer
1515
{
16-
private CustomActionBarDrawerToggle toggle;
16+
private CustomActionBarDrawerToggle actionBarDrawerToggle;
1717

1818
public override void SetDrawerListener(IDrawerListener listener)
1919
{
20-
base.SetDrawerListener(this.toggle);
20+
base.SetDrawerListener(this.actionBarDrawerToggle);
2121
}
2222

2323
protected override void OnElementChanged(VisualElement oldElement, VisualElement newElement)
@@ -29,53 +29,53 @@ protected override void OnElementChanged(VisualElement oldElement, VisualElement
2929
this.SetFitsSystemWindows(true);
3030

3131
var activity = (Activity)this.Context;
32-
this.toggle = new CustomActionBarDrawerToggle(this, activity, this) { DrawerIndicatorEnabled = true };
32+
this.actionBarDrawerToggle = new CustomActionBarDrawerToggle(this, activity, this) { DrawerIndicatorEnabled = true };
3333

3434
var actionbar = this.Context.GetSupportActionBar();
3535
actionbar.SetDisplayHomeAsUpEnabled(true);
3636
actionbar.SetHomeButtonEnabled(true);
3737

38-
this.toggle.SyncState();
38+
this.actionBarDrawerToggle.SyncState();
3939
}
4040
}
4141

4242
private class CustomActionBarDrawerToggle : ActionBarDrawerToggle
4343
{
4444
private readonly AppCompatDelegate appCompatDelegate;
4545

46-
private readonly AppCompatMasterDetailRenderer renderer;
46+
private readonly AppCompatMasterDetailRenderer owner;
4747

48-
public CustomActionBarDrawerToggle(AppCompatMasterDetailRenderer renderer, Activity activity, DrawerLayout drawerLayout)
48+
public CustomActionBarDrawerToggle(AppCompatMasterDetailRenderer owner, Activity activity, DrawerLayout drawerLayout)
4949
: base(activity, drawerLayout, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close)
5050
{
51-
this.renderer = renderer;
5251
this.appCompatDelegate = activity.GetAppCompatDelegate();
52+
this.owner = owner;
5353
}
5454

5555
public override void OnDrawerClosed(View drawerView)
5656
{
5757
base.OnDrawerClosed(drawerView);
5858
this.appCompatDelegate.InvalidateOptionsMenu();
59-
this.renderer.OnDrawerClosed(drawerView);
59+
this.owner.OnDrawerClosed(drawerView);
6060
}
6161

6262
public override void OnDrawerOpened(View drawerView)
6363
{
6464
base.OnDrawerOpened(drawerView);
6565
this.appCompatDelegate.InvalidateOptionsMenu();
66-
this.renderer.OnDrawerOpened(drawerView);
66+
this.owner.OnDrawerOpened(drawerView);
6767
}
6868

6969
public override void OnDrawerSlide(View drawerView, float slideOffset)
7070
{
7171
base.OnDrawerSlide(drawerView, slideOffset);
72-
this.renderer.OnDrawerSlide(drawerView, slideOffset);
72+
this.owner.OnDrawerSlide(drawerView, slideOffset);
7373
}
7474

7575
public override void OnDrawerStateChanged(int newState)
7676
{
7777
base.OnDrawerStateChanged(newState);
78-
this.renderer.OnDrawerStateChanged(newState);
78+
this.owner.OnDrawerStateChanged(newState);
7979
}
8080
}
8181
}

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Renderers
2020

2121
public class NavigationLayoutRenderer : ViewRenderer<NavigationLayout, NavigationView>, NavigationView.IOnNavigationItemSelectedListener
2222
{
23-
private readonly Dictionary<IMenuItem, NavigationMenu> mappings = new Dictionary<IMenuItem, NavigationMenu>();
23+
private readonly Dictionary<IMenuItem, NavigationLayoutMenu> mappings = new Dictionary<IMenuItem, NavigationLayoutMenu>();
2424

2525
public bool OnNavigationItemSelected(IMenuItem menuItem)
2626
{
@@ -60,6 +60,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<NavigationLayou
6060
var control = new NavigationView(context);
6161
control.SetFitsSystemWindows(true);
6262
control.SetNavigationItemSelectedListener(this);
63+
6364
this.SetNativeControl(control);
6465

6566
this.UpdateHeaderView();
@@ -71,6 +72,7 @@ private void UpdateHeaderView()
7172
{
7273
if (this.Element.HeaderView != null)
7374
{
75+
// TODO: It's adding it, but it never shows up in the XML in monitor.
7476
var renderer = RendererFactory.GetRenderer(this.Element.HeaderView);
7577
this.Control.AddHeaderView(renderer.ViewGroup);
7678
}
@@ -82,7 +84,8 @@ private void UpdateMenuItems()
8284

8385
for (var index = 0; index < this.Element.Children.Count; index++)
8486
{
85-
var menu = this.Element.Children[index];
87+
// NOTE: Not sure if it's just my local machine or not, but this doesn't seem to resolve until compile-time.
88+
var menu = (NavigationLayoutMenu)this.Element.Children[index];
8689
var item = this.Control.Menu.Add(0, index, index, menu.Text);
8790

8891
if (menu.Icon != null)

0 commit comments

Comments
 (0)