[ASCellNode] Add gating for -convertRect: call upon invisibility notification for iOS 7 & 8 edge case. (#1881)

* [ASCellNode] Add gating for -convertRect: call upon invisibility notification for iOS 7 & 8 edge case.

This should resolve https://github.com/facebook/AsyncDisplayKit/issues/1659, which corresponds to this
Fabric log for Pinterest: https://fabric.io/pinterest6/ios/apps/com.pinterest.enterprise/issues/5776fbfeffcdc042501a5f20/sessions/c178e977614b4ebab853084847fb241
8

* [ASCellNode] Additional improvements to visibilityDidChange: gating.
This commit is contained in:
appleguy
2016-07-10 16:01:55 -07:00
committed by GitHub
parent 5856bd3b59
commit a9e3eacfe5

View File

@@ -272,13 +272,21 @@
{
[super visibleStateDidChange:isVisible];
ASDisplayNodeAssert(self.isNodeLoaded, @"Node should be loaded in order for it to become visible or invisible. If not in this situation, we shouldn't trigger creating the view.");
UIView *view = self.view;
CGRect cellFrame = CGRectZero;
if (_scrollView) {
// It is not safe to message nil with a structure return value, so ensure our _scrollView has not died.
cellFrame = [self.view convertRect:self.bounds toView:_scrollView];
// Ensure our _scrollView is still valid before converting. It's also possible that we have already been removed from the _scrollView,
// in which case it is not valid to perform a convertRect (this actually crashes on iOS 7 and 8).
UIScrollView *scrollView = (_scrollView != nil && view.superview != nil && [view isDescendantOfView:_scrollView]) ? _scrollView : nil;
if (scrollView) {
cellFrame = [view convertRect:view.bounds toView:_scrollView];
}
// If we did not convert, we'll pass along CGRectZero and a nil scrollView. The EventInvisible call is thus equivalent to
// visibleStateDidChange:NO, but is more convenient for the developer than implementing multiple methods.
[self cellNodeVisibilityEvent:isVisible ? ASCellNodeVisibilityEventVisible : ASCellNodeVisibilityEventInvisible
inScrollView:_scrollView
inScrollView:scrollView
withCellFrame:cellFrame];
}