PinLayout icon indicating copy to clipboard operation
PinLayout copied to clipboard

WrapContent does not ignore hidden views

Open marclefrancois opened this issue 5 years ago • 3 comments

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 !

marclefrancois avatar Mar 19 '19 14:03 marclefrancois

Hi @marclefrancois!

I need to think about it, but:

  1. 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.
  2. What if someone wants to opposite? I.e. they want to wrap visible and unvisible views.

Possible solutions I see:

  1. Add new WrapType enumeration values for wrapContent(:WrapType). For example .horizontallyVisibleOnly or .horizontallyVisible. Ex: view.pin.wrapContent(.horizontallyVisibleOnly)
  2. Add a wrapContent(:[Layoutable]) method, receiving a list of views that you want a wrap.
  3. ... 🤔

lucdion avatar Mar 20 '19 12:03 lucdion

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)

marclefrancois avatar Mar 20 '19 14:03 marclefrancois

It will be very useful to ignore hidden views.

wjling avatar Apr 06 '22 02:04 wjling

Very old topic. Closing it, sorry

lucdion avatar Mar 01 '23 20:03 lucdion