faster gifView for images

This commit is contained in:
neon443 committed 2026-04-10 20:11:01 +01:00
1 parent 99500e7b08
commit fc1e812d4f
4 files changed
+74 -44

No files matched your search

+13
View File
@@ -246,6 +246,19 @@ class EmojiHoarder: BaseHoarder {
self.showWelcome = newValue self.showWelcome = newValue
} }
func loadEmojiPacks() {
}
func saveEmojiPacks() {
var toStore: [URL] = []
for pack in emojiPacks {
toStore.append(pack.shareLink())
}
guard let encoded = try? JSONEncoder().encode(toStore) else { return }
}
func generateLetterStats() { func generateLetterStats() {
var result: [EmojiHoarder.LetterStat] = [] var result: [EmojiHoarder.LetterStat] = []
for child in trie.root.children { for child in trie.root.children {
+29 -14
View File
@@ -18,6 +18,17 @@ struct GifView: View {
@State var timer: Timer? @State var timer: Timer?
func run() async { func run() async {
guard url.pathExtension == "gif" else {
if let data = try? await URLSession.shared.data(from: url).0,
let uiImage = UIImage(data: data),
let cgImage = uiImage.cgImage {
withAnimation(.spring) {
self.gif = [(cgImage, 1)]
}
}
return
}
do { do {
if gif.isEmpty { if gif.isEmpty {
let frames = try await GifManager.gifFrom(url: url) let frames = try await GifManager.gifFrom(url: url)
@@ -48,26 +59,30 @@ struct GifView: View {
var body: some View { var body: some View {
// /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Hello, world!@*/Text("Hello, world!")/*@END_MENU_TOKEN@*/ // /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Hello, world!@*/Text("Hello, world!")/*@END_MENU_TOKEN@*/
TimelineView(.animation) { tl in Group {
VStack { if gif.isEmpty {
if gif.isEmpty { ProgressView()
ProgressView() .controlSize(.large)
.controlSize(.large) .frame(maxWidth: .infinity, maxHeight: .infinity)
.frame(maxWidth: .infinity, maxHeight: .infinity) } else if url.pathExtension == "gif" {
} else { TimelineView(.animation) { tl in
if currentI < gif.count { if currentI < gif.count {
let image = Image(uiImage: .init(cgImage: gif[currentI].frame)) Image(uiImage: .init(cgImage: gif[currentI].frame))
image
.resizable().scaledToFit() .resizable().scaledToFit()
} }
} }
.onDisappear {
timer?.invalidate()
timer = nil
}
} else {
if let frame = gif.first {
Image(uiImage: .init(cgImage: frame.frame))
.resizable().scaledToFit()
}
} }
.transition(.scale)
}
.onDisappear {
timer?.invalidate()
timer = nil
} }
.transition(.scale)
.onAppear { .onAppear {
Task { Task {
await run() await run()
+30 -29
View File
@@ -134,35 +134,36 @@ extension EmojiPack {
"loll", "loll",
"bleh", "bleh",
"uhh", "uhh",
"communist", "communist"
"ufahh", // "communist",
"uhafh", // "ufahh",
"uhgfh", // "uhafh",
"uoohh", // "uhgfh",
"ujyhgghh", // "uoohh",
"uhfgh", // "ujyhgghh",
"ujg3thh", // "uhfgh",
"uyhh", // "ujg3thh",
"ughhhh", // "uyhh",
"uvhh", // "ughhhh",
"ujrg3tjthhg", // "uvhh",
"ujherh", // "ujrg3tjthhg",
"uxhggrh", // "ujherh",
"ushgrq3geallh", // "uxhggrh",
"u hrgqh", // "ushgrq3geallh",
"ujjjjjyhgh", // "u hrgqh",
"uherhh", // "ujjjjjyhgh",
"uhhesh", // "uherhh",
"hhreruhgh", // "uhhesh",
"u hffh", // "hhreruhgh",
"uh h", // "u hffh",
"uaugerhh", // "uh h",
"u4h3h", // "uaugerhh",
"u4hh", // "u4h3h",
"ueyhh ", // "u4hh",
"u erthh", // "ueyhh ",
"uhujh", // "u erthh",
"ujkkkkhh" // "uhujh",
// "ujkkkkhh"
] ]
) )
} }
@@ -81,6 +81,7 @@ struct EmojiPackDetailView: View {
.blur(radius: 5) .blur(radius: 5)
.shadow(color: .purple, radius: 5) .shadow(color: .purple, radius: 5)
} }
.padding()
} }
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing))) let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
@@ -172,7 +173,7 @@ struct EmojiPackDetailView: View {
} }
} }
.onDisappear { .onDisappear {
print("disappear") hoarder.
} }
} }
} }
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.