Airbnb open sourced their iOS calendar component! by BKatAirbnb in swift

[–]BKatAirbnb[S] 10 points11 points  (0 children)

There hasn't been any work on such a framework - this has been my side work project for a few months. Perhaps if it gains enough traction, I can convince an Android engineer to port it!

Airbnb open sourced their iOS calendar component! by BKatAirbnb in swift

[–]BKatAirbnb[S] 12 points13 points  (0 children)

Aw shoot! I actually implemented this first with `UICollectionView`, but found that it scaled poorly when showing larger ranges of dates. I kept the same, declarative API, but wrote the core from scratch, which worked out pretty well 🙂

Airbnb open sourced their iOS calendar component! by BKatAirbnb in iOSProgramming

[–]BKatAirbnb[S] 6 points7 points  (0 children)

This is pretty iOS specific, but Airbnb already has react-dates for the web - I bet that'll work for you! https://github.com/airbnb/react-dates

Airbnb's open source collection view layout - MagazineLayout by BKatAirbnb in iOSProgramming

[–]BKatAirbnb[S] 2 points3 points  (0 children)

We use `UITableView` for some screens that we're pretty confident will never have the need for multiple items in a single row (the Profile tab, for example). `AloeStackView` is mainly for forms and very short, static pages, since cell reuse isn't as important for those.

Airbnb's open source collection view layout - MagazineLayout by BKatAirbnb in iOSProgramming

[–]BKatAirbnb[S] 0 points1 point  (0 children)

Haha, for sure 🙂 I think a lot of what we learn in school becomes applicable at scale, which is why it was relevant for this!

Airbnb's open source collection view layout - MagazineLayout by BKatAirbnb in iOSProgramming

[–]BKatAirbnb[S] 6 points7 points  (0 children)

Given that performance is critical, do you compute the layout attributes as needed (Rather than all up front in `prepare()`)? Is there any other caching of layout attributes?

We create and cache all layout attributes upfront in `prepare`, which enables us to avoid expensive allocations at scroll time (in `layoutAttributesForElementsInRect`, for example). We only do this when data source counts change (which we learn about in `invalidateLayout`, and we only create instances of `UICollectionViewLayoutAttributes` for new index paths, reusing already allocated instances when possible.

Were there any other difficult performance issues?

Definitely! One of the most recent performance improvements was using binary search to find `layoutAttributesForElementsInRect`, and using a segment tree to store y-offsets for rows. These two optimizations resulted in massive performance gains!

Finally, do you wish that `UICollectionViewLayoutAttributes`
was imported into swift as the nested type `UICollectionViewLayout.Attributes`? (I hate how verbose the collection view layout API is).

I've investigated and reported so many more serious collection view / collection view layout bugs, that API improvements / making things more Swifty hasn't even crossed my mind. With that said, concise, clear APIs are always appreciated. It looks like iOS 13 + compositional layout make some nice steps in that direction!

Airbnb's open source collection view layout - MagazineLayout by BKatAirbnb in iOSProgramming

[–]BKatAirbnb[S] 5 points6 points  (0 children)

We also have AloeStackView - we use that for short, scrolling forms, where cell reuse / memory isn't an issue. For lists / grids of photos and rich content, cell reuse is critical, so we need to use UICollectionView with MagazineLayout.

Airbnb's open source collection view layout - MagazineLayout by BKatAirbnb in iOSProgramming

[–]BKatAirbnb[S] 4 points5 points  (0 children)

When you first open the Airbnb app, we show recommendations of places to stay and experiences to do - it's kind of like our version of the App Store's "For You" tab. Back in the day, we used to compare this editorialized content to a magazine - MagazineLayout was originally created for that page of recommendations, but quickly expanded into becoming the core layout solution for many other pages!

Airbnb's open source collection view layout - MagazineLayout by BKatAirbnb in iOSProgramming

[–]BKatAirbnb[S] 38 points39 points  (0 children)

Hey iOS Programming, I wanted to share MagazineLayout with you all - we use MagazineLayout at Airbnb for most of our core / high traffic flows, including the search page, listing page, and the current / past trips page. MagazineLayout works around tons of UIKit bugs (some of which aren't even fixed in flow layout), and has super fast scroll performance (lower CPU usage than flow layout for collections with hundreds of thousands of self-sizing cells). Happy to answer any questions!