You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
// Profiling has shown that locking this method is beneficial, so each of the property accesses don't have to lock and unlock.
1546
1546
ASDN::MutexLocker l(_propertyLock);
1547
1547
1548
-
if (!self.inHierarchy && !_flags.visibilityNotificationsDisabled && ![self__selfOrParentHasVisibilityNotificationsDisabled]) {
1549
-
self.inHierarchy = YES;
1548
+
if (!_flags.isInHierarchy && !_flags.visibilityNotificationsDisabled && ![self__selfOrParentHasVisibilityNotificationsDisabled]) {
1550
1549
_flags.isEnteringHierarchy = YES;
1551
-
if (self.shouldRasterizeDescendants) {
1550
+
_flags.isInHierarchy = YES;
1551
+
1552
+
if (_flags.shouldRasterizeDescendants) {
1552
1553
// Nodes that are descendants of a rasterized container do not have views or layers, and so cannot receive visibility notifications directly via orderIn/orderOut CALayer actions. Manually send visibility notifications to rasterized descendants.
1553
1554
[self_recursiveWillEnterHierarchy];
1554
1555
} else {
@@ -1568,7 +1569,7 @@ - (void)__enterHierarchy
1568
1569
[self_setupPlaceholderLayerIfNeeded];
1569
1570
_placeholderLayer.opacity = 1.0;
1570
1571
[CATransactioncommit];
1571
-
[self.layer addSublayer:_placeholderLayer];
1572
+
[layer addSublayer:_placeholderLayer];
1572
1573
}
1573
1574
}
1574
1575
}
@@ -1582,18 +1583,34 @@ - (void)__exitHierarchy
1582
1583
// Profiling has shown that locking this method is beneficial, so each of the property accesses don't have to lock and unlock.
1583
1584
ASDN::MutexLocker l(_propertyLock);
1584
1585
1585
-
if (self.inHierarchy && !_flags.visibilityNotificationsDisabled && ![self__selfOrParentHasVisibilityNotificationsDisabled]) {
1586
-
self.inHierarchy = NO;
1586
+
if (_flags.isInHierarchy && !_flags.visibilityNotificationsDisabled && ![self__selfOrParentHasVisibilityNotificationsDisabled]) {
1587
+
_flags.isExitingHierarchy = YES;
1588
+
_flags.isInHierarchy = NO;
1587
1589
1588
1590
[self.asyncLayer cancelAsyncDisplay];
1589
1591
1590
-
_flags.isExitingHierarchy = YES;
1591
-
if (self.shouldRasterizeDescendants) {
1592
+
if (_flags.shouldRasterizeDescendants) {
1592
1593
// Nodes that are descendants of a rasterized container do not have views or layers, and so cannot receive visibility notifications directly via orderIn/orderOut CALayer actions. Manually send visibility notifications to rasterized descendants.
1593
1594
[self_recursiveDidExitHierarchy];
1594
-
} else {
1595
-
[selfdidExitHierarchy];
1596
1595
}
1596
+
1597
+
// This case is important when tearing down hierarchies. We must deliver a visibilityDidChange:NO callback, as part our API guarantee that this method can be used for
1598
+
// things like data analytics about user content viewing. We cannot call the method in the dealloc as any incidental retain operations in client code would fail.
1599
+
// Additionally, it may be that a Standard UIView which is containing us is moving between hierarchies, and we should not send the call if we will be re-added in the
1600
+
// same runloop. Strategy: strong reference (might be the last!), wait one runloop, and confirm we are still outside the hierarchy (both layer-backed and view-backed).
1601
+
// TODO: This approach could be optimized by only performing the dispatch for root elements + recursively apply the interface state change. This would require a closer
1602
+
// integration with _ASDisplayLayer to ensure that the superlayer pointer has been cleared by this stage (to check if we are root or not), or a different delegate call.
1603
+
1604
+
if (ASInterfaceStateIncludesVisible(_interfaceState)) {
1605
+
dispatch_async(dispatch_get_main_queue(), ^{
1606
+
ASDN::MutexLocker l(_propertyLock);
1607
+
if (!_flags.isInHierarchy && ASInterfaceStateIncludesVisible(_interfaceState)) {
0 commit comments