Skip to content

Commit 2b544e0

Browse files
committed
#352 fix expand conditional, code formatting, remove number keys fix
1 parent 8a0cede commit 2b544e0

11 files changed

+154
-144
lines changed

Keyboards/KeyboardsBase/InterfaceVariables.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ var proxy: UITextDocumentProxy!
1212
// MARK: Display Variables
1313

1414
// Variables for the keyboard and its appearance.
15-
public var usingExpandedKeyboard = false;
1615
var keyboard = [[String]]()
16+
var usingExpandedKeyboard = false
1717
var allKeys = [String]()
1818
let specialKeys = [
1919
"shift", "delete", "ABC", "АБВ", "123", "#+=", "selectKeyboard", "space", "return", ".?123", "hideKeyboard",

Keyboards/KeyboardsBase/KeyboardViewController.swift

+56-38
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,32 @@ class KeyboardViewController: UIInputViewController {
1818
@IBOutlet var stackView2: UIStackView!
1919
@IBOutlet var stackView3: UIStackView!
2020

21-
2221
private var tipView: ToolTipView?
2322

2423
/// Changes the height of `stackViewNum` depending on device type and size.
2524
func conditionallyShowTopNumbersRow() {
2625
if DeviceType.isPhone {
2726
view.addConstraint(
2827
NSLayoutConstraint(
29-
item: stackViewNum!, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 0, constant: 0
28+
item: stackViewNum!, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1, constant: 0
3029
)
3130
)
3231
} else if DeviceType.isPad {
3332
// Update the size of the numbers row to add it to the view.
34-
// let numbersRowHeight = self.scribeKey.frame.height
35-
view.addConstraint(
36-
NSLayoutConstraint(
37-
item: stackViewNum!, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 0, constant: 0
33+
if usingExpandedKeyboard {
34+
let numbersRowHeight = scribeKey.frame.height
35+
view.addConstraint(
36+
NSLayoutConstraint(
37+
item: stackViewNum!, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1, constant: numbersRowHeight
38+
)
3839
)
39-
)
40+
} else {
41+
view.addConstraint(
42+
NSLayoutConstraint(
43+
item: stackViewNum!, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1, constant: 0
44+
)
45+
)
46+
}
4047
}
4148
}
4249

@@ -1545,6 +1552,15 @@ class KeyboardViewController: UIInputViewController {
15451552
keyboardView.backgroundColor? = keyboardBgColor
15461553
allNonSpecialKeys = allKeys.filter { !specialKeys.contains($0) }
15471554

1555+
// Check if the device has a home button and is large enough so we should use an expanded keyboard.
1556+
if DeviceType.isPad {
1557+
if UIScreen.main.bounds.width > 768 {
1558+
usingExpandedKeyboard = true
1559+
} else {
1560+
usingExpandedKeyboard = false
1561+
}
1562+
}
1563+
15481564
linkShadowBlendElements()
15491565
setAutoActionPartitions()
15501566
conditionallyShowTopNumbersRow()
@@ -1592,18 +1608,6 @@ class KeyboardViewController: UIInputViewController {
15921608
} catch {}
15931609
}
15941610

1595-
//Check if ipad device meets the criteria for expanded keyboard
1596-
if DeviceType.isPad {
1597-
//Check if device has home button, this will be used later to determine if we should use expanded keypad or not.
1598-
if #available(iOS 13.0, *), (keyboardView.safeAreaInsets.bottom <= 0 && UIScreen.main.bounds.width > 768) {
1599-
usingExpandedKeyboard = true;
1600-
}
1601-
else
1602-
{
1603-
usingExpandedKeyboard = false;
1604-
}
1605-
}
1606-
16071611
setKeyboard()
16081612
setCommaAndPeriodKeysConditionally()
16091613
setCommandBackground()
@@ -1633,8 +1637,7 @@ class KeyboardViewController: UIInputViewController {
16331637
}
16341638
} else {
16351639
letterKeyWidth = (UIScreen.main.bounds.width - 6) / CGFloat(letterKeys[0].count) * 0.9
1636-
//If we are using expanded keys the numberKeys array is empty, we use symbolKeys
1637-
numSymKeyWidth = (UIScreen.main.bounds.width - 6) / CGFloat( (usingExpandedKeyboard) == true ? symbolKeys[0].count: numberKeys[0].count) * 0.9
1640+
numSymKeyWidth = (UIScreen.main.bounds.width - 6) / CGFloat(symbolKeys[0].count) * 0.9
16381641
}
16391642

16401643
// Derive keyboard given current states and set widths.
@@ -1673,13 +1676,17 @@ class KeyboardViewController: UIInputViewController {
16731676
}
16741677
}
16751678

1676-
if ![.selectVerbConjugation, .selectCaseDeclension, .displayInformation].contains(commandState) { // normal keyboard view
1677-
for view in [stackView0, stackView1, stackView2, stackView3] {
1679+
if ![
1680+
.selectVerbConjugation, .selectCaseDeclension, .displayInformation
1681+
].contains(commandState) { // normal keyboard view
1682+
for view in [stackViewNum, stackView0, stackView1, stackView2, stackView3] {
16781683
view?.isUserInteractionEnabled = true
16791684
view?.isLayoutMarginsRelativeArrangement = true
16801685

16811686
// Set edge insets for stack views to provide vertical key spacing.
1682-
if view == stackView0 {
1687+
if view == stackViewNum {
1688+
view?.layoutMargins = UIEdgeInsets(top: 3, left: 0, bottom: 4, right: 0)
1689+
} else if view == stackView0 {
16831690
view?.layoutMargins = UIEdgeInsets(top: 3, left: 0, bottom: 8, right: 0)
16841691
} else if view == stackView1 {
16851692
view?.layoutMargins = UIEdgeInsets(top: 5, left: 0, bottom: 6, right: 0)
@@ -1827,13 +1834,25 @@ class KeyboardViewController: UIInputViewController {
18271834
}
18281835

18291836
keyboardKeys.append(btn)
1830-
switch row {
1831-
case 0: stackView0.addArrangedSubview(btn)
1832-
case 1: stackView1.addArrangedSubview(btn)
1833-
case 2: stackView2.addArrangedSubview(btn)
1834-
case 3: stackView3.addArrangedSubview(btn)
1835-
default:
1836-
break
1837+
if !usingExpandedKeyboard {
1838+
switch row {
1839+
case 0: stackView0.addArrangedSubview(btn)
1840+
case 1: stackView1.addArrangedSubview(btn)
1841+
case 2: stackView2.addArrangedSubview(btn)
1842+
case 3: stackView3.addArrangedSubview(btn)
1843+
default:
1844+
break
1845+
}
1846+
} else {
1847+
switch row {
1848+
case 0: stackViewNum.addArrangedSubview(btn)
1849+
case 1: stackView0.addArrangedSubview(btn)
1850+
case 2: stackView1.addArrangedSubview(btn)
1851+
case 3: stackView2.addArrangedSubview(btn)
1852+
case 4: stackView3.addArrangedSubview(btn)
1853+
default:
1854+
break
1855+
}
18371856
}
18381857

18391858
// Special key styling.
@@ -1924,7 +1943,7 @@ class KeyboardViewController: UIInputViewController {
19241943
} else {
19251944
widthOfSpacing = (
19261945
(UIScreen.main.bounds.width - 6.0)
1927-
- (CGFloat((usingExpandedKeyboard) == true ? symbolKeys[0].count : numberKeys[0].count) * numSymKeyWidth)
1946+
- (CGFloat(usingExpandedKeyboard == true ? symbolKeys[0].count : numberKeys[0].count) * numSymKeyWidth)
19281947
) / (CGFloat(letterKeys[0].count)
19291948
- 1.0
19301949
)
@@ -1979,7 +1998,7 @@ class KeyboardViewController: UIInputViewController {
19791998

19801999
} else {
19812000
// Load conjugation view.
1982-
for view in [stackView0, stackView1, stackView2, stackView3] {
2001+
for view in [stackViewNum, stackView0, stackView1, stackView2, stackView3] {
19832002
view?.isUserInteractionEnabled = false
19842003
}
19852004

@@ -2031,9 +2050,9 @@ class KeyboardViewController: UIInputViewController {
20312050
let letterKeysHaveCommaPeriod = userDefaults.bool(forKey: dictionaryKey)
20322051

20332052
if letterKeysHaveCommaPeriod {
2034-
letterKeys[3] = ["123", "selectKeyboard", ",", "space", ".", "return"]
2035-
} else {
2036-
letterKeys[3] = ["123", "selectKeyboard", "space", "return"]
2053+
let spaceIndex = letterKeys[3].firstIndex(where: {$0 == "space"})
2054+
letterKeys[3].insert(",", at: spaceIndex!)
2055+
letterKeys[3].insert(".", at: spaceIndex! + 2)
20372056
}
20382057
}
20392058

@@ -2468,8 +2487,7 @@ class KeyboardViewController: UIInputViewController {
24682487
capsLockPossible = true
24692488

24702489
case "123", ".?123":
2471-
(usingExpandedKeyboard) == true ? changeKeyboardToSymbolKeys() : changeKeyboardToNumberKeys()
2472-
2490+
usingExpandedKeyboard == true ? changeKeyboardToSymbolKeys() : changeKeyboardToNumberKeys()
24732491

24742492
case "#+=":
24752493
changeKeyboardToSymbolKeys()

Keyboards/LanguageKeyboards/English/ENInterfaceVariables.swift

+14-14
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ public enum EnglishKeyboardConstants {
3535
["q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "delete"],
3636
["a", "s", "d", "f", "g", "h", "j", "k", "l", "return"],
3737
["shift", "w", "x", "c", "v", "b", "n", "m", ",", ".", "shift"],
38-
[".?123", "selectKeyboard", "space", ".?123", "hideKeyboard"], // "undo"
38+
["selectKeyboard", ".?123", "space", ".?123", "hideKeyboard"], // "undo"
3939
]
4040

4141
static let numberKeysPad = [
4242
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "delete"],
4343
["@", "#", "$", "&", "*", "(", ")", "'", "\"", "return"],
4444
["#+=", "%", "_", "+", "=", "/", ";", ":", ",", ".", "#+="],
45-
["ABC", "selectKeyboard", "space", "ABC", "hideKeyboard"], // "undo"
45+
["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"], // "undo"
4646
]
4747

4848
static let symbolKeysPad = [
4949
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "delete"],
5050
["", "£", "¥", "_", "^", "[", "]", "{", "}", "return"],
5151
["123", "§", "|", "~", "...", "\\", "<", ">", "!", "?", "123"],
52-
["ABC", "selectKeyboard", "space", "ABC", "hideKeyboard"], // "undo"
52+
["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"], // "undo"
5353
]
5454

5555
// Expanded iPad keyboard layouts for wider devices.
@@ -98,21 +98,21 @@ func getENKeys() {
9898
rightKeyChars = ["p", "0", "\"", "=", "·"]
9999
centralKeyChars = allKeys.filter { !leftKeyChars.contains($0) && !rightKeyChars.contains($0) }
100100
} else {
101-
if (usingExpandedKeyboard)
102-
{
103-
letterKeys = EnglishKeyboardConstants.letterKeysPadExpanded;
104-
symbolKeys = EnglishKeyboardConstants.symbolKeysPadExpanded;
105-
}
106-
else
107-
{
101+
// Use the expanded keys layout if the iPad is wide enough and has no home button.
102+
if usingExpandedKeyboard {
103+
letterKeys = EnglishKeyboardConstants.letterKeysPadExpanded
104+
symbolKeys = EnglishKeyboardConstants.symbolKeysPadExpanded
105+
106+
allKeys = Array(letterKeys.joined()) + Array(symbolKeys.joined())
107+
} else {
108108
letterKeys = EnglishKeyboardConstants.letterKeysPad
109109
numberKeys = EnglishKeyboardConstants.numberKeysPad
110110
symbolKeys = EnglishKeyboardConstants.symbolKeysPad
111-
}
112-
// If the iPad is too small to have a numbers row.
113-
letterKeys.removeFirst(1)
114111

115-
allKeys = Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())
112+
letterKeys.removeFirst(1)
113+
114+
allKeys = Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())
115+
}
116116

117117
leftKeyChars = ["q", "1"]
118118
// TODO: add "p" to rightKeyChar if the keyboard has 4 rows.

Keyboards/LanguageKeyboards/French/FR-AZERTYInterfaceVariables.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@ func getFRKeys() {
9696
rightKeyChars = ["p", "m", "0", "\"", "=", "·"]
9797
centralKeyChars = allKeys.filter { !leftKeyChars.contains($0) && !rightKeyChars.contains($0) }
9898
} else {
99-
if (usingExpandedKeyboard)
100-
{
101-
letterKeys = FrenchKeyboardConstants.letterKeysPadExpanded;
102-
symbolKeys = FrenchKeyboardConstants.symbolKeysPadExpanded;
103-
}
104-
else
105-
{
99+
// Use the expanded keys layout if the iPad is wide enough and has no home button.
100+
if usingExpandedKeyboard {
101+
letterKeys = FrenchKeyboardConstants.letterKeysPadExpanded
102+
symbolKeys = FrenchKeyboardConstants.symbolKeysPadExpanded
103+
104+
allKeys = Array(letterKeys.joined()) + Array(symbolKeys.joined())
105+
} else {
106106
letterKeys = FrenchKeyboardConstants.letterKeysPad
107107
numberKeys = FrenchKeyboardConstants.numberKeysPad
108108
symbolKeys = FrenchKeyboardConstants.symbolKeysPad
109-
}
110-
// If the iPad is too small to have a numbers row.
111-
letterKeys.removeFirst(1)
112109

113-
allKeys = Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())
110+
letterKeys.removeFirst(1)
111+
112+
allKeys = Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())
113+
}
114114

115115
leftKeyChars = ["q", "a", "1", "@", "~"]
116116
// TODO: add "p" to rightKeyChar if the keyboard has 4 rows.

Keyboards/LanguageKeyboards/French/FR-QWERTYInterfaceVariables.swift

+13-14
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public enum FrenchQWERTYKeyboardConstants {
4747
["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "delete"],
4848
["~", "", "[", "]", "{", "}", "^", "$", "£", "¥", "return"],
4949
["123", "§", "<", ">", "|", "\\", "...", "·", "?", "'", "123"],
50-
["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"], // "undo"
50+
["ABC", "selectKeyboard", "space", "ABC", "hideKeyboard"], // "undo"
5151
]
5252

5353
// Expanded iPad keyboard layouts for wider devices.
@@ -56,15 +56,15 @@ public enum FrenchQWERTYKeyboardConstants {
5656
["indent", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "^", "ç", ":"],
5757
["uppercase", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "è", "à", "return"],
5858
["shift", "ù", "z", "x", "c", "v", "b", "n", "m", ",", ".", "é", "shift"],
59-
["selectKeyboard", ".?123", "microphone", "space", ".?123", "hideKeyboard"], // "microphone", "scribble"
59+
["selectKeyboard", ".?123", "space", ".?123", "hideKeyboard"], // "microphone", "scribble"
6060
]
6161

6262
static let symbolKeysPadExpanded = [
6363
["`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "<", ">", "delete"],
6464
["indent", "[", "]", "{", "}", "#", "%", "^", "*", "+", "=", "\"", "|", "~"],
6565
["uppercase", "-", "/", ":", ";", "(", ")", "$", "&", "@", "£", "¥", "~", "return"], // "undo"
6666
["shift", "...", ".", ",", "?", "!", "'", "\"", "_", ""], // "redo"
67-
["selectKeyboard", "ABC", "microphone", "space", "ABC", "hideKeyboard"], // "microphone", "scribble"
67+
["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"], // "microphone", "scribble"
6868
]
6969

7070
// Alternate key vars.
@@ -94,22 +94,21 @@ func getFRQWERTYKeys() {
9494
rightKeyChars = ["p", "m", "0", "\"", "=", "·"]
9595
centralKeyChars = allKeys.filter { !leftKeyChars.contains($0) && !rightKeyChars.contains($0) }
9696
} else {
97-
if (usingExpandedKeyboard)
98-
{
99-
letterKeys = FrenchQWERTYKeyboardConstants.letterKeysPadExpanded;
100-
symbolKeys = FrenchQWERTYKeyboardConstants.symbolKeysPadExpanded;
101-
}
102-
else
103-
{
97+
// Use the expanded keys layout if the iPad is wide enough and has no home button.
98+
if usingExpandedKeyboard {
99+
letterKeys = FrenchQWERTYKeyboardConstants.letterKeysPadExpanded
100+
symbolKeys = FrenchQWERTYKeyboardConstants.symbolKeysPadExpanded
101+
102+
allKeys = Array(letterKeys.joined()) + Array(symbolKeys.joined())
103+
} else {
104104
letterKeys = FrenchQWERTYKeyboardConstants.letterKeysPad
105105
numberKeys = FrenchQWERTYKeyboardConstants.numberKeysPad
106106
symbolKeys = FrenchQWERTYKeyboardConstants.symbolKeysPad
107-
}
108107

109-
// If the iPad is too small to have a numbers row.
110-
letterKeys.removeFirst(1)
108+
letterKeys.removeFirst(1)
111109

112-
allKeys = Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())
110+
allKeys = Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())
111+
}
113112

114113
leftKeyChars = ["q", "a", "1", "@", "~"]
115114
rightKeyChars = []

Keyboards/LanguageKeyboards/German/DEInterfaceVariables.swift

+10-11
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,21 @@ func getDEKeys() {
9999
rightKeyChars = ["ü", "ä", "0", "\"", "=", "·"]
100100
centralKeyChars = allKeys.filter { !leftKeyChars.contains($0) && !rightKeyChars.contains($0) }
101101
} else {
102-
if (usingExpandedKeyboard)
103-
{
104-
letterKeys = GermanKeyboardConstants.letterKeysPadExpanded;
105-
symbolKeys = GermanKeyboardConstants.symbolKeysPadExpanded;
106-
}
107-
else
108-
{
102+
// Use the expanded keys layout if the iPad is wide enough and has no home button.
103+
if usingExpandedKeyboard {
104+
letterKeys = GermanKeyboardConstants.letterKeysPadExpanded
105+
symbolKeys = GermanKeyboardConstants.symbolKeysPadExpanded
106+
107+
allKeys = Array(letterKeys.joined()) + Array(symbolKeys.joined())
108+
} else {
109109
letterKeys = GermanKeyboardConstants.letterKeysPad
110110
numberKeys = GermanKeyboardConstants.numberKeysPad
111111
symbolKeys = GermanKeyboardConstants.symbolKeysPad
112-
}
113112

114-
// If the iPad is too small to have a numbers row.
115-
letterKeys.removeFirst(1)
113+
letterKeys.removeFirst(1)
116114

117-
allKeys = Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())
115+
allKeys = Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())
116+
}
118117

119118
leftKeyChars = ["q", "a", "1", "\"", "$"]
120119
// TODO: add "ü" to rightKeyChar if the keyboard has 4 rows.

0 commit comments

Comments
 (0)