import SwiftUI struct CreatorChannelSeriesOwnershipRateView: View { let purchasedContentCount: Int let paidContentCount: Int let purchasedPaidContentRate: Int private var progress: Double { max(0, min(Double(purchasedPaidContentRate) / 100, 1)) } init( purchasedContentCount: Int, paidContentCount: Int, purchasedPaidContentRate: Int ) { self.purchasedContentCount = purchasedContentCount self.paidContentCount = paidContentCount self.purchasedPaidContentRate = purchasedPaidContentRate } var body: some View { VStack(alignment: .leading, spacing: SodaSpacing.s4) { HStack(alignment: .center, spacing: SodaSpacing.s8) { ( Text(purchasedContentCount.comma()) .foregroundColor(.white) + Text("/\(paidContentCount.comma())\(I18n.CreatorChannelSeries.contentCountUnit)") .foregroundColor(Color.gray500) ) .appFont(size: 14, weight: .medium) .lineLimit(1) Spacer(minLength: SodaSpacing.s8) Text("\(purchasedPaidContentRate)%") .appFont(size: 14, weight: .medium) .foregroundColor(Color.soda400) .lineLimit(1) } ProgressView(value: progress) .progressViewStyle(.linear) .tint(Color.soda400) .frame(height: 4) } } } struct CreatorChannelSeriesOwnershipRateView_Previews: PreviewProvider { static var previews: some View { CreatorChannelSeriesOwnershipRateView( purchasedContentCount: 12, paidContentCount: 45, purchasedPaidContentRate: 40 ) .background(Color.black) .previewLayout(.sizeThatFits) } }