Respond to CR.

pull/1/head
Matthew Chen 6 years ago
parent 9b7ae86a6d
commit eb7c6ff441

@ -102,7 +102,7 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes
self.bodyTextView.dataDetectorTypes = kOWSAllowedDataDetectorTypes; self.bodyTextView.dataDetectorTypes = kOWSAllowedDataDetectorTypes;
self.bodyTextView.hidden = YES; self.bodyTextView.hidden = YES;
self.linkPreviewView = [[LinkPreviewView alloc] initWithDelegate:nil]; self.linkPreviewView = [[LinkPreviewView alloc] initWithDraftDelegate:nil];
self.footerView = [OWSMessageFooterView new]; self.footerView = [OWSMessageFooterView new];
} }

@ -43,7 +43,7 @@ const CGFloat kMaxTextViewHeight = 98;
@interface ConversationInputToolbar () <ConversationTextViewToolbarDelegate, @interface ConversationInputToolbar () <ConversationTextViewToolbarDelegate,
QuotedReplyPreviewDelegate, QuotedReplyPreviewDelegate,
LinkPreviewViewDelegate> LinkPreviewViewDraftDelegate>
@property (nonatomic, readonly) ConversationStyle *conversationStyle; @property (nonatomic, readonly) ConversationStyle *conversationStyle;
@ -768,7 +768,7 @@ const CGFloat kMaxTextViewHeight = 98;
[self clearLinkPreviewView]; [self clearLinkPreviewView];
LinkPreviewView *linkPreviewView = [[LinkPreviewView alloc] initWithDelegate:self]; LinkPreviewView *linkPreviewView = [[LinkPreviewView alloc] initWithDraftDelegate:self];
linkPreviewView.state = state; linkPreviewView.state = state;
self.linkPreviewWrapper.hidden = NO; self.linkPreviewWrapper.hidden = NO;
@ -800,7 +800,7 @@ const CGFloat kMaxTextViewHeight = 98;
return self.inputLinkPreview.linkPreviewDraft; return self.inputLinkPreview.linkPreviewDraft;
} }
#pragma mark - LinkPreviewViewDelegate #pragma mark - LinkPreviewViewDraftDelegate
- (BOOL)linkPreviewCanCancel - (BOOL)linkPreviewCanCancel
{ {

@ -3,12 +3,12 @@
// //
public extension CGPoint { public extension CGPoint {
public func plusX(_ value: CGFloat) -> CGPoint { public func offsetBy(dx: CGFloat) -> CGPoint {
return CGPoint(x: x + value, y: y) return CGPoint(x: x + dx, y: y)
} }
public func plusY(_ value: CGFloat) -> CGPoint { public func offsetBy(dy: CGFloat) -> CGPoint {
return CGPoint(x: x, y: y + value) return CGPoint(x: x, y: y + dy)
} }
} }
@ -218,7 +218,7 @@ public class LinkPreviewSent: NSObject, LinkPreviewState {
// MARK: - // MARK: -
@objc @objc
public protocol LinkPreviewViewDelegate { public protocol LinkPreviewViewDraftDelegate {
func linkPreviewCanCancel() -> Bool func linkPreviewCanCancel() -> Bool
func linkPreviewDidCancel() func linkPreviewDidCancel()
} }
@ -279,25 +279,25 @@ public class LinkPreviewImageView: UIImageView {
let path = UIBezierPath() let path = UIBezierPath()
// It's sufficient to "draw" the rounded corners and not the edges that connect them. // It's sufficient to "draw" the rounded corners and not the edges that connect them.
path.addArc(withCenter: upperLeft.plusX(+upperLeftRounding).plusY(+upperLeftRounding), path.addArc(withCenter: upperLeft.offsetBy(dx: +upperLeftRounding).offsetBy(dy: +upperLeftRounding),
radius: upperLeftRounding, radius: upperLeftRounding,
startAngle: CGFloat.pi * 1.0, startAngle: CGFloat.pi * 1.0,
endAngle: CGFloat.pi * 1.5, endAngle: CGFloat.pi * 1.5,
clockwise: true) clockwise: true)
path.addArc(withCenter: upperRight.plusX(-upperRightRounding).plusY(+upperRightRounding), path.addArc(withCenter: upperRight.offsetBy(dx: -upperRightRounding).offsetBy(dy: +upperRightRounding),
radius: upperRightRounding, radius: upperRightRounding,
startAngle: CGFloat.pi * 1.5, startAngle: CGFloat.pi * 1.5,
endAngle: CGFloat.pi * 0.0, endAngle: CGFloat.pi * 0.0,
clockwise: true) clockwise: true)
path.addArc(withCenter: lowerRight.plusX(-lowerRightRounding).plusY(-lowerRightRounding), path.addArc(withCenter: lowerRight.offsetBy(dx: -lowerRightRounding).offsetBy(dy: -lowerRightRounding),
radius: lowerRightRounding, radius: lowerRightRounding,
startAngle: CGFloat.pi * 0.0, startAngle: CGFloat.pi * 0.0,
endAngle: CGFloat.pi * 0.5, endAngle: CGFloat.pi * 0.5,
clockwise: true) clockwise: true)
path.addArc(withCenter: lowerLeft.plusX(+lowerLeftRounding).plusY(-lowerLeftRounding), path.addArc(withCenter: lowerLeft.offsetBy(dx: +lowerLeftRounding).offsetBy(dy: -lowerLeftRounding),
radius: lowerLeftRounding, radius: lowerLeftRounding,
startAngle: CGFloat.pi * 0.5, startAngle: CGFloat.pi * 0.5,
endAngle: CGFloat.pi * 1.0, endAngle: CGFloat.pi * 1.0,
@ -311,7 +311,7 @@ public class LinkPreviewImageView: UIImageView {
@objc @objc
public class LinkPreviewView: UIStackView { public class LinkPreviewView: UIStackView {
private weak var delegate: LinkPreviewViewDelegate? private weak var draftDelegate: LinkPreviewViewDraftDelegate?
@objc @objc
public var state: LinkPreviewState? { public var state: LinkPreviewState? {
@ -339,20 +339,20 @@ public class LinkPreviewView: UIStackView {
private var layoutConstraints = [NSLayoutConstraint]() private var layoutConstraints = [NSLayoutConstraint]()
@objc @objc
public init(delegate: LinkPreviewViewDelegate?) { public init(draftDelegate: LinkPreviewViewDraftDelegate?) {
self.delegate = delegate self.draftDelegate = draftDelegate
super.init(frame: .zero) super.init(frame: .zero)
if let delegate = delegate, if let draftDelegate = draftDelegate,
delegate.linkPreviewCanCancel() { draftDelegate.linkPreviewCanCancel() {
self.isUserInteractionEnabled = true self.isUserInteractionEnabled = true
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(wasTapped))) self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(wasTapped)))
} }
} }
private var isApproval: Bool { private var isDraft: Bool {
return delegate != nil return draftDelegate != nil
} }
private func resetContents() { private func resetContents() {
@ -381,15 +381,15 @@ public class LinkPreviewView: UIStackView {
return return
} }
guard isApproval else { guard isDraft else {
createSentContents() createSentContents()
return return
} }
guard state.isLoaded() else { guard state.isLoaded() else {
createLoadingContents() createDraftLoadingContents()
return return
} }
createApprovalContents(state: state) createDraftContents(state: state)
} }
private func createSentContents() { private func createSentContents() {
@ -532,10 +532,10 @@ public class LinkPreviewView: UIStackView {
return label return label
} }
private let approvalHeight: CGFloat = 72 private let draftHeight: CGFloat = 72
private let approvalMarginTop: CGFloat = 6 private let draftMarginTop: CGFloat = 6
private func createApprovalContents(state: LinkPreviewState) { private func createDraftContents(state: LinkPreviewState) {
self.axis = .horizontal self.axis = .horizontal
self.alignment = .fill self.alignment = .fill
self.distribution = .fill self.distribution = .fill
@ -543,19 +543,19 @@ public class LinkPreviewView: UIStackView {
self.isLayoutMarginsRelativeArrangement = true self.isLayoutMarginsRelativeArrangement = true
let hMarginLeading: CGFloat = 6 let hMarginLeading: CGFloat = 6
let hMarginTrailing: CGFloat = 12 let hMarginTrailing: CGFloat = 12
self.layoutMargins = UIEdgeInsets(top: approvalMarginTop, self.layoutMargins = UIEdgeInsets(top: draftMarginTop,
left: CurrentAppContext().isRTL ? hMarginTrailing : hMarginLeading, left: CurrentAppContext().isRTL ? hMarginTrailing : hMarginLeading,
bottom: 0, bottom: 0,
right: CurrentAppContext().isRTL ? hMarginLeading : hMarginTrailing) right: CurrentAppContext().isRTL ? hMarginLeading : hMarginTrailing)
self.layoutConstraints.append(self.autoSetDimension(.height, toSize: approvalHeight + approvalMarginTop)) self.layoutConstraints.append(self.autoSetDimension(.height, toSize: draftHeight + draftMarginTop))
// Image // Image
if let imageView = createApprovalImageView(state: state) { if let imageView = createDraftImageView(state: state) {
imageView.contentMode = .scaleAspectFill imageView.contentMode = .scaleAspectFill
imageView.autoPinToSquareAspectRatio() imageView.autoPinToSquareAspectRatio()
let imageSize = approvalHeight let imageSize = draftHeight
imageView.autoSetDimensions(to: CGSize(width: imageSize, height: imageSize)) imageView.autoSetDimensions(to: CGSize(width: imageSize, height: imageSize))
imageView.setContentHuggingHigh() imageView.setContentHuggingHigh()
imageView.setCompressionResistanceHigh() imageView.setCompressionResistanceHigh()
@ -655,7 +655,7 @@ public class LinkPreviewView: UIStackView {
return imageView return imageView
} }
private func createApprovalImageView(state: LinkPreviewState) -> UIImageView? { private func createDraftImageView(state: LinkPreviewState) -> UIImageView? {
guard state.isLoaded() else { guard state.isLoaded() else {
owsFailDebug("State not loaded.") owsFailDebug("State not loaded.")
return nil return nil
@ -673,11 +673,11 @@ public class LinkPreviewView: UIStackView {
return imageView return imageView
} }
private func createLoadingContents() { private func createDraftLoadingContents() {
self.axis = .vertical self.axis = .vertical
self.alignment = .center self.alignment = .center
self.layoutConstraints.append(self.autoSetDimension(.height, toSize: approvalHeight + approvalMarginTop)) self.layoutConstraints.append(self.autoSetDimension(.height, toSize: draftHeight + draftMarginTop))
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray) let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
activityIndicator.startAnimating() activityIndicator.startAnimating()
@ -698,7 +698,7 @@ public class LinkPreviewView: UIStackView {
let hotAreaInset: CGFloat = -20 let hotAreaInset: CGFloat = -20
let cancelButtonHotArea = cancelButton.bounds.insetBy(dx: hotAreaInset, dy: hotAreaInset) let cancelButtonHotArea = cancelButton.bounds.insetBy(dx: hotAreaInset, dy: hotAreaInset)
if cancelButtonHotArea.contains(cancelLocation) { if cancelButtonHotArea.contains(cancelLocation) {
self.delegate?.linkPreviewDidCancel() self.draftDelegate?.linkPreviewDidCancel()
return return
} }
} }
@ -794,6 +794,6 @@ public class LinkPreviewView: UIStackView {
} }
@objc func didTapCancel(sender: UIButton) { @objc func didTapCancel(sender: UIButton) {
self.delegate?.linkPreviewDidCancel() self.draftDelegate?.linkPreviewDidCancel()
} }
} }

Loading…
Cancel
Save