Files
sizzletracker-android/ios/app/Host/Screens/Setup/SetupComponents.swift
T
ReactorcoremeltdownandClaude Opus 5 dd04a61e22 0.41.1 (77): cleanup and optimisation round (Android and iOS)
Nothing user-visible changes, except that the Android app is half the size and
both are lighter on the battery.

R8 is on for release builds (21.5 MB -> 10.1 MB); only the two JNI classes are
pinned by name, since the app reflects over nothing of its own, and `make dist`
keeps the mapping beside the APK. The Kotlin DSP that core/ replaced in 0.37.0
was still compiled into every APK with nothing calling it — it moves to the test
source set, where it belongs as the reference the C++ is checked against — and
the golden tests' TestVoice wrappers leave core/src for core/tests/voices, so
neither app compiles them either.

Speed: channel gain, mute/solo and the FX chain are read once per audio block
instead of once per frame in Engine::fillBlock (both platforms, bit-identical —
all 61 reference scenarios still match); the transport pollers idle at 100 ms
(Android) and 10 Hz (iOS) instead of polling flat out while a song is stopped,
woken by any transport call; ProjectIo.save builds into one pre-sized buffer and
a burst of edits is coalesced into one engine sync; the Kotlin grain sources and
factory wavetables are built when their editor opens rather than at launch, where
they duplicated ~6 MB the engine already renders in core/; and Xcode builds the
DSP core at -O2, the level the golden tests measure, not -Os.

Fix: `make lint` failed on a manifest asking for ACCESS_FINE_LOCATION without
ACCESS_COARSE_LOCATION (the BLE MIDI scan on Android 8-11), so `make check`
passes again.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-11-18 10:21:09 +01:00

174 lines
6.1 KiB
Swift

// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
// SPDX-License-Identifier: GPL-3.0-or-later
import SwiftUI
/// Building blocks of the Setup tab, after Android's SettingsScreen: titled cards,
/// buttons, link rows, rows for sections still to come, and the modal dialog.
/// SwiftUI only (the Mac snapshot tool renders them).
enum SetupStyle {
static var danger: Color { Theme.danger }
static let corner: CGFloat = 10
}
/// A titled card for one settings group (Android's SettingsCard).
struct SetupCard<Content: View>: View {
let title: String
var subtitle: String?
var enabled = true
@ViewBuilder let content: () -> Content
var body: some View {
VStack(alignment: .leading, spacing: 10) {
VStack(alignment: .leading, spacing: 3) {
Text(title).font(.system(size: 17, weight: .semibold)).foregroundColor(enabled ? Theme.accent : Theme.dim)
if let s = subtitle { Text(s).font(.system(size: 13)).foregroundColor(Theme.dim) }
}
content()
}
.padding(16)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Theme.surface, in: RoundedRectangle(cornerRadius: SetupStyle.corner))
}
}
/// Filled (primary), outlined or destructive button.
struct SetupButton: View {
enum Kind { case filled, outlined, danger }
let title: String
var icon: String?
var kind: Kind = .outlined
var enabled = true
let action: () -> Void
var body: some View {
Button(action: action) {
HStack(spacing: 6) {
if let icon = icon { Image(systemName: icon).font(.system(size: 13)) }
Text(title).font(.system(size: 15, weight: .medium)).lineLimit(1)
}
.padding(.horizontal, 14).frame(minHeight: 38)
.foregroundColor(foreground)
.background(background, in: Capsule())
.overlay(Capsule().stroke(kind == .outlined ? Theme.grid : Color.clear, lineWidth: 1))
.contentShape(Capsule())
}
.buttonStyle(.plain)
.disabled(!enabled)
.opacity(enabled ? 1 : 0.4)
}
private var foreground: Color {
switch kind {
case .filled: return Theme.background
case .outlined: return Theme.text
case .danger: return .white
}
}
private var background: Color {
switch kind {
case .filled: return Theme.accent
case .outlined: return .clear
case .danger: return SetupStyle.danger
}
}
}
/// Small grey explanatory text under a group of buttons.
struct SetupNote: View {
let text: String
init(_ text: String) { self.text = text }
var body: some View {
Text(text).font(.system(size: 12)).foregroundColor(Theme.dim).fixedSize(horizontal: false, vertical: true)
}
}
struct SetupDivider: View {
var body: some View { Rectangle().fill(Theme.grid.opacity(0.7)).frame(height: 1) }
}
/// A tappable row with a label, a detail line and a chevron (Android's LinkRow and NavCard).
struct SetupRow: View {
let title: String
let detail: String
var icon: String?
var tint: Color = Theme.accent
let action: () -> Void
var body: some View {
Button(action: action) {
HStack(spacing: 12) {
if let icon = icon { Image(systemName: icon).font(.system(size: 17)).foregroundColor(tint).frame(width: 24) }
VStack(alignment: .leading, spacing: 2) {
Text(title).font(.system(size: 16, weight: .medium)).foregroundColor(tint)
Text(detail).font(.system(size: 12)).foregroundColor(Theme.dim).lineLimit(2)
}
Spacer(minLength: 8)
Image(systemName: "chevron.right").font(.system(size: 13, weight: .semibold)).foregroundColor(tint)
}
.padding(.vertical, 8)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
}
}
/// The Setup tab's modal dialogs. iOS 15 alerts can't hold a text field, so the
/// save prompt (and with it every dialog here, for one look) is drawn in SwiftUI.
enum SetupDialog: Identifiable {
case save
case confirmNew
case confirmDelete(String)
case confirmDeleteTheme(String)
case confirmRestore
case message(title: String, text: String)
var id: String {
switch self {
case .save: return "save"
case .confirmNew: return "new"
case .confirmDelete(let n): return "delete:" + n
case .confirmDeleteTheme(let n): return "theme:" + n
case .confirmRestore: return "restore"
case .message(let t, let m): return "msg:" + t + m
}
}
}
/// A dimmed backdrop with a centred card: title, message, optional text field, buttons.
struct SetupDialogView<Field: View>: View {
let title: String
let message: String?
let confirm: String
var destructive = false
var cancel: String? = "Cancel"
var confirmEnabled = true
@ViewBuilder let field: () -> Field
let onConfirm: () -> Void
let onCancel: () -> Void
var body: some View {
ZStack {
Color.black.opacity(0.55).ignoresSafeArea().onTapGesture(perform: onCancel)
VStack(alignment: .leading, spacing: 14) {
Text(title).font(.system(size: 19, weight: .semibold)).foregroundColor(Theme.text)
if let m = message {
Text(m).font(.system(size: 14)).foregroundColor(Theme.dim).fixedSize(horizontal: false, vertical: true)
}
field()
HStack(spacing: 10) {
Spacer()
if let c = cancel { SetupButton(title: c, kind: .outlined, action: onCancel) }
SetupButton(title: confirm, kind: destructive ? .danger : .filled, enabled: confirmEnabled, action: onConfirm)
}
}
.padding(20)
.frame(maxWidth: 420)
.background(Theme.surface, in: RoundedRectangle(cornerRadius: 14))
.overlay(RoundedRectangle(cornerRadius: 14).stroke(Theme.grid, lineWidth: 1))
.padding(24)
}
}
}