Composable Collection Layouts: How to create custom group layouts with fixed numbers of contents?

I am trying to use composable collection view layouts to build an interface that has sections and then "sub-sections". Imagine a photo picker with a section for each month, and then a separate sub-section for each day within the month. The month header would be sticky, while the headers on each date section would not.

I know iOS 14 has support for outline-style collection views which would probably work for representing sub-sections, but I'm hoping to do this in a way that's compatible with iOS 13.

My thought was that I could do something like this:
  • Section

    • (Sticky boundary item of kind "month-header")

    • Day Group (see below)

  • Day Group

    • (Non-sticky boundary item of kind "day-header")

    • Custom layout that provides the layout for each day view

You might think the day group could just be a wrapper for some NSCollectionViewLayout.horizontal and .vertical rows, but remember that all of the items for the entire month are in the same section. If the first day only has 7 photos, I need a way to tell the group to only provide layout for 7 items, and then the section should create another instance of the group to represent the next day. The only way I know to do that is to make a custom group layout that manually specifies the grid layout for the 7 items in that day.

The problem that I'm having is that I see no way for the group layout to know which item it's starting at. Ideally, I'd like for the custom group layout provider to receive an itemIndex parameter. If it's 0, I'd know I'm looking at day 1. If it's 7, I'd be able to do the math to know that we've moved on to day 2, etc.

Unfortunately, I see no way for the group to know that. I cannot assume that the group provider will be called only once sequentially for each group instance in the section; I already tried that and was quickly proven wrong.

Is there a better way to do this?


Notes on alternatives I've tried:

I could instead just provide a series of custom groups, each tailored to have the correct number of items for that group, like so:
  • Section

    • (Sticky boundary item of kind "month-header")

    • Day Group 1

    • Day Group 2

    • ...

    • Day Group 31

  • Day Group 1

    • (Non-sticky boundary item of kind "day-header-1" to serve as day header)

    • Custom layout for day 1

  • Day Group 2

    • (Non-sticky boundary item of kind "day-header-2" to serve as day header)

    • Custom layout for day 2

  • Day Group ...

Unfortunately, this means that the each day header would have to have a separate supplementary item kind, because you cannot reuse the same supplementary item kind for two different layout groups. This is workable, but results in a much more complex layout description, and means I have to register 32 supplementary item kinds. This all feels like a terrible hack.
Composable Collection Layouts: How to create custom group layouts with fixed numbers of contents?
 
 
Q