increase performance??

This commit is contained in:
neon443 committed 2026-05-04 20:21:33 +01:00
1 parent 0957e3b4c3
commit 2a135e7196
8 files changed
+52 -27

No files matched your search

+17 -8
View File
@@ -15,7 +15,7 @@ struct GifView: View {
@State var url: URL
@State var gif: [(frame: CGImage, showFor: Double)] = []
@State var currentI: Int = 0
@State var isVisible: Bool = false
@State var animate: Bool
@State var timer: Timer?
@@ -25,7 +25,11 @@ struct GifView: View {
if let data = try? await URLSession.shared.data(from: url).0,
let uiImage = UIImage(data: data),
let cgImage = uiImage.cgImage {
withAnimation(.spring(duration: 0.2)) {
if animate {
withAnimation(.spring(duration: 0.2)) {
self.gif = [(cgImage, 1)]
}
} else {
self.gif = [(cgImage, 1)]
}
}
@@ -36,7 +40,11 @@ struct GifView: View {
do {
if gif.isEmpty {
let frames = try await GifManager.gifFrom(url: url)
withAnimation(.spring(duration: 0.2)) {
if animate {
withAnimation(.spring(duration: 0.2)) {
self.gif = frames
}
} else {
self.gif = frames
}
}
@@ -66,7 +74,7 @@ struct GifView: View {
Group {
if gif.isEmpty {
ProgressView()
.modifier(fadeIn())
.modifier(fadeIn(enabled: animate))
} else if url.pathExtension == "gif" {
if currentI < gif.count {
Image(uiImage: .init(cgImage: gif[currentI].frame))
@@ -95,9 +103,10 @@ struct GifView: View {
#Preview {
GifView(
url: URL(string: "https://emoji.slack-edge.com/T09V59WQY1E/clockrun/f6641714fa6748ac.gif")!
url: URL(string: "https://emoji.slack-edge.com/T09V59WQY1E/clockrun/f6641714fa6748ac.gif")!,
animate: true
)
GifView(url: Emoji.test.remoteImageURL)
GifView(url: Emoji.testLongName.localImageURL)
GifView(url: Gif.test.remoteImageURL)
GifView(url: Emoji.test.remoteImageURL, animate: true)
GifView(url: Emoji.testLongName.localImageURL, animate: true)
GifView(url: Gif.test.remoteImageURL, animate: true)
}
+3 -4
View File
@@ -24,10 +24,9 @@ struct JumboMoji: CustomStringConvertible, Hashable {
self.baseName = components.first!.baseName
let coords = components.map { CGPoint(x: $0.x, y: $0.y) }
guard let width = Int(coords.sorted { $0.x > $1.x }.first?.x.formatted() ?? "") else { return nil }
self.width = width
guard let height = Int(coords.sorted { $0.y > $1.y }.first?.y.formatted() ?? "") else { return nil }
self.height = height
self.width = Int(coords.map { $0.x }.max() ?? -1)
self.height = Int(coords.map { $0.y }.max() ?? -1)
guard width != -1 && height != -1 else { return nil }
self.type = .grid
@@ -46,6 +46,7 @@ struct DownloadedView: View {
pack: nil,
width: 75,
style: .plainWithMenu,
animate: false,
edit: false
)
// GeometryReader { geo in
+2 -1
View File
@@ -31,7 +31,8 @@ struct JumboMojiTestView: View {
items: jumboMoji.items,
pack: nil,
width: CGFloat(jumboMoji.width),
style: .jumboMoji
style: .jumboMoji,
animate: false
)
.frame(width: 100, height: 100)
Text(jumboMoji.description)
+18 -9
View File
@@ -144,17 +144,26 @@ extension View {
}
struct fadeIn: ViewModifier {
@State private var enabled: Bool
@State private var isVisible: Bool = false
init(enabled: Bool = true) {
self.enabled = enabled
}
func body(content: Content) -> some View {
content
.opacity(isVisible ? 1 : 0)
.scaleEffect(isVisible ? 1 : 0)
.onAppear {
withAnimation { isVisible = true }
}
.onDisappear {
withAnimation { isVisible = false }
}
if enabled {
content
.opacity(isVisible ? 1 : 0)
.scaleEffect(isVisible ? 1 : 0)
.onAppear {
withAnimation { isVisible = true }
}
.onDisappear {
withAnimation { isVisible = false }
}
} else {
content
}
}
}
@@ -11,23 +11,24 @@ import Haptics
struct StickerPreview: View {
@State var sticker: any StickerProtocol
@State var gifImage: Image?
@State var animate: Bool = true
var body: some View {
if sticker.isLocal {
//local
GifView(url: sticker.localImageURL)
GifView(url: sticker.localImageURL, animate: animate)
} else {
//remote
if sticker.type == .slackEmoji {
GifView(url: sticker.remoteImageURL)
GifView(url: sticker.remoteImageURL, animate: animate)
} else {
let gif = sticker as! Gif
if let giphyImages = gif.giphyImages,
let preview_gif = giphyImages.preview_gif,
let url = URL(string: preview_gif.url) {
GifView(url: url)
GifView(url: url, animate: animate)
} else {
GifView(url: gif.remoteImageURL)
GifView(url: gif.remoteImageURL, animate: animate)
.overlay {
Image(systemName:
"square.arrowtriangle.4.outward")
@@ -16,6 +16,7 @@ struct EmojiCollectionView: UIViewRepresentable {
let pack: EmojiPack?
let width: CGFloat
let style: EmojiCollectionView.Style
var animate: Bool = true
var edit: Bool?
var onRemoveSUI: ((String) -> Void)?
@@ -32,6 +33,7 @@ struct EmojiCollectionView: UIViewRepresentable {
context.coordinator.hoarder = hoarder
context.coordinator.onRemove = onRemoveSUI
context.coordinator.animate = animate
context.coordinator.edit = edit
if edit ?? false {
context.coordinator.startAnimating()
@@ -77,6 +79,7 @@ struct EmojiCollectionView: UIViewRepresentable {
var pack: EmojiPack?
var width: CGFloat
var style: EmojiCollectionView.Style
var animate: Bool = true
var edit: Bool? = false
var onRemove: ((String) -> Void)?
@@ -153,6 +156,7 @@ struct EmojiCollectionView: UIViewRepresentable {
let emojiName = items[indexPath.item]
guard let emoji = hoarder.trie.dict[emojiName] else { return cell }
cell.animate = animate
cell.configure(with: hoarder, emoji: emoji)
return cell
}
@@ -11,6 +11,7 @@ import SwiftUI
class PlainEmojiCollectionViewCell: UICollectionViewCell {
var hostingController: UIHostingController<StickerPreview>?
var animate: Bool = true
override init(frame: CGRect) {
super.init(frame: frame)
@@ -25,7 +26,7 @@ class PlainEmojiCollectionViewCell: UICollectionViewCell {
func configure(with: EmojiHoarder, emoji: Emoji) {
hostingController?.view.removeFromSuperview()
let swiftUIView = StickerPreview(sticker: emoji)
let swiftUIView = StickerPreview(sticker: emoji, animate: animate)
let hostingController = UIHostingController(rootView: swiftUIView)
self.hostingController = hostingController
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.