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