예제 #1
0
        public static void UpdateTextColor(IMaterialTextField textField, IMaterialEntryRenderer element)
        {
            var uIColor = MaterialColors.GetEntryTextColor(element.TextColor);

            textField.ContainerScheme.ColorScheme.OnSurfaceColor = uIColor;
            textField.ContainerScheme.ColorScheme.PrimaryColor   = uIColor;
        }
예제 #2
0
        public static void ApplyTheme(IMaterialTextField textField, IMaterialEntryRenderer element)
        {
            if (element == null)
            {
                return;
            }

            if (textField.ActiveTextInputController == null)
            {
                return;
            }

            textField.ContainerScheme.ColorScheme = (SemanticColorScheme)CreateColorScheme();
            ApplyContainerTheme(textField);

            var textColor         = MaterialColors.GetEntryTextColor(element.TextColor);
            var placeHolderColors = MaterialColors.GetPlaceHolderColor(element.PlaceholderColor, element.TextColor);
            var underlineColors   = MaterialColors.GetUnderlineColor(element.PlaceholderColor);

            textField.TextInput.TextColor = textColor;
            textField.ActiveTextInputController.InlinePlaceholderColor         = placeHolderColors.InlineColor;
            textField.ActiveTextInputController.FloatingPlaceholderNormalColor = placeHolderColors.InlineColor;
            textField.ActiveTextInputController.FloatingPlaceholderActiveColor = placeHolderColors.FloatingColor;

            // BackgroundColor
            textField.ActiveTextInputController.BorderFillColor = MaterialColors.CreateEntryFilledInputBackgroundColor(element.BackgroundColor, element.TextColor);

            textField.ActiveTextInputController.ActiveColor = underlineColors.FocusedColor;
            textField.ActiveTextInputController.NormalColor = underlineColors.UnFocusedColor;
        }
예제 #3
0
        internal void UpdateTextColor(IMaterialEntryRenderer element)
        {
            var uIColor = MaterialColors.GetEntryTextColor(element.TextColor);

            _colorScheme.OnSurfaceColor = uIColor;
            _colorScheme.PrimaryColor   = uIColor;
        }
예제 #4
0
        static Color AdjustTextColor(IMaterialEntryRenderer element)
        {
            if (Forms.IsiOS14OrNewer)
            {
                // This is a workaround for an iOS/Material bug; https://github.com/xamarin/Microsoft.Maui.Controls/issues/12246
                // If we are on iOS 14, and we have multiple material text entry fields of the same color,
                // and any of them are password fields, setting them to the same TextColor value will cause the application
                // to hang when a password field loses focus.

                // So to work around this, we make an imperceptible adjustment to the alpha value of the color each time
                // we set it; that way, none of the text entry fields have _exactly_ the same color and we avoid the bug

                // Obviously this will start to become noticeable after the first 20 million or so text entry fields are displayed.
                // We apologize for the inconvenience.

                var elementTextColor = element.TextColor;
                AlphaAdjustment += 0.0000001;

                var adjustedAlpha = elementTextColor.IsDefault ? 1 - AlphaAdjustment : elementTextColor.A - AlphaAdjustment;
                if (adjustedAlpha < 0)
                {
                    // Below an alpha of 0.01 stuff on iOS doesn't show up in hit tests anyway, so it seems unlikely
                    // that the entry will get focus and cause the issue.
                    adjustedAlpha = 0;
                }

                return(new Color(elementTextColor.R, elementTextColor.G, elementTextColor.B, adjustedAlpha));
            }

            return(element.TextColor);
        }
예제 #5
0
        internal void ApplyTheme(IMaterialEntryRenderer element)
        {
            if (element == null)
            {
                return;
            }

            if (_activeTextinputController == null)
            {
                return;
            }

            FilledTextFieldColorThemer.ApplySemanticColorScheme(_colorScheme, (MTextInputControllerFilled)_activeTextinputController);

            var textColor         = MaterialColors.GetEntryTextColor(element.TextColor);
            var placeHolderColors = MaterialColors.GetPlaceHolderColor(element.PlaceholderColor, element.TextColor);
            var underlineColors   = MaterialColors.GetUnderlineColor(element.TextColor);

            TextColor = textColor;
            _activeTextinputController.InlinePlaceholderColor         = placeHolderColors.InlineColor;
            _activeTextinputController.FloatingPlaceholderNormalColor = placeHolderColors.InlineColor;
            _activeTextinputController.FloatingPlaceholderActiveColor = placeHolderColors.FloatingColor;

            // BackgroundColor
            _activeTextinputController.BorderFillColor = MaterialColors.CreateEntryFilledInputBackgroundColor(element.BackgroundColor, element.TextColor);

            _activeTextinputController.ActiveColor = underlineColors.FocusedColor;
            _activeTextinputController.NormalColor = underlineColors.UnFocusedColor;
        }
예제 #6
0
 public static void Init(IMaterialEntryRenderer element, IMaterialTextField textField, IFontElement fontElement)
 {
     textField.TextInput.ClearButtonMode = UITextFieldViewMode.Never;
     textField.ActiveTextInputController = new MTextInputControllerFilled(textField.TextInput);
     textField.TextInput.TextInsetsMode  = TextInputTextInsetsMode.IfContent;
     textField.TypographyScheme          = CreateTypographyScheme();
     textField.ColorScheme = (SemanticColorScheme)CreateColorScheme();
     ApplyTypographyScheme(textField, fontElement);
     ApplyTheme(textField, element);
 }
예제 #7
0
 public MaterialTextField(IMaterialEntryRenderer element, IFontElement fontElement)
 {
     VisualElement.VerifyVisualFlagEnabled();
     ClearButtonMode            = UITextFieldViewMode.Never;
     _activeTextinputController = new MTextInputControllerFilled(this);
     TextInsetsMode             = TextInputTextInsetsMode.IfContent;
     _typographyScheme          = CreateTypographyScheme();
     _colorScheme = (SemanticColorScheme)CreateColorScheme();
     ApplyTypographyScheme(fontElement);
     ApplyTheme(element);
 }
예제 #8
0
        public static void ApplyTheme(IMaterialTextField textField, IMaterialEntryRenderer element)
        {
            if (element == null)
            {
                return;
            }

            if (textField.ActiveTextInputController == null)
            {
                return;
            }

            textField.ContainerScheme.ColorScheme = (SemanticColorScheme)CreateColorScheme();
            ApplyContainerTheme(textField);

            var adjustedTextColor = AdjustTextColor(element);

            var textColor         = MaterialColors.GetEntryTextColor(adjustedTextColor);
            var placeHolderColors = MaterialColors.GetPlaceHolderColor(element.PlaceholderColor, adjustedTextColor);
            var underlineColors   = MaterialColors.GetUnderlineColor(element.PlaceholderColor);

            textField.TextInput.TextColor = textColor;

            var inputController = textField.ActiveTextInputController;

            inputController.InlinePlaceholderColor         = placeHolderColors.InlineColor;
            inputController.FloatingPlaceholderNormalColor = placeHolderColors.InlineColor;
            inputController.FloatingPlaceholderActiveColor = placeHolderColors.FloatingColor;
            inputController.DisabledColor = placeHolderColors.InlineColor;

            var brush = element.Background;

            if (Brush.IsNullOrEmpty(brush))
            {
                // BackgroundColor
                textField.ActiveTextInputController.BorderFillColor = MaterialColors.CreateEntryFilledInputBackgroundColor(element.BackgroundColor, adjustedTextColor);
            }
            else
            {
                // Background
                if (textField is UITextField || textField is MultilineTextField)
                {
                    var backgroundImage = ((UIView)textField).GetBackgroundImage(brush);
                    textField.BackgroundSize = backgroundImage?.Size;
                    var color = backgroundImage != null?UIColor.FromPatternImage(backgroundImage) : UIColor.Clear;

                    textField.ActiveTextInputController.BorderFillColor = color;
                }
            }
            textField.ActiveTextInputController.ActiveColor = underlineColors.FocusedColor;
            textField.ActiveTextInputController.NormalColor = underlineColors.UnFocusedColor;
        }
예제 #9
0
        public static void ApplyThemeIfNeeded(IMaterialTextField textField, IMaterialEntryRenderer element)
        {
            var bgBrush = element.Background;

            if (Brush.IsNullOrEmpty(bgBrush))
            {
                return;
            }

            UIImage backgroundImage = null;

            if (textField is UITextField || textField is MultilineTextField)
            {
                backgroundImage = ((UIView)textField).GetBackgroundImage(bgBrush);
            }

            if (textField.BackgroundSize != null && textField.BackgroundSize != backgroundImage?.Size)
            {
                ApplyTheme(textField, element);
            }
        }
예제 #10
0
        public static void UpdatePlaceholder(IMaterialTextField textField, IMaterialEntryRenderer element)
        {
            var placeholderText = element.Placeholder ?? String.Empty;

            textField.ActiveTextInputController.PlaceholderText = placeholderText;
            ApplyTheme(textField, element);

            var previous = textField.ActiveTextInputController.FloatingPlaceholderScale;

            if (String.IsNullOrWhiteSpace(placeholderText))
            {
                textField.ActiveTextInputController.FloatingPlaceholderScale = 0;
            }
            else
            {
                textField.ActiveTextInputController.FloatingPlaceholderScale = (float)TextInputControllerBase.FloatingPlaceholderScaleDefault;
            }

            if (previous != textField.ActiveTextInputController.FloatingPlaceholderScale && element is IVisualElementRenderer controller)
            {
                controller.Element?.InvalidateMeasureInternal(InvalidationTrigger.VerticalOptionsChanged);
            }
        }
예제 #11
0
 internal void UpdatePlaceholder(IMaterialEntryRenderer element) => MaterialTextManager.UpdatePlaceholder(this, element);
예제 #12
0
 internal void ApplyThemeIfNeeded(IMaterialEntryRenderer element) => MaterialTextManager.ApplyThemeIfNeeded(this, element);
예제 #13
0
 public MaterialTextField(IMaterialEntryRenderer element, IFontElement fontElement)
 {
     ContainerScheme = new ContainerScheme();
     MaterialTextManager.Init(element, this, fontElement);
 }
예제 #14
0
 public NoCaretMaterialTextField(IMaterialEntryRenderer element, IFontElement fontElement) : base(element, fontElement)
 {
     SpellCheckingType      = UITextSpellCheckingType.No;
     AutocorrectionType     = UITextAutocorrectionType.No;
     AutocapitalizationType = UITextAutocapitalizationType.None;
 }
예제 #15
0
 internal void UpdateTextColor(IMaterialEntryRenderer element) => MaterialTextManager.UpdateTextColor(this, element);
예제 #16
0
 public ReadOnlyMaterialTextField(IMaterialEntryRenderer element, IFontElement fontElement) : base(element, fontElement)
 {
     string[] actions = { "copy:", "select:", "selectAll:" };
     _enableActions = new HashSet <string>(actions);
 }
예제 #17
0
 public MaterialMultilineTextField(IMaterialEntryRenderer element, IFontElement fontElement) => MaterialTextManager.Init(element, this, fontElement);