Skip to content
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] Implemented PrefersHomeIndicatorAutoHidden, PrefersStatusBarHidden and PreferredStatusBarUpdateAnimation Platform Specifics #20069

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added a sample (#19970)
  • Loading branch information
kubaflo committed Apr 5, 2024
commit 65f7227eb192843a00201b429ab618c3a69bb606
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);
}
}
}