Skip to content
Merged
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 @@ -584,7 +584,6 @@ internal void UpdateView(object view, DataTemplate viewTemplate, ref UIView uiVi
//Platform.GetRenderer(formsElement)?.DisposeRendererAndChildren();
}


uiView?.Dispose();
uiView = null;
formsElement?.Handler?.DisconnectHandler();
Expand Down
17 changes: 8 additions & 9 deletions src/Controls/src/Core/Handlers/Items/iOS/TemplateHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#nullable disable
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Controls.Internals;
using ObjCRuntime;
using Microsoft.Maui.Controls.Platform;
using UIKit;

namespace Microsoft.Maui.Controls.Handlers.Items
Expand Down Expand Up @@ -49,16 +48,16 @@ public static (UIView PlatformView, VisualElement FormsElement) RealizeView(obje
return ((UIView)renderer.PlatformView, element);
}

if (view is View formsView)
if (view is View mauiView)
{
// Make sure the Visual property is available when the renderer is created
PropertyPropagationExtensions.PropagatePropertyChanged(null, formsView, itemsView);
PropertyPropagationExtensions.PropagatePropertyChanged(null, mauiView, itemsView);

// No template, and the EmptyView is a Forms view; use that
var renderer = GetHandler(formsView, itemsView.FindMauiContext());
var element = renderer.VirtualView as VisualElement;

return ((UIView)renderer.PlatformView, element);
// No template, and the EmptyView is a Maui view; use that
// But we need to wrap it in a GeneralWrapperView so it can be measured and arranged
var wrapperView = new GeneralWrapperView(mauiView, itemsView.FindMauiContext());
wrapperView.Frame = mauiView.Bounds.ToCGRect();
return (wrapperView, mauiView);
}

return (new UILabel { TextAlignment = UITextAlignment.Center, Text = $"{view}" }, null);
Expand Down
50 changes: 2 additions & 48 deletions src/Controls/src/Core/Handlers/Items2/iOS/TemplatedCell2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CoreGraphics;
using Foundation;
using Microsoft.Maui.Controls.Internals;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Graphics;
using UIKit;

Expand Down Expand Up @@ -126,7 +127,7 @@ void BindVirtualView(View virtualView, object bindingContext, ItemsView itemsVie

if (needsContainer)
{
PlatformView = new UIContainerView2(virtualView, mauiContext);
PlatformView = new GeneralWrapperView(virtualView, mauiContext);
}
else
{
Expand Down Expand Up @@ -258,51 +259,4 @@ void UpdateSelectionColor(View view)
}
}
}

class UIContainerView2 : UIView
{
readonly IView _view;
readonly IMauiContext _mauiContext;

public UIContainerView2(IView view, IMauiContext mauiContext)
{
_view = view;
_mauiContext = mauiContext;
UpdatePlatformView();
}

internal void UpdatePlatformView()
{
var handler = _view.ToHandler(_mauiContext);
var nativeView = _view.ToPlatform();

if (nativeView.Superview == this)
{
nativeView.RemoveFromSuperview();
}

if (nativeView is WrapperView)
{
// Disable clipping for WrapperView to allow the shadow to be displayed
ClipsToBounds = false;
}
else
{
ClipsToBounds = true;
}

AddSubview(nativeView);
}

public override void LayoutSubviews()
{
_view?.Arrange(new Rect(0, 0, Frame.Width, Frame.Height));
base.LayoutSubviews();
}

public override CGSize SizeThatFits(CGSize size)
{
return _view.Measure(size.Width, size.Height).ToCGSize();
}
}
}
71 changes: 71 additions & 0 deletions src/Controls/src/Core/Platform/iOS/GeneralWrapperView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls.Platform;

class GeneralWrapperView : MauiView, ICrossPlatformLayout
{
public WeakReference<IView>? ChildView { get; private set; }

public GeneralWrapperView(IView childView, IMauiContext mauiContext)
{
CrossPlatformLayout = this;
UpdatePlatformView(childView, mauiContext);
}

public void Disconnect()
{
if (ChildView is null || !ChildView.TryGetTarget(out var childView))
{
return;
}

childView.DisconnectHandlers();
}

public void UpdatePlatformView(IView? newChildView, IMauiContext mauiContext)
{
if (Subviews.Length > 0)
{
Subviews[0].RemoveFromSuperview();
}

if (newChildView is null)
{
ChildView = null;
return;
}

ChildView = new(newChildView);

var nativeView = newChildView.ToPlatform(mauiContext);

if (nativeView is WrapperView)
{
// Disable clipping for WrapperView to allow the shadow to be displayed
ClipsToBounds = false;
}
else
{
ClipsToBounds = true;
}

AddSubview(nativeView);
}

public Size CrossPlatformArrange(Rect bounds)
{
if (ChildView == null || !ChildView.TryGetTarget(out var childView))
return Size.Zero;

return childView.Arrange(bounds);
}

public Size CrossPlatformMeasure(double widthConstraint, double heightConstraint)
{
if (ChildView == null || !ChildView.TryGetTarget(out var childView))
return Size.Zero;

return childView.Measure(widthConstraint, heightConstraint);
}
}