diff --git a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift index 6792b8b..ca02247 100644 --- a/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift +++ b/StickerSlack/SwiftUI/EmojiPacks/EmojiPackDetailView.swift @@ -78,7 +78,8 @@ struct EmojiPackDetailView: View { pack: pack, width: 75, style: .full, - edit: edit + edit: edit, + onRemove: { pack.remove($0) } ) GeometryReader { geo in diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift index 1128d28..8003015 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift @@ -117,6 +117,24 @@ struct EmojiCollectionView: UIViewRepresentable { case .full: cell = collectionView.dequeueReusableCell(withReuseIdentifier: "full", for: indexPath) as! EmojiCollectionViewCell (cell as! EmojiCollectionViewCell).setEdit(to: edit) + + let button = UIButton(type: .custom) + button.setImage(UIImage(systemName: "minus.circle.fill"), for: .normal) + button.imageView?.contentMode = .scaleAspectFit + button.contentHorizontalAlignment = .fill + button.contentVerticalAlignment = .fill + button.addTarget(self, action: #selector(deleteTapped), for: .touchUpInside) + button.tintColor = .systemRed + button.clipsToBounds = false + button.translatesAutoresizingMaskIntoConstraints = false + collectionView.addSubview(button) + + NSLayoutConstraint.activate([ + button.topAnchor.constraint(equalTo: cell.topAnchor, constant: -12), + button.leadingAnchor.constraint(equalTo: cell.leadingAnchor, constant: -12), + button.heightAnchor.constraint(equalToConstant: 24), + button.widthAnchor.constraint(equalToConstant: 24) + ]) } guard !hoarder.trie.dict.isEmpty else { return cell } @@ -124,10 +142,14 @@ struct EmojiCollectionView: UIViewRepresentable { guard let emoji = hoarder.trie.dict[emojiName] else { return cell } cell.configure(with: hoarder, emoji: emoji) - return cell } + @objc + func deleteTapped() { + print(UUID()) + } + func collectionView( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift index 2281ed0..05ffa62 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionViewCell.swift @@ -11,7 +11,6 @@ import SwiftUI class EmojiCollectionViewCell: PlainEmojiCollectionViewCell { let label = UILabel() - let deleteButton = UIButton(type: .custom) var edit: Bool = false override init(frame: CGRect) { @@ -27,14 +26,6 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell { label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), ]) - - deleteButton.setImage(UIImage(systemName: "minus.circle.fill"), for: .normal) - deleteButton.imageView?.contentMode = .scaleAspectFit - deleteButton.configuration = .plain() - contentView.addSubview(deleteButton) - deleteButton.tintColor = .systemRed - deleteButton.clipsToBounds = false - deleteButton.translatesAutoresizingMaskIntoConstraints = false } required init?(coder: NSCoder) { @@ -48,14 +39,6 @@ class EmojiCollectionViewCell: PlainEmojiCollectionViewCell { override func configure(with: EmojiHoarder, emoji: Emoji) { super.configure(with: with, emoji: emoji) label.text = emoji.UIName - contentView.bringSubviewToFront(deleteButton) - - NSLayoutConstraint.activate([ - deleteButton.topAnchor.constraint(equalTo: hostingController!.view.topAnchor, constant: -16), - deleteButton.leadingAnchor.constraint(equalTo: hostingController!.view.leadingAnchor, constant: -16), - deleteButton.heightAnchor.constraint(equalToConstant: 32), - deleteButton.widthAnchor.constraint(equalToConstant: 32) - ]) } func setEdit(to newValue: Bool) { diff --git a/StickerSlackiMessageApp/MessagesViewController.swift b/StickerSlackiMessageApp/MessagesViewController.swift index b80e13b..0c72477 100644 --- a/StickerSlackiMessageApp/MessagesViewController.swift +++ b/StickerSlackiMessageApp/MessagesViewController.swift @@ -29,7 +29,6 @@ class MessagesViewController: MSMessagesAppViewController { guard stickerBrowser.dataSource?.numberOfStickers(in: stickerBrowser) != 0 else { let swiftUIView = NoStickersView() let hostingController = UIHostingController(rootView: swiftUIView) - addChild(hostingController) hostingController.view.translatesAutoresizingMaskIntoConstraints = false view.addSubview(hostingController.view) hostingController.didMove(toParent: self) @@ -38,16 +37,15 @@ class MessagesViewController: MSMessagesAppViewController { link.setTitle("Open StickerSlack", for: .normal) link.setImage(UIImage(systemName: "arrow.up.right.square"), for: .normal) link.setTitleColor(.systemBlue, for: .normal) - link.frame = view.frame link.translatesAutoresizingMaskIntoConstraints = false link.addTarget(self, action: #selector(openStickerSlack), for: .touchUpInside) view.addSubview(link) NSLayoutConstraint.activate([ - hostingController.view.centerXAnchor.constraint(equalTo: view.centerXAnchor), - hostingController.view.centerYAnchor.constraint(equalTo: view.centerYAnchor), - hostingController.view.widthAnchor.constraint(equalTo: view.widthAnchor), - hostingController.view.heightAnchor.constraint(equalTo: view.heightAnchor), + hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor), + hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), + hostingController.view.topAnchor.constraint(equalTo: view.topAnchor), + hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor), link.centerXAnchor.constraint(equalTo: view.centerXAnchor), link.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor), link.heightAnchor.constraint(equalToConstant: 50)