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

[iOS] Allow VC renderers of FlyoutPage to specify UIStatusBarStyle #13143

Merged
merged 5 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
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" />
</ItemGroup>
<ItemGroup>
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?.LastOrDefault() ?? base.ChildViewControllerForStatusBarStyle();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChildViewControllers is an array - can we just check the last index instead of allocating an enumerator?

Also, are we guaranteed that the last controller in the array is the correct one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it @hartez , this ChildVIewController wrapper is internal and we are the only ones adding to it the detail or flout as a children, it's the only children.

}
}

internal class EventedViewController : ChildViewController
Expand Down