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

Androidx material bump #9701

Merged
merged 6 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .nuspec/Xamarin.Forms.AppLinks.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<dependencies>
<group targetFramework="MonoAndroid10.0">
<dependency id="Xamarin.Firebase.AppIndexing" version="119.1.0"/>
<dependency id="Xamarin.AndroidX.Lifecycle.LiveData" version="2.2.0.3"/>
<dependency id="Xamarin.AndroidX.Legacy.Support.V4" version="1.0.0.5"/>
<dependency id="Xamarin.AndroidX.Lifecycle.LiveData" version="2.2.0.4"/>
<dependency id="Xamarin.AndroidX.Legacy.Support.V4" version="1.0.0.6"/>
</group>
</dependencies>
<references>
Expand Down
4 changes: 2 additions & 2 deletions .nuspec/Xamarin.Forms.Visual.Material.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
</group>

<group targetFramework="MonoAndroid10.0">
<dependency id="Xamarin.AndroidX.Lifecycle.LiveData" version="2.2.0.3" />
<dependency id="Xamarin.Google.Android.Material" version="1.0.0.1" />
<dependency id="Xamarin.AndroidX.Lifecycle.LiveData" version="2.2.0.4" />
<dependency id="Xamarin.Google.Android.Material" version="1.1.0.5" />
</group>
<group targetFramework="Xamarin.iOS10">
<dependency id="Xamarin.iOS.MaterialComponents" version="92.0.0"/>
Expand Down
8 changes: 4 additions & 4 deletions .nuspec/Xamarin.Forms.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<dependencies>
<group targetFramework="MonoAndroid10.0">
<dependency id="Xamarin.AndroidX.Lifecycle.LiveData" version="2.2.0.3" />
<dependency id="Xamarin.Google.Android.Material" version="1.0.0.1" />
<dependency id="Xamarin.AndroidX.Legacy.Support.V4" version="1.0.0.5" />
<dependency id="Xamarin.AndroidX.Browser" version="1.0.0.1" />
<dependency id="Xamarin.AndroidX.Lifecycle.LiveData" version="2.2.0.4" />
<dependency id="Xamarin.Google.Android.Material" version="1.1.0.5" />
<dependency id="Xamarin.AndroidX.Legacy.Support.V4" version="1.0.0.6" />
<dependency id="Xamarin.AndroidX.Browser" version="1.3.0" />
</group>
<group targetFramework="uap10.0.14393">
<dependency id="NETStandard.Library" version="2.0.1"/>
Expand Down
6 changes: 3 additions & 3 deletions DualScreen/DualScreen.Android/DualScreen.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.3" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0.1" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.5" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.4" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0.5" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.6" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\values\colors.xml" />
Expand Down
6 changes: 3 additions & 3 deletions EmbeddingTestBeds/Embedding.Droid/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project>
<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.Browser" Version="1.0.0.1" />
<PackageReference Include="Xamarin.AndroidX.Browser" Version="1.3.0" />
<PackageReference Include="Xamarin.AndroidX.Palette" Version="1.0.0.1" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.1.0.1" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0.1" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0.5" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.1" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid10.0'">
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.3" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.5" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0.1" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.4" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.6" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0.5" />
<PackageReference Include="Xamarin.AndroidX.RecyclerView" Version="1.1.0.5" />
</ItemGroup>
</Project>
10 changes: 5 additions & 5 deletions Xamarin.Forms.ControlGallery.Android/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project>
<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.3" />
<PackageReference Include="Xamarin.AndroidX.Browser" Version="1.2.0.2" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0.1" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.5" />
<PackageReference Include="Xamarin.AndroidX.Palette" Version="1.0.0.5" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.4" />
<PackageReference Include="Xamarin.AndroidX.Browser" Version="1.3.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0.5" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.6" />
<PackageReference Include="Xamarin.AndroidX.Palette" Version="1.0.0.6" />
</ItemGroup>
<Import Project="Nuget.Build.targets" />
<Import Project="..\Nuget.targets" Condition="'$(FromSource)' == 'false'" />
Expand Down
6 changes: 3 additions & 3 deletions Xamarin.Forms.ControlGallery.Android/Nuget.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</ItemGroup>
<ItemGroup>
<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.Browser" Version="1.3.0" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0.5" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0" />
<PackageReference Include="Xamarin.AndroidX.Palette" Version="1.0.0" />
</ItemGroup>
</Project>
</Project>
6 changes: 3 additions & 3 deletions Xamarin.Forms.DualScreen/Xamarin.Forms.DualScreen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
</ProjectReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid10.0'">
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.3" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0.1" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.5" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.4" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0.5" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.6" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions Xamarin.Forms.Maps.Android/Xamarin.Forms.Maps.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.3" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0.1" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.5" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.4" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0.5" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.6" />
<PackageReference Include="Xamarin.GooglePlayServices.Maps" Version="117.0.0" />
</ItemGroup>
</Project>
26 changes: 13 additions & 13 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 @@ -174,11 +174,11 @@ public static ColorStateList CreateEntryFilledPlaceholderColors(PlatformColor in
{
int[][] States =
{
new []{ global::Android.Resource.Attribute.StateEnabled, global::Android.Resource.Attribute.StatePressed },
new []{ ~global::Android.Resource.Attribute.StateEnabled },
new int[0] { }
};

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

Expand Down
1 change: 0 additions & 1 deletion Xamarin.Forms.Material.Android/MaterialEntryRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ protected override MaterialFormsTextInputLayout CreateNativeControl()
var view = inflater.Inflate(Resource.Layout.TextInputLayoutFilledBox, null);
_textInputLayout = (MaterialFormsTextInputLayout)view;
_textInputEditText = _textInputLayout.FindViewById<MaterialFormsEditText>(Resource.Id.materialformsedittext);

return _textInputLayout;
}

Expand Down
56 changes: 1 addition & 55 deletions Xamarin.Forms.Material.Android/MaterialFormsEditTextManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,66 +8,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);
}
}
}
}
33 changes: 7 additions & 26 deletions Xamarin.Forms.Material.Android/MaterialFormsTextInputLayoutBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ public class MaterialFormsTextInputLayoutBase : TextInputLayout
Color _formsTextColor;
Color _formsPlaceholderColor;
bool _isSetup = false;
ColorStateList _focusedFilledColorList;
ColorStateList _unfocusedEmptyColorList;
private ColorStateList _unfocusedUnderlineColorsList;
private ColorStateList _focusedUnderlineColorsList;
ColorStateList _placeholderColorsList;

static readonly int[][] s_colorStates = { new[] { global::Android.Resource.Attribute.StateEnabled }, new[] { -global::Android.Resource.Attribute.StateEnabled } };
bool _disposed = false;

Expand All @@ -47,15 +45,8 @@ void ResetTextColors(Color formsTextColor, Color formsPlaceHolderColor)

var underlineColors = MaterialColors.GetUnderlineColor(_formsPlaceholderColor);
var placeHolderColors = MaterialColors.GetPlaceHolderColor(_formsPlaceholderColor, _formsTextColor);
_placeholderColorsList = MaterialColors.CreateEntryFilledPlaceholderColors(placeHolderColors.InlineColor, placeHolderColors.FloatingColor);

// 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
_unfocusedUnderlineColorsList = MaterialColors.CreateEntryUnderlineColors(underlineColors.FocusedColor, underlineColors.UnFocusedColor);
_focusedUnderlineColorsList = MaterialColors.CreateEntryUnderlineColors(underlineColors.FocusedColor, underlineColors.UnFocusedColor);

_focusedFilledColorList = MaterialColors.CreateEntryFilledPlaceholderColors(placeHolderColors.FloatingColor, placeHolderColors.FloatingColor);
_unfocusedEmptyColorList = MaterialColors.CreateEntryFilledPlaceholderColors(placeHolderColors.InlineColor, placeHolderColors.FloatingColor);

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

if (HasFocus)
ViewCompat.SetBackgroundTintList(EditText, _focusedUnderlineColorsList);
else
ViewCompat.SetBackgroundTintList(EditText, _unfocusedUnderlineColorsList);

if (HasFocus || !string.IsNullOrWhiteSpace(EditText.Text))
this.DefaultHintTextColor = _focusedFilledColorList;
else
this.DefaultHintTextColor = _unfocusedEmptyColorList;
this.DefaultHintTextColor = _placeholderColorsList;
this.HintTextColor = _placeholderColorsList.ToDefaultOnlyColorStateList();
this.BoxStrokeColor = _placeholderColorsList.DefaultColor;
}

void ApplyTheme() => ApplyTheme(_formsTextColor, _formsPlaceholderColor);
Expand Down Expand Up @@ -117,9 +101,6 @@ public virtual void SetHint(string hint, VisualElement element)
{
element?.InvalidateMeasureNonVirtual(Internals.InvalidationTrigger.VerticalOptionsChanged);
Hint = hint;
// EditText.Hint => Hint
// It is impossible to reset it but you can make it invisible.
EditText.SetHintTextColor(global::Android.Graphics.Color.Transparent);
}
}

Expand All @@ -146,4 +127,4 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}
}
}
}
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>
3 changes: 1 addition & 2 deletions Xamarin.Forms.Material.Android/Resources/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<attr name="materialProgressBarCircularStyle" format="reference" />
<attr name="materialCheckBoxStyle" format="reference" />
<!-- Material Base Theme -->
<style name="XamarinFormsMaterialTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<style name="XamarinFormsMaterialTheme" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="materialButtonStyle">@style/XamarinFormsMaterialButton</item>
<item name="materialOutlinedButtonStyle">@style/XamarinFormsMaterialButtonOutlined</item>
<item name="materialSliderStyle">@style/XamarinFormsMaterialSlider</item>
Expand Down 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 @@ -14,9 +14,9 @@
<ItemGroup>
<AndroidResource Include="Resources\**\*" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid10.0'">
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.3" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.0.0.1" />
<ItemGroup Condition=" $(TargetFramework.StartsWith('MonoAndroid')) " >
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.4" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.1.0.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'MonoAndroid10.0'">
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.3" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.5" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.2.0.4" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.6" />
</ItemGroup>
</Project>
Loading