hex/ios/HEXMobile/ExperimentsCard.swift
Ryan Vogel 07e9fe309c Add Learn how I type, an on-device typing journal (experiment)
Off by default under Experiments with the full keyboard. Records per-key tap offsets as averages (never a letter sequence) and single-word corrections: retyped words within a small edit distance, autocorrect fixes, undone autocorrect, and picked suggestions, capped at 2,000. Skips URL, email, credential, code, card and phone fields and fields without autocorrect. Stored in the App Group; the app shows the most common fixes and off-centre keys and can delete it all. Personalization from this data is a later step.

Verified the Release build compiles and HEXMobileTests pass on the iPhone 18 Pro simulator; not yet tried on a device.
2026-11-19 16:03:46 -05:00

165 lines
7.1 KiB
Swift

import SwiftUI
/// Unfinished features, off until turned on here. They live in the App Group so the
/// keyboard reads them too.
struct ExperimentsCard: View {
@State private var fullKeyboard = FullKeyboardSettings().isEnabled
@State private var appleIntelligenceCleanup = AppleIntelligenceCleanupSettings().isEnabled
@State private var customVocabulary = CustomVocabularySettings().isEnabled
@State private var cleanupAvailability = AppleIntelligenceCleanupAvailability.current
@State private var autocorrect = FullKeyboardSettings().autocorrect
@State private var learnTyping = TypingJournalSettings().isEnabled
var body: some View {
VStack(alignment: .leading, spacing: 8) {
Text("Experiments")
.font(.system(size: 13, weight: .medium))
.foregroundStyle(HexTheme.textMuted)
.padding(.leading, 16)
VStack(spacing: 0) {
Toggle(isOn: $fullKeyboard) {
VStack(alignment: .leading, spacing: 2) {
Text("Full keyboard")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(HexTheme.textBase)
Text("Type with Hex, with a Hex key to dictate")
.font(.system(size: 12))
.foregroundStyle(HexTheme.textMuted)
}
}
.tint(HexTheme.success)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.onChange(of: fullKeyboard) { _, enabled in
FullKeyboardSettings().isEnabled = enabled
}
if fullKeyboard {
Divider()
.overlay(HexTheme.borderWeak)
.padding(.leading, 16)
Toggle(isOn: $autocorrect) {
VStack(alignment: .leading, spacing: 2) {
Text("Autocorrect")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(HexTheme.textBase)
Text("Fix contractions, shortcuts, and one-edit typos on space")
.font(.system(size: 12))
.foregroundStyle(HexTheme.textMuted)
}
}
.tint(HexTheme.success)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.onChange(of: autocorrect) { _, enabled in
FullKeyboardSettings().autocorrect = enabled
}
Divider()
.overlay(HexTheme.borderWeak)
.padding(.leading, 16)
Toggle(isOn: $learnTyping) {
VStack(alignment: .leading, spacing: 2) {
Text("Learn how I type")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(HexTheme.textBase)
Text("Keeps where you tap and the words you fix on this iPhone, never what you write")
.font(.system(size: 12))
.foregroundStyle(HexTheme.textMuted)
}
}
.tint(HexTheme.success)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.onChange(of: learnTyping) { _, enabled in
TypingJournalSettings().isEnabled = enabled
}
if learnTyping {
TypingInsightsView()
.padding(.horizontal, 16)
.padding(.bottom, 12)
}
}
}
.background(
HexTheme.bgBase,
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
)
.onChange(of: fullKeyboard) { _, enabled in
FullKeyboardSettings().isEnabled = enabled
}
Toggle(isOn: $appleIntelligenceCleanup) {
VStack(alignment: .leading, spacing: 2) {
Text("Clean up with Apple Intelligence")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(HexTheme.textBase)
Text("Fix misheard words and spoken corrections on device")
.font(.system(size: 12))
.foregroundStyle(HexTheme.textMuted)
if let reason = cleanupAvailability.reason {
Text(reason)
.font(.system(size: 12))
.foregroundStyle(HexTheme.textMuted)
}
}
}
.tint(HexTheme.success)
.disabled(!cleanupAvailability.isAvailable)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.background(
HexTheme.bgBase,
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
)
.onChange(of: appleIntelligenceCleanup) { _, enabled in
AppleIntelligenceCleanupSettings().isEnabled = enabled
}
Toggle(isOn: $customVocabulary) {
VStack(alignment: .leading, spacing: 2) {
Text("Custom vocabulary")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(HexTheme.textBase)
Text("Spell names and terms your way")
.font(.system(size: 12))
.foregroundStyle(HexTheme.textMuted)
}
}
.tint(HexTheme.success)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.background(
HexTheme.bgBase,
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
)
.onChange(of: customVocabulary) { _, enabled in
CustomVocabularySettings().isEnabled = enabled
}
if customVocabulary {
CustomVocabularyEditor()
.padding(12)
.background(
HexTheme.bgBase,
in: RoundedRectangle(
cornerRadius: HexTheme.cardRadius,
style: .continuous
)
)
}
}
.onAppear {
fullKeyboard = FullKeyboardSettings().isEnabled
appleIntelligenceCleanup = AppleIntelligenceCleanupSettings().isEnabled
customVocabulary = CustomVocabularySettings().isEnabled
cleanupAvailability = AppleIntelligenceCleanupAvailability.current
autocorrect = FullKeyboardSettings().autocorrect
learnTyping = TypingJournalSettings().isEnabled
}
}
}