mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
faster gifView for images
This commit is contained in:
4 files changed
+68
-38
No files matched your search
@@ -246,6 +246,19 @@ class EmojiHoarder: BaseHoarder {
|
||||
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() {
|
||||
var result: [EmojiHoarder.LetterStat] = []
|
||||
for child in trie.root.children {
|
||||
|
||||
@@ -18,6 +18,17 @@ struct GifView: View {
|
||||
@State var timer: Timer?
|
||||
|
||||
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 {
|
||||
if gif.isEmpty {
|
||||
let frames = try await GifManager.gifFrom(url: url)
|
||||
@@ -48,26 +59,30 @@ struct GifView: View {
|
||||
|
||||
var body: some View {
|
||||
// /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Hello, world!@*/Text("Hello, world!")/*@END_MENU_TOKEN@*/
|
||||
TimelineView(.animation) { tl in
|
||||
VStack {
|
||||
Group {
|
||||
if gif.isEmpty {
|
||||
ProgressView()
|
||||
.controlSize(.large)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
} else {
|
||||
} else if url.pathExtension == "gif" {
|
||||
TimelineView(.animation) { tl in
|
||||
if currentI < gif.count {
|
||||
let image = Image(uiImage: .init(cgImage: gif[currentI].frame))
|
||||
image
|
||||
Image(uiImage: .init(cgImage: gif[currentI].frame))
|
||||
.resizable().scaledToFit()
|
||||
}
|
||||
}
|
||||
}
|
||||
.transition(.scale)
|
||||
}
|
||||
.onDisappear {
|
||||
timer?.invalidate()
|
||||
timer = nil
|
||||
}
|
||||
} else {
|
||||
if let frame = gif.first {
|
||||
Image(uiImage: .init(cgImage: frame.frame))
|
||||
.resizable().scaledToFit()
|
||||
}
|
||||
}
|
||||
}
|
||||
.transition(.scale)
|
||||
.onAppear {
|
||||
Task {
|
||||
await run()
|
||||
|
||||
@@ -134,35 +134,36 @@ extension EmojiPack {
|
||||
"loll",
|
||||
"bleh",
|
||||
"uhh",
|
||||
"communist",
|
||||
"ufahh",
|
||||
"uhafh",
|
||||
"uhgfh",
|
||||
"uoohh",
|
||||
"ujyhgghh",
|
||||
"uhfgh",
|
||||
"ujg3thh",
|
||||
"uyhh",
|
||||
"ughhhh",
|
||||
"uvhh",
|
||||
"ujrg3tjthhg",
|
||||
"ujherh",
|
||||
"uxhggrh",
|
||||
"ushgrq3geallh",
|
||||
"u hrgqh",
|
||||
"ujjjjjyhgh",
|
||||
"uherhh",
|
||||
"uhhesh",
|
||||
"hhreruhgh",
|
||||
"u hffh",
|
||||
"uh h",
|
||||
"uaugerhh",
|
||||
"u4h3h",
|
||||
"u4hh",
|
||||
"ueyhh ",
|
||||
"u erthh",
|
||||
"uhujh",
|
||||
"ujkkkkhh"
|
||||
"communist"
|
||||
// "communist",
|
||||
// "ufahh",
|
||||
// "uhafh",
|
||||
// "uhgfh",
|
||||
// "uoohh",
|
||||
// "ujyhgghh",
|
||||
// "uhfgh",
|
||||
// "ujg3thh",
|
||||
// "uyhh",
|
||||
// "ughhhh",
|
||||
// "uvhh",
|
||||
// "ujrg3tjthhg",
|
||||
// "ujherh",
|
||||
// "uxhggrh",
|
||||
// "ushgrq3geallh",
|
||||
// "u hrgqh",
|
||||
// "ujjjjjyhgh",
|
||||
// "uherhh",
|
||||
// "uhhesh",
|
||||
// "hhreruhgh",
|
||||
// "u hffh",
|
||||
// "uh h",
|
||||
// "uaugerhh",
|
||||
// "u4h3h",
|
||||
// "u4hh",
|
||||
// "ueyhh ",
|
||||
// "u erthh",
|
||||
// "uhujh",
|
||||
// "ujkkkkhh"
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ struct EmojiPackDetailView: View {
|
||||
.blur(radius: 5)
|
||||
.shadow(color: .purple, radius: 5)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
let columns: Int = max(1, Int((geo.size.width - 2*spacing) / (minColWidth + spacing)))
|
||||
@@ -172,7 +173,7 @@ struct EmojiPackDetailView: View {
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
print("disappear")
|
||||
hoarder.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||