Skip to content

Commit 82aa61f

Browse files
committed
Merge pull request #16 from cemolcay/fix/cemolcay-default-keyboard-paddings
Fix paddings and add landscape row padding
2 parents d7ed60b + 1210236 commit 82aa61f

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

Keyboard/DefaultKeyboard/DefaultKeyboardLayout.swift

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ import UIKit
1111
// MARK: - Layout Style
1212
public var DefaultKeyboardLayoutStyle = KeyboardLayoutStyle(
1313
topPadding: 10,
14-
bottomPadding: 5,
15-
rowPadding: 13,
14+
bottomPadding: 4,
15+
rowPadding: 12,
1616
backgroundColor: UIColor(red: 208.0/255.0, green: 213.0/255.0, blue: 219.0/255.0, alpha: 1))
1717

1818
// MARK: - Row Style
1919
public var DefaultKeyboardRowStyle = KeyboardRowStyle(
20-
leadingPadding: 5,
21-
trailingPadding: 5,
20+
leadingPadding: 3,
21+
trailingPadding: 3,
2222
buttonsPadding: 6)
2323

2424
public var DefaultKeyboardSecondRowStyle = KeyboardRowStyle(
25-
leadingPadding: 20,
26-
trailingPadding: 20,
25+
leadingPadding: 22,
26+
trailingPadding: 22,
2727
buttonsPadding: 6)
2828

2929
public var DefaultKeyboardChildRowStyle = KeyboardRowStyle(
30-
leadingPadding: 10,
31-
trailingPadding: 10,
30+
leadingPadding: 12,
31+
trailingPadding: 12,
3232
buttonsPadding: 6)
3333

3434
// MARK: - Button Style
@@ -139,7 +139,7 @@ public enum DefaultKeyboardLayout {
139139
KeyboardButton(
140140
type: .Image(UIImage(named: toggled ? "shiftToggled" : "shiftToggledOnce", inBundle: NSBundle(forClass: DefaultKeyboard.self), compatibleWithTraitCollection: nil)),
141141
style: DefaultKeyboardShiftButtonStyle,
142-
width: .Relative(percent: 0.13),
142+
width: .Relative(percent: 0.115),
143143
identifier: toggled ? DefaultKeyboardIdentifier.ShiftToggled.rawValue : DefaultKeyboardIdentifier.ShiftToggledOnce.rawValue),
144144
KeyboardRow(
145145
style: DefaultKeyboardChildRowStyle,
@@ -156,7 +156,7 @@ public enum DefaultKeyboardLayout {
156156
KeyboardButton(
157157
type: .Image(UIImage(named: "backspace", inBundle: NSBundle(forClass: DefaultKeyboard.self), compatibleWithTraitCollection: nil)),
158158
style: DefaultKeyboardBackspaceButtonStyle,
159-
width: .Relative(percent: 0.13),
159+
width: .Relative(percent: 0.115),
160160
identifier: DefaultKeyboardIdentifier.Backspace.rawValue),
161161
]
162162
),
@@ -166,12 +166,12 @@ public enum DefaultKeyboardLayout {
166166
KeyboardButton(
167167
type: .Text("123"),
168168
style: DefaultKeyboardNumbersButtonStyle,
169-
width: .Relative(percent: 0.13),
169+
width: .Relative(percent: 0.115),
170170
identifier: DefaultKeyboardIdentifier.Numbers.rawValue),
171171
KeyboardButton(
172172
type: .Image(UIImage(named: "globe", inBundle: NSBundle(forClass: DefaultKeyboard.self), compatibleWithTraitCollection: nil)),
173173
style: DefaultKeyboardGlobeButtonStyle,
174-
width: .Static(width: 40),
174+
width: .Relative(percent: 0.115),
175175
identifier: DefaultKeyboardIdentifier.Globe.rawValue),
176176
KeyboardButton(
177177
type: .Text("space"),
@@ -180,7 +180,7 @@ public enum DefaultKeyboardLayout {
180180
KeyboardButton(
181181
type: .Text("return"),
182182
style: DefaultKeyboardReturnButtonStyle,
183-
width: .Relative(percent: 0.2),
183+
width: .Relative(percent: 0.18),
184184
identifier: DefaultKeyboardIdentifier.Return.rawValue),
185185
]
186186
),
@@ -227,7 +227,7 @@ public enum DefaultKeyboardLayout {
227227
KeyboardButton(
228228
type: .Image(UIImage(named: "shift", inBundle: NSBundle(forClass: DefaultKeyboard.self), compatibleWithTraitCollection: nil)),
229229
style: DefaultKeyboardShiftButtonStyle,
230-
width: .Relative(percent: 0.13),
230+
width: .Relative(percent: 0.115),
231231
identifier: DefaultKeyboardIdentifier.Shift.rawValue),
232232
KeyboardRow(
233233
style: DefaultKeyboardChildRowStyle,
@@ -244,7 +244,7 @@ public enum DefaultKeyboardLayout {
244244
KeyboardButton(
245245
type: .Image(UIImage(named: "backspace", inBundle: NSBundle(forClass: DefaultKeyboard.self), compatibleWithTraitCollection: nil)),
246246
style: DefaultKeyboardBackspaceButtonStyle,
247-
width: .Relative(percent: 0.13),
247+
width: .Relative(percent: 0.115),
248248
identifier: DefaultKeyboardIdentifier.Backspace.rawValue),
249249
]
250250
),
@@ -254,12 +254,12 @@ public enum DefaultKeyboardLayout {
254254
KeyboardButton(
255255
type: .Text("123"),
256256
style: DefaultKeyboardNumbersButtonStyle,
257-
width: .Relative(percent: 0.13),
257+
width: .Relative(percent: 0.115),
258258
identifier: DefaultKeyboardIdentifier.Numbers.rawValue),
259259
KeyboardButton(
260260
type: .Image(UIImage(named: "globe", inBundle: NSBundle(forClass: DefaultKeyboard.self), compatibleWithTraitCollection: nil)),
261261
style: DefaultKeyboardGlobeButtonStyle,
262-
width: .Static(width: 40),
262+
width: .Relative(percent: 0.115),
263263
identifier: DefaultKeyboardIdentifier.Globe.rawValue),
264264
KeyboardButton(
265265
type: .Text("space"),
@@ -268,7 +268,7 @@ public enum DefaultKeyboardLayout {
268268
KeyboardButton(
269269
type: .Text("return"),
270270
style: DefaultKeyboardReturnButtonStyle,
271-
width: .Relative(percent: 0.2),
271+
width: .Relative(percent: 0.18),
272272
identifier: DefaultKeyboardIdentifier.Return.rawValue),
273273
]
274274
),
@@ -316,7 +316,7 @@ public enum DefaultKeyboardLayout {
316316
KeyboardButton(
317317
type: .Text("#+="),
318318
style: DefaultKeyboardNumbersButtonStyle,
319-
width: .Relative(percent: 0.13),
319+
width: .Relative(percent: 0.115),
320320
identifier: DefaultKeyboardIdentifier.Symbols.rawValue),
321321
KeyboardRow(
322322
style: DefaultKeyboardChildRowStyle,
@@ -331,7 +331,7 @@ public enum DefaultKeyboardLayout {
331331
KeyboardButton(
332332
type: .Image(UIImage(named: "backspace", inBundle: NSBundle(forClass: DefaultKeyboard.self), compatibleWithTraitCollection: nil)),
333333
style: DefaultKeyboardBackspaceButtonStyle,
334-
width: .Relative(percent: 0.13),
334+
width: .Relative(percent: 0.115),
335335
identifier: DefaultKeyboardIdentifier.Backspace.rawValue),
336336
]
337337
),
@@ -341,12 +341,12 @@ public enum DefaultKeyboardLayout {
341341
KeyboardButton(
342342
type: .Text("ABC"),
343343
style: DefaultKeyboardNumbersButtonStyle,
344-
width: .Relative(percent: 0.13),
344+
width: .Relative(percent: 0.115),
345345
identifier: DefaultKeyboardIdentifier.Letters.rawValue),
346346
KeyboardButton(
347347
type: .Image(UIImage(named: "globe", inBundle: NSBundle(forClass: DefaultKeyboard.self), compatibleWithTraitCollection: nil)),
348348
style: DefaultKeyboardGlobeButtonStyle,
349-
width: .Static(width: 40),
349+
width: .Relative(percent: 0.115),
350350
identifier: DefaultKeyboardIdentifier.Globe.rawValue),
351351
KeyboardButton(
352352
type: .Text("space"),
@@ -355,7 +355,7 @@ public enum DefaultKeyboardLayout {
355355
KeyboardButton(
356356
type: .Text("return"),
357357
style: DefaultKeyboardReturnButtonStyle,
358-
width: .Relative(percent: 0.2),
358+
width: .Relative(percent: 0.18),
359359
identifier: DefaultKeyboardIdentifier.Return.rawValue),
360360
]
361361
),
@@ -403,7 +403,7 @@ public enum DefaultKeyboardLayout {
403403
KeyboardButton(
404404
type: .Text("123"),
405405
style: DefaultKeyboardNumbersButtonStyle,
406-
width: .Relative(percent: 0.13),
406+
width: .Relative(percent: 0.115),
407407
identifier: DefaultKeyboardIdentifier.Numbers.rawValue),
408408
KeyboardRow(
409409
style: DefaultKeyboardChildRowStyle,
@@ -418,7 +418,7 @@ public enum DefaultKeyboardLayout {
418418
KeyboardButton(
419419
type: .Image(UIImage(named: "backspace", inBundle: NSBundle(forClass: DefaultKeyboard.self), compatibleWithTraitCollection: nil)),
420420
style: DefaultKeyboardBackspaceButtonStyle,
421-
width: .Relative(percent: 0.13),
421+
width: .Relative(percent: 0.115),
422422
identifier: DefaultKeyboardIdentifier.Backspace.rawValue),
423423
]
424424
),
@@ -428,12 +428,12 @@ public enum DefaultKeyboardLayout {
428428
KeyboardButton(
429429
type: .Text("ABC"),
430430
style: DefaultKeyboardNumbersButtonStyle,
431-
width: .Relative(percent: 0.13),
431+
width: .Relative(percent: 0.115),
432432
identifier: DefaultKeyboardIdentifier.Letters.rawValue),
433433
KeyboardButton(
434434
type: .Image(UIImage(named: "globe", inBundle: NSBundle(forClass: DefaultKeyboard.self), compatibleWithTraitCollection: nil)),
435435
style: DefaultKeyboardGlobeButtonStyle,
436-
width: .Static(width: 40),
436+
width: .Relative(percent: 0.115),
437437
identifier: DefaultKeyboardIdentifier.Globe.rawValue),
438438
KeyboardButton(
439439
type: .Text("space"),
@@ -442,7 +442,7 @@ public enum DefaultKeyboardLayout {
442442
KeyboardButton(
443443
type: .Text("return"),
444444
style: DefaultKeyboardReturnButtonStyle,
445-
width: .Relative(percent: 0.2),
445+
width: .Relative(percent: 0.18),
446446
identifier: DefaultKeyboardIdentifier.Return.rawValue),
447447
]
448448
),

Keyboard/KeyboardLayoutEngine/KeyboardLayout.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ public struct KeyboardLayoutStyle {
2727
public var topPadding: CGFloat
2828
public var bottomPadding: CGFloat
2929
public var rowPadding: CGFloat
30+
public var rowPaddingLandscape: CGFloat
3031
public var backgroundColor: UIColor
3132

3233
public init(
3334
topPadding: CGFloat = 5,
3435
bottomPadding: CGFloat = 5,
3536
rowPadding: CGFloat = 15,
37+
rowPaddingPortrait: CGFloat = 8,
3638
backgroundColor: UIColor = UIColor(red: 208.0/255.0, green: 213.0/255.0, blue: 219.0/255.0, alpha: 1)) {
3739
self.topPadding = topPadding
3840
self.bottomPadding = bottomPadding
3941
self.rowPadding = rowPadding
42+
self.rowPaddingLandscape = rowPaddingLandscape
4043
self.backgroundColor = backgroundColor
4144
}
4245
}
@@ -80,17 +83,21 @@ public class KeyboardLayout: UIView {
8083
y: currentY,
8184
width: frame.size.width,
8285
height: optimumRowHeight)
83-
currentY += optimumRowHeight + style.rowPadding
86+
currentY += optimumRowHeight + getRowPadding()
8487
}
8588
}
8689

8790
private func getOptimumRowHeight(forView view: UIView) -> CGFloat {
8891
let height = view.frame.size.height
89-
let rowPaddings = CGFloat(max(rows.count - 1, 0)) * style.rowPadding
92+
let rowPaddings = CGFloat(max(rows.count - 1, 0)) * getRowPadding()
9093
let totalPaddings = rowPaddings + style.topPadding + style.bottomPadding
9194
return max(0, (height - totalPaddings) / CGFloat(rows.count))
9295
}
9396

97+
private func getRowPadding() -> CGFloat {
98+
return frame.size.width > frame.size.height ? style.rowPaddingLandscape : style.rowPadding
99+
}
100+
94101
// MARK: Manage Buttons
95102
public func getKeyboardButton(atRowIndex rowIndex: Int, buttonIndex: Int) -> KeyboardButton? {
96103
if let row = rows[safe: rowIndex], let button = row.characters[safe: buttonIndex] as? KeyboardButton {

0 commit comments

Comments
 (0)