New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Add Platform Specific features for PrefersStatusBarHidden/UIStatusBarAnimation #463

Merged
merged 2 commits into from Nov 16, 2016

Conversation

@pauldipietro
Member

pauldipietro commented Oct 16, 2016

Description of Change

This is a Platform Specific feature which enables setting the visibility of the iOS status bar on a per-view basis. See some examples below:

output_1iqobs
output_qnofag
output_yi11ig

This is accomplished through the StatusBarHiddenMode and UIStatusBarAnimation enumerators, which contain the following values:

StatusBarHiddenMode.Default
StatusBarHiddenMode.True
StatusBarHiddenMode.False

UIStatusBarAnimation.None
UIStatusBarAnimation.Fade
UIStatusBarAnimation.Slide

Per Apple's documentation, since iOS 8 the prefersStatusBarHidden method returns true on vertically compact environments. This represents the StatusBarHiddenMode.Default value, while the latter two apply the respective values to both the vertical and landscape orientations. This can be set as follows, for example:

page.On<iOS>().PrefersStatusBarHidden(StatusBarHiddenMode.True)

As one might guess, the UIStatusBarAnimation values represent the three possible manners by which the status bar can enter or leave the view. If a Fade or Slide value is set, a 0.25 second animation of setNeedsStatusBarAppearanceUpdate will execute. That can be used like so:

page.On<iOS>().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.Fade)

Starting with the Page value on the Platform (which has been subsequently marked as internal in order for the PlatformRenderer to get at it), childViewControllerForStatusBarHidden is utilized to redirect the views down to PageRenderer as a baseline for setting the values on a per-view basis. An exception is that in a TabbedPage, setting the PrefersStatusBarHidden value directly on that page will update all of its contained pages.

As of this submission, tests can still be added, though they may be somewhat complex due to the need to check the status bar -- screenshots might be preferable.

Bugs Fixed

This was technically not a bug, per se, but was reported under https://bugzilla.xamarin.com/show_bug.cgi?id=44803.

API Changes

Added:

  • public static readonly BindableProperty PrefersStatusBarHiddenProperty
  • public static StatusBarHiddenMode GetPrefersStatusBarHidden(BindableObject element)
  • public static void SetPrefersStatusBarHidden(BindableObject element, StatusBarHiddenMode value)
  • public static StatusBarHiddenMode PrefersStatusBarHidden(this IPlatformElementConfiguration<iOS, FormsElement> config)
  • public static IPlatformElementConfiguration<iOS, FormsElement> SetPrefersStatusBarHidden(this IPlatformElementConfiguration<iOS, FormsElement> config, StatusBarHiddenMode value)
  • public static readonly BindableProperty PreferredStatusBarUpdateAnimationProperty
  • public static UIStatusBarAnimation GetPreferredStatusBarUpdateAnimation(BindableObject element)
  • public static void SetPreferredStatusBarUpdateAnimation(BindableObject element, UIStatusBarAnimation value)
  • public static UIStatusBarAnimation PreferredStatusBarUpdateAnimation(this IPlatformElementConfiguration<iOS, FormsElement> config)
  • public static IPlatformElementConfiguration<iOS, FormsElement> SetPreferredStatusBarUpdateAnimation(this IPlatformElementConfiguration<iOS, FormsElement> config, UIStatusBarAnimation value)

Changed:

  • Page page => internal Page Page { get; set; }

Behavioral Changes

N/A

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Consolidate commits as makes sense
return true;
case (StatusBarHiddenMode.False):
return false;
case (StatusBarHiddenMode.Default):

This comment has been minimized.

@adrianknight89

adrianknight89 Oct 17, 2016

Contributor

I think this line is unnecessary in switch default. I could see similar things in other switch blocks.

@adrianknight89

adrianknight89 Oct 17, 2016

Contributor

I think this line is unnecessary in switch default. I could see similar things in other switch blocks.

if (Device.info.CurrentOrientation.IsLandscape())
return true;
else
return false;

This comment has been minimized.

@adrianknight89

adrianknight89 Oct 17, 2016

Contributor

This could be turned into a ternary statement.

@adrianknight89

adrianknight89 Oct 17, 2016

Contributor

This could be turned into a ternary statement.

{
Default,
True,
False

This comment has been minimized.

@StephaneDelcroix

StephaneDelcroix Oct 20, 2016

Member

NULLABLE BOOL !!!

@StephaneDelcroix

StephaneDelcroix Oct 20, 2016

Member

NULLABLE BOOL !!!

This comment has been minimized.

@rmarinho

rmarinho Oct 25, 2016

Member

i like this API more so user understands that Default is default .. and not null ..

@rmarinho

rmarinho Oct 25, 2016

Member

i like this API more so user understands that Default is default .. and not null ..

@rmarinho

This comment has been minimized.

Show comment
Hide comment
@rmarinho

rmarinho Oct 24, 2016

Member

Needs rebase

Member

rmarinho commented Oct 24, 2016

Needs rebase

@pauldipietro

This comment has been minimized.

Show comment
Hide comment
@pauldipietro

pauldipietro Oct 24, 2016

Member

Rebased

Member

pauldipietro commented Oct 24, 2016

Rebased

@rmarinho

This comment has been minimized.

Show comment
Hide comment
@rmarinho

rmarinho Oct 25, 2016

Member

@pauldipietro this is failing , please check the build logs. and make sure this builds ok :)

Member

rmarinho commented Oct 25, 2016

@pauldipietro this is failing , please check the build logs. and make sure this builds ok :)

Show outdated Hide outdated Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs
}
public override UIViewController ChildViewControllerForStatusBarHidden()
{
return (UIViewController)Platform.GetRenderer(((MasterDetailPage)Element).Detail);

This comment has been minimized.

@rmarinho

rmarinho Oct 25, 2016

Member

Are we sure there always a detail renderer at this time?
i wonder if while switching detail pages could have a case where the renderer isn't created yet for the Detail element, this will blow up with NRE.
Maybe add a check and return base if no renderer is there.

@rmarinho

rmarinho Oct 25, 2016

Member

Are we sure there always a detail renderer at this time?
i wonder if while switching detail pages could have a case where the renderer isn't created yet for the Detail element, this will blow up with NRE.
Maybe add a check and return base if no renderer is there.

Show outdated Hide outdated Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs
@@ -234,6 +235,11 @@ public override void WillRotate(UIInterfaceOrientation toInterfaceOrientation, d
base.WillRotate(toInterfaceOrientation, duration);
}
public override UIViewController ChildViewControllerForStatusBarHidden()
{
return (UIViewController)Platform.GetRenderer(((MasterDetailPage)Element).Detail);

This comment has been minimized.

@rmarinho

rmarinho Oct 25, 2016

Member

same comment as above

@rmarinho

rmarinho Oct 25, 2016

Member

same comment as above

{
Default,
True,
False

This comment has been minimized.

@rmarinho

rmarinho Oct 25, 2016

Member

i like this API more so user understands that Default is default .. and not null ..

@rmarinho

rmarinho Oct 25, 2016

Member

i like this API more so user understands that Default is default .. and not null ..

@adrianknight89

This comment has been minimized.

Show comment
Hide comment

@rmarinho rmarinho removed the needs-changes label Nov 16, 2016

@rmarinho rmarinho merged commit 98235e0 into master Nov 16, 2016

1 of 5 checks passed

Android-UITests Finished TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: UI Tests :: OSX Test Cloud Package - Run Android 6.0.1 : Exit code 1
Details
OSX-Debug-C8 Finished TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: OSX Debug : Exit code 1
Details
iOS10-UITests Finished TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: UI Tests :: OSX Test Cloud Package - Run iOS Unified iOS10 : Exit code 1
Details
iOS9-UITests Finished TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: UI Tests :: OSX Test Cloud Package - Run iOS Unified iOS9 : Exit code 1
Details
Windows-Debug-C8 Finished TeamCity Build Xamarin.Forms :: Debug :: Cycle9 :: Windows Debug : Tests passed: 3458, ignored: 8
Details

@samhouts samhouts referenced this pull request Mar 24, 2017

Merged

[iOS] Prevent NRE when page is switched on Appearing #840

4 of 4 tasks complete

@rmarinho rmarinho deleted the ios-ps-prefersstatusbarhidden branch Jun 22, 2017

@pauldipietro pauldipietro referenced this pull request Nov 1, 2017

Merged

[iOS] Fixes for iOS11 #1238

2 of 4 tasks complete

@samhouts samhouts added this to the 2.3.4 milestone Jun 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment