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

Commit

Permalink
[iOS] Allow VC renderers of FlyoutPage to specify UIStatusBarStyle (#…
Browse files Browse the repository at this point in the history
…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 <javiersuarezruiz@hotmail.com>
  • Loading branch information
rmarinho and jsuarezruiz authored Jan 14, 2022
1 parent 2822e79 commit 000000c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.ControlGallery.iOS;
using Xamarin.Forms.ControlGallery.iOS.CustomRenderers;
using Xamarin.Forms.Controls;
using Xamarin.Forms.Controls.Issues;
using Xamarin.Forms.Platform.iOS;
Expand All @@ -17,6 +18,8 @@
[assembly: Dependency(typeof(TestCloudService))]
[assembly: Dependency(typeof(CacheService))]
[assembly: ExportRenderer(typeof(DisposePage), typeof(DisposePageRenderer))]
[assembly: ExportRenderer(typeof(CoreFlyoutView), typeof(FlyoutPageStatusRenderer))]
[assembly: ExportRenderer(typeof(CoreNavigationPage), typeof(DetailPageStatusBarRenderer))]
[assembly: ExportRenderer(typeof(DisposeLabel), typeof(DisposeLabelRenderer))]
[assembly: ExportEffect(typeof(BorderEffect), nameof(BorderEffect))]
namespace Xamarin.Forms.ControlGallery.iOS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using UIKit;
using Xamarin.Forms.Platform.iOS;

namespace Xamarin.Forms.ControlGallery.iOS.CustomRenderers
{
public class DetailPageStatusBarRenderer : NavigationRenderer
{
public override UIStatusBarStyle PreferredStatusBarStyle()
{
return UIStatusBarStyle.DarkContent;
}
}

public class FlyoutPageStatusRenderer : PageRenderer
{
public override UIStatusBarStyle PreferredStatusBarStyle()
{
return UIStatusBarStyle.LightContent;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<Compile Include="CustomEffects\FooEffect.cs" />
<Compile Include="_10337CustomRenderer.cs" />
<Compile Include="_11132CustomRenderer.cs" />
<Compile Include="CustomRenderers\UIStatusBarStyleRenderer.cs" />
<Compile Include="CustomRenderers\_12372CustomRenderer.cs" />
<Compile Include="CustomRenderers\_DemoShellPageCustomRenderer.cs" />
<Compile Include="CustomRenderers\_ModalShellPageCustomRenderer.cs" />
Expand Down
8 changes: 2 additions & 6 deletions Xamarin.Forms.Controls/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,13 @@ async Task TestMainPageSwitches()

public Page CreateDefaultMainPage()
{
var layout = new StackLayout { BackgroundColor = Color.Red };
layout.Children.Add(new Label { Text = "This is master Page" });
var master = new ContentPage { Title = "Flyout", Content = layout, BackgroundColor = Color.SkyBlue, IconImageSource = "menuIcon" };
master.On<iOS>().SetUseSafeArea(true);
var mdp = new FlyoutPage
{
AutomationId = DefaultMainPageId,
Flyout = master,
Flyout = CoreGallery.GetFlyoutPage(),
Detail = CoreGallery.GetMainPage()
};
master.IconImageSource.AutomationId = "btnMDPAutomationID";

mdp.SetAutomationPropertiesName("Main page");
mdp.SetAutomationPropertiesHelpText("Main page help text");
mdp.Flyout.IconImageSource.SetAutomationPropertiesHelpText("This as MDP icon");
Expand Down
22 changes: 21 additions & 1 deletion Xamarin.Forms.Controls/CoreGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,23 @@ public CoreFlyoutPage()
Detail = detailPage;
}
}

[Preserve(AllMembers = true)]
internal class CoreNavigationPage : NavigationPage
public class CoreFlyoutView : ContentPage
{
public CoreFlyoutView()
{
On<iOS>().SetUseSafeArea(true);
Title = "Flyout";
Content = new StackLayout { BackgroundColor = Color.Red, Children = { new Label { Text = "This is master Page" } } };
BackgroundColor = Color.SkyBlue;
IconImageSource = "menuIcon";
IconImageSource.AutomationId = "btnMDPAutomationID";
}
}

[Preserve(AllMembers = true)]
public class CoreNavigationPage : NavigationPage
{
public CoreNavigationPage()
{
Expand Down Expand Up @@ -668,5 +683,10 @@ public static Page GetMainPage()
{
return new CoreNavigationPage();
}

public static Page GetFlyoutPage()
{
return new CoreFlyoutView();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Linq;
using CoreGraphics;
using Foundation;
using UIKit;
Expand All @@ -13,6 +14,11 @@ public override void ViewDidLayoutSubviews()
foreach (var vc in ChildViewControllers)
vc.View.Frame = View.Bounds;
}

public override UIViewController ChildViewControllerForStatusBarStyle()
{
return ChildViewControllers.Length > 0 ? ChildViewControllers[0] : base.ChildViewControllerForStatusBarStyle();
}
}

internal class EventedViewController : ChildViewController
Expand Down

0 comments on commit 000000c

Please sign in to comment.