Respond to CR.

This commit is contained in:
Matthew Chen 2018-04-11 14:18:09 -04:00
parent c6df55b820
commit 759b2a332f
7 changed files with 14 additions and 19 deletions

View file

@ -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.

View file

@ -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;

View file

@ -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: {

View file

@ -6,6 +6,7 @@
#import "OWSAvatarBuilder.h"
#import "Signal-Swift.h"
#import <SignalMessaging/OWSFormat.h>
#import <SignalMessaging/OWSMath.h>
#import <SignalMessaging/OWSUserProfile.h>
#import <SignalMessaging/SignalMessaging-Swift.h>
#import <SignalServiceKit/OWSMessageManager.h>
@ -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;
}

View file

@ -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)
}
}

View file

@ -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);
}

View file

@ -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);
}