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

Commit

Permalink
Align BarBackground behavior between Android and iOS.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz committed Jan 22, 2021
1 parent b0ec436 commit 8ab614f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<FlyoutPage.Flyout>
<ContentPage
Title="Flyout"
BackgroundColor="White"
BackgroundColor="Transparent"
Background="{StaticResource HorizontalLinearGradient}">
<Label
FontSize="24"
Expand All @@ -36,6 +36,7 @@
</FlyoutPage.Flyout>
<FlyoutPage.Detail>
<NavigationPage
BarBackgroundColor="Transparent"
BarBackground="{StaticResource HorizontalLinearGradient}"
Title="Gradient NavigationPage">
<x:Arguments>
Expand Down
41 changes: 23 additions & 18 deletions Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -986,32 +986,37 @@ void UpdateToolbar()
}
}

Color tintColor = Element.BarBackgroundColor;
Color barBackgroundColor = Element.BarBackgroundColor;
Brush barBackground = Element.BarBackground;

if (Forms.IsLollipopOrNewer)
if (Brush.IsNullOrEmpty(barBackground))
{
if (tintColor.IsDefault)
bar.BackgroundTintMode = null;
if (Forms.IsLollipopOrNewer)
{
if (barBackgroundColor.IsDefault)
bar.BackgroundTintMode = null;
else
{
bar.BackgroundTintMode = PorterDuff.Mode.Src;
bar.BackgroundTintList = ColorStateList.ValueOf(barBackgroundColor.ToAndroid());
}
}
else
{
bar.BackgroundTintMode = PorterDuff.Mode.Src;
bar.BackgroundTintList = ColorStateList.ValueOf(tintColor.ToAndroid());
if (barBackgroundColor.IsDefault && _backgroundDrawable != null)
bar.SetBackground(_backgroundDrawable);
else if (!barBackgroundColor.IsDefault)
{
if (_backgroundDrawable == null)
_backgroundDrawable = bar.Background;
bar.SetBackgroundColor(barBackgroundColor.ToAndroid());
}
}
}
else
{
if (tintColor.IsDefault && _backgroundDrawable != null)
bar.SetBackground(_backgroundDrawable);
else if (!tintColor.IsDefault)
{
if (_backgroundDrawable == null)
_backgroundDrawable = bar.Background;
bar.SetBackgroundColor(tintColor.ToAndroid());
}
}

Brush barBackground = Element.BarBackground;
bar.UpdateBackground(barBackground);
bar.UpdateBackground(barBackground);
}

Color textColor = Element.BarTextColor;
if (!textColor.IsDefault)
Expand Down

0 comments on commit 8ab614f

Please sign in to comment.