Skip to content

Commit 5f9ef3b

Browse files
committed
Merge pull request #13 from nativecode-dev/development
Development
2 parents 55aa50c + 7f42fe7 commit 5f9ef3b

26 files changed

+482
-343
lines changed

src/Demo/Demo.Droid/Demo.Droid.csproj

-8
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,9 @@
111111
<Name>Demo</Name>
112112
</ProjectReference>
113113
</ItemGroup>
114-
<ItemGroup>
115-
<AndroidResource Include="Resources\values\styles.xml">
116-
<SubType>Designer</SubType>
117-
</AndroidResource>
118-
</ItemGroup>
119114
<ItemGroup>
120115
<AndroidResource Include="Resources\drawable\launcher.png" />
121116
</ItemGroup>
122-
<ItemGroup>
123-
<AndroidResource Include="Resources\values-v21\styles.xml" />
124-
</ItemGroup>
125117
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
126118
<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')" />
127119
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

src/Demo/Demo.Droid/MainActivity.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@
66

77
using NativeCode.Mobile.AppCompat.FormsAppCompat;
88
using NativeCode.Mobile.AppCompat.Renderers;
9-
using NativeCode.Mobile.AppCompat.Renderers.Renderers;
109

1110
using Xamarin.Forms;
1211

13-
[Activity(ConfigurationChanges = AppConfig, MainLauncher = true, Theme = AppTheme)]
12+
[Activity(ConfigurationChanges = AppConfig, MainLauncher = true, Theme = CompatThemeLightDarkActionBar)]
1413
public class MainActivity : AppCompatFormsApplicationActivity
1514
{
1615
private const ConfigChanges AppConfig = ConfigChanges.Orientation | ConfigChanges.ScreenSize;
1716

18-
private const string AppTheme = "@style/AppTheme";
19-
2017
protected override void OnCreate(Bundle savedInstanceState)
2118
{
2219
base.OnCreate(savedInstanceState);

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

+30-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Demo/Demo.Droid/Resources/values-v21/styles.xml

-11
This file was deleted.

src/Demo/Demo.Droid/Resources/values/styles.xml

-20
This file was deleted.

src/Demo/Demo/App.xaml.cs

+1-9
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,7 @@ private static Page CreateMainPage()
2626

2727
private static MasterDetailPage CreateMasterDetailPage(Page master, Page detail)
2828
{
29-
MasterDetail = new MasterDetailPage
30-
{
31-
Detail = detail,
32-
Master = master,
33-
MasterBehavior = MasterBehavior.Popover,
34-
Title = "AppCompat Demo"
35-
};
36-
37-
return MasterDetail;
29+
return MasterDetail = new MasterDetailPage { Detail = detail, Master = master, MasterBehavior = MasterBehavior.Popover, Title = "AppCompat Demo" };
3830
}
3931

4032
private static NavigationPage CreateNavigationPage(Page page)

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
{
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
namespace NativeCode.Mobile.AppCompat.Renderers.Extensions
22
{
33
using System;
4-
using System.Linq;
4+
using System.Reflection;
5+
6+
using NativeCode.Mobile.AppCompat.Renderers.Helpers;
57

68
using Xamarin.Forms;
79

@@ -10,10 +12,21 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Extensions
1012
/// </summary>
1113
public static class ElementExtensions
1214
{
13-
private const string ButtonController = "IButtonController";
15+
private const string ButtonControllerType = "Xamarin.Forms.IButtonController, Xamarin.Forms.Core";
1416

1517
private const string ButtonControllerSendClicked = "SendClicked";
1618

19+
private static readonly MethodInfo MethodSendClicked;
20+
21+
/// <summary>
22+
/// Initializes static members of the <see cref="ElementExtensions"/> class.
23+
/// </summary>
24+
static ElementExtensions()
25+
{
26+
var type = Type.GetType(ButtonControllerType, true);
27+
MethodSendClicked = type.GetMethod(ButtonControllerSendClicked);
28+
}
29+
1730
/// <summary>
1831
/// Tries to cast the element to a button controller and invoke the SendClicked method.
1932
/// </summary>
@@ -22,27 +35,7 @@ public static class ElementExtensions
2235
/// <remarks>The IButtonController is an internal interface, so we have to use reflection.</remarks>
2336
public static void InvokeSendClicked(this Element element)
2437
{
25-
var type = GetImplementedInterface(element, ButtonController);
26-
var method = type.GetMethod(ButtonControllerSendClicked);
27-
28-
if (method == null)
29-
{
30-
throw new MissingMethodException(type.Name, ButtonControllerSendClicked);
31-
}
32-
33-
method.Invoke(element, new object[0]);
34-
}
35-
36-
private static Type GetImplementedInterface(object instance, string name)
37-
{
38-
var type = instance.GetType().GetInterfaces().Single(x => x.Name == ButtonController);
39-
40-
if (type == null)
41-
{
42-
throw new InvalidCastException("Type does not implement interface " + name + ".");
43-
}
44-
45-
return type;
38+
MethodSendClicked.Invoke(element, ReflectionHelper.EmptyParameters);
4639
}
4740
}
4841
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
namespace NativeCode.Mobile.AppCompat.Renderers.Extensions
22
{
3-
using System;
43
using System.Reflection;
54

5+
using NativeCode.Mobile.AppCompat.Renderers.Helpers;
6+
67
using Xamarin.Forms;
78

89
/// <summary>
@@ -12,21 +13,24 @@ public static class EntryExtensions
1213
{
1314
private const string EntrySendCompleted = "SendCompleted";
1415

16+
private static readonly MethodInfo MethodSendCompleted;
17+
18+
/// <summary>
19+
/// Initializes static members of the <see cref="EntryExtensions"/> class.
20+
/// </summary>
21+
static EntryExtensions()
22+
{
23+
var type = typeof(Entry);
24+
MethodSendCompleted = type.GetMethod(EntrySendCompleted, ReflectionHelper.InstanceNonPublic);
25+
}
26+
1527
/// <summary>
1628
/// Invokes the send completed.
1729
/// </summary>
1830
/// <param name="entry">The entry.</param>
1931
public static void InvokeSendCompleted(this Entry entry)
2032
{
21-
var type = entry.GetType();
22-
var method = type.GetMethod(EntrySendCompleted, BindingFlags.Instance | BindingFlags.NonPublic);
23-
24-
if (method == null)
25-
{
26-
throw new MissingMethodException(type.Name, EntrySendCompleted);
27-
}
28-
29-
method.Invoke(entry, new object[0]);
33+
MethodSendCompleted.Invoke(entry, ReflectionHelper.EmptyParameters);
3034
}
3135
}
3236
}

0 commit comments

Comments
 (0)