Exemplo n.º 1
0
        private void Control_EditorAction(object sender, TextView.EditorActionEventArgs e)
        {
            if (_view.ReturnType != ReturnType.Next)
            {
                _view.Unfocus();
            }

            // Call all the methods attached to base_entry event handler Completed
            _view.InvokeCompleted();
        }
        /// <summary>
        /// Called when [element changed].
        /// </summary>
        /// <param name="e">The e.</param>
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);
            if (!string.IsNullOrEmpty(e.NewElement?.FontFamily))
            {
                try
                {
                    var font = Typeface.CreateFromAsset(Forms.Context.ApplicationContext.Assets, e.NewElement.FontFamily + ".ttf");
                    Control.Typeface = font;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            var view = (ExtendedEntry)Element;

            if (Control != null && e.NewElement != null && e.NewElement.IsPassword)
            {
                //Control.SetTypeface(Typeface.Default, TypefaceStyle.Normal);
                Control.TransformationMethod = new PasswordTransformationMethod();
            }

            if ((Control != null) && (e.NewElement != null))
            {
                var entryExt = (e.NewElement as ExtendedEntry);
                Control.ImeOptions = entryExt.ReturnKeyType.GetValueFromDescription();
                // This is hackie ;-) / A Android-only bindable property should be added to the EntryExt class
                Control.SetImeActionLabel(entryExt.ReturnKeyType.ToString(), Control.ImeOptions);

                ExtendedEntry entry = (ExtendedEntry)this.Element;
                Control.EditorAction += (object sender, TextView.EditorActionEventArgs args) =>
                {
                    entry.InvokeCompleted();
                };
            }


            SetFont(view);
            SetTextAlignment(view);
            //SetBorder(view);
            SetPlaceholderTextColor(view);
            SetMaxLength(view);

            if (e.NewElement == null)
            {
                this.Touch -= HandleTouch;
            }

            if (e.OldElement == null)
            {
                this.Touch += HandleTouch;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// The on element changed callback.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);

            var view = e.NewElement as ExtendedEntry;

            if (view != null)
            {
                //SetFont(view);
                SetTextAlignment(view);
                SetBorder(view);
                SetPlaceholderTextColor(view);
                SetMaxLength(view);

                ResizeHeight();
            }

            if ((Control != null) && (e.NewElement != null))
            {
                Control.ReturnKeyType = (e.NewElement as ExtendedEntry).ReturnKeyType.GetValueFromDescription();
                ExtendedEntry entry = (ExtendedEntry)this.Element;
                Control.ShouldReturn += (UITextField tf) =>
                {
                    entry.InvokeCompleted();
                    return(true);
                };
            }

            if (e.OldElement == null)
            {
                _leftSwipeGestureRecognizer = new UISwipeGestureRecognizer(() => view.OnLeftSwipe(this, EventArgs.Empty))
                {
                    Direction = UISwipeGestureRecognizerDirection.Left
                };

                _rightSwipeGestureRecognizer = new UISwipeGestureRecognizer(() => view.OnRightSwipe(this, EventArgs.Empty))
                {
                    Direction = UISwipeGestureRecognizerDirection.Right
                };

                Control.AddGestureRecognizer(_leftSwipeGestureRecognizer);
                Control.AddGestureRecognizer(_rightSwipeGestureRecognizer);
            }

            if (e.NewElement == null)
            {
                Control.RemoveGestureRecognizer(_leftSwipeGestureRecognizer);
                Control.RemoveGestureRecognizer(_rightSwipeGestureRecognizer);
            }
        }