Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Namespace all the things. XAML test.
Browse files Browse the repository at this point in the history
  • Loading branch information
samhouts committed Aug 12, 2016
1 parent a074ac9 commit a75157c
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 122 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.PlatformConfiguration.iOS;

namespace Xamarin.Forms.Controls
{
Expand Down
3 changes: 3 additions & 0 deletions Xamarin.Forms.Controls/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using System.Reflection;
using System.Threading.Tasks;
using Xamarin.Forms.Controls.Issues;
using Xamarin.Forms.PlatformConfiguration.Android;
using Xamarin.Forms.PlatformConfiguration.iOS;
using ImAVendor.Forms.iOS;

namespace Xamarin.Forms.Controls
{
Expand Down
4 changes: 3 additions & 1 deletion Xamarin.Forms.Core.UnitTests/PlatformSpecificsTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using NUnit.Framework;

using Xamarin.Forms.PlatformConfiguration.Android;
using Xamarin.Forms.PlatformConfiguration.iOS;
using ImAVendor.Forms.iOS;

namespace Xamarin.Forms.Core.UnitTests
{
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.Core/MasterDetailPage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms.Platform;
using Xamarin.Forms.PlatformConfiguration;

namespace Xamarin.Forms
{
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.Core/NavigationPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform;
using Xamarin.Forms.PlatformConfiguration;

namespace Xamarin.Forms
{
Expand Down
207 changes: 90 additions & 117 deletions Xamarin.Forms.Core/PlatformSpecifics.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System;
using System.Collections.Generic;
using Xamarin.Forms;

namespace Xamarin.Forms
namespace Xamarin.Forms.PlatformConfiguration
{
public interface IConfigElement<out T> where T : Element
{
T Element { get; }
}
{
T Element { get; }
}

public interface IPlatformElementConfiguration<out TPlatform, out TElement> : IConfigElement<TElement>
public interface IPlatformElementConfiguration<out TPlatform, out TElement> : IConfigElement<TElement>
where TPlatform : IConfigPlatform
where TElement : Element
{
}
{
}

public interface IElementConfiguration<out TElement> where TElement : Element
{
Expand All @@ -21,59 +22,71 @@ public interface IElementConfiguration<out TElement> where TElement : Element

public interface IConfigPlatform { }

public interface IConfigIOS : IConfigPlatform { }

public interface IConfigAndroid : IConfigPlatform { }

public interface IConfigWindows : IConfigPlatform { }

#region MDP

#region Windows
public class Configuration<TPlatform, TElement> : IPlatformElementConfiguration<TPlatform, TElement>
where TPlatform : IConfigPlatform
where TElement : Element

public static class MasterDetailPageWindowsSpecifics
{
public static readonly BindableProperty CollapseStyleProperty = BindableProperty.Create("CollapseStyle",
typeof(CollapseStyle),
typeof(IPlatformElementConfiguration<IConfigWindows, MasterDetailPage>), CollapseStyle.None);

public static CollapseStyle GetCollapseStyle(this IPlatformElementConfiguration<IConfigWindows, MasterDetailPage> config)
public Configuration(TElement element)
{
return (CollapseStyle)config.Element.GetValue(CollapseStyleProperty);
Element = element;
}

public static void SetCollapseStyle(this IPlatformElementConfiguration<IConfigWindows, MasterDetailPage> config, CollapseStyle value)
public TElement Element { get; }

public static Configuration<TPlatform, TElement> Create(TElement element)
{
config.Element.SetValue(CollapseStyleProperty, value);
return new Configuration<TPlatform, TElement>(element);
}
}

public static class MasterDetailPageWindowsConfigurationExtensions
/// <summary>
/// Helper that handles storing and lookup of platform specifics implementations
/// </summary>
/// <typeparam name="TElement">The Element type</typeparam>
internal class PlatformConfigurationRegistry<TElement> : IElementConfiguration<TElement>
where TElement : Element
{
public static IPlatformElementConfiguration<IConfigWindows, MasterDetailPage> UsePartialCollapse(
this IPlatformElementConfiguration<IConfigWindows, MasterDetailPage> config)
readonly TElement _element;
readonly Dictionary<Type, object> _platformSpecifics = new Dictionary<Type, object>();

internal PlatformConfigurationRegistry(TElement element)
{
config.Element.SetValue(MasterDetailPageWindowsSpecifics.CollapseStyleProperty, CollapseStyle.Partial);
return config;
_element = element;
}
}

#endregion
public IPlatformElementConfiguration<T, TElement> On<T>() where T : IConfigPlatform
{
if (_platformSpecifics.ContainsKey(typeof(T)))
{
return (IPlatformElementConfiguration<T, TElement>)_platformSpecifics[typeof(T)];
}

var emptyConfig = Configuration<T, TElement>.Create(_element);

_platformSpecifics.Add(typeof(T), emptyConfig);

return emptyConfig;
}
}
}

#region Android
namespace Xamarin.Forms.PlatformConfiguration.Android
{
public interface IConfigAndroid : IConfigPlatform { }

public static class MasterDetailPageAndroidSpecifics
public static class MasterDetailPageConfig
{
#region Properties

public static readonly BindableProperty SomeAndroidThingProperty = BindableProperty.Create("SomeAndroidThing",
typeof(int),
typeof(MasterDetailPage), 1);
typeof(MasterDetailPageConfig), 1);

public static readonly BindableProperty SomeOtherAndroidThingProperty =
BindableProperty.Create("SomeOtherAndroidThing", typeof(int),
typeof(MasterDetailPage), 1);
typeof(MasterDetailPageConfig), 1);

#endregion

#region Configuration
Expand Down Expand Up @@ -118,120 +131,80 @@ public static IPlatformElementConfiguration<IConfigAndroid, MasterDetailPage> Us

#endregion
}
}

#endregion

#region iOS
namespace Xamarin.Forms.PlatformConfiguration.Windows
{
public interface IConfigWindows : IConfigPlatform { }

public class MasterDetailPageiOSConfiguration : Configuration<IConfigIOS, MasterDetailPage>
public enum CollapseStyle
{
public MasterDetailPageiOSConfiguration (MasterDetailPage element) : base(element)
{
}
None,
Partial
}
public static class MasterDetailPageConfig
{
public static readonly BindableProperty CollapseStyleProperty = BindableProperty.Create("CollapseStyle",
typeof(CollapseStyle),
typeof(MasterDetailPageConfig), CollapseStyle.None);

#endregion
public static CollapseStyle GetCollapseStyle(this IPlatformElementConfiguration<IConfigWindows, MasterDetailPage> config)
{
return (CollapseStyle)config.Element.GetValue(CollapseStyleProperty);
}

#endregion
public static void SetCollapseStyle(this IPlatformElementConfiguration<IConfigWindows, MasterDetailPage> config, CollapseStyle value)
{
config.Element.SetValue(CollapseStyleProperty, value);
}

#region NavigationPage
public static IPlatformElementConfiguration<IConfigWindows, MasterDetailPage> UsePartialCollapse(
this IPlatformElementConfiguration<IConfigWindows, MasterDetailPage> config)
{
config.Element.SetValue(CollapseStyleProperty, CollapseStyle.Partial);
return config;
}
}
}

#region iOS
namespace Xamarin.Forms.PlatformConfiguration.iOS
{
public interface IConfigIOS : IConfigPlatform { }

public static class NavigationPageiOSpecifics
{
public static readonly BindableProperty IsNavigationBarTranslucentProperty =
BindableProperty.Create("IsNavigationBarTranslucent", typeof(bool),
typeof(NavigationPage), false);

public static bool GetNavigationBarIsTranslucent(this IPlatformElementConfiguration<IConfigIOS, NavigationPage> config)
{
return (bool)config.Element.GetValue(IsNavigationBarTranslucentProperty);
}

public static IPlatformElementConfiguration<IConfigIOS, NavigationPage> SetNavigationBarIsTranslucent(this IPlatformElementConfiguration<IConfigIOS, NavigationPage> config, bool value)
{
config.Element.SetValue(IsNavigationBarTranslucentProperty, value);
return config;
}
}
}

#endregion

#endregion

public class Configuration<TPlatform, TElement> : IPlatformElementConfiguration<TPlatform, TElement>
where TPlatform : IConfigPlatform
where TElement : Element

{
public Configuration(TElement element)
{
Element = element;
}

public TElement Element { get; }

public static Configuration<TPlatform, TElement> Create(TElement element)
{
return new Configuration<TPlatform, TElement>(element);
}
}
namespace ImAVendor.Forms.iOS
{
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOS;

#region Vendor

public static class FakeVendorExtensions
{
public static readonly BindableProperty FooProperty = BindableProperty.Create("VendorFoo", typeof(bool), typeof(IPlatformElementConfiguration<IConfigIOS, MasterDetailPage> ), true);
public static readonly BindableProperty FooProperty = BindableProperty.Create("VendorFoo", typeof(bool), typeof(IPlatformElementConfiguration<IConfigIOS, MasterDetailPage>), true);

public static void SetVendorFoo(this IPlatformElementConfiguration<IConfigIOS, MasterDetailPage> mdp, bool value)
public static void SetVendorFoo(this IPlatformElementConfiguration<IConfigIOS, MasterDetailPage> mdp, bool value)
{
mdp.Element.SetValue(FooProperty, value);
}

public static bool GetVendorFoo(this IPlatformElementConfiguration<IConfigIOS, MasterDetailPage> mdp)
public static bool GetVendorFoo(this IPlatformElementConfiguration<IConfigIOS, MasterDetailPage> mdp)
{
return (bool)mdp.Element.GetValue(FooProperty);
}
}

#endregion

// Should this be in a different namespace? Xamarin.Forms.PlatformSpecific

public enum CollapseStyle
{
None,
Partial
}

/// <summary>
/// Helper that handles storing and lookup of platform specifics implementations
/// </summary>
/// <typeparam name="TElement">The Element type</typeparam>
internal class PlatformConfigurationRegistry<TElement> : IElementConfiguration<TElement>
where TElement : Element
{
readonly TElement _element;
readonly Dictionary<Type, object> _platformSpecifics = new Dictionary<Type, object>();

internal PlatformConfigurationRegistry(TElement element)
{
_element = element;
}

public IPlatformElementConfiguration<T, TElement> On<T>() where T : IConfigPlatform
{
if (_platformSpecifics.ContainsKey(typeof(T)))
{
return (IPlatformElementConfiguration<T, TElement>)_platformSpecifics[typeof(T)];
}

var emptyConfig = Configuration<T, TElement>.Create(_element);

_platformSpecifics.Add(typeof(T), emptyConfig);

return emptyConfig;
}
}
}
9 changes: 5 additions & 4 deletions Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
using Xamarin.Forms.PlatformConfiguration.iOS;

#if __UNIFIED__
using UIKit;
Expand All @@ -21,9 +22,9 @@
using PointF = CoreGraphics.CGPoint;

#else
using nfloat=System.Single;
using nint=System.Int32;
using nuint=System.UInt32;
using nfloat = System.Single;
using nint = System.Int32;
using nuint = System.UInt32;
#endif

namespace Xamarin.Forms.Platform.iOS
Expand Down Expand Up @@ -520,7 +521,7 @@ void RemovePage(Page page)
if (page == null)
throw new ArgumentNullException("page");
if (page == Current)
throw new NotSupportedException(); // should never happen as NavPage protecs against this
throw new NotSupportedException(); // should never happen as NavPage protects against this

var target = Platform.GetRenderer(page).ViewController.ParentViewController;

Expand Down
19 changes: 19 additions & 0 deletions Xamarin.Forms.Xaml.UnitTests/PlatformSpecifics.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<forms:MasterDetailPage xmlns="clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:forms="http://xamarin.com/schemas/2014/forms"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.Android;assembly=Xamarin.Forms.Core"
x:Class="Xamarin.Forms.Xaml.UnitTests.PlatformSpecific"
android:MasterDetailPageConfig.SomeAndroidThing="9999"
x:Name="TestMDP">
<forms:MasterDetailPage.Master>
<forms:ContentPage x:Name="masterPage" Title="Platform Specifics" />
</forms:MasterDetailPage.Master>
<forms:MasterDetailPage.Detail>
<forms:NavigationPage>
<x:Arguments>
<forms:ContentPage />
</x:Arguments>
</forms:NavigationPage>
</forms:MasterDetailPage.Detail>
</forms:MasterDetailPage>
Loading

0 comments on commit a75157c

Please sign in to comment.