From a397f058f9fc36b619291c0bb746df22df5e5956 Mon Sep 17 00:00:00 2001 From: Geoffrey Liu Date: Wed, 9 Mar 2022 21:10:30 -0800 Subject: [PATCH] Reset keyboard state --- .../CustomKeyboard/WordleKeyboardInputView.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/WordleWithFriends/Views/CustomKeyboard/WordleKeyboardInputView.swift b/WordleWithFriends/Views/CustomKeyboard/WordleKeyboardInputView.swift index 65f4493..ad23f41 100644 --- a/WordleWithFriends/Views/CustomKeyboard/WordleKeyboardInputView.swift +++ b/WordleWithFriends/Views/CustomKeyboard/WordleKeyboardInputView.swift @@ -24,7 +24,7 @@ final class WordleKeyboardInputView: UIInputView { private var keyReferences: [WeakRef] = [] private weak var forfeitKey: WordleKeyboardKey? - private static let keyboardLayout: [[WordleKeyboardKey]] = { + private let keyboardLayout: [[WordleKeyboardKey]] = { let characterRows = ["QWERTYUIOP", "ASDFGHJKL", "ZXCVBNM"] var keyRows = characterRows.map { row in row.map { @@ -65,7 +65,7 @@ final class WordleKeyboardInputView: UIInputView { return stackView }() - static func getPortraitModeKeyWidth() -> CGFloat { + func getPortraitModeKeyWidth() -> CGFloat { let keyboardWidth = UIScreen.main.bounds.width let keyboardRowKeyWidths = keyboardLayout.enumerated().map { index, row -> CGFloat in let totalSpace = row.reduce(0) { res, key in @@ -99,7 +99,7 @@ final class WordleKeyboardInputView: UIInputView { setupKeyboard() } - private func setupKeyboard(keyWidth: CGFloat = getPortraitModeKeyWidth()) { + private func setupKeyboard() { backgroundColor = .tertiarySystemFill translatesAutoresizingMaskIntoConstraints = false @@ -110,7 +110,9 @@ final class WordleKeyboardInputView: UIInputView { mainStackView.removeAllArrangedSubviews() keyReferences = [] - type(of: self).keyboardLayout.enumerated().forEach { index, row in + let keyWidth = getPortraitModeKeyWidth() + + keyboardLayout.enumerated().forEach { index, row in let keyboardRow = KeyboardRow() keyboardRow.delegate = delegate let keyRowRefs = keyboardRow.configure(keys: row, keyWidth: keyWidth) @@ -131,6 +133,7 @@ final class WordleKeyboardInputView: UIInputView { let operationKeysRow = KeyboardRow() operationKeysRow.delegate = delegate + if gamemode == .infinite { operationKeysRow.configure(keys: [forfeitKey, mainMenuKey], keyWidth: keyWidth) } else {