From ff92d3fb10cf550a4973208574114f88882ba9c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enis=20Necipo=C4=9Flu?= Date: Wed, 8 Aug 2018 11:27:07 +0300 Subject: [PATCH] Improvements & Fixes --- InputKit.nuspec | 17 +++++++++++++++-- InputKit/Platforms/iOS/MenuEffect.cs | 9 ++++----- InputKit/Shared/Controls/AdvancedEntry.cs | 13 +++++++++++-- InputKit/Shared/Controls/CheckBox.cs | 12 +++++++++--- InputKit/Shared/Controls/Dropdown.cs | 11 +++++++++-- InputKit/Shared/Controls/RadioButton.cs | 7 ++++++- InputKit/Shared/Controls/SelectionView.cs | 3 ++- README.md | 4 ++-- .../Sample.InputKit.Android.csproj | 6 ++++++ .../Sample.InputKit.iOS.csproj | 3 +++ Sample.InputKit/Sample.InputKit/App.xaml.cs | 2 +- .../Sample.InputKit/Sample.InputKit.csproj | 4 +--- 12 files changed, 69 insertions(+), 22 deletions(-) diff --git a/InputKit.nuspec b/InputKit.nuspec index 1cf6b8c..69f25c5 100644 --- a/InputKit.nuspec +++ b/InputKit.nuspec @@ -5,7 +5,7 @@ Xamarin.Forms.InputKit - 2.2.1 + 2.2.2 Enis Necipoglu @@ -26,7 +26,7 @@ false - CheckBox Color property fixed, CheckBox CommandParameter added. Some SelectionView improvements. + Highly dropdown bug fixed Common controls mostly required @@ -34,6 +34,19 @@ + + v.2.2.2 + Dropdown BidnableProperties added, + Dropdown selectedIndex bug fixed. + CanExecute check added all commands + CommandParameter added in AdvancedEntry + CommandParameter added in RadioButton + Checkbox unwanted shadow bug fixed + SelectionView TextColor fixed + iOS Dropdown improvements. + + Dropdown will be popover on iOS + v.2.2.0 Controls in this package are fully bindable and ready to use. AdvancedEntry Completed event added, diff --git a/InputKit/Platforms/iOS/MenuEffect.cs b/InputKit/Platforms/iOS/MenuEffect.cs index 5e06e54..f62b939 100644 --- a/InputKit/Platforms/iOS/MenuEffect.cs +++ b/InputKit/Platforms/iOS/MenuEffect.cs @@ -33,13 +33,12 @@ void OnPopupRequest(View view) RootViewController = UIApplication.SharedApplication.KeyWindow.RootViewController; - UIAlertController actionSheetAlert = UIAlertController.Create(null, null, UIAlertControllerStyle.ActionSheet); + UIAlertController actionSheetAlert = UIAlertController.Create(null, null, UIAlertControllerStyle.Alert); - int i = 0; - foreach (var item in Effect.Parent.ItemsSource) + //int i = 0; + for (int i = 0; i < Effect.Parent.ItemsSource.Count; i++) { - actionSheetAlert.AddAction(UIAlertAction.Create(item.ToString(), UIAlertActionStyle.Default, (action) => Effect.Parent.InvokeItemSelected(item.ToString(),i))); - i++; + actionSheetAlert.AddAction(UIAlertAction.Create(Effect.Parent.ItemsSource[i].ToString(), UIAlertActionStyle.Default, (action) => Effect.Parent.InvokeItemSelected(Effect.Parent.ItemsSource[i].ToString(),i))); } actionSheetAlert.AddAction(UIAlertAction.Create(UIAlertControllerCancelText, UIAlertActionStyle.Destructive, null)); diff --git a/InputKit/Shared/Controls/AdvancedEntry.cs b/InputKit/Shared/Controls/AdvancedEntry.cs index 0176a7c..7feaedb 100644 --- a/InputKit/Shared/Controls/AdvancedEntry.cs +++ b/InputKit/Shared/Controls/AdvancedEntry.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Text.RegularExpressions; using System.Windows.Input; using Xamarin.Forms; using Xamarin.Forms.Internals; @@ -60,9 +59,14 @@ public AdvancedEntry() }; txtInput.TextChanged += TxtInput_TextChanged; - txtInput.Completed += (s, args) => { CompletedCommand?.Execute(s); Completed?.Invoke(this, new EventArgs()); FocusNext(); }; + txtInput.Completed += (s, args) => { ExecuteCommand(); Completed?.Invoke(this, new EventArgs()); FocusNext(); }; imgWarning.IsVisible = this.IsRequired; } + void ExecuteCommand() + { + if (CompletedCommand?.CanExecute(CommandParameter ?? this) ?? false) + CompletedCommand?.Execute(CommandParameter ?? this); + } #region Not Implemented public bool IsSelected { get => false; set { } } public object Value { get; set; } @@ -300,6 +304,10 @@ public bool IsAnnotated /// Executed when entry completed. /// public ICommand CompletedCommand { get; set; } + /// + /// Parameter to send with CompletedCommand + /// + public object CommandParameter { get => GetValue(CommandParameterProperty); set => SetValue(CommandParameterProperty, value); } //-------------------------------------------------------------------------------------------------------------------------------------------------- #region BindableProperties #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member @@ -317,6 +325,7 @@ public bool IsAnnotated public static readonly BindableProperty IgnoreValidationMessageProperty = BindableProperty.Create(nameof(IgnoreValidationMessage), typeof(bool), typeof(AdvancedEntry), false, propertyChanged: (bo, ov, nv) => (bo as AdvancedEntry).DisplayValidation()); public static readonly BindableProperty IsRequiredProperty = BindableProperty.Create(nameof(IsRequired), typeof(bool), typeof(AdvancedEntry), false, propertyChanged: (bo, ov, nv) => (bo as AdvancedEntry).UpdateWarning()); public static readonly BindableProperty PlaceholderColorProperty = BindableProperty.Create(nameof(PlaceholderColor), typeof(Color), typeof(AdvancedEntry), Color.LightGray, propertyChanged: (bo, ov, nv) => (bo as AdvancedEntry).PlaceholderColor = (Color)nv); + public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(AdvancedEntry), propertyChanged: (bo, ov, nv) => (bo as AdvancedEntry).CommandParameter = nv); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member #endregion //-------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/InputKit/Shared/Controls/CheckBox.cs b/InputKit/Shared/Controls/CheckBox.cs index d95fd76..f2a3e26 100644 --- a/InputKit/Shared/Controls/CheckBox.cs +++ b/InputKit/Shared/Controls/CheckBox.cs @@ -24,7 +24,7 @@ public class CheckBox : StackLayout, IValidatable }; - Frame boxBackground = new Frame { Padding = 0, CornerRadius = GlobalSetting.CornerRadius, InputTransparent = true, HeightRequest = GlobalSetting.Size, WidthRequest = GlobalSetting.Size, BackgroundColor = GlobalSetting.BackgroundColor, MinimumWidthRequest = 35, BorderColor = GlobalSetting.BorderColor, VerticalOptions = LayoutOptions.CenterAndExpand }; + Frame boxBackground = new Frame { Padding = 0, CornerRadius = GlobalSetting.CornerRadius, InputTransparent = true, HeightRequest = GlobalSetting.Size, WidthRequest = GlobalSetting.Size, BackgroundColor = GlobalSetting.BackgroundColor, MinimumWidthRequest = 35, BorderColor = GlobalSetting.BorderColor, VerticalOptions = LayoutOptions.CenterAndExpand, HasShadow = false }; BoxView boxSelected = new BoxView { IsVisible = false, HeightRequest = GlobalSetting.Size * .60, WidthRequest = GlobalSetting.Size * .60, Color = GlobalSetting.Color, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Center }; Label lblSelected = new Label { Text = "✓", Margin = new Thickness(0, -1, 0, 0), FontSize = GlobalSetting.Size * .72, FontAttributes = FontAttributes.Bold, IsVisible = false, TextColor = GlobalSetting.Color, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.CenterAndExpand }; Label lblOption = new Label { VerticalOptions = LayoutOptions.CenterAndExpand, FontSize = GlobalSetting.FontSize, TextColor = GlobalSetting.TextColor, FontFamily = GlobalSetting.FontFamily }; @@ -44,9 +44,15 @@ public CheckBox() this.Children.Add(lblOption); this.GestureRecognizers.Add(new TapGestureRecognizer { - Command = new Command(() => { if (IsDisabled) return; IsChecked = !IsChecked; CheckChanged?.Invoke(this, new EventArgs()); CheckChangedCommand?.Execute(CommandParameter ?? this); ValidationChanged?.Invoke(this, new EventArgs()); }), + Command = new Command(() => { if (IsDisabled) return; IsChecked = !IsChecked; ExecuteCommand(); CheckChanged?.Invoke(this, new EventArgs()); ValidationChanged?.Invoke(this, new EventArgs()); }), }); } + + void ExecuteCommand() + { + if (CheckChangedCommand?.CanExecute(CommandParameter ?? this) ?? false) + CheckChangedCommand?.Execute(CommandParameter ?? this); + } async void Animate() { try @@ -144,7 +150,7 @@ public Color Color /// /// Border color of around CheckBox /// - public Color BorderColor { get => (Color)GetValue(BorderColorProperty); set => SetValue(BorderColorProperty,value); } + public Color BorderColor { get => (Color)GetValue(BorderColorProperty); set => SetValue(BorderColorProperty, value); } /// /// WARNING! : If you set this as required, user must set checked this control to be validated! /// diff --git a/InputKit/Shared/Controls/Dropdown.cs b/InputKit/Shared/Controls/Dropdown.cs index c9e2b17..3eba2df 100644 --- a/InputKit/Shared/Controls/Dropdown.cs +++ b/InputKit/Shared/Controls/Dropdown.cs @@ -63,7 +63,14 @@ private void Menu_Requested(object sender, EventArgs e) } private void Menu_Item_Selected(string item, int index) { - SelectedItem = ItemsSource[index]; + try + { + SelectedItem = ItemsSource[index]; + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine(ex.ToString()); + } } public IList ItemsSource { @@ -135,7 +142,7 @@ public void DisplayValidation() public static readonly BindableProperty BorderColorProperty = BindableProperty.Create(nameof(BorderColor), typeof(Color), typeof(Dropdown), GlobalSetting.BorderColor, propertyChanged: (bo, ov, nv) => (bo as Dropdown).BorderColor = (Color)nv); public static readonly BindableProperty PlaceholderProperty = BindableProperty.Create(nameof(Placeholder), typeof(string), typeof(Dropdown), null, propertyChanged: (bo, ov, nv) => (bo as Dropdown).Placeholder = (string)nv); public static readonly BindableProperty IsRequiredProperty = BindableProperty.Create(nameof(IsRequired), typeof(bool), typeof(Dropdown), false, propertyChanged: (bo, ov, nv) => (bo as Dropdown).IsRequired = (bool)nv); - public static readonly BindableProperty ValidationMessageProperty = BindableProperty.Create(nameof(ValidationMessage), typeof(string), typeof(Dropdown), false, propertyChanged: (bo, ov, nv) => (bo as Dropdown).ValidationMessage = (string)nv); + public static readonly BindableProperty ValidationMessageProperty = BindableProperty.Create(nameof(ValidationMessage), typeof(string), typeof(Dropdown), null, propertyChanged: (bo, ov, nv) => (bo as Dropdown).ValidationMessage = (string)nv); #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member #endregion } diff --git a/InputKit/Shared/Controls/RadioButton.cs b/InputKit/Shared/Controls/RadioButton.cs index c3b89e3..65c933a 100644 --- a/InputKit/Shared/Controls/RadioButton.cs +++ b/InputKit/Shared/Controls/RadioButton.cs @@ -37,6 +37,10 @@ public RadioButtonGroupView() /// Executes when tapped on RadioButton /// public ICommand SelectedItemChangedCommand { get; set; } + /// + /// Command Parameter will be sent in SelectedItemChangedCommand + /// + public object CommandParameter { get; set; } private void RadioButtonGroupView_ChildrenReordered(object sender, EventArgs e) { UpdateAllEvent(); @@ -73,7 +77,8 @@ void UpdateSelected(object selected, EventArgs e) SetValue(SelectedIndexProperty, this.SelectedIndex); OnPropertyChanged(nameof(SelectedIndex)); SelectedItemChanged?.Invoke(this, new EventArgs()); - SelectedItemChangedCommand?.Execute(this); + if (SelectedItemChangedCommand?.CanExecute(CommandParameter ?? this) ?? false) ; + SelectedItemChangedCommand?.Execute(CommandParameter ?? this); ValidationChanged?.Invoke(this, new EventArgs()); } /// diff --git a/InputKit/Shared/Controls/SelectionView.cs b/InputKit/Shared/Controls/SelectionView.cs index cb7f984..a4ef4a2 100644 --- a/InputKit/Shared/Controls/SelectionView.cs +++ b/InputKit/Shared/Controls/SelectionView.cs @@ -1,5 +1,6 @@ using Plugin.InputKit.Shared.Abstraction; using Plugin.InputKit.Shared.Configuration; +using Plugin.InputKit.Shared.Helpers; using System; using System.Collections; using System.Collections.Generic; @@ -400,7 +401,7 @@ private void UpdateColors() if (IsSelected) { this.BackgroundColor = SelectionColor; - this.TextColor = Color.WhiteSmoke; + this.TextColor = SelectionColor.ToSurfaceColor(); } else { diff --git a/README.md b/README.md index de36c60..69860fe 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

Xamarin.Forms.InputKit

-

CheckBox, Radio Button, Advanced Slider, Dropdows etc.

+

CheckBox, Radio Button, Advanced Entry, Advanced Slider, Dropdown etc.

@@ -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) - +

Nuget Package Available: : Xamarin.Forms.InputKit on NuGet diff --git a/Sample.InputKit/Sample.InputKit.Android/Sample.InputKit.Android.csproj b/Sample.InputKit/Sample.InputKit.Android/Sample.InputKit.Android.csproj index d6abfbf..ca1cbb9 100644 --- a/Sample.InputKit/Sample.InputKit.Android/Sample.InputKit.Android.csproj +++ b/Sample.InputKit/Sample.InputKit.Android/Sample.InputKit.Android.csproj @@ -47,12 +47,18 @@ + + 2.1.0.4 + + + 2.2.2 + diff --git a/Sample.InputKit/Sample.InputKit.iOS/Sample.InputKit.iOS.csproj b/Sample.InputKit/Sample.InputKit.iOS/Sample.InputKit.iOS.csproj index b773cda..75a969b 100644 --- a/Sample.InputKit/Sample.InputKit.iOS/Sample.InputKit.iOS.csproj +++ b/Sample.InputKit/Sample.InputKit.iOS/Sample.InputKit.iOS.csproj @@ -120,6 +120,9 @@ + + 2.2.2 + diff --git a/Sample.InputKit/Sample.InputKit/App.xaml.cs b/Sample.InputKit/Sample.InputKit/App.xaml.cs index 4293dd5..0b38956 100644 --- a/Sample.InputKit/Sample.InputKit/App.xaml.cs +++ b/Sample.InputKit/Sample.InputKit/App.xaml.cs @@ -13,7 +13,7 @@ public partial class App : Application public App() { InitializeComponent(); - + MainPage = new NavigationPage(new Sample.InputKit.MainPage()); } diff --git a/Sample.InputKit/Sample.InputKit/Sample.InputKit.csproj b/Sample.InputKit/Sample.InputKit/Sample.InputKit.csproj index 1001447..4baba3a 100644 --- a/Sample.InputKit/Sample.InputKit/Sample.InputKit.csproj +++ b/Sample.InputKit/Sample.InputKit/Sample.InputKit.csproj @@ -6,6 +6,7 @@ + @@ -22,7 +23,4 @@ *.xaml - - - \ No newline at end of file