Skip to content

Commit

Permalink
fix(ios): add more logging to determine first call for keyboard size
Browse files Browse the repository at this point in the history
also avoid call to userdefaults unless key exists
  • Loading branch information
sgschantz committed Dec 6, 2024
1 parent f2ff959 commit b4fb78a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private class CustomInputView: UIInputView, UIInputViewAudioFeedback {
}

func setConstraints() {
os_log("CustomInputView setConstraints", log: KeymanEngineLogger.ui, type: .info)
let innerView = keymanWeb.view!
let guide = self.safeAreaLayoutGuide

Expand All @@ -93,7 +94,7 @@ private class CustomInputView: UIInputView, UIInputViewAudioFeedback {
}

func keyboardHeightChanged() {
os_log("CustomInputView keyboardHeightChanged", log: KeymanEngineLogger.ui, type: .debug)
os_log("CustomInputView keyboardHeightChanged", log: KeymanEngineLogger.ui, type: .info)

// deactivate constraints for both orientations (though one should already be inactive)
landscapeConstraint?.isActive = false
Expand All @@ -113,7 +114,7 @@ private class CustomInputView: UIInputView, UIInputViewAudioFeedback {
}

private func buildKeyboardHeightConstraints(bannerHeight: CGFloat) {
os_log("CustomInputView buildKeyboardHeightConstraints", log: KeymanEngineLogger.ui, type: .debug)
os_log("CustomInputView buildKeyboardHeightConstraints", log: KeymanEngineLogger.ui, type: .info)
let innerView = keymanWeb.view!

// Cannot be met by the in-app keyboard, but helps to 'force' height for the system keyboard.
Expand Down Expand Up @@ -170,6 +171,7 @@ open class InputViewController: UIInputViewController, KeymanWebDelegate {
}

open class var topBarHeight: CGFloat {
os_log("topBarHeight", log:KeymanEngineLogger.ui, type: .info)
let scaling = KeyboardScaleMap.getDeviceDefaultKeyboardScale(forPortrait: self.isPortrait)

return scaling?.bannerHeight ?? 38 // default for iPhone SE, older/smaller devices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ extension KeymanWebViewController {
}

func constraintTargetHeight(isPortrait: Bool) -> CGFloat {
os_log("constraintTargetHeight", log:KeymanEngineLogger.ui, type: .info)
var keyboardHeight = 0.0

let defaultHeight = KeyboardScaleMap.getDeviceDefaultKeyboardScale(forPortrait: isPortrait)?.keyboardHeight ?? 216 // default for ancient devices
Expand All @@ -719,8 +720,8 @@ extension KeymanWebViewController {
os_log("%{public}s", log:KeymanEngineLogger.ui, type: .info, message)
keyboardHeight = defaultHeight
}
} else {
if (Storage.active.userDefaults.object(forKey: Key.portraitKeyboardHeight) != nil) {
} else { // landscape
if (Storage.active.userDefaults.object(forKey: Key.landscapeKeyboardHeight) != nil) {
keyboardHeight = Storage.active.userDefaults.landscapeKeyboardHeight
let message = "constraintTargetHeight, from UserDefaults loaded landscape value \(keyboardHeight)"
os_log("%{public}s", log:KeymanEngineLogger.ui, type: .info, message)
Expand All @@ -742,15 +743,16 @@ extension KeymanWebViewController {
var width: CGFloat
var height: CGFloat
width = UIScreen.main.bounds.width
os_log("initKeyboardSize()", log:KeymanEngineLogger.ui, type: .info)

if Util.isSystemKeyboard {
height = constraintTargetHeight(isPortrait: InputViewController.isPortrait)
let message = "initKeyboardSize(), for system keyboard, keyboardHeight: \(keyboardHeight)"
os_log("%{public}s", log:KeymanEngineLogger.ui, type: .debug, message)
os_log("%{public}s", log:KeymanEngineLogger.ui, type: .info, message)
} else {
height = constraintTargetHeight(isPortrait: UIDevice.current.orientation.isPortrait)
let message = "initKeyboardSize(), for in-app keyboard, keyboardHeight: \(keyboardHeight)"
os_log("%{public}s", log:KeymanEngineLogger.ui, type: .debug, message)
os_log("%{public}s", log:KeymanEngineLogger.ui, type: .info, message)
}

keyboardSize = CGSize(width: width, height: height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class KeyboardHeightViewController: UIViewController {
}

private func loadDefaultKeyboardHeights() {
os_log("loadDefaultKeyboardHeights", log:KeymanEngineLogger.ui, type: .info)
// if no KeyboardScaleMap found for device, then default to 216.0
let portraitKeyboardScale = KeyboardScaleMap.getDeviceDefaultKeyboardScale(forPortrait: true)
self.defaultPortraitHeight = Double(portraitKeyboardScale?.keyboardHeight ?? 216.0)
Expand Down

0 comments on commit b4fb78a

Please sign in to comment.