Skip to content

Commit

Permalink
Fix bug in ASRangeController that causes some cell nodes of a collect…
Browse files Browse the repository at this point in the history
…ion view which is about to becomes invisible to load their backing view/layer and render (#1418)
  • Loading branch information
nguyenhuy committed Mar 22, 2019
1 parent ae2b3af commit 4dbd699
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Schemas/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"exp_disable_a11y_cache",
"exp_dispatch_apply",
"exp_image_downloader_priority",
"exp_text_drawing"
"exp_text_drawing",
"exp_fix_range_controller"
]
}
}
Expand Down
1 change: 1 addition & 0 deletions Source/ASExperimentalFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef NS_OPTIONS(NSUInteger, ASExperimentalFeatures) {
ASExperimentalDispatchApply = 1 << 10, // exp_dispatch_apply
ASExperimentalImageDownloaderPriority = 1 << 11, // exp_image_downloader_priority
ASExperimentalTextDrawing = 1 << 12, // exp_text_drawing
ASExperimentalFixRangeController = 1 << 13, // exp_fix_range_controller
ASExperimentalFeatureAll = 0xFFFFFFFF
};

Expand Down
3 changes: 2 additions & 1 deletion Source/ASExperimentalFeatures.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
@"exp_disable_a11y_cache",
@"exp_dispatch_apply",
@"exp_image_downloader_priority",
@"exp_text_drawing"]));
@"exp_text_drawing",
@"exp_fix_range_controller"]));
if (flags == ASExperimentalFeatureAll) {
return allNames;
}
Expand Down
28 changes: 16 additions & 12 deletions Source/Details/ASRangeController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -349,21 +349,25 @@ - (void)_updateVisibleNodeIndexPaths
}
}
} else {
// If selfInterfaceState isn't visible, then visibleIndexPaths represents what /will/ be immediately visible at the
// instant we come onscreen. So, preload and display all of those things, but don't waste resources preloading yet.
// We handle this as a separate case to minimize set operations for offscreen preloading, including containsObject:.
// If selfInterfaceState isn't visible, then visibleIndexPaths represents either what /will/ be immediately visible at the
// instant we come onscreen, or what /will/ no longer be visible at the instant we come offscreen.
// So, preload and display all of those things, but don't waste resources preloading others.
// We handle this as a separate case to minimize set operations, including -containsObject:.
//
// DO NOT set Visible: even though these elements are in the visible range / "viewport",
// our overall container object is itself not yet, or no longer, visible.
// The moment it becomes visible, we will run the condition above.

BOOL shouldUpdateInterfaceState = NO;
if (ASActivateExperimentalFeature(ASExperimentalFixRangeController)) {
shouldUpdateInterfaceState = [visibleIndexPaths containsObject:indexPath];
} else {
shouldUpdateInterfaceState = [allCurrentIndexPaths containsObject:indexPath];
}

if ([allCurrentIndexPaths containsObject:indexPath]) {
// DO NOT set Visible: even though these elements are in the visible range / "viewport",
// our overall container object is itself not visible yet. The moment it becomes visible, we will run the condition above

// Set Layout, Preload
if (shouldUpdateInterfaceState) {
interfaceState |= ASInterfaceStatePreload;

if (rangeMode != ASLayoutRangeModeLowMemory) {
// Add Display.
// We might be looking at an indexPath that was previously in-range, but now we need to clear it.
// In that case we'll just set it back to MeasureLayout. Only set Display | Preload if in allCurrentIndexPaths.
interfaceState |= ASInterfaceStateDisplay;
}
}
Expand Down
6 changes: 4 additions & 2 deletions Tests/ASConfigurationTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
ASExperimentalDisableAccessibilityCache,
ASExperimentalDispatchApply,
ASExperimentalImageDownloaderPriority,
ASExperimentalTextDrawing
ASExperimentalTextDrawing,
ASExperimentalFixRangeController
};

@interface ASConfigurationTests : ASTestCase <ASConfigurationDelegate>
Expand All @@ -55,7 +56,8 @@ + (NSArray *)names {
@"exp_disable_a11y_cache",
@"exp_dispatch_apply",
@"exp_image_downloader_priority",
@"exp_text_drawing"
@"exp_text_drawing",
@"exp_fix_range_controller"
];
}

Expand Down

0 comments on commit 4dbd699

Please sign in to comment.