Skip to content

Commit 475f225

Browse files
committed
Add reload function
1 parent 24bfbec commit 475f225

File tree

1 file changed

+56
-12
lines changed

1 file changed

+56
-12
lines changed

Keyboard/DefaultKeyboard/CustomKeyboard.swift

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ import UIKit
2020

2121
// MARK: - CustomKeyboard
2222
public class CustomKeyboard: UIView, KeyboardLayoutDelegate {
23-
public var uppercaseToggledLayout: KeyboardLayout!
24-
public var uppercaseLayout: KeyboardLayout!
25-
public var lowercaseLayout: KeyboardLayout!
26-
public var numbersLayout: KeyboardLayout!
27-
public var symbolsLayout: KeyboardLayout!
28-
2923
public var shiftToggleInterval: NSTimeInterval = 0.5
3024
private var shiftToggleTimer: NSTimer?
3125
private var shiftCanBeToggled: Bool = false
@@ -36,6 +30,51 @@ public class CustomKeyboard: UIView, KeyboardLayoutDelegate {
3630
private var backspaceDeleteTimer: NSTimer?
3731
private var backspaceAutoDeleteModeTimer: NSTimer?
3832

33+
public var uppercaseToggledLayout: KeyboardLayout! {
34+
didSet {
35+
guard currentLayout != nil && oldValue != nil else { return }
36+
if currentLayout == oldValue {
37+
currentLayout = uppercaseToggledLayout
38+
}
39+
}
40+
}
41+
42+
public var uppercaseLayout: KeyboardLayout! {
43+
didSet {
44+
guard currentLayout != nil && oldValue != nil else { return }
45+
if currentLayout == oldValue {
46+
currentLayout = uppercaseLayout
47+
}
48+
}
49+
}
50+
51+
public var lowercaseLayout: KeyboardLayout! {
52+
didSet {
53+
guard currentLayout != nil && oldValue != nil else { return }
54+
if currentLayout == oldValue {
55+
currentLayout = lowercaseLayout
56+
}
57+
}
58+
}
59+
60+
public var numbersLayout: KeyboardLayout! {
61+
didSet {
62+
guard currentLayout != nil && oldValue != nil else { return }
63+
if currentLayout == oldValue {
64+
currentLayout = numbersLayout
65+
}
66+
}
67+
}
68+
69+
public var symbolsLayout: KeyboardLayout! {
70+
didSet {
71+
guard currentLayout != nil && oldValue != nil else { return }
72+
if currentLayout == oldValue {
73+
currentLayout = symbolsLayout
74+
}
75+
}
76+
}
77+
3978
private var lastLetterLayout: KeyboardLayout?
4079
private(set) var currentLayout: KeyboardLayout! {
4180
didSet {
@@ -65,16 +104,12 @@ public class CustomKeyboard: UIView, KeyboardLayoutDelegate {
65104
}
66105

67106
private func defaultInit() {
68-
uppercaseToggledLayout = CustomKeyboardLayout.UppercaseToggled.keyboardLayout
69-
uppercaseLayout = CustomKeyboardLayout.Uppercase.keyboardLayout
70-
lowercaseLayout = CustomKeyboardLayout.Lowercase.keyboardLayout
71-
numbersLayout = CustomKeyboardLayout.Numbers.keyboardLayout
72-
symbolsLayout = CustomKeyboardLayout.Symbols.keyboardLayout
73-
107+
reload()
74108
currentLayout = uppercaseLayout
75109
addSubview(currentLayout)
76110
}
77111

112+
// MARK: Layout
78113
public override func layoutSubviews() {
79114
super.layoutSubviews()
80115
currentLayout?.frame = CGRect(
@@ -84,6 +119,15 @@ public class CustomKeyboard: UIView, KeyboardLayoutDelegate {
84119
height: frame.size.height)
85120
}
86121

122+
// MARK: Reload
123+
public func reload() {
124+
uppercaseToggledLayout = CustomKeyboardLayout.UppercaseToggled.keyboardLayout
125+
uppercaseLayout = CustomKeyboardLayout.Uppercase.keyboardLayout
126+
lowercaseLayout = CustomKeyboardLayout.Lowercase.keyboardLayout
127+
numbersLayout = CustomKeyboardLayout.Numbers.keyboardLayout
128+
symbolsLayout = CustomKeyboardLayout.Symbols.keyboardLayout
129+
}
130+
87131
// MARK: Backspace Auto Delete
88132
private func startBackspaceAutoDeleteModeTimer() {
89133
backspaceAutoDeleteModeTimer = NSTimer.scheduledTimerWithTimeInterval(

0 commit comments

Comments
 (0)