Files
platform/ios/Platform 1.44.16 AM/Platform/Shared/Components/MacroRing.swift
Yusuf Suleman fdb8aeba8a
All checks were successful
Security Checks / dependency-audit (push) Successful in 12s
Security Checks / secret-scanning (push) Successful in 3s
Security Checks / dockerfile-lint (push) Successful in 3s
restore: original UI views from first build, keep fixed models/API
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 01:54:46 -05:00

97 lines
2.8 KiB
Swift

import SwiftUI
struct MacroRing: View {
let current: Double
let goal: Double
let color: Color
let label: String
let unit: String
var size: CGFloat = 72
var lineWidth: CGFloat = 7
private var progress: Double {
guard goal > 0 else { return 0 }
return min(current / goal, 1.0)
}
private var remaining: Double {
max(goal - current, 0)
}
var body: some View {
VStack(spacing: 4) {
ZStack {
Circle()
.stroke(color.opacity(0.12), lineWidth: lineWidth)
Circle()
.trim(from: 0, to: progress)
.stroke(
color,
style: StrokeStyle(lineWidth: lineWidth, lineCap: .round)
)
.rotationEffect(.degrees(-90))
.animation(.easeOut(duration: 0.5), value: progress)
VStack(spacing: 0) {
Text("\(Int(remaining))")
.font(.system(size: size * 0.22, weight: .bold, design: .rounded))
.foregroundStyle(Color.text1)
Text("left")
.font(.system(size: size * 0.13, weight: .medium))
.foregroundStyle(Color.text4)
}
}
.frame(width: size, height: size)
Text(label)
.font(.caption2)
.fontWeight(.medium)
.foregroundStyle(Color.text3)
}
}
}
struct MacroRingLarge: View {
let current: Double
let goal: Double
let color: Color
var size: CGFloat = 120
var lineWidth: CGFloat = 10
private var progress: Double {
guard goal > 0 else { return 0 }
return min(current / goal, 1.0)
}
private var remaining: Double {
max(goal - current, 0)
}
var body: some View {
ZStack {
Circle()
.stroke(color.opacity(0.12), lineWidth: lineWidth)
Circle()
.trim(from: 0, to: progress)
.stroke(
color,
style: StrokeStyle(lineWidth: lineWidth, lineCap: .round)
)
.rotationEffect(.degrees(-90))
.animation(.easeOut(duration: 0.5), value: progress)
VStack(spacing: 2) {
Text("\(Int(remaining))")
.font(.system(size: size * 0.26, weight: .bold, design: .rounded))
.foregroundStyle(Color.text1)
Text("remaining")
.font(.system(size: size * 0.11, weight: .medium))
.foregroundStyle(Color.text4)
}
}
.frame(width: size, height: size)
}
}