summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authorPaul DiPietro <pauldipietro@users.noreply.github.com>2016-11-16 04:02:54 -0600
committerRui Marinho <me@ruimarinho.net>2016-11-16 11:02:54 +0100
commit98235e0eea8b540ac10a71b97ee08a5842abd664 (patch)
tree83856b6c24d0b8730946cd3241f550623a0d7f7b /Xamarin.Forms.Platform.iOS
parent107ed5e545698a647b9cd1be22745a2c35aeebc4 (diff)
downloadxamarin-forms-98235e0eea8b540ac10a71b97ee08a5842abd664.tar.gz
xamarin-forms-98235e0eea8b540ac10a71b97ee08a5842abd664.tar.bz2
xamarin-forms-98235e0eea8b540ac10a71b97ee08a5842abd664.zip
[iOS] Add Platform Specific features for PrefersStatusBarHidden/UIStatusBarAnimation (#463)
* [iOS] Add Platform Specific features for PrefersStatusBarHidden/UIStatusBarAnimation * Update docs
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/Platform.cs2
-rw-r--r--Xamarin.Forms.Platform.iOS/PlatformRenderer.cs6
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs40
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs53
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs11
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs25
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs9
7 files changed, 144 insertions, 2 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Platform.cs b/Xamarin.Forms.Platform.iOS/Platform.cs
index 8db28f6f..762ccf00 100644
--- a/Xamarin.Forms.Platform.iOS/Platform.cs
+++ b/Xamarin.Forms.Platform.iOS/Platform.cs
@@ -146,7 +146,7 @@ namespace Xamarin.Forms.Platform.iOS
get { return _renderer; }
}
- Page Page { get; set; }
+ internal Page Page { get; set; }
void IDisposable.Dispose()
{
diff --git a/Xamarin.Forms.Platform.iOS/PlatformRenderer.cs b/Xamarin.Forms.Platform.iOS/PlatformRenderer.cs
index f2d897e4..5767c184 100644
--- a/Xamarin.Forms.Platform.iOS/PlatformRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/PlatformRenderer.cs
@@ -1,4 +1,5 @@
using UIKit;
+using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
namespace Xamarin.Forms.Platform.iOS
{
@@ -103,6 +104,11 @@ namespace Xamarin.Forms.Platform.iOS
}
return base.PreferredInterfaceOrientationForPresentation();
}
+
+ public override UIViewController ChildViewControllerForStatusBarHidden()
+ {
+ return (UIViewController)Platform.GetRenderer(this.Platform.Page);
+ }
public override bool ShouldAutorotate()
{
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
index fdbd116d..676c73ae 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
@@ -1,12 +1,14 @@
+using CoreGraphics;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
-using CoreGraphics;
using UIKit;
using Xamarin.Forms.Internals;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
+using static Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page;
+using PageUIStatusBarAnimation = Xamarin.Forms.PlatformConfiguration.iOSSpecific.UIStatusBarAnimation;
using PointF = CoreGraphics.CGPoint;
using RectangleF = CoreGraphics.CGRect;
@@ -424,6 +426,29 @@ namespace Xamarin.Forms.Platform.iOS
Current = ((NavigationPage)Element).CurrentPage;
else if (e.PropertyName == PlatformConfiguration.iOSSpecific.NavigationPage.IsNavigationBarTranslucentProperty.PropertyName)
UpdateTranslucent();
+ else if (e.PropertyName == PreferredStatusBarUpdateAnimationProperty.PropertyName)
+ UpdateCurrentPagePreferredStatusBarUpdateAnimation();
+ }
+
+ void UpdateCurrentPagePreferredStatusBarUpdateAnimation()
+ {
+ PageUIStatusBarAnimation animation = ((Page)Element).OnThisPlatform().PreferredStatusBarUpdateAnimation();
+ Current.OnThisPlatform().SetPreferredStatusBarUpdateAnimation(animation);
+ }
+
+ UIKit.UIStatusBarAnimation GetPreferredStatusBarUpdateAnimation()
+ {
+ var animation = Current.OnThisPlatform().PreferredStatusBarUpdateAnimation();
+ switch (animation)
+ {
+ case (PageUIStatusBarAnimation.Fade):
+ return UIKit.UIStatusBarAnimation.Fade;
+ case (PageUIStatusBarAnimation.Slide):
+ return UIKit.UIStatusBarAnimation.Slide;
+ case (PageUIStatusBarAnimation.None):
+ default:
+ return UIKit.UIStatusBarAnimation.None;
+ }
}
void UpdateTranslucent()
@@ -865,6 +890,14 @@ namespace Xamarin.Forms.Platform.iOS
NavigationItem.Title = Child.Title;
else if (e.PropertyName == NavigationPage.HasBackButtonProperty.PropertyName)
UpdateHasBackButton();
+ else if (e.PropertyName == PrefersStatusBarHiddenProperty.PropertyName)
+ UpdatePrefersStatusBarHidden();
+ }
+
+ void UpdatePrefersStatusBarHidden()
+ {
+ View.SetNeedsLayout();
+ ParentViewController?.View.SetNeedsLayout();
}
void TrackerOnCollectionChanged(object sender, EventArgs eventArgs)
@@ -961,6 +994,11 @@ namespace Xamarin.Forms.Platform.iOS
public override bool ShouldAutomaticallyForwardRotationMethods => true;
}
+ public override UIViewController ChildViewControllerForStatusBarHidden()
+ {
+ return (UIViewController)Platform.GetRenderer(Current);
+ }
+
void IEffectControlProvider.RegisterEffect(Effect effect)
{
var platformEffect = effect as PlatformEffect;
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs
index 94caef04..1f7408b7 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs
@@ -2,6 +2,8 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using UIKit;
+using PageUIStatusBarAnimation = Xamarin.Forms.PlatformConfiguration.iOSSpecific.UIStatusBarAnimation;
+using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
namespace Xamarin.Forms.Platform.iOS
{
@@ -75,6 +77,7 @@ namespace Xamarin.Forms.Platform.iOS
_appeared = true;
PageController.SendAppearing();
+ UpdateStatusBarPrefersHidden();
}
public override void ViewDidDisappear(bool animated)
@@ -176,6 +179,36 @@ namespace Xamarin.Forms.Platform.iOS
UpdateBackground();
else if (e.PropertyName == Page.TitleProperty.PropertyName)
UpdateTitle();
+ else if (e.PropertyName == PlatformConfiguration.iOSSpecific.Page.PrefersStatusBarHiddenProperty.PropertyName)
+ UpdateStatusBarPrefersHidden();
+ }
+
+ public override UIKit.UIStatusBarAnimation PreferredStatusBarUpdateAnimation
+ {
+ get
+ {
+ var animation = ((Page)Element).OnThisPlatform().PreferredStatusBarUpdateAnimation();
+ switch (animation)
+ {
+ case (PageUIStatusBarAnimation.Fade):
+ return UIKit.UIStatusBarAnimation.Fade;
+ case (PageUIStatusBarAnimation.Slide):
+ return UIKit.UIStatusBarAnimation.Slide;
+ case (PageUIStatusBarAnimation.None):
+ default:
+ return UIKit.UIStatusBarAnimation.None;
+ }
+ }
+ }
+
+ void UpdateStatusBarPrefersHidden()
+ {
+ var animation = ((Page)Element).OnThisPlatform().PreferredStatusBarUpdateAnimation();
+ if (animation == PageUIStatusBarAnimation.Fade || animation == PageUIStatusBarAnimation.Slide)
+ UIView.Animate(0.25, () => SetNeedsStatusBarAppearanceUpdate());
+ else
+ SetNeedsStatusBarAppearanceUpdate();
+ View.SetNeedsLayout();
}
bool OnShouldReceiveTouch(UIGestureRecognizer recognizer, UITouch touch)
@@ -188,6 +221,26 @@ namespace Xamarin.Forms.Platform.iOS
return true;
}
+ public override bool PrefersStatusBarHidden()
+ {
+ var mode = ((Page)Element).OnThisPlatform().PrefersStatusBarHidden();
+ switch (mode)
+ {
+ case (StatusBarHiddenMode.True):
+ return true;
+ case (StatusBarHiddenMode.False):
+ return false;
+ case (StatusBarHiddenMode.Default):
+ default:
+ {
+ if (Device.info.CurrentOrientation.IsLandscape())
+ return true;
+ else
+ return false;
+ }
+ }
+ }
+
void UpdateBackground()
{
string bgImage = ((Page)Element).BackgroundImage;
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs
index 17c08e75..7add5eb4 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs
@@ -2,6 +2,7 @@ using System;
using System.ComponentModel;
using System.Linq;
using UIKit;
+using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
using PointF = CoreGraphics.CGPoint;
namespace Xamarin.Forms.Platform.iOS
@@ -318,8 +319,18 @@ namespace Xamarin.Forms.Platform.iOS
_detailController.View.AddSubview(detailRenderer.NativeView);
_detailController.AddChildViewController(detailRenderer.ViewController);
+
+ SetNeedsStatusBarAppearanceUpdate();
}
+ public override UIViewController ChildViewControllerForStatusBarHidden()
+ {
+ if (((MasterDetailPage)Element).Detail != null)
+ return (UIViewController)Platform.GetRenderer(((MasterDetailPage)Element).Detail);
+ else
+ return base.ChildViewControllerForStatusBarHidden();
+ }
+
void UpdatePanGesture()
{
var model = (MasterDetailPage)Element;
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
index f9802a21..25527dfb 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
@@ -4,6 +4,8 @@ using System.Collections.Specialized;
using System.ComponentModel;
using UIKit;
using Xamarin.Forms.Internals;
+using static Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page;
+using PageUIStatusBarAnimation = Xamarin.Forms.PlatformConfiguration.iOSSpecific.UIStatusBarAnimation;
namespace Xamarin.Forms.Platform.iOS
{
@@ -241,6 +243,29 @@ namespace Xamarin.Forms.Platform.iOS
UpdateBarBackgroundColor();
else if (e.PropertyName == TabbedPage.BarTextColorProperty.PropertyName)
UpdateBarTextColor();
+ else if (e.PropertyName == PrefersStatusBarHiddenProperty.PropertyName)
+ UpdatePrefersStatusBarHiddenOnPages();
+ else if (e.PropertyName == PreferredStatusBarUpdateAnimationProperty.PropertyName)
+ UpdateCurrentPagePreferredStatusBarUpdateAnimation();
+ }
+
+ public override UIViewController ChildViewControllerForStatusBarHidden()
+ {
+ return GetViewController(Tabbed.CurrentPage);
+ }
+
+ void UpdateCurrentPagePreferredStatusBarUpdateAnimation()
+ {
+ PageUIStatusBarAnimation animation = ((Page)Element).OnThisPlatform().PreferredStatusBarUpdateAnimation();
+ Tabbed.CurrentPage.OnThisPlatform().SetPreferredStatusBarUpdateAnimation(animation);
+ }
+
+ void UpdatePrefersStatusBarHiddenOnPages()
+ {
+ for (var i = 0; i < ViewControllers.Length; i++)
+ {
+ Tabbed.GetPageByIndex(i).OnThisPlatform().SetPrefersStatusBarHidden(Tabbed.OnThisPlatform().PrefersStatusBarHidden());
+ }
}
void Reset()
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs
index a3fbd2ab..207282e7 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
using UIKit;
+using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
namespace Xamarin.Forms.Platform.iOS
{
@@ -234,6 +235,14 @@ namespace Xamarin.Forms.Platform.iOS
base.WillRotate(toInterfaceOrientation, duration);
}
+ public override UIViewController ChildViewControllerForStatusBarHidden()
+ {
+ if (((MasterDetailPage)Element).Detail != null)
+ return (UIViewController)Platform.GetRenderer(((MasterDetailPage)Element).Detail);
+ else
+ return base.ChildViewControllerForStatusBarHidden();
+ }
+
protected virtual void OnElementChanged(VisualElementChangedEventArgs e)
{
if (e.OldElement != null)