summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls
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.Controls
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.Controls')
-rw-r--r--Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageiOS.cs178
-rw-r--r--Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/NavigationPageiOS.cs46
-rw-r--r--Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/TabbedPageiOS.cs97
-rw-r--r--Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGallery.cs16
-rw-r--r--Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj8
5 files changed, 328 insertions, 17 deletions
diff --git a/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageiOS.cs b/Xamarin.Forms.Controls/GalleryPages/PlatformSpecificsGalleries/MasterDetailPageiOS.cs
new file mode 100644
index 00000000..715fd6a1
--- /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<NavItem>
+ {
+ 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<iOS>().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<NavItem> 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<iOS>().PrefersStatusBarHidden();
+ if (mode == StatusBarHiddenMode.Default)
+ page.On<iOS>().SetPrefersStatusBarHidden(StatusBarHiddenMode.True);
+ else if (mode == StatusBarHiddenMode.True)
+ page.On<iOS>().SetPrefersStatusBarHidden(StatusBarHiddenMode.False);
+ else
+ page.On<iOS>().SetPrefersStatusBarHidden(StatusBarHiddenMode.Default);
+ });
+
+ togglePreferredStatusBarUpdateAnimationButton.Command = new Command(() =>
+ {
+ var animation = page.On<iOS>().PreferredStatusBarUpdateAnimation();
+ if (animation == UIStatusBarAnimation.Fade)
+ page.On<iOS>().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.Slide);
+ else if (animation == UIStatusBarAnimation.Slide)
+ page.On<iOS>().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.None);
+ else
+ page.On<iOS>().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 92f278bb..a24aabe6 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<iOS>().EnableTranslucentNavigationBar();
+ CurrentPage.On<iOS>().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<iOS>().SetIsNavigationBarTranslucent(!navPage.On<iOS>().IsNavigationBarTranslucent());
- return navPage;
- }
+ togglePrefersStatusBarHiddenButton.Command = new Command(() =>
+ {
+ var mode = navPage.CurrentPage.On<iOS>().PrefersStatusBarHidden();
+ if (mode == StatusBarHiddenMode.Default)
+ navPage.CurrentPage.On<iOS>().SetPrefersStatusBarHidden(StatusBarHiddenMode.True);
+ else if (mode == StatusBarHiddenMode.True)
+ navPage.CurrentPage.On<iOS>().SetPrefersStatusBarHidden(StatusBarHiddenMode.False);
+ else
+ navPage.CurrentPage.On<iOS>().SetPrefersStatusBarHidden(StatusBarHiddenMode.Default);
+ });
- public NavigationPageiOS(Page root, ICommand restore) : base(root)
- {
- BackgroundColor = Color.Pink;
- On<iOS>().EnableTranslucentNavigationBar();
+ togglePreferredStatusBarUpdateAnimationButton.Command = new Command(() =>
+ {
+ var animation = navPage.On<iOS>().PreferredStatusBarUpdateAnimation();
+ if (animation == UIStatusBarAnimation.Fade)
+ navPage.On<iOS>().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.Slide);
+ else if (animation == UIStatusBarAnimation.Slide)
+ navPage.On<iOS>().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.None);
+ else
+ navPage.On<iOS>().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 00000000..73cce1c9
--- /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<iOS>().PrefersStatusBarHidden();
+ if (mode == StatusBarHiddenMode.Default)
+ On<iOS>().SetPrefersStatusBarHidden(StatusBarHiddenMode.True);
+ else if (mode == StatusBarHiddenMode.True)
+ On<iOS>().SetPrefersStatusBarHidden(StatusBarHiddenMode.False);
+ else
+ On<iOS>().SetPrefersStatusBarHidden(StatusBarHiddenMode.Default);
+ });
+
+ togglePrefersStatusBarHiddenForPageButton.Command = new Command(() =>
+ {
+ var mode = page.On<iOS>().PrefersStatusBarHidden();
+ if (mode == StatusBarHiddenMode.Default)
+ page.On<iOS>().SetPrefersStatusBarHidden(StatusBarHiddenMode.True);
+ else if (mode == StatusBarHiddenMode.True)
+ page.On<iOS>().SetPrefersStatusBarHidden(StatusBarHiddenMode.False);
+ else
+ page.On<iOS>().SetPrefersStatusBarHidden(StatusBarHiddenMode.Default);
+ });
+
+ togglePreferredStatusBarUpdateAnimationButton.Command = new Command(() =>
+ {
+ var animation = page.On<iOS>().PreferredStatusBarUpdateAnimation();
+ if (animation == UIStatusBarAnimation.Fade)
+ page.On<iOS>().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.Slide);
+ else if (animation == UIStatusBarAnimation.Slide)
+ page.On<iOS>().SetPreferredStatusBarUpdateAnimation(UIStatusBarAnimation.None);
+ else
+ page.On<iOS>().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 2907d9b7..dbfa554c 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 2fdc657a..7e8e64c5 100644
--- a/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj
+++ b/Xamarin.Forms.Controls/Xamarin.Forms.Controls.csproj
@@ -100,14 +100,16 @@
<DependentUpon>ControlTemplateXamlPage.xaml</DependentUpon>
</Compile>
<Compile Include="GalleryPages\LayoutPerformanceGallery.cs" />
- <Compile Include="GalleryPages\PlatformSpecificsGalleries\EntryPageiOS.cs" />
- <Compile Include="GalleryPages\PlatformSpecificsGalleries\MasterDetailPageWindows.cs" />
<Compile Include="GalleryPages\NavigationPropertiesGallery.cs" />
<Compile Include="ControlGalleryPages\ListViewSelectionColor.cs" />
+ <Compile Include="GalleryPages\PlatformSpecificsGalleries\ApplicationAndroid.cs" />
+ <Compile Include="GalleryPages\PlatformSpecificsGalleries\EntryPageiOS.cs" />
+ <Compile Include="GalleryPages\PlatformSpecificsGalleries\MasterDetailPageiOS.cs" />
+ <Compile Include="GalleryPages\PlatformSpecificsGalleries\MasterDetailPageWindows.cs" />
<Compile Include="GalleryPages\PlatformSpecificsGalleries\NavigationPageiOS.cs" />
<Compile Include="GalleryPages\PlatformSpecificsGalleries\NavigationPageWindows.cs" />
- <Compile Include="GalleryPages\PlatformSpecificsGalleries\ApplicationAndroid.cs" />
<Compile Include="GalleryPages\PlatformSpecificsGalleries\TabbedPageAndroid.cs" />
+ <Compile Include="GalleryPages\PlatformSpecificsGalleries\TabbedPageiOS.cs" />
<Compile Include="GalleryPages\PlatformSpecificsGalleries\TabbedPageWindows.cs" />
<Compile Include="GalleryPages\PlatformSpecificsGalleries\VisualElementiOS.cs" />
<Compile Include="GalleryPages\PlatformSpecificsGalleries\WindowsPlatformSpecificsGalleryHelpers.cs" />