Skip to content

Commit

Permalink
Removed unused module
Browse files Browse the repository at this point in the history
Modify AutoSuggestBox project file for generating output files
  • Loading branch information
davefxy committed Apr 26, 2023
1 parent ad00fd3 commit 6e6eb8b
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 82 deletions.
24 changes: 0 additions & 24 deletions AutoSuggestBox/Extensions/AutoSuggestBoxViewExtensions.cs

This file was deleted.

29 changes: 0 additions & 29 deletions AutoSuggestBox/Handlers/AutoSuggestBoxHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,63 +89,34 @@ 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<object>(), (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<object>(), (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))
return instance?.GetType().GetProperty(memberPath)?.GetValue(instance)?.ToString() ?? "";
else
return instance?.ToString() ?? "";
}
#endif

}
87 changes: 83 additions & 4 deletions AutoSuggestBox/Handlers/AutoSuggestBoxHandler.iOS.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -12,13 +15,66 @@ public partial class AutoSuggestBoxHandler : ViewHandler<IAutoSuggestBox, AutoSu
protected override void ConnectHandler(AutoSuggestBoxView platformView)
{
base.ConnectHandler(platformView);

//UpdateTextColor(platformView);
//UpdatePlaceholderText(platformView);
//UpdatePlaceholderTextColor(platformView);
//UpdateIsEnabled(platformView);

platformView.SuggestionChosen += OnPlatformViewSuggestionChosen;
platformView.TextChanged += OnPlatformViewTextChanged;
platformView.QuerySubmitted += OnPlatformViewQuerySubmitted;
//platformView.UpdateTextOnSelect = e.NewElement.UpdateTextOnSelect;
//platformView.IsSuggestionListOpen = e.NewElement.IsSuggestionListOpen;
//Control.EditingDidBegin += Control_EditingDidBegin;
//Control.EditingDidEnd += Control_EditingDidEnd;
//Frame = new RectangleF(0, 20, 320, 40);
}
protected override void DisconnectHandler(AutoSuggestBoxView 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);
}
private void OnPlatformViewTextChanged(object? sender, AutoSuggestBoxTextChangedEventArgs e)
{
VirtualView?.NativeControlTextChanged(e);
}
private void OnPlatformViewQuerySubmitted(object? sender, AutoSuggestBoxQuerySubmittedEventArgs e)
{
VirtualView?.RaiseQuerySubmitted(e);
}

static readonly int baseHeight = 10;
/// <inheritdoc />
//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)
Expand All @@ -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)
Expand All @@ -39,28 +96,50 @@ public static void MapPlaceholderTextColor(AutoSuggestBoxHandler handler, IAutoS
}
public static void MapTextMemberPath(AutoSuggestBoxHandler handler, IAutoSuggestBox view)
{

handler.PlatformView?.SetItems(view.ItemsSource?.OfType<object>(), (o) => FormatType(o, view.DisplayMemberPath), (o) => FormatType(o, view.TextMemberPath));
}
public static void MapDisplayMemberPath(AutoSuggestBoxHandler handler, IAutoSuggestBox view)
{

handler.PlatformView.SetItems(view?.ItemsSource?.OfType<object>(), (o) => FormatType(o, view?.DisplayMemberPath), (o) => FormatType(o, view?.TextMemberPath));
}
public static void MapIsSuggestionListOpen(AutoSuggestBoxHandler handler, IAutoSuggestBox view)
{
handler.PlatformView.IsSuggestionListOpen = view.IsSuggestionListOpen;
}
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<object>(), (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<object>(), (o) => FormatType(o, VirtualView?.DisplayMemberPath), (o) => FormatType(o, VirtualView?.TextMemberPath));
}
private static string FormatType(object instance, string memberPath)
{
if (!string.IsNullOrEmpty(memberPath))
Expand Down
65 changes: 40 additions & 25 deletions AutoSuggestBox/Maui.AutoSuggestBox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,51 @@
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>

<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">30.0</SupportedOSPlatformVersion>
<RootNamespace>Maui.AutoSuggestBox</RootNamespace>
</PropertyGroup>

<PropertyGroup>
<GitInfoReportImportance>high</GitInfoReportImportance>
<PackageId>AutoSuggestBox</PackageId>
<Summary>A control that allows you to design any type of switch/ toggle for .NET MAUI. It's also 100% accessible.</Summary>
<Authors>Morten Nielsen</Authors>
<NeutralLanguage>en</NeutralLanguage>
<Copyright>Morten Nielsen</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes></PackageReleaseNotes>
<DefineConstants>$(DefineConstants);</DefineConstants>
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
<Title>Maui AutoSuggest Box</Title>
<Description>Use an AutoSuggestBox to provide a list of suggestions for a user to select from as they type.</Description>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<AssemblyFileVersion>1.0.0.0</AssemblyFileVersion>
<Version>1.0.0</Version>
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>dot,maui,control,custom,autosuggest</PackageTags>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>
<PropertyGroup>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<AssemblyFileVersion>1.0.0.0</AssemblyFileVersion>
<Version>1.0.0</Version>
<NeutralLanguage>en</NeutralLanguage>
<LangVersion>latest</LangVersion>
<GitInfoReportImportance>high</GitInfoReportImportance>
<PackageId>AutoSuggestBox</PackageId>
<Summary>A control that allows you to design any type of switch/ toggle for .NET MAUI. It's also 100% accessible.</Summary>
<Authors>Morten Nielsen</Authors>
<Copyright>Morten Nielsen</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes></PackageReleaseNotes>
<DefineConstants>$(DefineConstants);</DefineConstants>
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
<Title>Maui AutoSuggest Box</Title>
<Description>Use an AutoSuggestBox to provide a list of suggestions for a user to select from as they type.</Description>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
<PackageVersion>$(Version)$(VersionSuffix)</PackageVersion>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageTags>Maui dotnet.Maui .net-Maui AutoSuggestBox uikit TextInputLayout</PackageTags>
<Configurations>Debug;Release</Configurations>
<PackOnBuild>true</PackOnBuild>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-android|AnyCPU'">
<CreatePackage>false</CreatePackage>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0-ios|AnyCPU'">
<CreatePackage>false</CreatePackage>
</PropertyGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net7.0-android')) != true">
<Compile Remove="**\**\*.Android.cs" />
Expand Down

0 comments on commit 6e6eb8b

Please sign in to comment.