mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-03-11 05:19:13 +00:00
quick update to gifs
added a continue button to welocme view
This commit is contained in:
@@ -14,7 +14,8 @@ 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 go: Bool = false
|
|
||||||
|
@State var timer: Timer?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
// /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Hello, world!@*/Text("Hello, world!")/*@END_MENU_TOKEN@*/
|
// /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Hello, world!@*/Text("Hello, world!")/*@END_MENU_TOKEN@*/
|
||||||
@@ -27,33 +28,32 @@ struct GifView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onChange(of: go) { _ in
|
.onDisappear {
|
||||||
if currentI == (gif.count-1) {
|
timer?.invalidate()
|
||||||
currentI = 0
|
|
||||||
} else {
|
|
||||||
currentI += 1
|
|
||||||
}
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now()+gif[currentI].showFor) {
|
|
||||||
go.toggle()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.onTapGesture {
|
|
||||||
go.toggle()
|
|
||||||
}
|
}
|
||||||
.task {
|
.task {
|
||||||
self.gif = await GifManager.gifFrom(url: url)
|
self.gif = await GifManager.gifFrom(url: url)
|
||||||
guard gif.count > 0 else {
|
guard gif.count > 0 else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now()+gif[0].showFor) {
|
guard timer == nil else {
|
||||||
go.toggle()
|
timer!.invalidate()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
timer = Timer(timeInterval: gif[0].showFor, repeats: true) { timer in
|
||||||
|
if currentI == (gif.count-1) {
|
||||||
|
currentI = 0
|
||||||
|
} else {
|
||||||
|
currentI += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RunLoop.main.add(timer!, forMode: .common)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
GifView(
|
GifView(
|
||||||
url: URL(string: "https://files.catbox.moe/3x5sea.gif")!
|
url: URL(string: "https://emoji.slack-edge.com/T0266FRGM/clockrun/ec33c513d30a6ed8.gif")!
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,13 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct WelcomeView: View {
|
struct WelcomeView: View {
|
||||||
var body: some View {
|
@Environment(\.dismiss) var dismiss
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
VStack {
|
VStack {
|
||||||
Text("StickerSlack")
|
Text("StickerSlack")
|
||||||
.bold()
|
.bold()
|
||||||
.font(.title)
|
.font(.largeTitle)
|
||||||
.monospaced()
|
.monospaced()
|
||||||
.padding()
|
.padding()
|
||||||
List {
|
List {
|
||||||
@@ -26,10 +28,36 @@ struct WelcomeView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.scrollContentBackground(.hidden)
|
.scrollContentBackground(.hidden)
|
||||||
|
Spacer()
|
||||||
|
if #available(iOS 19, *) {
|
||||||
|
Button() {
|
||||||
|
dismiss()
|
||||||
|
} label: {
|
||||||
|
Text("Continue")
|
||||||
|
.font(.title)
|
||||||
|
.bold()
|
||||||
|
}
|
||||||
|
.buttonStyle(.glassProminent)
|
||||||
|
.padding(.bottom)
|
||||||
|
} else {
|
||||||
|
Button() {
|
||||||
|
dismiss()
|
||||||
|
} label: {
|
||||||
|
Text("Continue")
|
||||||
|
.font(.title)
|
||||||
|
.bold()
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderedProminent)
|
||||||
|
.padding(.bottom)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
WelcomeView()
|
Color.gray.opacity(0.5)
|
||||||
|
.ignoresSafeArea(.all)
|
||||||
|
.sheet(isPresented: .constant(true)) {
|
||||||
|
WelcomeView()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user