mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
[AltWidget] Replaces ProgressRing with SwiftUI.Gauge
This commit is contained in:
committed by
Joseph Mattello
parent
e3c331c911
commit
d7d0a83550
@@ -23,26 +23,27 @@ struct ComplicationView: View
|
||||
|
||||
let progress = Double(daysRemaining) / Double(totalDays)
|
||||
|
||||
ZStack(alignment: .center) {
|
||||
ProgressRing(progress: progress) {
|
||||
if daysRemaining < 0
|
||||
{
|
||||
Text("Expired")
|
||||
.font(.system(size: 10, weight: .bold))
|
||||
}
|
||||
else
|
||||
{
|
||||
VStack(spacing: -1) {
|
||||
Text("\(daysRemaining)")
|
||||
.font(.system(size: 20, weight: .bold, design: .rounded))
|
||||
|
||||
Text(daysRemaining == 1 ? "DAY" : "DAYS")
|
||||
.font(.caption)
|
||||
}
|
||||
.offset(y: -1)
|
||||
Gauge(value: progress) {
|
||||
if daysRemaining < 0
|
||||
{
|
||||
Text("Expired")
|
||||
.font(.system(size: 10, weight: .bold))
|
||||
}
|
||||
else
|
||||
{
|
||||
VStack(spacing: -1) {
|
||||
let fontSize = daysRemaining > 99 ? 18.0 : 20.0
|
||||
Text("\(daysRemaining)")
|
||||
.font(.system(size: fontSize, weight: .bold, design: .rounded))
|
||||
|
||||
Text(daysRemaining == 1 ? "DAY" : "DAYS")
|
||||
.font(.caption)
|
||||
}
|
||||
.fixedSize()
|
||||
.offset(y: -1)
|
||||
}
|
||||
}
|
||||
.gaugeStyle(.accessoryCircularCapacity)
|
||||
.unredacted()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
//
|
||||
// ProgressRing.swift
|
||||
// AltWidgetExtension
|
||||
//
|
||||
// Created by Riley Testut on 8/17/22.
|
||||
// Copyright © 2022 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import WidgetKit
|
||||
|
||||
struct ProgressRing<Content: View>: View
|
||||
{
|
||||
let progress: Double
|
||||
|
||||
private let content: Content
|
||||
|
||||
init(progress: Double, @ViewBuilder content: () -> Content)
|
||||
{
|
||||
self.progress = progress
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ZStack(alignment: .center) {
|
||||
ring(progress: 1.0)
|
||||
.opacity(0.3)
|
||||
|
||||
ring(progress: self.progress)
|
||||
|
||||
content
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func ring(progress: Double) -> some View {
|
||||
let strokeStyle = StrokeStyle(lineWidth: 4.0, lineCap: .round, lineJoin: .round)
|
||||
|
||||
Circle()
|
||||
.inset(by: 2.0)
|
||||
.trim(from: 0.0, to: progress)
|
||||
.rotation(Angle(degrees: -90), anchor: .center)
|
||||
.stroke(style: strokeStyle)
|
||||
}
|
||||
}
|
||||
|
||||
struct ProgressRing_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ProgressRing(progress: 0.5) {
|
||||
EmptyView()
|
||||
}
|
||||
.previewContext(WidgetPreviewContext(family: .systemSmall))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user