Skip to content

Instantly share code, notes, and snippets.

@saroar
Created July 18, 2023 13:11
Show Gist options
  • Save saroar/685e2612749cc24986b271ca7c05d487 to your computer and use it in GitHub Desktop.
Save saroar/685e2612749cc24986b271ca7c05d487 to your computer and use it in GitHub Desktop.
public var body: some View {
WithViewStore(store) { viewStore in
VStack {
VStack(alignment: .leading) {
HStack {
if let imageUrl = viewStore.vCard.imageURLs.first(where: { $0.type == .icon }) {
AsyncImage(url: URL(string: imageUrl.urlString)) { phase in
if let image = phase.image {
image.resizable()
} else if phase.error != nil {
Color.red
} else {
ProgressView()
.tint(Color.blue)
}
}
.frame(width: 30, height: 30)
} else {
Image("icon")
.resizable()
.frame(width: 30, height: 30)
}
Text(viewStore.vCard.organization ?? viewStore.vCard.contact.fullName)
.font(.title)
.fontWeight(.bold)
.foregroundColor(Color(rgbString: viewStore.colorP.foregroundColor))
Spacer()
}
HStack {
VStack(alignment: .leading) {
Text("NAME")
.font(.title2)
.fontWeight(.medium)
.foregroundColor(Color(rgbString: viewStore.colorP.labelColor))
Text(viewStore.vCard.contact.fullName.replacingOccurrences(of: " ", with: "\n").uppercased())
.font(.title)
.fontWeight(.bold)
.foregroundColor(Color(rgbString: viewStore.colorP.foregroundColor))
}
Spacer()
if let imageUrl = viewStore.vCard.imageURLs.first(where: { $0.type == .thumbnail }) {
AsyncImage(url: URL(string: imageUrl.urlString)) { phase in
if let image = phase.image {
image.resizable()
} else if phase.error != nil {
Color.red
} else {
ProgressView()
.tint(Color.blue)
}
}
.frame(width: 120, height: 120)
} else {
Image("thumbnail")
.resizable()
.frame(width: 120, height: 120)
}
}
.padding(.top, 20)
VStack(alignment: .leading) {
Text("POSITION")
.font(.title2)
.fontWeight(.medium)
.foregroundColor(Color(rgbString: viewStore.colorP.labelColor))
Text(viewStore.vCard.position)
.font(.title2)
.fontWeight(.light)
.foregroundColor(Color(rgbString: viewStore.colorP.foregroundColor))
}
.padding(.top, 20)
HStack {
VStack(alignment: .leading) {
Text("EMAIL")
.font(.title2)
.fontWeight(.medium)
.foregroundColor(Color(rgbString: viewStore.colorP.labelColor))
Text(viewStore.vCard.emails.first?.text ?? "[email protected]")
.minimumScaleFactor(0.4)
.lineLimit(1)
.layoutPriority(1)
.font(.title2)
.fontWeight(.light)
.accentColor(Color(rgbString: viewStore.colorP.foregroundColor))
Spacer()
}
Spacer()
VStack(alignment: .leading) {
Text("MOBILE")
.font(.title2)
.fontWeight(.medium)
.foregroundColor(Color(rgbString: viewStore.colorP.labelColor))
Text(viewStore.vCard.telephones.first?.number ?? "+7921000000")
.minimumScaleFactor(0.4)
.lineLimit(1)
.font(.title2)
.fontWeight(.light)
.foregroundColor(Color(rgbString: viewStore.colorP.foregroundColor))
Spacer()
}
}
.padding(.top, 20)
HStack(alignment: .bottom) {
Image(systemName: "square.and.arrow.up")
.resizable()
.frame(width: 20, height: 25)
Spacer()
if let image = viewStore.qrCodeImage {
image
.resizable()
.interpolation(.none)
.frame(width: 100, height: 100)
.padding(.trailing, -16)
} else {
Image("qr")
.resizable()
.frame(width: 180, height: 180)
}
Spacer()
Button {
viewStore.send(.selectedDCard(by: viewStore.id), animation: .easeIn(duration: 1))
} label: {
Image(
systemName: viewStore.isTappedCard == true
? "heart.circle"
: "circle"
)
.resizable()
.foregroundColor(viewStore.isTappedCard == true ? Color(rgbString: viewStore.colorP.foregroundColor) : Color.gray)
.frame(width: 40, height: 40)
}
}
// .padding(.top, 20)
}
.onAppear {
viewStore.send(.onAppear)
}
.padding(20)
.background(Color(rgbString: viewStore.colorP.backgroundColor))
.cornerRadius(30)
}
.padding(20)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment