Iglistkit: Vertical gallery with IGListKit

Created on 13 Aug 2017  路  8Comments  路  Source: Instagram/IGListKit

I have a very basic case of a vertical gallery that can have any height of an image with full-screen width set. Images a load async from the network.
Is this solvable with IGListKit?
I saw a few mentions of dynamic height issues already, so is my task doable, or I better just go with raw UICollectionView?

question

All 8 comments

@aaverin Do you know the image size before downloading the actual image? This seems absolutely doable (similar to Instagram's full width images with dynamic heights).

  • You need an aspect ratio of the image
  • Then in the section controller method sizeForItemAtIndex: you get the width of the container with collectionContext.containerSize.width
  • Lastly multiply the aspect ratio with the screen width to get the appropriate height

Make sense?

@rnystrom No, image size is not known, and that's kind of the whole point and complexity =)
Basically, any image can be downloaded from the network. ImageView is full-width, and image should occupy whatever height necessary for given screen width.

Can your API include aspect ratio in the initial payload?

@rnystrom Take Flickr, for example. They have a public API that doesn't provide aspect ratio or image size in the response. And because images can be landscape and portrait 鈥撀爏ize can differ.

Ah ok. So what I'd probably try in that case is to start with a placeholder size (maybe square with the screen width). Download the image within the section controller. Once done, call batch updates on the collection context and call reload (see some of our examples).

In the size API, use the placeholder size if no image exists, and use the actual image size (scaled for screen width) when there's an image.

Make sense?

seems hard even with raw UICollectionView without aspect ratio

Ya, finding a way to get aspect ratio before loading the image data will

  • Make for a much better UX
  • Be a vastly simpler implementation

Going to close out since IMO the question is answered.

This is something that works out of the box on Android.
I am porting my Android app to iOS, was hoping to have same functionality. But yes, that doesn't seem to be easy with UICollectionView.
I'll keep your suggestions in mind and will stay with a fixed-height workaround for now

Was this page helpful?
0 / 5 - 0 ratings