How to hide LayoutView from a Layout?

I have implemented a custom Layout, specifically a label view that hides any trailing views that are clipped.

Now in my placeSubviews() method - even if I don't explicitly place a view - SwiftUI will layout the view and show it.

As there seems to be no way to hide a LayoutSubview, I have resorted to placing the view somewhere very far off screen like this

let maxOffset = CGFloat.greatestFiniteMagnitude
let offScreen = CGPoint(x: maxOffset, y: maxOffset)
subview.place(at: offScreen, proposal: .unspecified)

but I don't really like this solution.

Is there an official Apple "sanctioned" way how to hide LayoutSubviews inside a Layout?

I have the exact same issue. When you don't place the view (& hence are trying hiding it), it just puts it in the center. Which in my opinion is a bug Apple should fix

Hello

I've been facing a similar issue. My case is the following:

I have some grid-like custom Layout that needs to have a linelimit parameter.

In placeSubviews if I don't call .place(at: .., from...) the subviews gets in the middle of the view.

I found a workaround where I simply changed my view height calculation to only stop at my limit, but I'm still "placing" the other views that are out of my limit, then clipping will work.

For example:

Let's assume I have 12 subviews, and can fit 3 of them per Row in my grid.

If my line limit is set to 3

I will render each of the 4 row BUT in sizeThatFits only return the height of 3 rows.

Then in the parent that calls the CustomGridLayout I just need to call .clipped() so that subviews placed outside of the parent are not visible.

I don't know if that helps your case. It would be interesting to have a way to handle that case from the Layout implemented by Apple.

How to hide LayoutView from a Layout?
 
 
Q