hex/ios/HEXMobile/Settings/ExperimentsSettingsPage.swift
Ryan Vogel be66952f64 iOS keyboard: nothing opens Hex unless the person taps Open Hex
A dictation tap (the Hex key, Dictate, the bar's Hex mark, a hold on the
strip, two-thumb Dictate) opened Hex without saying so in four cases on
iOS 26 and later. Ryan asked that nothing in the keyboard takes people to
Hex unless they tapped something that says it will.

- Multilingual model: removed the hand-off. With Experiments › Multilingual
  model on and ready in Hex, every dictation in its 25 languages (English
  included) opened Hex unless the keyboard had the model loaded at that
  moment (any fresh keyboard process, the first compile, Speech model in
  keyboard off, Two-language dictation, a keyboard limit under 131 MB, a
  memory warning). The keyboard now dictates those languages itself, with
  the model once loaded and Apple's speech recognition until then, as
  English already did. Removed KeyboardSelfDictation.Reason.multilingual,
  MultilingualParakeetSettings.keyboardOpensHex and isModelReady (only that
  read it), KeyboardParakeetSettings.keyboardHasMultilingualModel and
  KeyboardParakeet.dictatesMultilingualHere. The Experiments row no longer
  says "Once ready, keyboard dictation opens Hex."
- Speech model missing twice, short of memory, Hex not set up: from iOS 26
  a dictation tap now shows one line saying why ("Download English in Hex
  to dictate", "Not enough memory to dictate here", "Finish setting up Hex
  to dictate") with Open Hex and a ✕, in the bar's top row and the full
  keyboard's strip (KeyboardDictationBlock), for 8 s. Only Open Hex opens
  Hex (to record there, as the tap used to). The second failure to get the
  speech model shows the line by itself; it goes once the keyboard can
  dictate again. The keyboard's error for that case uses the same words.
- With a warm session the bar's Hex mark dictated by opening Hex; it now
  dictates through the warm session as Dictate does, and VoiceOver names it
  for what it does (Dictate, Set up Hex, or before iOS 26 Open Hex). The Hex
  key's VoiceOver label says "Open Hex to dictate" only where it does.
- The translation note: a tap anywhere on it in the bar opened Hex. Now
  only its Open Hex chip opens Hex's Settings, and a ✕ puts it away (both
  keyboards); the strip notice's title shrinks to 0.7 to fit beside the ✕.

Before iOS 26 nothing changes for a dictation tap: KeyboardDictationBlock
.resolve is nil there and the tap opens Hex as before (Ryan decides).

A simulator-only App Group key (simulator.keyboardMemoryShort) stands in
for a keyboard short of memory, for screenshots.

Verified: build for the simulator; DictationSSOTTests, KeyboardBridgeTests,
SpeechModelInstallTests and the changed DictationControllerTests case pass
on basebook's iOS 27.2 simulator (new cases in DictationSSOTTests); every
line, both keyboards, light and dark, English and Chinese, on the real
keyboard in a host app on the simulator; code-shape --check passes.
2026-11-24 09:28:27 -05:00

403 lines
15 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
/// Settings › Experiments: unfinished features grouped by domain (Dictation, Languages,
/// Keyboard layout, Typing), off until turned on. They live in the App Group so the keyboard
/// reads them too.
struct ExperimentsSettingsPage: View {
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@State private var revision = 0
@State private var cleanupAvailability = AppleIntelligenceCleanupAvailability.current
@State private var adaptiveTouchStatus = AdaptiveTouchStatus.sessionOnly
@State private var confirmingTouchReset = false
@State private var multilingualParakeet = MultilingualParakeetSettings().isEnabled
private let multilingualParakeetFits = MultilingualParakeetSettings.fits()
private func toggleBinding(_ get: @escaping () -> Bool, _ set: @escaping (Bool) -> Void) -> Binding<Bool> {
Binding(
get: {
_ = revision
return get()
},
set: { value in
set(value)
revision += 1
}
)
}
private func keyboardBinding(_ keyPath: WritableKeyPath<FullKeyboardSettings, Bool>) -> Binding<Bool> {
toggleBinding(
{ FullKeyboardSettings()[keyPath: keyPath] },
{
var current = FullKeyboardSettings()
current[keyPath: keyPath] = $0
}
)
}
private var adaptiveTouchOn: Bool {
_ = revision
return AdaptiveTouchSettings().isEnabled
}
private var keyboardThemesOn: Bool {
_ = revision
return FullKeyboardSettings().keyboardThemesEnabled
}
private var spatialAutocorrectOn: Bool {
_ = revision
let settings = FullKeyboardSettings()
return settings.autocorrect && settings.spatialAutocorrect
}
var body: some View {
SettingsPageScaffold(title: "Experiments") {
dictationSection
languagesSection
layoutSection
typingSection
// Testers tell the team how an experiment went (absent without a report key).
if Feedback.isAvailable {
SettingsCard {
FeedbackRow(screen: "Settings › Experiments", dictation: DictationController.shared)
}
.padding(.top, 8)
}
}
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: adaptiveTouchOn)
.animation(HexMotion.settleAnimation(reduceMotion: reduceMotion), value: keyboardThemesOn)
.onChange(of: multilingualParakeet) { _, enabled in
guard enabled != MultilingualParakeetSettings().isEnabled else { return }
MultilingualParakeetSettings().isEnabled = enabled
// On: downloads beside the engine that dictates; off: stops and deletes it.
DictationController.shared.multilingualParakeetChanged()
}
.onAppear {
cleanupAvailability = AppleIntelligenceCleanupAvailability.current
multilingualParakeet = MultilingualParakeetSettings().isEnabled
refreshAdaptiveTouchStatus()
revision += 1
}
}
@ViewBuilder
private var dictationSection: some View {
SettingsSectionHeader(title: "Dictation")
SettingsCard {
SettingsToggleRow(
title: String(localized: "Multilingual model (Parakeet)"),
detail: multilingualParakeetFits
? String(localized: "25 languages, even mixed in one sentence. \(ParakeetUltraTranscriber.downloadSize) download.")
: String(localized: "Needs an iPhone with 6 GB of memory or more"),
isOn: $multilingualParakeet
)
.disabled(!multilingualParakeetFits)
if multilingualParakeet {
MultilingualModelStatus(
download: DictationController.shared.multilingualDownload,
retry: { DictationController.shared.retryMultilingualParakeet() },
turnOff: { multilingualParakeet = false }
)
.padding(.horizontal, 12)
.padding(.bottom, 12)
}
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Two-language dictation"),
detail: String(localized: "Checks a second keyboard language and keeps the better match."),
isOn: toggleBinding(
{ TwoLanguageDictationSettings().isEnabled },
{ TwoLanguageDictationSettings().isEnabled = $0 }
)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Voice isolation"),
detail: String(localized: "Records with Apple's voice chat processing so Control Center's Mic Mode can offer Voice Isolation. Other audio may be lowered while recording, and Bluetooth headphones may switch to the call (hands-free) profile."),
isOn: toggleBinding(
{ VoiceIsolationSettings().isEnabled },
{ VoiceIsolationSettings().isEnabled = $0 }
)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Clean up with Apple Intelligence"),
detail: cleanupAvailability.reason ?? String(localized: "Fixes misheard words on device"),
isOn: toggleBinding(
{ AppleIntelligenceCleanupSettings().isEnabled },
{ AppleIntelligenceCleanupSettings().isEnabled = $0 }
)
)
.disabled(!cleanupAvailability.isAvailable)
}
}
@ViewBuilder
private var languagesSection: some View {
SettingsSectionHeader(title: "Languages")
SettingsCard {
SettingsToggleRow(
title: String(localized: "Hinglish (Hindi in Latin letters)"),
detail: String(localized: "Adds Hinglish to dictation languages"),
isOn: toggleBinding(
{ HinglishSettings().isEnabled },
{ HinglishSettings().isEnabled = $0 }
)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Greeklish (Greek in Latin letters)"),
detail: String(localized: "Adds Greeklish to dictation languages"),
isOn: toggleBinding(
{ GreeklishSettings().isEnabled },
{ GreeklishSettings().isEnabled = $0 }
)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Korean keyboard (두벌식)"),
detail: String(localized: "Adds 한국어, composing syllables as you type"),
isOn: keyboardBinding(\.koreanKeyboard)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Swipe typing in more languages"),
detail: String(localized: "French and Polish, and German with German spatial autocorrect"),
isOn: keyboardBinding(\.swipeMoreLanguages)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "German spatial autocorrect"),
detail: String(localized: "Needs Spatial autocorrect"),
isOn: keyboardBinding(\.germanSpatialAutocorrect)
)
.disabled(!spatialAutocorrectOn)
}
}
@ViewBuilder
private var layoutSection: some View {
SettingsSectionHeader(title: "Keyboard layout")
SettingsCard {
SettingsToggleRow(
title: String(localized: "Comma and period keys"),
detail: String(localized: "Puts comma and period keys beside the space bar on the letters keyboard."),
isOn: keyboardBinding(\.commaPeriodKeys)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Dvorak punctuation keys"),
detail: String(localized: "Adds comma, period and semicolon keys to the English Dvorak keyboard."),
isOn: keyboardBinding(\.dvorakPunctuation)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Quick accents"),
detail: String(localized: "Holding a letter selects its main accent, so letting go types it. Slide to pick another."),
isOn: keyboardBinding(\.quickAccents)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "ABC under the emoji key"),
detail: String(localized: "In the emoji panel, ABC takes the emoji key's place"),
isOn: keyboardBinding(\.emojiLettersUnderEmojiKey)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Keyboard themes"),
isOn: keyboardBinding(\.keyboardThemesEnabled)
)
if keyboardThemesOn {
SettingsDivider()
KeyboardThemeRow(
theme: Binding(
get: {
_ = revision
return FullKeyboardSettings().keyboardTheme
},
set: { value in
FullKeyboardSettings().keyboardTheme = value
revision += 1
}
)
)
}
// Only relevant on foldable hardware (iPhone Duo): hide on slab iPhones.
if FullKeyboardView.isFoldable {
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Join the keyboard when unfolded"),
detail: String(localized: "On the iPhone Duo unfolded, keeps the keys on one keyboard instead of splitting them."),
isOn: keyboardBinding(\.joinsKeyboardWhenUnfolded)
)
}
}
}
@ViewBuilder
private var typingSection: some View {
SettingsSectionHeader(title: "Typing")
SettingsCard {
SettingsToggleRow(
title: String(localized: "Adaptive touch"),
detail: String(localized: "Learns where you tap each key."),
isOn: toggleBinding(
{ AdaptiveTouchSettings().isEnabled },
{ enabled in
AdaptiveTouchSettings().isEnabled = enabled
refreshAdaptiveTouchStatus()
}
)
)
if adaptiveTouchOn {
Text(adaptiveTouchStatusText)
.font(.system(size: 12))
.foregroundStyle(HexTheme.textMuted)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 16)
.padding(.bottom, 10)
.accessibilityIdentifier("adaptive-touch-status")
SettingsDivider()
Button {
confirmingTouchReset = true
} label: {
Text("Reset touch learning")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(HexTheme.danger)
.frame(maxWidth: .infinity, minHeight: 50, alignment: .leading)
.padding(.horizontal, 16)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.confirmationDialog("Reset touch learning?", isPresented: $confirmingTouchReset, titleVisibility: .visible) {
Button("Reset touch learning", role: .destructive) {
AdaptiveTouchSettings().requestReset()
refreshAdaptiveTouchStatus()
}
}
}
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Two-thumb selection"),
detail: String(localized: "On the space bar trackpad, a second thumb selects text"),
isOn: keyboardBinding(\.twoThumbSelection)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Delete swiped words letter by letter"),
isOn: keyboardBinding(\.deletesSwipedWordsLetterByLetter)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Hide word suggestions"),
detail: String(localized: "Autocorrect still works"),
isOn: keyboardBinding(\.hideWordSuggestions)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Emoji shortcodes"),
detail: String(localized: "Type a colon and a name, like :pizza, to pick an emoji."),
isOn: keyboardBinding(\.emojiShortcodes)
)
SettingsDivider()
SettingsToggleRow(
title: String(localized: "Learn each language separately"),
detail: String(localized: "Learned words and fixes stay with their language"),
isOn: toggleBinding(
{ TypingJournalSettings().learnsPerLanguage },
{ TypingJournalSettings().learnsPerLanguage = $0 }
)
)
}
}
private var adaptiveTouchStatusText: String {
switch adaptiveTouchStatus {
case .sessionOnly:
String(localized: "Without Full Access, resets when the keyboard closes")
case .learning(let taps):
String(localized: "Learning: \(taps) of \(AdaptiveTouchModel.activeTaps) taps")
case .active:
String(localized: "Active, using your own key centers")
}
}
private func refreshAdaptiveTouchStatus() {
adaptiveTouchStatus = SettingsSnapshotFixture.adaptiveTouchStatus
?? AdaptiveTouchStatus.current(fullAccessConfirmed: KeyboardBridge().fullAccessSeenAt != nil)
}
}
/// Experiments › Keyboard themes: the theme the full keyboard draws while it's on.
private struct KeyboardThemeRow: View {
@Binding var theme: KeyboardTheme
var body: some View {
HStack(spacing: 12) {
SettingsRowLabel(title: String(localized: "Theme"))
Spacer(minLength: 8)
Menu {
ForEach(KeyboardTheme.allCases, id: \.self) { option in
Button {
theme = option
} label: {
if theme == option {
Label(option.name, systemImage: "checkmark")
} else {
Text(option.name)
}
}
}
} label: {
SettingsMenuValue(value: theme.name)
}
}
.padding(.horizontal, 16)
.frame(minHeight: 50)
}
}