PinLayout
PinLayout copied to clipboard
WrapContent does not ignore hidden views
Just came across an unexpected behaviour.
Lets says i have a view with 3 subviews that i layout side by side. if i hide one of the views, wrapContent on the parent view does not skip the hidden View so the parent ends up being too wide.
I was wondering if adding the following at the beginning of the wrapContent method would be desirable:
let subviews = view.subviews.filter { (view) -> Bool in
return view.isVisible
}
It requires adding isVisible
to the Layoutable
protocol which is fairly easy
Thanks !
Hi @marclefrancois!
I need to think about it, but:
- Changing the default behaviour of the
wrapContent
method is not a solution, it would create a behaviour breaking change. I'm fine with compilation breaking change, but changing the behaviour, its from my point of view totally wrong. We need a way to opt-in. - What if someone wants to opposite? I.e. they want to wrap visible and unvisible views.
Possible solutions I see:
- Add new
WrapType
enumeration values forwrapContent(:WrapType)
. For example.horizontallyVisibleOnly
or.horizontallyVisible
. Ex:view.pin.wrapContent(.horizontallyVisibleOnly)
- Add a
wrapContent(:[Layoutable])
method, receiving a list of views that you want a wrap. - ... 🤔
Thanks for the answer @lucdion !
Off the top of my head i kinda prefer option 1.
Or maybe it could be a secondParameter wrapContent(.horizontally, visibleOnly: true)
Or maybe it could be a another method: wrapVisibleContent(.horizontally)
It will be very useful to ignore hidden views.
Very old topic. Closing it, sorry