Align draft view of link preview and draft view of quoted reply.

This commit is contained in:
Matthew Chen 2019-01-25 16:43:16 -05:00
parent bba679eaef
commit c02d633272
5 changed files with 87 additions and 30 deletions

View File

@ -130,7 +130,7 @@ const CGFloat kRemotelySourcedContentRowSpacing = 3;
- (CGFloat)bubbleHMargin
{
return 6.f;
return (self.isForPreview ? 0.f : 6.f);
}
- (CGFloat)hSpacing

View File

@ -73,6 +73,7 @@ const CGFloat kMaxTextViewHeight = 98;
@property (nonatomic) UIEdgeInsets receivedSafeAreaInsets;
@property (nonatomic, nullable) InputLinkPreview *inputLinkPreview;
@property (nonatomic) BOOL wasLinkPreviewCancelled;
@property (nonatomic, nullable, weak) LinkPreviewView *linkPreviewView;
@end
@ -303,9 +304,11 @@ const CGFloat kMaxTextViewHeight = 98;
[quotedMessagePreview setCompressionResistanceHorizontalLow];
self.quotedReplyWrapper.hidden = NO;
self.quotedReplyWrapper.layoutMargins = UIEdgeInsetsMake(self.quotedMessageTopMargin, 0, 0, 0);
self.quotedReplyWrapper.layoutMargins = UIEdgeInsetsZero;
[self.quotedReplyWrapper addSubview:quotedMessagePreview];
[quotedMessagePreview ows_autoPinToSuperviewMargins];
self.linkPreviewView.hasAsymmetricalRounding = !self.quotedReply;
}
- (CGFloat)quotedMessageTopMargin
@ -716,31 +719,27 @@ const CGFloat kMaxTextViewHeight = 98;
OWSAssertIsOnMainThread();
if (self.wasLinkPreviewCancelled) {
self.inputLinkPreview = nil;
[self clearLinkPreviewView];
[self clearLinkPreviewStateAndView];
return;
}
NSString *body =
[[self messageText] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (body.length < 1) {
self.inputLinkPreview = nil;
[self clearLinkPreviewView];
[self clearLinkPreviewStateAndView];
self.wasLinkPreviewCancelled = NO;
return;
}
// Don't include link previews for oversize text messages.
if ([body lengthOfBytesUsingEncoding:NSUTF8StringEncoding] >= kOversizeTextMessageSizeThreshold) {
self.inputLinkPreview = nil;
[self clearLinkPreviewView];
[self clearLinkPreviewStateAndView];
return;
}
NSString *_Nullable previewUrl = [OWSLinkPreview previewUrlForMessageBodyText:body];
if (previewUrl.length < 1) {
self.inputLinkPreview = nil;
[self clearLinkPreviewView];
[self clearLinkPreviewStateAndView];
return;
}
@ -784,12 +783,24 @@ const CGFloat kMaxTextViewHeight = 98;
LinkPreviewView *linkPreviewView = [[LinkPreviewView alloc] initWithDraftDelegate:self];
linkPreviewView.state = state;
linkPreviewView.hasAsymmetricalRounding = !self.quotedReply;
self.linkPreviewView = linkPreviewView;
self.linkPreviewWrapper.hidden = NO;
[self.linkPreviewWrapper addSubview:linkPreviewView];
[linkPreviewView ows_autoPinToSuperviewMargins];
}
- (void)clearLinkPreviewStateAndView
{
OWSAssertIsOnMainThread();
self.inputLinkPreview = nil;
self.linkPreviewView = nil;
[self clearLinkPreviewView];
}
- (void)clearLinkPreviewView
{
OWSAssertIsOnMainThread();
@ -829,8 +840,8 @@ const CGFloat kMaxTextViewHeight = 98;
self.wasLinkPreviewCancelled = YES;
self.self.inputLinkPreview = nil;
[self clearLinkPreviewView];
self.inputLinkPreview = nil;
[self clearLinkPreviewStateAndView];
}
@end

View File

@ -231,14 +231,20 @@ public protocol LinkPreviewViewDraftDelegate {
public class LinkPreviewImageView: UIImageView {
private let maskLayer = CAShapeLayer()
private let hasAsymmetricalRounding: Bool
@objc
public init() {
public init(hasAsymmetricalRounding: Bool) {
self.hasAsymmetricalRounding = hasAsymmetricalRounding
super.init(frame: .zero)
self.layer.mask = maskLayer
}
public required init?(coder aDecoder: NSCoder) {
self.hasAsymmetricalRounding = false
super.init(coder: aDecoder)
}
@ -273,8 +279,15 @@ public class LinkPreviewImageView: UIImageView {
let bigRounding: CGFloat = 14
let smallRounding: CGFloat = 4
let upperLeftRounding = CurrentAppContext().isRTL ? smallRounding : bigRounding
let upperRightRounding = CurrentAppContext().isRTL ? bigRounding : smallRounding
let upperLeftRounding: CGFloat
let upperRightRounding: CGFloat
if hasAsymmetricalRounding {
upperLeftRounding = CurrentAppContext().isRTL ? smallRounding : bigRounding
upperRightRounding = CurrentAppContext().isRTL ? bigRounding : smallRounding
} else {
upperLeftRounding = smallRounding
upperRightRounding = smallRounding
}
let lowerRightRounding = smallRounding
let lowerLeftRounding = smallRounding
@ -325,6 +338,17 @@ public class LinkPreviewView: UIStackView {
}
}
@objc
public var hasAsymmetricalRounding: Bool = false {
didSet {
AssertIsOnMainThread()
if hasAsymmetricalRounding != oldValue {
updateContents()
}
}
}
@available(*, unavailable, message:"use other constructor instead.")
required init(coder aDecoder: NSCoder) {
notImplemented()
@ -672,7 +696,7 @@ public class LinkPreviewView: UIStackView {
owsFailDebug("Could not load image.")
return nil
}
let imageView = LinkPreviewImageView()
let imageView = LinkPreviewImageView(hasAsymmetricalRounding: self.hasAsymmetricalRounding)
imageView.image = image
return imageView
}

View File

@ -10,7 +10,7 @@ protocol QuotedReplyPreviewDelegate: class {
}
@objc
class QuotedReplyPreview: UIView {
class QuotedReplyPreview: UIStackView {
@objc
public weak var delegate: QuotedReplyPreviewDelegate?
@ -19,8 +19,13 @@ class QuotedReplyPreview: UIView {
private var quotedMessageView: OWSQuotedMessageView?
private var heightConstraint: NSLayoutConstraint!
@objc
required init?(coder aDecoder: NSCoder) {
@available(*, unavailable, message:"use other constructor instead.")
required init(coder aDecoder: NSCoder) {
notImplemented()
}
@available(*, unavailable, message:"use other constructor instead.")
override init(frame: CGRect) {
notImplemented()
}
@ -38,6 +43,8 @@ class QuotedReplyPreview: UIView {
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: .UIContentSizeCategoryDidChange, object: nil)
}
private let draftMarginTop: CGFloat = 6
func updateContents() {
subviews.forEach { $0.removeFromSuperview() }
@ -53,21 +60,35 @@ class QuotedReplyPreview: UIView {
let cancelButton: UIButton = UIButton(type: .custom)
let buttonImage: UIImage = #imageLiteral(resourceName: "quoted-message-cancel").withRenderingMode(.alwaysTemplate)
cancelButton.setImage(buttonImage, for: .normal)
let cancelImage = UIImage(named: "compose-cancel")?.withRenderingMode(.alwaysTemplate)
cancelButton.setImage(cancelImage, for: .normal)
cancelButton.imageView?.tintColor = Theme.secondaryColor
cancelButton.addTarget(self, action: #selector(didTapCancel), for: .touchUpInside)
if let cancelSize = cancelImage?.size {
cancelButton.autoSetDimensions(to: cancelSize)
}
self.layoutMargins = .zero
self.axis = .horizontal
self.alignment = .fill
self.distribution = .fill
self.spacing = 8
self.isLayoutMarginsRelativeArrangement = true
let hMarginLeading: CGFloat = 6
let hMarginTrailing: CGFloat = 12
self.layoutMargins = UIEdgeInsets(top: draftMarginTop,
left: CurrentAppContext().isRTL ? hMarginTrailing : hMarginLeading,
bottom: 0,
right: CurrentAppContext().isRTL ? hMarginLeading : hMarginTrailing)
self.addSubview(quotedMessageView)
self.addSubview(cancelButton)
self.addArrangedSubview(quotedMessageView)
quotedMessageView.autoPinEdges(toSuperviewMarginsExcludingEdge: .trailing)
cancelButton.autoPinEdges(toSuperviewMarginsExcludingEdge: .leading)
cancelButton.autoPinEdge(.leading, to: .trailing, of: quotedMessageView)
cancelButton.autoSetDimensions(to: CGSize(width: 40, height: 40))
let cancelStack = UIStackView()
cancelStack.axis = .horizontal
cancelStack.alignment = .top
cancelStack.setContentHuggingHigh()
cancelStack.setCompressionResistanceHigh()
cancelStack.addArrangedSubview(cancelButton)
self.addArrangedSubview(cancelStack)
updateHeight()
}

View File

@ -567,7 +567,8 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value)
UIView *borderView = [UIView new];
borderView.userInteractionEnabled = NO;
borderView.backgroundColor = nil;
borderView.backgroundColor = UIColor.clearColor;
borderView.opaque = NO;
borderView.layer.borderColor = color.CGColor;
borderView.layer.borderWidth = strokeWidth;
borderView.layer.cornerRadius = cornerRadius;