Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Google Material 1.1.0 bump
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Mar 31, 2020
1 parent 1be09cb commit 9c061f0
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .nuspec/Xamarin.Forms.Visual.Material.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</group>
<group targetFramework="MonoAndroid10.0">
<dependency id="Xamarin.AndroidX.Lifecycle.LiveData" version="2.1.0" />
<dependency id="Xamarin.Google.Android.Material" version="1.0.0" />
<dependency id="Xamarin.Google.Android.Material" version="1.1.0-rc3" />
</group>
<group targetFramework="Xamarin.iOS10">
<dependency id="Xamarin.iOS.MaterialComponents" version="92.0.0"/>
Expand Down
2 changes: 1 addition & 1 deletion .nuspec/Xamarin.Forms.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependencies>
<group targetFramework="MonoAndroid10.0">
<dependency id="Xamarin.AndroidX.Lifecycle.LiveData" version="2.1.0" />
<dependency id="Xamarin.Google.Android.Material" version="1.0.0" />
<dependency id="Xamarin.Google.Android.Material" version="1.1.0-rc2" />
<dependency id="Xamarin.AndroidX.Legacy.Support.V4" version="1.0.0" />
<dependency id="Xamarin.AndroidX.Browser" version="1.0.0" />
</group>
Expand Down
2 changes: 1 addition & 1 deletion EmbeddingTestBeds/Embedding.Droid/Android10.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageReference Include="Xamarin.AndroidX.Browser" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.Palette" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.1.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0-rc3" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion PagesGallery/PagesGallery.Droid/Android10.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageReference Include="Xamarin.AndroidX.Browser" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.Palette" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.1.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0-rc3" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid10.0'">
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.1.0" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0-rc3" />
<PackageReference Include="Xamarin.AndroidX.RecyclerView" Version="1.1.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid90'">
Expand Down
16 changes: 8 additions & 8 deletions Xamarin.Forms.ControlGallery.Android/Android10.Build.targets
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project>
<ItemGroup Condition="'$(TargetFrameworkVersion)' == 'v10.0'">
<PackageReference Include="Xamarin.AndroidX.Migration">
<Version>1.0.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.1.0" />
<PackageReference Include="Xamarin.AndroidX.Browser" Version="1.0.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.Palette" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.Migration">
<Version>1.0.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.1.0" />
<PackageReference Include="Xamarin.AndroidX.Browser" Version="1.0.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0-rc3" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.Palette" Version="1.0.0" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Xamarin.Forms.DualScreen/Xamarin.Forms.DualScreen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid10.0'">
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.1.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0-rc3" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid90'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid10.0'">
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.1.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0-rc3" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.Migration">
<Version>1.0.0</Version>
Expand Down
39 changes: 28 additions & 11 deletions Xamarin.Forms.Material.Android/MaterialColors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,27 @@ public static PlatformColor CreateEntryFilledInputBackgroundColor(Color backgrou

public static (PlatformColor InlineColor, PlatformColor FloatingColor) GetPlaceHolderColor(Color placeholderColor, Color textColor)
{
PlatformColor color;
PlatformColor inlineColor;
PlatformColor floatingColor;
float inlineAlpha = kFilledTextFieldOnSurfaceAlpha + kFilledPlaceHolderOffset;

if (placeholderColor == Color.Default)
{
if (textColor == Color.Default)
color = MaterialColors.Light.OnSurfaceColor;
else
color = ToPlatformColor(textColor);
inlineColor = WithAlpha(MaterialColors.Light.OnSurfaceColor, inlineAlpha);
floatingColor = MaterialColors.Light.PrimaryColor;
}
else
color = ToPlatformColor(placeholderColor);

var inlineColor = WithAlpha(color, kFilledTextFieldOnSurfaceAlpha + kFilledPlaceHolderOffset);
var floatingColor = WithAlpha(color, kFilledTextFieldActiveAlpha + kFilledPlaceHolderOffset);
{
inlineColor = WithAlpha(ToPlatformColor(placeholderColor), inlineAlpha);
floatingColor = ToPlatformColor(placeholderColor);
}

return (inlineColor, floatingColor);
}

public static (PlatformColor FocusedColor, PlatformColor UnFocusedColor) GetUnderlineColor(Color textColor)
public static (PlatformColor FocusedColor, PlatformColor UnFocusedColor) GetUnderlineColor(Color placeholderColor)
{
PlatformColor color = GetEntryTextColor(textColor);
PlatformColor color = GetEntryTextColor(placeholderColor);
return (color, WithAlpha(color, kFilledTextFieldIndicatorLineAlpha));
}

Expand Down Expand Up @@ -172,6 +172,16 @@ public static ColorStateList CreateButtonTextColors(PlatformColor primary, Platf

public static ColorStateList CreateEntryFilledPlaceholderColors(PlatformColor inlineColor, PlatformColor floatingColor)
{
#if __ANDROID_29__
int[][] States =
{
new []{ ~global::Android.Resource.Attribute.StateEnabled },
new int[0] { }
};

var colors = new int[] { inlineColor, floatingColor };
return new ColorStateList(States, colors);
#else
int[][] States =
{
new []{ global::Android.Resource.Attribute.StateEnabled, global::Android.Resource.Attribute.StatePressed },
Expand All @@ -180,12 +190,19 @@ public static ColorStateList CreateEntryFilledPlaceholderColors(PlatformColor in

var colors = new int[] { floatingColor, inlineColor };
return new ColorStateList(States, colors);
#endif
}

public static ColorStateList CreateEntryUnderlineColors(PlatformColor focusedColor, PlatformColor unfocusedColor)
{
#if __ANDROID_29__
var colors = new int[] { focusedColor, unfocusedColor };
return new ColorStateList(EntryUnderlineStates, colors);
#else

var colors = new int[] { focusedColor, unfocusedColor };
return new ColorStateList(EntryUnderlineStates, colors);
#endif
}

internal static PlatformColor WithAlpha(this PlatformColor color, double alpha) =>
Expand Down
21 changes: 21 additions & 0 deletions Xamarin.Forms.Material.Android/MaterialEntryRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ public class MaterialEntryRenderer : EntryRendererBase<MaterialFormsTextInputLay
{
}

public override SizeRequest GetDesiredSize(int widthConstraint, int heightConstraint)
{
SizeRequest value;
if (!string.IsNullOrWhiteSpace(_textInputEditText.Text))
{
var text = _textInputEditText.Text;
_textInputEditText.Text = string.Empty;
value = base.GetDesiredSize(widthConstraint, heightConstraint);
_textInputEditText.Text = text;
}
else
value = base.GetDesiredSize(widthConstraint, heightConstraint);

return value;
}

protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
}

protected override AView ControlUsedForAutomation => EditText;

protected override MaterialFormsTextInputLayout CreateNativeControl()
Expand Down
54 changes: 0 additions & 54 deletions Xamarin.Forms.Material.Android/MaterialFormsEditTextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,66 +12,12 @@ namespace Xamarin.Forms.Material.Android
{
internal static class MaterialFormsEditTextManager
{
// These paddings are a hack to center the hint
// once this issue is resolved we can get rid of these paddings
// 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(16, 8, 12, 27);
static Thickness _alignedWithUnderlineText = new Thickness(16, 20, 12, 16);

public static void Init(TextInputEditText textInputEditText)
{
textInputEditText.TextChanged += OnTextChanged;
textInputEditText.FocusChange += OnFocusChanged;
}

public static void Dispose(TextInputEditText textInputEditText)
{
textInputEditText.TextChanged -= OnTextChanged;
textInputEditText.FocusChange -= OnFocusChanged;
}

private static void OnFocusChanged(object sender, global::Android.Views.View.FocusChangeEventArgs e)
{
if (sender is TextInputEditText textInputEditText)
{
// Delay padding update until after the keyboard has showed up otherwise updating the padding
// stops the keyboard from showing up
// TODO closure
if (e.HasFocus)
Device.BeginInvokeOnMainThread(() => UpdatePadding(textInputEditText));
else
UpdatePadding(textInputEditText);
}
}

private static void OnTextChanged(object sender, global::Android.Text.TextChangedEventArgs e)
{
if (e.BeforeCount == 0 || e.AfterCount == 0)
UpdatePadding(sender as TextInputEditText);
}

static void UpdatePadding(TextInputEditText textInputEditText)
{
Thickness rect = _centeredText;

if (!String.IsNullOrWhiteSpace(textInputEditText.Text) || textInputEditText.HasFocus)
{
rect = _alignedWithUnderlineText;
}

Context Context = textInputEditText.Context;
var left = (int)Context.ToPixels(rect.Left);
var top = (int)Context.ToPixels(rect.Top);
var right = (int)Context.ToPixels(rect.Right);
var bottom = (int)Context.ToPixels(rect.Bottom);

if(textInputEditText.PaddingLeft != left ||
textInputEditText.PaddingTop != top ||
textInputEditText.PaddingRight != right ||
textInputEditText.PaddingBottom != bottom)
textInputEditText.SetPadding(left, top, right, bottom);
}
}
}
27 changes: 23 additions & 4 deletions Xamarin.Forms.Material.Android/MaterialFormsTextInputLayoutBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ public class MaterialFormsTextInputLayoutBase : TextInputLayout
Color _formsTextColor;
Color _formsPlaceholderColor;
bool _isSetup = false;

#if !__ANDROID_29__
ColorStateList _focusedFilledColorList;
ColorStateList _unfocusedEmptyColorList;
private ColorStateList _unfocusedUnderlineColorsList;
private ColorStateList _focusedUnderlineColorsList;
ColorStateList _unfocusedUnderlineColorsList;
ColorStateList _focusedUnderlineColorsList;
#else
ColorStateList _placeholderColorsList;
#endif
static readonly int[][] s_colorStates = { new[] { global::Android.Resource.Attribute.StateEnabled }, new[] { -global::Android.Resource.Attribute.StateEnabled } };
bool _disposed = false;

Expand Down Expand Up @@ -54,6 +59,7 @@ void ResetTextColors(Color formsTextColor, Color formsPlaceHolderColor)
var underlineColors = MaterialColors.GetUnderlineColor(_formsPlaceholderColor);
var placeHolderColors = MaterialColors.GetPlaceHolderColor(_formsPlaceholderColor, _formsTextColor);

#if !__ANDROID_29__
// I realize these are the same but I have to set it to a difference instance
// otherwise when focused it won't change to the color I want it to and it'll just think
// I'm not actually changing anything
Expand All @@ -62,6 +68,9 @@ void ResetTextColors(Color formsTextColor, Color formsPlaceHolderColor)

_focusedFilledColorList = MaterialColors.CreateEntryFilledPlaceholderColors(placeHolderColors.FloatingColor, placeHolderColors.FloatingColor);
_unfocusedEmptyColorList = MaterialColors.CreateEntryFilledPlaceholderColors(placeHolderColors.InlineColor, placeHolderColors.FloatingColor);
#else
_placeholderColorsList = MaterialColors.CreateEntryFilledPlaceholderColors(placeHolderColors.InlineColor, placeHolderColors.FloatingColor);
#endif

var textColor = MaterialColors.GetEntryTextColor(formsTextColor).ToArgb();
EditText.SetTextColor(new ColorStateList(s_colorStates, new[] { textColor, textColor }));
Expand All @@ -83,15 +92,25 @@ public virtual void ApplyTheme(Color formsTextColor, Color formsPlaceHolderColor
ResetTextColors(formsTextColor, formsPlaceHolderColor);
}

#if __ANDROID_29__
this.DefaultHintTextColor = _placeholderColorsList;
this.HintTextColor = _placeholderColorsList.ToDefaultOnlyColorStateList();
this.BoxStrokeColor = _placeholderColorsList.DefaultColor;
#else
if(HasFocus)
ViewCompat.SetBackgroundTintList(EditText, _focusedUnderlineColorsList);

else
ViewCompat.SetBackgroundTintList(EditText, _unfocusedUnderlineColorsList);

if (HasFocus || !string.IsNullOrWhiteSpace(EditText.Text))
{
this.DefaultHintTextColor = _focusedFilledColorList;
}
else
{
this.DefaultHintTextColor = _unfocusedEmptyColorList;
}
#endif
}

void ApplyTheme() => ApplyTheme(_formsTextColor, _formsPlaceholderColor);
Expand Down Expand Up @@ -125,7 +144,7 @@ public virtual void SetHint(string hint, VisualElement element)
Hint = hint;
// EditText.Hint => Hint
// It is impossible to reset it but you can make it invisible.
EditText.SetHintTextColor(global::Android.Graphics.Color.Transparent);
//EditText.SetHintTextColor(global::Android.Graphics.Color.Transparent);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
<xamarin.forms.material.android.MaterialPickerEditText
android:id="@+id/materialformsedittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-7dp"/>
android:layout_height="wrap_content" />
</xamarin.forms.material.android.MaterialPickerTextInputLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
<xamarin.forms.material.android.MaterialFormsEditText
android:id="@+id/materialformsedittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-7dp" />
android:layout_height="wrap_content" />
</xamarin.forms.material.android.MaterialFormsTextInputLayout>
1 change: 0 additions & 1 deletion Xamarin.Forms.Material.Android/Resources/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
<item name="android:paddingBottom">8dp</item>
</style>
<style name="XamarinFormsMaterialEntryFilled" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
<item name="boxCollapsedPaddingTop">8dp</item>
</style>
<!-- Material Checkbox -->
<style name="Widget.MaterialComponents.CompoundButton.CheckBox" parent="Widget.AppCompat.CompoundButton.CheckBox">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid10.0'">
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.1.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0-rc3" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid90'">
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ void RemovePage(Page page)
return;
}

#if DEBUG
#if DEBUG && !__ANDROID_29__
// Enables logging of moveToState operations to logcat
FragmentManager.EnableDebugLogging(true);
#endif
Expand Down Expand Up @@ -813,7 +813,7 @@ Task<bool> SwitchContentAsync(Page page, bool animated, bool removed = false, bo
var tcs = new TaskCompletionSource<bool>();
Fragment fragment = GetFragment(page, removed, popToRoot);

#if DEBUG
#if DEBUG && !__ANDROID_29__
// Enables logging of moveToState operations to logcat
FragmentManager.EnableDebugLogging(true);
#endif
Expand Down
Loading

0 comments on commit 9c061f0

Please sign in to comment.