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 gif: [(frame: CGImage, showFor: Double)] = []
|
||||
@State var currentI: Int = 0
|
||||
@State var go: Bool = false
|
||||
|
||||
@State var timer: Timer?
|
||||
|
||||
var body: some View {
|
||||
// /*@START_MENU_TOKEN@*//*@PLACEHOLDER=Hello, world!@*/Text("Hello, world!")/*@END_MENU_TOKEN@*/
|
||||
@@ -27,33 +28,32 @@ struct GifView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChange(of: go) { _ in
|
||||
if currentI == (gif.count-1) {
|
||||
currentI = 0
|
||||
} else {
|
||||
currentI += 1
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()+gif[currentI].showFor) {
|
||||
go.toggle()
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
go.toggle()
|
||||
.onDisappear {
|
||||
timer?.invalidate()
|
||||
}
|
||||
.task {
|
||||
self.gif = await GifManager.gifFrom(url: url)
|
||||
guard gif.count > 0 else {
|
||||
return
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now()+gif[0].showFor) {
|
||||
go.toggle()
|
||||
guard timer == nil else {
|
||||
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 {
|
||||
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
|
||||
|
||||
struct WelcomeView: View {
|
||||
var body: some View {
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text("StickerSlack")
|
||||
.bold()
|
||||
.font(.title)
|
||||
.font(.largeTitle)
|
||||
.monospaced()
|
||||
.padding()
|
||||
List {
|
||||
@@ -26,10 +28,36 @@ struct WelcomeView: View {
|
||||
}
|
||||
}
|
||||
.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 {
|
||||
WelcomeView()
|
||||
Color.gray.opacity(0.5)
|
||||
.ignoresSafeArea(.all)
|
||||
.sheet(isPresented: .constant(true)) {
|
||||
WelcomeView()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user