├── Resources ├── Fonts │ ├── OpenSans-Regular.ttf │ └── OpenSans-Semibold.ttf ├── AppIcon │ ├── appicon.svg │ └── appiconfg.svg ├── Raw │ └── AboutAssets.txt ├── Splash │ └── splash.svg ├── Styles │ ├── Colors.xaml │ └── Styles.xaml └── Images │ └── dotnet_bot.svg ├── Properties └── launchSettings.json ├── MainPage.xaml.cs ├── AppShell.xaml.cs ├── App.xaml.cs ├── Platforms ├── Android │ ├── Resources │ │ └── values │ │ │ └── colors.xml │ ├── _Maui │ │ ├── ViewExtensions.cs │ │ ├── Rtl.cs │ │ ├── ColorStates.cs │ │ ├── AlignmentExtensions.cs │ │ ├── TextAlignmentExtensions.cs │ │ ├── ColorStateListExtensions.cs │ │ └── EditTextExtensions.cs │ ├── MainApplication.cs │ ├── AndroidManifest.xml │ ├── MainActivity.cs │ └── MyEntryHandler.Android.cs ├── iOS │ ├── AppDelegate.cs │ ├── Program.cs │ └── Info.plist ├── MacCatalyst │ ├── AppDelegate.cs │ ├── Program.cs │ └── Info.plist ├── Windows │ ├── App.xaml │ ├── app.manifest │ ├── App.xaml.cs │ ├── Package.appxmanifest │ └── MyEntryHandler.Windows.cs └── Tizen │ ├── Main.cs │ └── tizen-manifest.xml ├── _Maui └── StringExtensions.cs ├── AppShell.xaml ├── MauiProgram.cs ├── IMyEntryHandler.cs ├── App.xaml ├── MainPage.xaml ├── MyEntry.cs ├── LICENSE ├── MauiCustomEntryHandler.sln ├── MauiCustomEntryHandler.csproj ├── ElementHandlerExtensions.cs ├── MyEntryHandler.cs └── .gitignore /Resources/Fonts/OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ToolmakerSteve/MauiCustomEntryHandler/HEAD/Resources/Fonts/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /Resources/Fonts/OpenSans-Semibold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ToolmakerSteve/MauiCustomEntryHandler/HEAD/Resources/Fonts/OpenSans-Semibold.ttf -------------------------------------------------------------------------------- /Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "Windows Machine": { 4 | "commandName": "MsixPackage", 5 | "nativeDebugging": false 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /MainPage.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace MauiCustomEntryHandler; 2 | 3 | public partial class MainPage : ContentPage 4 | { 5 | public MainPage() 6 | { 7 | InitializeComponent(); 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /AppShell.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace MauiCustomEntryHandler; 2 | 3 | public partial class AppShell : Shell 4 | { 5 | public AppShell() 6 | { 7 | InitializeComponent(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /App.xaml.cs: -------------------------------------------------------------------------------- 1 | namespace MauiCustomEntryHandler; 2 | 3 | public partial class App : Application 4 | { 5 | public App() 6 | { 7 | InitializeComponent(); 8 | 9 | MainPage = new AppShell(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Platforms/Android/Resources/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #512BD4 4 | #2B0B98 5 | #2B0B98 6 | -------------------------------------------------------------------------------- /Resources/AppIcon/appicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Platforms/iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | 3 | namespace MauiCustomEntryHandler; 4 | 5 | [Register("AppDelegate")] 6 | public class AppDelegate : MauiUIApplicationDelegate 7 | { 8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 9 | } 10 | -------------------------------------------------------------------------------- /Platforms/MacCatalyst/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Foundation; 2 | 3 | namespace MauiCustomEntryHandler; 4 | 5 | [Register("AppDelegate")] 6 | public class AppDelegate : MauiUIApplicationDelegate 7 | { 8 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 9 | } 10 | -------------------------------------------------------------------------------- /Platforms/Android/_Maui/ViewExtensions.cs: -------------------------------------------------------------------------------- 1 | //using System; 2 | //using System.Collections.Generic; 3 | //using System.Linq; 4 | //using System.Text; 5 | //using System.Threading.Tasks; 6 | 7 | //namespace MauiCustomEntryHandler.Platforms.Android._Maui 8 | //{ 9 | // internal class ViewExtensions 10 | // { 11 | // } 12 | //} 13 | -------------------------------------------------------------------------------- /Platforms/Windows/App.xaml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Platforms/Tizen/Main.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Maui; 3 | using Microsoft.Maui.Hosting; 4 | 5 | namespace MauiCustomEntryHandler; 6 | 7 | class Program : MauiApplication 8 | { 9 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 10 | 11 | static void Main(string[] args) 12 | { 13 | var app = new Program(); 14 | app.Run(args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /_Maui/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | #nullable enable 2 | namespace Microsoft.Maui.Platform 3 | { 4 | internal static class StringExtensions 5 | { 6 | public static string? TrimToMaxLength(this string? currentText, int maxLength) => 7 | maxLength >= 0 && currentText?.Length > maxLength 8 | ? currentText.Substring(0, maxLength) 9 | : currentText; 10 | } 11 | } -------------------------------------------------------------------------------- /Platforms/Android/MainApplication.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Runtime; 3 | 4 | namespace MauiCustomEntryHandler; 5 | 6 | [Application] 7 | public class MainApplication : MauiApplication 8 | { 9 | public MainApplication(IntPtr handle, JniHandleOwnership ownership) 10 | : base(handle, ownership) 11 | { 12 | } 13 | 14 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 15 | } 16 | -------------------------------------------------------------------------------- /Platforms/iOS/Program.cs: -------------------------------------------------------------------------------- 1 | using ObjCRuntime; 2 | using UIKit; 3 | 4 | namespace MauiCustomEntryHandler; 5 | 6 | public class Program 7 | { 8 | // This is the main entry point of the application. 9 | static void Main(string[] args) 10 | { 11 | // if you want to use a different Application Delegate class from "AppDelegate" 12 | // you can specify it here. 13 | UIApplication.Main(args, null, typeof(AppDelegate)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Platforms/MacCatalyst/Program.cs: -------------------------------------------------------------------------------- 1 | using ObjCRuntime; 2 | using UIKit; 3 | 4 | namespace MauiCustomEntryHandler; 5 | 6 | public class Program 7 | { 8 | // This is the main entry point of the application. 9 | static void Main(string[] args) 10 | { 11 | // if you want to use a different Application Delegate class from "AppDelegate" 12 | // you can specify it here. 13 | UIApplication.Main(args, null, typeof(AppDelegate)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Platforms/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Platforms/Android/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Content.PM; 3 | using Android.OS; 4 | 5 | namespace MauiCustomEntryHandler; 6 | 7 | [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] 8 | public class MainActivity : MauiAppCompatActivity 9 | { 10 | } 11 | -------------------------------------------------------------------------------- /AppShell.xaml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Platforms/Android/_Maui/Rtl.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Content.PM; 3 | using Application = Android.App.Application; 4 | 5 | namespace Microsoft.Maui.Platform 6 | { 7 | static class Rtl 8 | { 9 | /// 10 | /// True if /manifest/application@android:supportsRtl="true" 11 | /// 12 | public static readonly bool IsSupported = 13 | (Application.Context?.ApplicationInfo?.Flags & ApplicationInfoFlags.SupportsRtl) != 0; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MauiProgram.cs: -------------------------------------------------------------------------------- 1 | namespace MauiCustomEntryHandler; 2 | 3 | public static class MauiProgram 4 | { 5 | public static MauiApp CreateMauiApp() 6 | { 7 | var builder = MauiApp.CreateBuilder(); 8 | builder 9 | .UseMauiApp() 10 | .ConfigureMauiHandlers(handlers => 11 | { 12 | handlers.AddHandler(typeof(MyEntry), typeof(MyEntryHandler)); 13 | }) 14 | .ConfigureFonts(fonts => 15 | { 16 | fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); 17 | fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); 18 | }); 19 | 20 | return builder.Build(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Resources/Raw/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories). Deployment of the asset to your application 3 | is automatically handled by the following `MauiAsset` Build Action within your `.csproj`. 4 | 5 | 6 | 7 | These files will be deployed with you package and will be accessible using Essentials: 8 | 9 | async Task LoadMauiAsset() 10 | { 11 | using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); 12 | using var reader = new StreamReader(stream); 13 | 14 | var contents = reader.ReadToEnd(); 15 | } 16 | -------------------------------------------------------------------------------- /IMyEntryHandler.cs: -------------------------------------------------------------------------------- 1 | #if __IOS__ || MACCATALYST 2 | using PlatformView = Microsoft.Maui.Platform.MauiTextField; 3 | #elif MONOANDROID 4 | using PlatformView = AndroidX.AppCompat.Widget.AppCompatEditText; 5 | #elif WINDOWS 6 | using PlatformView = Microsoft.UI.Xaml.FrameworkElement; 7 | #elif TIZEN 8 | using PlatformView = Tizen.UIExtensions.ElmSharp.Entry; 9 | #elif (NETSTANDARD || !PLATFORM) || (NET6_0 && !IOS && !ANDROID && !TIZEN) 10 | using PlatformView = System.Object; 11 | #endif 12 | 13 | namespace MauiCustomEntryHandler 14 | { 15 | internal interface IMyEntryHandler : IViewHandler, IElementHandler 16 | { 17 | new IEntry VirtualView { get; } 18 | new PlatformView PlatformView { get; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /App.xaml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Platforms/Tizen/tizen-manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | appicon.xhigh.png 7 | 8 | 9 | 10 | 11 | http://tizen.org/privilege/internet 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Platforms/Windows/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | true/PM 12 | PerMonitorV2, PerMonitor 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Platforms/Windows/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.UI.Xaml; 2 | 3 | // To learn more about WinUI, the WinUI project structure, 4 | // and more about our project templates, see: http://aka.ms/winui-project-info. 5 | 6 | namespace MauiCustomEntryHandler.WinUI; 7 | 8 | /// 9 | /// Provides application-specific behavior to supplement the default Application class. 10 | /// 11 | public partial class App : MauiWinUIApplication 12 | { 13 | /// 14 | /// Initializes the singleton application object. This is the first line of authored code 15 | /// executed, and as such is the logical equivalent of main() or WinMain(). 16 | /// 17 | public App() 18 | { 19 | this.InitializeComponent(); 20 | } 21 | 22 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /MainPage.xaml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 12 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /MyEntry.cs: -------------------------------------------------------------------------------- 1 | namespace MauiCustomEntryHandler; 2 | 3 | public class MyEntry : Entry 4 | { 5 | /// 6 | /// Color of bottom border. 7 | /// 8 | public static BindableProperty UnderlineColorProperty = BindableProperty.Create( 9 | nameof(UnderlineColor), typeof(Color), typeof(MyEntry), Colors.Black); 10 | public Color UnderlineColor 11 | { 12 | get => (Color)GetValue(UnderlineColorProperty); 13 | set => SetValue(UnderlineColorProperty, value); 14 | } 15 | 16 | /// 17 | /// Thickness of bottom border. 18 | /// 19 | public static BindableProperty UnderlineThicknessProperty = BindableProperty.Create( 20 | nameof(UnderlineThickness), typeof(int), typeof(MyEntry), 0); 21 | public int UnderlineThickness 22 | { 23 | get => (int)GetValue(UnderlineThicknessProperty); 24 | set => SetValue(UnderlineThicknessProperty, value); 25 | } 26 | 27 | public MyEntry() 28 | { 29 | } 30 | } -------------------------------------------------------------------------------- /Platforms/MacCatalyst/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UIDeviceFamily 6 | 7 | 1 8 | 2 9 | 10 | UIRequiredDeviceCapabilities 11 | 12 | arm64 13 | 14 | UISupportedInterfaceOrientations 15 | 16 | UIInterfaceOrientationPortrait 17 | UIInterfaceOrientationLandscapeLeft 18 | UIInterfaceOrientationLandscapeRight 19 | 20 | UISupportedInterfaceOrientations~ipad 21 | 22 | UIInterfaceOrientationPortrait 23 | UIInterfaceOrientationPortraitUpsideDown 24 | UIInterfaceOrientationLandscapeLeft 25 | UIInterfaceOrientationLandscapeRight 26 | 27 | XSAppIconAssets 28 | Assets.xcassets/appicon.appiconset 29 | 30 | 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Steve Shaw 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Platforms/iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LSRequiresIPhoneOS 6 | 7 | UIDeviceFamily 8 | 9 | 1 10 | 2 11 | 12 | UIRequiredDeviceCapabilities 13 | 14 | arm64 15 | 16 | UISupportedInterfaceOrientations 17 | 18 | UIInterfaceOrientationPortrait 19 | UIInterfaceOrientationLandscapeLeft 20 | UIInterfaceOrientationLandscapeRight 21 | 22 | UISupportedInterfaceOrientations~ipad 23 | 24 | UIInterfaceOrientationPortrait 25 | UIInterfaceOrientationPortraitUpsideDown 26 | UIInterfaceOrientationLandscapeLeft 27 | UIInterfaceOrientationLandscapeRight 28 | 29 | XSAppIconAssets 30 | Assets.xcassets/appicon.appiconset 31 | 32 | 33 | -------------------------------------------------------------------------------- /MauiCustomEntryHandler.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31611.283 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MauiCustomEntryHandler", "MauiCustomEntryHandler.csproj", "{5245B013-C554-4EF6-9180-25B464EAE68C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {5245B013-C554-4EF6-9180-25B464EAE68C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {5245B013-C554-4EF6-9180-25B464EAE68C}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {5245B013-C554-4EF6-9180-25B464EAE68C}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 17 | {5245B013-C554-4EF6-9180-25B464EAE68C}.Release|Any CPU.ActiveCfg = Release|Any CPU 18 | {5245B013-C554-4EF6-9180-25B464EAE68C}.Release|Any CPU.Build.0 = Release|Any CPU 19 | {5245B013-C554-4EF6-9180-25B464EAE68C}.Release|Any CPU.Deploy.0 = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(SolutionProperties) = preSolution 22 | HideSolutionNode = FALSE 23 | EndGlobalSection 24 | GlobalSection(ExtensibilityGlobals) = postSolution 25 | SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572} 26 | EndGlobalSection 27 | EndGlobal 28 | -------------------------------------------------------------------------------- /Platforms/Android/_Maui/ColorStates.cs: -------------------------------------------------------------------------------- 1 | using AAttribute = Android.Resource.Attribute; 2 | 3 | namespace Microsoft.Maui 4 | { 5 | internal static class ColorStates 6 | { 7 | public static readonly int[][] Default = 8 | { 9 | new int[] { }, 10 | }; 11 | 12 | public static readonly int[][] EditText = 13 | { 14 | new[] { AAttribute.StateEnabled }, 15 | new[] { -AAttribute.StateEnabled }, 16 | }; 17 | 18 | public static readonly int[][] CheckBox = 19 | { 20 | new int[] { AAttribute.StateEnabled, AAttribute.StateChecked }, 21 | new int[] { AAttribute.StateEnabled, -AAttribute.StateChecked }, 22 | new int[] { -AAttribute.StateEnabled, AAttribute.StateChecked }, 23 | new int[] { -AAttribute.StateEnabled, -AAttribute.StatePressed }, 24 | }; 25 | 26 | public static readonly int[][] Switch = 27 | { 28 | new int[] { -AAttribute.StateEnabled }, 29 | new int[] { AAttribute.StateChecked }, 30 | new int[] { }, 31 | }; 32 | 33 | public static readonly int[][] Button = 34 | { 35 | new int[] { AAttribute.StateEnabled }, 36 | new int[] {-AAttribute.StateEnabled }, 37 | new int[] {-AAttribute.StateChecked }, 38 | new int[] { AAttribute.StatePressed } 39 | }; 40 | } 41 | } -------------------------------------------------------------------------------- /Platforms/Android/_Maui/AlignmentExtensions.cs: -------------------------------------------------------------------------------- 1 | using Android.Views; 2 | using ATextAlignment = Android.Views.TextAlignment; 3 | 4 | namespace Microsoft.Maui.Platform 5 | { 6 | internal static class AlignmentExtensions 7 | { 8 | internal static ATextAlignment ToTextAlignment(this TextAlignment alignment) 9 | { 10 | switch (alignment) 11 | { 12 | case TextAlignment.Center: 13 | return ATextAlignment.Center; 14 | case TextAlignment.End: 15 | return ATextAlignment.ViewEnd; 16 | default: 17 | return ATextAlignment.ViewStart; 18 | } 19 | } 20 | 21 | internal static GravityFlags ToHorizontalGravityFlags(this TextAlignment alignment) 22 | { 23 | switch (alignment) 24 | { 25 | case TextAlignment.Center: 26 | return GravityFlags.CenterHorizontal; 27 | case TextAlignment.End: 28 | return GravityFlags.End; 29 | default: 30 | return GravityFlags.Start; 31 | } 32 | } 33 | 34 | internal static GravityFlags ToVerticalGravityFlags(this TextAlignment alignment) 35 | { 36 | switch (alignment) 37 | { 38 | case TextAlignment.Start: 39 | return GravityFlags.Top; 40 | case TextAlignment.End: 41 | return GravityFlags.Bottom; 42 | default: 43 | return GravityFlags.CenterVertical; 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Platforms/Android/_Maui/TextAlignmentExtensions.cs: -------------------------------------------------------------------------------- 1 | using Android.Widget; 2 | using AGravityFlags = Android.Views.GravityFlags; 3 | 4 | namespace Microsoft.Maui.Platform 5 | { 6 | public static class TextAlignmentExtensions 7 | { 8 | internal static void UpdateHorizontalAlignment(this EditText view, TextAlignment alignment, AGravityFlags orMask = AGravityFlags.NoGravity) 9 | { 10 | if (!Rtl.IsSupported) 11 | view.Gravity = alignment.ToHorizontalGravityFlags() | orMask; 12 | else 13 | view.TextAlignment = alignment.ToTextAlignment(); 14 | } 15 | 16 | public static void UpdateVerticalAlignment(this EditText view, TextAlignment alignment, AGravityFlags orMask = AGravityFlags.NoGravity) 17 | { 18 | view.Gravity = alignment.ToVerticalGravityFlags() | orMask; 19 | } 20 | 21 | public static void UpdateVerticalAlignment(this TextView view, TextAlignment alignment, AGravityFlags orMask = AGravityFlags.NoGravity) 22 | { 23 | view.Gravity = alignment.ToVerticalGravityFlags() | orMask; 24 | } 25 | 26 | public static void UpdateTextAlignment(this EditText view, TextAlignment horizontal, TextAlignment vertical) 27 | { 28 | if (view.Context != null && !Rtl.IsSupported) 29 | { 30 | view.Gravity = vertical.ToVerticalGravityFlags() | horizontal.ToHorizontalGravityFlags(); 31 | } 32 | else 33 | { 34 | view.TextAlignment = horizontal.ToTextAlignment(); 35 | view.Gravity = vertical.ToVerticalGravityFlags(); 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Resources/AppIcon/appiconfg.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Resources/Splash/splash.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Platforms/Windows/Package.appxmanifest: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | $placeholder$ 12 | User Name 13 | $placeholder$.png 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Platforms/Android/_Maui/ColorStateListExtensions.cs: -------------------------------------------------------------------------------- 1 | using Android.Content.Res; 2 | using AColor = Android.Graphics.Color; 3 | 4 | namespace Microsoft.Maui.Platform 5 | { 6 | internal static class ColorStateListExtensions 7 | { 8 | public static bool IsOneColor(this ColorStateList? csl, int[][] states, AColor color) 9 | { 10 | if (csl == null) 11 | return false; 12 | 13 | if (states.Length == 0) 14 | return false; 15 | 16 | for (int i = 0; i < states.Length; i++) 17 | { 18 | var colorState = states[i]; 19 | if (csl.GetColorForState(colorState, color) != color) 20 | return false; 21 | } 22 | 23 | return true; 24 | } 25 | 26 | public static ColorStateList CreateDefault(int color) => 27 | new ColorStateList(ColorStates.Default, new[] { color }); 28 | 29 | public static ColorStateList CreateEditText(int all) => 30 | CreateEditText(all, all); 31 | 32 | public static ColorStateList CreateEditText(int enabled, int disabled) => 33 | new ColorStateList(ColorStates.EditText, new[] { enabled, disabled }); 34 | 35 | public static ColorStateList CreateCheckBox(int all) => 36 | CreateCheckBox(all, all, all, all); 37 | 38 | public static ColorStateList CreateCheckBox(int enabledChecked, int enabledUnchecked, int disabledChecked, int disabledUnchecked) => 39 | new ColorStateList(ColorStates.EditText, new[] { enabledChecked, enabledUnchecked, disabledChecked, disabledUnchecked }); 40 | 41 | public static ColorStateList CreateSwitch(int all) => 42 | CreateSwitch(all, all, all); 43 | 44 | public static ColorStateList CreateSwitch(int disabled, int on, int normal) => 45 | new ColorStateList(ColorStates.EditText, new[] { disabled, on, normal }); 46 | 47 | public static ColorStateList CreateButton(int all) => 48 | CreateButton(all, all, all, all); 49 | 50 | public static ColorStateList CreateButton(int enabled, int disabled, int off, int pressed) => 51 | new ColorStateList(ColorStates.EditText, new[] { enabled, disabled, off, pressed }); 52 | } 53 | } -------------------------------------------------------------------------------- /Resources/Styles/Colors.xaml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | #512BD4 8 | #DFD8F7 9 | #2B0B98 10 | White 11 | Black 12 | #E1E1E1 13 | #C8C8C8 14 | #ACACAC 15 | #919191 16 | #6E6E6E 17 | #404040 18 | #212121 19 | #141414 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | #F7B548 35 | #FFD590 36 | #FFE5B9 37 | #28C2D1 38 | #7BDDEF 39 | #C3F2F4 40 | #3E8EED 41 | #72ACF1 42 | #A7CBF6 43 | 44 | -------------------------------------------------------------------------------- /MauiCustomEntryHandler.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0-android;net6.0-ios;net6.0-maccatalyst 5 | $(TargetFrameworks);net6.0-windows10.0.19041.0 6 | 7 | 8 | Exe 9 | MauiCustomEntryHandler 10 | true 11 | true 12 | enable 13 | 14 | 15 | MauiCustomEntryHandler 16 | 17 | 18 | com.companyname.mauicustomentryhandler 19 | 514429FB-A68B-40CA-8196-12BBC43CF0E8 20 | 21 | 22 | 1.0 23 | 1 24 | 25 | 14.2 26 | 14.0 27 | 21.0 28 | 10.0.17763.0 29 | 10.0.17763.0 30 | 6.5 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /ElementHandlerExtensions.cs: -------------------------------------------------------------------------------- 1 | #nullable enable 2 | #if IOS || MACCATALYST 3 | using PlatformView = UIKit.UIView; 4 | #elif ANDROID 5 | using PlatformView = Android.Views.View; 6 | #elif WINDOWS 7 | using PlatformView = Microsoft.UI.Xaml.FrameworkElement; 8 | #elif TIZEN 9 | using PlatformView = ElmSharp.EvasObject; 10 | #elif (NETSTANDARD || !PLATFORM) 11 | using PlatformView = System.Object; 12 | #endif 13 | using System; 14 | using Microsoft.Extensions.DependencyInjection; 15 | using Microsoft.Maui.Handlers; 16 | using System.Threading.Tasks; 17 | 18 | // Copy of Maui repo maui\src\Core\src\Handlers\ElementHandlerExtensions.cs 19 | namespace Microsoft.Maui 20 | { 21 | static class ElementHandlerExtensions 22 | { 23 | #if WINDOWS 24 | //public static PlatformView ToPlatform(this IElementHandler elementHandler) => 25 | // (elementHandler.VirtualView?.ToPlatform() as PlatformView) ?? 26 | // throw new InvalidOperationException($"Unable to convert {elementHandler} to {typeof(PlatformView)}"); 27 | #endif 28 | 29 | public static IServiceProvider GetServiceProvider(this IElementHandler handler) 30 | { 31 | var context = handler.MauiContext ?? 32 | throw new InvalidOperationException($"Unable to find the context. The {nameof(ElementHandler.MauiContext)} property should have been set by the host."); 33 | 34 | var services = context?.Services ?? 35 | throw new InvalidOperationException($"Unable to find the service provider. The {nameof(ElementHandler.MauiContext)} property should have been set by the host."); 36 | 37 | return services; 38 | } 39 | 40 | public static T? GetService(this IElementHandler handler, Type type) 41 | { 42 | var services = handler.GetServiceProvider(); 43 | 44 | var service = services.GetService(type); 45 | 46 | return (T?)service; 47 | } 48 | 49 | public static T? GetService(this IElementHandler handler) 50 | { 51 | var services = handler.GetServiceProvider(); 52 | 53 | var service = services.GetService(); 54 | 55 | return service; 56 | } 57 | 58 | public static T GetRequiredService(this IElementHandler handler, Type type) 59 | where T : notnull 60 | { 61 | var services = handler.GetServiceProvider(); 62 | 63 | var service = services.GetRequiredService(type); 64 | 65 | return (T)service; 66 | } 67 | 68 | public static T GetRequiredService(this IElementHandler handler) 69 | where T : notnull 70 | { 71 | var services = handler.GetServiceProvider(); 72 | 73 | var service = services.GetRequiredService(); 74 | 75 | return service; 76 | } 77 | 78 | public static Task InvokeAsync(this IElementHandler handler, string commandName, 79 | TaskCompletionSource args) 80 | { 81 | handler?.Invoke(commandName, args); 82 | return args.Task; 83 | } 84 | 85 | public static T InvokeWithResult(this IElementHandler handler, string commandName, 86 | RetrievePlatformValueRequest args) 87 | { 88 | handler?.Invoke(commandName, args); 89 | return args.Result; 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /MyEntryHandler.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Maui.Handlers; 2 | #if WINDOWS 3 | using Microsoft.UI.Xaml.Controls; 4 | #endif 5 | 6 | namespace MauiCustomEntryHandler 7 | { 8 | #if WINDOWS 9 | // Cross-platform partial of class. See Maui repo maui\src\Core\src\Handlers\Entry\EntryHandler.cs 10 | public partial class MyEntryHandler : IMyEntryHandler //: EntryHandler 11 | { 12 | // static c'tor. 13 | static MyEntryHandler() 14 | { 15 | // TBD: Fill MyMapper here by copying from Entry.Mapper, then add custom ones defined in MyEntry? 16 | } 17 | 18 | //public static IPropertyMapper MyMapper => Mapper; 19 | public static IPropertyMapper MyMapper = new PropertyMapper(ViewMapper) 20 | { 21 | // From Entry. 22 | [nameof(IEntry.Background)] = MapBackground, 23 | [nameof(IEntry.CharacterSpacing)] = MapCharacterSpacing, 24 | [nameof(IEntry.ClearButtonVisibility)] = MapClearButtonVisibility, 25 | [nameof(IEntry.Font)] = MapFont, 26 | [nameof(IEntry.IsPassword)] = MapIsPassword, 27 | [nameof(IEntry.HorizontalTextAlignment)] = MapHorizontalTextAlignment, 28 | [nameof(IEntry.VerticalTextAlignment)] = MapVerticalTextAlignment, 29 | [nameof(IEntry.IsReadOnly)] = MapIsReadOnly, 30 | [nameof(IEntry.IsTextPredictionEnabled)] = MapIsTextPredictionEnabled, 31 | [nameof(IEntry.Keyboard)] = MapKeyboard, 32 | [nameof(IEntry.MaxLength)] = MapMaxLength, 33 | [nameof(IEntry.Placeholder)] = MapPlaceholder, 34 | [nameof(IEntry.PlaceholderColor)] = MapPlaceholderColor, 35 | [nameof(IEntry.ReturnType)] = MapReturnType, 36 | [nameof(IEntry.Text)] = MapText, 37 | [nameof(IEntry.TextColor)] = MapTextColor, 38 | [nameof(IEntry.CursorPosition)] = MapCursorPosition, 39 | [nameof(IEntry.SelectionLength)] = MapSelectionLength, 40 | // From MyEntry 41 | [nameof(MyEntry.UnderlineThickness)] = MapUnderlineThickness 42 | }; 43 | 44 | // TBD: What is this for? Cloned one on Entry. 45 | private static void MapUnderlineThickness(MyEntryHandler arg1, IEntry arg2) 46 | { 47 | } 48 | 49 | 50 | public MyEntryHandler() : base(MyMapper) 51 | { 52 | } 53 | 54 | //IEntry IEntryHandler.VirtualView => throw new NotImplementedException(); 55 | 56 | //IView IViewHandler.VirtualView => throw new NotImplementedException(); 57 | 58 | //IElement IElementHandler.VirtualView => throw new NotImplementedException(); 59 | 60 | //TextBox IEntryHandler.PlatformView => throw new NotImplementedException(); 61 | 62 | //object IElementHandler.PlatformView => throw new NotImplementedException(); 63 | 64 | //bool IViewHandler.HasContainer { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } 65 | 66 | //object IViewHandler.ContainerView => throw new NotImplementedException(); 67 | 68 | //IMauiContext IElementHandler.MauiContext => throw new NotImplementedException(); 69 | 70 | //void IElementHandler.DisconnectHandler() 71 | //{ 72 | // throw new NotImplementedException(); 73 | //} 74 | 75 | //Size IViewHandler.GetDesiredSize(double widthConstraint, double heightConstraint) 76 | //{ 77 | // throw new NotImplementedException(); 78 | //} 79 | 80 | //void IElementHandler.Invoke(string command, object args) 81 | //{ 82 | // throw new NotImplementedException(); 83 | //} 84 | 85 | //void IViewHandler.PlatformArrange(Rect frame) 86 | //{ 87 | // throw new NotImplementedException(); 88 | //} 89 | 90 | //void IElementHandler.SetMauiContext(IMauiContext mauiContext) 91 | //{ 92 | // throw new NotImplementedException(); 93 | //} 94 | 95 | //void IElementHandler.SetVirtualView(IElement view) 96 | //{ 97 | // throw new NotImplementedException(); 98 | //} 99 | 100 | //void IElementHandler.UpdateValue(string property) 101 | //{ 102 | // throw new NotImplementedException(); 103 | //} 104 | } 105 | // ========== MAY NEED BELOW FOR PLATFORMS NOT YET IMPLEMENTED ========== 106 | #else 107 | public partial class MyEntryHandler : EntryHandler 108 | { 109 | } 110 | #endif 111 | } 112 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /Platforms/Android/MyEntryHandler.Android.cs: -------------------------------------------------------------------------------- 1 | using Android.Content.Res; 2 | using Android.Graphics.Drawables; 3 | using Android.Runtime; 4 | using Android.Text; 5 | using Android.Views; 6 | using Android.Views.InputMethods; 7 | #nullable enable 8 | #if __IOS__ || MACCATALYST 9 | using PlatformView = Microsoft.Maui.Platform.MauiTextField; 10 | #elif MONOANDROID 11 | using PlatformView = AndroidX.AppCompat.Widget.AppCompatEditText; 12 | #elif WINDOWS 13 | using PlatformView = Microsoft.UI.Xaml.Controls.TextBox; 14 | #elif TIZEN 15 | using PlatformView = Tizen.UIExtensions.ElmSharp.Entry; 16 | #elif (NETSTANDARD || !PLATFORM) || (NET6_0 && !IOS && !ANDROID && !TIZEN) 17 | using PlatformView = System.Object; 18 | #endif 19 | 20 | using Android.Widget; 21 | using AndroidX.AppCompat.Widget; 22 | using AndroidX.Core.Content; 23 | using Microsoft.Maui.Handlers; 24 | using ViewExtensions = Microsoft.Maui.Platform.ViewExtensions; 25 | using static Android.Views.View; 26 | using static Android.Widget.TextView; 27 | using TextChangedEventArgs = Android.Text.TextChangedEventArgs; 28 | using TouchEventArgs = Android.Views.View.TouchEventArgs; 29 | using Microsoft.Maui.Platform; 30 | 31 | namespace MauiCustomEntryHandler 32 | { 33 | /// 34 | /// Android platform partial of class. Based on Maui src\Core\src\Handlers\Entry\EntryHandler.Android.cs. 35 | /// 36 | public partial class MyEntryHandler : Microsoft.Maui.Handlers.EntryHandler 37 | { 38 | protected override AppCompatEditText CreatePlatformView() 39 | { 40 | var nativeEntry = new AppCompatEditText(Context); 41 | var myentry = VirtualView as MyEntry; 42 | 43 | if (myentry.UnderlineThickness == 0) 44 | { // Hide Underline. 45 | nativeEntry.PaintFlags &= ~Android.Graphics.PaintFlags.UnderlineText; 46 | //nativeEntry.Background = null; 47 | //nativeEntry.SetBackgroundColor(global::Android.Graphics.Color.Transparent); 48 | } 49 | else 50 | { // Show Underline. (Is only under the typed text, not the whole control.) 51 | nativeEntry.PaintFlags |= Android.Graphics.PaintFlags.UnderlineText; 52 | // TODO: Line thickness and color. For color, see https://stackoverflow.com/a/62486103/199364. 53 | // For thickness, probably need to "nest controls", similar to Windows implementation. 54 | } 55 | 56 | return nativeEntry; 57 | } 58 | 59 | 60 | 61 | // ========== TBD: Which of below are needed? (Most can be inherited) ========== 62 | //} 63 | //public partial class EntryHandler : Microsoft.Maui.Handlers.ViewHandler 64 | //{ 65 | Drawable? _clearButtonDrawable; 66 | 67 | // Returns the default 'X' char drawable in the AppCompatEditText. 68 | protected virtual Drawable GetClearButtonDrawable() => 69 | _clearButtonDrawable ??= ContextCompat.GetDrawable(Context, Resource.Drawable.abc_ic_clear_material); 70 | 71 | protected override void ConnectHandler(AppCompatEditText platformView) 72 | { 73 | platformView.TextChanged += OnTextChanged; 74 | platformView.FocusChange += OnFocusedChange; 75 | platformView.Touch += OnTouch; 76 | platformView.EditorAction += OnEditorAction; 77 | } 78 | 79 | protected override void DisconnectHandler(AppCompatEditText platformView) 80 | { 81 | _clearButtonDrawable = null; 82 | platformView.TextChanged -= OnTextChanged; 83 | platformView.FocusChange -= OnFocusedChange; 84 | platformView.Touch -= OnTouch; 85 | platformView.EditorAction -= OnEditorAction; 86 | } 87 | 88 | public static void MapBackground(IEntryHandler handler, IEntry entry) => 89 | handler.PlatformView?.UpdateBackground(entry); 90 | 91 | public static void MapText(IEntryHandler handler, IEntry entry) => 92 | handler.PlatformView?.UpdateText(entry); 93 | 94 | public static void MapTextColor(IEntryHandler handler, IEntry entry) => 95 | handler.PlatformView?.UpdateTextColor(entry); 96 | 97 | public static void MapIsPassword(IEntryHandler handler, IEntry entry) => 98 | handler.PlatformView?.UpdateIsPassword(entry); 99 | 100 | public static void MapHorizontalTextAlignment(IEntryHandler handler, IEntry entry) => 101 | handler.PlatformView?.UpdateHorizontalTextAlignment(entry); 102 | 103 | public static void MapVerticalTextAlignment(IEntryHandler handler, IEntry entry) => 104 | handler?.PlatformView?.UpdateVerticalTextAlignment(entry); 105 | 106 | public static void MapIsTextPredictionEnabled(IEntryHandler handler, IEntry entry) => 107 | handler.PlatformView?.UpdateIsTextPredictionEnabled(entry); 108 | 109 | public static void MapMaxLength(IEntryHandler handler, IEntry entry) => 110 | handler.PlatformView?.UpdateMaxLength(entry); 111 | 112 | public static void MapPlaceholder(IEntryHandler handler, IEntry entry) => 113 | handler.PlatformView?.UpdatePlaceholder(entry); 114 | 115 | public static void MapPlaceholderColor(IEntryHandler handler, IEntry entry) 116 | { 117 | if (handler is EntryHandler platformHandler) 118 | handler.PlatformView?.UpdatePlaceholderColor(entry); 119 | } 120 | 121 | public static void MapFont(IEntryHandler handler, IEntry entry) => 122 | handler.PlatformView?.UpdateFont(entry, handler.GetRequiredService()); 123 | 124 | public static void MapIsReadOnly(IEntryHandler handler, IEntry entry) => 125 | handler.PlatformView?.UpdateIsReadOnly(entry); 126 | 127 | public static void MapKeyboard(IEntryHandler handler, IEntry entry) => 128 | handler.PlatformView?.UpdateKeyboard(entry); 129 | 130 | public static void MapReturnType(IEntryHandler handler, IEntry entry) => 131 | handler.PlatformView?.UpdateReturnType(entry); 132 | 133 | public static void MapCharacterSpacing(IEntryHandler handler, IEntry entry) => 134 | handler.PlatformView?.UpdateCharacterSpacing(entry); 135 | 136 | public static void MapCursorPosition(IEntryHandler handler, IEntry entry) => 137 | handler.PlatformView?.UpdateCursorPosition(entry); 138 | 139 | public static void MapSelectionLength(IEntryHandler handler, IEntry entry) => 140 | handler.PlatformView?.UpdateSelectionLength(entry); 141 | 142 | public static void MapClearButtonVisibility(IEntryHandler handler, IEntry entry) 143 | { 144 | if (handler is MyEntryHandler platformHandler) 145 | handler.PlatformView?.UpdateClearButtonVisibility(entry, platformHandler.GetClearButtonDrawable); 146 | } 147 | 148 | void OnTextChanged(object? sender, TextChangedEventArgs e) => 149 | VirtualView?.UpdateText(e); 150 | 151 | // This will eliminate additional native property setting if not required. 152 | void OnFocusedChange(object? sender, FocusChangeEventArgs e) 153 | { 154 | if (VirtualView?.ClearButtonVisibility == ClearButtonVisibility.WhileEditing) 155 | UpdateValue(nameof(IEntry.ClearButtonVisibility)); 156 | } 157 | 158 | // Check whether the touched position inbounds with clear button. 159 | void OnTouch(object? sender, TouchEventArgs e) => 160 | e.Handled = 161 | VirtualView?.ClearButtonVisibility == ClearButtonVisibility.WhileEditing && 162 | PlatformView.HandleClearButtonTouched(VirtualView.FlowDirection, e, GetClearButtonDrawable); 163 | 164 | void OnEditorAction(object? sender, EditorActionEventArgs e) 165 | { 166 | if (e.IsCompletedAction()) 167 | { 168 | // TODO: Dismiss keyboard for hardware / physical keyboards 169 | 170 | VirtualView?.Completed(); 171 | } 172 | 173 | e.Handled = true; 174 | } 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /Platforms/Windows/MyEntryHandler.Windows.cs: -------------------------------------------------------------------------------- 1 | // TBD: Not supposed to need "#if" in Windows folder, but w/o this get compile errors. Those go away if add dummy implementation on ALL platforms mentioned in .csproj. 2 | #if WINDOWS 3 | //using Microsoft.Maui.Handlers; 4 | using Microsoft.Maui.Platform; 5 | using Microsoft.UI.Xaml; 6 | //using Microsoft.UI.Xaml.Controls; 7 | using Microsoft.UI.Xaml.Input; 8 | //using Microsoft.UI.Xaml.Media; 9 | using Windows.System; 10 | //using Windows.UI; 11 | using static Microsoft.Maui.ElementHandlerExtensions; 12 | using Border = Microsoft.UI.Xaml.Controls.Border; 13 | using Color = Windows.UI.Color; 14 | using Colors = Microsoft.UI.Colors; 15 | using MauiColor = Microsoft.Maui.Graphics.Color; 16 | using PlatformEntryType = Microsoft.Maui.Platform.MauiPasswordTextBox; 17 | using PlatformView = Microsoft.UI.Xaml.Controls.Border; // Microsoft.UI.Xaml.FrameworkElement; 18 | using SolidColorBrush = Microsoft.UI.Xaml.Media.SolidColorBrush; 19 | using TextChangedEventArgs = Microsoft.UI.Xaml.Controls.TextChangedEventArgs; 20 | using Thickness = Microsoft.UI.Xaml.Thickness; 21 | 22 | namespace MauiCustomEntryHandler 23 | { 24 | /// 25 | /// Windows platform partial of class. Based on Maui src\Core\src\Handlers\Entry\EntryHandler.Windows.cs 26 | /// "TPlatformView" is "Microsoft.UI.Xaml.FrameworkElement". WAS "Microsoft.UI.Xaml.Controls.TextBox". 27 | /// 28 | public partial class MyEntryHandler : Microsoft.Maui.Handlers.ViewHandler //EntryHandler 29 | { 30 | static readonly bool s_shouldBeDelayed = DeviceInfo.Idiom != DeviceIdiom.Desktop; 31 | 32 | /// 33 | /// Adapted from EntryHandler.CreatePlatformView. 34 | /// 35 | /// 36 | protected override PlatformView CreatePlatformView() 37 | { 38 | var myentry = VirtualView as MyEntry; 39 | 40 | var textbox = new MauiPasswordTextBox 41 | { 42 | // From EntryHandler. 43 | IsObfuscationDelayed = s_shouldBeDelayed 44 | 45 | // TODO: pass entry properties through. 46 | }; 47 | 48 | MauiColor color = myentry != null 49 | ? myentry.UnderlineColor 50 | : MyEntry.UnderlineColorProperty.DefaultValue as MauiColor; 51 | int thickness = myentry != null 52 | ? myentry.UnderlineThickness 53 | : (int)MyEntry.UnderlineThicknessProperty.DefaultValue; 54 | 55 | var border = new Border 56 | { 57 | Child = textbox, 58 | BorderBrush = color.ToPlatform(), 59 | BorderThickness = new Thickness(0, 0, 0, thickness) 60 | }; 61 | 62 | 63 | return border; 64 | } 65 | 66 | 67 | private PlatformEntryType MyTextBox => (PlatformEntryType)PlatformView.Child; 68 | 69 | 70 | // ----- Based on Maui EntryHandler.Windows.cs ----- 71 | 72 | protected override void ConnectHandler(PlatformView platformView) 73 | { 74 | var textbox = (PlatformEntryType)platformView.Child; 75 | textbox.KeyUp += OnPlatformKeyUp; 76 | textbox.TextChanged += OnPlatformTextChanged; 77 | textbox.SelectionChanged += OnPlatformSelectionChanged; 78 | platformView.Loaded += OnPlatformLoaded; 79 | } 80 | 81 | protected override void DisconnectHandler(PlatformView platformView) 82 | { 83 | var textbox = (PlatformEntryType)platformView.Child; 84 | platformView.Loaded -= OnPlatformLoaded; 85 | textbox.KeyUp -= OnPlatformKeyUp; 86 | textbox.TextChanged -= OnPlatformTextChanged; 87 | textbox.SelectionChanged -= OnPlatformSelectionChanged; 88 | } 89 | 90 | public static void MapText(MyEntryHandler handler, IEntry entry) => 91 | handler.MyTextBox?.UpdateText(entry); 92 | 93 | public static void MapIsPassword(MyEntryHandler handler, IEntry entry) => 94 | handler.MyTextBox?.UpdateIsPassword(entry); 95 | 96 | public static void MapBackground(MyEntryHandler handler, IEntry entry) => 97 | handler.MyTextBox?.UpdateBackground(entry); 98 | 99 | public static void MapTextColor(MyEntryHandler handler, IEntry entry) => 100 | handler.MyTextBox?.UpdateTextColor(entry); 101 | 102 | public static void MapHorizontalTextAlignment(MyEntryHandler handler, IEntry entry) => 103 | handler.MyTextBox?.UpdateHorizontalTextAlignment(entry); 104 | 105 | public static void MapVerticalTextAlignment(MyEntryHandler handler, IEntry entry) => 106 | handler.MyTextBox?.UpdateVerticalTextAlignment(entry); 107 | 108 | public static void MapIsTextPredictionEnabled(MyEntryHandler handler, IEntry entry) => 109 | handler.MyTextBox?.UpdateIsTextPredictionEnabled(entry); 110 | 111 | public static void MapMaxLength(MyEntryHandler handler, IEntry entry) => 112 | handler.MyTextBox?.UpdateMaxLength(entry); 113 | 114 | public static void MapPlaceholder(MyEntryHandler handler, IEntry entry) => 115 | handler.MyTextBox?.UpdatePlaceholder(entry); 116 | 117 | public static void MapPlaceholderColor(MyEntryHandler handler, IEntry entry) => 118 | handler.MyTextBox?.UpdatePlaceholderColor(entry); 119 | 120 | public static void MapIsReadOnly(MyEntryHandler handler, IEntry entry) => 121 | handler.MyTextBox?.UpdateIsReadOnly(entry); 122 | 123 | public static void MapFont(MyEntryHandler handler, IEntry entry) => 124 | handler.MyTextBox?.UpdateFont(entry, handler.GetRequiredService()); 125 | 126 | public static void MapReturnType(MyEntryHandler handler, IEntry entry) => 127 | handler.MyTextBox?.UpdateReturnType(entry); 128 | 129 | public static void MapClearButtonVisibility(MyEntryHandler handler, IEntry entry) => 130 | handler.MyTextBox?.UpdateClearButtonVisibility(entry); 131 | 132 | public static void MapCharacterSpacing(MyEntryHandler handler, IEntry entry) => 133 | handler.MyTextBox?.UpdateCharacterSpacing(entry); 134 | 135 | public static void MapKeyboard(MyEntryHandler handler, IEntry entry) => 136 | handler.MyTextBox?.UpdateKeyboard(entry); 137 | 138 | public static void MapCursorPosition(MyEntryHandler handler, IEntry entry) => 139 | handler.MyTextBox?.UpdateCursorPosition(entry); 140 | 141 | public static void MapSelectionLength(MyEntryHandler handler, IEntry entry) => 142 | handler.MyTextBox?.UpdateSelectionLength(entry); 143 | 144 | void OnPlatformTextChanged(object sender, TextChangedEventArgs args) 145 | { 146 | var textbox = sender as PlatformEntryType; 147 | if (textbox == null) 148 | textbox = MyTextBox; 149 | 150 | VirtualView?.UpdateText(textbox.Password); 151 | } 152 | 153 | void OnPlatformKeyUp(object? sender, KeyRoutedEventArgs args) 154 | { 155 | if (args?.Key != VirtualKey.Enter) 156 | return; 157 | 158 | if (VirtualView?.ReturnType == ReturnType.Next) 159 | { 160 | PlatformView?.TryMoveFocus(FocusNavigationDirection.Next); 161 | } 162 | else 163 | { 164 | // TODO: Hide the soft keyboard; this matches the behavior of .NET MAUI on Android/iOS 165 | } 166 | 167 | VirtualView?.Completed(); 168 | } 169 | 170 | void OnPlatformSelectionChanged(object sender, RoutedEventArgs e) 171 | { 172 | if (VirtualView.CursorPosition != MyTextBox.SelectionStart) 173 | VirtualView.CursorPosition = MyTextBox.SelectionStart; 174 | 175 | if (VirtualView.SelectionLength != MyTextBox.SelectionLength) 176 | VirtualView.SelectionLength = MyTextBox.SelectionLength; 177 | } 178 | 179 | void OnPlatformLoaded(object sender, RoutedEventArgs e) => 180 | MauiTextBox.InvalidateAttachedProperties(PlatformView); 181 | } 182 | } 183 | #endif -------------------------------------------------------------------------------- /Resources/Images/dotnet_bot.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /Platforms/Android/_Maui/EditTextExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Android.Content.Res; 4 | using Android.Graphics.Drawables; 5 | using Android.Text; 6 | using Android.Views; 7 | using Android.Views.InputMethods; 8 | using Android.Widget; 9 | using Microsoft.Maui.Platform; 10 | using static Android.Views.View; 11 | using static Android.Widget.TextView; 12 | using TouchEventArgs = Android.Views.View.TouchEventArgs; 13 | 14 | namespace Microsoft.Maui.Platform 15 | { 16 | public static class EditTextExtensions 17 | { 18 | //public static void UpdateText(this EditText editText, IEntry entry) 19 | //{ 20 | // // Setting the text causes the cursor to reset to position zero 21 | // // Therefore if: 22 | // // User Types => VirtualView Updated => Triggers Native Update 23 | // // Then it will cause the cursor to reset to position zero as the user typed 24 | // if (entry.Text != editText.Text) 25 | // editText.Text = entry.Text; 26 | 27 | // // TODO ezhart The renderer sets the text to selected and shows the keyboard if the EditText is focused 28 | //} 29 | 30 | //public static void UpdateText(this EditText editText, IEditor editor) 31 | //{ 32 | // editText.Text = editor.Text; 33 | 34 | // editText.SetSelection(editText.Text?.Length ?? 0); 35 | //} 36 | 37 | //public static void UpdateTextColor(this EditText editText, ITextStyle entry) 38 | //{ 39 | // UpdateTextColor(editText, entry.TextColor); 40 | //} 41 | 42 | //public static void UpdateTextColor(this EditText editText, Microsoft.Maui.Graphics.Color textColor) 43 | //{ 44 | // if (textColor != null) 45 | // { 46 | // var androidColor = textColor.ToPlatform(); 47 | // if (!editText.TextColors.IsOneColor(ColorStates.EditText, androidColor)) 48 | // editText.SetTextColor(ColorStateListExtensions.CreateEditText(androidColor)); 49 | // } 50 | //} 51 | 52 | //public static void UpdateIsPassword(this EditText editText, IEntry entry) 53 | //{ 54 | // editText.SetInputType(entry); 55 | //} 56 | 57 | //public static void UpdateHorizontalTextAlignment(this EditText editText, ITextAlignment textAlignment) 58 | //{ 59 | // editText.UpdateHorizontalAlignment(textAlignment.HorizontalTextAlignment); 60 | //} 61 | 62 | //public static void UpdateVerticalTextAlignment(this EditText editText, ITextAlignment entry) 63 | //{ 64 | // TextAlignmentExtensions.UpdateVerticalAlignment(editText, entry.VerticalTextAlignment); 65 | //} 66 | 67 | //public static void UpdateIsTextPredictionEnabled(this EditText editText, IEntry entry) 68 | //{ 69 | // editText.SetInputType(entry); 70 | //} 71 | 72 | //public static void UpdateIsTextPredictionEnabled(this EditText editText, IEditor editor) 73 | //{ 74 | // if (editor.IsTextPredictionEnabled) 75 | // editText.InputType &= ~InputTypes.TextFlagNoSuggestions; 76 | // else 77 | // editText.InputType |= InputTypes.TextFlagNoSuggestions; 78 | //} 79 | 80 | //public static void UpdateMaxLength(this EditText editText, IEntry entry) => 81 | // UpdateMaxLength(editText, entry.MaxLength); 82 | 83 | //public static void UpdateMaxLength(this EditText editText, IEditor editor) => 84 | // UpdateMaxLength(editText, editor.MaxLength); 85 | 86 | //public static void UpdateMaxLength(this EditText editText, int maxLength) 87 | //{ 88 | // SetLengthFilter(editText, maxLength); 89 | 90 | // var newText = editText.Text.TrimToMaxLength(maxLength); 91 | // if (editText.Text != newText) 92 | // editText.Text = newText; 93 | //} 94 | 95 | //public static void SetLengthFilter(this EditText editText, int maxLength) 96 | //{ 97 | // if (maxLength == -1) 98 | // maxLength = int.MaxValue; 99 | 100 | // var currentFilters = new List(editText.GetFilters() ?? new IInputFilter[0]); 101 | // var changed = false; 102 | 103 | // for (var i = 0; i < currentFilters.Count; i++) 104 | // { 105 | // if (currentFilters[i] is InputFilterLengthFilter) 106 | // { 107 | // currentFilters.RemoveAt(i); 108 | // changed = true; 109 | // break; 110 | // } 111 | // } 112 | 113 | // if (maxLength >= 0) 114 | // { 115 | // currentFilters.Add(new InputFilterLengthFilter(maxLength)); 116 | // changed = true; 117 | // } 118 | 119 | // if (changed) 120 | // editText.SetFilters(currentFilters.ToArray()); 121 | //} 122 | 123 | //public static void UpdatePlaceholder(this EditText editText, IPlaceholder textInput) 124 | //{ 125 | // if (editText.Hint == textInput.Placeholder) 126 | // return; 127 | 128 | // editText.Hint = textInput.Placeholder; 129 | //} 130 | 131 | //public static void UpdatePlaceholderColor(this EditText editText, IPlaceholder placeholder) 132 | //{ 133 | // UpdatePlaceholderColor(editText, placeholder.PlaceholderColor); 134 | //} 135 | 136 | //public static void UpdatePlaceholderColor(this EditText editText, Graphics.Color placeholderTextColor) 137 | //{ 138 | // if (placeholderTextColor != null) 139 | // { 140 | // var androidColor = placeholderTextColor.ToPlatform(); 141 | // if (!editText.HintTextColors.IsOneColor(ColorStates.EditText, androidColor)) 142 | // editText.SetHintTextColor(ColorStateListExtensions.CreateEditText(androidColor)); 143 | // } 144 | //} 145 | 146 | //public static void UpdateIsReadOnly(this EditText editText, IEntry entry) 147 | //{ 148 | // bool isEditable = !entry.IsReadOnly; 149 | 150 | // editText.SetInputType(entry); 151 | 152 | // editText.FocusableInTouchMode = isEditable; 153 | // editText.Focusable = isEditable; 154 | 155 | // editText.SetCursorVisible(isEditable); 156 | //} 157 | 158 | //public static void UpdateKeyboard(this EditText editText, IEntry entry) 159 | //{ 160 | // editText.SetInputType(entry); 161 | //} 162 | 163 | //public static void UpdateKeyboard(this EditText editText, IEditor editor) 164 | //{ 165 | // editText.SetInputType(editor); 166 | //} 167 | 168 | //public static void UpdateIsReadOnly(this EditText editText, IEditor editor) 169 | //{ 170 | // bool isReadOnly = !editor.IsReadOnly; 171 | 172 | // editText.FocusableInTouchMode = isReadOnly; 173 | // editText.Focusable = isReadOnly; 174 | // editText.SetCursorVisible(isReadOnly); 175 | //} 176 | 177 | //public static void UpdateClearButtonVisibility(this EditText editText, IEntry entry, Drawable? clearButtonDrawable) => 178 | // UpdateClearButtonVisibility(editText, entry, () => clearButtonDrawable); 179 | 180 | //public static void UpdateClearButtonVisibility(this EditText editText, IEntry entry, Func? getClearButtonDrawable) 181 | //{ 182 | // // Places clear button drawable at the end or start of the EditText based on FlowDirection. 183 | // void ShowClearButton() 184 | // { 185 | // var drawable = getClearButtonDrawable?.Invoke(); 186 | 187 | // if (entry.GetEffectiveFlowDirection() == FlowDirection.RightToLeft) 188 | // { 189 | // editText.SetCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); 190 | // } 191 | // else 192 | // { 193 | // editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null); 194 | // } 195 | // } 196 | 197 | // // Hides clear button drawable from the control. 198 | // void HideClearButton() 199 | // { 200 | // editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, null, null); 201 | // } 202 | 203 | // bool isFocused = editText.IsFocused; 204 | // bool hasText = entry.Text?.Length > 0; 205 | 206 | // bool shouldDisplayClearButton = entry.ClearButtonVisibility == ClearButtonVisibility.WhileEditing 207 | // && hasText 208 | // && isFocused; 209 | 210 | // if (shouldDisplayClearButton) 211 | // { 212 | // ShowClearButton(); 213 | // } 214 | // else 215 | // { 216 | // HideClearButton(); 217 | // } 218 | //} 219 | 220 | //public static void UpdateReturnType(this EditText editText, IEntry entry) 221 | //{ 222 | // editText.ImeOptions = entry.ReturnType.ToPlatform(); 223 | //} 224 | 225 | //public static void UpdateCursorPosition(this EditText editText, ITextInput entry) 226 | //{ 227 | // if (editText.SelectionStart != entry.CursorPosition) 228 | // UpdateCursorSelection(editText, entry); 229 | //} 230 | 231 | //public static void UpdateSelectionLength(this EditText editText, ITextInput entry) 232 | //{ 233 | // if ((editText.SelectionEnd - editText.SelectionStart) != entry.SelectionLength) 234 | // UpdateCursorSelection(editText, entry); 235 | //} 236 | 237 | /* Updates both the IEntry.CursorPosition and IEntry.SelectionLength properties. */ 238 | static void UpdateCursorSelection(EditText editText, ITextInput entry) 239 | { 240 | if (!entry.IsReadOnly)// && editText.HasFocus)// || editText.RequestFocus()))//&& editText.RequestFocus()) 241 | { 242 | if (!editText.HasFocus) 243 | editText.RequestFocus(); 244 | 245 | int start = GetSelectionStart(editText, entry); 246 | int end = GetSelectionEnd(editText, entry, start); 247 | 248 | editText.SetSelection(start, end); 249 | } 250 | } 251 | 252 | static int GetSelectionStart(EditText editText, ITextInput entry) 253 | { 254 | int start = editText.Length(); 255 | int cursorPosition = entry.CursorPosition; 256 | 257 | if (editText.Text != null) 258 | { 259 | // Capping cursorPosition to the end of the text if needed 260 | start = System.Math.Min(editText.Text.Length, cursorPosition); 261 | } 262 | 263 | if (start != cursorPosition) 264 | { 265 | // Update the interface if start was capped 266 | entry.CursorPosition = start; 267 | } 268 | 269 | return start; 270 | } 271 | 272 | static int GetSelectionEnd(EditText editText, ITextInput entry, int start) 273 | { 274 | int end = start; 275 | int selectionLength = entry.SelectionLength; 276 | end = System.Math.Max(start, System.Math.Min(editText.Length(), start + selectionLength)); 277 | int newSelectionLength = System.Math.Max(0, end - start); 278 | // Updating this property results in UpdateSelectionLength being called again messing things up 279 | if (newSelectionLength != selectionLength) 280 | entry.SelectionLength = newSelectionLength; 281 | return end; 282 | } 283 | 284 | internal static void SetInputType(this EditText editText, ITextInput textInput) 285 | { 286 | if (textInput.IsReadOnly) 287 | { 288 | editText.InputType = InputTypes.Null; 289 | } 290 | else 291 | { 292 | var keyboard = textInput.Keyboard; 293 | var nativeInputTypeToUpdate = keyboard.ToInputType(); 294 | 295 | if (keyboard is not CustomKeyboard) 296 | { 297 | // TODO: IsSpellCheckEnabled handling must be here. 298 | 299 | if ((nativeInputTypeToUpdate & InputTypes.TextFlagNoSuggestions) != InputTypes.TextFlagNoSuggestions) 300 | { 301 | if (!textInput.IsTextPredictionEnabled) 302 | nativeInputTypeToUpdate |= InputTypes.TextFlagNoSuggestions; 303 | } 304 | } 305 | 306 | if (keyboard == Keyboard.Numeric) 307 | { 308 | editText.KeyListener = LocalizedDigitsKeyListener.Create(editText.InputType); 309 | } 310 | 311 | if (textInput is IEntry entry && entry.IsPassword) 312 | { 313 | if ((nativeInputTypeToUpdate & InputTypes.ClassText) == InputTypes.ClassText) 314 | nativeInputTypeToUpdate |= InputTypes.TextVariationPassword; 315 | 316 | if ((nativeInputTypeToUpdate & InputTypes.ClassNumber) == InputTypes.ClassNumber) 317 | nativeInputTypeToUpdate |= InputTypes.NumberVariationPassword; 318 | } 319 | 320 | editText.InputType = nativeInputTypeToUpdate; 321 | } 322 | 323 | if (textInput is IEditor) 324 | editText.InputType |= InputTypes.TextFlagMultiLine; 325 | } 326 | 327 | internal static bool IsCompletedAction(this EditorActionEventArgs e) 328 | { 329 | var actionId = e.ActionId; 330 | var evt = e.Event; 331 | 332 | return 333 | actionId == ImeAction.Done || 334 | (actionId == ImeAction.ImeNull && evt?.KeyCode == Keycode.Enter && evt?.Action == KeyEventActions.Up); 335 | } 336 | 337 | /// 338 | /// Checks whether the touched position on the EditText is inbounds with clear button and clears if so. 339 | /// This will return True to handle OnTouch to prevent re-activating keyboard after clearing the text. 340 | /// 341 | /// True if clear button is clicked and Text is cleared. False if not. 342 | internal static bool HandleClearButtonTouched(this EditText? platformView, FlowDirection flowDirection, TouchEventArgs? touchEvent, Func? getClearButtonDrawable) 343 | { 344 | if (platformView is null) 345 | return false; 346 | 347 | var motionEvent = touchEvent?.Event; 348 | if (motionEvent is null) 349 | return false; 350 | 351 | var rBounds = getClearButtonDrawable?.Invoke()?.Bounds; 352 | var buttonWidth = rBounds?.Width(); 353 | 354 | if (buttonWidth <= 0) 355 | return false; 356 | 357 | if (motionEvent.Action != MotionEventActions.Up) 358 | return false; 359 | 360 | var x = motionEvent.GetX(); 361 | var y = motionEvent.GetY(); 362 | 363 | if ((flowDirection != FlowDirection.LeftToRight 364 | || x < platformView.Right - buttonWidth 365 | || x > platformView.Right - platformView.PaddingRight 366 | || y < platformView.PaddingTop 367 | || y > platformView.Height - platformView.PaddingBottom) && 368 | (flowDirection != FlowDirection.RightToLeft 369 | || x < platformView.Left + platformView.PaddingLeft 370 | || x > platformView.Left + buttonWidth 371 | || y < platformView.PaddingTop 372 | || y > platformView.Height - platformView.PaddingBottom)) 373 | { 374 | return false; 375 | } 376 | 377 | platformView.Text = null; 378 | return true; 379 | } 380 | } 381 | } -------------------------------------------------------------------------------- /Resources/Styles/Styles.xaml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 10 | 11 | 15 | 16 | 21 | 22 | 25 | 26 | 47 | 48 | 63 | 64 | 82 | 83 | 102 | 103 | 122 | 123 | 128 | 129 | 147 | 148 | 165 | 166 | 170 | 171 | 191 | 192 | 207 | 208 | 226 | 227 | 230 | 231 | 252 | 253 | 273 | 274 | 280 | 281 | 300 | 301 | 304 | 305 | 333 | 334 | 352 | 353 | 357 | 358 | 370 | 371 | 376 | 377 | 383 | 384 | 385 | --------------------------------------------------------------------------------