https://www.youtube.com/watch?v=po4lRojJXdA&list=PLwvDm4Vfkdphbc3bgy_LpLRQ9DDfFGcFu&index=23
coinDetailDataService
.$coinDetails
.sink { [weak self] coinDetails in
self?.coinDescription = coinDetails?.readableDescription
self?.websiteURL = coinDetails?.links?.homepage?.first
self?.redditURL = coinDetails?.links?.subredditURL
}
.store(in: &cancellables)
addSubscription
함수의 일부분private var descriptionSection: some View {
ZStack {
if
let coinDescription = viewModel.coinDescription,
!coinDescription.isEmpty {
VStack(alignment: .leading) {
Text(coinDescription)
.lineLimit(showFullDescription ? nil : 3)
.font(.callout)
.foregroundColor(Color.theme.secondaryText)
Button {
withAnimation(.easeInOut) {
showFullDescription.toggle()
}
} label: {
Text(showFullDescription ? "Less" : "Read more...")
.font(.caption)
.fontWeight(.bold)
}
.tint(.blue)
}
.frame(maxWidth: .infinity, alignment: .leading)
}
}
}
@State
로 선언한 showFullDescription
변수 값에 따라 현재 설명 텍스트 뷰를 보여줄 lineNumber
를 결정 가능private var descriptionSection: some View {
ZStack {
if
let coinDescription = viewModel.coinDescription,
!coinDescription.isEmpty {
VStack(alignment: .leading) {
Text(coinDescription)
.lineLimit(showFullDescription ? nil : 3)
.font(.callout)
.foregroundColor(Color.theme.secondaryText)
Button {
withAnimation(.easeInOut) {
showFullDescription.toggle()
}
} label: {
Text(showFullDescription ? "Less" : "Read more...")
.font(.caption)
.fontWeight(.bold)
}
.tint(.blue)
}
.frame(maxWidth: .infinity, alignment: .leading)
}
}
}
private var websiteSection: some View {
VStack(alignment: .leading, spacing: 20) {
if
let websiteURLString = viewModel.websiteURL,
let url = URL(string: websiteURLString) {
Link("Website", destination: url)
}
if let redditURLString = viewModel.redditURL,
let url = URL(string: redditURLString) {
Link("Reddit", destination: url)
}
}
.tint(.blue)
.frame(maxWidth: .infinity, alignment: .leading)
.font(.headline)
}