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

[iOS] Fix issue when enabling SafeArea and scrolling #1274

Merged
merged 4 commits into from Nov 15, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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;
Expand Down Expand Up @@ -45,12 +47,39 @@ public LargeTitlesPageiOS(ICommand restore)
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;
Expand Down
Expand Up @@ -8,6 +8,7 @@ public class PlatformSpecificsGallery : ContentPage

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)" };
Expand Down
28 changes: 24 additions & 4 deletions Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
Expand Up @@ -26,6 +26,8 @@ public class NavigationRenderer : UINavigationController, IVisualElementRenderer
UIViewController[] _removeControllers;
UIToolbar _secondaryToolbar;
VisualElementTracker _tracker;
nfloat _navigationBottom = 0;


public NavigationRenderer()
{
Expand Down Expand Up @@ -147,14 +149,15 @@ public override void ViewDidDisappear(bool animated)
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;
Expand Down Expand Up @@ -713,6 +716,14 @@ internal static async void SetMasterLeftBarButton(UIViewController containerCont
}
}

internal void ValidateInsets()
{
nfloat navBottom = NavigationBar.Frame.Bottom;

if (_navigationBottom != navBottom && Current != null)
ViewDidLayoutSubviews();
}

class SecondaryToolbar : UIToolbar
{
readonly List<UIView> _lines = new List<UIView>();
Expand Down Expand Up @@ -842,6 +853,15 @@ public override void ViewDidDisappear(bool animated)
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;
Expand Down