Skip to content

Commit ae2b3af

Browse files
committedMar 14, 2019
Revert "Add setNeedsLayout to yoga tree changes. (#1361)"
This reverts commit babd81b.
1 parent 9d77ef9 commit ae2b3af

File tree

3 files changed

+90
-154
lines changed

3 files changed

+90
-154
lines changed
 

‎Source/ASDisplayNode+Layout.mm

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@
2323

2424
using AS::MutexLocker;
2525

26-
@interface ASDisplayNode (ASLayoutElementStyleDelegate) <ASLayoutElementStyleDelegate>
27-
@end
28-
29-
@implementation ASDisplayNode (ASLayoutElementStyleDelegate)
30-
31-
#pragma mark <ASLayoutElementStyleDelegate>
32-
33-
- (void)style:(ASLayoutElementStyle *)style propertyDidChange:(NSString *)propertyName {
34-
[self setNeedsLayout];
35-
}
36-
37-
@end
38-
3926
#pragma mark - ASDisplayNode (ASLayoutElement)
4027

4128
@implementation ASDisplayNode (ASLayoutElement)
@@ -59,9 +46,8 @@ - (ASLayoutElementStyle *)style
5946

6047
- (ASLayoutElementStyle *)_locked_style
6148
{
62-
ASAssertLocked(__instanceLock__);
6349
if (_style == nil) {
64-
_style = [[ASLayoutElementStyle alloc] initWithDelegate:self];
50+
_style = [[ASLayoutElementStyle alloc] init];
6551
}
6652
return _style;
6753
}

‎Source/ASDisplayNode+Yoga.mm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ - (void)_locked_removeYogaChild:(ASDisplayNode *)child
9393

9494
// YGNodeRef removal is done in setParent:
9595
child.yogaParent = nil;
96-
[self setNeedsLayout];
9796
}
9897

9998
- (void)insertYogaChild:(ASDisplayNode *)child atIndex:(NSUInteger)index
@@ -118,7 +117,6 @@ - (void)_locked_insertYogaChild:(ASDisplayNode *)child atIndex:(NSUInteger)index
118117

119118
// YGNodeRef insertion is done in setParent:
120119
child.yogaParent = self;
121-
[self setNeedsLayout];
122120
}
123121

124122
#pragma mark - Subclass Hooks

‎Source/Layout/ASLayoutElement.mm

Lines changed: 89 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,12 @@ void ASLayoutElementPopContext()
141141
NSString * const ASYogaAspectRatioProperty = @"ASYogaAspectRatioProperty";
142142
#endif
143143

144-
#define ASLayoutElementStyleSetSizeWithScope(x) \
145-
({ \
146-
__instanceLock__.lock(); \
147-
const ASLayoutElementSize oldSize = _size.load(); \
148-
ASLayoutElementSize newSize = oldSize; \
149-
{x}; \
150-
BOOL changed = !ASLayoutElementSizeEqualToLayoutElementSize(oldSize, newSize); \
151-
if (changed) { \
152-
_size.store(newSize); \
153-
} \
154-
__instanceLock__.unlock(); \
155-
changed; \
156-
})
144+
#define ASLayoutElementStyleSetSizeWithScope(x) \
145+
__instanceLock__.lock(); \
146+
ASLayoutElementSize newSize = _size.load(); \
147+
{ x } \
148+
_size.store(newSize); \
149+
__instanceLock__.unlock();
157150

158151
#define ASLayoutElementStyleCallDelegate(propertyName)\
159152
do {\
@@ -211,13 +204,9 @@ - (instancetype)init
211204
{
212205
self = [super init];
213206
if (self) {
214-
std::atomic_init(&_size, ASLayoutElementSizeMake());
215-
std::atomic_init(&_flexBasis, ASDimensionAuto);
207+
_size = ASLayoutElementSizeMake();
216208
#if YOGA
217209
_parentAlignStyle = ASStackLayoutAlignItemsNotSet;
218-
std::atomic_init(&_flexDirection, ASStackLayoutDirectionVertical);
219-
std::atomic_init(&_alignItems, ASStackLayoutAlignItemsStretch);
220-
std::atomic_init(&_aspectRatio, static_cast<CGFloat>(YGUndefined));
221210
#endif
222211
}
223212
return self;
@@ -249,10 +238,10 @@ - (ASDimension)width
249238

250239
- (void)setWidth:(ASDimension)width
251240
{
252-
BOOL changed = ASLayoutElementStyleSetSizeWithScope({ newSize.width = width; });
253-
if (changed) {
254-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleWidthProperty);
255-
}
241+
ASLayoutElementStyleSetSizeWithScope({
242+
newSize.width = width;
243+
});
244+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleWidthProperty);
256245
}
257246

258247
- (ASDimension)height
@@ -262,10 +251,10 @@ - (ASDimension)height
262251

263252
- (void)setHeight:(ASDimension)height
264253
{
265-
BOOL changed = ASLayoutElementStyleSetSizeWithScope({ newSize.height = height; });
266-
if (changed) {
267-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleHeightProperty);
268-
}
254+
ASLayoutElementStyleSetSizeWithScope({
255+
newSize.height = height;
256+
});
257+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleHeightProperty);
269258
}
270259

271260
- (ASDimension)minWidth
@@ -275,10 +264,10 @@ - (ASDimension)minWidth
275264

276265
- (void)setMinWidth:(ASDimension)minWidth
277266
{
278-
BOOL changed = ASLayoutElementStyleSetSizeWithScope({ newSize.minWidth = minWidth; });
279-
if (changed) {
280-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMinWidthProperty);
281-
}
267+
ASLayoutElementStyleSetSizeWithScope({
268+
newSize.minWidth = minWidth;
269+
});
270+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMinWidthProperty);
282271
}
283272

284273
- (ASDimension)maxWidth
@@ -288,10 +277,10 @@ - (ASDimension)maxWidth
288277

289278
- (void)setMaxWidth:(ASDimension)maxWidth
290279
{
291-
BOOL changed = ASLayoutElementStyleSetSizeWithScope({ newSize.maxWidth = maxWidth; });
292-
if (changed) {
293-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxWidthProperty);
294-
}
280+
ASLayoutElementStyleSetSizeWithScope({
281+
newSize.maxWidth = maxWidth;
282+
});
283+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxWidthProperty);
295284
}
296285

297286
- (ASDimension)minHeight
@@ -301,10 +290,10 @@ - (ASDimension)minHeight
301290

302291
- (void)setMinHeight:(ASDimension)minHeight
303292
{
304-
BOOL changed = ASLayoutElementStyleSetSizeWithScope({ newSize.minHeight = minHeight; });
305-
if (changed) {
306-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMinHeightProperty);
307-
}
293+
ASLayoutElementStyleSetSizeWithScope({
294+
newSize.minHeight = minHeight;
295+
});
296+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMinHeightProperty);
308297
}
309298

310299
- (ASDimension)maxHeight
@@ -314,25 +303,23 @@ - (ASDimension)maxHeight
314303

315304
- (void)setMaxHeight:(ASDimension)maxHeight
316305
{
317-
BOOL changed = ASLayoutElementStyleSetSizeWithScope({ newSize.maxHeight = maxHeight; });
318-
if (changed) {
319-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxHeightProperty);
320-
}
306+
ASLayoutElementStyleSetSizeWithScope({
307+
newSize.maxHeight = maxHeight;
308+
});
309+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxHeightProperty);
321310
}
322311

323312

324313
#pragma mark - ASLayoutElementStyleSizeHelpers
325314

326315
- (void)setPreferredSize:(CGSize)preferredSize
327316
{
328-
BOOL changed = ASLayoutElementStyleSetSizeWithScope({
317+
ASLayoutElementStyleSetSizeWithScope({
329318
newSize.width = ASDimensionMakeWithPoints(preferredSize.width);
330319
newSize.height = ASDimensionMakeWithPoints(preferredSize.height);
331320
});
332-
if (changed) {
333-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleWidthProperty);
334-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleHeightProperty);
335-
}
321+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleWidthProperty);
322+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleHeightProperty);
336323
}
337324

338325
- (CGSize)preferredSize
@@ -353,26 +340,22 @@ - (CGSize)preferredSize
353340

354341
- (void)setMinSize:(CGSize)minSize
355342
{
356-
BOOL changed = ASLayoutElementStyleSetSizeWithScope({
343+
ASLayoutElementStyleSetSizeWithScope({
357344
newSize.minWidth = ASDimensionMakeWithPoints(minSize.width);
358345
newSize.minHeight = ASDimensionMakeWithPoints(minSize.height);
359346
});
360-
if (changed) {
361-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMinWidthProperty);
362-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMinHeightProperty);
363-
}
347+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMinWidthProperty);
348+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMinHeightProperty);
364349
}
365350

366351
- (void)setMaxSize:(CGSize)maxSize
367352
{
368-
BOOL changed = ASLayoutElementStyleSetSizeWithScope({
353+
ASLayoutElementStyleSetSizeWithScope({
369354
newSize.maxWidth = ASDimensionMakeWithPoints(maxSize.width);
370355
newSize.maxHeight = ASDimensionMakeWithPoints(maxSize.height);
371356
});
372-
if (changed) {
373-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxWidthProperty);
374-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxHeightProperty);
375-
}
357+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxWidthProperty);
358+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxHeightProperty);
376359
}
377360

378361
- (ASLayoutSize)preferredLayoutSize
@@ -383,14 +366,12 @@ - (ASLayoutSize)preferredLayoutSize
383366

384367
- (void)setPreferredLayoutSize:(ASLayoutSize)preferredLayoutSize
385368
{
386-
BOOL changed = ASLayoutElementStyleSetSizeWithScope({
369+
ASLayoutElementStyleSetSizeWithScope({
387370
newSize.width = preferredLayoutSize.width;
388371
newSize.height = preferredLayoutSize.height;
389372
});
390-
if (changed) {
391-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleWidthProperty);
392-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleHeightProperty);
393-
}
373+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleWidthProperty);
374+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleHeightProperty);
394375
}
395376

396377
- (ASLayoutSize)minLayoutSize
@@ -401,14 +382,12 @@ - (ASLayoutSize)minLayoutSize
401382

402383
- (void)setMinLayoutSize:(ASLayoutSize)minLayoutSize
403384
{
404-
BOOL changed = ASLayoutElementStyleSetSizeWithScope({
385+
ASLayoutElementStyleSetSizeWithScope({
405386
newSize.minWidth = minLayoutSize.width;
406387
newSize.minHeight = minLayoutSize.height;
407388
});
408-
if (changed) {
409-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMinWidthProperty);
410-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMinHeightProperty);
411-
}
389+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMinWidthProperty);
390+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMinHeightProperty);
412391
}
413392

414393
- (ASLayoutSize)maxLayoutSize
@@ -419,23 +398,20 @@ - (ASLayoutSize)maxLayoutSize
419398

420399
- (void)setMaxLayoutSize:(ASLayoutSize)maxLayoutSize
421400
{
422-
BOOL changed = ASLayoutElementStyleSetSizeWithScope({
401+
ASLayoutElementStyleSetSizeWithScope({
423402
newSize.maxWidth = maxLayoutSize.width;
424403
newSize.maxHeight = maxLayoutSize.height;
425404
});
426-
if (changed) {
427-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxWidthProperty);
428-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxHeightProperty);
429-
}
405+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxWidthProperty);
406+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleMaxHeightProperty);
430407
}
431408

432409
#pragma mark - ASStackLayoutElement
433410

434411
- (void)setSpacingBefore:(CGFloat)spacingBefore
435412
{
436-
if (_spacingBefore.exchange(spacingBefore) != spacingBefore) {
437-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleSpacingBeforeProperty);
438-
}
413+
_spacingBefore.store(spacingBefore);
414+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleSpacingBeforeProperty);
439415
}
440416

441417
- (CGFloat)spacingBefore
@@ -445,9 +421,8 @@ - (CGFloat)spacingBefore
445421

446422
- (void)setSpacingAfter:(CGFloat)spacingAfter
447423
{
448-
if (_spacingAfter.exchange(spacingAfter) != spacingAfter) {
449-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleSpacingAfterProperty);
450-
}
424+
_spacingAfter.store(spacingAfter);
425+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleSpacingAfterProperty);
451426
}
452427

453428
- (CGFloat)spacingAfter
@@ -457,9 +432,8 @@ - (CGFloat)spacingAfter
457432

458433
- (void)setFlexGrow:(CGFloat)flexGrow
459434
{
460-
if (_flexGrow.exchange(flexGrow) != flexGrow) {
461-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleFlexGrowProperty);
462-
}
435+
_flexGrow.store(flexGrow);
436+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleFlexGrowProperty);
463437
}
464438

465439
- (CGFloat)flexGrow
@@ -469,9 +443,8 @@ - (CGFloat)flexGrow
469443

470444
- (void)setFlexShrink:(CGFloat)flexShrink
471445
{
472-
if (_flexShrink.exchange(flexShrink) != flexShrink) {
473-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleFlexShrinkProperty);
474-
}
446+
_flexShrink.store(flexShrink);
447+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleFlexShrinkProperty);
475448
}
476449

477450
- (CGFloat)flexShrink
@@ -481,9 +454,8 @@ - (CGFloat)flexShrink
481454

482455
- (void)setFlexBasis:(ASDimension)flexBasis
483456
{
484-
if (!ASDimensionEqualToDimension(_flexBasis.exchange(flexBasis), flexBasis)) {
485-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleFlexBasisProperty);
486-
}
457+
_flexBasis.store(flexBasis);
458+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleFlexBasisProperty);
487459
}
488460

489461
- (ASDimension)flexBasis
@@ -493,9 +465,8 @@ - (ASDimension)flexBasis
493465

494466
- (void)setAlignSelf:(ASStackLayoutAlignSelf)alignSelf
495467
{
496-
if (_alignSelf.exchange(alignSelf) != alignSelf) {
497-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleAlignSelfProperty);
498-
}
468+
_alignSelf.store(alignSelf);
469+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleAlignSelfProperty);
499470
}
500471

501472
- (ASStackLayoutAlignSelf)alignSelf
@@ -505,9 +476,8 @@ - (ASStackLayoutAlignSelf)alignSelf
505476

506477
- (void)setAscender:(CGFloat)ascender
507478
{
508-
if (_ascender.exchange(ascender) != ascender) {
509-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleAscenderProperty);
510-
}
479+
_ascender.store(ascender);
480+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleAscenderProperty);
511481
}
512482

513483
- (CGFloat)ascender
@@ -517,9 +487,8 @@ - (CGFloat)ascender
517487

518488
- (void)setDescender:(CGFloat)descender
519489
{
520-
if (_descender.exchange(descender) != descender) {
521-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleDescenderProperty);
522-
}
490+
_descender.store(descender);
491+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleDescenderProperty);
523492
}
524493

525494
- (CGFloat)descender
@@ -531,9 +500,8 @@ - (CGFloat)descender
531500

532501
- (void)setLayoutPosition:(CGPoint)layoutPosition
533502
{
534-
if (!CGPointEqualToPoint(_layoutPosition.exchange(layoutPosition), layoutPosition)) {
535-
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleLayoutPositionProperty);
536-
}
503+
_layoutPosition.store(layoutPosition);
504+
ASLayoutElementStyleCallDelegate(ASLayoutElementStyleLayoutPositionProperty);
537505
}
538506

539507
- (CGPoint)layoutPosition
@@ -821,64 +789,48 @@ - (ASStackLayoutAlignItems)parentAlignStyle {
821789
}
822790

823791
- (void)setFlexWrap:(YGWrap)flexWrap {
824-
if (_flexWrap.exchange(flexWrap) != flexWrap) {
825-
ASLayoutElementStyleCallDelegate(ASYogaFlexWrapProperty);
826-
}
792+
_flexWrap.store(flexWrap);
793+
ASLayoutElementStyleCallDelegate(ASYogaFlexWrapProperty);
827794
}
828795
- (void)setFlexDirection:(ASStackLayoutDirection)flexDirection {
829-
if (_flexDirection.exchange(flexDirection) != flexDirection) {
830-
ASLayoutElementStyleCallDelegate(ASYogaFlexDirectionProperty);
831-
}
796+
_flexDirection.store(flexDirection);
797+
ASLayoutElementStyleCallDelegate(ASYogaFlexDirectionProperty);
832798
}
833799
- (void)setDirection:(YGDirection)direction {
834-
if (_direction.exchange(direction) != direction) {
835-
ASLayoutElementStyleCallDelegate(ASYogaDirectionProperty);
836-
}
800+
_direction.store(direction);
801+
ASLayoutElementStyleCallDelegate(ASYogaDirectionProperty);
837802
}
838803
- (void)setJustifyContent:(ASStackLayoutJustifyContent)justify {
839-
if (_justifyContent.exchange(justify) != justify) {
840-
ASLayoutElementStyleCallDelegate(ASYogaJustifyContentProperty);
841-
}
804+
_justifyContent.store(justify);
805+
ASLayoutElementStyleCallDelegate(ASYogaJustifyContentProperty);
842806
}
843807
- (void)setAlignItems:(ASStackLayoutAlignItems)alignItems {
844-
if (_alignItems.exchange(alignItems) != alignItems) {
845-
ASLayoutElementStyleCallDelegate(ASYogaAlignItemsProperty);
846-
}
808+
_alignItems.store(alignItems);
809+
ASLayoutElementStyleCallDelegate(ASYogaAlignItemsProperty);
847810
}
848811
- (void)setPositionType:(YGPositionType)positionType {
849-
if (_positionType.exchange(positionType) != positionType) {
850-
ASLayoutElementStyleCallDelegate(ASYogaPositionTypeProperty);
851-
}
812+
_positionType.store(positionType);
813+
ASLayoutElementStyleCallDelegate(ASYogaPositionTypeProperty);
852814
}
853-
/// TODO: smart compare ASEdgeInsets instead of memory compare.
854815
- (void)setPosition:(ASEdgeInsets)position {
855-
ASEdgeInsets oldValue = _position.exchange(position);
856-
if (0 != memcmp(&position, &oldValue, sizeof(ASEdgeInsets))) {
857-
ASLayoutElementStyleCallDelegate(ASYogaPositionProperty);
858-
}
816+
_position.store(position);
817+
ASLayoutElementStyleCallDelegate(ASYogaPositionProperty);
859818
}
860819
- (void)setMargin:(ASEdgeInsets)margin {
861-
ASEdgeInsets oldValue = _margin.exchange(margin);
862-
if (0 != memcmp(&margin, &oldValue, sizeof(ASEdgeInsets))) {
863-
ASLayoutElementStyleCallDelegate(ASYogaMarginProperty);
864-
}
820+
_margin.store(margin);
821+
ASLayoutElementStyleCallDelegate(ASYogaMarginProperty);
865822
}
866823
- (void)setPadding:(ASEdgeInsets)padding {
867-
ASEdgeInsets oldValue = _padding.exchange(padding);
868-
if (0 != memcmp(&padding, &oldValue, sizeof(ASEdgeInsets))) {
869-
ASLayoutElementStyleCallDelegate(ASYogaPaddingProperty);
870-
}
824+
_padding.store(padding);
825+
ASLayoutElementStyleCallDelegate(ASYogaPaddingProperty);
871826
}
872827
- (void)setBorder:(ASEdgeInsets)border {
873-
ASEdgeInsets oldValue = _border.exchange(border);
874-
if (0 != memcmp(&border, &oldValue, sizeof(ASEdgeInsets))) {
875-
ASLayoutElementStyleCallDelegate(ASYogaBorderProperty);
876-
}
828+
_border.store(border);
829+
ASLayoutElementStyleCallDelegate(ASYogaBorderProperty);
877830
}
878831
- (void)setAspectRatio:(CGFloat)aspectRatio {
879-
if (_aspectRatio.exchange(aspectRatio) != aspectRatio) {
880-
ASLayoutElementStyleCallDelegate(ASYogaAspectRatioProperty);
881-
}
832+
_aspectRatio.store(aspectRatio);
833+
ASLayoutElementStyleCallDelegate(ASYogaAspectRatioProperty);
882834
}
883835
// private (ASLayoutElementStylePrivate.h)
884836
- (void)setParentAlignStyle:(ASStackLayoutAlignItems)style {

0 commit comments

Comments
 (0)
Please sign in to comment.