_ASPendingState.mm
ASPendingStateFlags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
typedef struct {
// Properties
int needsDisplay:1;
int needsLayout:1;
int layoutIfNeeded:1;
// Flags indicating that a given property should be applied to the view at creation
int setClipsToBounds:1;
int setOpaque:1;
int setNeedsDisplayOnBoundsChange:1;
int setAutoresizesSubviews:1;
int setAutoresizingMask:1;
int setFrame:1;
int setBounds:1;
int setBackgroundColor:1;
int setTintColor:1;
int setHidden:1;
int setAlpha:1;
int setCornerRadius:1;
int setContentMode:1;
int setNeedsDisplay:1;
int setAnchorPoint:1;
int setPosition:1;
int setZPosition:1;
int setTransform:1;
int setSublayerTransform:1;
int setContents:1;
int setContentsGravity:1;
int setContentsRect:1;
int setContentsCenter:1;
int setContentsScale:1;
int setRasterizationScale:1;
int setUserInteractionEnabled:1;
int setExclusiveTouch:1;
int setShadowColor:1;
int setShadowOpacity:1;
int setShadowOffset:1;
int setShadowRadius:1;
int setBorderWidth:1;
int setBorderColor:1;
int setAsyncTransactionContainer:1;
int setAllowsGroupOpacity:1;
int setAllowsEdgeAntialiasing:1;
int setEdgeAntialiasingMask:1;
int setIsAccessibilityElement:1;
int setAccessibilityLabel:1;
int setAccessibilityAttributedLabel:1;
int setAccessibilityHint:1;
int setAccessibilityAttributedHint:1;
int setAccessibilityValue:1;
int setAccessibilityAttributedValue:1;
int setAccessibilityTraits:1;
int setAccessibilityFrame:1;
int setAccessibilityLanguage:1;
int setAccessibilityElementsHidden:1;
int setAccessibilityViewIsModal:1;
int setShouldGroupAccessibilityChildren:1;
int setAccessibilityIdentifier:1;
int setAccessibilityNavigationStyle:1;
int setAccessibilityHeaderElements:1;
int setAccessibilityActivationPoint:1;
int setAccessibilityPath:1;
int setSemanticContentAttribute:1;
int setLayoutMargins:1;
int setPreservesSuperviewLayoutMargins:1;
int setInsetsLayoutMarginsFromSafeArea:1;
int setAccessibilityCustomActions:1;
} ASPendingStateFlags;
_ASPendingState
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
@implementation _ASPendingState
{
@package //Expose all ivars for ASDisplayNode to bypass getters for efficiency
UIViewAutoresizing autoresizingMask;
unsigned int edgeAntialiasingMask;
CGRect frame; // Frame is only to be used for synchronous views wrapped by nodes (see setFrame:)
CGRect bounds;
CGColorRef backgroundColor;
CGFloat alpha;
CGFloat cornerRadius;
UIViewContentMode contentMode;
CGPoint anchorPoint;
CGPoint position;
CGFloat zPosition;
CATransform3D transform;
CATransform3D sublayerTransform;
id contents;
NSString *contentsGravity;
CGRect contentsRect;
CGRect contentsCenter;
CGFloat contentsScale;
CGFloat rasterizationScale;
CGColorRef shadowColor;
CGFloat shadowOpacity;
CGSize shadowOffset;
CGFloat shadowRadius;
CGFloat borderWidth;
CGColorRef borderColor;
BOOL asyncTransactionContainer;
UIEdgeInsets layoutMargins;
BOOL preservesSuperviewLayoutMargins;
BOOL insetsLayoutMarginsFromSafeArea;
BOOL isAccessibilityElement;
NSString *accessibilityLabel;
NSAttributedString *accessibilityAttributedLabel;
NSString *accessibilityHint;
NSAttributedString *accessibilityAttributedHint;
NSString *accessibilityValue;
NSAttributedString *accessibilityAttributedValue;
UIAccessibilityTraits accessibilityTraits;
CGRect accessibilityFrame;
NSString *accessibilityLanguage;
BOOL accessibilityElementsHidden;
BOOL accessibilityViewIsModal;
BOOL shouldGroupAccessibilityChildren;
NSString *accessibilityIdentifier;
UIAccessibilityNavigationStyle accessibilityNavigationStyle;
NSArray *accessibilityHeaderElements;
CGPoint accessibilityActivationPoint;
UIBezierPath *accessibilityPath;
UISemanticContentAttribute semanticContentAttribute API_AVAILABLE(ios(9.0), tvos(9.0));
NSArray<UIAccessibilityCustomAction *> * accessibilityCustomActions;
ASPendingStateFlags _flags;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@synthesize clipsToBounds=clipsToBounds;
@synthesize opaque=opaque;
@synthesize frame=frame;
@synthesize bounds=bounds;
@synthesize backgroundColor=backgroundColor;
@synthesize hidden=isHidden;
@synthesize needsDisplayOnBoundsChange=needsDisplayOnBoundsChange;
@synthesize allowsGroupOpacity=allowsGroupOpacity;
@synthesize allowsEdgeAntialiasing=allowsEdgeAntialiasing;
@synthesize edgeAntialiasingMask=edgeAntialiasingMask;
@synthesize autoresizesSubviews=autoresizesSubviews;
@synthesize autoresizingMask=autoresizingMask;
@synthesize tintColor=tintColor;
@synthesize alpha=alpha;
@synthesize cornerRadius=cornerRadius;
@synthesize contentMode=contentMode;
@synthesize anchorPoint=anchorPoint;
@synthesize position=position;
@synthesize zPosition=zPosition;
@synthesize transform=transform;
@synthesize sublayerTransform=sublayerTransform;
@synthesize contents=contents;
@synthesize contentsGravity=contentsGravity;
@synthesize contentsRect=contentsRect;
@synthesize contentsCenter=contentsCenter;
@synthesize contentsScale=contentsScale;
@synthesize rasterizationScale=rasterizationScale;
@synthesize userInteractionEnabled=userInteractionEnabled;
@synthesize exclusiveTouch=exclusiveTouch;
@synthesize shadowColor=shadowColor;
@synthesize shadowOpacity=shadowOpacity;
@synthesize shadowOffset=shadowOffset;
@synthesize shadowRadius=shadowRadius;
@synthesize borderWidth=borderWidth;
@synthesize borderColor=borderColor;
@synthesize asyncdisplaykit_asyncTransactionContainer=asyncTransactionContainer;
@synthesize semanticContentAttribute=semanticContentAttribute;
@synthesize layoutMargins=layoutMargins;
@synthesize preservesSuperviewLayoutMargins=preservesSuperviewLayoutMargins;
@synthesize insetsLayoutMarginsFromSafeArea=insetsLayoutMarginsFromSafeArea;
applyToView
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
- (void)applyToView:(UIView *)view withSpecialPropertiesHandling:(BOOL)specialPropertiesHandling
{
/*
Use our convenience setters blah here instead of layer.blah
We were accidentally setting some properties on layer here, but view in UIViewBridgeOptimizations.
That could easily cause bugs where it mattered whether you set something up on a bg thread on in -didLoad
because a different setter would be called.
*/
CALayer *layer = view.layer;
ASPendingStateFlags flags = _flags;
if (__shouldSetNeedsDisplay(layer)) {
[view setNeedsDisplay];
}
if (flags.setAnchorPoint)
layer.anchorPoint = anchorPoint;
if (flags.setPosition)
layer.position = position;
if (flags.setZPosition)
layer.zPosition = zPosition;
if (flags.setBounds)
view.bounds = bounds;
if (flags.setTransform)
layer.transform = transform;
if (flags.setSublayerTransform)
layer.sublayerTransform = sublayerTransform;
if (flags.setClipsToBounds)
view.clipsToBounds = clipsToBounds;
if (flags.setBackgroundColor) {
// We have to make sure certain nodes get the background color call directly set
if (specialPropertiesHandling) {
view.backgroundColor = [UIColor colorWithCGColor:backgroundColor];
} else {
// Set the background color to the layer as in the UIView bridge we use this value as background color
layer.backgroundColor = backgroundColor;
}
}
if (flags.setTintColor)
view.tintColor = self.tintColor;
if (flags.setOpaque)
layer.opaque = opaque;
if (flags.setHidden)
view.hidden = isHidden;
if (flags.setAlpha)
view.alpha = alpha;
if (flags.setCornerRadius)
layer.cornerRadius = cornerRadius;
if (flags.setContentMode)
view.contentMode = contentMode;
if (flags.setUserInteractionEnabled)
view.userInteractionEnabled = userInteractionEnabled;
#if TARGET_OS_IOS
if (flags.setExclusiveTouch)
view.exclusiveTouch = exclusiveTouch;
#endif
if (flags.setShadowColor)
layer.shadowColor = shadowColor;
if (flags.setShadowOpacity)
layer.shadowOpacity = shadowOpacity;
if (flags.setShadowOffset)
layer.shadowOffset = shadowOffset;
if (flags.setShadowRadius)
layer.shadowRadius = shadowRadius;
if (flags.setBorderWidth)
layer.borderWidth = borderWidth;
if (flags.setBorderColor)
layer.borderColor = borderColor;
if (flags.setAutoresizingMask)
view.autoresizingMask = autoresizingMask;
if (flags.setAutoresizesSubviews)
view.autoresizesSubviews = autoresizesSubviews;
if (flags.setNeedsDisplayOnBoundsChange)
layer.needsDisplayOnBoundsChange = needsDisplayOnBoundsChange;
if (flags.setAllowsGroupOpacity)
layer.allowsGroupOpacity = allowsGroupOpacity;
if (flags.setAllowsEdgeAntialiasing)
layer.allowsEdgeAntialiasing = allowsEdgeAntialiasing;
if (flags.setEdgeAntialiasingMask)
layer.edgeAntialiasingMask = edgeAntialiasingMask;
if (flags.setAsyncTransactionContainer)
view.asyncdisplaykit_asyncTransactionContainer = asyncTransactionContainer;
if (flags.setOpaque)
ASDisplayNodeAssert(layer.opaque == opaque, @"Didn't set opaque as desired");
if (flags.setLayoutMargins)
view.layoutMargins = layoutMargins;
if (flags.setPreservesSuperviewLayoutMargins)
view.preservesSuperviewLayoutMargins = preservesSuperviewLayoutMargins;
if (AS_AVAILABLE_IOS(11.0)) {
if (flags.setInsetsLayoutMarginsFromSafeArea) {
view.insetsLayoutMarginsFromSafeArea = insetsLayoutMarginsFromSafeArea;
}
}
if (flags.setAccessibilityCustomActions) {
view.accessibilityCustomActions = accessibilityCustomActions;
}
if (flags.setSemanticContentAttribute) {
view.semanticContentAttribute = semanticContentAttribute;
}
if (flags.setIsAccessibilityElement)
view.isAccessibilityElement = isAccessibilityElement;
if (flags.setAccessibilityLabel)
view.accessibilityLabel = accessibilityLabel;
if (flags.setAccessibilityHint)
view.accessibilityHint = accessibilityHint;
if (flags.setAccessibilityValue)
view.accessibilityValue = accessibilityValue;
if (AS_AVAILABLE_IOS(11)) {
if (flags.setAccessibilityAttributedLabel) {
view.accessibilityAttributedLabel = accessibilityAttributedLabel;
}
if (flags.setAccessibilityAttributedHint) {
view.accessibilityAttributedHint = accessibilityAttributedHint;
}
if (flags.setAccessibilityAttributedValue) {
view.accessibilityAttributedValue = accessibilityAttributedValue;
}
}
if (flags.setAccessibilityTraits)
view.accessibilityTraits = accessibilityTraits;
if (flags.setAccessibilityFrame)
view.accessibilityFrame = accessibilityFrame;
if (flags.setAccessibilityLanguage)
view.accessibilityLanguage = accessibilityLanguage;
if (flags.setAccessibilityElementsHidden)
view.accessibilityElementsHidden = accessibilityElementsHidden;
if (flags.setAccessibilityViewIsModal)
view.accessibilityViewIsModal = accessibilityViewIsModal;
if (flags.setShouldGroupAccessibilityChildren)
view.shouldGroupAccessibilityChildren = shouldGroupAccessibilityChildren;
if (flags.setAccessibilityIdentifier)
view.accessibilityIdentifier = accessibilityIdentifier;
if (flags.setAccessibilityNavigationStyle)
view.accessibilityNavigationStyle = accessibilityNavigationStyle;
#if TARGET_OS_TV
if (flags.setAccessibilityHeaderElements)
view.accessibilityHeaderElements = accessibilityHeaderElements;
#endif
if (flags.setAccessibilityActivationPoint)
view.accessibilityActivationPoint = accessibilityActivationPoint;
if (flags.setAccessibilityPath)
view.accessibilityPath = accessibilityPath;
if (flags.setFrame && specialPropertiesHandling) {
// Frame is only defined when transform is identity because we explicitly diverge from CALayer behavior and define frame without transform
//#if DEBUG
// // Checking if the transform is identity is expensive, so disable when unnecessary. We have assertions on in Release, so DEBUG is the only way I know of.
// ASDisplayNodeAssert(CATransform3DIsIdentity(layer.transform), @"-[ASDisplayNode setFrame:] - self.transform must be identity in order to set the frame property. (From Apple's UIView documentation: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.)");
//#endif
view.frame = frame;
} else {
ASPendingStateApplyMetricsToLayer(self, layer);
}
if (flags.setContents)
layer.contents = contents;
if (flags.setContentsGravity)
layer.contentsGravity = contentsGravity;
if (flags.setContentsRect)
layer.contentsRect = contentsRect;
if (flags.setContentsCenter)
layer.contentsCenter = contentsCenter;
if (flags.setContentsScale)
layer.contentsScale = contentsScale;
if (flags.setRasterizationScale)
layer.rasterizationScale = rasterizationScale;
if (flags.needsLayout)
[view setNeedsLayout];
if (flags.layoutIfNeeded)
[view layoutIfNeeded];
}
hasChanges
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
- (BOOL)hasChanges
{
ASPendingStateFlags flags = _flags;
return (flags.setAnchorPoint
|| flags.setPosition
|| flags.setZPosition
|| flags.setFrame
|| flags.setBounds
|| flags.setPosition
|| flags.setTransform
|| flags.setSublayerTransform
|| flags.setContents
|| flags.setContentsGravity
|| flags.setContentsRect
|| flags.setContentsCenter
|| flags.setContentsScale
|| flags.setRasterizationScale
|| flags.setClipsToBounds
|| flags.setBackgroundColor
|| flags.setTintColor
|| flags.setHidden
|| flags.setAlpha
|| flags.setCornerRadius
|| flags.setContentMode
|| flags.setUserInteractionEnabled
|| flags.setExclusiveTouch
|| flags.setShadowOpacity
|| flags.setShadowOffset
|| flags.setShadowRadius
|| flags.setShadowColor
|| flags.setBorderWidth
|| flags.setBorderColor
|| flags.setAutoresizingMask
|| flags.setAutoresizesSubviews
|| flags.setNeedsDisplayOnBoundsChange
|| flags.setAllowsGroupOpacity
|| flags.setAllowsEdgeAntialiasing
|| flags.setEdgeAntialiasingMask
|| flags.needsDisplay
|| flags.needsLayout
|| flags.setAsyncTransactionContainer
|| flags.setOpaque
|| flags.setSemanticContentAttribute
|| flags.setLayoutMargins
|| flags.setPreservesSuperviewLayoutMargins
|| flags.setInsetsLayoutMarginsFromSafeArea
|| flags.setIsAccessibilityElement
|| flags.setAccessibilityLabel
|| flags.setAccessibilityAttributedLabel
|| flags.setAccessibilityHint
|| flags.setAccessibilityAttributedHint
|| flags.setAccessibilityValue
|| flags.setAccessibilityAttributedValue
|| flags.setAccessibilityTraits
|| flags.setAccessibilityFrame
|| flags.setAccessibilityLanguage
|| flags.setAccessibilityElementsHidden
|| flags.setAccessibilityViewIsModal
|| flags.setShouldGroupAccessibilityChildren
|| flags.setAccessibilityIdentifier
|| flags.setAccessibilityNavigationStyle
|| flags.setAccessibilityHeaderElements
|| flags.setAccessibilityActivationPoint
|| flags.setAccessibilityPath);
}
1
2
3
4
- (void)clearChanges
{
_flags = (ASPendingStateFlags){ 0 };
}