Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent c6df55b820
commit 759b2a332f

@ -161,7 +161,7 @@ const CGFloat kExpirationTimerViewSize = 16.f;
} }
CGFloat ratioRemaining = (CGFloat)timeUntilFlashing / (CGFloat)self.initialDurationSeconds; 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); CGPoint startPosition = CGPointMake(0, self.fullHourglassImageView.height * ratioComplete);
// We offset the bottom slightly to make sure the duration of the perceived animation is correct. // We offset the bottom slightly to make sure the duration of the perceived animation is correct.

@ -316,7 +316,7 @@ static const CGFloat ConversationInputToolbarBorderViewHeight = 0.5;
const CGFloat kMaxTextViewHeight = 98.f; const CGFloat kMaxTextViewHeight = 98.f;
const CGFloat textViewDesiredHeight = (self.inputTextView.contentSize.height + self.inputTextView.contentInset.top const CGFloat textViewDesiredHeight = (self.inputTextView.contentSize.height + self.inputTextView.contentInset.top
+ self.inputTextView.contentInset.bottom); + 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; const CGFloat kMinContentHeight = kMinTextViewHeight + textViewVInset * 2;
self.textViewHeight = textViewHeight; self.textViewHeight = textViewHeight;

@ -3960,7 +3960,7 @@ typedef enum : NSUInteger {
// keyboard, up to the limits of the content bounds. // keyboard, up to the limits of the content bounds.
CGFloat insetChange = newInsets.bottom - oldInsets.bottom; CGFloat insetChange = newInsets.bottom - oldInsets.bottom;
CGFloat oldYOffset = self.collectionView.contentOffset.y; 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); CGPoint newOffset = CGPointMake(0, newYOffset);
// If the user is dismissing the keyboard via interactive scrolling, any additional conset offset feels // 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 const CGFloat swipeTranslation
= ([gestureRecognizer translationInView:self.view].x * (self.view.isRTL ? +1.f : -1.f)); = ([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) { switch (gestureRecognizer.state) {
case UIGestureRecognizerStateBegan: { case UIGestureRecognizerStateBegan: {

@ -6,6 +6,7 @@
#import "OWSAvatarBuilder.h" #import "OWSAvatarBuilder.h"
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import <SignalMessaging/OWSFormat.h> #import <SignalMessaging/OWSFormat.h>
#import <SignalMessaging/OWSMath.h>
#import <SignalMessaging/OWSUserProfile.h> #import <SignalMessaging/OWSUserProfile.h>
#import <SignalMessaging/SignalMessaging-Swift.h> #import <SignalMessaging/SignalMessaging-Swift.h>
#import <SignalServiceKit/OWSMessageManager.h> #import <SignalServiceKit/OWSMessageManager.h>
@ -85,14 +86,8 @@ NS_ASSUME_NONNULL_BEGIN
[self.payloadView autoPinTrailingToSuperviewMarginWithInset:self.cellHMargin]; [self.payloadView autoPinTrailingToSuperviewMarginWithInset:self.cellHMargin];
[self.payloadView autoVCenterInSuperview]; [self.payloadView autoVCenterInSuperview];
// Ensure that the cell's contents never overflow the cell bounds. // Ensure that the cell's contents never overflow the cell bounds.
[self.payloadView.bottomAnchor [self.payloadView autoPinEdgeToSuperviewMargin:ALEdgeTop relation:NSLayoutRelationGreaterThanOrEqual];
constraintLessThanOrEqualToAnchor:self.payloadView.superview.layoutMarginsGuide.bottomAnchor] [self.payloadView autoPinEdgeToSuperviewMargin:ALEdgeBottom relation:NSLayoutRelationGreaterThanOrEqual];
.active
= YES;
[self.payloadView.topAnchor
constraintGreaterThanOrEqualToAnchor:self.payloadView.superview.layoutMarginsGuide.topAnchor]
.active
= YES;
self.nameLabel = [UILabel new]; self.nameLabel = [UILabel new];
self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail; self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
@ -338,7 +333,7 @@ NS_ASSUME_NONNULL_BEGIN
const NSUInteger kReferenceFontSizeMin = 17.f; const NSUInteger kReferenceFontSizeMin = 17.f;
CGFloat referenceFontSize = UIFont.ows_dynamicTypeBodyFont.pointSize; 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; return minValue * alpha;
} }

@ -686,6 +686,6 @@ class CaptioningToolbar: UIView, UITextViewDelegate {
private func clampedTextViewHeight(fixedWidth: CGFloat) -> CGFloat { private func clampedTextViewHeight(fixedWidth: CGFloat) -> CGFloat {
let contentSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude)) let contentSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))
return Clamp(contentSize.height, kMinTextViewHeight, maxTextViewHeight) return CGFloatClamp(contentSize.height, kMinTextViewHeight, maxTextViewHeight)
} }
} }

@ -124,7 +124,7 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value)
- (NSLayoutConstraint *)autoPinToAspectRatio:(CGFloat)ratio - (NSLayoutConstraint *)autoPinToAspectRatio:(CGFloat)ratio
{ {
// Clamp to ensure view has reasonable aspect 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) { if (clampedRatio != ratio) {
OWSFail(@"Invalid aspect ratio: %f for view: %@", ratio, self); OWSFail(@"Invalid aspect ratio: %f for view: %@", ratio, self);
} }

@ -5,19 +5,19 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
// TODO: We'll eventually want to promote these into an OWSMath.h header. // 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)); 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) static inline CGFloat CGFloatLerp(CGFloat left, CGFloat right, CGFloat alpha)
{ {
alpha = Clamp01(alpha); alpha = CGFloatClamp01(alpha);
return (left * (1.f - alpha)) + (right * alpha); return (left * (1.f - alpha)) + (right * alpha);
} }

Loading…
Cancel
Save