Skip to content

Commit 19999fc

Browse files
authored
Merge pull request #35 from cemolcay/fix/cemolcay-keyboard
Fix/cemolcay keyboard
2 parents 086575f + 8491b52 commit 19999fc

File tree

3 files changed

+54
-35
lines changed

3 files changed

+54
-35
lines changed

Keyboard/DefaultKeyboard/CustomKeyboard.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class CustomKeyboard: UIView, KeyboardLayoutDelegate {
3737
case Symbols
3838
}
3939

40-
private(set) var previousShiftState: CustomKeyboardShiftState = .Once
4140
private(set) var keyboardLayoutState: CustomKeyboardLayoutState = .Letters(shiftState: CustomKeyboardShiftState.Once) {
4241
didSet {
4342
keyboardLayoutStateDidChange(oldState: oldValue, newState: keyboardLayoutState)
@@ -128,6 +127,20 @@ public class CustomKeyboard: UIView, KeyboardLayoutDelegate {
128127
return getKeyboardLayout(ofState: keyboardLayoutState)
129128
}
130129

130+
public func enumerateKeyboardLayouts(enumerate: (KeyboardLayout) -> Void) {
131+
let layouts = [
132+
keyboardLayout.uppercase,
133+
keyboardLayout.uppercaseToggled,
134+
keyboardLayout.lowercase,
135+
keyboardLayout.numbers,
136+
keyboardLayout.symbols,
137+
]
138+
139+
for layout in layouts {
140+
enumerate(layout)
141+
}
142+
}
143+
131144
public func keyboardLayoutStateDidChange(oldState oldState: CustomKeyboardLayoutState?, newState: CustomKeyboardLayoutState) {
132145
// Remove old keyboard layout
133146
if let oldState = oldState {
@@ -140,11 +153,6 @@ public class CustomKeyboard: UIView, KeyboardLayoutDelegate {
140153
let newKeyboardLayout = getKeyboardLayout(ofState: newState)
141154
newKeyboardLayout.delegate = self
142155
addSubview(newKeyboardLayout)
143-
144-
// Set previous shift state
145-
if case CustomKeyboardLayoutState.Letters(let shiftState) = newState {
146-
previousShiftState = shiftState
147-
}
148156
}
149157

150158
public func reload() {
@@ -260,6 +268,8 @@ public class CustomKeyboard: UIView, KeyboardLayoutDelegate {
260268
}
261269

262270
public func keyboardLayout(keyboardLayout: KeyboardLayout, didKeyPressEnd keyboardButton: KeyboardButton) {
271+
delegate?.customKeyboard?(self, keyboardButtonPressed: keyboardButton)
272+
263273
// If keyboard key is pressed notify no questions asked
264274
if case KeyboardButtonType.Key(let text) = keyboardButton.type {
265275
delegate?.customKeyboard?(self, keyButtonPressed: text)
@@ -287,7 +297,7 @@ public class CustomKeyboard: UIView, KeyboardLayoutDelegate {
287297

288298
// Update keyboard layout state
289299
case .Letters:
290-
keyboardLayoutState = .Letters(shiftState: previousShiftState)
300+
keyboardLayoutState = .Letters(shiftState: .Off)
291301
case .Numbers:
292302
keyboardLayoutState = .Numbers
293303
case .Symbols:

Keyboard/KeyboardLayoutEngine/KeyboardButton.swift

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public var KeyboardButtonPopupViewTag: Int = 101
9898
public var KeyboardButtonMenuViewTag: Int = 102
9999

100100
public class KeyboardButton: UIView {
101-
public var type: KeyboardButtonType = .Key("")
102-
public var widthInRow: KeyboardButtonWidth = .Dynamic
103-
public var style: KeyboardButtonStyle!
101+
public var type: KeyboardButtonType = .Key("") { didSet { reload() } }
102+
public var widthInRow: KeyboardButtonWidth = .Dynamic { didSet { reload() } }
103+
public var style: KeyboardButtonStyle! { didSet { reload() } }
104104
public var keyMenu: KeyMenu?
105105

106106
public var textLabel: UILabel?
@@ -122,8 +122,39 @@ public class KeyboardButton: UIView {
122122
self.style = style
123123
self.widthInRow = width
124124
self.identifier = identifier
125+
reload()
126+
}
127+
128+
public required init?(coder aDecoder: NSCoder) {
129+
super.init(coder: aDecoder)
130+
reload()
131+
}
132+
133+
private func reload() {
125134
userInteractionEnabled = true
126-
setupAppearance()
135+
backgroundColor = style.backgroundColor
136+
layer.cornerRadius = style.cornerRadius
137+
138+
// border
139+
layer.borderColor = style.borderColor.CGColor
140+
layer.borderWidth = style.borderWidth
141+
142+
// shadow
143+
if style.shadowEnabled {
144+
layer.shadowColor = style.shadowColor.CGColor
145+
layer.shadowOpacity = style.shadowOpacity
146+
layer.shadowOffset = style.shadowOffset
147+
layer.shadowRadius = style.shadowRadius
148+
if let path = style.shadowPath {
149+
layer.shadowPath = path.CGPath
150+
}
151+
}
152+
153+
// content
154+
textLabel?.removeFromSuperview()
155+
textLabel = nil
156+
imageView?.removeFromSuperview()
157+
imageView = nil
127158

128159
switch type {
129160
case .Key(let text):
@@ -153,28 +184,6 @@ public class KeyboardButton: UIView {
153184
}
154185
}
155186

156-
public required init?(coder aDecoder: NSCoder) {
157-
super.init(coder: aDecoder)
158-
}
159-
160-
private func setupAppearance() {
161-
backgroundColor = style.backgroundColor
162-
layer.cornerRadius = style.cornerRadius
163-
// border
164-
layer.borderColor = style.borderColor.CGColor
165-
layer.borderWidth = style.borderWidth
166-
// shadow
167-
if style.shadowEnabled {
168-
layer.shadowColor = style.shadowColor.CGColor
169-
layer.shadowOpacity = style.shadowOpacity
170-
layer.shadowOffset = style.shadowOffset
171-
layer.shadowRadius = style.shadowRadius
172-
if let path = style.shadowPath {
173-
layer.shadowPath = path.CGPath
174-
}
175-
}
176-
}
177-
178187
// MARK: Layout
179188
public override func layoutSubviews() {
180189
super.layoutSubviews()

KeyboardLayoutEngine.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "KeyboardLayoutEngine"
19-
s.version = "0.9"
19+
s.version = "0.9.1"
2020
s.summary = "⌨️ Simplest custom keyboard generator for iOS ever!"
2121

2222
# This description is used to generate tags and improve search results.
@@ -336,7 +336,7 @@ optional func defaultKeyboardDidPressReturnButton(defaultKeyboard: DefaultKeyboa
336336
# Supports git, hg, bzr, svn and HTTP.
337337
#
338338

339-
s.source = { :git => "https://github.com/cemolcay/KeyboardLayoutEngine.git", :tag => "0.9" }
339+
s.source = { :git => "https://github.com/cemolcay/KeyboardLayoutEngine.git", :tag => "0.9.1" }
340340

341341

342342
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #

0 commit comments

Comments
 (0)