diff --git a/Source/ASDisplayNode+Layout.mm b/Source/ASDisplayNode+Layout.mm index 66eb99879..592b18db9 100644 --- a/Source/ASDisplayNode+Layout.mm +++ b/Source/ASDisplayNode+Layout.mm @@ -128,15 +128,18 @@ - (ASLayout *)layoutThatFits:(ASSizeRange)constrainedSize parentSize:(CGSize)par - (ASPrimitiveTraitCollection)primitiveTraitCollection { - return _primitiveTraitCollection.load(); + AS::MutexLocker l(__instanceLock__); + return _primitiveTraitCollection; } - (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection { - if (ASPrimitiveTraitCollectionIsEqualToASPrimitiveTraitCollection(traitCollection, _primitiveTraitCollection.load()) == NO) { + AS::UniqueLock l(__instanceLock__); + if (ASPrimitiveTraitCollectionIsEqualToASPrimitiveTraitCollection(traitCollection, _primitiveTraitCollection) == NO) { _primitiveTraitCollection = traitCollection; ASDisplayNodeLogEvent(self, @"asyncTraitCollectionDidChange: %@", NSStringFromASPrimitiveTraitCollection(traitCollection)); + l.unlock(); [self asyncTraitCollectionDidChange]; } } diff --git a/Source/Details/ASTraitCollection.h b/Source/Details/ASTraitCollection.h index 68244a660..17e1740c1 100644 --- a/Source/Details/ASTraitCollection.h +++ b/Source/Details/ASTraitCollection.h @@ -106,16 +106,6 @@ AS_EXTERN void ASTraitCollectionPropagateDown(id element, ASPri @end -#define ASPrimitiveTraitCollectionDefaults \ -- (ASPrimitiveTraitCollection)primitiveTraitCollection\ -{\ - return _primitiveTraitCollection.load();\ -}\ -- (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection\ -{\ - _primitiveTraitCollection = traitCollection;\ -}\ - #define ASLayoutElementCollectionTableSetTraitCollection(lock) \ - (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection\ {\ diff --git a/Source/Layout/ASLayoutSpec.mm b/Source/Layout/ASLayoutSpec.mm index 8da22d3d0..2bcb92787 100644 --- a/Source/Layout/ASLayoutSpec.mm +++ b/Source/Layout/ASLayoutSpec.mm @@ -146,7 +146,17 @@ - (ASTraitCollection *)asyncTraitCollection return [ASTraitCollection traitCollectionWithASPrimitiveTraitCollection:self.primitiveTraitCollection]; } -ASPrimitiveTraitCollectionDefaults +- (ASPrimitiveTraitCollection)primitiveTraitCollection +{ + AS::MutexLocker l(__instanceLock__); + return _primitiveTraitCollection; +} + +- (void)setPrimitiveTraitCollection:(ASPrimitiveTraitCollection)traitCollection +{ + AS::MutexLocker l(__instanceLock__); + _primitiveTraitCollection = traitCollection; +} #pragma mark - ASLayoutElementStyleExtensibility diff --git a/Source/Private/ASDisplayNodeInternal.h b/Source/Private/ASDisplayNodeInternal.h index 879639f16..0cb4f1cc7 100644 --- a/Source/Private/ASDisplayNodeInternal.h +++ b/Source/Private/ASDisplayNodeInternal.h @@ -153,7 +153,7 @@ static constexpr CACornerMask kASCACornerAllCorners = // Layout support ASLayoutElementStyle *_style; - std::atomic _primitiveTraitCollection; + ASPrimitiveTraitCollection _primitiveTraitCollection; // Layout Spec ASLayoutSpecBlock _layoutSpecBlock; diff --git a/Source/Private/_ASCollectionGalleryLayoutItem.mm b/Source/Private/_ASCollectionGalleryLayoutItem.mm index 573370299..e0faa1802 100644 --- a/Source/Private/_ASCollectionGalleryLayoutItem.mm +++ b/Source/Private/_ASCollectionGalleryLayoutItem.mm @@ -14,9 +14,12 @@ #import #import -@implementation _ASGalleryLayoutItem { - std::atomic _primitiveTraitCollection; -} +@interface _ASGalleryLayoutItem () +@property ASPrimitiveTraitCollection primitiveTraitCollection; + +@end + +@implementation _ASGalleryLayoutItem @synthesize style; @@ -33,7 +36,6 @@ - (instancetype)initWithItemSize:(CGSize)itemSize collectionElement:(ASCollectio } ASLayoutElementStyleExtensibilityForwarding -ASPrimitiveTraitCollectionDefaults - (ASTraitCollection *)asyncTraitCollection {