maui
maui copied to clipboard
Embedding an iOS ContentView or Layout does not get a size
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
- Clone https://github.com/mattleibow/EmbeddedMauiApps
- Run on Mac Catalyst
- Observe nothing works from maui
- Run on Android/Windows
- 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
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.
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.
any updates ?
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;
@davidbritch FYI ^
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.
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.
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;
}