ios vpn app

This commit is contained in:
kulikov0 committed 2026-09-03 14:35:47 +02:00
1 parent 96f16399d7
commit 1b506b9ee7
48 files changed
+4934 -45

No files matched your search

@@ -0,0 +1,64 @@
import SwiftUI
struct CallRow: View {
let call: CallConfig
let active: Bool
let phase: ConnectionPhase
let onTap: () -> Void
let onLong: () -> Void
var body: some View {
HStack(spacing: 12) {
Circle().fill(dotColor).frame(width: 6, height: 6)
Text(call.glyph)
.font(Mono.bold(12))
.foregroundStyle(active ? .white : Palette.ink2)
.frame(width: 40, height: 40)
.background(
RoundedRectangle(cornerRadius: 11, style: .continuous)
.fill(active ? Palette.accent : Palette.surface)
)
.overlay(
RoundedRectangle(cornerRadius: 11, style: .continuous)
.stroke(Palette.hair, lineWidth: 1)
)
VStack(alignment: .leading, spacing: 2) {
Text(call.name)
.font(.system(size: 14, weight: .bold))
.foregroundStyle(Palette.ink)
.lineLimit(1)
Text(call.url)
.font(Mono.label(11))
.foregroundStyle(Palette.ink3)
.lineLimit(1)
}
Spacer(minLength: 8)
}
.padding(.horizontal, 14)
.padding(.vertical, 12)
.frame(maxWidth: .infinity)
.background(
RoundedRectangle(cornerRadius: 16, style: .continuous)
.fill(active ? Palette.accentSoft : Palette.panel2)
)
.overlay(
RoundedRectangle(cornerRadius: 16, style: .continuous)
.stroke(active ? Palette.accent.opacity(0.4) : Palette.hair, lineWidth: 1)
)
.contentShape(Rectangle())
.onTapGesture { onTap() }
.onLongPressGesture(minimumDuration: 0.4) { onLong() }
}
private var dotColor: Color {
guard active else { return Palette.ink3 }
switch phase {
case .connected: return Palette.accent
case .connecting: return Palette.warn
default: return Palette.ink2
}
}
}
@@ -0,0 +1,57 @@
import SwiftUI
import WebKit
struct CaptchaWebView: UIViewRepresentable {
let url: URL
func makeUIView(context: Context) -> WKWebView {
let webView = WKWebView()
webView.customUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
webView.load(URLRequest(url: url))
return webView
}
func updateUIView(_ uiView: WKWebView, context: Context) {}
}
struct CaptchaScreen: View {
let url: URL
let onClose: () -> Void
var body: some View {
VStack(spacing: 0) {
HStack(spacing: 10) {
Image(systemName: "checkmark.shield")
.font(.system(size: 14))
.foregroundStyle(Palette.accent)
Text(NSLocalizedString("status_solve_captcha", comment: ""))
.font(Mono.label(12))
.foregroundStyle(Palette.ink)
Spacer()
Button(action: onClose) {
Image(systemName: "xmark")
.font(.system(size: 15, weight: .semibold))
.foregroundStyle(Palette.ink2)
.frame(width: 36, height: 36)
.background(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.fill(Palette.panel2)
)
.overlay(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.stroke(Palette.hair, lineWidth: 1)
)
}
.buttonStyle(.plain)
}
.padding(.horizontal, 16)
.padding(.vertical, 12)
Rectangle().fill(Palette.hair).frame(height: 1)
CaptchaWebView(url: url)
.ignoresSafeArea(edges: .bottom)
}
.background(Palette.surface.ignoresSafeArea())
}
}
@@ -0,0 +1,269 @@
import SwiftUI
private func clampedInt(_ text: String, lo: Int, hi: Int, fallback: Int) -> Int {
guard let value = Int(text.trimmingCharacters(in: .whitespaces)) else { return fallback }
return min(max(value, lo), hi)
}
struct AddDestinationSheet: View {
@ObservedObject var appState: AppState
@State private var name: String
@State private var link: String
@State private var pasteFlashed = false
@Environment(\.dismiss) private var dismiss
init(appState: AppState, prefillUrl: String = "") {
self.appState = appState
let url = prefillUrl.trimmingCharacters(in: .whitespacesAndNewlines)
_link = State(initialValue: url)
_name = State(initialValue: url.isEmpty ? "" : CallPlatform.detect(url: url).suggestedName)
}
var body: some View {
SheetScaffold {
SheetHeader(title: NSLocalizedString("sheet_new_title", comment: ""),
sub: NSLocalizedString("sheet_new_sub", comment: ""))
FieldBlock(label: NSLocalizedString("sheet_field_name", comment: "")) {
SheetField(placeholder: NSLocalizedString("sheet_field_name_hint", comment: ""), text: $name)
}
FieldBlock(label: NSLocalizedString("sheet_field_link", comment: "")) {
SheetField(placeholder: NSLocalizedString("sheet_field_link_hint", comment: ""),
text: $link, mono: true, keyboard: .URL)
}
Button(action: pasteFromClipboard) {
HStack(spacing: 8) {
Image(systemName: "doc.on.clipboard").font(.system(size: 13))
Text(NSLocalizedString("paste_from_clipboard", comment: ""))
.font(.system(size: 13, weight: .semibold))
}
.foregroundStyle(pasteFlashed ? Palette.accent : Palette.ink2)
.padding(.vertical, 10)
.padding(.horizontal, 14)
.overlay(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.stroke(pasteFlashed ? Palette.accent : Palette.hairStrong, lineWidth: 1)
)
}
.buttonStyle(.plain)
SheetFooter(saveTitle: NSLocalizedString("sheet_save", comment: ""),
destructive: false,
onCancel: { dismiss() },
onSave: save)
}
}
private func save() {
let trimmedLink = link.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmedLink.isEmpty else { return }
appState.addCall(name: name, url: trimmedLink)
dismiss()
}
private func pasteFromClipboard() {
guard let clip = UIPasteboard.general.string?.trimmingCharacters(in: .whitespacesAndNewlines), !clip.isEmpty else { return }
link = clip
if name.trimmingCharacters(in: .whitespaces).isEmpty {
name = CallPlatform.detect(url: clip).suggestedName
}
withAnimation(.easeOut(duration: 0.32)) { pasteFlashed = true }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.32) {
withAnimation { pasteFlashed = false }
}
}
}
struct Vp8Sheet: View {
let onSave: (Int, Int, Bool, Bool) -> Void
@State private var fps: String
@State private var batch: String
@State private var dualTrack: Bool
@State private var reliable: Bool
@Environment(\.dismiss) private var dismiss
init(fps: Int, batch: Int, dualTrack: Bool, reliable: Bool, onSave: @escaping (Int, Int, Bool, Bool) -> Void) {
self.onSave = onSave
_fps = State(initialValue: String(fps))
_batch = State(initialValue: String(batch))
_dualTrack = State(initialValue: dualTrack)
_reliable = State(initialValue: reliable)
}
var body: some View {
SheetScaffold {
SheetHeader(title: NSLocalizedString("vp8_settings_title", comment: ""),
sub: NSLocalizedString("vp8_settings_sub", comment: ""))
HStack(spacing: 12) {
FieldBlock(label: NSLocalizedString("vp8_fps_label", comment: "")) {
SheetField(text: $fps, keyboard: .numberPad)
}
FieldBlock(label: NSLocalizedString("vp8_batch_label", comment: "")) {
SheetField(text: $batch, keyboard: .numberPad)
}
}
SheetToggleRow(title: NSLocalizedString("vp8_dual_track_title", comment: ""),
sub: NSLocalizedString("vp8_dual_track_sub", comment: ""), isOn: $dualTrack)
SheetToggleRow(title: NSLocalizedString("vp8_reliable_title", comment: ""),
sub: NSLocalizedString("vp8_reliable_sub", comment: ""), isOn: $reliable)
SheetFooter(onCancel: { dismiss() }, onSave: {
onSave(clampedInt(fps, lo: 1, hi: 240, fallback: Defaults.vp8Fps),
clampedInt(batch, lo: 1, hi: 256, fallback: Defaults.vp8Batch),
dualTrack, reliable)
dismiss()
})
}
}
}
struct DnsSheet: View {
@ObservedObject var appState: AppState
@State private var mode: DnsMode
@State private var primary: String
@State private var secondary: String
@Environment(\.dismiss) private var dismiss
init(appState: AppState) {
self.appState = appState
_mode = State(initialValue: appState.dnsMode)
_primary = State(initialValue: appState.dnsPrimary)
_secondary = State(initialValue: appState.dnsSecondary)
}
var body: some View {
SheetScaffold {
SheetHeader(title: NSLocalizedString("dns_settings_title", comment: ""),
sub: NSLocalizedString("dns_sub", comment: ""))
VStack(spacing: 8) {
ForEach(DnsMode.allCases) { option in
OptionRow(title: option.label, selected: option == mode) { mode = option }
}
}
if mode == .custom {
FieldBlock(label: NSLocalizedString("dns_primary_label", comment: "")) {
SheetField(placeholder: VpnConfig.dnsPrimary, text: $primary, mono: true, keyboard: .numbersAndPunctuation)
}
FieldBlock(label: NSLocalizedString("dns_secondary_label", comment: "")) {
SheetField(placeholder: VpnConfig.dnsSecondary, text: $secondary, mono: true, keyboard: .numbersAndPunctuation)
}
}
SheetFooter(onCancel: { dismiss() }, onSave: {
appState.dnsMode = mode
appState.dnsPrimary = primary.trimmingCharacters(in: .whitespaces)
appState.dnsSecondary = secondary.trimmingCharacters(in: .whitespaces)
dismiss()
})
}
}
}
struct ProxySheet: View {
@ObservedObject var appState: AppState
@State private var port: String
@State private var authMode: SocksAuthMode
@State private var user: String
@State private var pass: String
@Environment(\.dismiss) private var dismiss
init(appState: AppState) {
self.appState = appState
_port = State(initialValue: String(appState.socksPort))
_authMode = State(initialValue: appState.socksAuthMode)
_user = State(initialValue: appState.manualSocksUser)
_pass = State(initialValue: appState.manualSocksPass)
}
var body: some View {
SheetScaffold {
SheetHeader(title: NSLocalizedString("proxy_settings_title", comment: ""),
sub: NSLocalizedString("proxy_sub", comment: ""))
FieldBlock(label: NSLocalizedString("proxy_port_field_label", comment: "")) {
SheetField(text: $port, keyboard: .numberPad)
}
FieldBlock(label: NSLocalizedString("proxy_auth_field_label", comment: "")) {
VStack(spacing: 8) {
ForEach(SocksAuthMode.allCases) { option in
OptionRow(title: option.label, sub: option.sub, selected: option == authMode) { authMode = option }
}
}
}
if authMode == .manual {
FieldBlock(label: NSLocalizedString("proxy_user_field_label", comment: "")) {
SheetField(placeholder: NSLocalizedString("proxy_username_hint", comment: ""), text: $user)
}
FieldBlock(label: NSLocalizedString("proxy_pass_field_label", comment: "")) {
SheetField(placeholder: NSLocalizedString("proxy_password_hint", comment: ""), text: $pass, secure: true)
}
}
SheetFooter(onCancel: { dismiss() }, onSave: {
appState.socksPort = clampedInt(port, lo: 1, hi: 65535, fallback: VpnConfig.defaultSocksPort)
appState.socksAuthMode = authMode
appState.manualSocksUser = user
appState.manualSocksPass = pass
dismiss()
})
}
}
}
struct AutofillSheet: View {
@ObservedObject var appState: AppState
@State private var enabled: Bool
@State private var name: String
@Environment(\.dismiss) private var dismiss
init(appState: AppState) {
self.appState = appState
_enabled = State(initialValue: appState.autofillEnabled)
_name = State(initialValue: appState.autofillName)
}
var body: some View {
SheetScaffold {
SheetHeader(title: NSLocalizedString("autofill_settings_title", comment: ""),
sub: NSLocalizedString("autofill_settings_sub", comment: ""))
SheetToggleRow(title: NSLocalizedString("autofill_enable_title", comment: ""),
sub: NSLocalizedString("autofill_enable_sub", comment: ""), isOn: $enabled)
FieldBlock(label: NSLocalizedString("autofill_name_field_label", comment: "")) {
HStack(spacing: 8) {
SheetField(placeholder: NSLocalizedString("autofill_name_input_hint", comment: ""), text: $name)
Button {
name = RandomNames.pool.randomElement() ?? Defaults.autofillName
} label: {
Text(NSLocalizedString("autofill_generate_random", comment: ""))
.font(.system(size: 13, weight: .semibold))
.foregroundStyle(Palette.accent)
.padding(.vertical, 12)
.padding(.horizontal, 14)
.overlay(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.stroke(Palette.hairStrong, lineWidth: 1)
)
}
.buttonStyle(.plain)
}
}
SheetFooter(onCancel: { dismiss() }, onSave: {
appState.autofillEnabled = enabled
let trimmed = name.trimmingCharacters(in: .whitespaces)
appState.autofillName = trimmed.isEmpty ? Defaults.autofillName : trimmed
dismiss()
})
}
}
}
@@ -0,0 +1,148 @@
import SwiftUI
struct HeroRing: View {
let phase: ConnectionPhase
@State private var pulsing = false
private var active: Bool { phase == .connecting || phase == .connected }
private var spinDuration: Double { phase == .connected ? 18 : 6 }
var body: some View {
ZStack {
if active {
TimelineView(.animation) { timeline in
Circle()
.fill(sweepGradient)
.frame(width: 224, height: 224)
.rotationEffect(.degrees(spinAngle(at: timeline.date)))
.blur(radius: phase == .connected ? 6 : 4)
.opacity(phase == .connected ? 0.9 : 0.85)
}
}
Circle()
.fill(Palette.panel2)
.overlay(Circle().stroke(Palette.hair, lineWidth: 1))
.frame(width: 192, height: 192)
Circle()
.stroke(active ? Palette.accentSoft : Palette.hairStrong,
style: StrokeStyle(lineWidth: 1, dash: [4, 3]))
.frame(width: 220, height: 220)
if phase == .connecting {
Circle()
.fill(Palette.accentSoft)
.frame(width: 168, height: 168)
.scaleEffect(pulsing ? 1.18 : 1.0)
.opacity(pulsing ? 0.0 : 0.7)
}
button
}
.frame(width: 248, height: 248)
.onAppear { syncPulse() }
.onDisappear { stopPulse() }
.onChange(of: phase) { _ in syncPulse() }
}
private func spinAngle(at date: Date) -> Double {
(date.timeIntervalSinceReferenceDate / spinDuration).truncatingRemainder(dividingBy: 1) * 360
}
private var sweepGradient: AngularGradient {
switch phase {
case .connected:
return AngularGradient(
gradient: Gradient(stops: [
.init(color: .clear, location: 0),
.init(color: Palette.accent, location: 0.3),
.init(color: Palette.accent, location: 0.7),
.init(color: .clear, location: 1),
]),
center: .center
)
default:
return AngularGradient(
gradient: Gradient(stops: [
.init(color: .clear, location: 0),
.init(color: Palette.accentSoft, location: 0.35),
.init(color: .clear, location: 0.6),
.init(color: .clear, location: 1),
]),
center: .center
)
}
}
private func syncPulse() {
if phase == .connecting {
startPulse()
} else {
stopPulse()
}
}
private func startPulse() {
pulsing = false
withAnimation(.easeOut(duration: 1.6).repeatForever(autoreverses: false)) {
pulsing = true
}
}
private func stopPulse() {
withAnimation(.linear(duration: 0)) {
pulsing = false
}
}
@ViewBuilder
private var button: some View {
ZStack {
switch phase {
case .connected:
Circle().fill(Palette.accentSoft).frame(width: 168, height: 168)
Circle().fill(Palette.accent).frame(width: 152, height: 152)
case .connecting:
Circle().fill(Palette.accentSoft).frame(width: 168, height: 168)
Circle()
.fill(Palette.panel)
.overlay(Circle().stroke(Palette.accent, lineWidth: 1))
.frame(width: 156, height: 156)
case .disconnected, .failed:
Circle()
.fill(Palette.panel)
.overlay(Circle().stroke(Palette.hairStrong, lineWidth: 1))
.frame(width: 168, height: 168)
}
VStack(spacing: 12) {
Image(systemName: "power")
.font(.system(size: 40, weight: .regular))
Text(buttonLabel.uppercased())
.font(Mono.label(11))
.tracking(2.4)
}
.foregroundStyle(labelColor)
}
.frame(width: 168, height: 168)
.contentShape(Circle())
}
private var buttonLabel: String {
switch phase {
case .connected: return NSLocalizedString("btn_disconnect", comment: "")
case .connecting: return NSLocalizedString("btn_cancel", comment: "")
case .disconnected, .failed: return NSLocalizedString("btn_connect", comment: "")
}
}
private var labelColor: Color {
switch phase {
case .connected: return Palette.panel
case .connecting: return Palette.accent
case .disconnected, .failed: return Palette.ink3
}
}
}
@@ -0,0 +1,176 @@
import SwiftUI
import AVFoundation
extension View {
func dismissKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
struct QRScannerSheet: View {
let onResult: (String) -> Void
@Environment(\.dismiss) private var dismiss
@State private var status = AVCaptureDevice.authorizationStatus(for: .video)
var body: some View {
ZStack {
Color.black.ignoresSafeArea()
switch status {
case .authorized:
camera
viewfinder
case .notDetermined:
ProgressView()
.tint(.white)
.onAppear(perform: requestAccess)
default:
denied
}
VStack {
HStack {
Spacer()
Button { dismiss() } label: {
Image(systemName: "xmark")
.font(.system(size: 15, weight: .semibold))
.foregroundStyle(.white)
.frame(width: 40, height: 40)
.background(Circle().fill(.black.opacity(0.4)))
}
}
Spacer()
}
.padding(20)
}
}
private var camera: some View {
QRCameraView { value in
let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty else { return }
onResult(trimmed)
dismiss()
}
.ignoresSafeArea()
}
private var viewfinder: some View {
VStack(spacing: 20) {
RoundedRectangle(cornerRadius: 24, style: .continuous)
.stroke(Palette.accent, lineWidth: 3)
.frame(width: 240, height: 240)
.shadow(color: .black.opacity(0.35), radius: 12)
Text(NSLocalizedString("qr_prompt", comment: ""))
.font(Mono.label(12))
.foregroundStyle(.white)
}
}
private var denied: some View {
VStack(spacing: 16) {
Image(systemName: "camera.metering.none")
.font(.system(size: 36))
.foregroundStyle(.white.opacity(0.7))
Text(NSLocalizedString("qr_denied_title", comment: ""))
.font(.system(size: 15, weight: .semibold))
.foregroundStyle(.white)
Text(NSLocalizedString("qr_denied_sub", comment: ""))
.font(.system(size: 13))
.foregroundStyle(.white.opacity(0.6))
.multilineTextAlignment(.center)
Button(NSLocalizedString("qr_open_settings", comment: "")) {
if let url = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(url)
}
}
.font(.system(size: 13, weight: .semibold))
.foregroundStyle(Palette.accent)
}
.padding(32)
}
private func requestAccess() {
AVCaptureDevice.requestAccess(for: .video) { granted in
DispatchQueue.main.async {
status = granted ? .authorized : .denied
}
}
}
}
struct QRCameraView: UIViewControllerRepresentable {
let onFound: (String) -> Void
func makeUIViewController(context: Context) -> QRCameraController {
let controller = QRCameraController()
controller.onFound = onFound
return controller
}
func updateUIViewController(_ uiViewController: QRCameraController, context: Context) {}
}
final class QRCameraController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
var onFound: ((String) -> Void)?
private let session = AVCaptureSession()
private let sessionQueue = DispatchQueue(label: "qr.session")
private var previewLayer: AVCaptureVideoPreviewLayer?
private var handled = false
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .black
configureSession()
}
private func configureSession() {
guard let device = AVCaptureDevice.default(for: .video),
let input = try? AVCaptureDeviceInput(device: device),
session.canAddInput(input) else { return }
session.addInput(input)
let output = AVCaptureMetadataOutput()
guard session.canAddOutput(output) else { return }
session.addOutput(output)
output.setMetadataObjectsDelegate(self, queue: .main)
output.metadataObjectTypes = [.qr]
let layer = AVCaptureVideoPreviewLayer(session: session)
layer.videoGravity = .resizeAspectFill
layer.frame = view.layer.bounds
view.layer.addSublayer(layer)
previewLayer = layer
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
sessionQueue.async { [weak self] in
guard let self, !self.session.isRunning else { return }
self.session.startRunning()
}
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
previewLayer?.frame = view.layer.bounds
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
sessionQueue.async { [weak self] in
guard let self, self.session.isRunning else { return }
self.session.stopRunning()
}
}
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
guard !handled,
let object = metadataObjects.first as? AVMetadataMachineReadableCodeObject,
let value = object.stringValue else { return }
handled = true
UINotificationFeedbackGenerator().notificationOccurred(.success)
onFound?(value)
}
}
@@ -0,0 +1,358 @@
import SwiftUI
struct SheetScaffold<Content: View>: View {
@ViewBuilder var content: Content
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 16) {
content
}
.padding(20)
}
.scrollDismissesKeyboard(.interactively)
.background(Palette.surface.ignoresSafeArea())
.toolbar {
ToolbarItemGroup(placement: .keyboard) {
Spacer()
Button(NSLocalizedString("btn_done", comment: "")) { dismissKeyboard() }
.font(.system(size: 14, weight: .semibold))
.foregroundStyle(Palette.accent)
}
}
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
}
}
struct SheetHeader: View {
let title: String
var sub: String? = nil
var destructive: Bool = false
var body: some View {
VStack(alignment: .leading, spacing: 6) {
Text(title)
.font(.system(size: 19, weight: .bold))
.foregroundStyle(destructive ? Palette.accent : Palette.ink)
if let sub {
Text(sub)
.font(.system(size: 13))
.foregroundStyle(Palette.ink3)
.fixedSize(horizontal: false, vertical: true)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
}
}
struct SheetFooter: View {
var cancelTitle: String = NSLocalizedString("sheet_cancel", comment: "")
var saveTitle: String = NSLocalizedString("sheet_save_short", comment: "")
var destructive: Bool = false
let onCancel: () -> Void
let onSave: () -> Void
var body: some View {
HStack(spacing: 10) {
Button(action: onCancel) {
Text(cancelTitle)
.font(.system(size: 14, weight: .semibold))
.foregroundStyle(Palette.ink2)
.frame(maxWidth: .infinity)
.padding(.vertical, 13)
.overlay(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.stroke(Palette.hairStrong, lineWidth: 1)
)
}
.buttonStyle(.plain)
Button(action: onSave) {
Text(saveTitle)
.font(.system(size: 14, weight: .semibold))
.foregroundStyle(.white)
.frame(maxWidth: .infinity)
.padding(.vertical, 13)
.background(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.fill(destructive ? Palette.error : Palette.accent)
)
}
.buttonStyle(.plain)
}
.padding(.top, 4)
}
}
struct FieldBlock<Content: View>: View {
let label: String
@ViewBuilder var content: Content
var body: some View {
VStack(alignment: .leading, spacing: 6) {
Text(label.uppercased())
.font(Mono.label(10))
.tracking(1.2)
.foregroundStyle(Palette.ink3)
content
}
}
}
struct SheetField: View {
var placeholder: String = ""
@Binding var text: String
var mono: Bool = false
var keyboard: UIKeyboardType = .default
var secure: Bool = false
var body: some View {
Group {
if secure {
SecureField(placeholder, text: $text)
} else {
TextField(placeholder, text: $text)
}
}
.font(mono ? Mono.label(13) : .system(size: 14))
.foregroundStyle(Palette.ink)
.keyboardType(keyboard)
.autocorrectionDisabled(true)
.textInputAutocapitalization(.never)
.padding(12)
.background(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.fill(Palette.panel2)
)
.overlay(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.stroke(Palette.hair, lineWidth: 1)
)
}
}
struct OptionRow: View {
let title: String
var sub: String? = nil
let selected: Bool
var danger: Bool = false
var trailingValue: String? = nil
let action: () -> Void
var body: some View {
Button(action: action) {
HStack(spacing: 12) {
VStack(alignment: .leading, spacing: 2) {
Text(title)
.font(.system(size: 14, weight: .semibold))
.foregroundStyle(danger ? Palette.error : Palette.ink)
if let sub {
Text(sub)
.font(.system(size: 11))
.foregroundStyle(Palette.ink3)
.fixedSize(horizontal: false, vertical: true)
}
}
Spacer(minLength: 8)
if let trailingValue {
Text(trailingValue)
.font(Mono.label(11))
.foregroundStyle(Palette.ink3)
}
if selected {
Image(systemName: "checkmark")
.font(.system(size: 13, weight: .bold))
.foregroundStyle(Palette.accent)
}
}
.padding(.vertical, 12)
.padding(.horizontal, 14)
.frame(maxWidth: .infinity)
.background(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.fill(selected ? Palette.accentSoft : Palette.panel2)
)
.overlay(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.stroke(selected ? Palette.accent.opacity(0.4) : Palette.hair, lineWidth: 1)
)
}
.buttonStyle(.plain)
}
}
struct ChoiceOption: Identifiable {
let id: String
let title: String
var sub: String? = nil
}
struct ChoiceSheet: View {
let title: String
var sub: String? = nil
let options: [ChoiceOption]
let selectedId: String
let onSelect: (String) -> Void
@Environment(\.dismiss) private var dismiss
var body: some View {
SheetScaffold {
SheetHeader(title: title, sub: sub)
VStack(spacing: 8) {
ForEach(options) { option in
OptionRow(title: option.title, sub: option.sub, selected: option.id == selectedId) {
onSelect(option.id)
dismiss()
}
}
}
}
}
}
struct ConfirmSheet: View {
let title: String
var sub: String? = nil
var confirmTitle: String
var destructive: Bool = true
let onConfirm: () -> Void
@Environment(\.dismiss) private var dismiss
var body: some View {
SheetScaffold {
SheetHeader(title: title, sub: sub, destructive: destructive)
SheetFooter(saveTitle: confirmTitle, destructive: destructive,
onCancel: { dismiss() },
onSave: { onConfirm(); dismiss() })
}
}
}
struct InputSheet: View {
let title: String
var sub: String? = nil
let fieldLabel: String
let onSave: (String) -> Void
@State private var value: String
@Environment(\.dismiss) private var dismiss
init(title: String, sub: String? = nil, fieldLabel: String, initial: String, onSave: @escaping (String) -> Void) {
self.title = title
self.sub = sub
self.fieldLabel = fieldLabel
self.onSave = onSave
_value = State(initialValue: initial)
}
var body: some View {
SheetScaffold {
SheetHeader(title: title, sub: sub)
FieldBlock(label: fieldLabel) {
SheetField(text: $value)
}
SheetFooter(onCancel: { dismiss() }, onSave: {
let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmed.isEmpty else { return }
onSave(trimmed)
dismiss()
})
}
}
}
struct MenuAction: Identifiable {
let id: String
let title: String
let icon: String
var value: String? = nil
var danger: Bool = false
}
struct MenuSheet: View {
let title: String
var sub: String? = nil
let actions: [MenuAction]
let onSelect: (String) -> Void
@Environment(\.dismiss) private var dismiss
var body: some View {
SheetScaffold {
SheetHeader(title: title, sub: sub)
VStack(spacing: 8) {
ForEach(actions) { action in
Button {
onSelect(action.id)
dismiss()
} label: {
HStack(spacing: 12) {
Image(systemName: action.icon)
.font(.system(size: 14))
.foregroundStyle(action.danger ? Palette.error : Palette.ink2)
.frame(width: 26)
Text(action.title)
.font(.system(size: 14, weight: .semibold))
.foregroundStyle(action.danger ? Palette.error : Palette.ink)
Spacer(minLength: 8)
if let value = action.value {
Text(value)
.font(Mono.label(11))
.foregroundStyle(Palette.ink3)
}
Image(systemName: "chevron.right")
.font(.system(size: 11))
.foregroundStyle(Palette.ink3)
}
.padding(.vertical, 12)
.padding(.horizontal, 14)
.frame(maxWidth: .infinity)
.background(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.fill(Palette.panel2)
)
.overlay(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.stroke(Palette.hair, lineWidth: 1)
)
}
.buttonStyle(.plain)
}
}
}
}
}
struct SheetToggleRow: View {
let title: String
var sub: String? = nil
@Binding var isOn: Bool
var body: some View {
HStack(spacing: 12) {
VStack(alignment: .leading, spacing: 2) {
Text(title)
.font(.system(size: 14, weight: .semibold))
.foregroundStyle(Palette.ink)
if let sub {
Text(sub)
.font(.system(size: 11))
.foregroundStyle(Palette.ink3)
.fixedSize(horizontal: false, vertical: true)
}
}
Spacer(minLength: 8)
Toggle("", isOn: $isOn).labelsHidden().tint(Palette.accent)
}
.padding(.vertical, 12)
.padding(.horizontal, 14)
.frame(maxWidth: .infinity)
.background(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.fill(Palette.panel2)
)
.overlay(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.stroke(Palette.hair, lineWidth: 1)
)
}
}