Skip to content

Commit

Permalink
#188 make buttons conditionally active based on annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis committed Aug 13, 2022
1 parent b599eed commit 443b2da
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,25 +288,27 @@ class KeyboardViewController: UIInputViewController {

/// Sets up command buttons to execute autocomplete and autosuggest.
func conditionallySetAutoActionBtns() {
deactivateBtn(btn: translateKey)
deactivateBtn(btn: conjugateKey)
deactivateBtn(btn: pluralKey)
if commandState == false && scribeKeyState == false && conjugateView == false {
deactivateBtn(btn: translateKey)
deactivateBtn(btn: conjugateKey)
deactivateBtn(btn: pluralKey)

if autoAction1Visible == true {
setBtn(btn: translateKey, color: keyboardBgColor, name: "AutoAction1", canCap: false, isSpecial: false)
activateBtn(btn: translateKey)
}
if autoAction2Visible == true {
setBtn(btn: conjugateKey, color: keyboardBgColor, name: "AutoAction2", canCap: false, isSpecial: false)
activateBtn(btn: conjugateKey)
}
if autoAction1Visible == true {
setBtn(btn: translateKey, color: keyboardBgColor, name: "AutoAction1", canCap: false, isSpecial: false)
activateBtn(btn: translateKey)
}
if autoAction2Visible == true {
setBtn(btn: conjugateKey, color: keyboardBgColor, name: "AutoAction2", canCap: false, isSpecial: false)
activateBtn(btn: conjugateKey)
}

setBtn(btn: pluralKey, color: keyboardBgColor, name: "AutoAction3", canCap: false, isSpecial: false)
activateBtn(btn: pluralKey)
setBtn(btn: pluralKey, color: keyboardBgColor, name: "AutoAction3", canCap: false, isSpecial: false)
activateBtn(btn: pluralKey)

translateKey.layer.shadowColor = UIColor.clear.cgColor
conjugateKey.layer.shadowColor = UIColor.clear.cgColor
pluralKey.layer.shadowColor = UIColor.clear.cgColor
translateKey.layer.shadowColor = UIColor.clear.cgColor
conjugateKey.layer.shadowColor = UIColor.clear.cgColor
pluralKey.layer.shadowColor = UIColor.clear.cgColor
}

// Reset autocorrect and autosuggest button visibility.
autoAction1Visible = true
Expand Down Expand Up @@ -817,6 +819,10 @@ class KeyboardViewController: UIInputViewController {
conditionallyShowAutoActionPartitions()
deactivateConjugationDisplay()

styleBtn(btn: translateKey, title: translateKeyLbl, radius: commandKeyCornerRadius)
styleBtn(btn: conjugateKey, title: conjugateKeyLbl, radius: commandKeyCornerRadius)
styleBtn(btn: pluralKey, title: pluralKeyLbl, radius: commandKeyCornerRadius)

if scribeKeyState {
scribeKey.toEscape()
scribeKey.setFullCornerRadius()
Expand All @@ -825,10 +831,6 @@ class KeyboardViewController: UIInputViewController {
commandBar.hide()
hideAutoActionPartitions()

styleBtn(btn: translateKey, title: translateKeyLbl, radius: commandKeyCornerRadius)
styleBtn(btn: conjugateKey, title: conjugateKeyLbl, radius: commandKeyCornerRadius)
styleBtn(btn: pluralKey, title: pluralKeyLbl, radius: commandKeyCornerRadius)

if DeviceType.isPhone {
translateKey.titleLabel?.font = .systemFont(ofSize: annotationHeight * 0.65)
conjugateKey.titleLabel?.font = .systemFont(ofSize: annotationHeight * 0.65)
Expand Down Expand Up @@ -859,7 +861,6 @@ class KeyboardViewController: UIInputViewController {
commandBar.text = ""
commandBar.textColor = keyCharColor
commandBar.hide()
// conditionallySetAutoActionBtns()
}
}

Expand Down Expand Up @@ -1470,6 +1471,7 @@ class KeyboardViewController: UIInputViewController {
}
// Add partitions if the keyboard states dictate.
conditionallyShowAutoActionPartitions()
conditionallySetAutoActionBtns()

// Remove alternates view if it's present.
if self.view.viewWithTag(1001) != nil {
Expand Down

0 comments on commit 443b2da

Please sign in to comment.