Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uniwersal platform implementation of rounded box based on windows pho… #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ Resource.Designer.cs
.userprefs
.suo
*.user
*.bak
*.bak
/RoundedBoxView/SampleApp/SampleApp.UWP/project.lock.json
1,287 changes: 1,036 additions & 251 deletions RoundedBoxView/RoundedBoxView.sln

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Xamarin.Forms;
using Rectangle = Windows.UI.Xaml.Shapes.Rectangle;

namespace RoundedBoxView.Forms.Plugin.WindowsUniversal.ExtensionMethods
{
public static class BorderExtensions
{
public static void InitializeFrom(this Border nativeControl, Abstractions.RoundedBoxView formsControl)
{
if (nativeControl == null || formsControl == null)
return;

nativeControl.Height = formsControl.HeightRequest;
nativeControl.Width = formsControl.WidthRequest;
nativeControl.UpdateCornerRadius(formsControl.CornerRadius);
nativeControl.UpdateBorderColor(formsControl.BorderColor);

var rectangle = new Rectangle();

rectangle.InitializeFrom(formsControl);

nativeControl.Child = rectangle;
}

public static void UpdateFrom(this Border nativeControl, Abstractions.RoundedBoxView formsControl,
string propertyChanged)
{
if (nativeControl == null || formsControl == null)
return;

if (propertyChanged == Abstractions.RoundedBoxView.CornerRadiusProperty.PropertyName)
{
nativeControl.UpdateCornerRadius(formsControl.CornerRadius);

var rect = nativeControl.Child as Rectangle;

if (rect != null)
{
rect.UpdateCornerRadius(formsControl.CornerRadius);
}

}
if (propertyChanged == VisualElement.BackgroundColorProperty.PropertyName)
{
var rect = nativeControl.Child as Rectangle;

if (rect != null)
{
rect.UpdateBackgroundColor(formsControl.BackgroundColor);
}
}

if (propertyChanged == Abstractions.RoundedBoxView.BorderColorProperty.PropertyName)
{
nativeControl.Background = formsControl.BorderColor.ToBrush();
}

if (propertyChanged == Abstractions.RoundedBoxView.BorderThicknessProperty.PropertyName)
{
var rect = nativeControl.Child as Rectangle;

if (rect != null)
{
rect.UpdateBorderThickness(formsControl.BorderThickness, formsControl.HeightRequest, formsControl.WidthRequest);
}
}
}

private static void UpdateCornerRadius(this Border nativeControl, double cornerRadius)
{
var relativeBorderCornerRadius = cornerRadius * 1.25;

nativeControl.CornerRadius = new CornerRadius(relativeBorderCornerRadius);
}

public static void UpdateBorderColor(this Border nativeControl, Color backgroundColor)
{
nativeControl.Background = backgroundColor.ToBrush();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Windows.UI;
using Windows.UI.Xaml.Media;

namespace RoundedBoxView.Forms.Plugin.WindowsUniversal.ExtensionMethods
{
public static class ColorExtensions
{
public static Brush ToBrush(this Xamarin.Forms.Color color)
{
return new SolidColorBrush(color.ToMediaColor());
}

public static Color ToMediaColor(this Xamarin.Forms.Color color)
{
return Color.FromArgb((byte)(color.A * 255.0), (byte)(color.R * 255.0), (byte)(color.G * 255.0), (byte)(color.B * 255.0));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Windows.UI.Xaml.Shapes;
using Color = Xamarin.Forms.Color;

namespace RoundedBoxView.Forms.Plugin.WindowsUniversal.ExtensionMethods
{
public static class RectangleExtensions
{
public static void InitializeFrom(this Rectangle nativeControl, Abstractions.RoundedBoxView formsControl)
{
if (nativeControl == null || formsControl == null)
return;

nativeControl.UpdateCornerRadius(formsControl.CornerRadius);
nativeControl.UpdateBackgroundColor(formsControl.BackgroundColor);
nativeControl.UpdateBorderThickness(formsControl.BorderThickness, formsControl.HeightRequest, formsControl.WidthRequest);
}

public static void UpdateCornerRadius(this Rectangle nativeControl, double cornerRadius)
{
var relativeBorderCornerRadius = cornerRadius * 1.25;

nativeControl.RadiusX = relativeBorderCornerRadius;
nativeControl.RadiusY = relativeBorderCornerRadius;
}

public static void UpdateBackgroundColor(this Rectangle nativeControl, Color backgroundColor)
{
nativeControl.Fill = backgroundColor.ToBrush();
}

/// <summary>
/// Changes the border size by changing the height and width of the rectangle
/// </summary>
/// <param name="nativeControl"></param>
/// <param name="borderThickness"></param>
/// <param name="formsControlHeightRequest"></param>
/// <param name="formsControlWidthRequest"></param>
public static void UpdateBorderThickness(this Rectangle nativeControl, int borderThickness, double formsControlHeightRequest, double formsControlWidthRequest)
{
var relativeBorderThickness = borderThickness * 1.7;

var rectHeight = formsControlHeightRequest - relativeBorderThickness;
var rectWidth = formsControlWidthRequest - relativeBorderThickness;

nativeControl.Height = rectHeight;
nativeControl.Width = rectWidth;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RoundedBoxView.Forms.Plugin.WindowsUniversal")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RoundedBoxView.Forms.Plugin.WindowsUniversal")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ComVisible(false)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains Runtime Directives, specifications about types your application accesses
through reflection and other dynamic code patterns. Runtime Directives are used to control the
.NET Native optimizer and ensure that it does not remove code accessed by your library. If your
library does not do any reflection, then you generally do not need to edit this file. However,
if your library reflects over types, especially types passed to it or derived from its types,
then you should write Runtime Directives.

The most common use of reflection in libraries is to discover information about types passed
to the library. Runtime Directives have three ways to express requirements on types passed to
your library.

1. Parameter, GenericParameter, TypeParameter, TypeEnumerableParameter
Use these directives to reflect over types passed as a parameter.

2. SubTypes
Use a SubTypes directive to reflect over types derived from another type.

3. AttributeImplies
Use an AttributeImplies directive to indicate that your library needs to reflect over
types or methods decorated with an attribute.

For more information on writing Runtime Directives for libraries, please visit
http://go.microsoft.com/fwlink/?LinkID=391919
-->
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Library Name="RoundedBoxView.Forms.Plugin.WindowsUniversal">

<!-- add directives for your library here -->

</Library>
</Directives>
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{611BEFDE-23B3-40C1-AB00-754995E009AB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RoundedBoxView.Forms.Plugin.WindowsUniversal</RootNamespace>
<AssemblyName>RoundedBoxView.Forms.Plugin.WindowsUniversal</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.14393.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<PlatformTarget>ARM</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<PlatformTarget>ARM</PlatformTarget>
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExtensionMethods\BorderExtensions.cs" />
<Compile Include="ExtensionMethods\ColorExtensions.cs" />
<Compile Include="ExtensionMethods\RectangleExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RoundedBoxViewRenderer.cs" />
<EmbeddedResource Include="Properties\RoundedBoxView.Forms.Plugin.WindowsUniversal.rd.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RoundedBoxView.Forms.Plugin.Abstractions\RoundedBoxView.Forms.Plugin.Abstractions.csproj">
<Project>{14c534b6-1984-41a9-a384-d3a5508588e3}</Project>
<Name>RoundedBoxView.Forms.Plugin.Abstractions</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(NuGetPackageRoot)' == ''">
<NuGetPackageRoot>$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
</PropertyGroup>
<ImportGroup>
<Import Project="$(NuGetPackageRoot)\Xamarin.Forms\2.0.0.6490\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('$(NuGetPackageRoot)\Xamarin.Forms\2.0.0.6490\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
</ImportGroup>
</Project>
Loading