void HandleKeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Enter && !_multiline) { _controller.Return(); } }
public NativeInput(Rectangle position, TextInputType keyboardContext, string text, int textSize, Align align, ITextEdit controller) { if (CurrentFocus != null) { CurrentFocus.Unfocus(); } _controller = controller; CurrentFocus = this; if (_textField == null) { InitTextField(); } text = text.Replace('\n', '\r'); Bottom = position.Bottom + (int)Platform.PointsToPixels(10); position.Y += AppMain.Current.SetFocus(this); float x = Platform.PixelsToPoints(position.X) + 1; float y = Platform.PixelsToPoints(position.Y) + 2; float width = Platform.PixelsToPoints(position.Width) - 2; float height = Platform.PixelsToPoints(position.Height) - 4; if (keyboardContext.HasFlag(TextInputType.PasswordClass)) { keyboardContext &= ~(TextInputType.NoSuggestions); } if (keyboardContext.HasFlag(TextInputType.MultilineText)) { _useTextView = true; _textView.Frame = new System.Drawing.RectangleF(x, y, width, height); _textView.BackgroundColor = new UIColor(255, 255, 255, 255); _textView.TextColor = new UIColor(0, 0, 0, 255); _textView.Opaque = true; _textView.KeyboardType = TypeFromContext(keyboardContext); _textView.AutocapitalizationType = AutoCapitalizationFromContext(keyboardContext); _textView.KeyboardType = UIKeyboardType.Default; _textView.AutocorrectionType = keyboardContext.HasFlag(TextInputType.NoSuggestions) ? UITextAutocorrectionType.No : UITextAutocorrectionType.Default; _textView.SecureTextEntry = keyboardContext.HasFlag(TextInputType.PasswordClass); _textView.Font = UIFont.FromName("Helvetica", textSize); SetText(text); _textView.Ended += HandleEnded; _textView.BecomeFirstResponder(); } else { _textField.Frame = new System.Drawing.RectangleF(x, y, width, height); _textField.BackgroundColor = new UIColor(255, 255, 255, 255); _textField.TextColor = new UIColor(0, 0, 0, 255); _textField.Opaque = true; _textField.KeyboardType = TypeFromContext(keyboardContext); _textField.AutocapitalizationType = AutoCapitalizationFromContext(keyboardContext); _textField.ResignFirstResponder(); _textField.AutocorrectionType = keyboardContext.HasFlag(TextInputType.NoSuggestions) ? UITextAutocorrectionType.No : UITextAutocorrectionType.Default; _textField.SecureTextEntry = keyboardContext.HasFlag(TextInputType.PasswordClass); _textField.ClearsOnBeginEditing = false; _textField.Font = UIFont.FromName("Helvetica", textSize); switch (align & Align.Horz) { case Align.Center: _textField.TextAlignment = UITextAlignment.Center; break; case Align.Left: _textField.TextAlignment = UITextAlignment.Left; break; case Align.Right: _textField.TextAlignment = UITextAlignment.Right; break; } SetText(text); _textField.EditingChanged += HandleEditingChanged; _textField.EditingDidEnd += HandleEditingDidEnd; _textField.ShouldReturn = delegate { if ((keyboardContext & TextInputType.TypeFilter) != TextInputType.MultilineText) { _controller.Return(); return(true); } return(false); }; _textField.BecomeFirstResponder(); } }