From a5c7bdb9870021bdd3287db71478834a08d0adf9 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 13 Apr 2018 17:33:21 -0400 Subject: [PATCH 1/2] Don't animate changes to shape layer properties. --- .../Cells/OWSBubbleStrokeView.m | 19 +++++++++++++++---- .../ConversationView/Cells/OWSBubbleView.m | 13 +++++++++++++ Signal/src/views/AudioProgressView.swift | 6 ++++++ Signal/src/views/OWSBezierPathView.m | 6 ++++++ Signal/src/views/OWSProgressView.m | 14 +++++++++++++- 5 files changed, 53 insertions(+), 5 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleStrokeView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleStrokeView.m index 425bed494..dd310ad7d 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleStrokeView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleStrokeView.m @@ -85,19 +85,21 @@ NS_ASSUME_NONNULL_BEGIN 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. self.shapeLayer.fillColor = [UIColor clearColor].CGColor; + [CATransaction commit]; + self.clipsToBounds = YES; if (!self.bubbleView) { return; } - self.shapeLayer.strokeColor = self.strokeColor.CGColor; - self.shapeLayer.lineWidth = self.strokeThickness; - self.shapeLayer.zPosition = 100.f; - UIBezierPath *bezierPath = [UIBezierPath new]; UIBezierPath *boundsBezierPath = [UIBezierPath bezierPathWithRect:self.bounds]; @@ -110,7 +112,16 @@ NS_ASSUME_NONNULL_BEGIN [bubbleBezierPath applyTransform:transform]; [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; + + [CATransaction commit]; } @end diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m index 6d428768a..e1dd5ada2 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m @@ -130,7 +130,14 @@ const CGFloat kBubbleTextVInset = 10.f; if (!self.shapeLayer) { [self updateLayers]; } + + // Prevent the shape layer from animating changes. + [CATransaction begin]; + [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; + self.shapeLayer.fillColor = bubbleColor.CGColor; + + [CATransaction commit]; } - (void)updateLayers @@ -144,9 +151,15 @@ const CGFloat kBubbleTextVInset = 10.f; 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.path = bezierPath.CGPath; self.maskLayer.path = bezierPath.CGPath; + + [CATransaction commit]; } - (UIBezierPath *)maskPath diff --git a/Signal/src/views/AudioProgressView.swift b/Signal/src/views/AudioProgressView.swift index a5052511f..4bda2204f 100644 --- a/Signal/src/views/AudioProgressView.swift +++ b/Signal/src/views/AudioProgressView.swift @@ -73,6 +73,10 @@ import SignalServiceKit internal func updateContent() { SwiftAssertIsOnMainThread(#function) + // Prevent the shape layer from animating changes. + CATransaction.begin() + CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions) + let horizontalBarPath = UIBezierPath() let horizontalBarHeightFraction = CGFloat(0.25) let horizontalBarHeight = bounds.size.height * horizontalBarHeightFraction @@ -89,5 +93,7 @@ import SignalServiceKit progressPath.append(UIBezierPath(roundedRect: progressBounds, cornerRadius: progressCornerRadius)) progressLayer.path = progressPath.cgPath progressLayer.fillColor = progressColor.cgColor + + CATransaction.commit() } } diff --git a/Signal/src/views/OWSBezierPathView.m b/Signal/src/views/OWSBezierPathView.m index 323b0ed5f..645632ad7 100644 --- a/Signal/src/views/OWSBezierPathView.m +++ b/Signal/src/views/OWSBezierPathView.m @@ -84,12 +84,18 @@ NS_ASSUME_NONNULL_BEGIN [layer removeFromSuperlayer]; } + // Prevent the shape layer from animating changes. + [CATransaction begin]; + [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; + for (ConfigureShapeLayerBlock configureShapeLayerBlock in self.configureShapeLayerBlocks) { CAShapeLayer *shapeLayer = [CAShapeLayer new]; configureShapeLayerBlock(shapeLayer, self.bounds); [self.layer addSublayer:shapeLayer]; } + [CATransaction commit]; + [self setNeedsDisplay]; } diff --git a/Signal/src/views/OWSProgressView.m b/Signal/src/views/OWSProgressView.m index 554f2e4c1..84a4b9190 100644 --- a/Signal/src/views/OWSProgressView.m +++ b/Signal/src/views/OWSProgressView.m @@ -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" @@ -43,6 +43,10 @@ NS_ASSUME_NONNULL_BEGIN self.backgroundColor = [UIColor clearColor]; 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.fillColor = self.color.CGColor; [self.layer addSublayer:self.borderLayer]; @@ -51,6 +55,8 @@ NS_ASSUME_NONNULL_BEGIN self.progressLayer.fillColor = self.color.CGColor; [self.layer addSublayer:self.progressLayer]; + [CATransaction commit]; + [self setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisVertical]; [self setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisVertical]; } @@ -79,6 +85,10 @@ NS_ASSUME_NONNULL_BEGIN - (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 kOuterRadius = self.bounds.size.height * 0.25f; CGFloat kInnerRadius = kOuterRadius - kBorderThickness; @@ -107,6 +117,8 @@ NS_ASSUME_NONNULL_BEGIN self.progressLayer.path = progressPath.CGPath; self.progressLayer.fillColor = self.color.CGColor; + + [CATransaction commit]; } - (CGSize)sizeThatFits:(CGSize)size From 6831412e44ea1c562de9b915190f101968a660e8 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 16 Apr 2018 12:14:09 -0400 Subject: [PATCH 2/2] Respond to CR. --- .../ConversationView/Cells/OWSBubbleStrokeView.m | 4 ++-- .../ViewControllers/ConversationView/Cells/OWSBubbleView.m | 4 ++-- Signal/src/views/AudioProgressView.swift | 2 +- Signal/src/views/OWSBezierPathView.m | 2 +- Signal/src/views/OWSProgressView.m | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleStrokeView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleStrokeView.m index dd310ad7d..415de838b 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleStrokeView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleStrokeView.m @@ -87,7 +87,7 @@ NS_ASSUME_NONNULL_BEGIN // Prevent the shape layer from animating changes. [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; + [CATransaction setDisableActions:YES]; // Don't fill the shape layer; we just want a stroke around the border. self.shapeLayer.fillColor = [UIColor clearColor].CGColor; @@ -114,7 +114,7 @@ NS_ASSUME_NONNULL_BEGIN // Prevent the shape layer from animating changes. [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; + [CATransaction setDisableActions:YES]; self.shapeLayer.strokeColor = self.strokeColor.CGColor; self.shapeLayer.lineWidth = self.strokeThickness; diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m index e1dd5ada2..b14f604a3 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m @@ -133,7 +133,7 @@ const CGFloat kBubbleTextVInset = 10.f; // Prevent the shape layer from animating changes. [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; + [CATransaction setDisableActions:YES]; self.shapeLayer.fillColor = bubbleColor.CGColor; @@ -153,7 +153,7 @@ const CGFloat kBubbleTextVInset = 10.f; // Prevent the shape layer from animating changes. [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; + [CATransaction setDisableActions:YES]; self.shapeLayer.fillColor = self.bubbleColor.CGColor; self.shapeLayer.path = bezierPath.CGPath; diff --git a/Signal/src/views/AudioProgressView.swift b/Signal/src/views/AudioProgressView.swift index 4bda2204f..d897e5e98 100644 --- a/Signal/src/views/AudioProgressView.swift +++ b/Signal/src/views/AudioProgressView.swift @@ -75,7 +75,7 @@ import SignalServiceKit // Prevent the shape layer from animating changes. CATransaction.begin() - CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions) + CATransaction.setDisableActions(true) let horizontalBarPath = UIBezierPath() let horizontalBarHeightFraction = CGFloat(0.25) diff --git a/Signal/src/views/OWSBezierPathView.m b/Signal/src/views/OWSBezierPathView.m index 645632ad7..119842eb7 100644 --- a/Signal/src/views/OWSBezierPathView.m +++ b/Signal/src/views/OWSBezierPathView.m @@ -86,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN // Prevent the shape layer from animating changes. [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; + [CATransaction setDisableActions:YES]; for (ConfigureShapeLayerBlock configureShapeLayerBlock in self.configureShapeLayerBlocks) { CAShapeLayer *shapeLayer = [CAShapeLayer new]; diff --git a/Signal/src/views/OWSProgressView.m b/Signal/src/views/OWSProgressView.m index 84a4b9190..f64385607 100644 --- a/Signal/src/views/OWSProgressView.m +++ b/Signal/src/views/OWSProgressView.m @@ -45,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN // Prevent the shape layer from animating changes. [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; + [CATransaction setDisableActions:YES]; self.borderLayer = [CAShapeLayer new]; self.borderLayer.fillColor = self.color.CGColor; @@ -87,7 +87,7 @@ NS_ASSUME_NONNULL_BEGIN { // Prevent the shape layer from animating changes. [CATransaction begin]; - [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; + [CATransaction setDisableActions:YES]; CGFloat kBorderThickness = self.bounds.size.height * 0.1f; CGFloat kOuterRadius = self.bounds.size.height * 0.25f;