diff --git a/AutoSuggestBox/.editorconfig b/AutoSuggestBox/.editorconfig
new file mode 100644
index 0000000..f21cbf4
--- /dev/null
+++ b/AutoSuggestBox/.editorconfig
@@ -0,0 +1,10 @@
+[*.cs]
+
+# CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
+dotnet_diagnostic.CS8632.severity = none
+dotnet_diagnostic.CA1822.severity = none
+dotnet_code_quality.CA1826.exclude_ordefault_methods = true
+dotnet_diagnostic.IDE1006.severity = none
+dotnet_diagnostic.IDE0300.severity = none
+dotnet_diagnostic.IDE0305.severity = none
+dotnet_diagnostic.IDE0028.severity = none
diff --git a/AutoSuggestBox/.gitignore b/AutoSuggestBox/.gitignore
new file mode 100644
index 0000000..9491a2f
--- /dev/null
+++ b/AutoSuggestBox/.gitignore
@@ -0,0 +1,363 @@
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Oo]ut/
+[Ll]og/
+[Ll]ogs/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUnit
+*.VisualState.xml
+TestResult.xml
+nunit-*.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
\ No newline at end of file
diff --git a/AutoSuggestBox/Controls/AutoSuggestBox.cs b/AutoSuggestBox/Controls/AutoSuggestBox.cs
index c8c7772..6257470 100644
--- a/AutoSuggestBox/Controls/AutoSuggestBox.cs
+++ b/AutoSuggestBox/Controls/AutoSuggestBox.cs
@@ -8,25 +8,20 @@ public class AutoSuggestBox : View, IAutoSuggestBox
{
private bool suppressTextChangedEvent;
- readonly WeakEventManager querySubmittedEventManager = new();
- public readonly WeakEventManager textChangedEventManager = new();
- readonly WeakEventManager suggestionChosenEventManager = new();
-
///
/// Initializes a new instance of the class
///
public AutoSuggestBox()
{
- //Unloaded += OnAutoSuggestBoxUnloaded;
}
///
/// Gets or sets the Text property
///
///
- public string Text
+ public string? Text
{
- get { return (string)GetValue(TextProperty); }
+ get { return GetValue(TextProperty) as string; }
set { SetValue(TextProperty, value); }
}
@@ -36,22 +31,12 @@ public string Text
public static readonly BindableProperty TextProperty =
BindableProperty.Create(nameof(Text), typeof(string), typeof(AutoSuggestBox), "", BindingMode.OneWay, null, OnTextPropertyChanged);
- ///
- /// This command is invoked whenever the text on has changed.
- /// Note that this is fired after the tap or click is lifted.
- /// This is a bindable property.
- ///
- public ICommand? TextChangedCommand
- {
- get => (ICommand?)GetValue(TextChangedCommandProperty);
- set => SetValue(TextChangedCommandProperty, value);
- }
private static void OnTextPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
var box = (AutoSuggestBox)bindable;
if (!box.suppressTextChangedEvent) //Ensure this property changed didn't get call because we were updating it from the native text property
- box.textChangedEventManager.HandleEvent(box, new AutoSuggestBoxTextChangedEventArgs("", AutoSuggestBoxTextChangeReason.ProgrammaticChange), nameof(TextChanged));
+ box.TextChanged?.Invoke(box, new AutoSuggestBoxTextChangedEventArgs(AutoSuggestBoxTextChangeReason.ProgrammaticChange));
}
///
@@ -74,9 +59,9 @@ public Color TextColor
/// Gets or sets the PlaceholderText
///
///
- public string PlaceholderText
+ public string? PlaceholderText
{
- get { return (string)GetValue(PlaceholderTextProperty); }
+ get { return GetValue(PlaceholderTextProperty) as string; }
set { SetValue(PlaceholderTextProperty, value); }
}
@@ -110,9 +95,9 @@ public Color PlaceholderTextColor
/// The property path that is used to get the value for display in the text box portion
/// of the AutoSuggestBox control, when an item is selected.
///
- public string TextMemberPath
+ public string? TextMemberPath
{
- get { return (string)GetValue(TextMemberPathProperty); }
+ get { return GetValue(TextMemberPathProperty) as string; }
set { SetValue(TextMemberPathProperty, value); }
}
@@ -129,9 +114,9 @@ public string TextMemberPath
/// The name or path of the property that is displayed for each the data item in
/// the control. The default is an empty string ("").
///
- public string DisplayMemberPath
+ public string? DisplayMemberPath
{
- get { return (string)GetValue(DisplayMemberPathProperty); }
+ get { return GetValue(DisplayMemberPathProperty) as string; }
set { SetValue(DisplayMemberPathProperty, value); }
}
@@ -179,7 +164,7 @@ public bool UpdateTextOnSelect
/// Gets or sets the header object for the text box portion of this control.
///
/// The header object for the text box portion of this control.
- public System.Collections.IList ItemsSource
+ public System.Collections.IList? ItemsSource
{
get { return GetValue(ItemsSourceProperty) as System.Collections.IList; }
set { SetValue(ItemsSourceProperty, value); }
@@ -191,66 +176,41 @@ public System.Collections.IList ItemsSource
public static readonly BindableProperty ItemsSourceProperty =
BindableProperty.Create(nameof(ItemsSource), typeof(System.Collections.IList), typeof(AutoSuggestBox), null, BindingMode.OneWay, null, null);
- ///
- /// Backing BindableProperty for the property.
- ///
- public static readonly BindableProperty TextChangedCommandProperty = BindableProperty.Create(nameof(TextChangedCommand), typeof(ICommand), typeof(AutoSuggestBox));
-
- public event EventHandler SuggestionChosen
- {
- add => suggestionChosenEventManager.AddEventHandler(value);
- remove => suggestionChosenEventManager.RemoveEventHandler(value);
- }
- public void RaiseSuggestionChosen(AutoSuggestBoxSuggestionChosenEventArgs args)
+ void IAutoSuggestBox.SuggestionChosen(object selectedItem)
{
- suggestionChosenEventManager.HandleEvent(this, args, nameof(SuggestionChosen));
+ SuggestionChosen?.Invoke(this, new AutoSuggestBoxSuggestionChosenEventArgs(selectedItem));
}
///
/// Raised before the text content of the editable control component is updated.
///
- public event EventHandler TextChanged
- {
- add => textChangedEventManager.AddEventHandler(value);
- remove => textChangedEventManager.RemoveEventHandler(value);
- }
+ public event EventHandler? SuggestionChosen;
// Called by the native control when users enter text
- public void NativeControlTextChanged(AutoSuggestBoxTextChangedEventArgs args)
+ void IAutoSuggestBox.NativeControlTextChanged(string? text, AutoSuggestBoxTextChangeReason reason)
{
suppressTextChangedEvent = true; //prevent loop of events raising, as setting this property will make it back into the native control
- Text = args.Text;
+ Text = text;
suppressTextChangedEvent = false;
- textChangedEventManager.HandleEvent(this, args, nameof(TextChanged));
-
- //if (TextChangedCommand?.CanExecute(args.Text) ?? false)
- //{
- // TextChangedCommand.Execute(args.Text);
- //}
+ TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs(reason));
}
///
/// Raised after the text content of the editable control component is updated.
///
- public void RaiseQuerySubmitted(AutoSuggestBoxQuerySubmittedEventArgs args)
+
+ public event EventHandler? TextChanged;
+
+ void IAutoSuggestBox.RaiseQuerySubmitted(string? queryText, object? chosenSuggestion)
{
- querySubmittedEventManager.HandleEvent(this, args, nameof(QuerySubmitted));
+ QuerySubmitted?.Invoke(this, new AutoSuggestBoxQuerySubmittedEventArgs(queryText, chosenSuggestion));
}
///
- /// Executes QuerySubmitted event
/// Occurs when the user submits a search query.
///
- public event EventHandler QuerySubmitted
- {
- add => querySubmittedEventManager.AddEventHandler(value);
- remove => querySubmittedEventManager.RemoveEventHandler(value);
- }
- //void OnAutoSuggestBoxUnloaded(object? sender, EventArgs e)
- //{
- // Unloaded -= OnAutoSuggestBoxUnloaded;
- // Handler?.DisconnectHandler();
- //}
+ public event EventHandler? QuerySubmitted;
+
}
}
diff --git a/AutoSuggestBox/Controls/AutoSuggestBoxQuerySubmittedEventArgs.cs b/AutoSuggestBox/Controls/AutoSuggestBoxQuerySubmittedEventArgs.cs
index 3cfa919..32271df 100644
--- a/AutoSuggestBox/Controls/AutoSuggestBoxQuerySubmittedEventArgs.cs
+++ b/AutoSuggestBox/Controls/AutoSuggestBoxQuerySubmittedEventArgs.cs
@@ -10,7 +10,7 @@ public sealed class AutoSuggestBoxQuerySubmittedEventArgs : EventArgs
///
///
///
- internal AutoSuggestBoxQuerySubmittedEventArgs(string queryText, object chosenSuggestion)
+ internal AutoSuggestBoxQuerySubmittedEventArgs(string? queryText, object? chosenSuggestion)
{
QueryText = queryText;
ChosenSuggestion = chosenSuggestion;
@@ -20,12 +20,12 @@ internal AutoSuggestBoxQuerySubmittedEventArgs(string queryText, object chosenSu
/// Gets the suggested result that the use chose.
///
/// The suggested result that the use chose.
- public object ChosenSuggestion { get; }
+ public object? ChosenSuggestion { get; }
///
/// The query text of the current search.
///
/// Gets the query text of the current search.
- public string QueryText { get; }
+ public string? QueryText { get; }
}
}
diff --git a/AutoSuggestBox/Controls/AutoSuggestBoxTextChangedEventArgs.cs b/AutoSuggestBox/Controls/AutoSuggestBoxTextChangedEventArgs.cs
index 2556c0b..86c403a 100644
--- a/AutoSuggestBox/Controls/AutoSuggestBoxTextChangedEventArgs.cs
+++ b/AutoSuggestBox/Controls/AutoSuggestBoxTextChangedEventArgs.cs
@@ -9,12 +9,11 @@ public sealed class AutoSuggestBoxTextChangedEventArgs : EventArgs
/// Initializes a new instance of the class.
///
///
- internal AutoSuggestBoxTextChangedEventArgs(string text,AutoSuggestBoxTextChangeReason reason)
+ internal AutoSuggestBoxTextChangedEventArgs(AutoSuggestBoxTextChangeReason reason)
{
- Text = text;
Reason = reason;
}
- public string Text { get; }
+
///
/// Returns a Boolean value indicating if the current value of the TextBox is unchanged from the point in time when the TextChanged event was raised.
///
diff --git a/AutoSuggestBox/Controls/IAutoSuggestBox.shared.cs b/AutoSuggestBox/Controls/IAutoSuggestBox.shared.cs
index 1d77d15..9249ac3 100644
--- a/AutoSuggestBox/Controls/IAutoSuggestBox.shared.cs
+++ b/AutoSuggestBox/Controls/IAutoSuggestBox.shared.cs
@@ -12,7 +12,7 @@ public interface IAutoSuggestBox : IView
bool UpdateTextOnSelect { get; set; }
System.Collections.IList ItemsSource { get; set; }
- void RaiseSuggestionChosen(AutoSuggestBoxSuggestionChosenEventArgs e);
- void NativeControlTextChanged(AutoSuggestBoxTextChangedEventArgs e);
- void RaiseQuerySubmitted(AutoSuggestBoxQuerySubmittedEventArgs e);
+ void SuggestionChosen(object selectedItem);
+ void NativeControlTextChanged(string? text, AutoSuggestBoxTextChangeReason reason);
+ void RaiseQuerySubmitted(string? queryText, object? chosenSuggestion);
}
diff --git a/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.Android.cs b/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.Android.cs
index bad908e..bd03280 100644
--- a/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.Android.cs
+++ b/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.Android.cs
@@ -8,7 +8,6 @@ namespace Maui.AutoSuggestBox.Handlers;
public partial class AutoSuggestBoxHandler : ViewHandler
{
///
- //protected override AutoSuggestBoxView CreatePlatformView() => new AutoSuggestBoxView(Context);
protected override AutoSuggestBoxView CreatePlatformView() => new(Context);
protected override void ConnectHandler(AutoSuggestBoxView platformView)
{
@@ -17,30 +16,26 @@ protected override void ConnectHandler(AutoSuggestBoxView platformView)
platformView.TextChanged += OnPlatformViewTextChanged;
platformView.QuerySubmitted += OnPlatformViewQuerySubmitted;
platformView.SetTextColor(VirtualView?.TextColor.ToPlatform() ?? VirtualView.TextColor.ToPlatform());
- UpdateTextColor(platformView);
- UpdatePlaceholderText(platformView);
}
protected override void DisconnectHandler(AutoSuggestBoxView platformView)
{
+ base.DisconnectHandler(platformView);
platformView.SuggestionChosen -= OnPlatformViewSuggestionChosen;
platformView.TextChanged -= OnPlatformViewTextChanged;
platformView.QuerySubmitted -= OnPlatformViewQuerySubmitted;
-
- platformView.Dispose();
- base.DisconnectHandler(platformView);
}
private void OnPlatformViewSuggestionChosen(object? sender, AutoSuggestBoxSuggestionChosenEventArgs e)
{
- VirtualView?.RaiseSuggestionChosen(e);
+ VirtualView?.SuggestionChosen(e.SelectedItem);
}
private void OnPlatformViewTextChanged(object? sender, AutoSuggestBoxTextChangedEventArgs e)
{
- VirtualView?.NativeControlTextChanged(e);
+ VirtualView?.NativeControlTextChanged(PlatformView.Text, (AutoSuggestBoxTextChangeReason)e.Reason);
}
private void OnPlatformViewQuerySubmitted(object? sender, AutoSuggestBoxQuerySubmittedEventArgs e)
{
- VirtualView?.RaiseQuerySubmitted(e);
+ VirtualView?.RaiseQuerySubmitted(e.QueryText, e.ChosenSuggestion);
}
public static void MapText(AutoSuggestBoxHandler handler, IAutoSuggestBox view)
{
@@ -87,8 +82,7 @@ public static void MapItemsSource(AutoSuggestBoxHandler handler, IAutoSuggestBox
private void UpdateTextColor(AutoSuggestBoxView platformView)
{
- var color = VirtualView?.TextColor;
- platformView.SetTextColor(color.ToPlatform());
+ platformView.SetTextColor(VirtualView?.TextColor);
}
private void UpdateDisplayMemberPath(AutoSuggestBoxHandler handler, IAutoSuggestBox view)
{
diff --git a/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.cs b/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.cs
index 4b74891..9f9d9c2 100644
--- a/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.cs
+++ b/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.cs
@@ -1,21 +1,15 @@
-#if ANDROID
-using PlatformView = Maui.AutoSuggestBox.Platforms.Android.AutoSuggestBoxView;
-#elif IOS
-using PlatformView = Maui.AutoSuggestBox.Platforms.iOS.AutoSuggestBoxView;
-#elif (NETSTANDARD || !PLATFORM) || (NET6_0_OR_GREATER && !IOS && !ANDROID)
-using PlatformView = System.Object;
-#endif
-using Microsoft.Maui.Handlers;
-
-namespace Maui.AutoSuggestBox.Handlers;
+namespace Maui.AutoSuggestBox.Handlers;
///
-/// AutoSuggestBox handler
+/// Platform specific renderer for the
///
public partial class AutoSuggestBoxHandler
{
+ ///
+ /// Property mapper for the control.
+ ///
public static IPropertyMapper PropertyMapper =
- new PropertyMapper(ViewMapper)
+ new PropertyMapper(ViewMapper)
{
[nameof(IAutoSuggestBox.Text)] = MapText,
[nameof(IAutoSuggestBox.TextColor)] = MapTextColor,
@@ -23,10 +17,10 @@ public partial class AutoSuggestBoxHandler
[nameof(IAutoSuggestBox.PlaceholderTextColor)] = MapPlaceholderTextColor,
[nameof(IAutoSuggestBox.TextMemberPath)] = MapTextMemberPath,
[nameof(IAutoSuggestBox.DisplayMemberPath)] = MapDisplayMemberPath,
- [nameof(IAutoSuggestBox.IsEnabled)] = MapIsEnabled,
- [nameof(IAutoSuggestBox.ItemsSource)] = MapItemsSource,
- [nameof(IAutoSuggestBox.UpdateTextOnSelect)] = MapUpdateTextOnSelect,
[nameof(IAutoSuggestBox.IsSuggestionListOpen)] = MapIsSuggestionListOpen,
+ [nameof(IAutoSuggestBox.UpdateTextOnSelect)] = MapUpdateTextOnSelect,
+ [nameof(IAutoSuggestBox.ItemsSource)] = MapItemsSource,
+ [nameof(IAutoSuggestBox.IsEnabled)] = MapIsEnabled,
};
///
diff --git a/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.iOS.cs b/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.iOS.cs
index 1e63409..71cf5fc 100644
--- a/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.iOS.cs
+++ b/AutoSuggestBox/Handlers/AutoSuggestBoxHandler.iOS.cs
@@ -37,30 +37,28 @@ protected override void ConnectHandler(AutoSuggestBoxView platformView)
}
protected override void DisconnectHandler(AutoSuggestBoxView platformView)
{
+ base.DisconnectHandler(platformView);
platformView.SuggestionChosen -= OnPlatformViewSuggestionChosen;
platformView.TextChanged -= OnPlatformViewTextChanged;
platformView.QuerySubmitted -= OnPlatformViewQuerySubmitted;
PlatformView.EditingDidBegin -= Control_EditingDidBegin;
PlatformView.EditingDidEnd -= Control_EditingDidEnd;
-
- platformView.Dispose();
- base.DisconnectHandler(platformView);
}
private void OnPlatformViewSuggestionChosen(object? sender, AutoSuggestBoxSuggestionChosenEventArgs e)
{
- VirtualView?.RaiseSuggestionChosen(e);
+ VirtualView?.SuggestionChosen(e.SelectedItem);
}
private void OnPlatformViewTextChanged(object? sender, AutoSuggestBoxTextChangedEventArgs e)
{
- VirtualView?.NativeControlTextChanged(e);
+ VirtualView?.NativeControlTextChanged(PlatformView.Text, (AutoSuggestBoxTextChangeReason)e.Reason);
}
private void OnPlatformViewQuerySubmitted(object? sender, AutoSuggestBoxQuerySubmittedEventArgs e)
{
- VirtualView?.RaiseQuerySubmitted(e);
+ VirtualView?.RaiseQuerySubmitted(e.QueryText, e.ChosenSuggestion);
}
- static readonly int baseHeight = 20;
+ static readonly int baseHeight = 10;
///
public override Microsoft.Maui.Graphics.Size GetDesiredSize(double widthConstraint, double heightConstraint)
{
diff --git a/AutoSuggestBox/Handlers/AutoSuggestHandler.Windows.cs b/AutoSuggestBox/Handlers/AutoSuggestHandler.Windows.cs
index e03cf57..460c7d2 100644
--- a/AutoSuggestBox/Handlers/AutoSuggestHandler.Windows.cs
+++ b/AutoSuggestBox/Handlers/AutoSuggestHandler.Windows.cs
@@ -5,7 +5,6 @@
using XAutoSuggestBoxSuggestionChosenEventArgs = Microsoft.UI.Xaml.Controls.AutoSuggestBoxSuggestionChosenEventArgs;
using XAutoSuggestBoxTextChangedEventArgs = Microsoft.UI.Xaml.Controls.AutoSuggestBoxTextChangedEventArgs;
using XAutoSuggestBoxQuerySubmittedEventArgs = Microsoft.UI.Xaml.Controls.AutoSuggestBoxQuerySubmittedEventArgs;
-using Microsoft.Maui.Controls;
using Microsoft.UI.Xaml.Controls;
namespace Maui.AutoSuggestBox.Handlers;
@@ -20,23 +19,29 @@ protected override void ConnectHandler(AutoSuggestBoxView platformView)
platformView.SuggestionChosen += OnPlatformViewSuggestionChosen;
platformView.TextChanged += OnPlatformViewTextChanged;
platformView.QuerySubmitted += OnPlatformViewQuerySubmitted;
- UpdateTextMemberPath(platformView);
platformView.GotFocus += PlatformView_GotFocus;
+ platformView.Loaded += PlatformView_Loaded;
}
+
protected override void DisconnectHandler(AutoSuggestBoxView platformView)
{
+ base.DisconnectHandler(platformView);
platformView.SuggestionChosen -= OnPlatformViewSuggestionChosen;
platformView.TextChanged -= OnPlatformViewTextChanged;
platformView.QuerySubmitted -= OnPlatformViewQuerySubmitted;
platformView.GotFocus -= PlatformView_GotFocus;
-
- //platformView.Dispose();
- base.DisconnectHandler(platformView);
+ platformView.Loaded -= PlatformView_Loaded;
+ }
+ private void PlatformView_Loaded(object? sender, Microsoft.UI.Xaml.RoutedEventArgs e)
+ {
+ // Workaround issue in WinUI where the list doesn't open if you set before load
+ if (VirtualView.IsSuggestionListOpen && sender is AutoSuggestBoxView box)
+ box.IsSuggestionListOpen = true;
}
private void OnPlatformViewSuggestionChosen(object? sender, XAutoSuggestBoxSuggestionChosenEventArgs e)
{
- VirtualView?.RaiseSuggestionChosen(e.SelectedItem);
+ VirtualView?.SuggestionChosen(e.SelectedItem);
}
private void OnPlatformViewTextChanged(object? sender, XAutoSuggestBoxTextChangedEventArgs e)
{
@@ -47,7 +52,7 @@ private void OnPlatformViewTextChanged(object? sender, XAutoSuggestBoxTextChange
}
private void OnPlatformViewQuerySubmitted(object? sender, XAutoSuggestBoxQuerySubmittedEventArgs e)
{
- VirtualView?.RaiseQuerySubmitted(e.QueryText, e.ChosenSuggestion);
+ VirtualView?.RaiseQuerySubmitted(e.QueryText, e.ChosenSuggestion);
}
public static void MapText(AutoSuggestBoxHandler handler, IAutoSuggestBox view)
{
@@ -57,8 +62,9 @@ public static void MapText(AutoSuggestBoxHandler handler, IAutoSuggestBox view)
public static void MapTextColor(AutoSuggestBoxHandler handler, IAutoSuggestBox view)
{
- var color = view?.TextColor;
- handler.PlatformView.Foreground = color.ToPlatform();
+ Color? color = view?.TextColor;
+ if (color != null)
+ handler.PlatformView.Foreground = color.ToPlatform();
}
public static void MapPlaceholderText(AutoSuggestBoxHandler handler, IAutoSuggestBox view)
{
@@ -104,12 +110,13 @@ private void UpdateTextMemberPath(AutoSuggestBoxView platformView)
private void UpdateTextColor(AutoSuggestBoxView platformView)
{
- var color = VirtualView?.TextColor;
- platformView.Foreground = color.ToPlatform();
+ Color? color = VirtualView?.TextColor;
+ if (color != null)
+ platformView.Foreground = color.ToPlatform();
}
private void UpdateDisplayMemberPath(AutoSuggestBoxHandler handler, IAutoSuggestBox view)
{
handler.PlatformView.DisplayMemberPath = view?.DisplayMemberPath;
}
private void UpdatePlaceholderText(AutoSuggestBoxView platformView) => platformView.PlaceholderText = VirtualView?.PlaceholderText;
-}
+}
\ No newline at end of file
diff --git a/AutoSuggestBox/Handlers/NativeAutoSuggestBox.Android.cs b/AutoSuggestBox/Handlers/NativeAutoSuggestBox.Android.cs
index 3cac153..95fd9df 100644
--- a/AutoSuggestBox/Handlers/NativeAutoSuggestBox.Android.cs
+++ b/AutoSuggestBox/Handlers/NativeAutoSuggestBox.Android.cs
@@ -1,9 +1,12 @@
-using Android.Content;
+#if ANDROID
+#nullable enable
+using Android.Content;
+using Android.Graphics;
using Android.Runtime;
+using Android.Views;
using Android.Views.InputMethods;
using Android.Widget;
using Java.Lang;
-using Microsoft.Maui;
using Microsoft.Maui.Platform;
namespace Maui.AutoSuggestBox.Platforms.Android
@@ -15,7 +18,7 @@ public class AutoSuggestBoxView : AutoCompleteTextView
{
private bool suppressTextChangedEvent;
- private Func
///
- public virtual void SetTextColor(Color color)
+ public virtual void SetTextColor(Microsoft.Maui.Graphics.Color color)
{
- this.SetTextColor(color.ToPlatform());
+ this.SetTextColor(ColorExtensions.ToPlatform(color));
}
///
/// Gets or sets the placeholder text to be displayed in the
///
- public virtual string PlaceholderText
+ public virtual string? PlaceholderText
{
set => HintFormatted = new Java.Lang.String(value as string ?? "");
}
@@ -92,9 +96,9 @@ public virtual string PlaceholderText
/// Gets or sets the color of the .
///
/// color
- public virtual void SetPlaceholderTextColor(Color color)
+ public virtual void SetPlaceholderTextColor(Microsoft.Maui.Graphics.Color color)
{
- this.SetHintTextColor(color.ToPlatform());
+ this.SetHintTextColor(ColorExtensions.ToPlatform(color));
}
///
@@ -117,30 +121,29 @@ public virtual bool IsSuggestionListOpen
public virtual bool UpdateTextOnSelect { get; set; } = true;
///
- protected override void OnTextChanged(ICharSequence text, int start, int lengthBefore, int lengthAfter)
+ protected override void OnTextChanged(ICharSequence? text, int start, int lengthBefore, int lengthAfter)
{
if (!suppressTextChangedEvent)
- this.TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs(text.ToString(), AutoSuggestBoxTextChangeReason.UserInput));
+ this.TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs(AutoSuggestBoxTextChangeReason.UserInput));
base.OnTextChanged(text, start, lengthBefore, lengthAfter);
}
private void DismissKeyboard()
{
- var imm = (global::Android.Views.InputMethods.InputMethodManager)Context.GetSystemService(Context.InputMethodService);
+ var imm = (global::Android.Views.InputMethods.InputMethodManager)Context!.GetSystemService(Context.InputMethodService)!;
imm.HideSoftInputFromWindow(WindowToken, 0);
}
- private void OnItemClick(object sender, AdapterView.ItemClickEventArgs e)
+ private void OnItemClick(object? sender, AdapterView.ItemClickEventArgs e)
{
DismissKeyboard();
var obj = adapter.GetObject(e.Position);
if (UpdateTextOnSelect)
{
suppressTextChangedEvent = true;
- string text = textFunc(obj);
- base.Text = text;
+ base.Text = textFunc is null ? null : textFunc(obj);
suppressTextChangedEvent = false;
- TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs(text, AutoSuggestBoxTextChangeReason.SuggestionChosen));
+ TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs(AutoSuggestBoxTextChangeReason.SuggestionChosen));
}
SuggestionChosen?.Invoke(this, new AutoSuggestBoxSuggestionChosenEventArgs(obj));
QuerySubmitted?.Invoke(this, new AutoSuggestBoxQuerySubmittedEventArgs(Text, obj));
@@ -160,7 +163,7 @@ public override void OnEditorAction([GeneratedEnum] ImeAction actionCode)
}
///
- protected override void ReplaceText(ICharSequence text)
+ protected override void ReplaceText(ICharSequence? text)
{
//Override to avoid updating textbox on itemclick. We'll do this later using TextMemberPath and raise the proper TextChanged event then
}
@@ -168,23 +171,23 @@ protected override void ReplaceText(ICharSequence text)
///
/// Raised after the text content of the editable control component is updated.
///
- public new event EventHandler TextChanged;
+ public new event EventHandler? TextChanged;
///
/// Occurs when the user submits a search query.
///
- public event EventHandler QuerySubmitted;
+ public event EventHandler? QuerySubmitted;
///
/// Raised before the text content of the editable control component is updated.
///
- public event EventHandler SuggestionChosen;
+ public event EventHandler? SuggestionChosen;
private class SuggestCompleteAdapter : ArrayAdapter, IFilterable
{
private SuggestFilter filter = new SuggestFilter();
private List resultList;
- private Func labelFunc;
+ private Func? labelFunc;
public SuggestCompleteAdapter(Context context, int textViewResourceId) : base(context, textViewResourceId)
{
@@ -212,7 +215,7 @@ public override int Count
public override Java.Lang.Object GetItem(int position)
{
- return labelFunc(GetObject(position));
+ return labelFunc!(GetObject(position))!;
}
public object GetObject(int position)
@@ -227,7 +230,7 @@ public override long GetItemId(int position)
private class SuggestFilter : Filter
{
- private IEnumerable resultList;
+ private IEnumerable? resultList;
public SuggestFilter()
{
@@ -236,17 +239,18 @@ public void SetFilter(IEnumerable list)
{
resultList = list;
}
- protected override FilterResults PerformFiltering(ICharSequence constraint)
+ protected override FilterResults PerformFiltering(ICharSequence? constraint)
{
if (resultList == null)
return new FilterResults() { Count = 0, Values = null };
var arr = resultList.ToArray();
return new FilterResults() { Count = arr.Length, Values = arr };
}
- protected override void PublishResults(ICharSequence constraint, FilterResults results)
+ protected override void PublishResults(ICharSequence? constraint, FilterResults? results)
{
}
}
}
}
-}
\ No newline at end of file
+}
+#endif
\ No newline at end of file
diff --git a/AutoSuggestBox/Handlers/NativeAutoSuggestBox.iOS.cs b/AutoSuggestBox/Handlers/NativeAutoSuggestBox.iOS.cs
index cd40f16..0b28a77 100644
--- a/AutoSuggestBox/Handlers/NativeAutoSuggestBox.iOS.cs
+++ b/AutoSuggestBox/Handlers/NativeAutoSuggestBox.iOS.cs
@@ -1,7 +1,11 @@
-using CoreGraphics;
+#if __IOS__ || __MACCATALYST__
+#nullable enable
+using CoreGraphics;
using Foundation;
-using Microsoft.Maui.Platform;
using UIKit;
+using Microsoft.Maui.Platform;
+using System.Runtime.InteropServices;
+using System.Text.RegularExpressions;
namespace Maui.AutoSuggestBox.Platforms.iOS
{
@@ -11,9 +15,9 @@ namespace Maui.AutoSuggestBox.Platforms.iOS
public partial class AutoSuggestBoxView : UIKit.UIView
{
private nfloat keyboardHeight;
- private NSLayoutConstraint bottomConstraint;
- private Func textFunc;
- private CoreAnimation.CALayer border;
+ private NSLayoutConstraint? bottomConstraint;
+ private Func? textFunc;
+ private CoreAnimation.CALayer? border;
private bool showBottomBorder = true;
///
@@ -31,14 +35,14 @@ public partial class AutoSuggestBoxView : UIKit.UIView
///
public AutoSuggestBoxView()
{
- InputTextField = new UIKit.UITextField
+ InputTextField = new UIKit.UITextField()
{
TranslatesAutoresizingMaskIntoConstraints = false,
BorderStyle = UIKit.UITextBorderStyle.None,
ReturnKeyType = UIKit.UIReturnKeyType.Search,
- AutocorrectionType = UITextAutocorrectionType.No,
- ShouldReturn = InputText_OnShouldReturn
+ AutocorrectionType = UITextAutocorrectionType.No
};
+ InputTextField.ShouldReturn = InputText_OnShouldReturn;
InputTextField.EditingDidBegin += OnEditingDidBegin;
InputTextField.EditingDidEnd += OnEditingDidEnd;
InputTextField.EditingChanged += InputText_EditingChanged;
@@ -54,6 +58,8 @@ public AutoSuggestBoxView()
UIKit.UIKeyboard.Notifications.ObserveWillHide(OnKeyboardHide);
}
+ ///
+ public override CGSize SizeThatFits(CGSize size) => InputTextField.SizeThatFits(size);
///
public override void MovedToWindow()
{
@@ -61,21 +67,21 @@ public override void MovedToWindow()
UpdateSuggestionListOpenState();
}
- private void OnEditingDidBegin(object sender, EventArgs e)
+ private void OnEditingDidBegin(object? sender, EventArgs e)
{
IsSuggestionListOpen = true;
EditingDidBegin?.Invoke(this, e);
}
- private void OnEditingDidEnd(object sender, EventArgs e)
+ private void OnEditingDidEnd(object? sender, EventArgs e)
{
IsSuggestionListOpen = false;
EditingDidEnd?.Invoke(this, e);
}
- internal EventHandler EditingDidBegin;
+ internal EventHandler? EditingDidBegin;
- internal EventHandler EditingDidEnd;
+ internal EventHandler? EditingDidEnd;
///
public override void LayoutSubviews()
@@ -112,13 +118,13 @@ public bool ShowBottomBorder
///
/// Gets or sets the font of the
///
- public virtual UIFont Font
+ public virtual UIFont? Font
{
get => InputTextField.Font;
set => InputTextField.Font = value;
}
- internal void SetItems(IEnumerable items, Func labelFunc, Func textFunc)
+ internal void SetItems(IEnumerable? items, Func labelFunc, Func textFunc)
{
this.textFunc = textFunc;
if (SelectionList.Source is TableSource oldSource)
@@ -127,7 +133,7 @@ internal void SetItems(IEnumerable items, Func labelFunc
}
SelectionList.Source = null;
- IEnumerable suggestions = items?.OfType();
+ IEnumerable? suggestions = items?.OfType();
if (suggestions != null && suggestions.Any())
{
var suggestionTableSource = new TableSource(suggestions, labelFunc);
@@ -145,7 +151,7 @@ internal void SetItems(IEnumerable items, Func labelFunc
///
/// Gets or sets the placeholder text to be displayed in the .
///
- public virtual string PlaceholderText
+ public virtual string? PlaceholderText
{
get => InputTextField.Placeholder;
set => InputTextField.Placeholder = value;
@@ -158,7 +164,7 @@ public virtual string PlaceholderText
public virtual void SetPlaceholderTextColor(Color color)
{
// See https://github.com/xamarin/Xamarin.Forms/blob/4d9a5bf3706778770026a18ae81a7dd5c4c15db4/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs#L260
- InputTextField.AttributedPlaceholder = new NSAttributedString(InputTextField.Placeholder ?? string.Empty, null, color.ToPlatform()); //ColorExtensions.ToColor(color));
+ InputTextField.AttributedPlaceholder = new NSAttributedString(InputTextField.Placeholder ?? string.Empty, null, ColorExtensions.ToPlatform(color));
}
private bool _isSuggestionListOpen;
@@ -192,7 +198,7 @@ private void UpdateSuggestionListOpenState()
SelectionList.TopAnchor.ConstraintEqualTo(InputTextField.BottomAnchor).Active = true;
SelectionList.LeftAnchor.ConstraintEqualTo(InputTextField.LeftAnchor).Active = true;
SelectionList.WidthAnchor.ConstraintEqualTo(InputTextField.WidthAnchor).Active = true;
- bottomConstraint = SelectionList.BottomAnchor.ConstraintGreaterThanOrEqualTo(SelectionList.Superview.BottomAnchor, -keyboardHeight);
+ bottomConstraint = SelectionList.BottomAnchor.ConstraintGreaterThanOrEqualTo(SelectionList.Superview!.BottomAnchor, -keyboardHeight);
bottomConstraint.Active = true;
SelectionList.UpdateConstraints();
}
@@ -208,7 +214,7 @@ private void UpdateSuggestionListOpenState()
///
public virtual bool UpdateTextOnSelect { get; set; } = true;
- private void OnKeyboardHide(object sender, UIKeyboardEventArgs e)
+ private void OnKeyboardHide(object? sender, UIKeyboardEventArgs e)
{
keyboardHeight = 0;
if (bottomConstraint != null)
@@ -218,17 +224,38 @@ private void OnKeyboardHide(object sender, UIKeyboardEventArgs e)
}
}
- private void OnKeyboardShow(object sender, UIKeyboardEventArgs e)
+ private void OnKeyboardShow(object? sender, UIKeyboardEventArgs e)
{
- NSValue nsKeyboardBounds = (NSValue)e.Notification.UserInfo.ObjectForKey(UIKeyboard.FrameBeginUserInfoKey);
- var keyboardBounds = nsKeyboardBounds.RectangleFValue;
- keyboardHeight = keyboardBounds.Height;
+ CGRect? keyboardEndFrame = DescriptionToCGRect(e.Notification.UserInfo?.ValueForKey(UIKeyboard.FrameEndUserInfoKey).Description);
+ if (keyboardEndFrame is null)
+ return;
+ NFloat _keyboardHeight = UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.Portrait || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.PortraitUpsideDown ? keyboardEndFrame.Value.Size.Height : keyboardEndFrame.Value.Size.Width;
if (bottomConstraint != null)
{
bottomConstraint.Constant = -keyboardHeight;
SelectionList.UpdateConstraints();
}
}
+ // Used to get the numeric values from the UserInfo dictionary's NSObject value to CGRect.
+ // Doing manually since CGRectFromString is not yet bound
+ static CGRect? DescriptionToCGRect(string? description)
+ {
+ // example of passed in description: "NSRect: {{0, 586}, {430, 346}}"
+ if (description is null)
+ return null;
+ // remove everything except for numbers and commas
+ var temp = MyRegex().Replace(description, "");
+ var dimensions = temp.Split(',');
+ if (dimensions.Length == 4
+ && nfloat.TryParse(dimensions[0], out var x)
+ && nfloat.TryParse(dimensions[1], out var y)
+ && nfloat.TryParse(dimensions[2], out var width)
+ && nfloat.TryParse(dimensions[3], out var height))
+ {
+ return new CGRect(x, y, width, height);
+ }
+ return null;
+ }
private bool InputText_OnShouldReturn(UITextField field)
{
@@ -253,36 +280,36 @@ public override bool ResignFirstResponder()
///
public override bool IsFirstResponder => InputTextField.IsFirstResponder;
- private void SuggestionTableSource_TableRowSelected(object sender, TableRowSelectedEventArgs e)
+ private void SuggestionTableSource_TableRowSelected(object? sender, TableRowSelectedEventArgs e)
{
SelectionList.DeselectRow(e.SelectedItemIndexPath, false);
var selection = e.SelectedItem;
if (UpdateTextOnSelect)
{
- InputTextField.Text = textFunc(selection);
- TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs(textFunc(selection), AutoSuggestBoxTextChangeReason.SuggestionChosen));
+ InputTextField.Text = textFunc is null ? null : textFunc(selection);
+ TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs(AutoSuggestBoxTextChangeReason.SuggestionChosen));
}
SuggestionChosen?.Invoke(this, new AutoSuggestBoxSuggestionChosenEventArgs(selection));
QuerySubmitted?.Invoke(this, new AutoSuggestBoxQuerySubmittedEventArgs(Text, selection));
IsSuggestionListOpen = false;
}
- private void InputText_EditingChanged(object sender, EventArgs e)
+ private void InputText_EditingChanged(object? sender, EventArgs e)
{
- TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs(this.Text, AutoSuggestBoxTextChangeReason.UserInput));
+ TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs(AutoSuggestBoxTextChangeReason.UserInput));
IsSuggestionListOpen = true;
}
///
/// Gets or sets the text displayed in the
///
- public virtual string Text
+ public virtual string? Text
{
get => InputTextField.Text;
set
{
InputTextField.Text = value;
- this.TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs(value, AutoSuggestBoxTextChangeReason.ProgrammaticChange));
+ this.TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs(AutoSuggestBoxTextChangeReason.ProgrammaticChange));
}
}
@@ -292,32 +319,31 @@ public virtual string Text
/// color
public virtual void SetTextColor(Color color)
{
- //InputTextField.TextColor = ColorExtensions.ToColor(color);
- InputTextField.TextColor = color.ToPlatform();
+ InputTextField.TextColor = ColorExtensions.ToPlatform(color);
}
///
- /// Raised after the text config of the editable control component is updated.
+ /// Raised after the text content of the editable control component is updated.
///
- public event EventHandler TextChanged;
+ public event EventHandler? TextChanged;
///
/// Occurs when the user submits a search query.
///
- public event EventHandler QuerySubmitted;
+ public event EventHandler? QuerySubmitted;
///
- /// Raised before the text config of the editable control component is updated.
+ /// Raised before the text content of the editable control component is updated.
///
- public event EventHandler SuggestionChosen;
+ public event EventHandler? SuggestionChosen;
private class TableSource : UITableViewSource
{
readonly IEnumerable _items;
- readonly Func _labelFunc;
+ readonly Func _labelFunc;
readonly string _cellIdentifier;
- public TableSource(IEnumerable items, Func labelFunc)
+ public TableSource(IEnumerable items, Func labelFunc)
{
_items = items;
_labelFunc = labelFunc;
@@ -327,15 +353,11 @@ public TableSource(IEnumerable items, Func labelFunc)
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = tableView.DequeueReusableCell(_cellIdentifier);
- if (cell == null)
- cell = new UITableViewCell(UITableViewCellStyle.Default, _cellIdentifier);
+ cell ??= new UITableViewCell(UITableViewCellStyle.Default, _cellIdentifier);
var item = _items.ElementAt(indexPath.Row);
- var content = cell.DefaultContentConfiguration;
- content.Text = _labelFunc(item);
- cell.ContentConfiguration = content;
- cell.AutomaticallyUpdatesContentConfiguration = false;
+ cell.TextLabel.Text = _labelFunc(item);
return cell;
}
@@ -350,7 +372,11 @@ public override nint RowsInSection(UITableView tableview, nint section)
return _items.Count();
}
- public event EventHandler> TableRowSelected;
+ public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
+ {
+ return 30f;
+ }
+ public event EventHandler>? TableRowSelected;
private void OnTableRowSelected(NSIndexPath itemIndexPath)
{
@@ -362,7 +388,7 @@ private void OnTableRowSelected(NSIndexPath itemIndexPath)
private class TableRowSelectedEventArgs : EventArgs
{
- public TableRowSelectedEventArgs(T selectedItem, string selectedItemLabel, NSIndexPath selectedItemIndexPath)
+ public TableRowSelectedEventArgs(T selectedItem, string? selectedItemLabel, NSIndexPath selectedItemIndexPath)
{
SelectedItem = selectedItem;
SelectedItemLabel = selectedItemLabel;
@@ -370,8 +396,13 @@ public TableRowSelectedEventArgs(T selectedItem, string selectedItemLabel, NSInd
}
public T SelectedItem { get; }
- public string SelectedItemLabel { get; }
+ public string? SelectedItemLabel { get; }
public NSIndexPath SelectedItemIndexPath { get; }
}
+
+ [GeneratedRegex(@"[^0-9,]")]
+ private static partial Regex MyRegex();
}
}
+
+#endif
diff --git a/AutoSuggestBox/Maui.AutoSuggestBox.csproj b/AutoSuggestBox/Maui.AutoSuggestBox.csproj
index 559f35a..c279cb6 100644
--- a/AutoSuggestBox/Maui.AutoSuggestBox.csproj
+++ b/AutoSuggestBox/Maui.AutoSuggestBox.csproj
@@ -7,9 +7,10 @@
true
enable
- 14.2
- 30.0
+ 15.2
+ 31.0
10.0.17763.0
+ 32.0
Maui.AutoSuggestBox
@@ -28,7 +29,7 @@
$(DefineConstants);
false
- Maui AutoSuggest Box
+ Maui.AutoSuggestBox
Use an AutoSuggestBox to provide a list of suggestions for a user to select from as they type.
$(AssemblyName) ($(TargetFramework))
$(Version)$(VersionSuffix)
@@ -36,7 +37,16 @@
Maui dotnet.Maui .net-Maui AutoSuggestBox uikit TextInputLayout
Debug;Release
true
+ README.md
+ True
+
+
+
+ True
+ \
+
+
4
@@ -47,9 +57,22 @@
true
+
+ false
+ 1701;1702;CS8600;CS8604;CS8622;CS8629;CS8603;CS8620;CS8602
+
manual
+
+ 1701;1702;CS8600;CS8604;CS8622;CS8629;CS8603;CS8620;CS8602
+
+
+ 1701;1702;CS8600;CS8604;CS8622;CS8629;CS8603;CS8620;CS8602
+
+
+ 1701;1702;CS8600;CS8604;CS8622;CS8629;CS8603;CS8620;CS8602
+
@@ -65,7 +88,6 @@
-
all
diff --git a/AutoSuggestBox/README.md b/AutoSuggestBox/README.md
deleted file mode 100644
index 4b37031..0000000
--- a/AutoSuggestBox/README.md
+++ /dev/null
@@ -1,24 +0,0 @@
-# XamarinFormsControls
-
-I took the source for this project from the original DotMorten project at (https://github.com/dotMorten/XamarinFormsControls)
-I wanted a Maui version. So I modified the source and migrated it to .Net Maui. It supports Windows, Android and iOS, 3 types of hardware I posses.
-This was an exercise in how to migrate a Xamarin.Forms control to a .Net Maui control using the Maui Handler recipe. It took a number of days
-to get this sorted out. I know that it works for my needs. I did what I needed to get it to work. I am sure there is some unused code that can be removed.
-Someone familiar with Maui handlers and.or Windows code, iOS code or Android code can make improvements.
-I tired of trying to find a comparable .Net Maui version of this AutoSuggestion box that I had used in Xamarin.Forms. I wanted to finish migrating my apps
-from Xamarin.Forms to .Net Maui. After migrating this control and the Microcharts control, I was able to complete the migration to .Nwt Maui.
-I do like .Net Maui now more than Xamarin.Forms. Yes, you need to make design changes but in fact it isnt that much of a stretch.
-
-So many thanks to dotMorten for creating this control so long ago.
-
-## Sponsoring
-
-If you like this library and use it a lot, consider sponsoring me. Anything helps and encourages me to keep going.
-
-See here for details: https://github.com/sponsors/dotMorten
-
-### Controls
-
-- [AutoSuggestBox](AutoSuggestBox/) : Represents a text control that makes suggestions to users as they type. The app is notified when text has been changed by the user and is responsible for providing relevant suggestions for this control to display.
-![autosuggestbox](https://user-images.githubusercontent.com/1378165/51137780-42b30b80-17f4-11e9-8ac1-7b129fc3d9ee.gif)
-