From: Paul DiPietro Date: Wed, 16 Nov 2016 10:02:54 +0000 (-0600) Subject: [iOS] Add Platform Specific features for PrefersStatusBarHidden/UIStatusBarAnimation... X-Git-Tag: beta-2.3.4-pre1~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=98235e0eea8b540ac10a71b97ee08a5842abd664;p=platform%2Fupstream%2Fxamarin-forms.git [iOS] Add Platform Specific features for PrefersStatusBarHidden/UIStatusBarAnimation (#463) * [iOS] Add Platform Specific features for PrefersStatusBarHidden/UIStatusBarAnimation * Update docs --- diff --git a/Xamarin.Forms.ControlGallery.iOS/Info.plist b/Xamarin.Forms.ControlGallery.iOS/Info.plist index 706d8bb..02d18ff 100644 --- a/Xamarin.Forms.ControlGallery.iOS/Info.plist +++ b/Xamarin.Forms.ControlGallery.iOS/Info.plist @@ -35,7 +35,7 @@ Default-568h@2x.png UIViewControllerBasedStatusBarAppearance - + NSLocationWhenInUseUsageDescription We are using your location NSLocationAlwaysUsageDescription diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageiOS.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageiOS.cs new file mode 100644 index 0000000..715fd6a --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageiOS.cs @@ -0,0 +1,178 @@ +using System.Collections.Generic; +using System.Windows.Input; +using Xamarin.Forms.PlatformConfiguration; +using Xamarin.Forms.PlatformConfiguration.iOSSpecific; + +namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries +{ + public class MasterDetailPageiOS : MasterDetailPage + { + public MasterDetailPageiOS(ICommand restore) + { + MasterBehavior = MasterBehavior.Popover; + + var master = new ContentPage { Title = "Master Detail Page" }; + var masterContent = new StackLayout { Spacing = 10, Margin = new Thickness(0, 10, 5, 0) }; + var detail = new ContentPage + { + Title = "This is the detail page's Title", + Padding = new Thickness(0,20,0,0) + }; + + var navItems = new List + { + new NavItem("Display Alert", "\uE171", new Command(() => DisplayAlert("Alert", "This is an alert", "OK"))), + new NavItem("Return To Gallery", "\uE106", restore), + new NavItem("Save", "\uE105", new Command(() => DisplayAlert("Save", "Fake save dialog", "OK"))), + new NavItem("Audio", "\uE189", new Command(() => DisplayAlert("Audio", "Never gonna give you up...", "OK"))), + new NavItem("Set Detail to Navigation Page", "\uE16F", new Command(() => Detail = CreateNavigationPage())), + new NavItem("Set Detail to Content Page", "\uE160", new Command(() => Detail = detail)), + }; + + var navList = new NavList(navItems); + + masterContent.Children.Add(navList); + master.Content = masterContent; + + var detailContent = new StackLayout { + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Center, + Children = + { + new Label + { + Text = "This is a ContentPage with StatusBarHiddenMode.True" + } + } + }; + + detail.Content = detailContent; + + Master = master; + + detail.On().SetPrefersStatusBarHidden(StatusBarHiddenMode.True); + + Detail = detail; + } + + public class NavItem + { + public NavItem(string text, string icon, ICommand command) + { + Text = text; + Icon = icon; + Command = command; + } + + public ICommand Command { get; set; } + + public string Icon { get; set; } + + public string Text { get; set; } + } + + public class NavList : ListView + { + public NavList(IEnumerable items) + { + ItemsSource = items; + ItemTapped += (sender, args) => (args.Item as NavItem)?.Command.Execute(null); + + ItemTemplate = new DataTemplate(() => + { + var grid = new Grid(); + grid.ColumnDefinitions.Add(new ColumnDefinition { Width = 48 }); + grid.ColumnDefinitions.Add(new ColumnDefinition { Width = 200 }); + + grid.Margin = new Thickness(0, 10, 0, 10); + + var text = new Label + { + VerticalOptions = LayoutOptions.Fill + }; + text.SetBinding(Label.TextProperty, "Text"); + + var glyph = new Label + { + FontSize = 24, + HorizontalTextAlignment = TextAlignment.Center + }; + + glyph.SetBinding(Label.TextProperty, "Icon"); + + grid.Children.Add(glyph); + grid.Children.Add(text); + + Grid.SetColumn(glyph, 0); + Grid.SetColumn(text, 1); + + grid.WidthRequest = 48; + + var cell = new ViewCell + { + View = grid + }; + + return cell; + }); + } + } + + static NavigationPage CreateNavigationPage() + { + var page = new NavigationPage { Title = "This is the Navigation Page Title" }; + + page.PushAsync(CreateNavSubPage()); + + return page; + } + + static ContentPage CreateNavSubPage() + { + var page = new ContentPage(); + var content = new StackLayout(); + var navigateButton = new Button() { Text = "Push Another Page" }; + + navigateButton.Clicked += (sender, args) => page.Navigation.PushAsync(CreateNavSubPage()); + + var togglePrefersStatusBarHiddenButtonForPageButton = new Button + { + Text = "Toggle PrefersStatusBarHidden for Page" + }; + var togglePreferredStatusBarUpdateAnimationButton = new Button + { + Text = "Toggle PreferredStatusBarUpdateAnimation" + }; + + togglePrefersStatusBarHiddenButtonForPageButton.Command = new Command(() => + { + var mode = page.On().PrefersStatusBarHidden(); + if (mode == StatusBarHiddenMode.Default) + page.On().SetPrefersStatusBarHidden(StatusBarHiddenMode.True); + else if (mode == StatusBarHiddenMode.True) + page.On().SetPrefersStatusBarHidden(StatusBarHiddenMode.False); + else + page.On().SetPrefersStatusBarHidden(StatusBarHiddenMode.Default); + }); + + togglePreferredStatusBarUpdateAnimationButton.Command = new Command(() => + { + var animation = page.On().PreferredStatusBarUpdateAnimation(); + if (animation == UIStatusBarAnimation.Fade) + page.On().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.Slide); + else if (animation == UIStatusBarAnimation.Slide) + page.On().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.None); + else + page.On().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.Fade); + }); + + content.Children.Add(navigateButton); + content.Children.Add(togglePrefersStatusBarHiddenButtonForPageButton); + content.Children.Add(togglePreferredStatusBarUpdateAnimationButton); + + page.Content = content; + + return page; + } + } +} diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/NavigationPageiOS.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/NavigationPageiOS.cs index 92f278b..a24aabe 100644 --- a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/NavigationPageiOS.cs +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/NavigationPageiOS.cs @@ -6,13 +6,27 @@ namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries { public class NavigationPageiOS : NavigationPage { + public NavigationPageiOS(Page root, ICommand restore) : base(root) + { + BackgroundColor = Color.Pink; + On().EnableTranslucentNavigationBar(); + CurrentPage.On().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.Fade); + } + public static NavigationPageiOS Create(ICommand restore) { var restoreButton = new Button { Text = "Back To Gallery" }; restoreButton.Clicked += (sender, args) => restore.Execute(null); var translucentToggleButton = new Button { Text = "Toggle Translucent NavBar" }; - + var togglePrefersStatusBarHiddenButton = new Button + { + Text = "Toggle PrefersStatusBarHidden" + }; + var togglePreferredStatusBarUpdateAnimationButton = new Button + { + Text = "Toggle PreferredStatusBarUpdateAnimation" + }; var content = new ContentPage { Title = "Navigation Page Features", @@ -20,7 +34,7 @@ namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, - Children = { translucentToggleButton, restoreButton } + Children = { translucentToggleButton, restoreButton, togglePrefersStatusBarHiddenButton, togglePreferredStatusBarUpdateAnimationButton} } }; @@ -28,13 +42,29 @@ namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries translucentToggleButton.Clicked += (sender, args) => navPage.On().SetIsNavigationBarTranslucent(!navPage.On().IsNavigationBarTranslucent()); - return navPage; - } + togglePrefersStatusBarHiddenButton.Command = new Command(() => + { + var mode = navPage.CurrentPage.On().PrefersStatusBarHidden(); + if (mode == StatusBarHiddenMode.Default) + navPage.CurrentPage.On().SetPrefersStatusBarHidden(StatusBarHiddenMode.True); + else if (mode == StatusBarHiddenMode.True) + navPage.CurrentPage.On().SetPrefersStatusBarHidden(StatusBarHiddenMode.False); + else + navPage.CurrentPage.On().SetPrefersStatusBarHidden(StatusBarHiddenMode.Default); + }); - public NavigationPageiOS(Page root, ICommand restore) : base(root) - { - BackgroundColor = Color.Pink; - On().EnableTranslucentNavigationBar(); + togglePreferredStatusBarUpdateAnimationButton.Command = new Command(() => + { + var animation = navPage.On().PreferredStatusBarUpdateAnimation(); + if (animation == UIStatusBarAnimation.Fade) + navPage.On().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.Slide); + else if (animation == UIStatusBarAnimation.Slide) + navPage.On().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.None); + else + navPage.On().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.Fade); + }); + + return navPage; } } } \ No newline at end of file diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/TabbedPageiOS.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/TabbedPageiOS.cs new file mode 100644 index 0000000..73cce1c --- /dev/null +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/TabbedPageiOS.cs @@ -0,0 +1,97 @@ +using System.Windows.Input; +using Xamarin.Forms.PlatformConfiguration; +using Xamarin.Forms.PlatformConfiguration.iOSSpecific; + +namespace Xamarin.Forms.Controls.GalleryPages.PlatformSpecificsGalleries +{ + public class TabbedPageiOS : TabbedPage + { + public TabbedPageiOS(ICommand restore) + { + Children.Add(CreatePage(restore, "Page One")); + Children.Add(CreatePage(restore, "Page Two")); + } + + ContentPage CreatePage(ICommand restore, string title) + { + var page = new ContentPage { + Title = title + }; + var content = new StackLayout + { + VerticalOptions = LayoutOptions.Fill, + HorizontalOptions = LayoutOptions.Fill, + Padding = new Thickness(0, 20, 0, 0) + }; + content.Children.Add(new Label + { + Text = "TabbedPage iOS Features", + FontAttributes = FontAttributes.Bold, + HorizontalTextAlignment = TextAlignment.Center, + VerticalTextAlignment = TextAlignment.Center + }); + + var togglePrefersStatusBarHiddenButton = new Button + { + Text = "Toggle PrefersStatusBarHidden for TabbedPage" + }; + var togglePrefersStatusBarHiddenForPageButton = new Button + { + Text = "Toggle PrefersStatusBarHidden for Page" + }; + var togglePreferredStatusBarUpdateAnimationButton = new Button + { + Text = "Toggle PreferredStatusBarUpdateAnimation" + }; + + togglePrefersStatusBarHiddenButton.Command = new Command(() => + { + var mode = On().PrefersStatusBarHidden(); + if (mode == StatusBarHiddenMode.Default) + On().SetPrefersStatusBarHidden(StatusBarHiddenMode.True); + else if (mode == StatusBarHiddenMode.True) + On().SetPrefersStatusBarHidden(StatusBarHiddenMode.False); + else + On().SetPrefersStatusBarHidden(StatusBarHiddenMode.Default); + }); + + togglePrefersStatusBarHiddenForPageButton.Command = new Command(() => + { + var mode = page.On().PrefersStatusBarHidden(); + if (mode == StatusBarHiddenMode.Default) + page.On().SetPrefersStatusBarHidden(StatusBarHiddenMode.True); + else if (mode == StatusBarHiddenMode.True) + page.On().SetPrefersStatusBarHidden(StatusBarHiddenMode.False); + else + page.On().SetPrefersStatusBarHidden(StatusBarHiddenMode.Default); + }); + + togglePreferredStatusBarUpdateAnimationButton.Command = new Command(() => + { + var animation = page.On().PreferredStatusBarUpdateAnimation(); + if (animation == UIStatusBarAnimation.Fade) + page.On().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.Slide); + else if (animation == UIStatusBarAnimation.Slide) + page.On().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.None); + else + page.On().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.Fade); + }); + + var restoreButton = new Button { Text = "Back To Gallery" }; + restoreButton.Clicked += (sender, args) => restore.Execute(null); + content.Children.Add(restoreButton); + content.Children.Add(togglePrefersStatusBarHiddenButton); + content.Children.Add(togglePrefersStatusBarHiddenForPageButton); + content.Children.Add(togglePreferredStatusBarUpdateAnimationButton); + content.Children.Add(new Label + { + HorizontalOptions = LayoutOptions.Center, + Text = "Note: Setting the PrefersStatusBarHidden value on a TabbedPage applies that value to all its subpages." + }); + + page.Content = content; + + return page; + } + } +} diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGallery.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGallery.cs index 2907d9b..dbfa554 100644 --- a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGallery.cs +++ b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGallery.cs @@ -8,19 +8,23 @@ namespace Xamarin.Forms.Controls public PlatformSpecificsGallery() { - var mdpWindowsButton = new Button { Text = "Master Detail Page (Windows)" }; - var npWindowsButton = new Button { Text = "Navigation Page (Windows)" }; - var tbWindowsButton = new Button { Text = "Tabbed Page (Windows)" }; - var navpageiOSButton = new Button() { Text = "Navigation Page (iOS)" }; + var mdpiOSButton = new Button { Text = "MasterDetailPage (iOS)" }; + var mdpWindowsButton = new Button { Text = "MasterDetailPage (Windows)" }; + var npiOSButton = new Button() { Text = "NavigationPage (iOS)" }; + var npWindowsButton = new Button { Text = "NavigationPage (Windows)" }; + var tbiOSButton = new Button { Text = "TabbedPage (iOS)" }; + var tbWindowsButton = new Button { Text = "TabbedPage (Windows)" }; var viselemiOSButton = new Button() { Text = "Visual Element (iOS)" }; var appAndroidButton = new Button() { Text = "Application (Android)" }; var tbAndroidButton = new Button { Text = "TabbedPage (Android)" }; var entryiOSButton = new Button() { Text = "Entry (iOS)" }; + mdpiOSButton.Clicked += (sender, args) => { SetRoot(new MasterDetailPageiOS(new Command(RestoreOriginal))); }; mdpWindowsButton.Clicked += (sender, args) => { SetRoot(new MasterDetailPageWindows(new Command(RestoreOriginal))); }; + npiOSButton.Clicked += (sender, args) => { SetRoot(NavigationPageiOS.Create(new Command(RestoreOriginal))); }; npWindowsButton.Clicked += (sender, args) => { SetRoot(new NavigationPageWindows(new Command(RestoreOriginal))); }; + tbiOSButton.Clicked += (sender, args) => { SetRoot(new TabbedPageiOS(new Command(RestoreOriginal))); }; tbWindowsButton.Clicked += (sender, args) => { SetRoot(new TabbedPageWindows(new Command(RestoreOriginal))); }; - navpageiOSButton.Clicked += (sender, args) => { SetRoot(NavigationPageiOS.Create(new Command(RestoreOriginal))); }; viselemiOSButton.Clicked += (sender, args) => { SetRoot(new VisualElementiOS(new Command(RestoreOriginal))); }; appAndroidButton.Clicked += (sender, args) => { SetRoot(new ApplicationAndroid(new Command(RestoreOriginal))); }; tbAndroidButton.Clicked += (sender, args) => { SetRoot(new TabbedPageAndroid(new Command(RestoreOriginal))); }; @@ -29,7 +33,7 @@ namespace Xamarin.Forms.Controls Content = new StackLayout { - Children = { mdpWindowsButton, npWindowsButton, tbWindowsButton, navpageiOSButton, viselemiOSButton, appAndroidButton, entryiOSButton } + Children = { mdpiOSButton, mdpWindowsButton, npWindowsButton, tbiOSButton, tbWindowsButton, viselemiOSButton, appAndroidButton, tbAndroidButton, entryiOSButton } }; } diff --git a/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj b/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj index 2fdc657..7e8e64c 100644 --- a/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj +++ b/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj @@ -100,14 +100,16 @@ ControlTemplateXamlPage.xaml - - + + + + - + diff --git a/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/Page.cs b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/Page.cs new file mode 100644 index 0000000..a32a152 --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/Page.cs @@ -0,0 +1,60 @@ +namespace Xamarin.Forms.PlatformConfiguration.iOSSpecific +{ + using FormsElement = Forms.Page; + + public static class Page + { + public static readonly BindableProperty PrefersStatusBarHiddenProperty = + BindableProperty.Create("PrefersStatusBarHidden", typeof(StatusBarHiddenMode), typeof(Page), StatusBarHiddenMode.Default); + + public static StatusBarHiddenMode GetPrefersStatusBarHidden(BindableObject element) + { + return (StatusBarHiddenMode)element.GetValue(PrefersStatusBarHiddenProperty); + } + + public static void SetPrefersStatusBarHidden(BindableObject element, StatusBarHiddenMode value) + { + element.SetValue(PrefersStatusBarHiddenProperty, value); + } + + public static StatusBarHiddenMode PrefersStatusBarHidden(this IPlatformElementConfiguration config) + { + return GetPrefersStatusBarHidden(config.Element); + } + + public static IPlatformElementConfiguration SetPrefersStatusBarHidden(this IPlatformElementConfiguration config, StatusBarHiddenMode value) + { + SetPrefersStatusBarHidden(config.Element, value); + return config; + } + + public static readonly BindableProperty PreferredStatusBarUpdateAnimationProperty = + BindableProperty.Create("PreferredStatusBarUpdateAnimation", typeof(UIStatusBarAnimation), typeof(Page), UIStatusBarAnimation.None); + + public static UIStatusBarAnimation GetPreferredStatusBarUpdateAnimation(BindableObject element) + { + return (UIStatusBarAnimation)element.GetValue(PreferredStatusBarUpdateAnimationProperty); + } + + public static void SetPreferredStatusBarUpdateAnimation(BindableObject element, UIStatusBarAnimation value) + { + if (value == UIStatusBarAnimation.Fade) + element.SetValue(PreferredStatusBarUpdateAnimationProperty, value); + else if (value == UIStatusBarAnimation.Slide) + element.SetValue(PreferredStatusBarUpdateAnimationProperty, value); + else + element.SetValue(PreferredStatusBarUpdateAnimationProperty, value); + } + + public static UIStatusBarAnimation PreferredStatusBarUpdateAnimation(this IPlatformElementConfiguration config) + { + return GetPreferredStatusBarUpdateAnimation(config.Element); + } + + public static IPlatformElementConfiguration SetPreferredStatusBarUpdateAnimation(this IPlatformElementConfiguration config, UIStatusBarAnimation value) + { + SetPreferredStatusBarUpdateAnimation(config.Element, value); + return config; + } + } +} diff --git a/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/StatusBarHiddenMode.cs b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/StatusBarHiddenMode.cs new file mode 100644 index 0000000..57c54b8 --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/StatusBarHiddenMode.cs @@ -0,0 +1,9 @@ +namespace Xamarin.Forms.PlatformConfiguration.iOSSpecific +{ + public enum StatusBarHiddenMode + { + Default, + True, + False + } +} diff --git a/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/UIStatusBarAnimation.cs b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/UIStatusBarAnimation.cs new file mode 100644 index 0000000..ac594d1 --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/UIStatusBarAnimation.cs @@ -0,0 +1,9 @@ +namespace Xamarin.Forms.PlatformConfiguration.iOSSpecific +{ + public enum UIStatusBarAnimation + { + None, + Slide, + Fade + } +} diff --git a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj index 48bed53..eae36a4 100644 --- a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj +++ b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj @@ -94,6 +94,9 @@ + + + diff --git a/Xamarin.Forms.Platform.iOS/Platform.cs b/Xamarin.Forms.Platform.iOS/Platform.cs index 8db28f6..762ccf0 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 f2d897e..5767c18 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 fdbd116..676c73a 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 94caef0..1f7408b 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 17c08e7..7add5eb 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 f9802a2..25527df 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 a3fbd2a..207282e 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) diff --git a/docs/Xamarin.Forms.Core/Xamarin.Forms.PlatformConfiguration.iOSSpecific/Page.xml b/docs/Xamarin.Forms.Core/Xamarin.Forms.PlatformConfiguration.iOSSpecific/Page.xml new file mode 100644 index 0000000..d348143 --- /dev/null +++ b/docs/Xamarin.Forms.Core/Xamarin.Forms.PlatformConfiguration.iOSSpecific/Page.xml @@ -0,0 +1,214 @@ + + + + + Xamarin.Forms.Core + 2.0.0.0 + + + System.Object + + + + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + Xamarin.Forms.PlatformConfiguration.iOSSpecific.UIStatusBarAnimation + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + Xamarin.Forms.PlatformConfiguration.iOSSpecific.StatusBarHiddenMode + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + Xamarin.Forms.PlatformConfiguration.iOSSpecific.UIStatusBarAnimation + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Field + + 2.0.0.0 + + + Xamarin.Forms.BindableProperty + + + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + Xamarin.Forms.PlatformConfiguration.iOSSpecific.StatusBarHiddenMode + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Field + + 2.0.0.0 + + + Xamarin.Forms.BindableProperty + + + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + System.Void + + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + Xamarin.Forms.IPlatformElementConfiguration<Xamarin.Forms.PlatformConfiguration.iOS,Xamarin.Forms.Page> + + + + + + + To be added. + To be added. + To be added. + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + System.Void + + + + + + + To be added. + To be added. + To be added. + To be added. + + + + + + Method + + 2.0.0.0 + + + Xamarin.Forms.IPlatformElementConfiguration<Xamarin.Forms.PlatformConfiguration.iOS,Xamarin.Forms.Page> + + + + + + + To be added. + To be added. + To be added. + To be added. + To be added. + + + + diff --git a/docs/Xamarin.Forms.Core/Xamarin.Forms.PlatformConfiguration.iOSSpecific/StatusBarHiddenMode.xml b/docs/Xamarin.Forms.Core/Xamarin.Forms.PlatformConfiguration.iOSSpecific/StatusBarHiddenMode.xml new file mode 100644 index 0000000..c75e044 --- /dev/null +++ b/docs/Xamarin.Forms.Core/Xamarin.Forms.PlatformConfiguration.iOSSpecific/StatusBarHiddenMode.xml @@ -0,0 +1,59 @@ + + + + + Xamarin.Forms.Core + 2.0.0.0 + + + System.Enum + + + To be added. + To be added. + + + + + + Field + + 2.0.0.0 + + + Xamarin.Forms.PlatformConfiguration.iOSSpecific.StatusBarHiddenMode + + + To be added. + + + + + + Field + + 2.0.0.0 + + + Xamarin.Forms.PlatformConfiguration.iOSSpecific.StatusBarHiddenMode + + + To be added. + + + + + + Field + + 2.0.0.0 + + + Xamarin.Forms.PlatformConfiguration.iOSSpecific.StatusBarHiddenMode + + + To be added. + + + + diff --git a/docs/Xamarin.Forms.Core/Xamarin.Forms.PlatformConfiguration.iOSSpecific/UIStatusBarAnimation.xml b/docs/Xamarin.Forms.Core/Xamarin.Forms.PlatformConfiguration.iOSSpecific/UIStatusBarAnimation.xml new file mode 100644 index 0000000..bdef4ff --- /dev/null +++ b/docs/Xamarin.Forms.Core/Xamarin.Forms.PlatformConfiguration.iOSSpecific/UIStatusBarAnimation.xml @@ -0,0 +1,59 @@ + + + + + Xamarin.Forms.Core + 2.0.0.0 + + + System.Enum + + + To be added. + To be added. + + + + + + Field + + 2.0.0.0 + + + Xamarin.Forms.PlatformConfiguration.iOSSpecific.UIStatusBarAnimation + + + To be added. + + + + + + Field + + 2.0.0.0 + + + Xamarin.Forms.PlatformConfiguration.iOSSpecific.UIStatusBarAnimation + + + To be added. + + + + + + Field + + 2.0.0.0 + + + Xamarin.Forms.PlatformConfiguration.iOSSpecific.UIStatusBarAnimation + + + To be added. + + + +