Material Entry v1 (#5056)
authorShane Neuville <shane94@hotmail.com>
Wed, 30 Jan 2019 21:44:34 +0000 (14:44 -0700)
committerGitHub <noreply@github.com>
Wed, 30 Jan 2019 21:44:34 +0000 (14:44 -0700)
* Fixing entry style positioning to match ios/android

* centralize colors more

* [Android] underline alpha

* fix underline colors

* font and height tweaks

* Core Gallery updates

* add materials target to SLN

* implement suggestions

15 files changed:
Xamarin.Forms.Controls/CoreGallery.cs
Xamarin.Forms.Controls/CoreGalleryPages/EntryCoreGalleryPage.cs
Xamarin.Forms.Controls/GalleryPages/MaterialEntryGalleryPage.cs [new file with mode: 0644]
Xamarin.Forms.Material.iOS/MaterialColors.cs [deleted file]
Xamarin.Forms.Material.iOS/MaterialEntryRenderer.cs
Xamarin.Forms.Material.iOS/Xamarin.Forms.Material.iOS.csproj
Xamarin.Forms.Platform.Android/Material/MaterialColors.cs
Xamarin.Forms.Platform.Android/Material/MaterialEntryRenderer.cs
Xamarin.Forms.Platform.Android/Material/MaterialFormsEditText.cs
Xamarin.Forms.Platform.Android/Resources/Layout/TextInputLayoutFilledBox.axml
Xamarin.Forms.Platform.Android/Resources/Layout/TextInputLayoutOutlinedBox.axml [deleted file]
Xamarin.Forms.Platform.Android/Resources/values/styles.xml
Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs
Xamarin.Forms.sln

index d4474fb..ba379f2 100644 (file)
@@ -287,6 +287,8 @@ namespace Xamarin.Forms.Controls
                                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"),
index 8368f08..da7879c 100644 (file)
@@ -4,6 +4,10 @@ namespace Xamarin.Forms.Controls
 {
        internal class EntryCoreGalleryPage : CoreGalleryPage<Entry>
        {
+               public EntryCoreGalleryPage()
+               {
+               }
+
                protected override bool SupportsTapGestureRecognizer
                {
                        get { return false; }
diff --git a/Xamarin.Forms.Controls/GalleryPages/MaterialEntryGalleryPage.cs b/Xamarin.Forms.Controls/GalleryPages/MaterialEntryGalleryPage.cs
new file mode 100644 (file)
index 0000000..790d70e
--- /dev/null
@@ -0,0 +1,71 @@
+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
+                                                       },
+                                               }
+                                       }
+
+                               };
+               }
+       }
+}
diff --git a/Xamarin.Forms.Material.iOS/MaterialColors.cs b/Xamarin.Forms.Material.iOS/MaterialColors.cs
deleted file mode 100644 (file)
index 2686530..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-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,
-                               };
-                       }
-               }
-       }
-}
index b516c5e..024d261 100644 (file)
@@ -23,18 +23,6 @@ namespace Xamarin.Forms.Platform.iOS.Material
                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()
                {
@@ -43,12 +31,6 @@ namespace Xamarin.Forms.Platform.iOS.Material
                        _typographyScheme = CreateTypographyScheme();
                }
 
-               public override void LayoutSubviews()
-               {
-                       base.LayoutSubviews();
-               }
-
-
                public override CGSize SizeThatFits(CGSize size)
                {
                        var result =  base.SizeThatFits(size);
@@ -69,7 +51,7 @@ namespace Xamarin.Forms.Platform.iOS.Material
                        Control = field;
                        field.ClearButtonMode = UITextFieldViewMode.Never;
                        _activeTextinputController = new MTextInputControllerFilled(field);
-
+                       field.TextInsetsMode = TextInputTextInsetsMode.IfContent;
                        ApplyTypographyScheme();
                        ApplyTheme();
 
@@ -79,6 +61,7 @@ namespace Xamarin.Forms.Platform.iOS.Material
                protected virtual IColorScheming CreateColorScheme()
                {
                        var returnValue = MaterialColors.Light.CreateColorScheme();             
+                       
                        return returnValue;
                }
 
@@ -92,26 +75,31 @@ namespace Xamarin.Forms.Platform.iOS.Material
                        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();
                }
 
 
@@ -121,23 +109,26 @@ namespace Xamarin.Forms.Platform.iOS.Material
                                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()
index 475e6ec..c657ab7 100644 (file)
@@ -1,4 +1,4 @@
-<?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" />
index 5ef9899..fe00625 100644 (file)
@@ -1,12 +1,88 @@
-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 },
@@ -20,7 +96,7 @@ namespace Xamarin.Forms.Platform.Android.Material
                };
 
                public static readonly int[][] EntryUnderlineStates =
-               {
+{
                        new []{ global::Android.Resource.Attribute.StateFocused  },
                        new []{ -global::Android.Resource.Attribute.StateFocused  },
                };
@@ -41,14 +117,7 @@ namespace Xamarin.Forms.Platform.Android.Material
                        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 =
                        {
@@ -56,7 +125,7 @@ namespace Xamarin.Forms.Platform.Android.Material
                                new int[0] { }
                        };
 
-                       var colors = new int[] { color, color };
+                       var colors = new int[] { floatingColor, inlineColor };
                        return new ColorStateList(States, colors);
                }
 
@@ -68,15 +137,17 @@ namespace Xamarin.Forms.Platform.Android.Material
 
                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"
@@ -84,27 +155,101 @@ namespace Xamarin.Forms.Platform.Android.Material
                        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
                }
        }
 }
index 6cb35ba..98153e4 100644 (file)
@@ -1,4 +1,5 @@
 #if __ANDROID_28__
+using System.Threading.Tasks;
 using Android.Content;
 using Android.Content.Res;
 using Android.OS;
@@ -15,24 +16,6 @@ namespace Xamarin.Forms.Platform.Android.Material
 {
        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;
@@ -125,8 +108,6 @@ namespace Xamarin.Forms.Platform.Android.Material
                        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()
@@ -134,17 +115,7 @@ namespace Xamarin.Forms.Platform.Android.Material
                        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()
@@ -160,34 +131,21 @@ namespace Xamarin.Forms.Platform.Android.Material
                                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()
index 6ff3757..3320060 100644 (file)
@@ -51,8 +51,8 @@ namespace Xamarin.Forms.Platform.Android.Material
                // 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)
                {
index 2b18f48..41758bd 100644 (file)
@@ -3,9 +3,10 @@
        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>
diff --git a/Xamarin.Forms.Platform.Android/Resources/Layout/TextInputLayoutOutlinedBox.axml b/Xamarin.Forms.Platform.Android/Resources/Layout/TextInputLayoutOutlinedBox.axml
deleted file mode 100644 (file)
index 2c6c62c..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<?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>
index 73ef504..688ba0a 100644 (file)
@@ -1,11 +1,20 @@
 <?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
index b86b3e9..ea7a376 100644 (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-->
index d9351cf..7978cd8 100644 (file)
@@ -116,11 +116,12 @@ namespace Xamarin.Forms.Platform.iOS
                        _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();
@@ -246,7 +247,7 @@ namespace Xamarin.Forms.Platform.iOS
                        Control.AdjustsFontSizeToFitWidth = Element.OnThisPlatform().AdjustsFontSizeToFitWidth();
                }
 
-               void UpdateFont()
+               protected internal virtual void UpdateFont()
                {
                        if (initialSize == CGSize.Empty)
                        {
index efbff9b..b317fb8 100644 (file)
@@ -40,6 +40,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuspec", ".nuspec", "{7E12
                .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}"