Created
July 16, 2020 15:04
-
-
Save azamsharp/59ba5591216bf5a9b94eeac2b008109c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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() }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can I ask u about this code?