struct Flashcard : View {
@State var frontText = newArray[randomNum].kana
@State var backText = newArray[randomNum].romaji
var body: some View {
let zstack = ZStack {
Frontside(kanatext: frontText)
.background(Color.yellow)
.rotation3DEffect(.degrees(self.showResults ? 180.0 : 0.0), axis: (x: 0.0, y: 1.0, z: 0.0))
.zIndex(self.showResults ? 0 : 1)
.frame(width: 300, alignment: .center)
.cornerRadius(25)
}
}
public struct Frontside: View
{
@State public var kanatext: String = ""
public var body: some View
{
Text(self.kanatext)
.font(.title)
.fontWeight(.black)
.padding(32)
}
}
In my code snippet above, when I update the @State var frontText, I'm expecting my view to refresh and display the frontText. But for some reason it won't show the new frontText when it is used in my Frontside struct. If I just print Text(frontText) in my view, it will always refresh as the variable changes. What am I missing for it to refresh properly whenever frontText is updated? Thanks.