hex/ios/HEXMobile/ExperimentsCard.swift
Ryan Vogel ea4651e112 iOS: emoji panel for the full keyboard (Experiments › Emoji)
What changed
- Experiments › Full keyboard › Emoji (experiments.emoji, off by default; shown with the
  full keyboard): an emoji key (face.smiling) right of 123, after the globe, in plain
  text fields (not URL, email or ASCII-only ones). The bottom row takes the compact
  sizes it uses beside the globe. "Clear emoji history" empties EmojiUsageStore.
- EmojiPanelView replaces the strip and the keys: a row of up to ten suggestions for
  the text before the cursor and your history (one emoji per family, your skin tone),
  a search button; a grid that scrolls sideways through Frequently used (your history,
  then everyday emoji, 16 at least) and the eight categories in four rows of 42 pt
  (three of 38 in landscape), each section's name kept at the left edge while it
  scrolls; a bar with ABC, the categories and a repeating delete, drawn like the
  letter keys' 123 and delete. Holding an emoji with skin tones opens the accent
  picker with its five tones; the pick is typed and remembered for that emoji. Key
  pop-ups and haptics follow their switches.
- Search: the letter keys type into a search field in the strip (EmojiRoutedTarget),
  results above it in a row the keyboard grows 44 pt for, your suggestions while it's
  empty; return, the field's close button or the emoji key go back to the panel.
  Typing logs and Learn how I type see the emoji typed into the field, never the query.
- The strip, when it would be empty after a space, offers the finished word's strong
  emoji ("pizza " -> 🍕, "birthday " -> 🎂 🎉 🥳), a lone one in the centre slot; never
  over word suggestions, Undo dictation, a status or the clipboard chips.
- Grid cells drop their text (and bitmap) when they scroll off and prefetching is off:
  scrolling every section had kept 353 cell bitmaps, 35 MB.
- FullKeyboardView+Emoji.swift holds the wiring; the engine's target is now the routed
  target, which forwards everything to the field unless a search is open.
- Scenes: full-keyboard-emoji, -emoji-search (--emoji-query), -emoji-tones,
  -emoji-food, -emoji-strip (each -dark and -dark-field), and -emoji-probe, which prints
  the panel's footprint and open latency.

Measured in the keyboard extension (Release, iPhone 17 simulator, iOS 27.2, a field
focused with the real HEXKeyboard.appex and a temporary, uncommitted probe; the
simulator counts no GPU memory and reports no headroom), footprint:
  keyboard with the emoji key, nothing loaded   19.0 MB
  after "pizza " (the strip loads the index)    19.0 MB
  panel open                                     28.7 MB
  picked three suggestions, closed               22.7 MB
  every section scrolled                         41.6 MB (peak 48.4; 71.1 before the cell fix)
  closed after that                              36.5 MB
The 17.5 MB left after browsing everything is about 351 emoji glyph images the system's
text rendering caches process-wide (18.7 MB in the heap, 351 CGImages); drawing with a
font instance the panel owns or at 21 pt left it the same, and no public API frees it.
Whether iOS purges it under memory pressure is unverified on an iPhone.
Opening: 22-26 ms from the emoji key to the panel laid out the first time, 12-14 ms
after (median of 10), about 21 ms until committed.

Verified: xcodebuild test (245 tests, 1 skipped, 0 failures); every scene above in
light, dark and dark field looked at on the simulator.
2026-11-20 10:49:41 -05:00

339 lines
15 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 cleanupTagger = CleanupTaggerSettings().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 keyPopups = FullKeyboardSettings().keyPopups
@State private var haptics = FullKeyboardSettings().haptics
@State private var emoji = FullKeyboardSettings().emoji
@State private var emojiHistoryEmpty = EmojiUsageStore().isEmpty
@State private var learnTyping = TypingJournalSettings().isEnabled
@State private var typingLogs = TypingLogSettings().isEnabled
@State private var showTypingLogs = false
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: $keyPopups) {
VStack(alignment: .leading, spacing: 2) {
Text("Key pop-ups")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(HexTheme.textBase)
Text("Show a bigger letter above the key you press")
.font(.system(size: 12))
.foregroundStyle(HexTheme.textMuted)
}
}
.tint(HexTheme.success)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.onChange(of: keyPopups) { _, enabled in
FullKeyboardSettings().keyPopups = enabled
}
KeyboardLayoutRow()
Divider()
.overlay(HexTheme.borderWeak)
.padding(.leading, 16)
Toggle(isOn: $emoji) {
VStack(alignment: .leading, spacing: 2) {
Text("Emoji")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(HexTheme.textBase)
Text("An emoji key that suggests emoji for what you type, from the ones you use, on this iPhone")
.font(.system(size: 12))
.foregroundStyle(HexTheme.textMuted)
}
}
.tint(HexTheme.success)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.onChange(of: emoji) { _, enabled in
FullKeyboardSettings().emoji = enabled
}
if emoji {
Button {
EmojiUsageStore().clear()
emojiHistoryEmpty = true
} label: {
HStack {
Text("Clear emoji history")
.font(.system(size: 13, weight: .medium))
.foregroundStyle(emojiHistoryEmpty ? HexTheme.textMuted : HexTheme.textBase)
Spacer()
}
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.disabled(emojiHistoryEmpty)
.padding(.horizontal, 16)
.padding(.bottom, 12)
}
}
Divider()
.overlay(HexTheme.borderWeak)
.padding(.leading, 16)
// Both keyboards: the full keyboard's keys and the dictation bar's.
Toggle(isOn: $haptics) {
VStack(alignment: .leading, spacing: 2) {
Text("Haptics")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(HexTheme.textBase)
Text("A light tap under your finger as you press Hex's keys")
.font(.system(size: 12))
.foregroundStyle(HexTheme.textMuted)
}
}
.tint(HexTheme.success)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.onChange(of: haptics) { _, enabled in
FullKeyboardSettings().haptics = enabled
}
Divider()
.overlay(HexTheme.borderWeak)
.padding(.leading, 16)
// Not only for the full keyboard: it also learns from dictations the
// dictation bar inserts.
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, typed or dictated, 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)
}
Divider()
.overlay(HexTheme.borderWeak)
.padding(.leading, 16)
// Apart from Learn how I type: this keeps everything, to export and train on.
Toggle(isOn: $typingLogs) {
VStack(alignment: .leading, spacing: 2) {
Text("Record typing logs")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(HexTheme.textBase)
Text("Saves every tap, where it lands, and the text you type or dictate with Hex's keyboard on this iPhone for 14 days, so you can export it. Nothing is sent.")
.font(.system(size: 12))
.foregroundStyle(HexTheme.textMuted)
}
}
.tint(HexTheme.success)
.padding(.horizontal, 16)
.padding(.vertical, 10)
.onChange(of: typingLogs) { _, enabled in
TypingLogSettings().isEnabled = enabled
}
if typingLogs {
Button {
showTypingLogs = true
} label: {
HStack {
Text("Typing logs")
.font(.system(size: 13, weight: .medium))
.foregroundStyle(HexTheme.textBase)
Spacer()
Image(systemName: "chevron.right")
.font(.system(size: 12, weight: .semibold))
.foregroundStyle(HexTheme.textFaint)
}
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.padding(.horizontal, 16)
.padding(.bottom, 12)
.sheet(isPresented: $showTypingLogs) {
TypingLogsView()
}
}
}
.background(
HexTheme.bgBase,
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
)
.onChange(of: fullKeyboard) { _, enabled in
FullKeyboardSettings().isEnabled = enabled
}
Toggle(isOn: $cleanupTagger) {
VStack(alignment: .leading, spacing: 2) {
Text("Clean up what I say")
.font(.system(size: 15, weight: .regular))
.foregroundStyle(HexTheme.textBase)
Text("Removes ums, repeats and things you corrected (3pm, actually 4pm), on this iPhone")
.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: cleanupTagger) { _, enabled in
CleanupTaggerSettings().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
}
TranslateDictationRow()
.padding(.horizontal, 16)
.padding(.vertical, 10)
.background(
HexTheme.bgBase,
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
)
if customVocabulary {
CustomVocabularyEditor()
.padding(12)
.background(
HexTheme.bgBase,
in: RoundedRectangle(
cornerRadius: HexTheme.cardRadius,
style: .continuous
)
)
}
}
.onAppear {
fullKeyboard = FullKeyboardSettings().isEnabled
cleanupTagger = CleanupTaggerSettings().isEnabled
appleIntelligenceCleanup = AppleIntelligenceCleanupSettings().isEnabled
customVocabulary = CustomVocabularySettings().isEnabled
cleanupAvailability = AppleIntelligenceCleanupAvailability.current
autocorrect = FullKeyboardSettings().autocorrect
keyPopups = FullKeyboardSettings().keyPopups
haptics = FullKeyboardSettings().haptics
emoji = FullKeyboardSettings().emoji
emojiHistoryEmpty = EmojiUsageStore().isEmpty
learnTyping = TypingJournalSettings().isEnabled
typingLogs = TypingLogSettings().isEnabled
}
}
}