new GalleryPageFactory(() => new CellForceUpdateSizeGalleryPage(), "Cell Force Update Size Gallery"),
new GalleryPageFactory(() => new AppearingGalleryPage(), "Appearing Gallery"),
new GalleryPageFactory(() => new EntryCoreGalleryPage(), "Entry Gallery"),
+ new GalleryPageFactory(() => new EntryCoreGalleryPage{ Visual = VisualMarker.Material }, "Entry Gallery (Material)"),
+ new GalleryPageFactory(() => new MaterialEntryGalleryPage(), "Entry Material Demos"),
new GalleryPageFactory(() => new NavBarTitleTestPage(), "Titles And Navbar Windows"),
new GalleryPageFactory(() => new PanGestureGalleryPage(), "Pan gesture Gallery"),
new GalleryPageFactory(() => new SwipeGestureGalleryPage(), "Swipe gesture Gallery"),
{
internal class EntryCoreGalleryPage : CoreGalleryPage<Entry>
{
+ public EntryCoreGalleryPage()
+ {
+ }
+
protected override bool SupportsTapGestureRecognizer
{
get { return false; }
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Xamarin.Forms.Controls.GalleryPages
+{
+ public class MaterialEntryGalleryPage : ContentPage
+ {
+ public MaterialEntryGalleryPage()
+ {
+ Visual = VisualMarker.Material;
+ Content =
+ new ScrollView()
+ {
+
+ Content = new StackLayout()
+ {
+ Children =
+ {
+ new Entry()
+ {
+ Text = "With Text",
+ Placeholder="Placeholder",
+ },
+ new Entry()
+ {
+ Placeholder = "Placeholder"
+ },
+ new Entry()
+ {
+ Placeholder = "Green Placeholder",
+ PlaceholderColor = Color.Green,
+ },
+ new Entry()
+ {
+ Placeholder = "Purple Placeholder",
+ PlaceholderColor = Color.Purple,
+ },
+ new Entry()
+ {
+ Text = "Green TextColor",
+ TextColor = Color.Green
+ },
+ new Entry()
+ {
+ Text = "Purple TextColor",
+ TextColor = Color.Purple
+ },
+ new Entry()
+ {
+ Text = "With Text larger font",
+ Placeholder="Placeholder",
+ FontSize = 24
+ },
+ new Entry()
+ {
+ Text = "Yellow BackgroundColor",
+ BackgroundColor = Color.Yellow
+ },
+ new Entry()
+ {
+ Text = "Cyan BackgroundColor",
+ BackgroundColor = Color.Cyan
+ },
+ }
+ }
+
+ };
+ }
+ }
+}
+++ /dev/null
-using MaterialComponents;
-using UIKit;
-
-namespace Xamarin.Forms.Platform.iOS.Material
-{
- // colors from material-components-android
- // https://github.com/material-components/material-components-android/blob/3637c23078afc909e42833fd1c5fd47bb3271b5f/lib/java/com/google/android/material/color/res/values/colors.xml
- internal static class MaterialColors
- {
- public static class Light
- {
- // the colors for "branding"
- // - we selected the "black" theme from the default DarkActionBar theme
- public static readonly UIColor PrimaryColor = UIColor.FromRGB(33, 33, 33);
- public static readonly UIColor PrimaryColorVariant = UIColor.Black;
- public static readonly UIColor OnPrimaryColor = UIColor.White;
- public static readonly UIColor SecondaryColor = UIColor.FromRGB(33, 33, 33);
- public static readonly UIColor OnSecondaryColor = UIColor.White;
-
- // the colors for "UI"
- public static readonly UIColor BackgroundColor = UIColor.White;
- public static readonly UIColor OnBackgroundColor = UIColor.Black;
- public static readonly UIColor SurfaceColor = UIColor.White;
- public static readonly UIColor OnSurfaceColor = UIColor.Black;
- public static readonly UIColor ErrorColor = UIColor.FromRGB(176, 0, 32);
- public static readonly UIColor OnErrorColor = UIColor.White;
-
- public static SemanticColorScheme CreateColorScheme()
- {
- return new SemanticColorScheme
- {
- PrimaryColor = PrimaryColor,
- PrimaryColorVariant = PrimaryColorVariant,
- SecondaryColor = SecondaryColor,
- OnPrimaryColor = OnPrimaryColor,
- OnSecondaryColor = OnSecondaryColor,
-
- BackgroundColor = BackgroundColor,
- ErrorColor = ErrorColor,
- SurfaceColor = SurfaceColor,
- OnBackgroundColor = OnBackgroundColor,
- OnSurfaceColor = OnSurfaceColor,
- };
- }
- }
-
- public static class Dark
- {
- // the colors for "branding"
- // - we selected the "black" theme from the default DarkActionBar theme
- public static readonly UIColor PrimaryColor = UIColor.FromRGB(33, 33, 33);
- public static readonly UIColor PrimaryColorVariant = UIColor.Black;
- public static readonly UIColor OnPrimaryColor = UIColor.White;
- public static readonly UIColor SecondaryColor = UIColor.FromRGB(33, 33, 33);
- public static readonly UIColor OnSecondaryColor = UIColor.White;
-
- // the colors for "UI"
- public static readonly UIColor BackgroundColor = UIColor.FromRGB(20, 20, 20);
- public static readonly UIColor OnBackgroundColor = UIColor.White;
- public static readonly UIColor SurfaceColor = UIColor.FromRGB(40, 40, 40);
- public static readonly UIColor OnSurfaceColor = UIColor.White;
- public static readonly UIColor ErrorColor = UIColor.FromRGB(194, 108, 122);
- public static readonly UIColor OnErrorColor = UIColor.White;
-
- public static SemanticColorScheme CreateColorScheme()
- {
- return new SemanticColorScheme
- {
- PrimaryColor = PrimaryColor,
- PrimaryColorVariant = PrimaryColorVariant,
- SecondaryColor = SecondaryColor,
- OnPrimaryColor = OnPrimaryColor,
- OnSecondaryColor = OnSecondaryColor,
-
- BackgroundColor = BackgroundColor,
- ErrorColor = ErrorColor,
- SurfaceColor = SurfaceColor,
- OnBackgroundColor = OnBackgroundColor,
- OnSurfaceColor = OnSurfaceColor,
- };
- }
- }
- }
-}
SemanticColorScheme _colorScheme;
TypographyScheme _typographyScheme;
- // values based on
- // https://github.com/material-components/material-components-ios/blob/develop/components/TextFields/src/ColorThemer/MDCFilledTextFieldColorThemer.m
- const float kFilledTextFieldActiveAlpha = 0.87f;
- const float kFilledTextFieldOnSurfaceAlpha = 0.6f;
- const float kFilledTextFieldDisabledAlpha = 0.38f;
- const float kFilledTextFieldSurfaceOverlayAlpha = 0.04f;
- const float kFilledTextFieldIndicatorLineAlpha = 0.42f;
- const float kFilledTextFieldIconAlpha = 0.54f;
-
- // the idea of this value is that I want Active to be the exact color the user specified
- // and then all the other colors decrease according to the Material theme setup
- static float kFilledPlaceHolderOffset = 1f - kFilledTextFieldActiveAlpha;
public MaterialEntryRenderer()
{
_typographyScheme = CreateTypographyScheme();
}
- public override void LayoutSubviews()
- {
- base.LayoutSubviews();
- }
-
-
public override CGSize SizeThatFits(CGSize size)
{
var result = base.SizeThatFits(size);
Control = field;
field.ClearButtonMode = UITextFieldViewMode.Never;
_activeTextinputController = new MTextInputControllerFilled(field);
-
+ field.TextInsetsMode = TextInputTextInsetsMode.IfContent;
ApplyTypographyScheme();
ApplyTheme();
protected virtual IColorScheming CreateColorScheme()
{
var returnValue = MaterialColors.Light.CreateColorScheme();
+
return returnValue;
}
ApplyTheme();
}
- protected internal override void UpdateColor()
+ void ApplyTypographyScheme()
{
- var textColor = Element.TextColor;
- UIColor uIColor;
- if (Element.TextColor == Color.Default)
- uIColor = MaterialColors.Light.PrimaryColor;
- else
- uIColor = textColor.ToUIColor();
+ if (Control == null)
+ return;
- _colorScheme.OnSurfaceColor = uIColor;
- _colorScheme.PrimaryColor = uIColor;
+ _typographyScheme.Subtitle1 = Control.Font;
+ TextFieldTypographyThemer.ApplyTypographyScheme(_typographyScheme, Control);
+ TextFieldTypographyThemer.ApplyTypographyScheme(_typographyScheme, _activeTextinputController);
+ }
- ApplyTheme();
+ protected internal override void UpdateFont()
+ {
+ base.UpdateFont();
+ ApplyTypographyScheme();
}
- void ApplyTypographyScheme()
+
+ protected internal override void UpdateColor()
{
+ var uIColor = MaterialColors.GetEntryTextColor(Element.TextColor);
- TextFieldTypographyThemer.ApplyTypographyScheme(_typographyScheme, Control);
- TextFieldTypographyThemer.ApplyTypographyScheme(_typographyScheme, _activeTextinputController);
+ _colorScheme.OnSurfaceColor = uIColor;
+ _colorScheme.PrimaryColor = uIColor;
+
+ ApplyTheme();
}
return;
FilledTextFieldColorThemer.ApplySemanticColorScheme(_colorScheme, (MTextInputControllerFilled)_activeTextinputController);
+
OverrideThemeColors();
}
protected virtual void OverrideThemeColors()
{
- // Placeholder
- if(Element.PlaceholderColor != Color.Default)
- {
- var placeholderColor = Element.PlaceholderColor.ToUIColor();
- _activeTextinputController.InlinePlaceholderColor = placeholderColor.ColorWithAlpha(kFilledTextFieldOnSurfaceAlpha + kFilledPlaceHolderOffset);
- _activeTextinputController.FloatingPlaceholderNormalColor = placeholderColor.ColorWithAlpha(kFilledTextFieldOnSurfaceAlpha + kFilledPlaceHolderOffset);
- _activeTextinputController.FloatingPlaceholderActiveColor = placeholderColor.ColorWithAlpha(kFilledTextFieldActiveAlpha + kFilledPlaceHolderOffset);
- }
-
- // Backgroundcolor
- if(Element.BackgroundColor != Color.Default)
- _activeTextinputController.BorderFillColor = Element.BackgroundColor.ToUIColor();
+ var textColor = MaterialColors.GetEntryTextColor(Element.TextColor);
+ var placeHolderColors = MaterialColors.GetPlaceHolderColor(Element.PlaceholderColor, Element.TextColor);
+ var underlineColors = MaterialColors.GetUnderlineColor(Element.TextColor);
+
+ Control.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;
}
protected internal override void UpdatePlaceholder()
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<IOSDebuggerPort>25933</IOSDebuggerPort>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
<DeviceSpecificBuild>false</DeviceSpecificBuild>
- <MtouchVerbosity></MtouchVerbosity>
- <MtouchLink></MtouchLink>
+ <MtouchVerbosity>
+ </MtouchVerbosity>
+ <MtouchLink>
+ </MtouchLink>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
- <DefineConstants></DefineConstants>
+ <DefineConstants>
+ </DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
<MtouchLink>SdkOnly</MtouchLink>
<MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
- <MtouchVerbosity></MtouchVerbosity>
+ <MtouchVerbosity>
+ </MtouchVerbosity>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<PackageReference Include="Xamarin.iOS.MaterialComponents" Version="72.2.0.1" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="..\Xamarin.Forms.Platform.Android\Material\MaterialColors.cs">
+ <Link>MaterialColors.cs</Link>
+ </Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="MaterialActivityIndicatorRenderer.cs" />
<Compile Include="MaterialButtonRenderer.cs" />
- <Compile Include="MaterialColors.cs" />
<Compile Include="MaterialEntryRenderer.cs" />
<Compile Include="MaterialFrameRenderer.cs" />
<Compile Include="MaterialProgressBarRenderer.cs" />
-using Android.Content.Res;
+// once we implement material configurations on core elements this can all be moved up to that
+// for now just leaving this as an internal class to make matching colors between two platforms easier
+
+#if __ANDROID__
+using Android.Content.Res;
using AColor = Android.Graphics.Color;
+#else
+using MaterialComponents;
+using AColor = UIKit.UIColor;
+#endif
+#if __ANDROID__
namespace Xamarin.Forms.Platform.Android.Material
+#else
+namespace Xamarin.Forms.Platform.iOS.Material
+#endif
{
// Colors from material-components-android
// https://github.com/material-components/material-components-android/blob/3637c23078afc909e42833fd1c5fd47bb3271b5f/lib/java/com/google/android/material/color/res/values/colors.xml
internal static class MaterialColors
{
+ // values based on
+ // copying to match iOS
+ // TODO generalize into xplat classes
+ // https://github.com/material-components/material-components-ios/blob/develop/components/TextFields/src/ColorThemer/MDCFilledTextFieldColorThemer.m
+ const float kFilledTextFieldActiveAlpha = 0.87f;
+ const float kFilledTextFieldOnSurfaceAlpha = 0.6f;
+ const float kFilledTextFieldDisabledAlpha = 0.38f;
+ const float kFilledTextFieldSurfaceOverlayAlpha = 0.04f;
+ const float kFilledTextFieldIndicatorLineAlpha = 0.42f;
+ const float kFilledTextFieldIconAlpha = 0.54f;
+
+ // the idea of this value is that I want Active to be the exact color the user specified
+ // and then all the other colors decrease according to the Material theme setup
+ static float kFilledPlaceHolderOffset = 1f - kFilledTextFieldActiveAlpha;
+
+ // State list from material-components-android
+ // https://github.com/material-components/material-components-android/blob/71694616056012fe1162adb9144be903d1e510d5/lib/java/com/google/android/material/textfield/res/values/colors.xml#L28
+ public static AColor CreateEntryFilledInputBackgroundColor(Color backgroundColor, Color textColor)
+ {
+ var platformTextColor = GetEntryTextColor(textColor);
+
+ if (backgroundColor == Color.Default)
+ {
+ if (textColor != Color.Default)
+ return WithAlpha(platformTextColor, 0.0392f);
+ else
+ return WithAlpha(MaterialColors.Light.PrimaryColorVariant, 0.0392f);
+ }
+
+ return ToPlatformColor(backgroundColor);
+ }
+
+ public static (AColor InlineColor, AColor FloatingColor) GetPlaceHolderColor(Color placeholderColor, Color textColor)
+ {
+ AColor color;
+
+ if (placeholderColor == Color.Default)
+ {
+ if (textColor == Color.Default)
+ color = MaterialColors.Light.OnSurfaceColor;
+ else
+ color = ToPlatformColor(textColor);
+ }
+ else
+ color = ToPlatformColor(placeholderColor);
+
+ var inlineColor = WithAlpha(color, kFilledTextFieldOnSurfaceAlpha + kFilledPlaceHolderOffset);
+ var floatingColor = WithAlpha(color, kFilledTextFieldActiveAlpha + kFilledPlaceHolderOffset);
+
+ return (inlineColor, floatingColor);
+ }
+
+ public static (AColor FocusedColor, AColor UnFocusedColor) GetUnderlineColor(Color textColor)
+ {
+ AColor color = GetEntryTextColor(textColor);
+ return (color, WithAlpha(color, kFilledTextFieldIndicatorLineAlpha));
+ }
+
+ public static AColor GetEntryTextColor(Color textColor)
+ {
+ return textColor != Color.Default ? ToPlatformColor(textColor) : MaterialColors.Light.PrimaryColor;
+ }
+
+#if __ANDROID__
public static readonly int[][] ButtonStates =
{
new int[] { global::Android.Resource.Attribute.StateEnabled },
};
public static readonly int[][] EntryUnderlineStates =
- {
+{
new []{ global::Android.Resource.Attribute.StateFocused },
new []{ -global::Android.Resource.Attribute.StateFocused },
};
return new ColorStateList(ButtonStates, colors);
}
- // State list from material-components-android
- // https://github.com/material-components/material-components-android/blob/71694616056012fe1162adb9144be903d1e510d5/lib/java/com/google/android/material/textfield/res/values/colors.xml#L28
- public static int CreateEntryFilledInputBackgroundColor(AColor primary)
- {
- return primary.WithAlpha(0.0392);
- }
-
- public static ColorStateList CreateEntryFilledPlaceholderColors(AColor color)
+ public static ColorStateList CreateEntryFilledPlaceholderColors(AColor inlineColor, AColor floatingColor)
{
int[][] States =
{
new int[0] { }
};
- var colors = new int[] { color, color };
+ var colors = new int[] { floatingColor, inlineColor };
return new ColorStateList(States, colors);
}
internal static AColor WithAlpha(this AColor color, double alpha) =>
new AColor(color.R, color.G, color.B, (byte)(alpha * 255));
+#endif
+
public static class Light
{
// the Colors for "branding"
// - we selected the "black" theme from the default DarkActionBar theme
- public static readonly AColor PrimaryColor = AColor.Rgb(33, 33, 33);
+ public static readonly AColor PrimaryColor = FromRgb(33, 33, 33);
public static readonly AColor PrimaryColorVariant = AColor.Black;
public static readonly AColor OnPrimaryColor = AColor.White;
- public static readonly AColor SecondaryColor = AColor.Rgb(33, 33, 33);
+ public static readonly AColor SecondaryColor = FromRgb(33, 33, 33);
public static readonly AColor OnSecondaryColor = AColor.White;
// the Colors for "UI"
public static readonly AColor OnBackgroundColor = AColor.Black;
public static readonly AColor SurfaceColor = AColor.White;
public static readonly AColor OnSurfaceColor = AColor.Black;
- public static readonly AColor ErrorColor = AColor.Rgb(176, 0, 32);
+ public static readonly AColor ErrorColor = FromRgb(176, 0, 32);
public static readonly AColor OnErrorColor = AColor.White;
+
+#if __IOS__
+ public static SemanticColorScheme CreateColorScheme()
+ {
+ return new SemanticColorScheme
+ {
+ PrimaryColor = PrimaryColor,
+ PrimaryColorVariant = PrimaryColorVariant,
+ SecondaryColor = SecondaryColor,
+ OnPrimaryColor = OnPrimaryColor,
+ OnSecondaryColor = OnSecondaryColor,
+
+ BackgroundColor = BackgroundColor,
+ ErrorColor = ErrorColor,
+ SurfaceColor = SurfaceColor,
+ OnBackgroundColor = OnBackgroundColor,
+ OnSurfaceColor = OnSurfaceColor,
+ };
+ }
+#endif
+
}
public static class Dark
{
// the Colors for "branding"
// - we selected the "black" theme from the default DarkActionBar theme
- public static readonly AColor PrimaryColor = AColor.Rgb(33, 33, 33);
+ public static readonly AColor PrimaryColor = FromRgb(33, 33, 33);
public static readonly AColor PrimaryColorVariant = AColor.Black;
public static readonly AColor OnPrimaryColor = AColor.White;
- public static readonly AColor SecondaryColor = AColor.Rgb(33, 33, 33);
+ public static readonly AColor SecondaryColor = FromRgb(33, 33, 33);
public static readonly AColor OnSecondaryColor = AColor.White;
// the Colors for "UI"
- public static readonly AColor BackgroundColor = AColor.Rgb(20, 20, 20);
+ public static readonly AColor BackgroundColor = FromRgb(20, 20, 20);
public static readonly AColor OnBackgroundColor = AColor.White;
- public static readonly AColor SurfaceColor = AColor.Rgb(40, 40, 40);
+ public static readonly AColor SurfaceColor = FromRgb(40, 40, 40);
public static readonly AColor OnSurfaceColor = AColor.White;
- public static readonly AColor ErrorColor = AColor.Rgb(194, 108, 122);
+ public static readonly AColor ErrorColor = FromRgb(194, 108, 122);
public static readonly AColor OnErrorColor = AColor.White;
+
+#if __IOS__
+ public static SemanticColorScheme CreateColorScheme()
+ {
+ return new SemanticColorScheme
+ {
+ PrimaryColor = PrimaryColor,
+ PrimaryColorVariant = PrimaryColorVariant,
+ SecondaryColor = SecondaryColor,
+ OnPrimaryColor = OnPrimaryColor,
+ OnSecondaryColor = OnSecondaryColor,
+
+ BackgroundColor = BackgroundColor,
+ ErrorColor = ErrorColor,
+ SurfaceColor = SurfaceColor,
+ OnBackgroundColor = OnBackgroundColor,
+ OnSurfaceColor = OnSurfaceColor,
+ };
+ }
+#endif
+
+ }
+
+
+ static AColor ToPlatformColor(Color color)
+ {
+#if __ANDROID__
+ return color.ToAndroid();
+#else
+ return color.ToUIColor();
+#endif
+ }
+
+
+
+ static AColor WithAlpha(AColor color, float alpha)
+ {
+#if __ANDROID__
+ return color.WithAlpha(alpha);
+#else
+ return color.ColorWithAlpha(alpha);
+#endif
+ }
+
+
+ static AColor FromRgb(int red, int green, int blue)
+ {
+#if __ANDROID__
+ return AColor.Rgb(red, green, blue);
+#else
+ return AColor.FromRGB(red, green, blue);
+
+#endif
}
}
}
#if __ANDROID_28__
+using System.Threading.Tasks;
using Android.Content;
using Android.Content.Res;
using Android.OS;
{
public sealed class MaterialEntryRenderer : EntryRendererBase<MaterialFormsTextInputLayout>
{
- // values based on
- // copying to match iOS
- // TODO generalize into xplat classes
- // https://github.com/material-components/material-components-ios/blob/develop/components/TextFields/src/ColorThemer/MDCFilledTextFieldColorThemer.m
- const float kFilledTextFieldActiveAlpha = 0.87f;
- const float kFilledTextFieldOnSurfaceAlpha = 0.6f;
- const float kFilledTextFieldDisabledAlpha = 0.38f;
- const float kFilledTextFieldSurfaceOverlayAlpha = 0.04f;
- const float kFilledTextFieldIndicatorLineAlpha = 0.42f;
- const float kFilledTextFieldIconAlpha = 0.54f;
-
- // the idea of this value is that I want Active to be the exact color the user specified
- // and then all the other colors decrease according to the Material theme setup
- static float kFilledPlaceHolderOffset = 1f - kFilledTextFieldActiveAlpha;
-
-
- AColor _previousTextColor = AColor.Transparent;
-
bool _disposed;
private MaterialFormsEditText _textInputEditText;
private MaterialFormsTextInputLayout _textInputLayout;
Device.BeginInvokeOnMainThread(() => UpdatePlaceholderColor());
}
- AColor TextColor => Element.TextColor != Color.Default ? Element.TextColor.ToAndroid() : MaterialColors.Light.PrimaryColor;
-
protected internal override void UpdateColor() => ApplyTheme();
protected override void UpdateBackgroundColor()
if (_textInputLayout == null)
return;
- if (Element.BackgroundColor == Color.Default)
- {
- if (Element.TextColor != Color.Default)
- _textInputLayout.BoxBackgroundColor = MaterialColors.CreateEntryFilledInputBackgroundColor(TextColor);
- else
- _textInputLayout.BoxBackgroundColor = MaterialColors.CreateEntryFilledInputBackgroundColor(MaterialColors.Light.PrimaryColorVariant);
- }
- else
- {
- _textInputLayout.BoxBackgroundColor = Element.BackgroundColor.ToAndroid();
- }
+ _textInputLayout.BoxBackgroundColor = MaterialColors.CreateEntryFilledInputBackgroundColor(Element.BackgroundColor, Element.TextColor);
}
protected internal override void UpdatePlaceHolderText()
return;
// set text color
- var textColor = TextColor;
+ var textColor = MaterialColors.GetEntryTextColor(Element.TextColor);
UpdateTextColor(Color.FromUint((uint)textColor.ToArgb()));
- var colors = MaterialColors.CreateEntryUnderlineColors(textColor, textColor.WithAlpha(kFilledTextFieldOnSurfaceAlpha));
- // Ensure that we SetBackgroundTintList when focused to override the themes accent color which gets
- // applied to the underline
- if (_previousTextColor != textColor)
- {
- if(HasFocus)
- _previousTextColor = textColor;
+ var placeHolderColors = MaterialColors.GetPlaceHolderColor(Element.PlaceholderColor, Element.TextColor);
+ var underlineColors = MaterialColors.GetUnderlineColor(Element.TextColor);
- ViewCompat.SetBackgroundTintList(_textInputEditText, colors);
- }
+ var colors = MaterialColors.CreateEntryUnderlineColors(underlineColors.FocusedColor, underlineColors.UnFocusedColor);
- // set placeholder color
- AColor placeholderColor;
- if (Element.PlaceholderColor == Color.Default)
- if (Element.TextColor == Color.Default)
- placeholderColor = MaterialColors.Light.OnSurfaceColor;
- else
- placeholderColor = textColor;
- else
- placeholderColor = Element.PlaceholderColor.ToAndroid();
-
- if (!HasFocus)
- placeholderColor = placeholderColor.WithAlpha(kFilledTextFieldOnSurfaceAlpha + kFilledPlaceHolderOffset);
+ ViewCompat.SetBackgroundTintList(_textInputEditText, colors);
- _textInputLayout.DefaultHintTextColor = MaterialColors.CreateEntryFilledPlaceholderColors(placeholderColor);
+
+ if (HasFocus || !string.IsNullOrWhiteSpace(_textInputEditText.Text))
+ _textInputLayout.DefaultHintTextColor = MaterialColors.CreateEntryFilledPlaceholderColors(placeHolderColors.FloatingColor, placeHolderColors.FloatingColor);
+ else
+ _textInputLayout.DefaultHintTextColor = MaterialColors.CreateEntryFilledPlaceholderColors(placeHolderColors.InlineColor, placeHolderColors.FloatingColor);
}
protected internal override void UpdateFont()
// https://github.com/material-components/material-components-android/issues/120
// https://stackoverflow.com/questions/50487871/how-to-make-the-hint-text-of-textinputlayout-vertically-center
- static Thickness _centeredText = new Thickness(12, 8, 12, 27);
- static Thickness _alignedWithUnderlineText = new Thickness(12, 20, 12, 16);
+ static Thickness _centeredText = new Thickness(16, 8, 12, 27);
+ static Thickness _alignedWithUnderlineText = new Thickness(16, 20, 12, 16);
public MaterialFormsEditText(Context context) : base(context)
{
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox">
+ style="@style/XamarinFormsMaterialEntryFilled">
<xamarin.forms.platform.android.material.MaterialFormsEditText
android:id="@+id/materialformsedittext"
+ android:layout_marginBottom="-7dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</xamarin.forms.platform.android.material.MaterialFormsTextInputLayout>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<xamarin.forms.platform.android.material.MaterialFormsTextInputLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
- <xamarin.forms.platform.android.material.MaterialFormsEditText
- android:id="@+id/materialformsedittext"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
-</xamarin.forms.platform.android.material.MaterialFormsTextInputLayout>
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="XamarinFormsMaterialTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
+ <item name="materialButtonStyle">@style/XamarinFormsMaterialButton</item>
</style>
<style name="XamarinFormsMaterialProgressBarHorizontal" parent="Widget.AppCompat.ProgressBar.Horizontal">
</style>
<style name="XamarinFormsMaterialProgressBarCircular" parent="Widget.AppCompat.ProgressBar">
</style>
- <style name="XamarinFormsMaterialTextInputLayoutFilledBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
+ <style name="XamarinFormsMaterialButton" parent="Widget.MaterialComponents.Button">
+ <item name="android:insetTop">0dp</item>
+ <item name="android:insetBottom">0dp</item>
+ <item name="android:minHeight">36dp</item>
+ <item name="android:paddingTop">8dp</item>
+ <item name="android:paddingBottom">8dp</item>
</style>
-</resources>
+ <style name="XamarinFormsMaterialEntryFilled" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
+ <item name="boxCollapsedPaddingTop">8dp</item>
+ </style>
+</resources>
\ No newline at end of file
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
- <ItemGroup Condition=" '$(TargetFrameworkVersion)' == 'v9.0' ">
- <AndroidResource Include="Resources\Layout\TextInputLayoutOutlinedBox.axml">
- <SubType>Designer</SubType>
- </AndroidResource>
- </ItemGroup>
<ItemGroup />
<Target Name="BeforeBuild" Condition=" '$(CreateAllAndroidTargets)' == 'true' ">
<!-- create 8.1 binaries-->
_cursorPositionChangePending = Element.IsSet(Entry.CursorPositionProperty);
_selectionLengthChangePending = Element.IsSet(Entry.SelectionLengthProperty);
+ // Font needs to be set before Text and Placeholder so that they layout correctly when set
+ UpdateFont();
UpdatePlaceholder();
UpdatePassword();
UpdateText();
UpdateColor();
- UpdateFont();
UpdateKeyboard();
UpdateAlignment();
UpdateAdjustsFontSizeToFitWidth();
Control.AdjustsFontSizeToFitWidth = Element.OnThisPlatform().AdjustsFontSizeToFitWidth();
}
- void UpdateFont()
+ protected internal virtual void UpdateFont()
{
if (initialSize == CGSize.Empty)
{
.nuspec\Xamarin.Forms.props = .nuspec\Xamarin.Forms.props
.nuspec\Xamarin.Forms.targets = .nuspec\Xamarin.Forms.targets
.nuspec\Xamarin.Forms.Visual.Material.nuspec = .nuspec\Xamarin.Forms.Visual.Material.nuspec
+ .nuspec\Xamarin.Forms.Visual.Material.targets = .nuspec\Xamarin.Forms.Visual.Material.targets
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Forms.Core", "Xamarin.Forms.Core\Xamarin.Forms.Core.csproj", "{57B8B73D-C3B5-4C42-869E-7B2F17D354AC}"