Skip to content

Commit

Permalink
[ASDisplayNode] Always return the thread-safe cornerRadius property, …
Browse files Browse the repository at this point in the history
…even in slow CALayer rounding mode (TextureGroup#749)

- Failing to do so will introduce race conditions in which the property was updated on a background thread but main thread has not executed the block that updates the property of the node's layer. During that window, the layer's property is out-of-date and can't be used.
- After this change, ASDisplayNode's cornerRadius is the only source of truth and users must always use it instead of CALayer's.
  • Loading branch information
nguyenhuy authored and bernieperez committed Apr 25, 2018
1 parent 20953a3 commit 060bdd2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## master
* Add your own contributions to the next release on the line below this with your name.
- **Important** ASDisplayNode's cornerRadius is a new thread-safe bridged property that should be preferred over CALayer's. Use the latter at your own risk! [Huy Nguyen](https://github.com/nguyenhuy) [#749](https://github.com/TextureGroup/Texture/pull/749).
- [ASCellNode] Adds mapping for UITableViewCell focusStyle [Alex Hill](https://github.com/alexhillc) [#727](https://github.com/TextureGroup/Texture/pull/727)
- [ASNetworkImageNode] Fix capturing self in the block while loading image in ASNetworkImageNode. [Denis Mororozov](https://github.com/morozkin) [#777](https://github.com/TextureGroup/Texture/pull/777)
- [ASTraitCollection] Add new properties of UITraitCollection to ASTraitCollection. [Yevgen Pogribnyi](https://github.com/ypogribnyi)
Expand Down
6 changes: 6 additions & 0 deletions Source/ASDisplayNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,12 @@ extern NSInteger const ASDefaultDrawingPriority;
* @default ASCornerRoundingTypeDefaultSlowCALayer
*/
@property (nonatomic, assign) ASCornerRoundingType cornerRoundingType; // default=Slow CALayer .cornerRadius (offscreen rendering)

/** @abstract The radius to use when rounding corners of the ASDisplayNode.
*
* @discussion This property is thread-safe and should always be preferred over CALayer's cornerRadius property,
* even if corner rounding type is ASCornerRoundingTypeDefaultSlowCALayer.
*/
@property (nonatomic, assign) CGFloat cornerRadius; // default=0.0

@property (nonatomic, assign) BOOL clipsToBounds; // default==NO
Expand Down
12 changes: 3 additions & 9 deletions Source/Private/ASDisplayNode+UIViewBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,12 @@ - (void)setAlpha:(CGFloat)newAlpha
- (CGFloat)cornerRadius
{
ASDN::MutexLocker l(__instanceLock__);
if (_cornerRoundingType == ASCornerRoundingTypeDefaultSlowCALayer) {
return self.layerCornerRadius;
} else {
return _cornerRadius;
}
return _cornerRadius;
}

- (void)setCornerRadius:(CGFloat)newCornerRadius
{
ASDN::MutexLocker l(__instanceLock__);
[self updateCornerRoundingWithType:_cornerRoundingType cornerRadius:newCornerRadius];
[self updateCornerRoundingWithType:self.cornerRoundingType cornerRadius:newCornerRadius];
}

- (ASCornerRoundingType)cornerRoundingType
Expand All @@ -207,8 +202,7 @@ - (ASCornerRoundingType)cornerRoundingType

- (void)setCornerRoundingType:(ASCornerRoundingType)newRoundingType
{
ASDN::MutexLocker l(__instanceLock__);
[self updateCornerRoundingWithType:newRoundingType cornerRadius:_cornerRadius];
[self updateCornerRoundingWithType:newRoundingType cornerRadius:self.cornerRadius];
}

- (NSString *)contentsGravity
Expand Down

0 comments on commit 060bdd2

Please sign in to comment.