Skip to content

Commit 62b07e1

Browse files
wsdwsd0829Adlai-Holler
authored andcommitted
Match interfacestate update sequence to uikit (#882)
* fix SIMULATE_WEB_RESPONSE not imported #449 * Fix to make rangeMode update in right time * Match interface update closer to UIKit. * allow the correct exiting sequence for thrashing * refactor
1 parent cac14e0 commit 62b07e1

4 files changed

Lines changed: 35 additions & 10 deletions

File tree

Source/ASCollectionView.mm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,15 +2276,23 @@ - (void)didMoveToWindow
22762276
{
22772277
BOOL visible = (self.window != nil);
22782278
ASDisplayNode *node = self.collectionNode;
2279+
BOOL rangeControllerNeedsUpdate = ![node supportsRangeManagedInterfaceState];;
2280+
22792281
if (!visible && node.inHierarchy) {
2282+
if (rangeControllerNeedsUpdate) {
2283+
rangeControllerNeedsUpdate = NO;
2284+
// Exit CellNodes first before Collection to match UIKit behaviors (tear down bottom up).
2285+
// Although we have not yet cleared the interfaceState's Visible bit (this happens in __exitHierarchy),
2286+
// the ASRangeController will get the correct value from -interfaceStateForRangeController:.
2287+
[_rangeController updateRanges];
2288+
}
22802289
[node __exitHierarchy];
22812290
}
22822291

22832292
// Updating the visible node index paths only for not range managed nodes. Range managed nodes will get their
22842293
// their update in the layout pass
2285-
if (![node supportsRangeManagedInterfaceState]) {
2286-
[_rangeController setNeedsUpdate];
2287-
[_rangeController updateIfNeeded];
2294+
if (rangeControllerNeedsUpdate) {
2295+
[_rangeController updateRanges];
22882296
}
22892297

22902298
// When we aren't visible, we will only fetch up to the visible area. Now that we are visible,

Source/ASTableView.mm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,15 +1907,23 @@ - (void)didMoveToWindow
19071907
{
19081908
BOOL visible = (self.window != nil);
19091909
ASDisplayNode *node = self.tableNode;
1910+
BOOL rangeControllerNeedsUpdate = ![node supportsRangeManagedInterfaceState];;
1911+
19101912
if (!visible && node.inHierarchy) {
1913+
if (rangeControllerNeedsUpdate) {
1914+
rangeControllerNeedsUpdate = NO;
1915+
// Exit CellNodes first before Table to match UIKit behaviors (tear down bottom up).
1916+
// Although we have not yet cleared the interfaceState's Visible bit (this happens in __exitHierarchy),
1917+
// the ASRangeController will get the correct value from -interfaceStateForRangeController:.
1918+
[_rangeController updateRanges];
1919+
}
19111920
[node __exitHierarchy];
19121921
}
19131922

19141923
// Updating the visible node index paths only for not range managed nodes. Range managed nodes will get their
19151924
// their update in the layout pass
1916-
if (![node supportsRangeManagedInterfaceState]) {
1917-
[_rangeController setNeedsUpdate];
1918-
[_rangeController updateIfNeeded];
1925+
if (rangeControllerNeedsUpdate) {
1926+
[_rangeController updateRanges];
19191927
}
19201928

19211929
// When we aren't visible, we will only fetch up to the visible area. Now that we are visible,

Source/Details/ASRangeController.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ AS_SUBCLASSING_RESTRICTED
6464
*/
6565
- (void)updateIfNeeded;
6666

67+
/**
68+
* Force update the ranges immediately.
69+
*/
70+
- (void)updateRanges;
71+
6772
/**
6873
* Add the sized node for `indexPath` as a subview of `contentView`.
6974
*

Source/Details/ASRangeController.mm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,16 @@ - (void)setNeedsUpdate
154154
- (void)updateIfNeeded
155155
{
156156
if (_needsRangeUpdate) {
157-
_needsRangeUpdate = NO;
158-
159-
[self _updateVisibleNodeIndexPaths];
157+
[self updateRanges];
160158
}
161159
}
162160

161+
- (void)updateRanges
162+
{
163+
_needsRangeUpdate = NO;
164+
[self _updateVisibleNodeIndexPaths];
165+
}
166+
163167
- (void)updateCurrentRangeWithMode:(ASLayoutRangeMode)rangeMode
164168
{
165169
_preserveCurrentRangeMode = YES;
@@ -376,7 +380,7 @@ - (void)_updateVisibleNodeIndexPaths
376380
[newVisibleNodes addObject:node];
377381
}
378382
// Skip the many method calls of the recursive operation if the top level cell node already has the right interfaceState.
379-
if (node.interfaceState != interfaceState) {
383+
if (node.pendingInterfaceState != interfaceState) {
380384
#if ASRangeControllerLoggingEnabled
381385
[modifiedIndexPaths addObject:indexPath];
382386
#endif

0 commit comments

Comments
 (0)