diff --git a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj index c59fb5cf6..43677ab7a 100644 --- a/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj +++ b/Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj @@ -138,6 +138,7 @@ + diff --git a/Xamarin.Forms.ControlGallery.iOS/_9767CustomRenderer.cs b/Xamarin.Forms.ControlGallery.iOS/_9767CustomRenderer.cs new file mode 100644 index 000000000..7eea65c16 --- /dev/null +++ b/Xamarin.Forms.ControlGallery.iOS/_9767CustomRenderer.cs @@ -0,0 +1,50 @@ +using CoreAnimation; +using CoreGraphics; +using UIKit; +using Xamarin.Forms; +using Xamarin.Forms.ControlGallery.iOS; +using Xamarin.Forms.Controls.Issues; +using Xamarin.Forms.Platform.iOS; + +[assembly: ExportRenderer(typeof(Issue9767NavigationPage), typeof(_9767CustomRenderer))] +namespace Xamarin.Forms.ControlGallery.iOS +{ + public class _9767CustomRenderer : NavigationRenderer + { + public _9767CustomRenderer() : base() + { + + } + + public override void ViewWillAppear(bool animated) + { + base.ViewWillAppear(animated); + + UpdateColors(); + UpdateGradientView(); + } + + void UpdateColors() + { + UINavigationBar.Appearance.BarTintColor = UIColor.FromPatternImage(UIImage.FromFile("coffee.png")); + UINavigationBar.Appearance.TintColor = UIColor.Yellow; + UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes { TextColor = UIColor.Blue }); + } + + void UpdateGradientView() + { + var gradientLayer = new CAGradientLayer + { + Bounds = NavigationBar.Bounds, + Colors = new CGColor[] { Color.Blue.ToCGColor(), Color.Purple.ToCGColor() }, + EndPoint = new CGPoint(0.0, 0.5), + StartPoint = new CGPoint(1.0, 0.5) + }; + UIGraphics.BeginImageContext(gradientLayer.Bounds.Size); + gradientLayer.RenderInContext(UIGraphics.GetCurrentContext()); + UIImage image = UIGraphics.GetImageFromCurrentImageContext(); + UIGraphics.EndImageContext(); + NavigationBar.SetBackgroundImage(image, UIBarMetrics.Default); + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9767.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9767.cs index 438c6b10d..8f9bbcff4 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9767.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue9767.cs @@ -68,10 +68,21 @@ namespace Xamarin.Forms.Controls.Issues BarTextColor = Color.Default; }; + var navigateButton = new Button + { + Text = "Navigate" + }; + + navigateButton.Clicked += (sender, args) => + { + Navigation.PushAsync(new Issue9767NavigationPage(new Issue9767())); + }; + layout.Children.Add(updateBarBackgroundButton); layout.Children.Add(updateBarTextButton); layout.Children.Add(resetBarBackgroundButton); layout.Children.Add(resetBarTextButton); + layout.Children.Add(navigateButton); page.Content = layout; @@ -80,7 +91,7 @@ namespace Xamarin.Forms.Controls.Issues protected override void Init() { - + } Color GetRandomColor() @@ -102,4 +113,18 @@ namespace Xamarin.Forms.Controls.Issues return (Color)result; } } -} + + [Preserve(AllMembers = true)] + public class Issue9767NavigationPage : NavigationPage + { + public Issue9767NavigationPage() + { + + } + + public Issue9767NavigationPage(Page root) : base(root) + { + + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs index 2995b3286..53e218b19 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs @@ -148,6 +148,14 @@ namespace Xamarin.Forms.Platform.iOS base.ViewWillAppear(animated); SetStatusBarStyle(); + + if (Forms.IsiOS13OrNewer) + { + UpdateTint(); + UpdateBarBackgroundColor(); + UpdateBarTextColor(); + UpdateHideNavigationBarSeparator(); + } } public override void ViewDidDisappear(bool animated) @@ -226,11 +234,16 @@ namespace Xamarin.Forms.Platform.iOS navPage.RemovePageRequested += OnRemovedPageRequested; navPage.InsertPageBeforeRequested += OnInsertPageBeforeRequested; - UpdateTint(); - UpdateBarBackgroundColor(); - UpdateBarTextColor(); + if (!Forms.IsiOS13OrNewer) + { + UpdateTint(); + UpdateBarBackgroundColor(); + UpdateBarTextColor(); + UpdateHideNavigationBarSeparator(); + } + UpdateUseLargeTitles(); - UpdateHideNavigationBarSeparator(); + if (Forms.RespondsToSetNeedsUpdateOfHomeIndicatorAutoHidden) SetNeedsUpdateOfHomeIndicatorAutoHidden(); @@ -678,6 +691,9 @@ namespace Xamarin.Forms.Platform.iOS NavigationBar.CompactAppearance = navigationBarAppearance; NavigationBar.StandardAppearance = navigationBarAppearance; NavigationBar.ScrollEdgeAppearance = navigationBarAppearance; + + var parentingViewController = (ParentingViewController)ViewControllers.Last(); + parentingViewController?.UpdateNavigationBarBackgroundImage(); } else #endif @@ -1081,6 +1097,7 @@ namespace Xamarin.Forms.Platform.iOS public override void ViewWillAppear(bool animated) { + UpdateNavigationBarBackgroundImage(); UpdateNavigationBarVisibility(animated); NavigationRenderer n; @@ -1155,6 +1172,22 @@ namespace Xamarin.Forms.Platform.iOS UpdateIconColor(); } + internal void UpdateNavigationBarBackgroundImage() + { + if (!Forms.IsiOS13OrNewer) + return; + + if (!_navigation.TryGetTarget(out NavigationRenderer navigationRenderer)) + 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; +#endif + } internal void UpdateLeftBarButtonItem(Page pageBeingRemoved = null) {