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

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

Merged
merged 2 commits into from
Nov 16, 2016

Conversation

pauldipietro
Copy link
Contributor

@pauldipietro 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):
Copy link
Contributor

@adrianknight89 adrianknight89 Oct 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be turned into a ternary statement.

{
Default,
True,
False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NULLABLE BOOL !!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@rmarinho
Copy link
Member

Needs rebase

@pauldipietro pauldipietro force-pushed the ios-ps-prefersstatusbarhidden branch from 097675c to edd0553 Compare October 24, 2016 21:35
@pauldipietro
Copy link
Contributor Author

Rebased

@rmarinho
Copy link
Member

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

}

public override UIViewController ChildViewControllerForStatusBarHidden()
{
return (UIViewController)Platform.GetRenderer(((MasterDetailPage)Element).Detail);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

{
Default,
True,
False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@pauldipietro pauldipietro force-pushed the ios-ps-prefersstatusbarhidden branch from edd0553 to 30a46ad Compare October 25, 2016 15:45
@adrianknight89
Copy link
Contributor

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants