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

Fix ios page background #1279

Merged
merged 7 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
47 changes: 40 additions & 7 deletions src/Controls/samples/Controls.Sample/Pages/XamlPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,49 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:Maui.Controls.Sample.Controls"
xmlns:layout="clr-namespace:Microsoft.Maui.Controls.Layout2;assembly=Microsoft.Maui.Controls"
x:Class="Maui.Controls.Sample.Pages.XamlPage">
x:Class="Maui.Controls.Sample.Pages.XamlPage"
BackgroundColor="#512bdf"
>

<layout:GridLayout x:Name="MyLayout" Margin="40" BackgroundColor="LightGreen">
<ScrollView Padding="{OnPlatform iOS='30,60,30,30', Default='30'}">
Copy link
Member Author

Choose a reason for hiding this comment

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

Just checked in our sample as the xamlapp so we can test it more easily

<StackLayout>
<Grid RowSpacing="25" RowDefinitions="Auto,Auto,Auto,Auto,*">

<Label
Text="Welcome to Microsoft MAUI!"
BackgroundColor="LightBlue" Margin="10,20,10,20"/>
<Label Text="Hello, World!"
Grid.Row="0"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="CenterAndExpand" />


</layout:GridLayout>
<Label Text="Welcome to .NET Multi-platform App UI"
Grid.Row="1"
SemanticProperties.Hint="Counts the number of times you click"
FontSize="16"
HorizontalOptions="CenterAndExpand" />

<Label Text="Current count: 0"
Grid.Row="2"
SemanticProperties.Hint="Counts the number of times you click"
FontSize="18"
FontAttributes="Bold"
x:Name="CounterLabel"
HorizontalOptions="Center" />

<Button Text="Click me"
Grid.Row="3"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />

<Image Grid.Row="4"
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dotnet bot waving hi to you!"
WidthRequest="300"
HorizontalOptions="Center" />

</Grid>
</StackLayout>
</ScrollView>


</controls:BasePage>
13 changes: 8 additions & 5 deletions src/Controls/samples/Controls.Sample/Pages/XamlPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using Maui.Controls.Sample.Controls;
using Microsoft.Maui.Controls.Xaml;

Expand All @@ -10,11 +11,13 @@ public partial class XamlPage : BasePage
public XamlPage()
{
InitializeComponent();
}

foreach (var x in MyLayout)
{
Debug.WriteLine($"{x}");
}
int count = 0;
private void OnCounterClicked(object sender, EventArgs e)
{
count++;
CounterLabel.Text = $"Current count: {count}";
}
}
}
3 changes: 3 additions & 0 deletions src/Core/src/Handlers/Page/PageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public partial class PageHandler : IViewHandler
{
[nameof(IPage.Title)] = MapTitle,
[nameof(IPage.Content)] = MapContent,
#if __IOS__
[nameof(IPage.Background)] = MapBackground,
#endif
};

public PageHandler() : base(PageMapper)
Expand Down
5 changes: 5 additions & 0 deletions src/Core/src/Handlers/Page/PageHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,10 @@ public static void MapContent(PageHandler handler, IPage page)
{
handler.UpdateContent();
}

public static void MapBackground(PageHandler handler, IView view)
{
handler.NativeView?.UpdateBackground(view);
}
}
}
27 changes: 27 additions & 0 deletions src/Core/src/Platform/iOS/PageViewExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using CoreAnimation;
using CoreGraphics;
using Microsoft.Maui.Graphics;
using UIKit;

namespace Microsoft.Maui
{
public static class PageViewExtensions
{
public static void UpdateBackground(this PageView nativeView, IView view)
{
var paint = view.Background;

if (paint.IsNullOrEmpty())
return;

var color = paint.ToColor();

if (color == null)
return;

nativeView.BackgroundColor = color.ToNative();
}
}
}