Support preview only text stories

This commit is contained in:
Nora Trapp 2022-03-30 12:44:06 -07:00
parent 7837ab0512
commit 60b35f3e60
3 changed files with 41 additions and 32 deletions

View File

@ -385,7 +385,11 @@ extension StoriesViewController: ContextMenuInteractionDelegate {
}
AttachmentSharing.showShareUI(forAttachment: attachment, sender: cell)
case .text(let attachment):
AttachmentSharing.showShareUI(forText: attachment.text, sender: cell)
if let url = attachment.preview?.urlString {
AttachmentSharing.showShareUI(for: URL(string: url)!, sender: cell)
} else if let text = attachment.text {
AttachmentSharing.showShareUI(forText: text, sender: cell)
}
case .missing:
owsFailDebug("Unexpectedly missing attachment for story.")
}

View File

@ -29,35 +29,37 @@ class TextAttachmentView: UIView {
addSubview(contentStackView)
contentStackView.autoPinEdgesToSuperviewEdges()
let label = UILabel()
label.numberOfLines = 0
label.textColor = attachment.textForegroundColor ?? Theme.darkThemePrimaryColor
label.text = transformedText(attachment.text, for: attachment.textStyle)
label.textAlignment = .center
label.font = font(for: attachment.textStyle)
label.adjustsFontSizeToFitWidth = true
label.minimumScaleFactor = 0.2
if let text = attachment.text {
let label = UILabel()
label.numberOfLines = 0
label.textColor = attachment.textForegroundColor ?? Theme.darkThemePrimaryColor
label.text = transformedText(text, for: attachment.textStyle)
label.textAlignment = .center
label.font = font(for: attachment.textStyle)
label.adjustsFontSizeToFitWidth = true
label.minimumScaleFactor = 0.2
if let textBackgroundColor = attachment.textBackgroundColor {
let labelBackgroundView = UIView()
labelBackgroundView.layoutMargins = UIEdgeInsets(hMargin: 16, vMargin: 16)
labelBackgroundView.backgroundColor = textBackgroundColor
labelBackgroundView.layer.cornerRadius = 18
if let textBackgroundColor = attachment.textBackgroundColor {
let labelBackgroundView = UIView()
labelBackgroundView.layoutMargins = UIEdgeInsets(hMargin: 16, vMargin: 16)
labelBackgroundView.backgroundColor = textBackgroundColor
labelBackgroundView.layer.cornerRadius = 18
labelBackgroundView.addSubview(label)
label.autoPinEdgesToSuperviewMargins()
labelBackgroundView.addSubview(label)
label.autoPinEdgesToSuperviewMargins()
let labelWrapper = UIView()
labelWrapper.addSubview(labelBackgroundView)
labelBackgroundView.autoPinWidthToSuperview(withMargin: 24)
labelBackgroundView.autoPinHeightToSuperview()
contentStackView.addArrangedSubview(labelWrapper)
} else {
let labelWrapper = UIView()
labelWrapper.addSubview(label)
label.autoPinWidthToSuperview(withMargin: 40)
label.autoPinHeightToSuperview()
contentStackView.addArrangedSubview(labelWrapper)
let labelWrapper = UIView()
labelWrapper.addSubview(labelBackgroundView)
labelBackgroundView.autoPinWidthToSuperview(withMargin: 24)
labelBackgroundView.autoPinHeightToSuperview()
contentStackView.addArrangedSubview(labelWrapper)
} else {
let labelWrapper = UIView()
labelWrapper.addSubview(label)
label.autoPinWidthToSuperview(withMargin: 40)
label.autoPinHeightToSuperview()
contentStackView.addArrangedSubview(labelWrapper)
}
}
if let linkPreviewView = buildLinkPreviewView(attachment.preview) {
@ -217,6 +219,8 @@ class TextAttachmentView: UIView {
titleLabel.font = .boldSystemFont(ofSize: 16)
titleLabel.textColor = Theme.darkThemePrimaryColor
titleLabel.numberOfLines = 2
titleLabel.setCompressionResistanceVerticalHigh()
titleLabel.setContentHuggingVerticalHigh()
previewVStack.addArrangedSubview(titleLabel)
}
@ -226,6 +230,8 @@ class TextAttachmentView: UIView {
descriptionLabel.font = .systemFont(ofSize: 12)
descriptionLabel.textColor = Theme.darkThemePrimaryColor
descriptionLabel.numberOfLines = 3
descriptionLabel.setCompressionResistanceVerticalHigh()
descriptionLabel.setContentHuggingVerticalHigh()
previewVStack.addArrangedSubview(descriptionLabel)
}
@ -233,6 +239,8 @@ class TextAttachmentView: UIView {
footerLabel.font = .systemFont(ofSize: 12)
footerLabel.numberOfLines = 2
footerLabel.textColor = Theme.darkThemeSecondaryTextAndIconColor
footerLabel.setCompressionResistanceVerticalHigh()
footerLabel.setContentHuggingVerticalHigh()
previewVStack.addArrangedSubview(footerLabel)
var footerText: String

View File

@ -257,7 +257,7 @@ public enum StoryMessageAttachment: Codable {
}
public struct TextAttachment: Codable {
public let text: String
public let text: String?
public enum TextStyle: Int, Codable {
case regular = 0
@ -310,10 +310,7 @@ public struct TextAttachment: Codable {
public private(set) var preview: OWSLinkPreview?
init(from proto: SSKProtoTextAttachment, transaction: SDSAnyWriteTransaction) throws {
guard let text = proto.text?.nilIfEmpty else {
throw OWSAssertionError("Missing text for attachment.")
}
self.text = text
self.text = proto.text?.nilIfEmpty
guard let style = proto.textStyle else {
throw OWSAssertionError("Missing style for attachment.")