enzyme69/blendersushi

Swift UI Display Text In List, change every few seconds

enzyme69 opened this issue · 0 comments

import SwiftUI

struct ContentView: View {
    let words: [String] = [
        "Your pixels bloom where doubt wilts. Tend your garden, samurai of polygons.",
        "Imperfections are brushstrokes of soul. Embrace the happy accidents, young padawan.",
        "Render not just textures, but emotions. Every mesh sings a silent song, hear it.",
        "The canvas is infinite, the deadline finite. Pace yourself, grasshopper, savor the journey.",
        "Critique is not a chisel, but a whetstone. Sharpen your skills, not your anxieties.",
        "Inspiration is everywhere, not just in tutorials. Open your eyes, apprentice, the world is your reference library.",
        "Comparison is a thief of progress. Steal only techniques, young master, leave your originality intact.",
        "Technical hurdles are merely stepping stones. Leap over them, young Jedi, reach for the summit of your vision.",
        "Community is your dojo, collaboration your sparring partner. Train together, grow together.",
        "The greatest masterpiece is not the final render, but the journey of creation. Forge your own legend, pixel by pixel."
    ]    
    
    @State private var currentWordIndex: Int = 0
    @State private var backgroundColor = Color.pink
    
    let timer = Timer.publish(every: 1.0, on: .main, in: .common).autoconnect()
    
    var body: some View {
        ZStack {
            Color(backgroundColor)
                .edgesIgnoringSafeArea(.all) // Fill the entire screen
            
            if currentWordIndex < words.count {
                Text(words[currentWordIndex])
                    .font(.largeTitle)
                    .font(.system(size: 200))
                    .bold()
                    .padding(.horizontal, 30) // 
            }
        }
        .onReceive(timer) { _ in
            withAnimation {
                if currentWordIndex < words.count - 1 {
                    currentWordIndex += 1
                } else {
                    timer.upstream.connect().cancel()
                }
            }
        }
    }
}