From 7f24277728730a138330e32f2f5c33a1833a35c5 Mon Sep 17 00:00:00 2001 From: Nihaal Sharma <69979447+neon443@users.noreply.github.com> Date: Wed, 29 Apr 2026 09:41:52 +0100 Subject: [PATCH] fix width issue and warnings in gifview --- StickerSlack/Emoji/GifView.swift | 12 ++++----- .../CollectionView/EmojiCollectionView.swift | 25 +++++++------------ .../PlainEmojiCollectionViewCell.swift | 2 +- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/StickerSlack/Emoji/GifView.swift b/StickerSlack/Emoji/GifView.swift index 6f27de2..bf5e720 100644 --- a/StickerSlack/Emoji/GifView.swift +++ b/StickerSlack/Emoji/GifView.swift @@ -18,7 +18,7 @@ struct GifView: View { @State var timer: Timer? nonisolated func run() async { - guard url.pathExtension == "gif" else { + guard await url.pathExtension == "gif" else { if let data = try? await URLSession.shared.data(from: url).0, let uiImage = UIImage(data: data), let cgImage = uiImage.cgImage { @@ -30,7 +30,7 @@ struct GifView: View { } do { - if gif.isEmpty { + if await gif.isEmpty { let frames = try await GifManager.gifFrom(url: url) withAnimation(.spring) { self.gif = frames @@ -42,8 +42,8 @@ struct GifView: View { print("falied loading or empty gif") return } - if timer != nil { - timer!.invalidate() + if await timer != nil { + await timer!.invalidate() timer = nil } @@ -54,7 +54,7 @@ struct GifView: View { currentI += 1 } } - RunLoop.main.add(timer!, forMode: .common) + await RunLoop.main.add(timer!, forMode: .common) } var body: some View { @@ -63,7 +63,6 @@ struct GifView: View { if gif.isEmpty { ProgressView() // .controlSize(.large) - .frame(maxWidth: .infinity, maxHeight: .infinity) } else if url.pathExtension == "gif" { TimelineView(.animation) { tl in if currentI < gif.count { @@ -82,6 +81,7 @@ struct GifView: View { } } } + .frame(maxWidth: .infinity, maxHeight: .infinity) .transition(.scale) .onAppear { Task { diff --git a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift index 8ca0a9e..a2c9509 100644 --- a/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift +++ b/StickerSlack/UIKit/CollectionView/EmojiCollectionView.swift @@ -15,7 +15,6 @@ struct EmojiCollectionView: UIViewRepresentable { let items: [String] let pack: EmojiPack? let width: CGFloat - let spacing: CGFloat = 16 let style: EmojiCollectionView.Style func makeUIView(context: Context) -> UICollectionView { @@ -40,7 +39,6 @@ struct EmojiCollectionView: UIViewRepresentable { items: items, pack: pack, width: width, - spacing: spacing, style: style ) } @@ -56,7 +54,6 @@ struct EmojiCollectionView: UIViewRepresentable { var items: [String] var pack: EmojiPack? var width: CGFloat - var spacing: CGFloat var style: EmojiCollectionView.Style var layout = UICollectionViewFlowLayout() @@ -66,7 +63,6 @@ struct EmojiCollectionView: UIViewRepresentable { items: [String], pack: EmojiPack?, width: CGFloat, - spacing: CGFloat, style: EmojiCollectionView.Style ) { self.hoarder = hoarder @@ -76,15 +72,12 @@ struct EmojiCollectionView: UIViewRepresentable { self.items = pack.items } self.width = width - self.spacing = spacing self.style = style - layout.sectionInset.left = 16 - layout.sectionInset.right = 16 - layout.itemSize = CGSize(width: width, height: width) super.init(collectionViewLayout: layout) + collectionView.contentInset = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) } required init?(coder: NSCoder) { @@ -92,9 +85,6 @@ struct EmojiCollectionView: UIViewRepresentable { } override func viewDidLayoutSubviews() { - layout.sectionInset.left = 16 - layout.sectionInset.right = 16 - layout.itemSize = CGSize(width: width, height: width) } @@ -127,7 +117,12 @@ struct EmojiCollectionView: UIViewRepresentable { layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath ) -> CGSize { - let defaultSize = CGSize(width: width, height: width) + let totalWidth = collectionView.bounds.width + let availWidth = totalWidth-(collectionView.contentInset.left*2) + let cols = max(1, floor(availWidth/width)) + let totalSpacing = 1 * (cols - 1) + let itemWidth = (availWidth-totalSpacing)/cols + let defaultSize = CGSize(width: itemWidth, height: itemWidth) guard self.style == .full else { return defaultSize } guard !hoarder.trie.dict.isEmpty else { return defaultSize } @@ -137,11 +132,9 @@ struct EmojiCollectionView: UIViewRepresentable { label.font = .preferredFont(forTextStyle: .caption1) label.numberOfLines = 0 label.text = emojiName - let labelHeight = label.sizeThatFits(CGSize(width: width, height: .infinity)).height + let labelHeight = label.sizeThatFits(CGSize(width: itemWidth, height: .infinity)).height - print(width, width+labelHeight+4) - - return CGSize(width: width, height: width+labelHeight+4) + return CGSize(width: itemWidth, height: itemWidth+labelHeight+4) } override func collectionView( diff --git a/StickerSlack/UIKit/CollectionView/PlainEmojiCollectionViewCell.swift b/StickerSlack/UIKit/CollectionView/PlainEmojiCollectionViewCell.swift index cb3858f..ed68699 100644 --- a/StickerSlack/UIKit/CollectionView/PlainEmojiCollectionViewCell.swift +++ b/StickerSlack/UIKit/CollectionView/PlainEmojiCollectionViewCell.swift @@ -34,9 +34,9 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell { hostingController.view.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ hostingController.view.topAnchor.constraint(equalTo: contentView.topAnchor), - hostingController.view.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), hostingController.view.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), hostingController.view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + hostingController.view.heightAnchor.constraint(equalTo: hostingController.view.widthAnchor), ]) }