Skip to content

Commit a2bd368

Browse files
committed
fix: clean up emoji suggestion UI to distinguish from word suggestions
1 parent c5025ad commit a2bd368

File tree

1 file changed

+167
-163
lines changed

1 file changed

+167
-163
lines changed

Keyboards/KeyboardsBase/KeyboardViewController.swift

Lines changed: 167 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -407,43 +407,45 @@ class KeyboardViewController: UIInputViewController {
407407
func getEmojiAutoSuggestionsPatternMatching(for word: String) {
408408
let emojisToDisplay = LanguageDBManager.shared.queryEmojisPatternMatching(of: word.lowercased())
409409

410+
emojisToDisplayArray = [String]()
410411
if !emojisToDisplay[0].isEmpty {
411-
emojisToDisplayArray = [String]()
412412
currentEmojiTriggerWord = ":" + word.lowercased()
413413

414-
if !emojisToDisplay[2].isEmpty && DeviceType.isPad {
415-
for i in 0 ..< 3 {
416-
emojisToDisplayArray.append(emojisToDisplay[i])
417-
}
414+
for emoji in emojisToDisplay where !emoji.isEmpty {
415+
emojisToDisplayArray.append(emoji)
416+
}
417+
418+
switch emojisToDisplayArray.count {
419+
case 1: emojisToShow = .one
420+
case 2: emojisToShow = .two
421+
case 3: emojisToShow = .three
422+
case 4: emojisToShow = .four
423+
case 5: emojisToShow = .five
424+
case 6: emojisToShow = .six
425+
default: emojisToShow = .zero
426+
}
427+
428+
if commandState == .colonToEmoji {
429+
autoAction0Visible = false
418430
autoAction2Visible = false
419-
emojisToShow = .three
431+
}
420432

433+
if DeviceType.isPad && emojisToShow.rawValue >= 2 {
421434
if UITraitCollection.current.userInterfaceStyle == .light {
422435
padEmojiDivider0.backgroundColor = specialKeyColor
423436
padEmojiDivider1.backgroundColor = specialKeyColor
424437
} else if UITraitCollection.current.userInterfaceStyle == .dark {
425438
padEmojiDivider0.backgroundColor = UIColor(cgColor: commandBarPlaceholderColorCG)
426439
padEmojiDivider1.backgroundColor = UIColor(cgColor: commandBarPlaceholderColorCG)
427440
}
428-
conditionallyHideEmojiDividers()
429-
} else if !emojisToDisplay[1].isEmpty {
430-
for i in 0 ..< 2 {
431-
emojisToDisplayArray.append(emojisToDisplay[i])
432-
}
433-
autoAction2Visible = false
434-
emojisToShow = .two
435-
441+
} else if DeviceType.isPhone && emojisToShow.rawValue >= 2 {
436442
if UITraitCollection.current.userInterfaceStyle == .light {
437443
phoneEmojiDivider.backgroundColor = specialKeyColor
438444
} else if UITraitCollection.current.userInterfaceStyle == .dark {
439445
phoneEmojiDivider.backgroundColor = UIColor(cgColor: commandBarPlaceholderColorCG)
440446
}
441-
conditionallyHideEmojiDividers()
442-
} else {
443-
emojisToDisplayArray.append(emojisToDisplay[0])
444-
445-
emojisToShow = .one
446447
}
448+
conditionallyHideEmojiDividers()
447449
} else {
448450
emojisToShow = .zero
449451
}
@@ -700,144 +702,168 @@ class KeyboardViewController: UIInputViewController {
700702
hideConjugateAndPluralKeys(state: false)
701703
}
702704

703-
if autoAction0Visible {
704-
allowUndo = false
705-
firstCompletionIsHighlighted = false
706-
// Highlight if the current prefix is the first autocompletion.
707-
if currentPrefix == completionWords[0] && completionWords[1] != " " {
708-
firstCompletionIsHighlighted = true
709-
}
710-
setBtn(
711-
btn: translateKey,
712-
color: firstCompletionIsHighlighted ? keyColor.withAlphaComponent(0.5) : keyboardBgColor,
713-
name: "AutoAction0",
714-
canBeCapitalized: false,
715-
isSpecial: false
716-
)
717-
styleBtn(
718-
btn: translateKey,
719-
title: completionWords[0],
720-
radius: firstCompletionIsHighlighted ? commandKeyCornerRadius / 2.5 : commandKeyCornerRadius
721-
)
722-
if translateKey.currentTitle != " " {
723-
activateBtn(btn: translateKey)
705+
if commandState == .colonToEmoji && emojisToShow != .zero {
706+
let emojiButtons: [UIButton]
707+
if DeviceType.isPad {
708+
emojiButtons = [translateKey, conjugateKey, pluralKey, padEmojiKey0, padEmojiKey1, padEmojiKey2]
709+
} else {
710+
emojiButtons = [translateKey, conjugateKey, pluralKey, phoneEmojiKey0, phoneEmojiKey1]
724711
}
725-
autoActionAnnotation(autoActionWord: completionWords[0], index: 0, KVC: self)
726-
}
727712

728-
// Add the current word being typed to the completion words if there is only one option that's highlighted.
729-
if firstCompletionIsHighlighted && completionWords[1] == " " && completionWords[0] != currentPrefix {
730-
// spaceAutoInsertIsPossible = true
731-
completionWords[1] = currentPrefix
732-
}
713+
for (index, emoji) in emojisToDisplayArray.enumerated() {
714+
if index < emojiButtons.count {
715+
let btn = emojiButtons[index]
716+
setBtn(btn: btn, color: keyboardBgColor, name: "EmojiKey\(index)", canBeCapitalized: false, isSpecial: false)
717+
styleBtn(btn: btn, title: emoji, radius: commandKeyCornerRadius)
718+
if DeviceType.isPhone {
719+
btn.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPhone)
720+
} else {
721+
btn.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPad)
722+
}
723+
activateBtn(btn: btn)
724+
}
725+
}
726+
conditionallyHideEmojiDividers()
727+
} else {
728+
if autoAction0Visible {
729+
allowUndo = false
730+
firstCompletionIsHighlighted = false
731+
// Highlight if the current prefix is the first autocompletion.
732+
if currentPrefix == completionWords[0] && completionWords[1] != " " {
733+
firstCompletionIsHighlighted = true
734+
}
735+
setBtn(
736+
btn: translateKey,
737+
color: firstCompletionIsHighlighted ? keyColor.withAlphaComponent(0.5) : keyboardBgColor,
738+
name: "AutoAction0",
739+
canBeCapitalized: false,
740+
isSpecial: false
741+
)
742+
styleBtn(
743+
btn: translateKey,
744+
title: completionWords[0],
745+
radius: firstCompletionIsHighlighted ? commandKeyCornerRadius / 2.5 : commandKeyCornerRadius
746+
)
747+
if translateKey.currentTitle != " " {
748+
activateBtn(btn: translateKey)
749+
}
750+
autoActionAnnotation(autoActionWord: completionWords[0], index: 0, KVC: self)
751+
}
733752

734-
setBtn(
735-
btn: conjugateKey,
736-
color: keyboardBgColor, name: "AutoAction1",
737-
canBeCapitalized: false,
738-
isSpecial: false
739-
)
740-
styleBtn(
741-
btn: conjugateKey,
742-
title: !autoAction0Visible ? completionWords[0] : completionWords[1],
743-
radius: commandKeyCornerRadius
744-
)
745-
if conjugateKey.currentTitle != " " {
746-
activateBtn(btn: conjugateKey)
747-
}
748-
autoActionAnnotation(
749-
autoActionWord: !autoAction0Visible ? completionWords[0] : completionWords[1], index: 1, KVC: self
750-
)
753+
// Add the current word being typed to the completion words if there is only one option that's highlighted.
754+
if firstCompletionIsHighlighted && completionWords[1] == " " && completionWords[0] != currentPrefix {
755+
// spaceAutoInsertIsPossible = true
756+
completionWords[1] = currentPrefix
757+
}
751758

752-
if autoAction2Visible && emojisToShow == .zero {
753759
setBtn(
754-
btn: pluralKey,
755-
color: keyboardBgColor,
756-
name: "AutoAction2",
760+
btn: conjugateKey,
761+
color: keyboardBgColor, name: "AutoAction1",
757762
canBeCapitalized: false,
758763
isSpecial: false
759764
)
760765
styleBtn(
761-
btn: pluralKey,
762-
title: !autoAction0Visible ? completionWords[1] : completionWords[2],
766+
btn: conjugateKey,
767+
title: !autoAction0Visible ? completionWords[0] : completionWords[1],
763768
radius: commandKeyCornerRadius
764769
)
765-
if pluralKey.currentTitle != " " {
766-
activateBtn(btn: pluralKey)
770+
if conjugateKey.currentTitle != " " {
771+
activateBtn(btn: conjugateKey)
767772
}
768773
autoActionAnnotation(
769-
autoActionWord: !autoAction0Visible ? completionWords[1] : completionWords[2], index: 2, KVC: self
774+
autoActionWord: !autoAction0Visible ? completionWords[0] : completionWords[1], index: 1, KVC: self
770775
)
771776

772-
conditionallyHideEmojiDividers()
773-
} else if autoAction2Visible && emojisToShow == .one {
774-
setBtn(
775-
btn: pluralKey,
776-
color: keyboardBgColor,
777-
name: "AutoAction2",
778-
canBeCapitalized: false,
779-
isSpecial: false
780-
)
781-
styleBtn(
782-
btn: pluralKey,
783-
title: emojisToDisplayArray[0],
784-
radius: commandKeyCornerRadius
785-
)
786-
if DeviceType.isPhone {
787-
pluralKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPhone)
788-
} else if DeviceType.isPad {
789-
pluralKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPad)
790-
}
791-
activateBtn(btn: pluralKey)
792-
793-
conditionallyHideEmojiDividers()
794-
} else if !autoAction2Visible && emojisToShow == .two {
795-
setBtn(
796-
btn: phoneEmojiKey0,
797-
color: keyboardBgColor,
798-
name: "EmojiKey0",
799-
canBeCapitalized: false,
800-
isSpecial: false
801-
)
802-
setBtn(
803-
btn: phoneEmojiKey1,
804-
color: keyboardBgColor,
805-
name: "EmojiKey1",
806-
canBeCapitalized: false,
807-
isSpecial: false
808-
)
809-
styleBtn(btn: phoneEmojiKey0, title: emojisToDisplayArray[0], radius: commandKeyCornerRadius)
810-
styleBtn(btn: phoneEmojiKey1, title: emojisToDisplayArray[1], radius: commandKeyCornerRadius)
777+
if autoAction2Visible && emojisToShow == .zero {
778+
setBtn(
779+
btn: pluralKey,
780+
color: keyboardBgColor,
781+
name: "AutoAction2",
782+
canBeCapitalized: false,
783+
isSpecial: false
784+
)
785+
styleBtn(
786+
btn: pluralKey,
787+
title: !autoAction0Visible ? completionWords[1] : completionWords[2],
788+
radius: commandKeyCornerRadius
789+
)
790+
if pluralKey.currentTitle != " " {
791+
activateBtn(btn: pluralKey)
792+
}
793+
autoActionAnnotation(
794+
autoActionWord: !autoAction0Visible ? completionWords[1] : completionWords[2], index: 2, KVC: self
795+
)
811796

812-
if DeviceType.isPhone {
813-
phoneEmojiKey0.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPhone)
814-
phoneEmojiKey1.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPhone)
815-
} else if DeviceType.isPad {
816-
phoneEmojiKey0.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPad)
817-
phoneEmojiKey1.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPad)
818-
}
797+
conditionallyHideEmojiDividers()
798+
} else if autoAction2Visible && emojisToShow == .one {
799+
setBtn(
800+
btn: pluralKey,
801+
color: keyboardBgColor,
802+
name: "AutoAction2",
803+
canBeCapitalized: false,
804+
isSpecial: false
805+
)
806+
styleBtn(
807+
btn: pluralKey,
808+
title: emojisToDisplayArray[0],
809+
radius: commandKeyCornerRadius
810+
)
811+
if DeviceType.isPhone {
812+
pluralKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPhone)
813+
} else if DeviceType.isPad {
814+
pluralKey.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPad)
815+
}
816+
activateBtn(btn: pluralKey)
819817

820-
activateBtn(btn: phoneEmojiKey0)
821-
activateBtn(btn: phoneEmojiKey1)
818+
conditionallyHideEmojiDividers()
819+
} else if !autoAction2Visible && emojisToShow.rawValue >= 2 {
820+
if DeviceType.isPhone || emojisToShow == .two {
821+
setBtn(
822+
btn: phoneEmojiKey0,
823+
color: keyboardBgColor,
824+
name: "EmojiKey0",
825+
canBeCapitalized: false,
826+
isSpecial: false
827+
)
828+
setBtn(
829+
btn: phoneEmojiKey1,
830+
color: keyboardBgColor,
831+
name: "EmojiKey1",
832+
canBeCapitalized: false,
833+
isSpecial: false
834+
)
835+
styleBtn(btn: phoneEmojiKey0, title: emojisToDisplayArray[0], radius: commandKeyCornerRadius)
836+
styleBtn(btn: phoneEmojiKey1, title: emojisToDisplayArray[1], radius: commandKeyCornerRadius)
837+
838+
if DeviceType.isPhone {
839+
phoneEmojiKey0.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPhone)
840+
phoneEmojiKey1.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPhone)
841+
} else if DeviceType.isPad {
842+
phoneEmojiKey0.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPad)
843+
phoneEmojiKey1.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarFontPad)
844+
}
822845

823-
conditionallyHideEmojiDividers()
824-
} else if !autoAction2Visible && emojisToShow == .three {
825-
setBtn(btn: padEmojiKey0, color: keyboardBgColor, name: "EmojiKey0", canBeCapitalized: false, isSpecial: false)
826-
setBtn(btn: padEmojiKey1, color: keyboardBgColor, name: "EmojiKey1", canBeCapitalized: false, isSpecial: false)
827-
setBtn(btn: padEmojiKey2, color: keyboardBgColor, name: "EmojiKey2", canBeCapitalized: false, isSpecial: false)
828-
styleBtn(btn: padEmojiKey0, title: emojisToDisplayArray[0], radius: commandKeyCornerRadius)
829-
styleBtn(btn: padEmojiKey1, title: emojisToDisplayArray[1], radius: commandKeyCornerRadius)
830-
styleBtn(btn: padEmojiKey2, title: emojisToDisplayArray[2], radius: commandKeyCornerRadius)
831-
832-
padEmojiKey0.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarEmojiKeyFont)
833-
padEmojiKey1.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarEmojiKeyFont)
834-
padEmojiKey2.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarEmojiKeyFont)
835-
836-
activateBtn(btn: padEmojiKey0)
837-
activateBtn(btn: padEmojiKey1)
838-
activateBtn(btn: padEmojiKey2)
846+
activateBtn(btn: phoneEmojiKey0)
847+
activateBtn(btn: phoneEmojiKey1)
848+
} else if DeviceType.isPad && emojisToShow.rawValue >= 3 {
849+
setBtn(btn: padEmojiKey0, color: keyboardBgColor, name: "EmojiKey0", canBeCapitalized: false, isSpecial: false)
850+
setBtn(btn: padEmojiKey1, color: keyboardBgColor, name: "EmojiKey1", canBeCapitalized: false, isSpecial: false)
851+
setBtn(btn: padEmojiKey2, color: keyboardBgColor, name: "EmojiKey2", canBeCapitalized: false, isSpecial: false)
852+
styleBtn(btn: padEmojiKey0, title: emojisToDisplayArray[0], radius: commandKeyCornerRadius)
853+
styleBtn(btn: padEmojiKey1, title: emojisToDisplayArray[1], radius: commandKeyCornerRadius)
854+
styleBtn(btn: padEmojiKey2, title: emojisToDisplayArray[2], radius: commandKeyCornerRadius)
855+
856+
padEmojiKey0.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarEmojiKeyFont)
857+
padEmojiKey1.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarEmojiKeyFont)
858+
padEmojiKey2.titleLabel?.font = .systemFont(ofSize: scribeKey.frame.height * scalarEmojiKeyFont)
859+
860+
activateBtn(btn: padEmojiKey0)
861+
activateBtn(btn: padEmojiKey1)
862+
activateBtn(btn: padEmojiKey2)
863+
}
839864

840-
conditionallyHideEmojiDividers()
865+
conditionallyHideEmojiDividers()
866+
}
841867
}
842868

843869
translateKey.layer.shadowColor = UIColor.clear.cgColor
@@ -2698,30 +2724,8 @@ class KeyboardViewController: UIInputViewController {
26982724
loadKeys()
26992725
}
27002726

2701-
case "EmojiKey0":
2702-
if DeviceType.isPhone || emojisToShow == .two {
2703-
executeAutoAction(keyPressed: phoneEmojiKey0)
2704-
} else if DeviceType.isPad {
2705-
executeAutoAction(keyPressed: padEmojiKey0)
2706-
}
2707-
if shiftButtonState == .normal {
2708-
shiftButtonState = .shift
2709-
}
2710-
loadKeys()
2711-
2712-
case "EmojiKey1":
2713-
if DeviceType.isPhone || emojisToShow == .two {
2714-
executeAutoAction(keyPressed: phoneEmojiKey1)
2715-
} else if DeviceType.isPad {
2716-
executeAutoAction(keyPressed: padEmojiKey1)
2717-
}
2718-
if shiftButtonState == .normal {
2719-
shiftButtonState = .shift
2720-
}
2721-
loadKeys()
2722-
2723-
case "EmojiKey2":
2724-
executeAutoAction(keyPressed: padEmojiKey2)
2727+
case "EmojiKey0", "EmojiKey1", "EmojiKey2", "EmojiKey3", "EmojiKey4", "EmojiKey5":
2728+
executeAutoAction(keyPressed: sender)
27252729
if shiftButtonState == .normal {
27262730
shiftButtonState = .shift
27272731
}
@@ -2977,7 +2981,7 @@ class KeyboardViewController: UIInputViewController {
29772981

29782982
// Reset emoji repeat functionality.
29792983
if !(
2980-
["EmojiKey0", "EmojiKey1", "EmojiKey2"].contains(originalKey)
2984+
["EmojiKey0", "EmojiKey1", "EmojiKey2", "EmojiKey3", "EmojiKey4", "EmojiKey5"].contains(originalKey)
29812985
|| (originalKey == "AutoAction2" && emojisToShow == .one)
29822986
) {
29832987
emojiAutoActionRepeatPossible = false

0 commit comments

Comments
 (0)