[iOS] Fix NavBar issues on iOS 13 (#10493)
* Created repro sample * Fixed #10337 and #10338 * Update Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs Co-Authored-By: Samantha Houts <samhouts@users.noreply.github.com> * Update NavigationRenderer.cs Co-authored-by: Rui Marinho <me@ruimarinho.net> Co-authored-by: Samantha Houts <samhouts@users.noreply.github.com> fixes #10337 fixes #10338
This commit is contained in:
Родитель
7938a26460
Коммит
5276134af5
|
@ -138,6 +138,7 @@
|
|||
<Compile Include="ApiLabelRenderer.cs" />
|
||||
<Compile Include="CustomRenderers\CustomSearchBarRenderer.cs" />
|
||||
<Compile Include="_9767CustomRenderer.cs" />
|
||||
<Compile Include="_10337CustomRenderer.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Xamarin.Forms.Controls\Xamarin.Forms.Controls.csproj">
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.ControlGallery.iOS;
|
||||
using Xamarin.Forms.Controls.Issues;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
|
||||
[assembly: ExportRenderer(typeof(Issue10337NavigationPage), typeof(_10337CustomRenderer))]
|
||||
namespace Xamarin.Forms.ControlGallery.iOS
|
||||
{
|
||||
public class _10337CustomRenderer : NavigationRenderer
|
||||
{
|
||||
public override void ViewDidLoad()
|
||||
{
|
||||
base.ViewDidLoad();
|
||||
|
||||
NavigationBar.ShadowImage = new UIImage();
|
||||
UINavigationBar.Appearance.BackIndicatorImage = new UIImage();
|
||||
UINavigationBar.Appearance.BackIndicatorTransitionMaskImage = new UIImage();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.Forms.Core.UITests;
|
||||
using Xamarin.UITest;
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
#if UITEST
|
||||
[Category(UITestCategories.Navigation)]
|
||||
#endif
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Github, 10337, "[Bug]iOS Renderer NavigationBar.ShadowImage = new UIImage() not remove shadow line after xamarin.forms 4.5", PlatformAffected.iOS)]
|
||||
public class Issue10337 : TestNavigationPage
|
||||
{
|
||||
public Issue10337()
|
||||
{
|
||||
var page = new ContentPage
|
||||
{
|
||||
Title = "Issue 10337"
|
||||
};
|
||||
|
||||
var layout = new StackLayout();
|
||||
|
||||
var navigateButton = new Button
|
||||
{
|
||||
Text = "Navigate using Custom NavigationPage"
|
||||
};
|
||||
|
||||
navigateButton.Clicked += (sender, args) =>
|
||||
{
|
||||
Navigation.PushAsync(new Issue10337NavigationPage(new Issue10337()));
|
||||
};
|
||||
|
||||
layout.Children.Add(navigateButton);
|
||||
|
||||
page.Content = layout;
|
||||
|
||||
PushAsync(page);
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Preserve(AllMembers = true)]
|
||||
public class Issue10337NavigationPage : NavigationPage
|
||||
{
|
||||
public Issue10337NavigationPage()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Issue10337NavigationPage(Page root) : base(root)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1297,6 +1297,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Issue9417.xaml.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue8272.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue8964.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue10337.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue9794.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue10438.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -659,7 +659,10 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
if (barBackgroundColor == Color.Default)
|
||||
{
|
||||
navigationBarAppearance.ConfigureWithDefaultBackground();
|
||||
navigationBarAppearance.BackgroundColor = UINavigationBar.Appearance.BarTintColor;
|
||||
navigationBarAppearance.BackgroundColor = null;
|
||||
|
||||
var parentingViewController = GetParentingViewController();
|
||||
parentingViewController?.SetupDefaultNavigationBarAppearance();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -670,9 +673,6 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
NavigationBar.CompactAppearance = navigationBarAppearance;
|
||||
NavigationBar.StandardAppearance = navigationBarAppearance;
|
||||
NavigationBar.ScrollEdgeAppearance = navigationBarAppearance;
|
||||
|
||||
var parentingViewController = GetParentingViewController();
|
||||
parentingViewController?.UpdateNavigationBarBackgroundImage();
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
@ -1070,7 +1070,7 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
|
||||
public override void ViewWillAppear(bool animated)
|
||||
{
|
||||
UpdateNavigationBarBackgroundImage();
|
||||
SetupDefaultNavigationBarAppearance();
|
||||
UpdateNavigationBarVisibility(animated);
|
||||
|
||||
NavigationRenderer n;
|
||||
|
@ -1136,7 +1136,7 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
UpdateTitleArea(Child);
|
||||
}
|
||||
|
||||
internal void UpdateNavigationBarBackgroundImage()
|
||||
internal void SetupDefaultNavigationBarAppearance()
|
||||
{
|
||||
if (!Forms.IsiOS13OrNewer)
|
||||
return;
|
||||
|
@ -1145,14 +1145,65 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
return;
|
||||
|
||||
#if __XCODE11__
|
||||
var backgroundImage = navigationRenderer.NavigationBar.GetBackgroundImage(UIBarMetrics.Default);
|
||||
|
||||
navigationRenderer.NavigationBar.CompactAppearance.BackgroundImage = backgroundImage;
|
||||
navigationRenderer.NavigationBar.StandardAppearance.BackgroundImage = backgroundImage;
|
||||
navigationRenderer.NavigationBar.ScrollEdgeAppearance.BackgroundImage = backgroundImage;
|
||||
// We will use UINavigationBar.Appareance to infer settings that
|
||||
// were already set to navigation bar in older versions of
|
||||
// iOS.
|
||||
var navBar = navigationRenderer.NavigationBar;
|
||||
var navAppearance = navBar.StandardAppearance;
|
||||
|
||||
if (navAppearance.BackgroundColor == null)
|
||||
{
|
||||
var backgroundColor = navBar.BarTintColor;
|
||||
navBar.CompactAppearance.BackgroundColor = navBar.StandardAppearance.BackgroundColor = navBar.ScrollEdgeAppearance.BackgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
if (navAppearance.BackgroundImage == null)
|
||||
{
|
||||
var backgroundImage = navBar.GetBackgroundImage(UIBarMetrics.Default);
|
||||
navBar.CompactAppearance.BackgroundImage = navBar.StandardAppearance.BackgroundImage = navBar.ScrollEdgeAppearance.BackgroundImage = backgroundImage;
|
||||
}
|
||||
|
||||
if (navAppearance.ShadowImage == null)
|
||||
{
|
||||
var shadowImage = navBar.ShadowImage;
|
||||
navBar.CompactAppearance.ShadowImage = navBar.StandardAppearance.ShadowImage = navBar.ScrollEdgeAppearance.ShadowImage = shadowImage;
|
||||
|
||||
if (shadowImage != null && shadowImage.Size == SizeF.Empty)
|
||||
navBar.CompactAppearance.ShadowColor = navBar.StandardAppearance.ShadowColor = navBar.ScrollEdgeAppearance.ShadowColor = UIColor.Clear;
|
||||
}
|
||||
|
||||
UIImage backIndicatorImage = navBar.BackIndicatorImage;
|
||||
UIImage backIndicatorTransitionMaskImage = navBar.BackIndicatorTransitionMaskImage;
|
||||
|
||||
if (backIndicatorImage != null && backIndicatorImage.Size == SizeF.Empty)
|
||||
backIndicatorImage = GetEmptyBackIndicatorImage();
|
||||
|
||||
if (backIndicatorTransitionMaskImage != null && backIndicatorTransitionMaskImage.Size == SizeF.Empty)
|
||||
backIndicatorTransitionMaskImage = GetEmptyBackIndicatorImage();
|
||||
|
||||
navBar.CompactAppearance.SetBackIndicatorImage(backIndicatorImage, backIndicatorTransitionMaskImage);
|
||||
navBar.StandardAppearance.SetBackIndicatorImage(backIndicatorImage, backIndicatorTransitionMaskImage);
|
||||
navBar.ScrollEdgeAppearance.SetBackIndicatorImage(backIndicatorImage, backIndicatorTransitionMaskImage);
|
||||
#endif
|
||||
}
|
||||
|
||||
UIImage GetEmptyBackIndicatorImage()
|
||||
{
|
||||
var rect = RectangleF.Empty;
|
||||
var size = rect.Size;
|
||||
|
||||
UIGraphics.BeginImageContext(size);
|
||||
var context = UIGraphics.GetCurrentContext();
|
||||
context.SetFillColor(1, 1, 1, 0);
|
||||
context.FillRect(rect);
|
||||
|
||||
var empty = UIGraphics.GetImageFromCurrentImageContext();
|
||||
context.Dispose();
|
||||
|
||||
return empty;
|
||||
}
|
||||
|
||||
internal void UpdateLeftBarButtonItem(Page pageBeingRemoved = null)
|
||||
{
|
||||
NavigationRenderer n;
|
||||
|
|
Загрузка…
Ссылка в новой задаче