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

Fix tabs layout on iOS when using Shell navigation - #14773 #14877

Merged
merged 2 commits into from
Nov 18, 2021
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
9 changes: 5 additions & 4 deletions Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class PageRenderer : UIViewController, IVisualElementRenderer, IEffectCon
Page Page => Element as Page;
IAccessibilityElementsController AccessibilityElementsController => this;
Thickness SafeAreaInsets => Page.On<PlatformConfiguration.iOS>().SafeAreaInsets();
bool IsPartOfShell => (Element?.Parent is BaseShellItem);
bool IsPartOfShell => (Element?.Parent is BaseShellItem || (
Element?.Parent is TabbedPage && Element?.Parent?.Parent is BaseShellItem));
TrinTragula marked this conversation as resolved.
Show resolved Hide resolved
ShellSection _shellSection;
bool _safeAreasSet = false;
Thickness _userPadding = default(Thickness);
Expand Down Expand Up @@ -102,7 +103,7 @@ public UIView NativeView
{
get { return _disposed ? null : View; }
}

public void SetElement(VisualElement element)
{
VisualElement oldElement = Element;
Expand Down Expand Up @@ -281,10 +282,10 @@ void IDisconnectable.Disconnect()

if (_appeared)
Page.SendDisappearing();

Element = null;
}

_events?.Disconnect();
_packager?.Disconnect();
_tracker?.Disconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void UpdateiOS15TabBarAppearance(UITabBarController controller, ShellAppearance
var tabBar = controller.TabBar;

var tabBarAppearance = new UITabBarAppearance();
tabBarAppearance.ConfigureWithOpaqueBackground();
tabBarAppearance.ConfigureWithDefaultBackground();

// Set TabBarBackgroundColor
var tabBarBackgroundColor = appearanceElement.EffectiveTabBarBackgroundColor;
Expand Down Expand Up @@ -129,10 +129,9 @@ void UpdateTabBarAppearance(UITabBarController controller, ShellAppearance appea

bool operatingSystemSupportsUnselectedTint = Forms.IsiOS10OrNewer;

if (operatingSystemSupportsUnselectedTint)
if (operatingSystemSupportsUnselectedTint && !unselectedColor.IsDefault)
{
if (!unselectedColor.IsDefault)
tabBar.UnselectedItemTintColor = unselectedColor.ToUIColor();
tabBar.UnselectedItemTintColor = unselectedColor.ToUIColor();
}
}

Expand Down
13 changes: 3 additions & 10 deletions Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class TabbedRenderer : UITabBarController, IVisualElementRenderer, IEffec
Size _queuedSize;
UITabBarAppearance _tabBarAppearance;

Page Page => Element as Page;
Page Page => Element as Page;

[Internals.Preserve(Conditional = true)]
public TabbedRenderer()
Expand Down Expand Up @@ -133,21 +133,14 @@ public override void ViewDidLayoutSubviews()
if (Element.Parent is BaseShellItem)
Element.Layout(View.Bounds.ToRectangle());

if (!Element.Bounds.IsEmpty)
{
View.Frame = new RectangleF((float)Element.X, (float)Element.Y, (float)Element.Width, (float)Element.Height);
}

var frame = View.Frame;
var tabBarFrame = TabBar.Frame;
Page.ContainerArea = new Rectangle(0, 0, frame.Width, frame.Height - tabBarFrame.Height);

if (!_queuedSize.IsZero)
{
Element.Layout(new Rectangle(Element.X, Element.Y, _queuedSize.Width, _queuedSize.Height));
_queuedSize = Size.Zero;
}

_loaded = true;
}

Expand Down Expand Up @@ -479,7 +472,7 @@ void IEffectControlProvider.RegisterEffect(Effect effect)
async void SetTabBarItem(IVisualElementRenderer renderer)
{
var page = renderer.Element as Page;
if(page == null)
if (page == null)
throw new InvalidCastException($"{nameof(renderer)} must be a {nameof(Page)} renderer.");

var icons = await GetIcon(page);
Expand Down Expand Up @@ -544,7 +537,7 @@ void UpdateiOS15TabBarAppearance()
if (_tabBarAppearance == null)
{
_tabBarAppearance = new UITabBarAppearance();
_tabBarAppearance.ConfigureWithOpaqueBackground();
_tabBarAppearance.ConfigureWithDefaultBackground();
}

var barBackgroundColor = Tabbed.BarBackgroundColor;
Expand Down