Skip to content

Commit fdfe620

Browse files
committed
Merge pull request #10 from nativecode-dev/development
Development
2 parents ee99d56 + 10778c6 commit fdfe620

29 files changed

+6547
-175
lines changed

src/Demo/Demo.Droid/MainActivity.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Android.OS;
66

77
using NativeCode.Mobile.AppCompat.FormsAppCompat;
8+
using NativeCode.Mobile.AppCompat.Renderers;
89
using NativeCode.Mobile.AppCompat.Renderers.Renderers;
910

1011
using Xamarin.Forms;
@@ -21,7 +22,7 @@ protected override void OnCreate(Bundle savedInstanceState)
2122
base.OnCreate(savedInstanceState);
2223

2324
Forms.Init(this, savedInstanceState);
24-
AppCompatRenderers.EnableAll();
25+
FormsAppCompat.EnableAll();
2526

2627
this.LoadApplication(new App());
2728
}

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

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

src/Demo/Demo/Views/MainView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Label Text="Entry Field" />
1414
<Entry HorizontalOptions="FillAndExpand" />
1515
</StackLayout>
16-
<RelativeLayout>
16+
<RelativeLayout Padding="10" HorizontalOptions="Center" VerticalOptions="Center">
1717
<controls:FloatingButton ButtonSize="Mini" Color="Green" Command="{Binding FloatingButtonCommand}" Icon="launcher" />
1818
</RelativeLayout>
1919
</StackLayout>

src/Demo/Demo/Views/MenuView.xaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

33
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:controls="clr-namespace:NativeCode.Mobile.AppCompat.Controls;assembly=NativeCode.Mobile.AppCompat.Controls"
45
x:Class="Demo.Views.MenuView" IsBusy="{Binding IsBusy}" Title="{Binding Title}">
5-
<StackLayout>
6-
<Button Command="{Binding HomeCommand}" Text="{Binding HomeText}" />
7-
<Button Command="{Binding LoremIpsumCommand}" Text="{Binding LoremIpsumText}" />
8-
</StackLayout>
6+
<controls:NavigationLayout>
7+
<controls:NavigationLayout.HeaderView>
8+
<StackLayout>
9+
<BoxView HeightRequest="150" BackgroundColor="Green" />
10+
<Label Text="Header" />
11+
</StackLayout>
12+
</controls:NavigationLayout.HeaderView>
13+
<controls:NavigationLayout.Children>
14+
<controls:NavigationMenu Command="{Binding HomeCommand}" Text="{Binding HomeText}" />
15+
<controls:NavigationMenu Command="{Binding LoremIpsumCommand}" Text="{Binding LoremIpsumText}" />
16+
</controls:NavigationLayout.Children>
17+
</controls:NavigationLayout>
918
</ContentPage>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/// <summary>
88
/// Provides a floating action button.
99
/// </summary>
10-
public class FloatingButton : View
10+
public class FloatingButton : View, ICommandProvider
1111
{
1212
public static readonly BindableProperty ButtonSizeProperty = BindableProperty.Create<FloatingButton, FloatingButtonSize>(
1313
x => x.ButtonSize,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace NativeCode.Mobile.AppCompat.Controls
2+
{
3+
using System.Windows.Input;
4+
5+
public interface ICommandProvider
6+
{
7+
ICommand Command { get; }
8+
9+
object CommandParameter { get; }
10+
}
11+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
<ItemGroup>
3838
<Compile Include="FloatingButton.cs" />
3939
<Compile Include="FloatingButtonSize.cs" />
40+
<Compile Include="ICommandProvider.cs" />
41+
<Compile Include="NavigationLayout.cs" />
42+
<Compile Include="NavigationMenu.cs" />
4043
<Compile Include="Platforms\IUserNotifier.cs" />
4144
<Compile Include="Properties\AssemblyInfo.cs" />
4245
</ItemGroup>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace NativeCode.Mobile.AppCompat.Controls
2+
{
3+
using Xamarin.Forms;
4+
5+
public class NavigationLayout : Layout<NavigationMenu>
6+
{
7+
public static readonly BindableProperty HeaderViewProperty = BindableProperty.Create<NavigationLayout, View>(x => x.HeaderView, default(View));
8+
9+
public View HeaderView
10+
{
11+
get { return (View)this.GetValue(HeaderViewProperty); }
12+
set { this.SetValue(HeaderViewProperty, value); }
13+
}
14+
15+
protected override void LayoutChildren(double x, double y, double width, double height)
16+
{
17+
}
18+
}
19+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace NativeCode.Mobile.AppCompat.Controls
2+
{
3+
using System.Windows.Input;
4+
5+
using Xamarin.Forms;
6+
7+
public class NavigationMenu : View, ICommandProvider
8+
{
9+
public static readonly BindableProperty CommandProperty = BindableProperty.Create<NavigationMenu, ICommand>(x => x.Command, default(ICommand));
10+
11+
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create<NavigationMenu, object>(
12+
x => x.CommandParameter,
13+
default(object));
14+
15+
public static readonly BindableProperty IconProperty = BindableProperty.Create<NavigationMenu, ImageSource>(x => x.Icon, default(ImageSource));
16+
17+
public static readonly BindableProperty TextProperty = BindableProperty.Create<NavigationMenu, string>(x => x.Text, default(string));
18+
19+
public ICommand Command
20+
{
21+
get { return (ICommand)this.GetValue(CommandProperty); }
22+
set { this.SetValue(CommandProperty, value); }
23+
}
24+
25+
public object CommandParameter
26+
{
27+
get { return this.GetValue(CommandParameterProperty); }
28+
set { this.SetValue(CommandParameterProperty, value); }
29+
}
30+
31+
public ImageSource Icon
32+
{
33+
get { return (ImageSource)this.GetValue(IconProperty); }
34+
set { this.SetValue(IconProperty, value); }
35+
}
36+
37+
public string Text
38+
{
39+
get { return (string)this.GetValue(TextProperty); }
40+
set { this.SetValue(TextProperty, value); }
41+
}
42+
}
43+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace NativeCode.Mobile.AppCompat.Renderers.Extensions
2+
{
3+
using NativeCode.Mobile.AppCompat.Controls;
4+
5+
public static class CommandExtensions
6+
{
7+
public static void ExecuteCommand(this ICommandProvider provider)
8+
{
9+
var command = provider.Command;
10+
var parameter = provider.CommandParameter;
11+
12+
if (command != null && command.CanExecute(parameter))
13+
{
14+
command.Execute(parameter);
15+
}
16+
}
17+
}
18+
}

src/NativeCode.Mobile.AppCompat.Renderers/Renderers/AppCompatRenderers.cs renamed to src/NativeCode.Mobile.AppCompat.Renderers/FormsAppCompat.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
namespace NativeCode.Mobile.AppCompat.Renderers.Renderers
1+
namespace NativeCode.Mobile.AppCompat.Renderers
22
{
33
using System;
44
using System.Reflection;
55

6+
using NativeCode.Mobile.AppCompat.Renderers.Renderers;
7+
68
using Xamarin.Forms;
79

810
/// <summary>
9-
/// Allows registration of renderers.
11+
/// Enables renderers for various aspects of the library.
1012
/// </summary>
11-
public static class AppCompatRenderers
13+
public static class FormsAppCompat
1214
{
1315
private const string RegistrarType = "Xamarin.Forms.Registrar, Xamarin.Forms.Core";
1416

@@ -17,9 +19,9 @@ public static class AppCompatRenderers
1719
private static readonly MethodInfo RegisterMethod;
1820

1921
/// <summary>
20-
/// Initializes static members of the <see cref="AppCompatRenderers"/> class.
22+
/// Initializes static members of the <see cref="FormsAppCompat"/> class.
2123
/// </summary>
22-
static AppCompatRenderers()
24+
static FormsAppCompat()
2325
{
2426
var type = Type.GetType(RegistrarType, true);
2527
var property = type.GetProperty("Registered", BindingFlags.NonPublic | BindingFlags.Static);
@@ -32,16 +34,8 @@ static AppCompatRenderers()
3234
/// </summary>
3335
public static void EnableAll()
3436
{
35-
EnableMasterDetailRenderer();
3637
EnableAppCompatReplacements();
37-
}
38-
39-
/// <summary>
40-
/// Enables registration of the <see cref="AppCompatMasterDetailRenderer"/>.
41-
/// </summary>
42-
public static void EnableMasterDetailRenderer()
43-
{
44-
RegisterType(typeof(MasterDetailPage), typeof(AppCompatMasterDetailRenderer));
38+
EnableMasterDetailRenderer();
4539
}
4640

4741
/// <summary>
@@ -54,6 +48,14 @@ public static void EnableAppCompatReplacements()
5448
RegisterType(typeof(Switch), typeof(AppCompatSwitchRenderer));
5549
}
5650

51+
/// <summary>
52+
/// Enables registration of the <see cref="AppCompatMasterDetailRenderer"/>.
53+
/// </summary>
54+
public static void EnableMasterDetailRenderer()
55+
{
56+
RegisterType(typeof(MasterDetailPage), typeof(AppCompatMasterDetailRenderer));
57+
}
58+
5759
private static void RegisterType(Type handler, Type target)
5860
{
5961
RegisterMethod.Invoke(RegistrarInstance, new object[] { handler, target });

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
</Reference>
7777
</ItemGroup>
7878
<ItemGroup>
79+
<Compile Include="Extensions\CommandExtensions.cs" />
7980
<Compile Include="Extensions\ElementExtensions.cs" />
8081
<Compile Include="Extensions\EntryExtensions.cs" />
8182
<Compile Include="Helpers\KeyboardHelper.cs" />
@@ -86,8 +87,9 @@
8687
<Compile Include="Renderers\AppCompatMasterDetailRenderer.cs" />
8788
<Compile Include="Renderers\AppCompatSwitchRenderer.cs" />
8889
<Compile Include="Renderers\Controls\AppCompatEntryEditText.cs" />
90+
<Compile Include="FormsAppCompat.cs" />
8991
<Compile Include="Renderers\FloatingButtonRenderer.cs" />
90-
<Compile Include="Renderers\AppCompatRenderers.cs" />
92+
<Compile Include="Renderers\NavigationLayoutRenderer.cs" />
9193
<Compile Include="Resources\Resource.Designer.cs" />
9294
<Compile Include="Properties\AssemblyInfo.cs" />
9395
</ItemGroup>
@@ -120,6 +122,21 @@
120122
<SubType>Designer</SubType>
121123
</AndroidResource>
122124
</ItemGroup>
125+
<ItemGroup>
126+
<AndroidResource Include="Resources\values\dimensions.xml">
127+
<SubType>Designer</SubType>
128+
</AndroidResource>
129+
</ItemGroup>
130+
<ItemGroup>
131+
<AndroidResource Include="Resources\layout-v21\fab_mini.xml">
132+
<SubType>Designer</SubType>
133+
</AndroidResource>
134+
</ItemGroup>
135+
<ItemGroup>
136+
<AndroidResource Include="Resources\layout-v21\fab_normal.xml">
137+
<SubType>Designer</SubType>
138+
</AndroidResource>
139+
</ItemGroup>
123140
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
124141
<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')" />
125142
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
2626
// in the base method.
2727
if (this.Control == null)
2828
{
29-
var control = new AppCompatButton(this.Context.GetAppCompatThemedContext());
29+
var context = this.Context.GetAppCompatThemedContext();
30+
var control = new AppCompatButton(context);
3031
this.SetNativeControl(control);
3132

3233
control.SetOnClickListener(ButtonClickListener.Instance);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
6767

6868
if (e.OldElement == null)
6969
{
70-
var control = new AppCompatEntryEditText(this.Context.GetAppCompatThemedContext());
70+
var context = this.Context.GetAppCompatThemedContext();
71+
var control = new AppCompatEntryEditText(context);
7172
this.SetNativeControl(control);
7273

7374
this.Control.ImeOptions = ImeAction.Done;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ protected override void OnElementChanged(ElementChangedEventArgs<Switch> e)
8585

8686
if (this.Control == null)
8787
{
88-
var control = new SwitchCompat(this.Context.GetAppCompatThemedContext());
88+
var context = this.Context.GetAppCompatThemedContext();
89+
var control = new SwitchCompat(context);
8990
control.SetOnCheckedChangeListener(this);
9091
this.SetNativeControl(control);
9192
}

0 commit comments

Comments
 (0)