[iOS] Fix issue when enabling SafeArea and scrolling (#1274)
authorRui Marinho <me@ruimarinho.net>
Wed, 15 Nov 2017 19:20:22 +0000 (19:20 +0000)
committerRui Marinho <me@ruimarinho.net>
Wed, 15 Nov 2017 19:22:19 +0000 (19:22 +0000)
* [Controls] Add example for bugzilla 60659

* [iOS] Adjust size of the PageContainer related with the UINavigationBar height

* [iOS] Fix typo

* [iOS] Make sure we don't crash when disposed and LayoutSubviews is called

Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/LargeTitlesPageiOS.cs
Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGallery.cs
Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs

index 313eeee..d17992a 100644 (file)
@@ -1,4 +1,6 @@
 using System;
+using System.Collections.Generic;
+using System.Linq;
 using System.Windows.Input;
 using Xamarin.Forms.PlatformConfiguration;
 using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
@@ -45,12 +47,39 @@ namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries
                                                        navPage.On<iOS>().SetPrefersLargeTitles(!navPage.On<iOS>().PrefersLargeTitles());
                                                } )
                                        },
+
+                                       new Button
+                                       {
+                                               Text = "UseLargeTitles on Navigation with safe Area",
+                                               Command = new Command( () =>{
+                                                       var navPage = (Parent as NavigationPage);
+                                                       navPage.On<iOS>().SetPrefersLargeTitles(true);
+                                                       var page = new ContentPage { Title = "New Title", BackgroundColor = Color.Red };
+                                                       page.On<iOS>().SetUseSafeArea(true);
+                                                       var listView = new ListView(ListViewCachingStrategy.RecycleElementAndDataTemplate)
+                                                       {
+                                                               HasUnevenRows = true,
+                                                               VerticalOptions = LayoutOptions.FillAndExpand
+                                                       };
+
+                                                       listView.ItemTemplate = new DataTemplate(()=>{
+                                                               var cell = new ViewCell();
+                                                               cell.View = new Label { Text ="Hello", FontSize = 30};
+                                                               return cell;
+                                                       });
+                                                       listView.ItemsSource = Enumerable.Range(1, 40);
+                                                       listView.Header = new Label { BackgroundColor = Color.Pink , Text = "I'm a header, background is red"};
+                                                       listView.Footer = new Label { BackgroundColor = Color.Yellow , Text = "I'm a footer, you should see no white below me"};
+                                                       page.Content = listView;
+                                                       navPage.PushAsync(page);
+                                               } )
+                                       },
                                        offscreenPageLimit
                                }
                        };
 
                        var restoreButton = new Button { Text = "Back To Gallery" };
-                       restoreButton.Clicked +=  async (sender, args) => await Navigation.PopAsync();
+                       restoreButton.Clicked += async (sender, args) => await Navigation.PopAsync();
                        content.Children.Add(restoreButton);
 
                        Content = content;
index e1c51b8..af50dbc 100644 (file)
@@ -8,6 +8,7 @@ namespace Xamarin.Forms.Controls
 
                public PlatformSpecificsGallery()
                {
+                       Title = "PlatformSpecificsGallery";
                        var mdpiOSButton = new Button { Text = "MasterDetailPage (iOS)" };
                        var mdpWindowsButton = new Button { Text = "MasterDetailPage (Windows)" };
                        var npiOSButton = new Button() { Text = "NavigationPage (iOS)" };
index 25dec56..915d2a8 100644 (file)
@@ -26,6 +26,8 @@ namespace Xamarin.Forms.Platform.iOS
                UIViewController[] _removeControllers;
                UIToolbar _secondaryToolbar;
                VisualElementTracker _tracker;
+               nfloat _navigationBottom = 0;
+
 
                public NavigationRenderer()
                {
@@ -147,14 +149,15 @@ namespace Xamarin.Forms.Platform.iOS
                public override void ViewDidLayoutSubviews()
                {
                        base.ViewDidLayoutSubviews();
+                       if (Current == null)
+                               return;
                        UpdateToolBarVisible();
 
-                       //var navBarFrameBotton = Forms.IsiOS11OrNewer ? View.SafeAreaInsets.Top : NavigationBar.Frame.Bottom;
-                       var navBarFrameBotton = NavigationBar.Frame.Bottom;
-
+                       var navBarFrameBottom = Math.Min(NavigationBar.Frame.Bottom, 140);
+                       _navigationBottom = (nfloat)navBarFrameBottom;
                        var toolbar = _secondaryToolbar;
                        // Use 0 if the NavBar is hidden or will be hidden
-                       var toolbarY = NavigationBarHidden || NavigationBar.Translucent || !NavigationPage.GetHasNavigationBar(Current) ? 0 : navBarFrameBotton;
+                       var toolbarY = NavigationBarHidden || NavigationBar.Translucent || !NavigationPage.GetHasNavigationBar(Current) ? 0 : navBarFrameBottom;
                        toolbar.Frame = new RectangleF(0, toolbarY, View.Frame.Width, toolbar.Frame.Height);
 
                        double trueBottom = toolbar.Hidden ? toolbarY : toolbar.Frame.Bottom;
@@ -713,6 +716,14 @@ namespace Xamarin.Forms.Platform.iOS
                        }
                }
 
+               internal void ValidateInsets()
+               {
+                       nfloat navBottom = NavigationBar.Frame.Bottom;
+
+                       if (_navigationBottom != navBottom && Current != null)
+                               ViewDidLayoutSubviews();
+               }
+
                class SecondaryToolbar : UIToolbar
                {
                        readonly List<UIView> _lines = new List<UIView>();
@@ -835,6 +846,15 @@ namespace Xamarin.Forms.Platform.iOS
                                        handler(this, EventArgs.Empty);
                        }
 
+                       public override void ViewWillLayoutSubviews()
+                       {
+                               base.ViewWillLayoutSubviews();
+
+                               NavigationRenderer n;
+                               if (_navigation.TryGetTarget(out n))
+                                       n.ValidateInsets();
+                       }
+
                        public override void ViewDidLayoutSubviews()
                        {
                                IVisualElementRenderer childRenderer;