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
This commit is contained in:
Max Wang 2018-05-25 18:21:50 -07:00 committed by Adlai Holler
parent cac14e0bce
commit 62b07e100e
4 changed files with 35 additions and 10 deletions

View File

@ -2276,15 +2276,23 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
{
BOOL visible = (self.window != nil);
ASDisplayNode *node = self.collectionNode;
BOOL rangeControllerNeedsUpdate = ![node supportsRangeManagedInterfaceState];;
if (!visible && node.inHierarchy) {
if (rangeControllerNeedsUpdate) {
rangeControllerNeedsUpdate = NO;
// Exit CellNodes first before Collection to match UIKit behaviors (tear down bottom up).
// Although we have not yet cleared the interfaceState's Visible bit (this happens in __exitHierarchy),
// the ASRangeController will get the correct value from -interfaceStateForRangeController:.
[_rangeController updateRanges];
}
[node __exitHierarchy];
}
// Updating the visible node index paths only for not range managed nodes. Range managed nodes will get their
// their update in the layout pass
if (![node supportsRangeManagedInterfaceState]) {
[_rangeController setNeedsUpdate];
[_rangeController updateIfNeeded];
if (rangeControllerNeedsUpdate) {
[_rangeController updateRanges];
}
// When we aren't visible, we will only fetch up to the visible area. Now that we are visible,

View File

@ -1907,15 +1907,23 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
{
BOOL visible = (self.window != nil);
ASDisplayNode *node = self.tableNode;
BOOL rangeControllerNeedsUpdate = ![node supportsRangeManagedInterfaceState];;
if (!visible && node.inHierarchy) {
if (rangeControllerNeedsUpdate) {
rangeControllerNeedsUpdate = NO;
// Exit CellNodes first before Table to match UIKit behaviors (tear down bottom up).
// Although we have not yet cleared the interfaceState's Visible bit (this happens in __exitHierarchy),
// the ASRangeController will get the correct value from -interfaceStateForRangeController:.
[_rangeController updateRanges];
}
[node __exitHierarchy];
}
// Updating the visible node index paths only for not range managed nodes. Range managed nodes will get their
// their update in the layout pass
if (![node supportsRangeManagedInterfaceState]) {
[_rangeController setNeedsUpdate];
[_rangeController updateIfNeeded];
if (rangeControllerNeedsUpdate) {
[_rangeController updateRanges];
}
// When we aren't visible, we will only fetch up to the visible area. Now that we are visible,

View File

@ -64,6 +64,11 @@ AS_SUBCLASSING_RESTRICTED
*/
- (void)updateIfNeeded;
/**
* Force update the ranges immediately.
*/
- (void)updateRanges;
/**
* Add the sized node for `indexPath` as a subview of `contentView`.
*

View File

@ -154,12 +154,16 @@ static UIApplicationState __ApplicationState = UIApplicationStateActive;
- (void)updateIfNeeded
{
if (_needsRangeUpdate) {
_needsRangeUpdate = NO;
[self _updateVisibleNodeIndexPaths];
[self updateRanges];
}
}
- (void)updateRanges
{
_needsRangeUpdate = NO;
[self _updateVisibleNodeIndexPaths];
}
- (void)updateCurrentRangeWithMode:(ASLayoutRangeMode)rangeMode
{
_preserveCurrentRangeMode = YES;
@ -376,7 +380,7 @@ static UIApplicationState __ApplicationState = UIApplicationStateActive;
[newVisibleNodes addObject:node];
}
// Skip the many method calls of the recursive operation if the top level cell node already has the right interfaceState.
if (node.interfaceState != interfaceState) {
if (node.pendingInterfaceState != interfaceState) {
#if ASRangeControllerLoggingEnabled
[modifiedIndexPaths addObject:indexPath];
#endif