mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-03-11 05:19:13 +00:00
yay okay ui is state-ing
added swipe actions to delete local image slow, but i think i can fix it?? switch to gh neon443/Haptics
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"originHash" : "62caf5d3b5c5f962753f0e93862d5d90e6fcd2157c5fef072880f7c4ca348c7c",
|
||||||
|
"pins" : [
|
||||||
|
{
|
||||||
|
"identity" : "haptics",
|
||||||
|
"kind" : "remoteSourceControl",
|
||||||
|
"location" : "http://github.com/neon443/Haptics",
|
||||||
|
"state" : {
|
||||||
|
"branch" : "main",
|
||||||
|
"revision" : "90e080694752c1af657d2f7ac2dce22eaf439391"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version" : 3
|
||||||
|
}
|
||||||
@@ -8,9 +8,11 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
import UniformTypeIdentifiers
|
import UniformTypeIdentifiers
|
||||||
|
import Haptics
|
||||||
|
|
||||||
struct Emoji: Codable, Identifiable, Hashable {
|
struct Emoji: Codable, Identifiable, Hashable {
|
||||||
var id: UUID
|
var id: UUID
|
||||||
|
var uiID: UUID
|
||||||
var name: String
|
var name: String
|
||||||
var localImageURL: URL
|
var localImageURL: URL
|
||||||
var remoteImageURL: URL
|
var remoteImageURL: URL
|
||||||
@@ -31,6 +33,7 @@ struct Emoji: Codable, Identifiable, Hashable {
|
|||||||
init(from decoder: any Decoder) throws {
|
init(from decoder: any Decoder) throws {
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
self.id = try container.decode(UUID.self, forKey: .id)
|
self.id = try container.decode(UUID.self, forKey: .id)
|
||||||
|
self.uiID = UUID()
|
||||||
self.name = try container.decode(String.self, forKey: .name)
|
self.name = try container.decode(String.self, forKey: .name)
|
||||||
self.localImageURL = try container.decode(URL.self, forKey: .localImageURL)
|
self.localImageURL = try container.decode(URL.self, forKey: .localImageURL)
|
||||||
self.remoteImageURL = try container.decode(URL.self, forKey: .remoteImageURL)
|
self.remoteImageURL = try container.decode(URL.self, forKey: .remoteImageURL)
|
||||||
@@ -48,9 +51,12 @@ struct Emoji: Codable, Identifiable, Hashable {
|
|||||||
id: UUID = UUID()
|
id: UUID = UUID()
|
||||||
) {
|
) {
|
||||||
self.id = id
|
self.id = id
|
||||||
|
self.uiID = id
|
||||||
self.name = apiEmoji.name
|
self.name = apiEmoji.name
|
||||||
self.remoteImageURL = apiEmoji.url
|
self.remoteImageURL = apiEmoji.url
|
||||||
self.localImageURL = EmojiHoarder.container.appendingPathComponent(id.uuidString, conformingTo: .image)
|
|
||||||
|
let fileExtension = String(apiEmoji.urlString.split(separator: ".").last ?? "png")
|
||||||
|
self.localImageURL = EmojiHoarder.container.appendingPathComponent(id.uuidString+"."+fileExtension, conformingTo: .image)
|
||||||
|
|
||||||
// Task { [weak self] in
|
// Task { [weak self] in
|
||||||
// let (data, response) = try await URLSession.shared.data(from: apiEmoji.url)
|
// let (data, response) = try await URLSession.shared.data(from: apiEmoji.url)
|
||||||
@@ -70,4 +76,12 @@ struct Emoji: Codable, Identifiable, Hashable {
|
|||||||
try! data.write(to: localImageURL)
|
try! data.write(to: localImageURL)
|
||||||
return UIImage(data: data)!
|
return UIImage(data: data)!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteImage() {
|
||||||
|
try? FileManager.default.removeItem(at: localImageURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
mutating func refresh() {
|
||||||
|
self.uiID = UUID()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,20 +15,29 @@ struct ContentView: View {
|
|||||||
NavigationView {
|
NavigationView {
|
||||||
TabView {
|
TabView {
|
||||||
List {
|
List {
|
||||||
ForEach(hoarder.emojis, id: \.self) { emoji in
|
ForEach($hoarder.emojis, id: \.self) { $emoji in
|
||||||
HStack {
|
HStack {
|
||||||
EmojiPreview(emoji: emoji)
|
EmojiPreview(emoji: emoji, image: emoji.image)
|
||||||
.frame(maxWidth: 100)
|
.frame(maxWidth: 100)
|
||||||
Spacer()
|
Spacer()
|
||||||
Button("", systemImage: "arrow.down.circle") {
|
Button("", systemImage: "arrow.down.circle") {
|
||||||
Task {
|
Task {
|
||||||
let _ = try? await emoji.downloadImage()
|
try? await emoji.downloadImage()
|
||||||
Haptic.success.trigger()
|
emoji.refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
}
|
}
|
||||||
.border(emoji.isLocal ? .red : .clear)
|
.id(emoji.uiID)
|
||||||
|
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
|
||||||
|
if emoji.isLocal {
|
||||||
|
Button("Remove", systemImage: "trash") {
|
||||||
|
emoji.deleteImage()
|
||||||
|
emoji.refresh()
|
||||||
|
}
|
||||||
|
.tint(.red)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.tabItem {
|
.tabItem {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ struct EmojiPreview: View {
|
|||||||
@State var emoji: Emoji
|
@State var emoji: Emoji
|
||||||
|
|
||||||
@State private var id: UUID = UUID()
|
@State private var id: UUID = UUID()
|
||||||
@State private var image: UIImage?
|
@State var image: UIImage? = nil
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
@@ -51,12 +51,6 @@ struct EmojiPreview: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onTapGesture {
|
|
||||||
Task {
|
|
||||||
image = try? await emoji.downloadImage()
|
|
||||||
Haptic.success.trigger()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.id(id)
|
.id(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user