-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[Table / Collection] Trigger new batch fetch after programmatic scrolls, or layout transitions. #1697
[Table / Collection] Trigger new batch fetch after programmatic scrolls, or layout transitions. #1697
Conversation
* @discussion During various layout changes that trigger content size changes, batch fetching needs to recalulate it's number of screens left to scroll before the delegate -collectionView:beginBatchFetchingWithContext: is called. Call when a layout transition is complete, or it will have no effect. | ||
* | ||
*/ | ||
- (void)invalidateBatchFetchMeasurements; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nickvelloff Thanks! I see the need for this, but I do not see a need for it to be a public API.
Could you explain? Are you confident it can't be called internally, by something like relayoutItems or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@appleguy I looked really closely to try to find a way to trigger this without exposing it. The problem is, the batch invalidation is purely scroll related, and view re-layout when item size changes is not.
Also having the control to fire this manually gave me the ability to be sure it fired once and only once at the exact end of my interactive ASDisplayNode layout transition.
There are nuances to transitions and their completion, like during a "pinch to zoom" you let go, you must call collectionNode.view.cancelInteractiveTransition()
or collectionNode.view.finishInteractiveTransition()
typically depending on the transition progress. This means you would only want to fire this in the completion block of startInteractiveTransitionToCollectionViewLayout
, which might me really tricky to detect within ASDK.
Happy to try another approach if you have any ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@appleguy All that said I think the correct way to go is ultimately decoupling scroll from this as a hard dependency, and making invalidation/re-measurement of batch trigger in a more generic way. That would solve it without exposing anything. Fear we may be a bit far away from that currently though, from a ASDK priority standpoint (I'm guessing this of course)..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I guess I am not familiar enough with the use case. Is there no other call the ASCollectionView can intercept from the UICollectionViewDelegate? Or from the layout? There is a proxy so that ASCollectionView is able to listen to absolutely any kind of delegate / datasource call...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to dig in and see if there is another way to trigger this behavior.
Here is my specific use case:
- x cells displayed in an
ASViewController
- transition to 2nd layout via pinch to zoom
- fetch is ultimately controlled by number of elements in the view * batch fetch screen count
- when the number of items displayed on the screen is changed, via a zoom or transition, that must invalidate the calculation, thereby invalidating the data required to fulfill that 3x trailing promise
I'm happy to try another approach. |
* @discussion During various layout changes that trigger content size changes, batch fetching needs to recalulate it's number of screens left to scroll before the delegate -collectionView:beginBatchFetchingWithContext: is called. Call when a layout transition is complete, or it will have no effect. | ||
* | ||
*/ | ||
- (void)invalidateBatchFetchMeasurements; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's too unclear to users when and why they need to call this, at least because it is still unclear to me :). It may indeed be the only solution, but we have to clarify the cases that it is needed; e.g. what's an example using ASTableView?
I think we should find any possible way for this to be triggered internally even if it means that batch fetching will be re-checked more frequently than absolutely necessary.
16e9c58
to
3897c6f
Compare
@appleguy I think I may have found the appropriate place to trigger this internally. It seems to fire at the appropriate times, and not frequently. |
3cde6ff
to
e94a1d1
Compare
e94a1d1
to
c129b78
Compare
e58d1e5
to
4f588c8
Compare
Expose completed delegate method for ASRangeController
OK. This time we are going to add delegate method Then trigger at the end of |
During various layout changes that trigger content size changes, batch fetching needs to recalulate it's number of screens left to scroll before the delegate -collectionView:beginBatchFetchingWithContext: is called.
Just exposes
[self _checkForBatchFetching];
UPDATE:
Due to conversations with @appleguy the approach has changed to triggering
[self _checkForBatchFetching];
internally, at the appropriate times.After some digging, it appears triggering this on
- (NSArray *)visibleNodeIndexPathsForRangeController:(ASRangeController *)rangeController
exhibits the least amount of additional calculations, but covers a range of use cases that require a batch fetch re-measurement.From the code comments: