Add progress for file transfer

This commit is contained in:
Leon Böttger committed 2025-08-16 21:16:08 +02:00
1 parent de0faad177
commit 6d780d7e9c
3 files changed
+116 -12

No files matched your search

+12 -3
View File
@@ -63,6 +63,8 @@ struct DeviceListView: View {
CustomSection(header: "AvailableDevices") {
ForEach(model.foundDevices) { device in
let isSelected = model.selectedDevice == device
SendPickerButton {
HStack(spacing: 12) {
@@ -90,15 +92,20 @@ struct DeviceListView: View {
.fontWeight(.medium)
.foregroundColor(Color.primary)
Text(model.selectedDevice == device ? model.progressState ?? "..." : "Available".localized())
Text(isSelected ? model.progressState ?? "..." : "Available".localized())
.font(.system(size: 12))
.foregroundColor(Color.primary.opacity(0.6))
}
Spacer()
Image(systemName: "chevron.right")
.foregroundColor(Color.primary.opacity(0.6))
if isSelected, let progress = model.progressValue {
PieProgressView(progress: progress, size: 20)
}
else {
Image(systemName: "chevron.right")
.foregroundColor(Color.primary.opacity(0.6))
}
}
.padding(.vertical, 13)
} onResult: { urls, text in
@@ -106,6 +113,8 @@ struct DeviceListView: View {
model.textToSend = text
model.selectDevice(device: device)
}
.animation(.easeInOut, value: model.progressValue)
.animation(.easeInOut, value: isSelected)
}
}
}
+69
View File
@@ -0,0 +1,69 @@
//
// PieProgressView.swift
// QuickDrop
//
// Created by Leon Böttger on 16.08.25.
//
import SwiftUI
struct PieProgressView: View {
let progress: CGFloat // value between 0.0 and 1.0
var size: CGFloat = 25.0
var color: Color? = nil
var body: some View {
let color = color ?? .gray
ZStack {
Circle()
.stroke(lineWidth: size * 0.08)
.foregroundColor(color)
ZStack {
PieSlice(progress: progress)
.fill(color)
.rotationEffect(.degrees(-90)) // Start from the top
}
.overlay (
Image(systemName: "checkmark")
.font(.system(size: 12, weight: .bold))
.foregroundColor(color == .white ? .blue : .white)
.opacity(progress >= 1.0 ? 1.0 : 0.0) // Show checkmark only when complete
)
}
.frame(width: size, height: size)
}
}
struct PieSlice: Shape {
var progress: CGFloat // from 0.0 to 1.0
func path(in rect: CGRect) -> Path {
var path = Path()
let center = CGPoint(x: rect.midX, y: rect.midY)
let radius = rect.width / 2
let endAngle = Angle(degrees: 360 * Double(progress))
path.move(to: center)
path.addArc(center: center,
radius: radius,
startAngle: .degrees(0),
endAngle: endAngle,
clockwise: false)
path.closeSubpath()
return path
}
}
#Preview {
PieProgressView(progress: 0.76)
.padding()
}