Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

refactor: add onboarding UI primitives

altic-dev5730bd292433
diff --git a/Sources/Fluid/Theme/AppTheme.swift b/Sources/Fluid/Theme/AppTheme.swift
index 9449a697..e5fab66f 100644
--- a/Sources/Fluid/Theme/AppTheme.swift
+++ b/Sources/Fluid/Theme/AppTheme.swift
@@ -139,11 +139,40 @@ struct AppTheme {
)
}
+ struct OnboardingSurface {
+ let normalFillOpacity: Double
+ let selectedFillOpacity: Double
+ let normalBorderOpacity: Double
+ let selectedBorderOpacity: Double
+ let editorBorderOpacity: Double
+ let editorPadding: CGFloat
+ let optionPadding: CGFloat
+ let compactOptionPadding: CGFloat
+ let optionCornerRadius: CGFloat
+ let compactOptionCornerRadius: CGFloat
+ let editorCornerRadius: CGFloat
+
+ static let standard = OnboardingSurface(
+ normalFillOpacity: 0.55,
+ selectedFillOpacity: 0.82,
+ normalBorderOpacity: 0.32,
+ selectedBorderOpacity: 0.45,
+ editorBorderOpacity: 0.6,
+ editorPadding: 10,
+ optionPadding: 12,
+ compactOptionPadding: 10,
+ optionCornerRadius: 12,
+ compactOptionCornerRadius: 10,
+ editorCornerRadius: 8
+ )
+ }
+
let spacing: Spacing
let corners: CornerRadius
let formRow: FormRow
let pickerControl: PickerControl
let cardSurface: CardSurface
+ let onboardingSurface: OnboardingSurface
let cardShadow: Shadow
let elevatedCardShadow: Shadow
}
@@ -187,6 +216,7 @@ struct AppTheme {
formRow: .standard,
pickerControl: .standard,
cardSurface: .defaults,
+ onboardingSurface: .standard,
cardShadow: .subtle(color: .black, opacity: 0.70),
elevatedCardShadow: .subtle(color: .black, opacity: 0.80)
),
diff --git a/Sources/Fluid/Theme/Components/OnboardingComponents.swift b/Sources/Fluid/Theme/Components/OnboardingComponents.swift
new file mode 100644
index 00000000..44b5d30f
--- /dev/null
+++ b/Sources/Fluid/Theme/Components/OnboardingComponents.swift
@@ -0,0 +1,117 @@
+import SwiftUI
+
+private struct OnboardingSelectableSurfaceModifier: ViewModifier {
+ @Environment(\.theme) private var theme
+ let isSelected: Bool
+ let cornerRadius: CGFloat?
+ let padding: CGFloat?
+ let selectedBorderOpacity: Double?
+
+ func body(content: Content) -> some View {
+ let surface = self.theme.metrics.onboardingSurface
+ let radius = self.cornerRadius ?? surface.optionCornerRadius
+ let shape = RoundedRectangle(cornerRadius: radius, style: .continuous)
+
+ content
+ .padding(self.padding ?? surface.optionPadding)
+ .background(
+ shape
+ .fill(self.theme.palette.cardBackground.opacity(
+ self.isSelected ? surface.selectedFillOpacity : surface.normalFillOpacity
+ ))
+ .overlay(
+ shape.stroke(
+ self.isSelected
+ ? self.theme.palette.accent.opacity(self.selectedBorderOpacity ?? surface.selectedBorderOpacity)
+ : self.theme.palette.cardBorder.opacity(surface.normalBorderOpacity),
+ lineWidth: 1
+ )
+ )
+ )
+ .contentShape(shape)
+ }
+}
+
+private struct OnboardingEditorSurfaceModifier: ViewModifier {
+ @Environment(\.theme) private var theme
+ let cornerRadius: CGFloat?
+
+ func body(content: Content) -> some View {
+ let surface = self.theme.metrics.onboardingSurface
+ let radius = self.cornerRadius ?? surface.editorCornerRadius
+ let shape = RoundedRectangle(cornerRadius: radius, style: .continuous)
+
+ content
+ .padding(surface.editorPadding)
+ .background(
+ shape
+ .fill(self.theme.palette.cardBackground)
+ .overlay(
+ shape.stroke(self.theme.palette.cardBorder.opacity(surface.editorBorderOpacity), lineWidth: 1)
+ )
+ )
+ }
+}
+
+private struct OnboardingProminentButtonModifier: ViewModifier {
+ @Environment(\.theme) private var theme
+ let controlSize: ControlSize?
+
+ @ViewBuilder
+ func body(content: Content) -> some View {
+ if let controlSize {
+ content
+ .buttonStyle(.borderedProminent)
+ .controlSize(controlSize)
+ .tint(self.theme.palette.accent)
+ } else {
+ content
+ .buttonStyle(.borderedProminent)
+ .tint(self.theme.palette.accent)
+ }
+ }
+}
+
+private struct OnboardingSecondaryButtonModifier: ViewModifier {
+ let controlSize: ControlSize?
+
+ @ViewBuilder
+ func body(content: Content) -> some View {
+ if let controlSize {
+ content
+ .buttonStyle(.bordered)
+ .controlSize(controlSize)
+ } else {
+ content
+ .buttonStyle(.bordered)
+ }
+ }
+}
+
+extension View {
+ func fluidOnboardingSelectableSurface(
+ isSelected: Bool,
+ cornerRadius: CGFloat? = nil,
+ padding: CGFloat? = nil,
+ selectedBorderOpacity: Double? = nil
+ ) -> some View {
+ self.modifier(OnboardingSelectableSurfaceModifier(
+ isSelected: isSelected,
+ cornerRadius: cornerRadius,
+ padding: padding,
+ selectedBorderOpacity: selectedBorderOpacity
+ ))
+ }
+
+ func fluidOnboardingEditorSurface(cornerRadius: CGFloat? = nil) -> some View {
+ self.modifier(OnboardingEditorSurfaceModifier(cornerRadius: cornerRadius))
+ }
+
+ func fluidOnboardingProminentButton(controlSize: ControlSize? = nil) -> some View {
+ self.modifier(OnboardingProminentButtonModifier(controlSize: controlSize))
+ }
+
+ func fluidOnboardingSecondaryButton(controlSize: ControlSize? = nil) -> some View {
+ self.modifier(OnboardingSecondaryButtonModifier(controlSize: controlSize))
+ }
+}
diff --git a/Sources/Fluid/UI/WelcomeView.swift b/Sources/Fluid/UI/WelcomeView.swift
index 4d2ed910..492bb23a 100644
--- a/Sources/Fluid/UI/WelcomeView.swift
+++ b/Sources/Fluid/UI/WelcomeView.swift
@@ -1024,8 +1024,7 @@ struct OnboardingFlowView: View {
Button(self.onboardingModelActionButtonTitle(for: self.recommendedOnboardingModel)) {
self.prepareOnboardingModel(self.recommendedOnboardingModel)
}
- .buttonStyle(.borderedProminent)
- .tint(self.theme.palette.accent)
+ .fluidOnboardingProminentButton()
.disabled(self.asr.isRunning || self.isPreparingRecommendedModel || self.isRecommendedModelReady)
}
}
@@ -1081,8 +1080,7 @@ struct OnboardingFlowView: View {
Button(self.microphoneActionButtonTitle) {
self.handleMicrophoneAction()
}
- .buttonStyle(.borderedProminent)
- .tint(self.theme.palette.accent)
+ .fluidOnboardingProminentButton()
}
}
@@ -1132,8 +1130,7 @@ struct OnboardingFlowView: View {
Button("Enable Accessibility") {
self.openAccessibilitySettings()
}
- .buttonStyle(.borderedProminent)
- .tint(self.theme.palette.accent)
+ .fluidOnboardingProminentButton()
}
}
@@ -1153,8 +1150,7 @@ struct OnboardingFlowView: View {
Button("Restart FluidVoice") {
self.restartApp()
}
- .buttonStyle(.bordered)
- .controlSize(.small)
+ .fluidOnboardingSecondaryButton(controlSize: .small)
}
}
.padding(16)
@@ -1216,15 +1212,7 @@ struct OnboardingFlowView: View {
))
.font(.body)
.frame(height: 170)
- .padding(10)
- .background(
- RoundedRectangle(cornerRadius: 8, style: .continuous)
- .fill(self.theme.palette.cardBackground)
- .overlay(
- RoundedRectangle(cornerRadius: 8, style: .continuous)
- .stroke(self.theme.palette.cardBorder.opacity(0.6), lineWidth: 1)
- )
- )
+ .fluidOnboardingEditorSurface()
.scrollContentBackground(.hidden)
if self.isPlaygroundReady {
@@ -1259,7 +1247,7 @@ struct OnboardingFlowView: View {
Button("Back") {
self.goBack()
}
- .buttonStyle(.bordered)
+ .fluidOnboardingSecondaryButton()
}
Spacer()
@@ -1269,14 +1257,13 @@ struct OnboardingFlowView: View {
self.markAISkipped()
self.goNext()
}
- .buttonStyle(.bordered)
+ .fluidOnboardingSecondaryButton()
}
Button(self.primaryButtonTitle) {
self.handlePrimaryAction()
}
- .buttonStyle(.borderedProminent)
- .tint(self.theme.palette.accent)
+ .fluidOnboardingProminentButton()
.disabled(!self.canContinue)
}
.padding(20)
@@ -1386,8 +1373,7 @@ struct OnboardingFlowView: View {
Button(self.onboardingModelActionButtonTitle(for: model)) {
self.prepareOnboardingModel(model, preserveManualChoice: true)
}
- .buttonStyle(.bordered)
- .controlSize(.small)
+ .fluidOnboardingSecondaryButton(controlSize: .small)
.disabled(self.asr.isRunning || isPreparing || isReady)
if isPreparing {
@@ -1422,19 +1408,11 @@ struct OnboardingFlowView: View {
.foregroundStyle(.secondary)
}
}
- .padding(10)
- .background(
- RoundedRectangle(cornerRadius: 10, style: .continuous)
- .fill(self.theme.palette.cardBackground.opacity(isSelected ? 0.82 : 0.55))
- .overlay(
- RoundedRectangle(cornerRadius: 10, style: .continuous)
- .stroke(
- isSelected ? self.theme.palette.accent.opacity(0.45) : self.theme.palette.cardBorder.opacity(0.32),
- lineWidth: 1
- )
- )
+ .fluidOnboardingSelectableSurface(
+ isSelected: isSelected,
+ cornerRadius: self.theme.metrics.onboardingSurface.compactOptionCornerRadius,
+ padding: self.theme.metrics.onboardingSurface.compactOptionPadding
)
- .contentShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
.onTapGesture {
self.selectOnboardingModel(model, preserveManualChoice: true)
}
@@ -1509,26 +1487,12 @@ struct OnboardingFlowView: View {
Button(self.onboardingModelActionButtonTitle(for: model)) {
self.prepareOnboardingModel(model, preserveManualChoice: true)
}
- .buttonStyle(.borderedProminent)
- .controlSize(.small)
- .tint(self.theme.palette.accent)
+ .fluidOnboardingProminentButton(controlSize: .small)
.disabled(self.asr.isRunning || isPreparing || isReady)
}
}
.frame(maxWidth: .infinity, minHeight: 190, alignment: .topLeading)
- .padding(12)
- .background(
- RoundedRectangle(cornerRadius: 12, style: .continuous)
- .fill(self.theme.palette.cardBackground.opacity(isSelected ? 0.82 : 0.55))
- .overlay(
- RoundedRectangle(cornerRadius: 12, style: .continuous)
- .stroke(
- isSelected ? self.theme.palette.accent.opacity(0.45) : self.theme.palette.cardBorder.opacity(0.32),
- lineWidth: 1
- )
- )
- )
- .contentShape(RoundedRectangle(cornerRadius: 12, style: .continuous))
+ .fluidOnboardingSelectableSurface(isSelected: isSelected)
.onTapGesture {
self.selectOnboardingModel(model, preserveManualChoice: true)
}
@@ -1588,18 +1552,7 @@ struct OnboardingFlowView: View {
.multilineTextAlignment(.leading)
}
.frame(maxWidth: .infinity, alignment: .leading)
- .padding(12)
- .background(
- RoundedRectangle(cornerRadius: 12, style: .continuous)
- .fill(self.theme.palette.cardBackground.opacity(isSelected ? 0.82 : 0.55))
- .overlay(
- RoundedRectangle(cornerRadius: 12, style: .continuous)
- .stroke(
- isSelected ? self.theme.palette.accent.opacity(0.55) : self.theme.palette.cardBorder.opacity(0.32),
- lineWidth: 1
- )
- )
- )
+ .fluidOnboardingSelectableSurface(isSelected: isSelected, selectedBorderOpacity: 0.55)
}
.buttonStyle(.plain)
}