Exemple #1
0
        public static void UpdateCancelButton(this UISearchBar uiSearchBar, ISearchBar searchBar,
                                              UIColor?cancelButtonTextColorDefaultNormal, UIColor?cancelButtonTextColorDefaultHighlighted, UIColor?cancelButtonTextColorDefaultDisabled)
        {
            uiSearchBar.ShowsCancelButton = !string.IsNullOrEmpty(uiSearchBar.Text);

            // We can't cache the cancel button reference because iOS drops it when it's not displayed
            // and creates a brand new one when necessary, so we have to look for it each time
            var cancelButton = uiSearchBar.FindDescendantView <UIButton>();

            if (cancelButton == null)
            {
                return;
            }

            if (searchBar.CancelButtonColor == null)
            {
                cancelButton.SetTitleColor(cancelButtonTextColorDefaultNormal, UIControlState.Normal);
                cancelButton.SetTitleColor(cancelButtonTextColorDefaultHighlighted, UIControlState.Highlighted);
                cancelButton.SetTitleColor(cancelButtonTextColorDefaultDisabled, UIControlState.Disabled);
            }
            else
            {
                cancelButton.SetTitleColor(searchBar.CancelButtonColor.ToNative(), UIControlState.Normal);
                cancelButton.SetTitleColor(searchBar.CancelButtonColor.ToNative(), UIControlState.Highlighted);
                cancelButton.SetTitleColor(searchBar.CancelButtonColor.ToNative(), UIControlState.Disabled);
            }
        }
Exemple #2
0
        public static void UpdateFont(this UISearchBar uiSearchBar, ITextStyle textStyle, IFontManager fontManager, UITextField?textField)
        {
            textField ??= uiSearchBar.FindDescendantView <UITextField>();
            if (textField == null)
            {
                return;
            }

            textField.UpdateFont(textStyle, fontManager);
        }
Exemple #3
0
        public static void UpdateVerticalTextAlignment(this UISearchBar uiSearchBar, ISearchBar searchBar, UITextField?textField)
        {
            textField ??= uiSearchBar.FindDescendantView <UITextField>();

            if (textField == null)
            {
                return;
            }

            textField.VerticalAlignment = searchBar.VerticalTextAlignment.ToPlatformVertical();
        }
        void GetDefaultSearchBarColors(UISearchBar searchBar)
        {
            _defaultTintColor = searchBar.BarTintColor;

            var cancelButton = searchBar.FindDescendantView <UIButton>();

            if (cancelButton != null)
            {
                _cancelButtonTextColorDefaultNormal      = cancelButton.TitleColor(UIControlState.Normal);
                _cancelButtonTextColorDefaultHighlighted = cancelButton.TitleColor(UIControlState.Highlighted);
                _cancelButtonTextColorDefaultDisabled    = cancelButton.TitleColor(UIControlState.Disabled);
            }
        }
        void SetupDefaults(UISearchBar nativeView)
        {
            _defaultTextColor = QueryEditor?.TextColor;

            var cancelButton = nativeView.FindDescendantView <UIButton>();

            if (cancelButton != null)
            {
                _cancelButtonTextColorDefaultNormal      = cancelButton.TitleColor(UIControlState.Normal);
                _cancelButtonTextColorDefaultHighlighted = cancelButton.TitleColor(UIControlState.Highlighted);
                _cancelButtonTextColorDefaultDisabled    = cancelButton.TitleColor(UIControlState.Disabled);
            }
        }
Exemple #6
0
        public static void UpdateFont(this UISearchBar uiSearchBar, ISearchBar searchBar, IFontManager fontManager, UITextField?textField)
        {
            textField ??= uiSearchBar.FindDescendantView <UITextField>();

            if (textField == null)
            {
                return;
            }

            var uiFont = fontManager.GetFont(searchBar.Font);

            textField.Font = uiFont;
        }
Exemple #7
0
        public static void UpdateHorizontalTextAlignment(this UISearchBar uiSearchBar, ISearchBar searchBar, UITextField?textField)
        {
            textField ??= uiSearchBar.FindDescendantView <UITextField>();

            if (textField == null)
            {
                return;
            }

            // We don't have a FlowDirection yet, so there's nothing to pass in here.
            // TODO: Update this when FlowDirection is available
            // (or update the extension to take an ILabel instead of an alignment and work it out from there)
            textField.TextAlignment = searchBar.HorizontalTextAlignment.ToNative(true);
        }
Exemple #8
0
        public static void UpdateIsTextPredictionEnabled(this UISearchBar uiSearchBar, ISearchBar searchBar, UITextField?textField)
        {
            textField ??= uiSearchBar.FindDescendantView <UITextField>();

            if (textField == null)
            {
                return;
            }

            if (searchBar.IsTextPredictionEnabled)
            {
                textField.AutocorrectionType = UITextAutocorrectionType.Yes;
            }
            else
            {
                textField.AutocorrectionType = UITextAutocorrectionType.No;
            }
        }
        public SearchHandlerAppearanceTracker(UISearchBar searchBar, SearchHandler searchHandler)
        {
            _searchHandler = searchHandler;
            _searchHandler.PropertyChanged      += SearchHandlerPropertyChanged;
            _searchHandler.FocusChangeRequested += SearchHandlerFocusChangeRequested;
            _uiSearchBar = searchBar;
            _uiSearchBar.OnEditingStarted += OnEditingStarted;
            _uiSearchBar.OnEditingStopped += OnEditingEnded;
            _uiSearchBar.TextChanged      += OnTextChanged;
            _uiSearchBar.ShowsCancelButton = true;
            GetDefaultSearchBarColors(_uiSearchBar);
            var uiTextField = searchBar.FindDescendantView <UITextField>();

            UpdateSearchBarColors();
            UpdateSearchBarTextAlignment(uiTextField);
            UpdateFont(uiTextField);
            UpdateKeyboard();
        }
Exemple #10
0
        public static void UpdatePlaceholder(this UISearchBar uiSearchBar, ISearchBar searchBar, UITextField?textField)
        {
            textField ??= uiSearchBar.FindDescendantView <UITextField>();

            if (textField == null)
            {
                return;
            }

            var placeholder      = searchBar.Placeholder ?? string.Empty;
            var placeholderColor = searchBar.PlaceholderColor;
            var foregroundColor  = placeholderColor ?? ColorExtensions.PlaceholderColor.ToColor();

            textField.AttributedPlaceholder = foregroundColor == null
                                ? new NSAttributedString(placeholder)
                                : new NSAttributedString(str: placeholder, foregroundColor: foregroundColor.ToPlatform());

            textField.AttributedPlaceholder.WithCharacterSpacing(searchBar.CharacterSpacing);
        }
        public void UpdateSearchBarColors()
        {
            var cancelButton = _uiSearchBar.FindDescendantView <UIButton>();
            var uiTextField  = _uiSearchBar.FindDescendantView <UITextField>();

            UpdateTextColor(uiTextField);
            UpdateSearchBarPlaceholder(uiTextField);
            UpdateCancelButtonColor(cancelButton);
            UpdateSearchBarBackgroundColor(uiTextField);
        }