Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ios/HEXMobile/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,16 @@
}
}
},
"Key flicks" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "按键轻扫"
}
}
}
},
"Key pop-ups" : {
"localizations" : {
"zh-Hans" : {
Expand Down Expand Up @@ -4273,6 +4283,16 @@
}
}
},
"Pull a key down to type the character above its letter" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "向下拉按键即可输入其字母上方的字符"
}
}
}
},
"The multilingual model's download stopped. Trying again in %lld s." : {
"localizations" : {
"zh-Hans" : {
Expand Down
22 changes: 17 additions & 5 deletions ios/HEXMobile/Settings/KeyboardSettingsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ struct KeyboardSettingsPage: View {

private var settings: FullKeyboardSettings { FullKeyboardSettings() }

/// Hex is an iPhone app, so on an iPad its idiom says phone; the device's model doesn't.
/// There the keyboard has Apple's iPad rows: no number row, and key flicks instead.
private static let runsOnIPad = UIDevice.current.model.hasPrefix("iPad")

private var fullKeyboard: Bool {
_ = revision
return settings.isEnabled
Expand Down Expand Up @@ -204,11 +208,19 @@ struct KeyboardSettingsPage: View {

SettingsDivider()

SettingsToggleRow(
title: String(localized: "Number row"),
detail: String(localized: "Shows 1 to 0 above the letters"),
isOn: binding(\.numberRow)
)
if Self.runsOnIPad {
SettingsToggleRow(
title: String(localized: "Key flicks"),
detail: String(localized: "Pull a key down to type the character above its letter"),
isOn: binding(\.keyFlicks)
)
} else {
SettingsToggleRow(
title: String(localized: "Number row"),
detail: String(localized: "Shows 1 to 0 above the letters"),
isOn: binding(\.numberRow)
)
}
}
}

Expand Down
39 changes: 39 additions & 0 deletions ios/HEXMobileTests/FullKeyboardEngineTests+SwipeTyping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,45 @@ extension FullKeyboardEngineTests {
XCTAssertEqual(rowOne.text, "power")
}

/// TestFlight build 147 (iPad): "flick for symbol is not working". On a docked iPad, pulling
/// a key down past half its travel types the character over its letter, as Apple's key
/// flicks do; a short pull, a pull taken back, or the switch off types the letter. The pull
/// keeps its key (no slide onto the row below), a rollover types the flicked character, and
/// a digit goes in as typed, with nothing corrected.
func testDockedIPadKeyFlicks() throws {
engine.pad = .docked(.mini)
defer { KeyboardFlicks.isEnabled = true }
let e = try XCTUnwrap(engine.layout.key(.character("e")))
XCTAssertEqual(e.flick, "3")
let start = CGPoint(x: e.frame.midX, y: e.frame.midY)
func pull(_ dy: CGFloat, back: Bool = false, id: Int = 1, lift: Bool = true) {
engine.touchBegan(id: id, at: start)
for step in stride(from: CGFloat(3), through: dy, by: 3) {
engine.touchMoved(id: id, to: CGPoint(x: start.x, y: start.y + step))
}
if back { engine.touchMoved(id: id, to: start) }
if lift { engine.touchEnded(id: id, at: CGPoint(x: start.x, y: start.y + (back ? 0 : dy))) }
}
pull(30)
XCTAssertEqual(target.text, "3")
pull(12)
XCTAssertEqual(target.text, "3e", "a short pull types the letter")
pull(30, back: true)
XCTAssertEqual(target.text, "3ee", "taken back, the letter")
pull(60)
XCTAssertEqual(target.text, "3ee3", "past the row below, still the flick")
pull(30, lift: false)
XCTAssertEqual(engine.touches[1]?.key.kind, .character("e"))
tap(.character("r"))
engine.touchEnded(id: 1, at: CGPoint(x: start.x, y: start.y + 30))
XCTAssertEqual(target.text, "3ee33r", "rollover types the flicked character")
KeyboardFlicks.isEnabled = false
pull(30)
XCTAssertEqual(target.text, "3ee33re", "Settings › Keyboard › Key flicks off")
engine.pad = nil
XCTAssertNil(engine.layout.key(.character("e"))?.flick, "an iPhone has none")
}

/// Without the switch, or on an iPad, the keys have no number row.
func testNumberRowNeedsItsSwitchAndAnIPhone() {
XCTAssertFalse(engine.layout.hasNumberRow, "off by default")
Expand Down
20 changes: 20 additions & 0 deletions ios/HEXMobileTests/KeyboardLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3504,4 +3504,24 @@ final class FullKeyboardSettingsTests: XCTestCase {
XCTAssertTrue(settings.quickAccents)
XCTAssertEqual(defaults.object(forKey: "experiments.quickAccents") as? Bool, true)
}

/// Apple's key flicks over the docked iPad's keys (iPad mini, iPadOS 27.2): digits over row 1,
/// @ # $ & * ( ) ' " over row 2 and % - + = / ; : over row 3 in English and German, AZERTY's
/// own in French, the #+= page's characters over the 123 page's symbols, nothing on the
/// two-symbol keys or the floating keyboard.
func testDockedIPadKeysCarryApplesKeyFlicks() {
func flicks(_ language: KeyboardLanguage, _ layer: KeyboardLayer = .letters, pad: KeyboardPadPlacement = .docked(.mini)) -> [String] {
let layout = KeyboardLayout(width: 744, layer: layer, language: language, pad: pad)
return (0..<3).map { row in
layout.keys.filter { $0.row == row }.sorted { $0.frame.minX < $1.frame.minX }.compactMap(\.flick).joined()
}
}
XCTAssertEqual(flicks(.english), ["1234567890", "@#$&*()'\"", "%-+=/;:"])
XCTAssertEqual(flicks(.german), ["1234567890", "@#$&*()'\"", "%-+=/;:"])
XCTAssertEqual(flicks(.french), ["1234567890", "@#&\"$(!)-*", "%_+=/;"])
XCTAssertEqual(flicks(.english, .numbers), ["", "€£¥_^[]{}", "§|~…\\<>"])
XCTAssertEqual(flicks(.english, .symbols), ["", "", ""])
XCTAssertEqual(flicks(.english, pad: .floating), ["", "", ""])
XCTAssertNil(KeyboardLayout(width: 744, layer: .letters, pad: .docked(.mini)).key(.character(","))?.flick)
}
}
43 changes: 43 additions & 0 deletions ios/HEXShared/FullKeyboard/Engine/FullKeyboardEngine+Flicks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import CoreGraphics

/// Key flicks on a docked iPad (`KeyboardFlicks`): a key pulled down types the character
/// over its letter.
@MainActor
extension FullKeyboardEngine {
/// A move of a key that flicks: once the finger has gone down more than across, the touch
/// keeps its key (no slide to the key below, no swipe) and its pull is tracked. False for
/// every other touch, which moves as before.
func moveFlick(_ touch: inout ActiveTouch, id: Int, to point: CGPoint) -> Bool {
guard KeyboardFlicks.isEnabled, layout.metrics.pad?.isDocked == true, !touch.committed,
touch.key.flick != nil, activeAccentMenu == nil else { return false }
let dy = point.y - touch.startPoint.y
let dx = abs(point.x - touch.startPoint.x)
if touch.flick == nil {
guard dy > 4, dy > dx else { return false }
}
let progress = KeyboardFlicks.progress(pull: dy)
guard progress != touch.flick else {
touches[id] = touch
return true
}
touch.flick = progress
touches[id] = touch
onChange?()
return true
}

/// Letting go of a pulled key: past half way, its character goes in as a typed one (as a
/// slide from 123 does: a mark after a word corrects it, a digit is just a digit). False
/// otherwise, and the letter goes in.
func commitFlick(_ touch: ActiveTouch) -> Bool {
guard let progress = touch.flick, progress >= KeyboardFlicks.commitProgress, let character = touch.key.flick else { return false }
typingLog?.ui("flick", [TypingLogField("key", .string(touch.key.label)), TypingLogField("chosen", .string(character))])
if dropsSuggestionSpace(before: character) || !correctWord(endingWith: character) {
insert(character, source: "flick")
}
if layerState.layer == .letters { shift.didType() }
refreshAutoCapitalization()
logState("typed")
return true
}
}
11 changes: 6 additions & 5 deletions ios/HEXShared/FullKeyboard/Engine/FullKeyboardEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ final class FullKeyboardEngine {
/// How far along the space bar a language swipe must go; a shorter one types a space.
static let languageSwipeDistance: CGFloat = 24

private(set) var shift = ShiftStateMachine()
var shift = ShiftStateMachine()
var layerState = KeyboardLayerState()
private(set) var field: KeyboardFieldKind = .text
private(set) var touches: [Int: ActiveTouch] = [:]
var touches: [Int: ActiveTouch] = [:]
/// Touch ids in the order they went down.
private var touchOrder: [Int] = []
var lastSpaceAt: TimeInterval?
Expand Down Expand Up @@ -500,7 +500,7 @@ final class FullKeyboardEngine {
commitAccentSelection(menu.selectedOption)
activeAccentMenu = nil
activeAccentTouchID = nil
} else {
} else if !commitFlick(touch) {
commitCharacter(touch.key, at: touch.startPoint, down: touch.downPoint)
}
touch.committed = true
Expand Down Expand Up @@ -663,6 +663,7 @@ final class FullKeyboardEngine {
return
}

if moveFlick(&touch, id: id, to: point) { return }
// 4. Sliding across character keys updates the active key and re-anchors the hold timer.
// A letter the next-letter odds claimed keeps the touch while it stays within reach.
if touch.key.character != nil, !touch.committed,
Expand Down Expand Up @@ -736,7 +737,7 @@ final class FullKeyboardEngine {

switch touch.key.kind {
case .character:
if !touch.committed {
if !touch.committed, !commitFlick(touch) {
commitCharacter(touch.key, at: touch.startPoint, down: touch.downPoint)
}
case .shift:
Expand Down Expand Up @@ -966,7 +967,7 @@ final class FullKeyboardEngine {
/// Punctuation right after a word corrects it as space does ("teh," becomes "the,"), and
/// goes in after the fix. Delete right after takes only the mark, as after a space.
/// False when there is nothing to fix: the caller types the mark as usual.
private func correctWord(endingWith text: String) -> Bool {
func correctWord(endingWith text: String) -> Bool {
guard text.count == 1, let mark = text.first, Self.wordEnders.contains(mark), swipedWord == nil else { return false }
if applyTextReplacement(ending: text) { return true }
let before = textBefore
Expand Down
9 changes: 9 additions & 0 deletions ios/HEXShared/FullKeyboard/FullKeyboardSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct FullKeyboardSettings {
static let hideWordSuggestions = "experiments.hideWordSuggestions"
static let hexKeyOnLeft = "settings.keyboardHexKeyLeft"
static let numberRow = "settings.keyboardNumberRow"
static let keyFlicks = "settings.keyboardKeyFlicks"
static let dictationBarAutoStart = "settings.dictationBarAutoStart"
static let joinKeyboardWhenUnfolded = "experiments.joinKeyboardWhenUnfolded"
static let dvorakPunctuation = "experiments.dvorakPunctuation"
Expand Down Expand Up @@ -324,6 +325,14 @@ struct FullKeyboardSettings {
nonmutating set { defaults?.set(newValue, forKey: Key.numberRow) }
}

/// Settings › Keyboard › Key flicks (iPad): pulling a docked iPad key down types the
/// character over its letter, as Apple's keyboard does (`KeyboardFlicks`). On by default, as
/// Apple's Enable Key Flicks is; a keyboard extension can't read that one.
var keyFlicks: Bool {
get { defaults?.object(forKey: Key.keyFlicks) as? Bool ?? true }
nonmutating set { defaults?.set(newValue, forKey: Key.keyFlicks) }
}

/// Settings › Experiments › Join the keyboard when unfolded: on the Duo unfolded and held
/// upright, Hex normally splits its keyboard as Apple's does there, since an extension
/// can't read Apple's Split Keyboard preference. On, it draws the joined keyboard instead,
Expand Down
3 changes: 3 additions & 0 deletions ios/HEXShared/FullKeyboard/FullKeyboardTouch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ extension FullKeyboardEngine {
var claimed = false
/// Where the finger went down, before a strip touch moved onto row 1 (Adaptive touch).
var downPoint: CGPoint = .zero
/// A docked iPad key pulled down (`KeyboardFlicks`): how far its character has come, 0 to 1;
/// nil until the finger goes down more than across.
var flick: CGFloat?
}

/// A press that types the character key it slides onto: 123, ABC and #+= (with a page to
Expand Down
76 changes: 76 additions & 0 deletions ios/HEXShared/FullKeyboard/KeyboardFlicks.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import CoreGraphics

/// Apple's key flicks on the docked iPad keyboard (Settings › General › Keyboard › Enable Key
/// Flicks): every letter key carries a small grey character above its letter, and pulling the
/// key down types it. Read on Apple's iPad mini keyboard (iPadOS 27.2 simulator, black box,
/// 2026-11-23), the rows Hex draws on every docked iPad (`KeyboardPadRows.swift`):
///
/// - English and German: 1 to 0 over row 1, @ # $ & * ( ) ' " over row 2, % - + = / ; : over
/// row 3; French (AZERTY): 1 to 0, @ # & " $ ( ! ) - *, and % _ + = / ;.
/// - The 123 page: the #+= page's character over each symbol (€ over @, § over %), not on the
/// digits.
/// - The two-symbol keys after the letters keep their own pair and flick nothing.
///
/// Drawn about 12.5 pt high in a grey a little above the key's middle top, the letter set
/// lower; while pulled, the character slides down to the middle and darkens as the letter
/// fades (none of it moves at 8 pt, about half way at 16 pt, all the way by 30 pt). A
/// keyboard extension can't read Apple's switch (the Custom Keyboard guide: no access to the
/// general keyboard settings), so Hex has its own (Settings › Keyboard › Key flicks).
nonisolated enum KeyboardFlicks {
/// Settings › Keyboard › Key flicks, set by the keyboard view from the App Group.
nonisolated(unsafe) static var isEnabled = true

/// No change below this pull (pt).
static let start: CGFloat = 8
/// Pull (pt) from `start` to the character in place.
static let travel: CGFloat = 18
/// Let go at or past this share of the way and the character goes in; short of it (or
/// pulled back up), the letter.
static let commitProgress: CGFloat = 0.5

/// How far a pull of `dy` points down has brought the character, 0 to 1.
static func progress(pull dy: CGFloat) -> CGFloat {
min(1, max(0, (dy - start) / travel))
}

private static let digits = "1234567890".map(String.init)
private static let englishMiddle = ["@", "#", "$", "&", "*", "(", ")", "'", "\""]
private static let englishBottom = ["%", "-", "+", "=", "/", ";", ":"]
private static let frenchMiddle = ["@", "#", "&", "\"", "$", "(", "!", ")", "-", "*"]
private static let frenchBottom = ["%", "_", "+", "=", "/", ";"]
/// The 123 page's symbols and the #+= page's character Apple puts over each.
private static let numbersPage: [String: String] = [
"@": "€", "#": "£", "$": "¥", "&": "_", "*": "^", "(": "[", ")": "]", "'": "{", "\"": "}",
"%": "§", "-": "|", "+": "~", "=": "…", "/": "\\", ";": "<", ":": ">",
]

/// Each key's flick on the letters and 123 pages. Measured for English, German and French;
/// every other language gets the digits over a ten-letter row 1 (Apple's own for them
/// unmeasured), and rows 2 and 3 only where they have English's nine and seven letters.
static func add(to keys: inout [KeyboardKey], layer: KeyboardLayer, language: KeyboardLanguage) {
switch layer {
case .symbols:
return
case .numbers:
for i in keys.indices where keys[i].shifted == nil && keys[i].row > 0 {
if let c = keys[i].character { keys[i].flick = numbersPage[c] }
}
case .letters:
let measured = language == .english || language == .german
let rows: [[String]] = language.isFrench
? [digits, frenchMiddle, frenchBottom]
: [digits, measured ? englishMiddle : [], measured ? englishBottom : []]
for row in 0..<3 {
let letters = keys.indices
.filter { keys[$0].row == row && keys[$0].shifted == nil && keys[$0].character?.first?.isLetter == true }
.sorted { keys[$0].frame.minX < keys[$1].frame.minX }
let flicks = rows[row]
if row == 0, letters.count != 10 { continue }
if row > 0, !language.isFrench, letters.count != flicks.count { continue }
for (n, i) in letters.enumerated() where n < flicks.count {
keys[i].flick = flicks[n]
}
}
}
}
}
Loading