diff --git a/AutoSuggestBox/Extensions/AutoSuggestBoxViewExtensions.cs b/AutoSuggestBox/Extensions/AutoSuggestBoxViewExtensions.cs deleted file mode 100644 index 18dbf31..0000000 --- a/AutoSuggestBox/Extensions/AutoSuggestBoxViewExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Maui.AutoSuggestBox.Extensions; - - -/// -/// Extension methods to support -/// -public static class AutoSuggestBoxViewExtensions -{ - /// - /// Set LineWidth - /// - /// - /// line width - public static void SetLineWidth(this IAutoSuggestBox autosuggestBoxView, int textLength) - { - //autosuggestBoxView.LineWidth = textLength; - } -} diff --git a/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.Android.cs b/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.Android.cs index 926a8ee..dd4f9aa 100644 --- a/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.Android.cs +++ b/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.Android.cs @@ -89,56 +89,29 @@ public static void MapItemsSource(AutoSuggestBoxHandler handler, IAutoSuggestBox private void UpdateTextColor(AutoSuggestBoxView platformView) { var color = VirtualView?.TextColor; -#if NETFX_CORE - Control.Foreground = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Color.FromArgb((byte)(color.A * 255), (byte)(color.R * 255), (byte)(color.G * 255), (byte)(color.B * 255))); -#elif __ANDROID__ || __IOS__ platformView.SetTextColor(color.ToPlatform()); -#endif } private void UpdatePlaceholderTextColor(AutoSuggestBoxView platformView) { var placeholderColor = VirtualView?.PlaceholderTextColor; -#if NETFX_CORE - // Not currently supported by UWP's control - // UpdateColor(placeholderColor, ref _placeholderDefaultBrush, - // () => Control.PlaceholderForegroundBrush, brush => Control.PlaceholderForegroundBrush = brush); - // UpdateColor(placeholderColor, ref _defaultPlaceholderColorFocusBrush, - // () => Control.PlaceholderForegroundFocusBrush, brush => Control.PlaceholderForegroundFocusBrush = brush); -#elif __ANDROID__ || __IOS__ platformView.SetPlaceholderTextColor(placeholderColor); -#endif } private void UpdateDisplayMemberPath(AutoSuggestBoxHandler handler, IAutoSuggestBox view) { -#if NETFX_CORE - Control.DisplayMemberPath = Element.DisplayMemberPath; -#elif __ANDROID__ || __IOS__ handler.PlatformView.SetItems(view ?.ItemsSource?.OfType(), (o) => FormatType(o, view?.DisplayMemberPath), (o) => FormatType(o, view?.TextMemberPath)); -#endif } private void UpdateIsEnabled(AutoSuggestBoxView platformView) { -#if NETFX_CORE - platformView.IsEnabled = Element.IsEnabled; -#elif __ANDROID__ platformView.Enabled = (bool)(VirtualView?.IsEnabled); -#elif __IOS__ - platformView.UserInteractionEnabled = Element.IsEnabled; -#endif } private void UpdateItemsSource(AutoSuggestBoxView platformView) { -#if NETFX_CORE - platformView.ItemsSource = Element?.ItemsSource; -#elif __ANDROID__ || __IOS__ platformView.SetItems(VirtualView?.ItemsSource?.OfType(), (o) => FormatType(o, VirtualView?.DisplayMemberPath), (o) => FormatType(o, VirtualView?.TextMemberPath)); -#endif } -#if __ANDROID__ || __IOS__ private static string FormatType(object instance, string memberPath) { if (!string.IsNullOrEmpty(memberPath)) @@ -146,6 +119,4 @@ private static string FormatType(object instance, string memberPath) else return instance?.ToString() ?? ""; } -#endif - } diff --git a/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.iOS.cs b/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.iOS.cs index 07467a0..bcbc7eb 100644 --- a/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.iOS.cs +++ b/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.iOS.cs @@ -1,6 +1,9 @@ #nullable enable using Microsoft.Maui.Handlers; using Maui.AutoSuggestBox.Platforms.iOS; +using Microsoft.Maui.Platform; +using System.Drawing; +using UIKit; namespace Maui.AutoSuggestBox.Handlers; @@ -12,13 +15,66 @@ public partial class AutoSuggestBoxHandler : ViewHandler + //public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) + //{ + // var baseResult = base.GetDesiredSize(widthConstraint, heightConstraint); + // var testString = new Foundation.NSString("Tj"); + // var testSize = testString.GetSizeUsingAttributes(new UIStringAttributes { Font = Control.Font }); + // double height = baseHeight + testSize.Height; + // height = Math.Round(height); + + // return new SizeRequest(new global::Xamarin.Forms.Size(baseResult.Request.Width, height)); + //} + + //private void Control_EditingDidBegin(object sender, EventArgs e) + //{ + // Element?.SetValue(VisualElement.IsFocusedPropertyKey, true); + //} + //private void Control_EditingDidEnd(object sender, EventArgs e) + //{ + // Element?.SetValue(VisualElement.IsFocusedPropertyKey, false); + //} + public static void MapText(AutoSuggestBoxHandler handler, IAutoSuggestBox view) { if (handler.PlatformView.Text != view.Text) @@ -31,6 +87,7 @@ public static void MapTextColor(AutoSuggestBoxHandler handler, IAutoSuggestBox v } public static void MapPlaceholderText(AutoSuggestBoxHandler handler, IAutoSuggestBox view) { + //handler.PlatformView.Hint = view.PlaceholderText; handler.PlatformView.PlaceholderText = view.PlaceholderText; } public static void MapPlaceholderTextColor(AutoSuggestBoxHandler handler, IAutoSuggestBox view) @@ -39,11 +96,11 @@ public static void MapPlaceholderTextColor(AutoSuggestBoxHandler handler, IAutoS } public static void MapTextMemberPath(AutoSuggestBoxHandler handler, IAutoSuggestBox view) { - + handler.PlatformView?.SetItems(view.ItemsSource?.OfType(), (o) => FormatType(o, view.DisplayMemberPath), (o) => FormatType(o, view.TextMemberPath)); } public static void MapDisplayMemberPath(AutoSuggestBoxHandler handler, IAutoSuggestBox view) { - + handler.PlatformView.SetItems(view?.ItemsSource?.OfType(), (o) => FormatType(o, view?.DisplayMemberPath), (o) => FormatType(o, view?.TextMemberPath)); } public static void MapIsSuggestionListOpen(AutoSuggestBoxHandler handler, IAutoSuggestBox view) { @@ -51,16 +108,38 @@ public static void MapIsSuggestionListOpen(AutoSuggestBoxHandler handler, IAutoS } public static void MapUpdateTextOnSelect(AutoSuggestBoxHandler handler, IAutoSuggestBox view) { - + handler.PlatformView.UpdateTextOnSelect = view.UpdateTextOnSelect; } public static void MapIsEnabled(AutoSuggestBoxHandler handler, IAutoSuggestBox view) { - + handler.PlatformView.UserInteractionEnabled = view.IsEnabled; } public static void MapItemsSource(AutoSuggestBoxHandler handler, IAutoSuggestBox view) { handler.PlatformView.SetItems(view?.ItemsSource?.OfType(), (o) => FormatType(o, view?.DisplayMemberPath), (o) => FormatType(o, view?.TextMemberPath)); } + + private void UpdateTextColor(AutoSuggestBoxView platformView) + { + var color = VirtualView?.TextColor; + platformView.SetTextColor(color); + } + private void UpdatePlaceholderTextColor(AutoSuggestBoxView platformView) + { + var placeholderColor = VirtualView?.PlaceholderTextColor; + platformView.SetPlaceholderTextColor(placeholderColor); + } + private void UpdatePlaceholderText(AutoSuggestBoxView platformView) => platformView.PlaceholderText = VirtualView?.PlaceholderText; + + private void UpdateIsEnabled(AutoSuggestBoxView platformView) + { + platformView.UserInteractionEnabled = (bool)(VirtualView?.IsEnabled); + } + + private void UpdateItemsSource(AutoSuggestBoxView platformView) + { + platformView.SetItems(VirtualView?.ItemsSource?.OfType(), (o) => FormatType(o, VirtualView?.DisplayMemberPath), (o) => FormatType(o, VirtualView?.TextMemberPath)); + } private static string FormatType(object instance, string memberPath) { if (!string.IsNullOrEmpty(memberPath)) diff --git a/AutoSuggestBox/Maui.AutoSuggestBox.csproj b/AutoSuggestBox/Maui.AutoSuggestBox.csproj index be97276..7da5ac9 100644 --- a/AutoSuggestBox/Maui.AutoSuggestBox.csproj +++ b/AutoSuggestBox/Maui.AutoSuggestBox.csproj @@ -6,36 +6,51 @@ true enable - true - $(BaseIntermediateOutputPath)\GeneratedFiles - 14.2 30.0 Maui.AutoSuggestBox - - high - AutoSuggestBox - A control that allows you to design any type of switch/ toggle for .NET MAUI. It's also 100% accessible. - Morten Nielsen - en - Morten Nielsen - MIT - - $(DefineConstants); - false - Maui AutoSuggest Box - Use an AutoSuggestBox to provide a list of suggestions for a user to select from as they type. - $(AssemblyName) ($(TargetFramework)) - 1.0.0.0 - 1.0.0.0 - 1.0.0 - $(Version)$(VersionSuffix) - true - dot,maui,control,custom,autosuggest - Debug;Release - + + 1.0.0.0 + 1.0.0.0 + 1.0.0 + en + latest + high + AutoSuggestBox + A control that allows you to design any type of switch/ toggle for .NET MAUI. It's also 100% accessible. + Morten Nielsen + Morten Nielsen + MIT + + $(DefineConstants); + false + Maui AutoSuggest Box + Use an AutoSuggestBox to provide a list of suggestions for a user to select from as they type. + $(AssemblyName) ($(TargetFramework)) + $(Version)$(VersionSuffix) + true + Maui dotnet.Maui .net-Maui AutoSuggestBox uikit TextInputLayout + Debug;Release + true + + + + 4 + latest + + + latest + true + + + + false + + + false +