Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created July 16, 2020 15:04
Show Gist options
  • Save azamsharp/59ba5591216bf5a9b94eeac2b008109c to your computer and use it in GitHub Desktop.
Save azamsharp/59ba5591216bf5a9b94eeac2b008109c to your computer and use it in GitHub Desktop.
//
// ContentView.swift
// Shared
//
// Created by Mohammad Azam on 7/21/20.
//
import SwiftUI
struct ContentView: View {
@State private var degrees: Double = 0
@State private var flipped: Bool = false
var body: some View {
CreditCard {
VStack {
Group {
if flipped {
CreditCardBack()
} else {
CreditCardFront()
}
}
}.rotation3DEffect(
.degrees(degrees),
axis: (x: 0.0, y: 1.0, z: 0.0)
)
}
.onTapGesture {
withAnimation {
degrees += 180
flipped.toggle()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
//
// CreditCard.swift
// CreditCardSwiftUI
//
// Created by Mohammad Azam on 7/21/20.
//
import SwiftUI
struct CreditCard<Content>: View where Content: View {
var content: () -> Content
var body: some View {
content()
}
}
struct CreditCardFront: View {
var body: some View {
VStack {
Text("FRONT").foregroundColor(Color.white)
}.frame(width: 300, height: 200)
.background(LinearGradient(gradient: Gradient(colors: [Color.red, Color.blue]), startPoint: .leading, endPoint: .trailing))
.cornerRadius(10)
}
}
struct CreditCardBack: View {
var body: some View {
VStack {
Text("").foregroundColor(Color.white)
}.frame(width: 300, height: 200)
.background(LinearGradient(gradient: Gradient(colors: [Color.yellow, Color.blue]), startPoint: /*@START_MENU_TOKEN@*/.leading/*@END_MENU_TOKEN@*/, endPoint: /*@START_MENU_TOKEN@*/.trailing/*@END_MENU_TOKEN@*/))
.cornerRadius(10)
}
}
struct CreditCard_Previews: PreviewProvider {
static var previews: some View {
CreditCard<CreditCardFront>(content: { CreditCardFront() })
}
}
@itiswafa
Copy link

itiswafa commented Jun 5, 2022

can I ask u about this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment