mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
updated resizing and gonna do gifs
fix crazy lag when changing pack name fix ui sizing issue on stickerpicker
This commit is contained in:
5 files changed
+41
-14
No files matched your search
@@ -37,4 +37,14 @@ class GifManager {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
static func dataFrom(frames: [(frame: CGImage, showFor: Double)]) -> Data? {
|
||||
// let cgImage = CGImageSourceCreateWithData(<#T##data: CFData##CFData#>, <#T##options: CFDictionary?##CFDictionary?#>)
|
||||
return nil
|
||||
}
|
||||
|
||||
static func dataFrom(gif: CGImage) -> Data? {
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,7 @@ extension StickerProtocol {
|
||||
|
||||
nonisolated
|
||||
func downloadImage() async throws {
|
||||
let targetSize = CGSize(width: 500, height: 500)
|
||||
if let data = try? await Data(contentsOf: localImageURL),
|
||||
let _ = UIImage(data: data) {
|
||||
return
|
||||
@@ -68,15 +69,20 @@ extension StickerProtocol {
|
||||
|
||||
var (data, _) = try await URLSession.shared.data(from: remoteImageURL)
|
||||
|
||||
if let uiImage = UIImage(data: data),
|
||||
let cgImage = uiImage.cgImage,
|
||||
await !self.localImageURLString.contains(".gif"),
|
||||
cgImage.width < 500 || cgImage.height < 500 {
|
||||
if await self.localImageURLString.suffix(4) == ".gif" {
|
||||
print(await GifManager.gifFrom(data: data).count)
|
||||
|
||||
} else {
|
||||
data = await resize(image: uiImage, to: CGSize(width: 500, height: 500)).pngData()!
|
||||
if let uiImage = UIImage(data: data),
|
||||
await GifManager.gifFrom(data: data).count == 1 {
|
||||
data = await resize(image: uiImage, to: targetSize).pngData()!
|
||||
} else {
|
||||
var frames: [(frame: CGImage, showFor: Double)] = []
|
||||
for frame in await GifManager.gifFrom(data: data) {
|
||||
frames.append((
|
||||
await resize(image: UIImage(cgImage: frame.frame), to: targetSize).cgImage!,
|
||||
frame.showFor
|
||||
))
|
||||
}
|
||||
data = await GifManager.dataFrom(frames: frames)!
|
||||
}
|
||||
try! await data.write(to: localImageURL)
|
||||
return
|
||||
|
||||
@@ -82,6 +82,9 @@ struct StickerRow<T: Hoarder>: View {
|
||||
.resizable().scaledToFit()
|
||||
}
|
||||
.transition(.scale)
|
||||
.onAppear {
|
||||
downloading = false
|
||||
}
|
||||
} else if downloading {
|
||||
ProgressView()
|
||||
.transition(.scale)
|
||||
|
||||
@@ -45,11 +45,13 @@ struct EmojiCollectionView: UIViewRepresentable {
|
||||
}
|
||||
}
|
||||
|
||||
if items != context.coordinator.items || context.coordinator.pack != pack {
|
||||
if items != context.coordinator.items {
|
||||
context.coordinator.items = items
|
||||
context.coordinator.pack = pack
|
||||
uiView.reloadData()
|
||||
}
|
||||
if pack != context.coordinator.pack {
|
||||
context.coordinator.pack = pack
|
||||
}
|
||||
}
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
|
||||
@@ -22,9 +22,16 @@ class MessagesViewController: MSMessagesAppViewController {
|
||||
|
||||
override func willBecomeActive(with conversation: MSConversation) {
|
||||
let stickerBrowser = MSStickerBrowserView(frame: .zero, stickerSize: .small)
|
||||
stickerBrowser.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)
|
||||
stickerBrowser.dataSource = dataSource
|
||||
stickerBrowser.autoresizingMask = [.flexibleWidth]
|
||||
|
||||
stickerBrowser.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stickerBrowser)
|
||||
NSLayoutConstraint.activate([
|
||||
stickerBrowser.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
stickerBrowser.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
stickerBrowser.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
stickerBrowser.trailingAnchor.constraint(equalTo: view.trailingAnchor)
|
||||
])
|
||||
|
||||
guard stickerBrowser.dataSource?.numberOfStickers(in: stickerBrowser) != 0 else {
|
||||
let swiftUIView = NoStickersView()
|
||||
@@ -54,9 +61,8 @@ class MessagesViewController: MSMessagesAppViewController {
|
||||
return
|
||||
}
|
||||
|
||||
view.addSubview(stickerBrowser)
|
||||
stickerBrowser.reloadData()
|
||||
view.bringSubviewToFront(stickerBrowser)
|
||||
// stickerBrowser.reloadData()
|
||||
// view.bringSubviewToFront(stickerBrowser)
|
||||
|
||||
// Called when the extension is about to move from the inactive to active state.
|
||||
// This will happen when the extension is about to present UI.
|
||||
|
||||