BlueWallet/ios/Widgets/PriceWidget/CompactPriceView.swift

69 lines
1.9 KiB
Swift
Raw Normal View History

2024-10-29 19:33:26 -04:00
import SwiftUI
@available(iOS 15.0, *)
struct CompactPriceView: View {
2024-11-20 02:57:42 -04:00
@Environment(\.colorScheme) var colorScheme
2024-10-29 19:33:26 -04:00
let price: String
let lastUpdated: String
2024-10-30 19:16:03 -04:00
let code: String
2024-10-29 19:33:26 -04:00
let dataSource: String
var body: some View {
VStack(alignment: .center, spacing: 16) {
Text(price)
.font(.title)
.bold()
.multilineTextAlignment(.center)
.dynamicTypeSize(.large ... .accessibility5)
2024-12-18 21:09:10 -04:00
.foregroundColor(textColor())
2024-10-29 19:33:26 -04:00
.accessibilityLabel("Bitcoin price: \(price)")
2024-10-30 19:16:03 -04:00
VStack(alignment: .center, spacing: 8) {
2024-11-20 02:57:42 -04:00
Text(code)
2024-11-20 23:54:07 -04:00
.shadow(color: shadowColor(), radius: 1, x: 0, y: 1)
2024-11-20 02:57:42 -04:00
Text(lastUpdated)
2024-11-20 23:54:07 -04:00
.shadow(color: shadowColor(), radius: 1, x: 0, y: 1)
2024-11-20 02:57:42 -04:00
Text(dataSource)
2024-11-20 23:54:07 -04:00
.shadow(color: shadowColor(), radius: 1, x: 0, y: 1)
2024-10-29 19:33:26 -04:00
}
.font(.subheadline)
2024-12-18 21:09:10 -04:00
.foregroundColor(textColor())
2024-10-29 19:33:26 -04:00
.multilineTextAlignment(.center)
.accessibilityElement(children: .combine)
}
.padding()
.frame(maxWidth: .infinity)
}
2024-11-20 02:57:42 -04:00
2024-12-18 21:09:10 -04:00
private func textColor() -> Color {
colorScheme == .dark ? .white : .black
}
2024-11-20 23:54:07 -04:00
private func shadowColor() -> Color {
2024-12-18 21:09:10 -04:00
textColor().opacity(0.2)
2024-11-20 02:57:42 -04:00
}
2024-11-20 23:54:07 -04:00
}
2024-11-20 08:58:59 -04:00
2024-11-20 23:54:07 -04:00
@available(iOS 15.0, *)
struct CompactPriceView_Previews: PreviewProvider {
static var previews: some View {
ZStack {
LinearGradient(
gradient: Gradient(colors: [.blue, .purple]),
startPoint: .top,
endPoint: .bottom
)
.ignoresSafeArea()
CompactPriceView(
price: "$50,000",
lastUpdated: "Last updated: Oct 10, 2023",
code: "BTC",
dataSource: "Data source: CoinDesk"
)
}
2024-11-20 08:58:59 -04:00
}
2024-11-20 23:54:07 -04:00
}