From 759b2a332f0c71f68fb1837bbc70b7fe63b11cfd Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 11 Apr 2018 14:18:09 -0400 Subject: [PATCH] Respond to CR. --- .../ConversationView/Cells/OWSExpirationTimerView.m | 2 +- .../ConversationView/ConversationInputToolbar.m | 2 +- .../ConversationView/ConversationViewController.m | 4 ++-- Signal/src/ViewControllers/HomeView/HomeViewCell.m | 13 ++++--------- .../AttachmentApprovalViewController.swift | 2 +- SignalMessaging/categories/UIView+OWS.m | 2 +- SignalMessaging/utils/OWSMath.h | 8 ++++---- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSExpirationTimerView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSExpirationTimerView.m index 76bdf39e7..15532f8da 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSExpirationTimerView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSExpirationTimerView.m @@ -161,7 +161,7 @@ const CGFloat kExpirationTimerViewSize = 16.f; } CGFloat ratioRemaining = (CGFloat)timeUntilFlashing / (CGFloat)self.initialDurationSeconds; - CGFloat ratioComplete = Clamp((CGFloat)1.0 - ratioRemaining, 0, 1.0); + CGFloat ratioComplete = CGFloatClamp((CGFloat)1.0 - ratioRemaining, 0, 1.0); CGPoint startPosition = CGPointMake(0, self.fullHourglassImageView.height * ratioComplete); // We offset the bottom slightly to make sure the duration of the perceived animation is correct. diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m index 578d5c3f8..0571a1e42 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m @@ -316,7 +316,7 @@ static const CGFloat ConversationInputToolbarBorderViewHeight = 0.5; const CGFloat kMaxTextViewHeight = 98.f; const CGFloat textViewDesiredHeight = (self.inputTextView.contentSize.height + self.inputTextView.contentInset.top + self.inputTextView.contentInset.bottom); - const CGFloat textViewHeight = ceil(Clamp(textViewDesiredHeight, kMinTextViewHeight, kMaxTextViewHeight)); + const CGFloat textViewHeight = ceil(CGFloatClamp(textViewDesiredHeight, kMinTextViewHeight, kMaxTextViewHeight)); const CGFloat kMinContentHeight = kMinTextViewHeight + textViewVInset * 2; self.textViewHeight = textViewHeight; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 8db321fdf..cea1d46c2 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3960,7 +3960,7 @@ typedef enum : NSUInteger { // keyboard, up to the limits of the content bounds. CGFloat insetChange = newInsets.bottom - oldInsets.bottom; CGFloat oldYOffset = self.collectionView.contentOffset.y; - CGFloat newYOffset = Clamp(oldYOffset + insetChange, 0, self.safeContentHeight); + CGFloat newYOffset = CGFloatClamp(oldYOffset + insetChange, 0, self.safeContentHeight); CGPoint newOffset = CGPointMake(0, newYOffset); // If the user is dismissing the keyboard via interactive scrolling, any additional conset offset feels @@ -4739,7 +4739,7 @@ typedef enum : NSUInteger { const CGFloat swipeTranslation = ([gestureRecognizer translationInView:self.view].x * (self.view.isRTL ? +1.f : -1.f)); - const CGFloat ratioComplete = Clamp(swipeTranslation / self.view.frame.size.width, 0, 1); + const CGFloat ratioComplete = CGFloatClamp(swipeTranslation / self.view.frame.size.width, 0, 1); switch (gestureRecognizer.state) { case UIGestureRecognizerStateBegan: { diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index c57af302f..371e6393b 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -6,6 +6,7 @@ #import "OWSAvatarBuilder.h" #import "Signal-Swift.h" #import +#import #import #import #import @@ -85,14 +86,8 @@ NS_ASSUME_NONNULL_BEGIN [self.payloadView autoPinTrailingToSuperviewMarginWithInset:self.cellHMargin]; [self.payloadView autoVCenterInSuperview]; // Ensure that the cell's contents never overflow the cell bounds. - [self.payloadView.bottomAnchor - constraintLessThanOrEqualToAnchor:self.payloadView.superview.layoutMarginsGuide.bottomAnchor] - .active - = YES; - [self.payloadView.topAnchor - constraintGreaterThanOrEqualToAnchor:self.payloadView.superview.layoutMarginsGuide.topAnchor] - .active - = YES; + [self.payloadView autoPinEdgeToSuperviewMargin:ALEdgeTop relation:NSLayoutRelationGreaterThanOrEqual]; + [self.payloadView autoPinEdgeToSuperviewMargin:ALEdgeBottom relation:NSLayoutRelationGreaterThanOrEqual]; self.nameLabel = [UILabel new]; self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail; @@ -338,7 +333,7 @@ NS_ASSUME_NONNULL_BEGIN const NSUInteger kReferenceFontSizeMin = 17.f; CGFloat referenceFontSize = UIFont.ows_dynamicTypeBodyFont.pointSize; - CGFloat alpha = MIN(1.3f, MAX(1.f, referenceFontSize / kReferenceFontSizeMin)); + CGFloat alpha = CGFloatClamp(referenceFontSize / kReferenceFontSizeMin, 1.f, 1.3f); return minValue * alpha; } diff --git a/SignalMessaging/attachments/AttachmentApprovalViewController.swift b/SignalMessaging/attachments/AttachmentApprovalViewController.swift index db24d8c87..ccaa6464d 100644 --- a/SignalMessaging/attachments/AttachmentApprovalViewController.swift +++ b/SignalMessaging/attachments/AttachmentApprovalViewController.swift @@ -686,6 +686,6 @@ class CaptioningToolbar: UIView, UITextViewDelegate { private func clampedTextViewHeight(fixedWidth: CGFloat) -> CGFloat { let contentSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude)) - return Clamp(contentSize.height, kMinTextViewHeight, maxTextViewHeight) + return CGFloatClamp(contentSize.height, kMinTextViewHeight, maxTextViewHeight) } } diff --git a/SignalMessaging/categories/UIView+OWS.m b/SignalMessaging/categories/UIView+OWS.m index 4fcdaee9c..4ca3d2741 100644 --- a/SignalMessaging/categories/UIView+OWS.m +++ b/SignalMessaging/categories/UIView+OWS.m @@ -124,7 +124,7 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value) - (NSLayoutConstraint *)autoPinToAspectRatio:(CGFloat)ratio { // Clamp to ensure view has reasonable aspect ratio. - CGFloat clampedRatio = Clamp(ratio, 0.05, 95.0); + CGFloat clampedRatio = CGFloatClamp(ratio, 0.05, 95.0); if (clampedRatio != ratio) { OWSFail(@"Invalid aspect ratio: %f for view: %@", ratio, self); } diff --git a/SignalMessaging/utils/OWSMath.h b/SignalMessaging/utils/OWSMath.h index 370b4cf86..4d4826017 100644 --- a/SignalMessaging/utils/OWSMath.h +++ b/SignalMessaging/utils/OWSMath.h @@ -5,19 +5,19 @@ NS_ASSUME_NONNULL_BEGIN // TODO: We'll eventually want to promote these into an OWSMath.h header. -static inline CGFloat Clamp(CGFloat value, CGFloat minValue, CGFloat maxValue) +static inline CGFloat CGFloatClamp(CGFloat value, CGFloat minValue, CGFloat maxValue) { return MAX(minValue, MIN(maxValue, value)); } -static inline CGFloat Clamp01(CGFloat value) +static inline CGFloat CGFloatClamp01(CGFloat value) { - return Clamp(value, 0.f, 1.f); + return CGFloatClamp(value, 0.f, 1.f); } static inline CGFloat CGFloatLerp(CGFloat left, CGFloat right, CGFloat alpha) { - alpha = Clamp01(alpha); + alpha = CGFloatClamp01(alpha); return (left * (1.f - alpha)) + (right * alpha); }