Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ios): configurable keyboard height #12571

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ios/engine/KMEI/KeymanEngine.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
1645D5952036C6FF0076C51B /* KeymanPackage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1645D5942036C6FF0076C51B /* KeymanPackage.swift */; };
1645D5972036C9F80076C51B /* KMPKeyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1645D5962036C9F80076C51B /* KMPKeyboard.swift */; };
165EB3A12098993900040A69 /* KeyboardError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 165EB3A02098993900040A69 /* KeyboardError.swift */; };
29084CAB2CD48B5D004070E7 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29084CAA2CD48B5D004070E7 /* Images.xcassets */; };
296EF2C72AFA26C700E3E384 /* ZIPFoundation.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 296EF2C62AFA26C700E3E384 /* ZIPFoundation.xcframework */; };
29B30C232B564F9900C342A4 /* KeymanEngineLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B30C222B564F9900C342A4 /* KeymanEngineLogger.swift */; };
29E202BD2CCB7541008B4740 /* KeyboardHeightViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29E202BC2CCB7541008B4740 /* KeyboardHeightViewController.swift */; };
377D10DE26846B8900467431 /* SpacebarTextViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 377D10DD26846B8900467431 /* SpacebarTextViewController.swift */; };
6CD5DFAA150F6DC8007A5DDE /* icon.png in Resources */ = {isa = PBXBuildFile; fileRef = 6CD5DFA8150F6DC8007A5DDE /* icon.png */; };
6CD5DFAB150F6DC8007A5DDE /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 6CD5DFA9150F6DC8007A5DDE /* [email protected] */; };
Expand Down Expand Up @@ -298,6 +300,7 @@
1645D5942036C6FF0076C51B /* KeymanPackage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeymanPackage.swift; sourceTree = "<group>"; };
1645D5962036C9F80076C51B /* KMPKeyboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPKeyboard.swift; sourceTree = "<group>"; };
165EB3A02098993900040A69 /* KeyboardError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardError.swift; sourceTree = "<group>"; };
29084CAA2CD48B5D004070E7 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
293EA3DB2705955300545EED /* ha */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ha; path = ha.lproj/ResourceInfoView.strings; sourceTree = "<group>"; };
293EA3DC2705964200545EED /* ha */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ha; path = ha.lproj/Localizable.strings; sourceTree = "<group>"; };
293EA3DD270596B700545EED /* ha */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = ha; path = ha.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
Expand Down Expand Up @@ -333,6 +336,7 @@
29C1E17128001F7600759EDE /* pt-PT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-PT"; path = "pt-PT.lproj/ResourceInfoView.strings"; sourceTree = "<group>"; };
29C1E17228001F8800759EDE /* pt-PT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-PT"; path = "pt-PT.lproj/Localizable.strings"; sourceTree = "<group>"; };
29C1E17328001FA200759EDE /* pt-PT */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "pt-PT"; path = "pt-PT.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
29E202BC2CCB7541008B4740 /* KeyboardHeightViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyboardHeightViewController.swift; sourceTree = "<group>"; };
377D10DD26846B8900467431 /* SpacebarTextViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpacebarTextViewController.swift; sourceTree = "<group>"; };
6C0A140E151EA930007FA4AD /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
6C0A140F151EA930007FA4AD /* Keyman.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; lineEnding = 0; path = Keyman.xcconfig; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.xcconfig; };
Expand Down Expand Up @@ -705,6 +709,7 @@
9A60763C22892485003BCFBA /* Settings.storyboard */,
9A60764322893A4E003BCFBA /* SettingsViewController.swift */,
377D10DD26846B8900467431 /* SpacebarTextViewController.swift */,
29E202BC2CCB7541008B4740 /* KeyboardHeightViewController.swift */,
);
name = Settings;
sourceTree = "<group>";
Expand Down Expand Up @@ -760,6 +765,7 @@
CEA1486F2407808F00C6ECD2 /* Localizable.strings */,
CE96E42D24D1229A005B8E5A /* Localizable.stringsdict */,
CE7A26D023CEE5790005955C /* Keyboard Colors.xcassets */,
29084CAA2CD48B5D004070E7 /* Images.xcassets */,
C06D372E1F81F4E100F61AE0 /* Info.plist */,
F273AB9615641D9300A47CEE /* Classes */,
);
Expand Down Expand Up @@ -1260,6 +1266,7 @@
buildActionMask = 2147483647;
files = (
C06D37601F82095200F61AE0 /* Keyman.bundle in Resources */,
29084CAB2CD48B5D004070E7 /* Images.xcassets in Resources */,
CEA1486C2407808F00C6ECD2 /* Localizable.strings in Resources */,
9ADC459F22E1895D004C78C6 /* LanguageLMDetailViewController.xib in Resources */,
CEA14870240780E100C6ECD2 /* ResourceInfoView.xib in Resources */,
Expand Down Expand Up @@ -1447,6 +1454,7 @@
CE67D961228A6F190029F2B5 /* KeyboardCommandStructs.swift in Sources */,
CE87751E24C68DA500B1475A /* KeyboardSearchViewController.swift in Sources */,
CE8B0BBF248764ED0045EB2E /* KMPResource.swift in Sources */,
29E202BD2CCB7541008B4740 /* KeyboardHeightViewController.swift in Sources */,
9AD4F53C229F85AC007992D3 /* LanguageSettingsViewController.swift in Sources */,
CE969BE8251AD8B500376D6A /* PackageWebViewController.swift in Sources */,
CE7A26DB23CEEF640005955C /* Colors.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions ios/engine/KMEI/KeymanEngine/Classes/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public enum Key {
static let synchronizeSWLexicalModel = "KeymanSynchronizeSWLexicalModel"

static let migrationLevel = "KeymanEngineMigrationLevel"
static let portraitKeyboardHeight = "PortraitKeyboardHeight"
static let landscapeKeyboardHeight = "LandscapeKeyboardHeight"

// JSON keys for language REST calls
static let options = "options"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,27 @@ public extension UserDefaults {
set(prefs, forKey: Key.userCorrectSettings)
}
}


var portraitKeyboardHeight: Double {
get {
return double(forKey: Key.portraitKeyboardHeight)
}

set(height) {
set(height, forKey: Key.portraitKeyboardHeight)
}
}

var landscapeKeyboardHeight: Double {
get {
return double(forKey: Key.landscapeKeyboardHeight)
}

set(height) {
set(height, forKey: Key.landscapeKeyboardHeight)
}
}

func predictSettingForLanguage(languageID: String) -> Bool {
if let dict = predictionEnablements {
return dict[languageID] ?? true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ class KeyboardScaleMap {
screenSize: CGSize = UIScreen.main.bounds.size,
asPhone: Bool? = nil) -> KeyboardSize? {
if let scaling = shared.scalings[KeyboardScaleMap.hashKey(for: device)] {
let kbHeight = (forPortrait ? scaling.portrait : scaling.landscape).keyboardHeight
os_log("KeyboardScaleMap getDeviceDefaultKeyboardScale keyboard height: %f", log:KeymanEngineLogger.ui, type: .debug, kbHeight)
return forPortrait ? scaling.portrait : scaling.landscape
}

Expand All @@ -240,6 +242,9 @@ class KeyboardScaleMap {
// keyboard dimensions. It's not a perfect rule, but should suffice for a stop-gap solution.
let scaling = shared.scalings[KeyboardScaleMap.hashKey(for: mappedDevice)]!

let kbHeight = (forPortrait ? scaling.portrait : scaling.landscape).keyboardHeight
os_log("KeyboardScaleMap getDeviceDefaultKeyboardScale keyboard height for missing device: %f", log:KeymanEngineLogger.ui, type: .debug, kbHeight)

return forPortrait ? scaling.portrait : scaling.landscape
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class KeymanWebViewController: UIViewController {
// after it has been replaced by KMW's OSK resizing operation.)

keyboardSize = view.bounds.size
os_log("KeymanWebViewController viewWillLayoutSubviews to keyboardSize %{public}s", log:KeymanEngineLogger.ui, type: .debug, NSCoder.string(for:keyboardSize))
}

open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
Expand Down Expand Up @@ -704,7 +705,33 @@ extension KeymanWebViewController {
}

func constraintTargetHeight(isPortrait: Bool) -> CGFloat {
return KeyboardScaleMap.getDeviceDefaultKeyboardScale(forPortrait: isPortrait)?.keyboardHeight ?? 216 // default for ancient devices
var keyboardHeight = 0.0

var defaultHeight = KeyboardScaleMap.getDeviceDefaultKeyboardScale(forPortrait: isPortrait)?.keyboardHeight ?? 216 // default for ancient devices

if (isPortrait) {
if (Storage.active.userDefaults.object(forKey: Key.portraitKeyboardHeight) != nil) {
keyboardHeight = Storage.active.userDefaults.portraitKeyboardHeight
let message = "constraintTargetHeight, from UserDefaults loaded portrait value \(keyboardHeight)"
os_log("%{public}s", log:KeymanEngineLogger.ui, type: .info, message)
} else {
let message = "constraintTargetHeight, portraitHeight not found in UserDefaults, using default value \(defaultHeight)"
os_log("%{public}s", log:KeymanEngineLogger.ui, type: .info, message)
keyboardHeight = defaultHeight
}
} else {
if (Storage.active.userDefaults.object(forKey: Key.portraitKeyboardHeight) != 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)
} else {
let message = "constraintTargetHeight, landscapeHeight not found in UserDefaults, using default value \(defaultHeight)"
os_log("%{public}s", log:KeymanEngineLogger.ui, type: .info, message)
keyboardHeight = defaultHeight
}
}

return keyboardHeight;
}

var keyboardWidth: CGFloat {
Expand All @@ -723,6 +750,7 @@ extension KeymanWebViewController {
}

keyboardSize = CGSize(width: width, height: height)
os_log("KeymanWebViewController initKeyboardSize %{public}s", log:KeymanEngineLogger.ui, type: .default, NSCoder.string(for:keyboardSize))
}

var keyboardSize: CGSize {
Expand Down Expand Up @@ -768,6 +796,7 @@ extension KeymanWebViewController {
// the first time.
setOskWidth(Int(kbSize.width))
setOskHeight(Int(kbSize.height))
os_log("KeymanWebViewController resizeKeyboard to kbSize %{public}s", log:KeymanEngineLogger.ui, type: .debug, NSCoder.string(for:kbSize))
}

func resetKeyboardState() {
Expand Down
Loading
Loading