Skip to content

Commit

Permalink
Bugs Fixed
Browse files Browse the repository at this point in the history
Checkbox Updated
ColorExtension added
  • Loading branch information
enisn committed Aug 1, 2018
1 parent b917a42 commit c3b846e
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 36 deletions.
8 changes: 7 additions & 1 deletion InputKit.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<id>Xamarin.Forms.InputKit</id>

<!-- The package version number that is used when resolving dependencies -->
<version>2.1.0-pre1</version>
<version>2.1.0</version>

<!-- Authors contain text that appears directly on the gallery -->
<authors>Enis Necipoglu</authors>
Expand Down Expand Up @@ -36,6 +36,12 @@
<description>
Controls in this package are fully bindable and ready to use.

v.2.1.0
AdvancedEntry Password Annotation problem fixed.
Material CheckBox coloring problem fixed.
ToSurfaceColor() extension added in ColorExtensions. (It used for CheckBox coloring)
AdvancedSlider looping problem fixed.


ChangeLog:
v.2.0.6
Expand Down
5 changes: 3 additions & 2 deletions InputKit/InputKit.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;MonoAndroid80;Xamarin.iOS10;Xamarin.TVOS10;Xamarin.WatchOS10;Xamarin.Mac20;</TargetFrameworks>
<!--<TargetFrameworks>netstandard2.0;MonoAndroid80;Xamarin.iOS10;</TargetFrameworks>-->
<!--<TargetFrameworks>netstandard2.0;MonoAndroid80;Xamarin.iOS10;Xamarin.TVOS10;Xamarin.WatchOS10;Xamarin.Mac20;</TargetFrameworks>-->
<TargetFrameworks>netstandard2.0;MonoAndroid80;Xamarin.iOS10;</TargetFrameworks>
<AssemblyName>Plugin.InputKit</AssemblyName>
<RootNamespace>Plugin.InputKit</RootNamespace>
<PackageId>Xamarin.Forms.InputKit</PackageId>
Expand Down Expand Up @@ -95,6 +95,7 @@
<None Remove="Shared\Controls\IconView.cs" />
<None Remove="Shared\Controls\RadioButton.cs" />
<None Remove="Shared\Controls\SelectionView.cs" />
<None Remove="Shared\Helpers\ColorExtensions.cs" />
</ItemGroup>

<!--
Expand Down
15 changes: 11 additions & 4 deletions InputKit/Shared/Controls/AdvancedEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AdvancedEntry : StackLayout, IValidatable
{
BackgroundColor = Color.White,
CornerRadius = 20,
BorderColor = (Color) Frame.BorderColorProperty.DefaultValue,
BorderColor = (Color)Frame.BorderColorProperty.DefaultValue,
Color = Color.Accent,
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
Size = -1,
Expand Down Expand Up @@ -73,7 +73,7 @@ public AdvancedEntry()
private AnnotationType _annotation;
private bool _isDisabled;
private bool _isRequired;
private int _minLength;
private int _minLength;
#endregion
public event EventHandler Completed;
public event EventHandler Clicked;
Expand Down Expand Up @@ -190,7 +190,9 @@ public int MaxLength
/// <summary>
/// To be added.
/// </summary>
public string FontFamily { get => txtInput.FontFamily;
public string FontFamily
{
get => txtInput.FontFamily;
set
{
lblTitle.FontFamily = value;
Expand Down Expand Up @@ -314,31 +316,36 @@ public bool IsAnnotated
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
#endregion
//--------------------------------------------------------------------------------------------------------------------------------------------------
void UpdateKeyboard(AnnotationType annotation)
public void UpdateKeyboard(AnnotationType annotation)
{
switch (annotation)
{
case AnnotationType.Letter:
case AnnotationType.Text:
txtInput.Keyboard = Keyboard.Chat;
txtInput.IsPassword = false;
break;
case AnnotationType.Integer:
case AnnotationType.Number:
case AnnotationType.Money:
txtInput.Keyboard = Keyboard.Numeric;
txtInput.IsPassword = false;
break;
case AnnotationType.Email:
txtInput.Keyboard = Keyboard.Email;
txtInput.IsPassword = false;
break;
case AnnotationType.Phone:
txtInput.Keyboard = Keyboard.Telephone;
txtInput.IsPassword = false;
break;
case AnnotationType.Password:
txtInput.Keyboard = Keyboard.Plain;
txtInput.IsPassword = true;
break;
default:
txtInput.Keyboard = Keyboard.Default;
txtInput.IsPassword = false;
break;
}
}
Expand Down
9 changes: 5 additions & 4 deletions InputKit/Shared/Controls/AdvancedSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ public AdvancedSlider()

private void Slider_ValueChanged(object sender, ValueChangedEventArgs e)
{
OnPropertyChanging(nameof(Value));
SetValue(ValueProperty, slider.Value);
//if (e.NewValue == e.OldValue || e.NewValue == slider.Value) return;


if (e.NewValue % StepValue != 0)
{
slider.Value = Math.Round(e.NewValue / StepValue) * StepValue;
return;
}
SetValue(ValueProperty, slider.Value);
UpdateValueText();
UpdateView();
}
Expand All @@ -73,7 +74,7 @@ protected override void OnSizeAllocated(double width, double height)
/// <summary>
/// Value of slider which user selected
/// </summary>
public double Value { get => slider.Value; set => slider.Value = value; }
public double Value { get => (double)GetValue(ValueProperty); set => SetValue(ValueProperty,value); }
///---------------------------------------------------------------------
/// <summary>
/// Title of slider, It'll be shown tp of slider
Expand Down Expand Up @@ -146,7 +147,7 @@ public Color TextColor
public string ValidationMessage { get; set; }

#region BindableProperties
public static readonly BindableProperty ValueProperty = BindableProperty.Create(nameof(Value), typeof(double), typeof(AdvancedSlider), 0.0, BindingMode.TwoWay, propertyChanged: (bo, ov, nv) => (bo as AdvancedSlider).Value = (double)nv);
public static readonly BindableProperty ValueProperty = BindableProperty.Create(nameof(Value), typeof(double), typeof(AdvancedSlider), 0.0, BindingMode.TwoWay, propertyChanged: (bo, ov, nv) => (bo as AdvancedSlider).slider.Value = (double)nv);
public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(AdvancedSlider), Color.Gray, propertyChanged: (bo, ov, nv) => (bo as AdvancedSlider).TextColor = (Color)nv);
#endregion
///---------------------------------------------------------------------
Expand Down
68 changes: 44 additions & 24 deletions InputKit/Shared/Controls/CheckBox.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Plugin.InputKit.Shared.Abstraction;
using Plugin.InputKit.Shared.Configuration;
using Plugin.InputKit.Shared.Helpers;
using System;
using System.Windows.Input;
using Xamarin.Forms;
Expand Down Expand Up @@ -107,7 +108,7 @@ public bool IsChecked
/// <summary>
/// Checkbox box background color. Default is LightGray
/// </summary>
public Color BoxBackgroundColor { get => boxBackground.BackgroundColor; set { if (this.Type == CheckType.Material) return; boxBackground.BackgroundColor = value; } }
public Color BoxBackgroundColor { get => (Color)GetValue(BoxBackgroundColorProperty); set => SetValue(BoxBackgroundColorProperty, value); }
/// <summary>
/// Gets or sets the checkbutton enabled or not. If checkbox is disabled, checkbox can not be interacted.
/// </summary>
Expand All @@ -117,21 +118,8 @@ public bool IsChecked
/// </summary>
public Color Color
{
get => boxSelected.Color;
set
{
boxSelected.Color = value;
if (Type == CheckType.Material)
{
boxBackground.BorderColor = value;
boxBackground.BackgroundColor = IsChecked ? value : Color.Transparent;
lblSelected.TextColor = Color.White;
}
else
{
lblSelected.TextColor = value;
}
}
get => (Color)GetValue(ColorProperty);
set => SetValue(ColorProperty, value);
}
/// <summary>
/// Color of text
Expand All @@ -156,7 +144,7 @@ public Color Color
/// <summary>
/// Border color of around CheckBox
/// </summary>
public Color BorderColor { get => boxBackground.BorderColor; set => boxBackground.BorderColor = value; }
public Color BorderColor { get => (Color)GetValue(BorderColorProperty); set => SetValue(BorderColorProperty,value); }
/// <summary>
/// WARNING! : If you set this as required, user must set checked this control to be validated!
/// </summary>
Expand All @@ -175,18 +163,52 @@ public Color Color
public string FontFamily { get => lblOption.FontFamily; set => lblOption.FontFamily = value; }
#region BindableProperties
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
public static readonly BindableProperty ColorProperty = BindableProperty.Create(nameof(Color), typeof(Color), typeof(CheckBox), Color.Accent, propertyChanged: (bo, ov, nv) => (bo as CheckBox).Color = (Color)nv);
public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(CheckBox), Color.Gray, propertyChanged: (bo, ov, nv) => (bo as CheckBox).TextColor = (Color)nv);
public static readonly BindableProperty ColorProperty = BindableProperty.Create(nameof(Color), typeof(Color), typeof(CheckBox), Color.Accent, propertyChanged: (bo, ov, nv) => (bo as CheckBox).UpdateColor());
public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(CheckBox), GlobalSetting.TextColor, propertyChanged: (bo, ov, nv) => (bo as CheckBox).TextColor = (Color)nv);
public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(CheckBox), false, BindingMode.TwoWay, propertyChanged: (bo, ov, nv) => (bo as CheckBox).IsChecked = (bool)nv);
public static readonly BindableProperty IsDisabledProperty = BindableProperty.Create(nameof(IsDisabled), typeof(bool), typeof(CheckBox), false, propertyChanged: (bo, ov, nv) => (bo as CheckBox).IsDisabled = (bool)nv);
public static readonly BindableProperty KeyProperty = BindableProperty.Create(nameof(Key), typeof(int), typeof(CheckBox), 0, propertyChanged: (bo, ov, nv) => (bo as CheckBox).Key = (int)nv);
public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(CheckBox), "", propertyChanged: (bo, ov, nv) => (bo as CheckBox).Text = (string)nv);
public static readonly BindableProperty CheckChangedCommandProperty = BindableProperty.Create(nameof(CheckChangedCommand), typeof(ICommand), typeof(CheckBox), null, propertyChanged: (bo, ov, nv) => (bo as CheckBox).CheckChangedCommand = (ICommand)nv);
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(CheckBox), null);
public static readonly BindableProperty BoxBackgroundColorProperty = BindableProperty.Create(nameof(BoxBackgroundColor), typeof(Color), typeof(CheckBox), Color.Gray, propertyChanged: (bo, ov, nv) => (bo as CheckBox).BoxBackgroundColor = (Color)nv);
public static readonly BindableProperty BoxBackgroundColorProperty = BindableProperty.Create(nameof(BoxBackgroundColor), typeof(Color), typeof(CheckBox), GlobalSetting.BackgroundColor, propertyChanged: (bo, ov, nv) => (bo as CheckBox).UpdateBoxBackground());
public static readonly BindableProperty TextFontSizeProperty = BindableProperty.Create(nameof(TextFontSize), typeof(double), typeof(CheckBox), 14.0, propertyChanged: (bo, ov, nv) => (bo as CheckBox).TextFontSize = (double)nv);
public static readonly BindableProperty BorderColorProperty = BindableProperty.Create(nameof(BorderColor), typeof(Color), typeof(CheckBox), GlobalSetting.BorderColor, propertyChanged: (bo, ov, nv) => (bo as CheckBox).UpdateBorderColor());
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
#endregion
void UpdateBoxBackground()
{
if (this.Type == CheckType.Material)
return;
boxBackground.BackgroundColor = BoxBackgroundColor;
}
void UpdateColor()
{
boxSelected.Color = Color;
if (Type == CheckType.Material)
{
boxBackground.BorderColor = Color;
boxBackground.BackgroundColor = IsChecked ? Color : Color.Transparent;
lblSelected.TextColor = Color.ToSurfaceColor();
}
else
{
boxBackground.BorderColor = BorderColor;
boxBackground.BackgroundColor = BackgroundColor;
lblSelected.TextColor = Color;
}
}
void UpdateBorderColor()
{
if (this.Type == CheckType.Material) return;
boxBackground.BorderColor = this.BorderColor;
}
void UpdateAllColors()
{
UpdateColor();
UpdateBoxBackground();
UpdateBorderColor();
}
void SetBoxSize(double value)
{
boxBackground.WidthRequest = value;
Expand Down Expand Up @@ -218,13 +240,11 @@ void UpdateType(CheckType _Type)
break;
case CheckType.Material:
lblSelected.Text = "✓";
lblSelected.TextColor = Color.White;
BoxBackgroundColor = Color.Transparent;
boxBackground.CornerRadius = 5;
BorderColor = Color;
boxBackground.Content = lblSelected;
return;
break;
}
UpdateAllColors();
}
/// <summary>
/// Not available for this control
Expand Down
20 changes: 20 additions & 0 deletions InputKit/Shared/Helpers/ColorExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Xamarin.Forms;

namespace Plugin.InputKit.Shared.Helpers
{
public static class ColorExtensions
{
/// <summary>
/// Defines a surface color will be black or white.
/// </summary>
/// <param name="color">Background color</param>
/// <returns>Surface color on background color</returns>
public static Color ToSurfaceColor(this Color color)
{
if ((color.R + color.G + color.B) >= 1.8)
return Color.Black;
else
return Color.White;
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

[![Build status](https://ci.appveyor.com/api/projects/status/st6lcbts9bkhxqub?svg=true)](https://ci.appveyor.com/project/enisn/xamarin-forms-inputkit)
[![CodeFactor](https://www.codefactor.io/repository/github/enisn/xamarin.forms.inputkit/badge)](https://www.codefactor.io/repository/github/enisn/xamarin.forms.inputkit)
<a href="https://www.nuget.org/packages/Xamarin.Forms.InputKit/"><img src="https://img.shields.io/badge/Nuget-2.0.6-blue.svg" /></a>
<a href="https://www.nuget.org/packages/Xamarin.Forms.InputKit/"><img src="https://img.shields.io/badge/Nuget-2.1.0-blue.svg" /></a>
<a href="https://github.com/enisn/Xamarin.Forms.InputKit/wiki"> <img src="https://img.shields.io/badge/Visit-WiKi-orange.svg"/></a>
<p>
<b>Nuget Package Available: </b> : <a href="https://www.nuget.org/packages/Xamarin.Forms.InputKit/"><img source="http://enisnecipoglu.com/Plugins/inputkit.png" height="15" />Xamarin.Forms.InputKit on NuGet</a>
Expand Down

0 comments on commit c3b846e

Please sign in to comment.