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
+40
-13
No files matched your search
@@ -37,4 +37,14 @@ class GifManager {
|
|||||||
}
|
}
|
||||||
return result
|
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
|
nonisolated
|
||||||
func downloadImage() async throws {
|
func downloadImage() async throws {
|
||||||
|
let targetSize = CGSize(width: 500, height: 500)
|
||||||
if let data = try? await Data(contentsOf: localImageURL),
|
if let data = try? await Data(contentsOf: localImageURL),
|
||||||
let _ = UIImage(data: data) {
|
let _ = UIImage(data: data) {
|
||||||
return
|
return
|
||||||
@@ -68,15 +69,20 @@ extension StickerProtocol {
|
|||||||
|
|
||||||
var (data, _) = try await URLSession.shared.data(from: remoteImageURL)
|
var (data, _) = try await URLSession.shared.data(from: remoteImageURL)
|
||||||
|
|
||||||
if let uiImage = UIImage(data: data),
|
print(await GifManager.gifFrom(data: data).count)
|
||||||
let cgImage = uiImage.cgImage,
|
|
||||||
await !self.localImageURLString.contains(".gif"),
|
|
||||||
cgImage.width < 500 || cgImage.height < 500 {
|
|
||||||
if await self.localImageURLString.suffix(4) == ".gif" {
|
|
||||||
|
|
||||||
|
if let uiImage = UIImage(data: data),
|
||||||
|
await GifManager.gifFrom(data: data).count == 1 {
|
||||||
|
data = await resize(image: uiImage, to: targetSize).pngData()!
|
||||||
} else {
|
} else {
|
||||||
data = await resize(image: uiImage, to: CGSize(width: 500, height: 500)).pngData()!
|
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)
|
try! await data.write(to: localImageURL)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -82,6 +82,9 @@ struct StickerRow<T: Hoarder>: View {
|
|||||||
.resizable().scaledToFit()
|
.resizable().scaledToFit()
|
||||||
}
|
}
|
||||||
.transition(.scale)
|
.transition(.scale)
|
||||||
|
.onAppear {
|
||||||
|
downloading = false
|
||||||
|
}
|
||||||
} else if downloading {
|
} else if downloading {
|
||||||
ProgressView()
|
ProgressView()
|
||||||
.transition(.scale)
|
.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.items = items
|
||||||
context.coordinator.pack = pack
|
|
||||||
uiView.reloadData()
|
uiView.reloadData()
|
||||||
}
|
}
|
||||||
|
if pack != context.coordinator.pack {
|
||||||
|
context.coordinator.pack = pack
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeCoordinator() -> Coordinator {
|
func makeCoordinator() -> Coordinator {
|
||||||
|
|||||||
@@ -22,9 +22,16 @@ class MessagesViewController: MSMessagesAppViewController {
|
|||||||
|
|
||||||
override func willBecomeActive(with conversation: MSConversation) {
|
override func willBecomeActive(with conversation: MSConversation) {
|
||||||
let stickerBrowser = MSStickerBrowserView(frame: .zero, stickerSize: .small)
|
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.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 {
|
guard stickerBrowser.dataSource?.numberOfStickers(in: stickerBrowser) != 0 else {
|
||||||
let swiftUIView = NoStickersView()
|
let swiftUIView = NoStickersView()
|
||||||
@@ -54,9 +61,8 @@ class MessagesViewController: MSMessagesAppViewController {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
view.addSubview(stickerBrowser)
|
// stickerBrowser.reloadData()
|
||||||
stickerBrowser.reloadData()
|
// view.bringSubviewToFront(stickerBrowser)
|
||||||
view.bringSubviewToFront(stickerBrowser)
|
|
||||||
|
|
||||||
// Called when the extension is about to move from the inactive to active state.
|
// 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.
|
// This will happen when the extension is about to present UI.
|
||||||
|
|||||||