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
35 changes: 35 additions & 0 deletions Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,15 @@ class KeyboardViewController: UIInputViewController {
}
}

func hapticFeedbackIsEnabled() -> Bool {
let langCode = languagesAbbrDict[controllerLanguage] ?? "unknown"
if let userDefaults = UserDefaults(suiteName: "group.be.scri.userDefaultsContainer") {
let dictionaryKey = langCode + "HapticFeedback"
return userDefaults.bool(forKey: dictionaryKey)
}
return false // default off
}

// MARK: Button Actions

/// Triggers actions based on the press of a key.
Expand Down Expand Up @@ -2542,6 +2551,32 @@ class KeyboardViewController: UIInputViewController {
} else {
sender.backgroundColor = keyPressedColor
}

// Haptic feedback on key press.
// Heavy: destructive/dismiss actions.
// Medium: command, navigation, and action keys.
// Light: all regular character keys.
guard hapticFeedbackIsEnabled() else { return }
let heavyKeys = ["delete", "hideKeyboard"]
let mediumKeys = [
"shift", "return", "Translate", "Conjugate", "Plural",
"AutoAction0", "AutoAction1", "AutoAction2",
"EmojiKey0", "EmojiKey1", "EmojiKey2",
"GetAnnotationInfo", "ScribeAnnotation",
"shiftFormsDisplayLeft", "shiftFormsDisplayRight",
"ABC", "АБВ", "123", "#+=", ".?123", "selectKeyboard",
SpecialKeys.indent, SpecialKeys.capsLock,
spaceBar, languageTextForSpaceBar
]
let style: UIImpactFeedbackGenerator.FeedbackStyle
if heavyKeys.contains(originalKey) {
style = .heavy
} else if mediumKeys.contains(originalKey) {
style = .medium
} else {
style = .light
}
UIImpactFeedbackGenerator(style: style).impactOccurred()
}

/// Shows the conjugation view for verbs.
Expand Down
1 change: 1 addition & 0 deletions Scribe/ParentTableCellModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ enum UserInteractiveState {
case toggleAccentCharacters
case toggleWordForWordDeletion
case increaseTextSize
case hapticFeedback
case none
}

Expand Down
6 changes: 6 additions & 0 deletions Scribe/SettingsTab/SettingsTableData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ enum SettingsTableData {
value: "Delete text word by word when the delete key is pressed and held.",
comment: ""
)
),
Section(
sectionTitle: "Haptic feedback",
hasToggle: true,
sectionState: .none(.hapticFeedback),
shortDescription: "Enable haptic feedback on key press."
)
],
hasDynamicData: nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ final class InfoChildTableViewCell: UITableViewCell {
let dictionaryKey = languageCode + "WordForWordDeletion"
userDefaults.setValue(toggleSwitch.isOn, forKey: dictionaryKey)

case .hapticFeedback:
let dictionaryKey = languageCode + "HapticFeedback"
userDefaults.setValue(toggleSwitch.isOn, forKey: dictionaryKey)

case .increaseTextSize:
userDefaults.setValue(toggleSwitch.isOn, forKey: "increaseTextSize")
initializeFontSize()
Expand Down Expand Up @@ -211,6 +215,14 @@ final class InfoChildTableViewCell: UITableViewCell {
toggleSwitch.isOn = false // default off
}

case .hapticFeedback:
let dictionaryKey = languageCode + "HapticFeedback"
if let toggleValue = userDefaults.object(forKey: dictionaryKey) as? Bool {
toggleSwitch.isOn = toggleValue
} else {
toggleSwitch.isOn = false // default off
}

case .increaseTextSize:
if let toggleValue = userDefaults.object(forKey: "increaseTextSize") as? Bool {
toggleSwitch.isOn = toggleValue
Expand Down
Loading