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 */; };
A957C17F2ECFAA1100EA3EE9 /* 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 */; };
A97BFFBC2F9E6092000441E5 /* 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>"; };
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; };
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>"; };
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>"; };
@@ -435,7 +432,6 @@
A917BACD2F9B787B008DB31E /* EmojiCollectionView.swift */,
A917BAD02F9B7B68008DB31E /* PlainEmojiCollectionViewCell.swift */,
A97BFFBE2F9E745C000441E5 /* EmojiCollectionViewCell.swift */,
A975F9152F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift */,
);
path = CollectionView;
sourceTree = "<group>";
@@ -707,7 +703,6 @@
A949B1FB2EA0518800215164 /* SlackResponse.swift in Sources */,
A957C17A2ECE542D00EA3EE9 /* GifManager.swift in Sources */,
A9C52F6F2F89A22000078588 /* Wiggle.metal in Sources */,
A975F9162F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift in Sources */,
A9BDEADE2F82BC93002798DF /* NoStickersView.swift in Sources */,
A955B3F52EC22EE900E1732D /* SearchView.swift in Sources */,
A935437B2EB2A3C800BB80A4 /* FilterCategory.swift in Sources */,
@@ -785,7 +780,6 @@
A9A7A4462F68360900BB84C6 /* Pagination.swift in Sources */,
A957C17C2ECE542D00EA3EE9 /* GifManager.swift in Sources */,
A9104C7F2EB4022500D160EA /* MSSticker.swift in Sources */,
A975F9172F9F800A00A5C62E /* PlainWithMenuEmojiCollectionViewCell.swift in Sources */,
A9C52F762F89A93D00078588 /* URL.swift in Sources */,
A9B9A8302EB2CD0B004C9245 /* Emoji.swift in Sources */,
A9C52F702F89A22000078588 /* Wiggle.metal in Sources */,
+58 -50
View File
@@ -39,56 +39,64 @@ struct DownloadedView: View {
NoStickersView()
.padding()
}
GeometryReader { geo in
ScrollView {
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
let layout = Array(repeating: col, count: columns)
LazyVGrid(columns: layout, spacing: spacing) {
ForEach(emojiHoarder.downloadedStickersArr, id: \.self) { name in
if let emoji = emojiHoarder.trie.dict[name] {
ZStack {
Rectangle()
.foregroundStyle(isDark ? .black : .white)
StickerPreview(sticker: emoji)
RoundedRectangle(cornerRadius: 15)
.stroke(.gray, lineWidth: 1)
}
.aspectRatio(1, contentMode: .fit)
.clipShape(RoundedRectangle(cornerRadius: 15))
.contextMenu {
Text(emoji.UIName)
Button("Copy Name", systemImage: "doc.on.clipboard") {
UIPasteboard.general.string = emoji.UIName
}
Button("Copy Image", systemImage: "photo.fill.on.rectangle.fill") {
UIPasteboard.general.image = emoji.image
}
Divider()
if #available(iOS 16, *) {
ShareLink(item: emoji.remoteImageURL) {
Label("Share", systemImage: "square.and.arrow.up")
}
} else {
Button("Share", systemImage: "square.and.arrow.up") {
showShare.toggle()
}
.sheet(isPresented: $showShare) {
ShareSheet(activityItems: [emoji.remoteImageURL])
}
}
Divider()
Button("Delete", systemImage: "trash.fill", role: .destructive) {
Task {
await emojiHoarder.delete(emoji: emoji)
}
}
}
}
}
}
.padding(.horizontal, spacing)
}
}
EmojiCollectionView(
hoarder: emojiHoarder,
items: emojiHoarder.downloadedStickersArr,
pack: nil,
width: 75,
style: .plainWithMenu
)
// GeometryReader { geo in
// ScrollView {
// let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
// let layout = Array(repeating: col, count: columns)
// LazyVGrid(columns: layout, spacing: spacing) {
// ForEach(emojiHoarder.downloadedStickersArr, id: \.self) { name in
// if let emoji = emojiHoarder.trie.dict[name] {
// ZStack {
// Rectangle()
// .foregroundStyle(isDark ? .black : .white)
// StickerPreview(sticker: emoji)
// RoundedRectangle(cornerRadius: 15)
// .stroke(.gray, lineWidth: 1)
// }
// .aspectRatio(1, contentMode: .fit)
// .clipShape(RoundedRectangle(cornerRadius: 15))
// .contextMenu {
// Text(emoji.UIName)
// Button("Copy Name", systemImage: "doc.on.clipboard") {
// UIPasteboard.general.string = emoji.UIName
// }
// Button("Copy Image", systemImage: "photo.fill.on.rectangle.fill") {
// UIPasteboard.general.image = emoji.image
// }
// Divider()
// if #available(iOS 16, *) {
// ShareLink(item: emoji.remoteImageURL) {
// Label("Share", systemImage: "square.and.arrow.up")
// }
// } else {
// Button("Share", systemImage: "square.and.arrow.up") {
// showShare.toggle()
// }
// .sheet(isPresented: $showShare) {
// ShareSheet(activityItems: [emoji.remoteImageURL])
// }
// }
// Divider()
// Button("Delete", systemImage: "trash.fill", role: .destructive) {
// Task {
// await emojiHoarder.delete(emoji: emoji)
// }
// }
// }
// }
// }
// }
// .padding(.horizontal, spacing)
// }
// }
}
}
@@ -75,6 +75,7 @@ struct EmojiPackDetailView: View {
EmojiCollectionView(
hoarder: hoarder,
items: pack.items,
pack: pack,
width: 80,
style: .full
+3 -2
View File
@@ -115,9 +115,10 @@ struct SettingsView: View {
NavigationLink {
EmojiCollectionView(
hoarder: hoarder,
pack: .test,
items: hoarder.emojis.prefix(1000).map { $0.name },
pack: nil,
width: 50,
style: .plain
style: .plainWithMenu
)
} label: {
Label("grid view", systemImage: "square.grid.2x2.fill")
@@ -11,7 +11,8 @@ import SwiftUI
struct EmojiCollectionView: UIViewRepresentable {
let hoarder: EmojiHoarder
let pack: EmojiPack
let items: [String]
let pack: EmojiPack?
let width: CGFloat
let spacing: CGFloat = 16
let style: EmojiCollectionView.Style
@@ -28,6 +29,7 @@ struct EmojiCollectionView: UIViewRepresentable {
func updateUIView(_ uiView: UICollectionView, context: Context) {
context.coordinator.hoarder = hoarder
context.coordinator.items = items
context.coordinator.pack = pack
uiView.reloadData()
}
@@ -35,6 +37,7 @@ struct EmojiCollectionView: UIViewRepresentable {
func makeCoordinator() -> Coordinator {
Coordinator(
hoarder: hoarder,
items: items,
pack: pack,
width: width,
spacing: spacing,
@@ -50,7 +53,8 @@ struct EmojiCollectionView: UIViewRepresentable {
final class Coordinator: UICollectionViewController, UICollectionViewDelegateFlowLayout {
var hoarder: EmojiHoarder
var pack: EmojiPack
var items: [String]
var pack: EmojiPack?
var width: CGFloat
var spacing: CGFloat
var style: EmojiCollectionView.Style
@@ -59,13 +63,18 @@ struct EmojiCollectionView: UIViewRepresentable {
init(
hoarder: EmojiHoarder,
pack: EmojiPack,
items: [String],
pack: EmojiPack?,
width: CGFloat,
spacing: CGFloat,
style: EmojiCollectionView.Style
) {
self.hoarder = hoarder
self.items = items
if let pack {
self.pack = pack
self.items = pack.items
}
self.width = width
self.spacing = spacing
self.style = style
@@ -90,23 +99,20 @@ struct EmojiCollectionView: UIViewRepresentable {
}
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 {
let cell: PlainEmojiCollectionViewCell
switch style {
case .plain:
case .plain, .plainWithMenu:
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plain", for: indexPath) as! PlainEmojiCollectionViewCell
case .plainWithMenu:
fatalError()
// cell = collectionView.dequeueReusableCell(withReuseIdentifier: "plainWithMenu", for: <#T##IndexPath#>)
case .full:
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "full", for: indexPath) as! EmojiCollectionViewCell
}
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 }
cell.configure(with: hoarder, emoji: emoji)
@@ -120,8 +126,9 @@ struct EmojiCollectionView: UIViewRepresentable {
) -> CGSize {
let defaultSize = CGSize(width: width, height: width)
guard self.style == .full 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()
label.font = .preferredFont(forTextStyle: .caption1)
@@ -139,10 +146,11 @@ struct EmojiCollectionView: UIViewRepresentable {
contextMenuConfigurationForItemAt indexPath: IndexPath,
point: CGPoint
) -> UIContextMenuConfiguration? {
guard self.style == .plainWithMenu else { return nil }
return UIContextMenuConfiguration(
identifier: nil,
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
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.