maui icon indicating copy to clipboard operation
maui copied to clipboard

Embedding an iOS ContentView or Layout does not get a size

Open mattleibow opened this issue 1 year ago • 3 comments

Description

If I embed a button or entry, the default layout by iOS works as expected.

However, if there is a layout or content view, the view has a size of 0x0 and thus none of the items are interactable since they are all outside the bounds of the views.

Android Working Mac Catalyst Not Working

Steps to Reproduce

  1. Clone https://github.com/mattleibow/EmbeddedMauiApps
  2. Run on Mac Catalyst
  3. Observe nothing works from maui
  4. Run on Android/Windows
  5. Observe things work

Link to public reproduction project repository

https://github.com/mattleibow/EmbeddedMauiApps

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, macOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

mattleibow avatar Dec 11 '23 18:12 mattleibow

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

ghost avatar Dec 11 '23 18:12 ghost

Have any workarounds been found for this yet? This is a huge blocker for us. We are dead in the water until this is fixed.

pnumainville avatar Apr 11 '24 21:04 pnumainville

any updates ?

MateuszLas421 avatar May 07 '24 21:05 MateuszLas421

Have any workarounds been found for this yet? This is a huge blocker for us. We are dead in the water until this is fixed.

I don't think this is an issue with embedding. I think this has to do with how UIStackView works. Using this SO post as a guide https://stackoverflow.com/a/41048208

If I add the following lines to @mattleibow 's sample it works fine

var nativeView = mauiView.ToPlatformEmbedded(mauiContext);

        nativeView.WidthAnchor.ConstraintEqualTo(500).Active = true;
        nativeView.HeightAnchor.ConstraintEqualTo(500).Active = true;

PureWeen avatar May 09 '24 09:05 PureWeen

@davidbritch FYI ^

mattleibow avatar May 09 '24 14:05 mattleibow

Closing this now as I was holding it wrong. I thought the stack layout was like all other OS ever before iOS and since - I was wrong. iOS is still wrong.

mattleibow avatar May 09 '24 14:05 mattleibow

I am reopening this as I think the way we do size "indication" might be incorrect. In my sample, I have a ContentView with some things in it, however the IntrinsicContentSize of the view is 0x0. Since all the things derive from MauiView, I updated the property to call SizeThatFits with infinite sizes and then it works:

class MauiView : UIView
{
    public override CGSize IntrinsicContentSize =>
        SizeThatFits(new CGSize(nfloat.MaxValue, nfloat.MaxValue));
}

It appears that for UIStackView at least, the IntrinsicContentSize is used instead of SizeThatFits or something.

mattleibow avatar Jul 18 '24 16:07 mattleibow

For now, I created this wrapper view that I can use to redirect things to the intrinsic content size. Not sure how well this works generally since all I am playing with is the UIStackView:

class ContainerView : UIView
{
	public ContainerView(UIView view)
	{
		AddSubview(view);
	}

	public override CGSize IntrinsicContentSize =>
		SizeThatFits(new CGSize(nfloat.MaxValue, nfloat.MaxValue));

	public override void LayoutSubviews()
	{
		if (Subviews?.FirstOrDefault() is {} view)
			view.Frame = Bounds;
	}

	public override void SetNeedsLayout()
	{
		base.SetNeedsLayout();
		InvalidateIntrinsicContentSize();
	}

	public override CGSize SizeThatFits(CGSize size) =>
		Subviews?.FirstOrDefault()?.SizeThatFits(size) ?? CGSize.Empty;
}

mattleibow avatar Jul 18 '24 17:07 mattleibow