DFWatchCloseCircle.swift 2.69 KB
//
//  DFWatchCloseCircle.swift
//  iwatch
//
//  Created by 权海 on 2026/6/12.
//

import SwiftUI

struct DFWatchCloseCircle: View {
    var outerProgress: CGFloat
    var middleProgress: CGFloat
    var innerProgress: CGFloat

    var outerColor: Color = Color(hex: "#FF5279")
    var middleColor: Color = Color(hex: "#3BD49D")
    var innerColor: Color = Color(hex: "#7B9BFB")

    var backgroundColor: Color = .black

    var body: some View {
        GeometryReader { geometry in
            let size = min(geometry.size.width, geometry.size.height)
            let lineWidth: CGFloat = size * 0.13

            ZStack {
                backgroundColor

                RingView(
                    progress: outerProgress,
                    color: outerColor,
                    lineWidth: lineWidth
                )
                .frame(
                    width: size * 0.87,
                    height: size * 0.87
                )

                RingView(
                    progress: middleProgress,
                    color: middleColor,
                    lineWidth: lineWidth
                )
                .frame(
                    width: size * 0.55,
                    height: size * 0.55
                )

                RingView(
                    progress: innerProgress,
                    color: innerColor,
                    lineWidth: lineWidth
                )
                .frame(
                    width: size * 0.24,
                    height: size * 0.24
                )

                Circle()
                    .fill(backgroundColor)
                    .frame(
                        width: size * 0.15,
                        height: size * 0.15
                    )
            }
            .frame(width: size, height: size)
            .clipShape(Circle())
        }
        .aspectRatio(1, contentMode: .fit)
    }
}
struct RingView: View {
    var progress: CGFloat
    var color: Color
    var lineWidth: CGFloat

    var body: some View {
        ZStack{
            Circle()
                .stroke(
                    color,
                    style: StrokeStyle(
                        lineWidth: lineWidth,
                        lineCap: .round,
                        lineJoin: .round
                    )
                )
                .opacity(0.3)
            Circle()
                .trim(from: 0, to: max(0, min(progress, 1)))
                .stroke(
                    color,
                    style: StrokeStyle(
                        lineWidth: lineWidth,
                        lineCap: .round,
                        lineJoin: .round
                    )
                )
                .rotationEffect(.degrees(-90))
        }
    }
}