Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public MainPage()
}

private void OnCounterClicked(object sender, EventArgs e)
{
{
count++;
CounterLabel.Text = $"Current count: {count}";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.MainPage"
xmlns:local="clr-namespace:Maui.Controls.Sample">

<Frame BackgroundColor="Purple" WidthRequest="400" HeightRequest="400"></Frame>
</ContentPage>
13 changes: 13 additions & 0 deletions src/Controls/samples/Controls.Sample.Sandbox/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,18 @@ public MainPage()
{
InitializeComponent();
}

protected override void OnAppearing()
{
base.OnAppearing();

}

protected override void OnNavigatedTo(NavigatedToEventArgs args)
{
base.OnNavigatedTo(args);

var activity = Window?.Handler?.PlatformView;
}
}
}
3 changes: 2 additions & 1 deletion src/Controls/samples/Controls.Sample.Sandbox/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Hosting;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.LifecycleEvents;

namespace Maui.Controls.Sample
{
Expand All @@ -18,6 +19,6 @@ public static MauiApp CreateMauiApp() =>
class App : Application
{
protected override Window CreateWindow(IActivationState activationState) =>
new Window(new NavigationPage(new MainPage()));
new Window(new MainPage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@
<Label
Text="Has Shadow" />
</Frame>
<Label
Text="Opacity"
Style="{StaticResource Headline}"/>
<Frame
BackgroundColor="LightGray"
BorderColor="Red"
Opacity="0.5"
HasShadow="True">
<Label
Text="Opacity 0.5" />
</Frame>
<Label
Text="IsClippedToBounds (False)"
Style="{StaticResource Headline}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@
VerticalOptions="Center"
HorizontalOptions="Center" />

<Label
Text="Using Opacity"
Style="{StaticResource Headline}"/>
<BoxView
Color="Orange"
Opacity="0.5"
WidthRequest="160"
HeightRequest="160"
VerticalOptions="Center"
HorizontalOptions="Center" />

</VerticalStackLayout>
</ScrollView>
</views:BasePage>
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Views;
using Android.Views.Inspectors;
using AndroidX.CardView.Widget;
using AndroidX.Core.View;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
using static Android.Icu.Text.CaseMap;
using AColor = Android.Graphics.Color;
using ARect = Android.Graphics.Rect;
using AView = Android.Views.View;
using Color = Microsoft.Maui.Graphics.Color;
using static Microsoft.Maui.Primitives.Dimension;

namespace Microsoft.Maui.Controls.Handlers.Compatibility
{
Expand All @@ -28,7 +31,10 @@ public static IPropertyMapper<Frame, FrameRenderer> Mapper
[Frame.CornerRadiusProperty.PropertyName] = (h, _) => h.UpdateCornerRadius(),
[Frame.BorderColorProperty.PropertyName] = (h, _) => h.UpdateBorderColor(),
[Microsoft.Maui.Controls.Compatibility.Layout.IsClippedToBoundsProperty.PropertyName] = (h, _) => h.UpdateClippedToBounds(),
[Frame.ContentProperty.PropertyName] = (h, _) => h.UpdateContent()
[Frame.ContentProperty.PropertyName] = (h, _) => h.UpdateContent(),
[nameof(IView.AutomationId)] = (h, v) => ViewHandler.MapAutomationId(h, v),
[nameof(IView.IsEnabled)] = (h, v) => ViewHandler.MapIsEnabled(h, v),
[nameof(IViewHandler.ContainerView)] = MapContainerView,
};

public static CommandMapper<Frame, FrameRenderer> CommandMapper
Expand All @@ -50,9 +56,19 @@ public static CommandMapper<Frame, FrameRenderer> CommandMapper
public event EventHandler<VisualElementChangedEventArgs>? ElementChanged;
public event EventHandler<PropertyChangedEventArgs>? ElementPropertyChanged;

public FrameRenderer(Context context) : base(context)
public FrameRenderer(Context context) : this(context, Mapper)
{
_viewHandlerWrapper = new ViewHandlerDelegator<Frame>(Mapper, CommandMapper, this);
}

// TODO NET8 make public
internal FrameRenderer(Context context, IPropertyMapper mapper)
: this(context, mapper, CommandMapper)
{
}

internal FrameRenderer(Context context, IPropertyMapper mapper, CommandMapper commandMapper) : base(context)
{
_viewHandlerWrapper = new ViewHandlerDelegator<Frame>(mapper, commandMapper, this);
}

protected CardView Control => this;
Expand All @@ -71,8 +87,16 @@ protected Frame? Element

Size IViewHandler.GetDesiredSize(double widthMeasureSpec, double heightMeasureSpec)
{
double minWidth = 20;
if (IsExplicitSet(widthMeasureSpec) && !double.IsInfinity(widthMeasureSpec))
minWidth = widthMeasureSpec;

double minHeight = 20;
if (IsExplicitSet(widthMeasureSpec) && !double.IsInfinity(heightMeasureSpec))
minHeight = heightMeasureSpec;

return VisualElementRenderer<Frame>.GetDesiredSize(this, widthMeasureSpec, heightMeasureSpec,
new Size(20, 20));
new Size(minWidth, minHeight));
}

protected override void Dispose(bool disposing)
Expand Down Expand Up @@ -317,9 +341,54 @@ void UpdateContent()
}

#region IPlatformViewHandler
bool IViewHandler.HasContainer { get => false; set { } }

object? IViewHandler.ContainerView => null;
bool NeedsContainer
{
get
{
var virtualView = Element as IView;
return virtualView?.Clip != null || virtualView?.Shadow != null
|| (virtualView as IBorder)?.Border != null || virtualView?.InputTransparent == true;
}
}

static void MapContainerView(IViewHandler handler, IView view)
{
if (handler is FrameRenderer frameRenderer)
{
handler.HasContainer = frameRenderer.NeedsContainer;
}
}

bool _hasContainer;
AView? _containerView;
bool IViewHandler.HasContainer
{
get => _hasContainer;
set
{
if (_hasContainer == value)
return;

_hasContainer = value;

if (value)
{
this.SetupContainerFromHandler((handler) =>
{
var view = new WrapperView(handler!.MauiContext!.Context);
_containerView = view;
return view;
});
}
else
{
this.RemoveContainerFromHandler(_ => _containerView = null);
}
}
}

object? IViewHandler.ContainerView => _containerView;

IView? IViewHandler.VirtualView => Element;

Expand All @@ -331,7 +400,7 @@ void UpdateContent()

AView IPlatformViewHandler.PlatformView => this;

AView? IPlatformViewHandler.ContainerView => this;
AView? IPlatformViewHandler.ContainerView => _containerView;

void IViewHandler.PlatformArrange(Graphics.Rect rect) =>
this.PlatformArrangeHandler(rect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,18 @@ internal static void SetVirtualView(

_ = view ?? throw new ArgumentNullException(nameof(view));

if (oldElement?.Handler != null)
oldElement.Handler = null;

currentVirtualView = (TElement)view;

if (currentVirtualView.Handler != nativeViewHandler)
currentVirtualView.Handler = nativeViewHandler;

// We set the previous virtual view to null after setting it on the incoming virtual view.
// This makes it easier for the incoming virtual view to have influence
// on how the exchange of handlers happens.
// We will just set the handler to null ourselves as a last resort cleanup
if (oldElement?.Handler != null)
oldElement.Handler = null;

_mapper = _defaultMapper;

if (currentVirtualView is IPropertyMapperView imv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ public static IPropertyMapper<Frame, FrameRenderer> Mapper
public static CommandMapper<Frame, FrameRenderer> CommandMapper
= new CommandMapper<Frame, FrameRenderer>(VisualElementRendererCommandMapper);

public FrameRenderer() : base(Mapper, CommandMapper)
public FrameRenderer() : this(Mapper, CommandMapper)
{
AutoPackage = false;
}

// TODO NET8 make public
internal FrameRenderer(IPropertyMapper mapper)
: this( mapper, CommandMapper)
{
}

// TODO NET8 make public
internal FrameRenderer(IPropertyMapper mapper, CommandMapper commandMapper) : base(mapper, commandMapper)
{
AutoPackage = false;
}
Expand Down Expand Up @@ -70,17 +82,19 @@ void UpdatePadding()
{
Control.Arrange(new WRect(0, 0, finalSize.Width, finalSize.Height));
if (Element is IContentView cv)
cv.CrossPlatformArrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
{
finalSize = cv.CrossPlatformArrange(new Rect(0, 0, finalSize.Width, finalSize.Height)).ToPlatform();
}

return finalSize;
return new global::Windows.Foundation.Size(Math.Max(0, finalSize.Width), Math.Max(0, finalSize.Height));
}

protected override global::Windows.Foundation.Size MeasureOverride(global::Windows.Foundation.Size availableSize)
{
var size = base.MeasureOverride(availableSize);

if (Element is IContentView cv)
size = cv.CrossPlatformMeasure(availableSize.Width, availableSize.Height).ToPlatform();
_ = cv.CrossPlatformMeasure(size.Width, size.Height);

return size;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected override WSize MeasureOverride(global::Windows.Foundation.Size availab
{
if (child is Maui.IElement childElement && childElement.Handler is IPlatformViewHandler nvh)
{
var size = nvh.GetDesiredSizeFromHandler(availableSize.Width, availableSize.Height);
var size = nvh.GetDesiredSizeFromHandler(width, height);
height = Math.Max(height, size.Height);
width = Math.Max(width, size.Width);
}
Expand Down
12 changes: 12 additions & 0 deletions src/Controls/src/Core/Compatibility/Handlers/iOS/FrameRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ public FrameRenderer() : base(Mapper, CommandMapper)
AddSubview(_actualView);
}

// TODO NET8 make public
internal FrameRenderer(IPropertyMapper mapper)
: this(mapper, CommandMapper)
{
}

// TODO NET8 make public
internal FrameRenderer(IPropertyMapper mapper, CommandMapper commandMapper) : base(mapper, commandMapper)
{
AutoPackage = false;
}

public override void AddSubview(UIView view)
{
if (view != _actualView)
Expand Down
Loading