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

Correctly handle ContainerView changes #13114

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
19 changes: 19 additions & 0 deletions src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,23 @@
x:Class="Maui.Controls.Sample.MainPage"
xmlns:local="clr-namespace:Maui.Controls.Sample">

<ContentPage.Resources>
<local:CrossDrawable x:Key="CrossDrawable" />
</ContentPage.Resources>

<Grid RowDefinitions="*,Auto">
<GraphicsView x:Name="Cross"
IsVisible="False"
InputTransparent="True"
HorizontalOptions="Center"
VerticalOptions="Center"
HeightRequest="50"
WidthRequest="50"
Drawable="{StaticResource CrossDrawable}" />

<Button Grid.Row="1"
Text="Toggle"
Clicked="Button_Clicked" />
</Grid>

</ContentPage>
21 changes: 20 additions & 1 deletion src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,24 @@ public MainPage()
{
InitializeComponent();
}

private void Button_Clicked(object sender, EventArgs e)
{
Cross.IsVisible = !Cross.IsVisible;
}
}

public sealed class CrossDrawable : IDrawable
{
public void Draw(ICanvas canvas, RectF dirtyRect)
{
canvas.StrokeColor = Colors.Red;

// horizontal line
canvas.DrawLine(0, dirtyRect.Height / 2, dirtyRect.Width, dirtyRect.Height / 2);

// vertical line
canvas.DrawLine(dirtyRect.Width / 2, 0, dirtyRect.Width / 2, dirtyRect.Height);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial class ActivityIndicatorHandler : ViewHandler<IActivityIndicator,

public static void MapBackground(IActivityIndicatorHandler handler, IActivityIndicator activityIndicator)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
(handler as IDynamicContainerViewHandler)?.ContainerAffectingProperties?.Add(nameof(IView.Background));
handler.ToPlatform().UpdateBackground(activityIndicator);
}

Expand Down
8 changes: 8 additions & 0 deletions src/Core/src/Handlers/IViewHandler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui
Expand All @@ -14,4 +15,11 @@ public interface IViewHandler : IElementHandler

void PlatformArrange(Rect frame);
}

public interface IDynamicContainerViewHandler : IViewHandler
{
bool NeedsContainer { get; }

ICollection<string> ContainerAffectingProperties { get; }
}
}
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Image/ImageHandler.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected override void DisconnectHandler(ImageView platformView)

public static void MapBackground(IImageHandler handler, IImage image)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
(handler as IDynamicContainerViewHandler)?.ContainerAffectingProperties?.Add(nameof(IView.Background));

handler.ToPlatform().UpdateBackground(image);
handler.ToPlatform().UpdateOpacity(image);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Image/ImageHandler.Tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override void DisconnectHandler(Image platformView)

public static void MapBackground(IImageHandler handler, IImage image)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
(handler as IDynamicContainerViewHandler)?.ContainerAffectingProperties?.Add(nameof(IView.Background));
handler.ToPlatform()?.UpdateBackground(image);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Image/ImageHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override void DisconnectHandler(Image platformView)

public static void MapBackground(IImageHandler handler, IImage image)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
(handler as IDynamicContainerViewHandler)?.ContainerAffectingProperties?.Add(nameof(IView.Background));
handler.ToPlatform().UpdateBackground(image);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Image/ImageHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override void DisconnectHandler(UIImageView platformView)

public static void MapBackground(IImageHandler handler, IImage image)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
(handler as IDynamicContainerViewHandler)?.ContainerAffectingProperties?.Add(nameof(IView.Background));

handler.ToPlatform().UpdateBackground(image);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Core/src/Handlers/Label/LabelHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ protected override void RemoveContainer()

public static void MapBackground(ILabelHandler handler, ILabel label)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
(handler as IDynamicContainerViewHandler)?.ContainerAffectingProperties?.Add(nameof(IView.Background));

handler.ToPlatform().UpdateBackground(label);
}

public static void MapOpacity(ILabelHandler handler, ILabel label)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
(handler as IDynamicContainerViewHandler)?.ContainerAffectingProperties?.Add(nameof(IView.Opacity));
handler.PlatformView.UpdateOpacity(label);
handler.ToPlatform().UpdateOpacity(label);
}
Expand All @@ -69,7 +69,7 @@ public static void MapFont(ILabelHandler handler, ILabel label)

public static void MapVerticalTextAlignment(ILabelHandler handler, ILabel label)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
(handler as IDynamicContainerViewHandler)?.ContainerAffectingProperties?.Add(nameof(ILabel.VerticalTextAlignment));

handler.PlatformView?.UpdateVerticalTextAlignment(label);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Label/LabelHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class LabelHandler : ViewHandler<ILabel, MauiLabel>

public static void MapBackground(ILabelHandler handler, ILabel label)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
(handler as IDynamicContainerViewHandler)?.ContainerAffectingProperties?.Add(nameof(IView.Background));

handler.ToPlatform().UpdateBackground(label);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protected override MauiShapeView CreatePlatformView()

public static void MapBackground(IShapeViewHandler handler, IShapeView shapeView)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
(handler as IDynamicContainerViewHandler)?.ContainerAffectingProperties?.Add(nameof(IView.Background));
handler.ToPlatform().UpdateBackground(shapeView);

handler.PlatformView?.InvalidateShape(shapeView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected override W2DGraphicsView CreatePlatformView()

public static void MapBackground(IShapeViewHandler handler, IShapeView shapeView)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
(handler as IDynamicContainerViewHandler)?.ContainerAffectingProperties?.Add(nameof(IView.Background));
handler.ToPlatform().UpdateBackground(shapeView);

handler.PlatformView?.InvalidateShape(shapeView);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/ShapeView/ShapeViewHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected override MauiShapeView CreatePlatformView()

public static void MapBackground(IShapeViewHandler handler, IShapeView shapeView)
{
handler.UpdateValue(nameof(IViewHandler.ContainerView));
(handler as IDynamicContainerViewHandler)?.ContainerAffectingProperties?.Add(nameof(IView.Background));
handler.ToPlatform().UpdateBackground(shapeView);

handler.PlatformView?.InvalidateShape(shapeView);
Expand Down
1 change: 0 additions & 1 deletion src/Core/src/Handlers/View/AndroidBatchPropertyMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class AndroidBatchPropertyMapper<TVirtualView, TViewHandler> : PropertyMapper<TV
// During mass property updates, this list of properties will be skipped
public static HashSet<string> SkipList = new(StringComparer.Ordinal)
{
nameof(IView.Visibility),
nameof(IView.MinimumHeight),
nameof(IView.MinimumWidth),
nameof(IView.IsEnabled),
Expand Down
Loading