Skip to content

Commit

Permalink
Simplify TabbedPageManager.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaflo committed Jan 5, 2025
1 parent 57f9f61 commit 3831a77
Showing 1 changed file with 3 additions and 59 deletions.
62 changes: 3 additions & 59 deletions src/Controls/src/Core/Platform/Android/TabbedPageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;
using Microsoft.Maui.Graphics;
using AColor = Android.Graphics.Color;
using ADrawableCompat = AndroidX.Core.Graphics.Drawable.DrawableCompat;
using AView = Android.Views.View;
using Color = Microsoft.Maui.Graphics.Color;

Expand All @@ -44,8 +43,6 @@ internal class TabbedPageManager
int[] _checkedStateSet = null;
int[] _selectedStateSet = null;
int[] _emptyStateSet = null;
int _defaultARGBColor = Colors.Transparent.ToPlatform().ToArgb();
AColor _defaultAndroidColor = Colors.Transparent.ToPlatform();
readonly IMauiContext _context;
readonly Listeners _listeners;
TabbedPage Element { get; set; }
Expand Down Expand Up @@ -385,8 +382,6 @@ void TabSelected(TabLayout.Tab tab)
int selectedIndex = tab.Position;
if (Element.Children.Count > selectedIndex && selectedIndex >= 0)
Element.CurrentPage = Element.Children[selectedIndex];

SetIconColorFilter(tab, true);
}

void TeardownPage(Page page)
Expand Down Expand Up @@ -528,7 +523,6 @@ void UpdateTabIcons()
protected virtual void SetTabIconImageSource(TabLayout.Tab tab, Drawable icon)
{
tab.SetIcon(icon);
SetIconColorFilter(tab);
}

void SetTabIconImageSource(Page page, TabLayout.Tab tab)
Expand Down Expand Up @@ -736,14 +730,7 @@ void UpdateItemIconColor()
if (IsBottomTabPlacement)
_bottomNavigationView.ItemIconTintList = GetItemIconTintColorState() ?? _orignalTabIconColors;
else
{
var colors = GetItemIconTintColorState() ?? _orignalTabIconColors;
for (int i = 0; i < _tabLayout.TabCount; i++)
{
TabLayout.Tab tab = _tabLayout.GetTabAt(i);
this.SetIconColorFilter(tab);
}
}
_tabLayout.TabIconTint = GetItemIconTintColorState() ?? _orignalTabIconColors;
}

internal void UpdateTabItemStyle()
Expand Down Expand Up @@ -780,49 +767,6 @@ void UpdateBarTextColor()
_tabLayout.TabTextColors = _currentBarTextColorStateList;
}

void SetIconColorFilter(TabLayout.Tab tab)
{
SetIconColorFilter(tab, _tabLayout.GetTabAt(_tabLayout.SelectedTabPosition) == tab);
}

void SetIconColorFilter(TabLayout.Tab tab, bool selected)
{
var icon = tab.Icon;
if (icon == null)
return;

var colors = GetItemIconTintColorState();
if (colors == null)
ADrawableCompat.SetTintList(icon, null);
else
{
int[] _stateSet = null;

if (selected)
_stateSet = GetSelectedStateSet();
else
_stateSet = GetEmptyStateSet();

if (colors.GetColorForState(_stateSet, _defaultAndroidColor) == _defaultARGBColor)
ADrawableCompat.SetTintList(icon, null);
else
{
var wrappedIcon = ADrawableCompat.Wrap(icon);
if (wrappedIcon != icon)
{
icon = wrappedIcon;
tab.SetIcon(wrappedIcon);
}

icon.Mutate();
icon.SetState(_stateSet);
_tabLayout.TabIconTint = colors;
ADrawableCompat.SetTintList(icon, colors);
}
}
icon.InvalidateSelf();
}

int[] GetSelectedStateSet()
{
if (IsBottomTabPlacement)
Expand Down Expand Up @@ -966,9 +910,9 @@ void TabLayout.IOnTabSelectedListener.OnTabSelected(TabLayout.Tab tab)
_tabbedPageManager.TabSelected(tab);
}

void TabLayout.IOnTabSelectedListener.OnTabUnselected(TabLayout.Tab tab)
void TabLayout.IOnTabSelectedListener.OnTabUnselected(TabLayout.Tab tab)
{
_tabbedPageManager.SetIconColorFilter(tab, false);

}
}
}
Expand Down

0 comments on commit 3831a77

Please sign in to comment.