Skip to content

Commit

Permalink
Merge pull request #63 from muak/development
Browse files Browse the repository at this point in the history
fix Border
  • Loading branch information
muak authored Sep 28, 2020
2 parents 02760b7 + 61b6034 commit bcfd2a6
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 61 deletions.
14 changes: 7 additions & 7 deletions AiForms.Effects.Droid/AiForms.Effects.Droid.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Xamarin.Forms.4.4.0.991537\build\Xamarin.Forms.props" Condition="Exists('..\packages\Xamarin.Forms.4.4.0.991537\build\Xamarin.Forms.props')" />
<Import Project="..\packages\Xamarin.Forms.4.6.0.800\build\Xamarin.Forms.props" Condition="Exists('..\packages\Xamarin.Forms.4.6.0.800\build\Xamarin.Forms.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -105,19 +105,19 @@
<HintPath>..\packages\Xamarin.Android.Support.v7.MediaRouter.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.v7.MediaRouter.dll</HintPath>
</Reference>
<Reference Include="FormsViewGroup">
<HintPath>..\packages\Xamarin.Forms.4.4.0.991537\lib\MonoAndroid90\FormsViewGroup.dll</HintPath>
<HintPath>..\packages\Xamarin.Forms.4.6.0.800\lib\MonoAndroid90\FormsViewGroup.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Core">
<HintPath>..\packages\Xamarin.Forms.4.4.0.991537\lib\MonoAndroid90\Xamarin.Forms.Core.dll</HintPath>
<HintPath>..\packages\Xamarin.Forms.4.6.0.800\lib\MonoAndroid90\Xamarin.Forms.Core.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform.Android">
<HintPath>..\packages\Xamarin.Forms.4.4.0.991537\lib\MonoAndroid90\Xamarin.Forms.Platform.Android.dll</HintPath>
<HintPath>..\packages\Xamarin.Forms.4.6.0.800\lib\MonoAndroid90\Xamarin.Forms.Platform.Android.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform">
<HintPath>..\packages\Xamarin.Forms.4.4.0.991537\lib\MonoAndroid90\Xamarin.Forms.Platform.dll</HintPath>
<HintPath>..\packages\Xamarin.Forms.4.6.0.800\lib\MonoAndroid90\Xamarin.Forms.Platform.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Xaml">
<HintPath>..\packages\Xamarin.Forms.4.4.0.991537\lib\MonoAndroid90\Xamarin.Forms.Xaml.dll</HintPath>
<HintPath>..\packages\Xamarin.Forms.4.6.0.800\lib\MonoAndroid90\Xamarin.Forms.Xaml.dll</HintPath>
</Reference>
<Reference Include="Java.Interop" />
<Reference Include="Xamarin.Android.Arch.Core.Runtime">
Expand Down Expand Up @@ -264,5 +264,5 @@
<Import Project="..\packages\Xamarin.Android.Support.v7.RecyclerView.28.0.0.3\build\monoandroid90\Xamarin.Android.Support.v7.RecyclerView.targets" Condition="Exists('..\packages\Xamarin.Android.Support.v7.RecyclerView.28.0.0.3\build\monoandroid90\Xamarin.Android.Support.v7.RecyclerView.targets')" />
<Import Project="..\packages\Xamarin.Android.Support.Design.28.0.0.3\build\monoandroid90\Xamarin.Android.Support.Design.targets" Condition="Exists('..\packages\Xamarin.Android.Support.Design.28.0.0.3\build\monoandroid90\Xamarin.Android.Support.Design.targets')" />
<Import Project="..\packages\Xamarin.Android.Support.v7.MediaRouter.28.0.0.3\build\monoandroid90\Xamarin.Android.Support.v7.MediaRouter.targets" Condition="Exists('..\packages\Xamarin.Android.Support.v7.MediaRouter.28.0.0.3\build\monoandroid90\Xamarin.Android.Support.v7.MediaRouter.targets')" />
<Import Project="..\packages\Xamarin.Forms.4.4.0.991537\build\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.4.4.0.991537\build\Xamarin.Forms.targets')" />
<Import Project="..\packages\Xamarin.Forms.4.6.0.800\build\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.4.6.0.800\build\Xamarin.Forms.targets')" />
</Project>
35 changes: 31 additions & 4 deletions AiForms.Effects.Droid/BorderPlatformEffect.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using AiForms.Effects;
using AiForms.Effects.Droid;
using Android.Content.Res;
using Android.Graphics.Drawables;
using Android.Widget;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

Expand All @@ -17,13 +19,20 @@ public class BorderPlatformEffect : AiEffectBase
int _width;
float _radius;
Drawable _orgDrawable;
Drawable _orgTextBackground;

protected override void OnAttachedOverride()
{
_view = Container ?? Control;

_border = new GradientDrawable();
_orgDrawable = _view.Background;
if(Control is FormsEditTextBase editText)
{
_orgTextBackground = editText.Background;
// hide underline.
editText.Background = null;
}

UpdateRadius();
UpdateWidth();
Expand All @@ -34,7 +43,23 @@ protected override void OnAttachedOverride()
protected override void OnDetachedOverride()
{
if (!IsDisposed) { // Check disposed
_view.Background = _orgDrawable;
if(Control is FormsEditTextBase editText)
{
editText.Background = _orgTextBackground;
}

if(Element is Label label)
{
(_view as FormsTextView).SetBackgroundColor(label.BackgroundColor.ToAndroid());
}
else if(Element is Image image)
{
(_view as ImageView).SetBackgroundColor(image.BackgroundColor.ToAndroid());
}
else
{
_view.Background = _orgDrawable;
}

_view.SetPadding(0, 0, 0, 0);
_view.ClipToOutline = false;
Expand All @@ -43,6 +68,8 @@ protected override void OnDetachedOverride()
}
_border?.Dispose();
_border = null;
_orgDrawable = null;
_orgTextBackground = null;
_view = null;
System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached completely");
}
Expand Down Expand Up @@ -82,7 +109,7 @@ void UpdateRadius()

void UpdateWidth()
{
_width = (int)_view.Context.ToPixels(Border.GetWidth(Element));
_width = (int)_view.Context.ToPixels(Border.GetWidth(Element) ?? 0);
}

void UpdateColor()
Expand Down Expand Up @@ -110,7 +137,7 @@ void UpdateBorder()
_view.SetPadding(_width, _width, _width, _width);
_view.ClipToOutline = true; //not to overflow children

_view.SetBackground(_border);
_view.SetBackground(_border);
}

void UpdateBackgroundColor()
Expand Down
2 changes: 1 addition & 1 deletion AiForms.Effects.Droid/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
<package id="Xamarin.Android.Support.Vector.Drawable" version="28.0.0.3" targetFramework="monoandroid90" />
<package id="Xamarin.Android.Support.VersionedParcelable" version="28.0.0.3" targetFramework="monoandroid90" />
<package id="Xamarin.Android.Support.ViewPager" version="28.0.0.3" targetFramework="monoandroid90" />
<package id="Xamarin.Forms" version="4.4.0.991537" targetFramework="monoandroid90" />
<package id="Xamarin.Forms" version="4.6.0.800" targetFramework="monoandroid90" />
</packages>
13 changes: 5 additions & 8 deletions AiForms.Effects.iOS/AiForms.Effects.iOS.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Xamarin.Forms.4.4.0.991537\build\Xamarin.Forms.props" Condition="Exists('..\packages\Xamarin.Forms.4.4.0.991537\build\Xamarin.Forms.props')" />
<Import Project="..\packages\Xamarin.Forms.4.6.0.800\build\Xamarin.Forms.props" Condition="Exists('..\packages\Xamarin.Forms.4.6.0.800\build\Xamarin.Forms.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -52,16 +52,13 @@
<Reference Include="System.Core" />
<Reference Include="Xamarin.iOS" />
<Reference Include="Xamarin.Forms.Core">
<HintPath>..\packages\Xamarin.Forms.4.4.0.991537\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
<HintPath>..\packages\Xamarin.Forms.4.6.0.800\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform">
<HintPath>..\packages\Xamarin.Forms.4.4.0.991537\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform.iOS">
<HintPath>..\packages\Xamarin.Forms.4.4.0.991537\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll</HintPath>
<HintPath>..\packages\Xamarin.Forms.4.6.0.800\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Xaml">
<HintPath>..\packages\Xamarin.Forms.4.4.0.991537\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll</HintPath>
<HintPath>..\packages\Xamarin.Forms.4.6.0.800\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -103,5 +100,5 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
<Import Project="..\packages\Xamarin.Forms.4.4.0.991537\build\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.4.4.0.991537\build\Xamarin.Forms.targets')" />
<Import Project="..\packages\Xamarin.Forms.4.6.0.800\build\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.4.6.0.800\build\Xamarin.Forms.targets')" />
</Project>
4 changes: 3 additions & 1 deletion AiForms.Effects.iOS/BorderPlatformEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ protected override void OnDetached()
if (hasBorderTypes.Any(x => x == Element.GetType())) {
var textfield = _view as UITextField;
textfield.BorderStyle = UITextBorderStyle.RoundedRect;
// restore the BackgroundColor, because it is sometimes lost.
textfield.BackgroundColor = (Element as VisualElement)?.BackgroundColor.ToUIColor();
}
_view.ClipsToBounds = _clipsToBounds;
if(_view.Layer != null)
Expand Down Expand Up @@ -83,7 +85,7 @@ void UpdateRadius()

void UpdateWidth()
{
_view.Layer.BorderWidth = (float)Border.GetWidth(Element);
_view.Layer.BorderWidth = (float)(Border.GetWidth(Element) ?? 0);
}

void UpdateColor()
Expand Down
2 changes: 1 addition & 1 deletion AiForms.Effects.iOS/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Xamarin.Forms" version="4.4.0.991537" targetFramework="xamarinios10" />
<package id="Xamarin.Forms" version="4.6.0.800" targetFramework="xamarinios10" />
</packages>
2 changes: 1 addition & 1 deletion AiForms.Effects/AiForms.Effects.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.4.0.991537" />
<PackageReference Include="Xamarin.Forms" Version="4.6.0.800" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions AiForms.Effects/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public static double GetRadius(BindableObject view)
public static readonly BindableProperty WidthProperty =
BindableProperty.CreateAttached(
"Width",
typeof(double),
typeof(double?),
typeof(Border),
default(double),
default(double?),
propertyChanged: AiRoutingEffectBase.AddEffectHandler<BorderRoutingEffect>
);

Expand All @@ -90,7 +90,7 @@ public static double GetRadius(BindableObject view)
/// </summary>
/// <param name="view">View.</param>
/// <param name="value">Value.</param>
public static void SetWidth(BindableObject view, double value)
public static void SetWidth(BindableObject view, double? value)
{
view.SetValue(WidthProperty, value);
}
Expand All @@ -100,9 +100,9 @@ public static void SetWidth(BindableObject view, double value)
/// </summary>
/// <returns>The width.</returns>
/// <param name="view">View.</param>
public static double GetWidth(BindableObject view)
public static double? GetWidth(BindableObject view)
{
return (double)view.GetValue(WidthProperty);
return (double?)view.GetValue(WidthProperty);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ Entry・Picker・DatePicker・TimePickerはiOSではデフォルトで罫線を
* On
* Effect On/Off (true is On)
* Width (trigger)
* Border width (default 0)
* Border width (default null)
* Color
* Border color (default transparent)
* Radius (trigger)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ When specifying their width 0, it is possible that hide border.
* On
* Effect On/Off (true is On)
* Width (trigger)
* Border width (default 0)
* Border width (default null)
* Color
* Border color (default transparent)
* Radius (trigger)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\packages\Xamarin.Forms.4.4.0.991537\build\Xamarin.Forms.props" Condition="Exists('..\..\..\packages\Xamarin.Forms.4.4.0.991537\build\Xamarin.Forms.props')" />
<Import Project="..\..\..\packages\Xamarin.Forms.4.6.0.800\build\Xamarin.Forms.props" Condition="Exists('..\..\..\packages\Xamarin.Forms.4.6.0.800\build\Xamarin.Forms.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -150,19 +150,19 @@
<HintPath>..\..\..\packages\Xamarin.Android.Support.v7.MediaRouter.28.0.0.3\lib\monoandroid90\Xamarin.Android.Support.v7.MediaRouter.dll</HintPath>
</Reference>
<Reference Include="FormsViewGroup">
<HintPath>..\..\..\packages\Xamarin.Forms.4.4.0.991537\lib\MonoAndroid90\FormsViewGroup.dll</HintPath>
<HintPath>..\..\..\packages\Xamarin.Forms.4.6.0.800\lib\MonoAndroid90\FormsViewGroup.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Core">
<HintPath>..\..\..\packages\Xamarin.Forms.4.4.0.991537\lib\MonoAndroid90\Xamarin.Forms.Core.dll</HintPath>
<HintPath>..\..\..\packages\Xamarin.Forms.4.6.0.800\lib\MonoAndroid90\Xamarin.Forms.Core.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform.Android">
<HintPath>..\..\..\packages\Xamarin.Forms.4.4.0.991537\lib\MonoAndroid90\Xamarin.Forms.Platform.Android.dll</HintPath>
<HintPath>..\..\..\packages\Xamarin.Forms.4.6.0.800\lib\MonoAndroid90\Xamarin.Forms.Platform.Android.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform">
<HintPath>..\..\..\packages\Xamarin.Forms.4.4.0.991537\lib\MonoAndroid90\Xamarin.Forms.Platform.dll</HintPath>
<HintPath>..\..\..\packages\Xamarin.Forms.4.6.0.800\lib\MonoAndroid90\Xamarin.Forms.Platform.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Xaml">
<HintPath>..\..\..\packages\Xamarin.Forms.4.4.0.991537\lib\MonoAndroid90\Xamarin.Forms.Xaml.dll</HintPath>
<HintPath>..\..\..\packages\Xamarin.Forms.4.6.0.800\lib\MonoAndroid90\Xamarin.Forms.Xaml.dll</HintPath>
</Reference>
<Reference Include="SettingsView">
<HintPath>..\..\..\packages\AiForms.SettingsView.0.4.15\lib\MonoAndroid\SettingsView.dll</HintPath>
Expand Down Expand Up @@ -318,5 +318,5 @@
<Import Project="..\..\..\packages\Xamarin.Android.Support.v7.RecyclerView.28.0.0.3\build\monoandroid90\Xamarin.Android.Support.v7.RecyclerView.targets" Condition="Exists('..\..\..\packages\Xamarin.Android.Support.v7.RecyclerView.28.0.0.3\build\monoandroid90\Xamarin.Android.Support.v7.RecyclerView.targets')" />
<Import Project="..\..\..\packages\Xamarin.Android.Support.Design.28.0.0.3\build\monoandroid90\Xamarin.Android.Support.Design.targets" Condition="Exists('..\..\..\packages\Xamarin.Android.Support.Design.28.0.0.3\build\monoandroid90\Xamarin.Android.Support.Design.targets')" />
<Import Project="..\..\..\packages\Xamarin.Android.Support.v7.MediaRouter.28.0.0.3\build\monoandroid90\Xamarin.Android.Support.v7.MediaRouter.targets" Condition="Exists('..\..\..\packages\Xamarin.Android.Support.v7.MediaRouter.28.0.0.3\build\monoandroid90\Xamarin.Android.Support.v7.MediaRouter.targets')" />
<Import Project="..\..\..\packages\Xamarin.Forms.4.4.0.991537\build\Xamarin.Forms.targets" Condition="Exists('..\..\..\packages\Xamarin.Forms.4.4.0.991537\build\Xamarin.Forms.targets')" />
<Import Project="..\..\..\packages\Xamarin.Forms.4.6.0.800\build\Xamarin.Forms.targets" Condition="Exists('..\..\..\packages\Xamarin.Forms.4.6.0.800\build\Xamarin.Forms.targets')" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@
<package id="Xamarin.Android.Support.Vector.Drawable" version="28.0.0.3" targetFramework="monoandroid90" />
<package id="Xamarin.Android.Support.VersionedParcelable" version="28.0.0.3" targetFramework="monoandroid90" />
<package id="Xamarin.Android.Support.ViewPager" version="28.0.0.3" targetFramework="monoandroid90" />
<package id="Xamarin.Forms" version="4.4.0.991537" targetFramework="monoandroid90" />
<package id="Xamarin.Forms" version="4.6.0.800" targetFramework="monoandroid90" />
</packages>
Loading

0 comments on commit bcfd2a6

Please sign in to comment.