0

I'm trying to use a slide transition every time I press draw to deal my cards but it don't do anything except slide the card onetime then another card just pop up without sliding.If I use toggle it works but it goes from false to true which I DON'T need. I need my dealtCard variable to be true every time I press draw. I don't know where I'm going wrong any help?

@State var dealtCard = false
var body: some View {
    ZStack {
        Image("white-background")
            .resizable()
            .ignoresSafeArea()
        VStack {
            HStack {
                Spacer()
                if dealtCard {
                    Image(cardDealt)
                        .resizable()
                        .cornerRadius(15)
                        .aspectRatio(contentMode: .fill)
                        .transition(AnyTransition.slide)
                }
                Spacer()
            }.shadow(radius: 4)
            
            HStack {
                Button {
                    //Action for button
                    deal()
                    
                } label:{
                    // How the button look
                    Text("Draw")
                        .foregroundColor(.white)
                        .padding()
                        .background(.black)
                        .cornerRadius(15.0)
                        .font(.system(size:25))
                        .fontWeight(.bold)
                } 
            }.buttonBorderShape(.capsule)
        }
    }
}
func deal() {
    let cpuCardValue = Int.random(in:1...20)
    cardDealt = "card" + String(cpuCardValue)
    withAnimation(.easeOut) {
        dealtCard = true
    }
}

}

0 Answers0