Don't animate changes to shape layer properties.

pull/1/head
Matthew Chen 7 years ago
parent e02bbaeec9
commit a5c7bdb987

@ -85,19 +85,21 @@ NS_ASSUME_NONNULL_BEGIN
return; return;
} }
// Prevent the shape layer from animating changes.
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
// Don't fill the shape layer; we just want a stroke around the border. // Don't fill the shape layer; we just want a stroke around the border.
self.shapeLayer.fillColor = [UIColor clearColor].CGColor; self.shapeLayer.fillColor = [UIColor clearColor].CGColor;
[CATransaction commit];
self.clipsToBounds = YES; self.clipsToBounds = YES;
if (!self.bubbleView) { if (!self.bubbleView) {
return; return;
} }
self.shapeLayer.strokeColor = self.strokeColor.CGColor;
self.shapeLayer.lineWidth = self.strokeThickness;
self.shapeLayer.zPosition = 100.f;
UIBezierPath *bezierPath = [UIBezierPath new]; UIBezierPath *bezierPath = [UIBezierPath new];
UIBezierPath *boundsBezierPath = [UIBezierPath bezierPathWithRect:self.bounds]; UIBezierPath *boundsBezierPath = [UIBezierPath bezierPathWithRect:self.bounds];
@ -110,7 +112,16 @@ NS_ASSUME_NONNULL_BEGIN
[bubbleBezierPath applyTransform:transform]; [bubbleBezierPath applyTransform:transform];
[bezierPath appendPath:bubbleBezierPath]; [bezierPath appendPath:bubbleBezierPath];
// Prevent the shape layer from animating changes.
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
self.shapeLayer.strokeColor = self.strokeColor.CGColor;
self.shapeLayer.lineWidth = self.strokeThickness;
self.shapeLayer.zPosition = 100.f;
self.shapeLayer.path = bezierPath.CGPath; self.shapeLayer.path = bezierPath.CGPath;
[CATransaction commit];
} }
@end @end

@ -130,7 +130,14 @@ const CGFloat kBubbleTextVInset = 10.f;
if (!self.shapeLayer) { if (!self.shapeLayer) {
[self updateLayers]; [self updateLayers];
} }
// Prevent the shape layer from animating changes.
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
self.shapeLayer.fillColor = bubbleColor.CGColor; self.shapeLayer.fillColor = bubbleColor.CGColor;
[CATransaction commit];
} }
- (void)updateLayers - (void)updateLayers
@ -144,9 +151,15 @@ const CGFloat kBubbleTextVInset = 10.f;
UIBezierPath *bezierPath = [self maskPath]; UIBezierPath *bezierPath = [self maskPath];
// Prevent the shape layer from animating changes.
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
self.shapeLayer.fillColor = self.bubbleColor.CGColor; self.shapeLayer.fillColor = self.bubbleColor.CGColor;
self.shapeLayer.path = bezierPath.CGPath; self.shapeLayer.path = bezierPath.CGPath;
self.maskLayer.path = bezierPath.CGPath; self.maskLayer.path = bezierPath.CGPath;
[CATransaction commit];
} }
- (UIBezierPath *)maskPath - (UIBezierPath *)maskPath

@ -73,6 +73,10 @@ import SignalServiceKit
internal func updateContent() { internal func updateContent() {
SwiftAssertIsOnMainThread(#function) SwiftAssertIsOnMainThread(#function)
// Prevent the shape layer from animating changes.
CATransaction.begin()
CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions)
let horizontalBarPath = UIBezierPath() let horizontalBarPath = UIBezierPath()
let horizontalBarHeightFraction = CGFloat(0.25) let horizontalBarHeightFraction = CGFloat(0.25)
let horizontalBarHeight = bounds.size.height * horizontalBarHeightFraction let horizontalBarHeight = bounds.size.height * horizontalBarHeightFraction
@ -89,5 +93,7 @@ import SignalServiceKit
progressPath.append(UIBezierPath(roundedRect: progressBounds, cornerRadius: progressCornerRadius)) progressPath.append(UIBezierPath(roundedRect: progressBounds, cornerRadius: progressCornerRadius))
progressLayer.path = progressPath.cgPath progressLayer.path = progressPath.cgPath
progressLayer.fillColor = progressColor.cgColor progressLayer.fillColor = progressColor.cgColor
CATransaction.commit()
} }
} }

@ -84,12 +84,18 @@ NS_ASSUME_NONNULL_BEGIN
[layer removeFromSuperlayer]; [layer removeFromSuperlayer];
} }
// Prevent the shape layer from animating changes.
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
for (ConfigureShapeLayerBlock configureShapeLayerBlock in self.configureShapeLayerBlocks) { for (ConfigureShapeLayerBlock configureShapeLayerBlock in self.configureShapeLayerBlocks) {
CAShapeLayer *shapeLayer = [CAShapeLayer new]; CAShapeLayer *shapeLayer = [CAShapeLayer new];
configureShapeLayerBlock(shapeLayer, self.bounds); configureShapeLayerBlock(shapeLayer, self.bounds);
[self.layer addSublayer:shapeLayer]; [self.layer addSublayer:shapeLayer];
} }
[CATransaction commit];
[self setNeedsDisplay]; [self setNeedsDisplay];
} }

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import "OWSProgressView.h" #import "OWSProgressView.h"
@ -43,6 +43,10 @@ NS_ASSUME_NONNULL_BEGIN
self.backgroundColor = [UIColor clearColor]; self.backgroundColor = [UIColor clearColor];
self.color = [UIColor whiteColor]; self.color = [UIColor whiteColor];
// Prevent the shape layer from animating changes.
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
self.borderLayer = [CAShapeLayer new]; self.borderLayer = [CAShapeLayer new];
self.borderLayer.fillColor = self.color.CGColor; self.borderLayer.fillColor = self.color.CGColor;
[self.layer addSublayer:self.borderLayer]; [self.layer addSublayer:self.borderLayer];
@ -51,6 +55,8 @@ NS_ASSUME_NONNULL_BEGIN
self.progressLayer.fillColor = self.color.CGColor; self.progressLayer.fillColor = self.color.CGColor;
[self.layer addSublayer:self.progressLayer]; [self.layer addSublayer:self.progressLayer];
[CATransaction commit];
[self setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisVertical]; [self setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisVertical];
[self setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisVertical]; [self setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisVertical];
} }
@ -79,6 +85,10 @@ NS_ASSUME_NONNULL_BEGIN
- (void)update - (void)update
{ {
// Prevent the shape layer from animating changes.
[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
CGFloat kBorderThickness = self.bounds.size.height * 0.1f; CGFloat kBorderThickness = self.bounds.size.height * 0.1f;
CGFloat kOuterRadius = self.bounds.size.height * 0.25f; CGFloat kOuterRadius = self.bounds.size.height * 0.25f;
CGFloat kInnerRadius = kOuterRadius - kBorderThickness; CGFloat kInnerRadius = kOuterRadius - kBorderThickness;
@ -107,6 +117,8 @@ NS_ASSUME_NONNULL_BEGIN
self.progressLayer.path = progressPath.CGPath; self.progressLayer.path = progressPath.CGPath;
self.progressLayer.fillColor = self.color.CGColor; self.progressLayer.fillColor = self.color.CGColor;
[CATransaction commit];
} }
- (CGSize)sizeThatFits:(CGSize)size - (CGSize)sizeThatFits:(CGSize)size

Loading…
Cancel
Save