Skip to content

Commit

Permalink
fix(commandbar): [iOS] Update CommandBar layout when Visibility changes
Browse files Browse the repository at this point in the history
Fixes bug where CommandBar position wouldn't be adjusted properly in a sequence involving collapsing the CommandBar, hiding the status bar, rotating the screen to landscape and back to portrait, showing the status bar, and finally showing the CommandBar again.
  • Loading branch information
davidjohnoliver committed Apr 27, 2020
1 parent 9ec81eb commit fc18909
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
21 changes: 16 additions & 5 deletions src/Uno.UI/Controls/CommandBarRenderer.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if __IOS__
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -60,8 +59,7 @@ protected override IEnumerable<IDisposable> Initialize()

protected override void Render()
{
// Visibility
Native.Hidden = Element.Visibility == Visibility.Collapsed;
ApplyVisibility();

// Foreground
var foregroundColor = (Element.Foreground as SolidColorBrush)?.ColorWithOpacity;
Expand Down Expand Up @@ -126,6 +124,19 @@ protected override void Render()
Element.Presenter.Height = Native.Hidden ? 0 : Native.Frame.Size.Height;
}
}

private void ApplyVisibility()
{
var newHidden = Element.Visibility == Visibility.Collapsed;
var hasChanged = Native.Hidden != newHidden;
Native.Hidden = newHidden;
if (hasChanged)
{
// Re-layout UINavigationBar when visibility changes, this is important eg in the case that status bar was shown/hidden
// while CommandBar was collapsed
Native.SetNeedsLayout();
Native.Superview?.SetNeedsLayout();
}
}
}
}
#endif
6 changes: 2 additions & 4 deletions src/Uno.UI/Controls/NativeCommandBarPresenter.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if __IOS__
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -20,7 +19,7 @@ public partial class NativeCommandBarPresenter : ContentPresenter
{
private readonly SerialDisposable _statusBarSubscription = new SerialDisposable();
private readonly SerialDisposable _orientationSubscription = new SerialDisposable();

protected override void OnLoaded()
{
base.OnLoaded();
Expand Down Expand Up @@ -61,4 +60,3 @@ protected override void OnUnloaded()
}
}
}
#endif
4 changes: 1 addition & 3 deletions src/Uno.UI/Controls/NativeFramePresenter.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if __IOS__
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -278,4 +277,3 @@ public override void DidShowViewController(UINavigationController navigationCont
}
}
}
#endif

0 comments on commit fc18909

Please sign in to comment.