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

Commit 000000c

Browse files
[iOS] Allow VC renderers of FlyoutPage to specify UIStatusBarStyle (#13143)
* [Controls] Add reproduction sample for issue #13053 * [iOS] Internal ChildViewController should specify the real renderer to override StatusBarStyle * Update Xamarin.Forms.ControlGallery.iOS.csproj * [iOS] Use index to find the correct ChildViewControllers Co-authored-by: Javier Suárez <[email protected]>
1 parent 2822e79 commit 000000c

File tree

6 files changed

+55
-7
lines changed

6 files changed

+55
-7
lines changed

Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using UIKit;
1010
using Xamarin.Forms;
1111
using Xamarin.Forms.ControlGallery.iOS;
12+
using Xamarin.Forms.ControlGallery.iOS.CustomRenderers;
1213
using Xamarin.Forms.Controls;
1314
using Xamarin.Forms.Controls.Issues;
1415
using Xamarin.Forms.Platform.iOS;
@@ -17,6 +18,8 @@
1718
[assembly: Dependency(typeof(TestCloudService))]
1819
[assembly: Dependency(typeof(CacheService))]
1920
[assembly: ExportRenderer(typeof(DisposePage), typeof(DisposePageRenderer))]
21+
[assembly: ExportRenderer(typeof(CoreFlyoutView), typeof(FlyoutPageStatusRenderer))]
22+
[assembly: ExportRenderer(typeof(CoreNavigationPage), typeof(DetailPageStatusBarRenderer))]
2023
[assembly: ExportRenderer(typeof(DisposeLabel), typeof(DisposeLabelRenderer))]
2124
[assembly: ExportEffect(typeof(BorderEffect), nameof(BorderEffect))]
2225
namespace Xamarin.Forms.ControlGallery.iOS
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using UIKit;
2+
using Xamarin.Forms.Platform.iOS;
3+
4+
namespace Xamarin.Forms.ControlGallery.iOS.CustomRenderers
5+
{
6+
public class DetailPageStatusBarRenderer : NavigationRenderer
7+
{
8+
public override UIStatusBarStyle PreferredStatusBarStyle()
9+
{
10+
return UIStatusBarStyle.DarkContent;
11+
}
12+
}
13+
14+
public class FlyoutPageStatusRenderer : PageRenderer
15+
{
16+
public override UIStatusBarStyle PreferredStatusBarStyle()
17+
{
18+
return UIStatusBarStyle.LightContent;
19+
}
20+
}
21+
22+
}

Xamarin.Forms.ControlGallery.iOS/Xamarin.Forms.ControlGallery.iOS.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
<Compile Include="CustomEffects\FooEffect.cs" />
146146
<Compile Include="_10337CustomRenderer.cs" />
147147
<Compile Include="_11132CustomRenderer.cs" />
148+
<Compile Include="CustomRenderers\UIStatusBarStyleRenderer.cs" />
148149
<Compile Include="CustomRenderers\_12372CustomRenderer.cs" />
149150
<Compile Include="CustomRenderers\_DemoShellPageCustomRenderer.cs" />
150151
<Compile Include="CustomRenderers\_ModalShellPageCustomRenderer.cs" />

Xamarin.Forms.Controls/App.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,13 @@ async Task TestMainPageSwitches()
109109

110110
public Page CreateDefaultMainPage()
111111
{
112-
var layout = new StackLayout { BackgroundColor = Color.Red };
113-
layout.Children.Add(new Label { Text = "This is master Page" });
114-
var master = new ContentPage { Title = "Flyout", Content = layout, BackgroundColor = Color.SkyBlue, IconImageSource = "menuIcon" };
115-
master.On<iOS>().SetUseSafeArea(true);
116112
var mdp = new FlyoutPage
117113
{
118114
AutomationId = DefaultMainPageId,
119-
Flyout = master,
115+
Flyout = CoreGallery.GetFlyoutPage(),
120116
Detail = CoreGallery.GetMainPage()
121117
};
122-
master.IconImageSource.AutomationId = "btnMDPAutomationID";
118+
123119
mdp.SetAutomationPropertiesName("Main page");
124120
mdp.SetAutomationPropertiesHelpText("Main page help text");
125121
mdp.Flyout.IconImageSource.SetAutomationPropertiesHelpText("This as MDP icon");

Xamarin.Forms.Controls/CoreGallery.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,23 @@ public CoreFlyoutPage()
8181
Detail = detailPage;
8282
}
8383
}
84+
8485
[Preserve(AllMembers = true)]
85-
internal class CoreNavigationPage : NavigationPage
86+
public class CoreFlyoutView : ContentPage
87+
{
88+
public CoreFlyoutView()
89+
{
90+
On<iOS>().SetUseSafeArea(true);
91+
Title = "Flyout";
92+
Content = new StackLayout { BackgroundColor = Color.Red, Children = { new Label { Text = "This is master Page" } } };
93+
BackgroundColor = Color.SkyBlue;
94+
IconImageSource = "menuIcon";
95+
IconImageSource.AutomationId = "btnMDPAutomationID";
96+
}
97+
}
98+
99+
[Preserve(AllMembers = true)]
100+
public class CoreNavigationPage : NavigationPage
86101
{
87102
public CoreNavigationPage()
88103
{
@@ -668,5 +683,10 @@ public static Page GetMainPage()
668683
{
669684
return new CoreNavigationPage();
670685
}
686+
687+
public static Page GetFlyoutPage()
688+
{
689+
return new CoreFlyoutView();
690+
}
671691
}
672692
}

Xamarin.Forms.Platform.iOS/Renderers/TabletFlyoutPageRenderer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel;
3+
using System.Linq;
34
using CoreGraphics;
45
using Foundation;
56
using UIKit;
@@ -13,6 +14,11 @@ public override void ViewDidLayoutSubviews()
1314
foreach (var vc in ChildViewControllers)
1415
vc.View.Frame = View.Bounds;
1516
}
17+
18+
public override UIViewController ChildViewControllerForStatusBarStyle()
19+
{
20+
return ChildViewControllers.Length > 0 ? ChildViewControllers[0] : base.ChildViewControllerForStatusBarStyle();
21+
}
1622
}
1723

1824
internal class EventedViewController : ChildViewController

0 commit comments

Comments
 (0)