I’ve an MAUI .NET 8 venture, I’m going through a difficulty that After I click on outdoors the customized entry when it has focus, it will not lose focus and will not cover the tender keyboard even once I Set HideSoftInputOnTapped=”True”.
Nevertheless, this challenge is not going to occur if CustomRender isn’t applied.
Please assist me to resolve this challenge.
Please discover the code
public class CustomEntry : Entry
{
public new occasion EventHandler Accomplished;
public CustomEntry()
{
// Default parameter
}
public CustomEntry(string PropertyID)
{
ClassId = PropertyID;
BackgroundColor = Colours.Clear;
HorizontalOptions = LayoutOptions.FillAndExpand;
}
public const string ReturnKeyPropertyName = "ReturnKeyType";
public static readonly BindableProperty ReturnKeyTypeProperty = BindableProperty.Create(
propertyName: ReturnKeyPropertyName,
returnType: typeof(ReturnKeyTypes),
declaringType: typeof(CustomEntry),
defaultValue: ReturnKeyTypes.Finished);
public ReturnKeyTypes ReturnKeyType
{
get { return (ReturnKeyTypes)GetValue(ReturnKeyTypeProperty); }
set { SetValue(ReturnKeyTypeProperty, worth); }
}
public Constants.eKeyboardTypes KeyBoardType
{
get;
set;
}
public void InvokeCompleted()
{
if (this.Accomplished != null)
this.Accomplished.Invoke(this, null);
}
public void SetVisible()
{
Allow();
IsVisible = true;
}
public void Allow()
{
IsEnabled = true;
BackgroundColor = Colours.Clear;
}
public void ReadOnly()
{
SetVisible();
IsEnabled = false;
BackgroundColor = Constants.ReadOnlyBackGroundColor;
}
public void Disabled()
{
SetVisible();
IsEnabled = false;
BackgroundColor = Constants.DisabledBackGroundColor;
}
}
public enum ReturnKeyTypes : int
{
Default,
Go,
Google,
Be part of,
Subsequent,
Route,
Search,
Ship,
Yahoo,
Finished,
EmergencyCall,
Proceed
}
public class CustomEntry_IOS: EntryRenderer
{
public CustomEntry_IOS()
{
}
protected override void OnElementChanged(ElementChangedEventArgs e)
{
CustomEntry entry = (CustomEntry)this.Component;
base.OnElementChanged(e);
if ((Management != null) && (e.NewElement != null))
Management.ReturnKeyType = (e.NewElement as CustomEntry).ReturnKeyType.GetValueFromDescription();
Management.Placeholder = entry.Placeholder;
//Management?.ResignFirstResponder();
// Editor Motion known as when the return button is pressed
//if (entry != null && entry.Keyboard == Keyboard.Numeric)
//{
// Management.KeyboardType = UIKeyboardType.NumbersAndPunctuation;
//}
if (Management != null)
Management.ShouldReturn += (UITextField tf) =>
{
entry.InvokeCompleted();
return true;
};
if (entry != null)
{
SetKeybordType(entry.KeyBoardType);
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
strive
{
base.OnElementPropertyChanged(sender, e);
// Management?.ResignFirstResponder();
if (e.PropertyName == CustomEntry.ReturnKeyPropertyName)
{
Management.ReturnKeyType = (sender as CustomEntry).ReturnKeyType.GetValueFromDescription();
//Management.ReturnKeyType = UIReturnKeyType.Proceed;
}
if ((sender as CustomEntry) != null && (sender as CustomEntry).Keyboard == Keyboard.Numeric)
{
Management.KeyboardType = UIKeyboardType.PhonePad;
}
}
catch (Exception ex)
{
// AppDelegate.log?.WriteLog(ex, Location: this.GetType().Identify + "." + MethodBase.GetCurrentMethod().Identify);
}
}
void SetKeybordType(Constants.eKeyboardTypes keyboardType)
{
change (keyboardType)
{
case Constants.eKeyboardTypes.Default:
this.Management.KeyboardType = UIKeyboardType.Default;
break;
case Constants.eKeyboardTypes.E-mail:
this.Management.KeyboardType = UIKeyboardType.EmailAddress;
break;
case Constants.eKeyboardTypes.Numeric:
this.Management.KeyboardType = UIKeyboardType.NumberPad;
break;
case Constants.eKeyboardTypes.NumericWithDecimal:
this.Management.KeyboardType = UIKeyboardType.DecimalPad;
break;
case Constants.eKeyboardTypes.NumericWithMinusAndDigit:
case Constants.eKeyboardTypes.NumericWithMinus:
this.Management.KeyboardType = UIKeyboardType.NumbersAndPunctuation;
break;
default:
this.Management.KeyboardType = UIKeyboardType.Default;
break;
}
}
}
public static class EnumExtensions
{
public static UIReturnKeyType GetValueFromDescription(this ReturnKeyTypes worth)
{
var sort = typeof(UIReturnKeyType);
if (!sort.IsEnum) throw new InvalidOperationException();
foreach (var area in sort.GetFields())
{
var attribute = Attribute.GetCustomAttribute(area,
typeof(DescriptionAttribute)) as DescriptionAttribute;
if (attribute != null)
{
if (attribute.Description == worth.ToString())
return (UIReturnKeyType)area.GetValue(null);
}
else
{
if (area.Identify == worth.ToString())
return (UIReturnKeyType)area.GetValue(null);
}
}
throw new NotSupportedException($"Not supported on iOS: {worth}");
}
}