Skip to content

Commit

Permalink
Added a sample (dotnet#19970)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubaflo committed Apr 5, 2024
1 parent ced005b commit 65f7227
Show file tree
Hide file tree
Showing 2 changed files with 255 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
x:Class="Maui.Controls.Sample.Pages.iOSHideHomeIndicatorPage"
Title="Hide Home Indicator"
ios:Page.PrefersHomeIndicatorAutoHidden="true">
<StackLayout Margin="20,35,20,20">
<Label Text="Tap the button below to toggle the home indicator on iPhone X, XR, and XS models." />
<Button Text="Toggle Home Indicator"
Clicked="OnButtonClicked" />
Title="Hide Home Indicator">
<StackLayout>
<Button Text="Navigation page" Clicked="NavigationPage_Clicked"/>
<Button Text="Tabbed page" Clicked="TabbedPage_Clicked"/>
<Button Text="Flyout page" Clicked="FlyoutPage_Clicked"/>
<Button Text="Shell" Clicked="Shell_Clicked"/>
</StackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,255 @@ public iOSHideHomeIndicatorPage()
InitializeComponent();
}

void OnButtonClicked(object sender, EventArgs e)
void NavigationPage_Clicked(object sender, EventArgs e)
{
On<iOS>().SetPrefersHomeIndicatorAutoHidden(!On<iOS>().PrefersHomeIndicatorAutoHidden());
Navigation.PushAsync(new iOSHideHomeIndicatorNavigationPageDemo());
}

void TabbedPage_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new iOSHideHomeIndicatorPageDemo());
}

void FlyoutPage_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new iOSHideHomeIndicatorFlyoutPageDemo());
}

void Shell_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new iOSHideHomeIndicatorShellDemo());
}
}

public class iOSHideHomeIndicatorNavigationPageDemo : ContentPage
{
public iOSHideHomeIndicatorNavigationPageDemo()
{
Content = new StackLayout()
{
Margin = new Microsoft.Maui.Thickness(20),
Children = {
new Button()
{
Text = "Toggle Home Indicator",
Command = new Command(() => On<iOS>().SetPrefersHomeIndicatorAutoHidden(!On<iOS>().PrefersHomeIndicatorAutoHidden()))
},
new Button()
{
Text = "Navigate back",
Command = new Command(() => Navigation.PopAsync())
}
}
};
}
}

public class iOSHideHomeIndicatorFlyoutPageDemo : Microsoft.Maui.Controls.FlyoutPage
{
public iOSHideHomeIndicatorFlyoutPageDemo()
{
Flyout = new ContentPage()
{
Title = "Detail",
Content = new StackLayout()
{
Children = {
new Button()
{
Text = "Open page 1",
Command = new Command(() => Detail = OpenPage("Page 1"))
},
new Button()
{
Text = "Open page 2",
Command = new Command(() => Detail = OpenPage("Page 2"))
}
}
}
};

Detail = OpenPage("Page 1");
}

public ContentPage OpenPage(string title)
{
return new ContentPage()
{
Title = title,
Content = new StackLayout()
{
Margin = new Microsoft.Maui.Thickness(20),
Children = {
new Button
{
Text = "Toggle Home Indicator",
Command = new Command(() => On<iOS>().SetPrefersHomeIndicatorAutoHidden(!On<iOS>().PrefersHomeIndicatorAutoHidden()))
},
new Button()
{
Text = "Click to open the flyout",
Command = new Command(() => IsPresented = true)
},
new Button
{
VerticalOptions = LayoutOptions.End,
Text = "Back",
Command = new Command(() => Navigation.PopAsync())
}
}
}
};
}
}

public class iOSHideHomeIndicatorPageDemo : Microsoft.Maui.Controls.TabbedPage
{
public iOSHideHomeIndicatorPageDemo()
{

Children.Add
(
new ContentPage()
{
Title = "Tab 1",
Content = new StackLayout()
{
Margin = new Microsoft.Maui.Thickness(20),
Children =
{
new Button()
{
Text = "Toggle Home Indicator",
Command = new Command(() => On<iOS>().SetPrefersHomeIndicatorAutoHidden(!On<iOS>().PrefersHomeIndicatorAutoHidden()))
},
new Button()
{
Text = "Navigate back",
Command = new Command(() => Navigation.PopAsync())
}
}
}
}
);

Children.Add
(
new ContentPage()
{
Title = "Tab 2",
Content = new StackLayout()
{
Margin = new Microsoft.Maui.Thickness(20),
Children =
{
new Button()
{
Text = "Toggle Home Indicator",
Command = new Command(() => On<iOS>().SetPrefersHomeIndicatorAutoHidden(!On<iOS>().PrefersHomeIndicatorAutoHidden()))
},
new Button()
{
Text = "Navigate back",
Command = new Command(() => Navigation.PopAsync())
}
}
}
}
);

}
}

public class iOSHideHomeIndicatorShellDemo : Shell
{
public iOSHideHomeIndicatorShellDemo()
{
TabBar tabBar = new TabBar();

var toggleHomeIndicatorButton1 = new Button()
{
Text = "Toggle Home Indicator",
Command = new Command(() => On<iOS>().SetPrefersHomeIndicatorAutoHidden(!On<iOS>().PrefersHomeIndicatorAutoHidden()))
};

var contentPage1 = new ContentPage
{
Title = "Shell Tab 1",
Content = new StackLayout()
{
Margin = new Microsoft.Maui.Thickness(20),
Children =
{
toggleHomeIndicatorButton1,
new Button()
{
Text = "Navigate back",
Command = new Command(() => Navigation.PopAsync())
}
}
}
};

toggleHomeIndicatorButton1.Command = new Command(() => contentPage1.On<iOS>().SetPrefersHomeIndicatorAutoHidden(!On<iOS>().PrefersHomeIndicatorAutoHidden()));

tabBar.Items.Add
(
new Tab
{
Title = "Shell Tab 1",
Items = {
new ShellContent
{
Content = contentPage1,
Title = "Shell Tab 1",
}
}
}
);

var toggleHomeIndicatorButton2 = new Button()
{
Text = "Toggle Home Indicator",
Command = new Command(() => On<iOS>().SetPrefersHomeIndicatorAutoHidden(!On<iOS>().PrefersHomeIndicatorAutoHidden()))
};

var contentPage2 = new ContentPage
{
Title = "Shell Tab 2",
Content = new StackLayout()
{
Margin = new Microsoft.Maui.Thickness(20),
Children =
{
toggleHomeIndicatorButton2,
new Button()
{
Text = "Navigate back",
Command = new Command(() => Navigation.PopAsync())
}
}
}
};

toggleHomeIndicatorButton2.Command = new Command(() => contentPage2.On<iOS>().SetPrefersHomeIndicatorAutoHidden(!On<iOS>().PrefersHomeIndicatorAutoHidden()));

tabBar.Items.Add
(
new Tab
{
Title = "Shell Tab 2",
Items = {
new ShellContent
{
Content = contentPage2,
Title = "Shell Tab 2",
}
}
}
);

Items.Add(tabBar);
}
}
}

0 comments on commit 65f7227

Please sign in to comment.