Пример #1
0
        public static void ApplyKeyboard(this IUITextInputTraits textInput, Keyboard keyboard)
        {
            textInput.AutocapitalizationType = UITextAutocapitalizationType.None;
            textInput.AutocorrectionType     = UITextAutocorrectionType.No;
            textInput.SpellCheckingType      = UITextSpellCheckingType.No;

            if (keyboard == Keyboard.Default)
            {
                textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                textInput.AutocorrectionType     = UITextAutocorrectionType.Default;
                textInput.SpellCheckingType      = UITextSpellCheckingType.Default;
            }
            else if (keyboard == Keyboard.Chat)
            {
                textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                textInput.AutocorrectionType     = UITextAutocorrectionType.Yes;
            }
            else if (keyboard == Keyboard.Email)
            {
                textInput.KeyboardType = UIKeyboardType.EmailAddress;
            }
            else if (keyboard == Keyboard.Numeric)
            {
                textInput.KeyboardType = UIKeyboardType.DecimalPad;
            }
            else if (keyboard == Keyboard.Telephone)
            {
                textInput.KeyboardType = UIKeyboardType.PhonePad;
            }
            else if (keyboard == Keyboard.Text)
            {
                textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                textInput.AutocorrectionType     = UITextAutocorrectionType.Yes;
                textInput.SpellCheckingType      = UITextSpellCheckingType.Yes;
            }
            else if (keyboard == Keyboard.Url)
            {
                textInput.KeyboardType = UIKeyboardType.Url;
            }
            else
            {
                try
                {
                    // ReSharper disable once PossibleNullReferenceException
                    var flags = (KeyboardFlags)keyboard.GetType()
                                .GetProperty("Flags", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(keyboard);

                    textInput.AutocapitalizationType = flags.HasFlag(KeyboardFlags.CapitalizeSentence) ? UITextAutocapitalizationType.Sentences : UITextAutocapitalizationType.None;
                    textInput.AutocorrectionType     = flags.HasFlag(KeyboardFlags.Suggestions) ? UITextAutocorrectionType.Yes : UITextAutocorrectionType.No;
                    textInput.SpellCheckingType      = flags.HasFlag(KeyboardFlags.Spellcheck) ? UITextSpellCheckingType.Yes : UITextSpellCheckingType.No;
                }
                catch
                {
                    // ignored
                }
            }
        }
        private static bool TextFieldShouldReturn(IUITextInputTraits textfield)
        {
            switch (textfield.ReturnKeyType)
            {
            case UIReturnKeyType.Done:
                (textfield as UITextField)?.ResignFirstResponder();
                break;

            case UIReturnKeyType.Default:
                break;

            case UIReturnKeyType.Go:
                (textfield as UITextField)?.ResignFirstResponder();
                break;

            case UIReturnKeyType.Google:
                break;

            case UIReturnKeyType.Join:
                break;

            case UIReturnKeyType.Next:
                (textfield as UITextField)?.BecomeFirstResponder();
                break;

            case UIReturnKeyType.Route:
                break;

            case UIReturnKeyType.Search:
                (textfield as UITextField)?.ResignFirstResponder();
                break;

            case UIReturnKeyType.Send:
                break;

            case UIReturnKeyType.Yahoo:
                break;

            case UIReturnKeyType.EmergencyCall:
                break;

            case UIReturnKeyType.Continue:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            UIView.BeginAnimations(string.Empty, IntPtr.Zero);
            UIView.SetAnimationDuration(0.3);
            UIView.CommitAnimations();

            return(false);
        }
Пример #3
0
        public static void ApplyKeyboard(this IUITextInputTraits textInput, Keyboard keyboard)
        {
            textInput.AutocapitalizationType = UITextAutocapitalizationType.None;
            textInput.AutocorrectionType     = UITextAutocorrectionType.No;
            textInput.SpellCheckingType      = UITextSpellCheckingType.No;
            textInput.KeyboardType           = UIKeyboardType.Default;

            if (keyboard == Keyboard.Default)
            {
                textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                textInput.AutocorrectionType     = UITextAutocorrectionType.Default;
                textInput.SpellCheckingType      = UITextSpellCheckingType.Default;
            }
            else if (keyboard == Keyboard.Chat)
            {
                textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                textInput.AutocorrectionType     = UITextAutocorrectionType.Yes;
            }
            else if (keyboard == Keyboard.Email)
            {
                textInput.KeyboardType = UIKeyboardType.EmailAddress;
            }
            else if (keyboard == Keyboard.Numeric)
            {
                textInput.KeyboardType = UIKeyboardType.DecimalPad;
            }
            else if (keyboard == Keyboard.Telephone)
            {
                textInput.KeyboardType = UIKeyboardType.PhonePad;
            }
            else if (keyboard == Keyboard.Text)
            {
                textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
                textInput.AutocorrectionType     = UITextAutocorrectionType.Yes;
                textInput.SpellCheckingType      = UITextSpellCheckingType.Yes;
            }
            else if (keyboard == Keyboard.Url)
            {
                textInput.KeyboardType = UIKeyboardType.Url;
            }
            else if (keyboard is CustomKeyboard)
            {
                var custom = (CustomKeyboard)keyboard;

                var capitalizedSentenceEnabled  = (custom.Flags & KeyboardFlags.CapitalizeSentence) == KeyboardFlags.CapitalizeSentence;
                var capitalizedWordsEnabled     = (custom.Flags & KeyboardFlags.CapitalizeWord) == KeyboardFlags.CapitalizeWord;
                var capitalizedCharacterEnabled = (custom.Flags & KeyboardFlags.CapitalizeCharacter) == KeyboardFlags.CapitalizeCharacter;
                var capitalizedNone             = (custom.Flags & KeyboardFlags.None) == KeyboardFlags.None;

                var spellcheckEnabled  = (custom.Flags & KeyboardFlags.Spellcheck) == KeyboardFlags.Spellcheck;
                var suggestionsEnabled = (custom.Flags & KeyboardFlags.Suggestions) == KeyboardFlags.Suggestions;


                UITextAutocapitalizationType capSettings = UITextAutocapitalizationType.None;

                // Sentence being first ensures that the behavior of ALL is backwards compatible
                if (capitalizedSentenceEnabled)
                {
                    capSettings = UITextAutocapitalizationType.Sentences;
                }
                else if (capitalizedWordsEnabled)
                {
                    capSettings = UITextAutocapitalizationType.Words;
                }
                else if (capitalizedCharacterEnabled)
                {
                    capSettings = UITextAutocapitalizationType.AllCharacters;
                }
                else if (capitalizedNone)
                {
                    capSettings = UITextAutocapitalizationType.None;
                }

                textInput.AutocapitalizationType = capSettings;
                textInput.AutocorrectionType     = suggestionsEnabled ? UITextAutocorrectionType.Yes : UITextAutocorrectionType.No;
                textInput.SpellCheckingType      = spellcheckEnabled ? UITextSpellCheckingType.Yes : UITextSpellCheckingType.No;
            }
        }