/// <summary> /// /// </summary> /// <param name="item"></param> /// <param name="convertView"></param> /// <param name="parent"></param> /// <param name="context"></param> /// <returns></returns> protected override Android.Views.View GetCellCore(Cell item, Android.Views.View convertView, ViewGroup parent, Context context) { var r = base.GetCellCore(item, convertView, parent, context); var viewCell = (ViewCell)item; var content = viewCell.BindingContext as Xamarin.Forms.View; if (content != null && !(content is Editor)) { var textField = Platform.GetRenderer(content)?.GetPropertyValue("Control") as EditText; if (textField != null) { var next = AtomForm.GetFocusNext(content); textField.ImeOptions = next is AtomSubmitButton ? ImeAction.Go : ImeAction.Next; textField.EditorAction += (s, e) => { if (e.ActionId == ImeAction.Next || e.ActionId == ImeAction.Go) { var nextField = Platform.GetRenderer(next)?.GetPropertyValue("Control") as Android.Views.View; var button = nextField as Android.Widget.Button; if (button != null) { button.CallOnClick(); // hide keyboard... HideKeyboard(textField); return; } var tf = nextField as EditText; if (tf != null) { tf.RequestFocus(); return; } HideKeyboard(textField); } }; } } return(r); }
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv) { var r = base.GetCell(item, reusableCell, tv); var viewCell = (ViewCell)item; var content = viewCell?.BindingContext as Xamarin.Forms.View; if (content != null && !(content is Editor)) { var textField = Platform.GetRenderer(content)?.NativeView?.GetPropertyValue("Control") as UITextField; if (textField != null) { var next = AtomForm.GetFocusNext(content); var submitButton = next as AtomSubmitButton; textField.ReturnKeyType = submitButton != null ? UIReturnKeyType.Go : UIReturnKeyType.Next; textField.ShouldReturn = (tf) => { var nextField = Platform.GetRenderer(next)?.NativeView?.GetPropertyValue("Control") as UIView; if (nextField == null) { tf.ResignFirstResponder(); return(false); } var cell = nextField.FindParent <UITableViewCell>(); cell?.BecomeFirstResponder(); //var button = nextField as UIButton; if (submitButton != null) { tf.ResignFirstResponder(); //button.SendActionForControlEvents(UIControlEvent.TouchUpInside); submitButton.OnSubmitCommand(); return(false); } var txt = nextField as UITextField; if (txt != null) { tf.ResignFirstResponder(); txt.BecomeFirstResponder(); } return(false); }; } } return(r); }
public static IDisposable BindKeyboardActions(Xamarin.Forms.View content) { if (content != null && !(content is Editor)) { var textField = Platform.GetRenderer(content)?.NativeView?.GetPropertyValue("Control") as UITextField; if (textField != null) { var next = AtomForm.GetFocusNext(content); var submitButton = next as AtomSubmitButton; textField.ReturnKeyType = submitButton != null ? UIReturnKeyType.Go : UIReturnKeyType.Next; textField.ShouldReturn = (tf) => { var nextField = Platform.GetRenderer(next)?.NativeView?.GetPropertyValue("Control") as UIView; if (nextField == null) { tf.ResignFirstResponder(); return(false); } var cell = nextField.FindParent <UITableViewCell>(); cell?.BecomeFirstResponder(); //var button = nextField as UIButton; if (submitButton != null) { tf.ResignFirstResponder(); //button.SendActionForControlEvents(UIControlEvent.TouchUpInside); submitButton.OnSubmitCommand(); return(false); } var txt = nextField as UITextField; if (txt != null) { tf.ResignFirstResponder(); txt.BecomeFirstResponder(); } return(false); }; new AtomDisposableAction(() => { textField.ShouldReturn = null; }); } } return(new AtomDisposableAction()); }
/// <summary> /// /// </summary> /// <param name="item"></param> /// <param name="convertView"></param> /// <param name="parent"></param> /// <param name="context"></param> /// <returns></returns> public static IDisposable BindKeyboardActions(Xamarin.Forms.View content) { if (content != null && !(content is Editor)) { var textField = Platform.GetRenderer(content)?.GetPropertyValue("Control") as EditText; if (textField != null) { var next = AtomForm.GetFocusNext(content); textField.ImeOptions = next is AtomSubmitButton ? ImeAction.Go : ImeAction.Next; EventHandler <EditorActionEventArgs> editorAction = (s, e) => { if (e.ActionId == ImeAction.Next || e.ActionId == ImeAction.Go) { var nextField = Platform.GetRenderer(next)?.GetPropertyValue("Control") as Android.Views.View; var button = nextField as Android.Widget.Button; if (button != null) { button.CallOnClick(); // hide keyboard... HideKeyboard(textField); return; } var tf = nextField as EditText; if (tf != null) { tf.RequestFocus(); return; } HideKeyboard(textField); } }; textField.EditorAction += editorAction; return(new AtomDisposableAction(() => { textField.EditorAction -= editorAction; })); } } return(new AtomDisposableAction(() => { })); }