airbnb / MagazineLayout

A collection view layout capable of laying out views in vertically scrolling grids and lists.
Apache License 2.0
3.28k stars 219 forks source link

Add support for items order by zIndex #48

Open yossiavramov opened 5 years ago

yossiavramov commented 5 years ago

UICollectionViewLayout supports the ability to order its elements (cells, supplementary views & decoration views) not only by their IndexPath, so items with small IndexPath will be in the collectionView subviews' stack in front of item with bigger IndexPath. This is required, for example, if you want to have an animation on a cell's content which will hover above all other cells.

It'd be great if MagazineLayout will support changing item's zIndex.

I can implement it & make a pull request. I think that the best place to get this data is part of the delegate call for 'MagazineLayoutItemSizeMode' (maybe we need to change its name to MagazineLayoutItemSizeAndOrderMode)

bryankeller commented 5 years ago

@yossiavramov you'd like the ability to change the z index of an arbitrary item? Is your use case just to have the cell "in front" during an animation? I'm trying to understand the use case better.

I don't love the idea of needing to specify a z-index for every item in the delegate. We could provide some sensible defaults, but I feel like this use case might be too niche to incorporate into the layout delegate.

I could see an argument being made for MagazineLayout being an open class. If you could subclass MagazineLayout, you could change layout attributes as you see fit.

Another possibility is providing a way to modify layout attributes without subclassing. I think this would be preferable, as subclassing collection view layouts is incredibly error prone (so many functions that can be overwritten that will mess things up).

yossiavramov commented 5 years ago

In my use case, I have a cell that contains draggable views. I want those views to be on top of all other cells. To achieve this, I need the cell that contains those draggable views to be the top most cell in the views hierarchy.

I forked MagazineLayout & added support for this: https://github.com/yossiavramov/MagazineLayout/commit/d542a95d84d51c2be9e693949c23d674be076d21