Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion FlowCrypt/Controllers/Compose/ComposeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,11 @@ extension ComposeViewController {
AttachmentNode(
input: .init(
composeAttachment: contextToSend.attachments[index]
)
),
onDeleteTap: { [weak self] in
self?.contextToSend.attachments.safeRemove(at: index)
self?.node.reloadSections(IndexSet(integer: 2), with: .automatic)
}
)
}
}
Expand Down
7 changes: 7 additions & 0 deletions FlowCryptCommon/Extensions/CollectionExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public extension Array {
}
}

public extension Array {
mutating func safeRemove(at index: Int) {
if !self.indices.contains(index) { return }
self.remove(at: index)
}
}

public extension Array where Element == String {
func firstCaseInsensitive(_ stringToCompare: String) -> Element? {
first(where: { $0.caseInsensitiveCompare(stringToCompare) == .orderedSame })
Expand Down
17 changes: 14 additions & 3 deletions FlowCryptUI/Nodes/AttachmentNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ public final class AttachmentNode: CellNode {
private let imageNode = ASImageNode()
private let buttonNode = ASButtonNode()
private let borderNode = ASDisplayNode()
private let deleteButtonNode = ASButtonNode()

private var onDownloadTap: (() -> Void)?
private var onDeleteTap: (() -> Void)?

public init(
input: Input,
onDownloadTap: (() -> Void)? = nil
onDownloadTap: (() -> Void)? = nil,
onDeleteTap: (() -> Void)? = nil
) {
self.onDownloadTap = onDownloadTap
self.onDeleteTap = onDeleteTap
super.init()
automaticallyManagesSubnodes = true
borderNode.borderWidth = 1.0
Expand All @@ -38,19 +42,26 @@ public final class AttachmentNode: CellNode {

imageNode.tintColor = .gray
buttonNode.tintColor = .gray

deleteButtonNode.setImage(UIImage(named: "cancel")?.tinted(.gray), for: .normal)
imageNode.image = UIImage(named: "paperclip")?.tinted(.gray)
buttonNode.setImage(UIImage(named: "download")?.tinted(.gray), for: .normal)
titleNode.attributedText = input.name
subtitleNode.attributedText = input.size

buttonNode.addTarget(self, action: #selector(onDownloadButtonTap), forControlEvents: .touchUpInside)
buttonNode.isHidden = onDownloadTap == nil

deleteButtonNode.addTarget(self, action: #selector(onDeleteButtonTap), forControlEvents: .touchUpInside)
deleteButtonNode.isHidden = onDeleteTap == nil
}

@objc private func onDownloadButtonTap() {
onDownloadTap?()
}

@objc private func onDeleteButtonTap() {
onDeleteTap?()
}

public override func layoutSpecThatFits(_: ASSizeRange) -> ASLayoutSpec {
let verticalStack = ASStackLayoutSpec.vertical()
Expand All @@ -65,7 +76,7 @@ public final class AttachmentNode: CellNode {
spacing: 10,
justifyContent: .start,
alignItems: .center,
children: [imageNode, verticalStack, buttonNode]
children: [imageNode, verticalStack, buttonNode, deleteButtonNode]
)

let borderInset = UIEdgeInsets.side(8)
Expand Down