implemented collectionview in downloaded

This commit is contained in:
Nihaal Sharma committed 2026-04-27 12:52:58 +01:00
1 parent 5e5a04abf8
commit c99bdce4a3
6 files changed
+81 -82

No files matched your search

-6
View File
@@ -48,8 +48,6 @@
A957C17E2ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; }; A957C17E2ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; };
A957C17F2ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; }; A957C17F2ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; };
A957C1802ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; }; A957C1802ECFAA1100EA3EE9 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A957C17D2ECFAA1100EA3EE9 /* GifView.swift */; };
A975F9162F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F9152F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift */; };
A975F9172F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A975F9152F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift */; };
A9773C2F2EA54AF000F3B753 /* StickerPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */; }; A9773C2F2EA54AF000F3B753 /* StickerPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */; };
A97BFFBC2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */; }; A97BFFBC2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */; };
A97BFFBD2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */; }; A97BFFBD2F9E6092000441E5 /* EmptyEmojiPackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */; };
@@ -211,7 +209,6 @@
A957C1792ECE542D00EA3EE9 /* GifManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifManager.swift; sourceTree = "<group>"; }; A957C1792ECE542D00EA3EE9 /* GifManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifManager.swift; sourceTree = "<group>"; };
A957C17D2ECFAA1100EA3EE9 /* GifView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifView.swift; sourceTree = "<group>"; }; A957C17D2ECFAA1100EA3EE9 /* GifView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GifView.swift; sourceTree = "<group>"; };
A969D6932EA3E86500399C05 /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = Library/Frameworks/Messages.framework; sourceTree = DEVELOPER_DIR; }; A969D6932EA3E86500399C05 /* Messages.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Messages.framework; path = Library/Frameworks/Messages.framework; sourceTree = DEVELOPER_DIR; };
A975F9152F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlainWithMenuEmojiCollectionViewCell.swift; sourceTree = "<group>"; };
A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPreview.swift; sourceTree = "<group>"; }; A9773C2E2EA54AF000F3B753 /* StickerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPreview.swift; sourceTree = "<group>"; };
A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyEmojiPackView.swift; sourceTree = "<group>"; }; A97BFFBB2F9E6092000441E5 /* EmptyEmojiPackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyEmojiPackView.swift; sourceTree = "<group>"; };
A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionViewCell.swift; sourceTree = "<group>"; }; A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiCollectionViewCell.swift; sourceTree = "<group>"; };
@@ -435,7 +432,6 @@
A917BACD2F9B787B008DB31E /* EmojiCollectionView.swift */, A917BACD2F9B787B008DB31E /* EmojiCollectionView.swift */,
A917BAD02F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift */, A917BAD02F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift */,
A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */, A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */,
A975F9152F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift */,
); );
path = CollectionView; path = CollectionView;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -707,7 +703,6 @@
A949B1FB2EA0518800215164 /* SlackResponse.swift in Sources */, A949B1FB2EA0518800215164 /* SlackResponse.swift in Sources */,
A957C17A2ECE542D00EA3EE9 /* GifManager.swift in Sources */, A957C17A2ECE542D00EA3EE9 /* GifManager.swift in Sources */,
A9C52F6F2F89A22000078588 /* Wiggle.metal in Sources */, A9C52F6F2F89A22000078588 /* Wiggle.metal in Sources */,
A975F9162F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift in Sources */,
A9BDEADE2F82BC93002798DF /* NoStickersView.swift in Sources */, A9BDEADE2F82BC93002798DF /* NoStickersView.swift in Sources */,
A955B3F52EC22EE900E1732D /* SearchView.swift in Sources */, A955B3F52EC22EE900E1732D /* SearchView.swift in Sources */,
A935437B2EB2A3C800BB80A4 /* FilterCategory.swift in Sources */, A935437B2EB2A3C800BB80A4 /* FilterCategory.swift in Sources */,
@@ -785,7 +780,6 @@
A9A7A4462F68360900BB84C6 /* Pagination.swift in Sources */, A9A7A4462F68360900BB84C6 /* Pagination.swift in Sources */,
A957C17C2ECE542D00EA3EE9 /* GifManager.swift in Sources */, A957C17C2ECE542D00EA3EE9 /* GifManager.swift in Sources */,
A9104C7F2EB4022500D160EA /* MSSticker.swift in Sources */, A9104C7F2EB4022500D160EA /* MSSticker.swift in Sources */,
A975F9172F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift in Sources */,
A9C52F762F89A93D00078588 /* URL.swift in Sources */, A9C52F762F89A93D00078588 /* URL.swift in Sources */,
A9B9A8302EB2CD0B004C9245 /* Emoji.swift in Sources */, A9B9A8302EB2CD0B004C9245 /* Emoji.swift in Sources */,
A9C52F702F89A22000078588 /* Wiggle.metal in Sources */, A9C52F702F89A22000078588 /* Wiggle.metal in Sources */,
+58 -50
View File
@@ -39,56 +39,64 @@ struct DownloadedView: View {
NoStickersView() NoStickersView()
.padding() .padding()
} }
GeometryReader { geo in
ScrollView { EmojiCollectionView(
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing))) hoarder: emojiHoarder,
let layout = Array(repeating: col, count: columns) items: emojiHoarder.downloadedStickersArr,
LazyVGrid(columns: layout, spacing: spacing) { pack: nil,
ForEach(emojiHoarder.downloadedStickersArr, id: \.self) { name in width: 75,
if let emoji = emojiHoarder.trie.dict[name] { style: .plainWithMenu
ZStack { )
Rectangle() // GeometryReader { geo in
.foregroundStyle(isDark ? .black : .white) // ScrollView {
StickerPreview(sticker: emoji) // let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
RoundedRectangle(cornerRadius: 15) // let layout = Array(repeating: col, count: columns)
.stroke(.gray, lineWidth: 1) // LazyVGrid(columns: layout, spacing: spacing) {
} // ForEach(emojiHoarder.downloadedStickersArr, id: \.self) { name in
.aspectRatio(1, contentMode: .fit) // if let emoji = emojiHoarder.trie.dict[name] {
.clipShape(RoundedRectangle(cornerRadius: 15)) // ZStack {
.contextMenu { // Rectangle()
Text(emoji.UIName) // .foregroundStyle(isDark ? .black : .white)
Button("Copy Name", systemImage: "doc.on.clipboard") { // StickerPreview(sticker: emoji)
UIPasteboard.general.string = emoji.UIName // RoundedRectangle(cornerRadius: 15)
} // .stroke(.gray, lineWidth: 1)
Button("Copy Image", systemImage: "photo.fill.on.rectangle.fill") { // }
UIPasteboard.general.image = emoji.image // .aspectRatio(1, contentMode: .fit)
} // .clipShape(RoundedRectangle(cornerRadius: 15))
Divider() // .contextMenu {
if #available(iOS 16, *) { // Text(emoji.UIName)
ShareLink(item: emoji.remoteImageURL) { // Button("Copy Name", systemImage: "doc.on.clipboard") {
Label("Share", systemImage: "square.and.arrow.up") // UIPasteboard.general.string = emoji.UIName
} // }
} else { // Button("Copy Image", systemImage: "photo.fill.on.rectangle.fill") {
Button("Share", systemImage: "square.and.arrow.up") { // UIPasteboard.general.image = emoji.image
showShare.toggle() // }
} // Divider()
.sheet(isPresented: $showShare) { // if #available(iOS 16, *) {
ShareSheet(activityItems: [emoji.remoteImageURL]) // ShareLink(item: emoji.remoteImageURL) {
} // Label("Share", systemImage: "square.and.arrow.up")
} // }
Divider() // } else {
Button("Delete", systemImage: "trash.fill", role: .destructive) { // Button("Share", systemImage: "square.and.arrow.up") {
Task { // showShare.toggle()
await emojiHoarder.delete(emoji: emoji) // }
} // .sheet(isPresented: $showShare) {
} // ShareSheet(activityItems: [emoji.remoteImageURL])
} // }
} // }
} // Divider()
} // Button("Delete", systemImage: "trash.fill", role: .destructive) {
.padding(.horizontal, spacing) // Task {
} // await emojiHoarder.delete(emoji: emoji)
} // }
// }
// }
// }
// }
// }
// .padding(.horizontal, spacing)
// }
// }
} }
} }
@@ -75,6 +75,7 @@ struct EmojiPackDetailView: View {
EmojiCollectionView( EmojiCollectionView(
hoarder: hoarder, hoarder: hoarder,
items: pack.items,
pack: pack, pack: pack,
width: 80, width: 80,
style: .full style: .full
+3 -2
View File
@@ -115,9 +115,10 @@ struct SettingsView: View {
NavigationLink { NavigationLink {
EmojiCollectionView( EmojiCollectionView(
hoarder: hoarder, hoarder: hoarder,
pack: .test, items: hoarder.emojis.prefix(1000).map { $0.name },
pack: nil,
width: 50, width: 50,
style: .plain style: .plainWithMenu
) )
} label: { } label: {
Label("grid view", systemImage: "square.grid.2x2.fill") Label("grid view", systemImage: "square.grid.2x2.fill")
@@ -11,7 +11,8 @@ import SwiftUI
struct EmojiCollectionView: UIViewRepresentable { struct EmojiCollectionView: UIViewRepresentable {
let hoarder: EmojiHoarder let hoarder: EmojiHoarder
let pack: EmojiPack let items: [String]
let pack: EmojiPack?
let width: CGFloat let width: CGFloat
let spacing: CGFloat = 16 let spacing: CGFloat = 16
let style: EmojiCollectionView.Style let style: EmojiCollectionView.Style
@@ -28,6 +29,7 @@ struct EmojiCollectionView: UIViewRepresentable {
func updateUIView(_ uiView: UICollectionView, context: Context) { func updateUIView(_ uiView: UICollectionView, context: Context) {
context.coordinator.hoarder = hoarder context.coordinator.hoarder = hoarder
context.coordinator.items = items
context.coordinator.pack = pack context.coordinator.pack = pack
uiView.reloadData() uiView.reloadData()
} }
@@ -35,6 +37,7 @@ struct EmojiCollectionView: UIViewRepresentable {
func makeCoordinator() -> Coordinator { func makeCoordinator() -> Coordinator {
Coordinator( Coordinator(
hoarder: hoarder, hoarder: hoarder,
items: items,
pack: pack, pack: pack,
width: width, width: width,
spacing: spacing, spacing: spacing,
@@ -50,7 +53,8 @@ struct EmojiCollectionView: UIViewRepresentable {
final class Coordinator: UICollectionViewController, UICollectionViewDelegateFlowLayout { final class Coordinator: UICollectionViewController, UICollectionViewDelegateFlowLayout {
var hoarder: EmojiHoarder var hoarder: EmojiHoarder
var pack: EmojiPack var items: [String]
var pack: EmojiPack?
var width: CGFloat var width: CGFloat
var spacing: CGFloat var spacing: CGFloat
var style: EmojiCollectionView.Style var style: EmojiCollectionView.Style
@@ -59,13 +63,18 @@ struct EmojiCollectionView: UIViewRepresentable {
init( init(
hoarder: EmojiHoarder, hoarder: EmojiHoarder,
pack: EmojiPack, items: [String],
pack: EmojiPack?,
width: CGFloat, width: CGFloat,
spacing: CGFloat, spacing: CGFloat,
style: EmojiCollectionView.Style style: EmojiCollectionView.Style
) { ) {
self.hoarder = hoarder self.hoarder = hoarder
self.items = items
if let pack {
self.pack = pack self.pack = pack
self.items = pack.items
}
self.width = width self.width = width
self.spacing = spacing self.spacing = spacing
self.style = style self.style = style
@@ -90,23 +99,20 @@ struct EmojiCollectionView: UIViewRepresentable {
} }
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return pack.items.count return items.count
} }
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: PlainEmojiCollectionViewCell let cell: PlainEmojiCollectionViewCell
switch style { switch style {
case .plain: case .plain, .plainWithMenu:
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plain", for: indexPath) as! PlainEmojiCollectionViewCell cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plain", for: indexPath) as! PlainEmojiCollectionViewCell
case .plainWithMenu:
fatalError()
// cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plainWithMenu", for: <#T##IndexPath#>)
case .full: case .full:
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "full", for: indexPath) as! EmojiCollectionViewCell cell = collectionView.dequeueReusableCell(withReuseIdentifier: "full", for: indexPath) as! EmojiCollectionViewCell
} }
guard !hoarder.trie.dict.isEmpty else { return cell } guard !hoarder.trie.dict.isEmpty else { return cell }
let emojiName = pack.items[indexPath.item] let emojiName = items[indexPath.item]
guard let emoji = hoarder.trie.dict[emojiName] else { return cell } guard let emoji = hoarder.trie.dict[emojiName] else { return cell }
cell.configure(with: hoarder, emoji: emoji) cell.configure(with: hoarder, emoji: emoji)
@@ -120,8 +126,9 @@ struct EmojiCollectionView: UIViewRepresentable {
) -> CGSize { ) -> CGSize {
let defaultSize = CGSize(width: width, height: width) let defaultSize = CGSize(width: width, height: width)
guard self.style == .full else { return defaultSize }
guard !hoarder.trie.dict.isEmpty else { return defaultSize } guard !hoarder.trie.dict.isEmpty else { return defaultSize }
let emojiName = pack.items[indexPath.item] let emojiName = items[indexPath.item]
let label = UILabel() let label = UILabel()
label.font = .preferredFont(forTextStyle: .caption1) label.font = .preferredFont(forTextStyle: .caption1)
@@ -139,10 +146,11 @@ struct EmojiCollectionView: UIViewRepresentable {
contextMenuConfigurationForItemAt indexPath: IndexPath, contextMenuConfigurationForItemAt indexPath: IndexPath,
point: CGPoint point: CGPoint
) -> UIContextMenuConfiguration? { ) -> UIContextMenuConfiguration? {
guard self.style == .plainWithMenu else { return nil }
return UIContextMenuConfiguration( return UIContextMenuConfiguration(
identifier: nil, identifier: nil,
previewProvider: nil) { suggestedActions in previewProvider: nil) { suggestedActions in
let emojiName = self.pack.items[indexPath.row] let emojiName = self.items[indexPath.row]
let label = UIAction(title: "idk", image: UIImage(systemName: "plus")) { action in let label = UIAction(title: "idk", image: UIImage(systemName: "plus")) { action in
print("idk") print("idk")
} }
@@ -1,13 +0,0 @@
//
// PlainWithMenuEmojiCollectionViewCell.swift
// StickerSlack
//
// Created by neon443 on 27/04/2026.
//
import Foundation
import UIKit
class PlainWithMenuEmojiCollectionViewCell: PlainEmojiCollectionViewCell {
// override func
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.