Skip to content

Commit 9f1bcc9

Browse files
committed
adaptive keyboard height
1 parent 4ac3a74 commit 9f1bcc9

File tree

14 files changed

+154
-14
lines changed

14 files changed

+154
-14
lines changed

docs/size.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Default keyboard size
2+
3+
Simulator|Screen height|Screen width|Portrait height|Landscape height|Floating height
4+
-|-|-|-|-|-
5+
iPhone 16e|844|390|260|198|-
6+
iPhone 16|852|393|260|198|-
7+
iPhone 16 Pro|874|402|260|198|-
8+
iPhone 16 Plus|932|430|270|198|-
9+
iPhone 16 Pro Max|956|440|270|198|-
10+
iPad mini (A17 Pro)|1133|744|260|348|255
11+
iPad (A16)|1180|820|255|342|255
12+
iPad Air 11-inch (M3)|1180|820|255|342|255
13+
iPad Pro 11-inch (M4)|1210|834|260|348|255
14+
iPad Air 13-inch (M3)|1366|1024|325|420|260*
15+
iPad Pro 13-inch (M4)|1376|1032|325|420|255
16+
17+
\* Context menu mask shows that there is no padding top, which may not be the case for real device, so use 255 to unify.

keyboard/KeyboardViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class KeyboardViewController: UIInputViewController, FcitxProtocol {
5454
setLocale(syncLocale())
5555
startFcitx(appBundlePath, "\(Bundle.main.bundlePath)/share", appGroup.path)
5656

57-
hostingController = UIHostingController(rootView: virtualKeyboardView)
57+
// Must recreate SwiftUI view, otherwise rotating may have old height which can't be updated.
58+
hostingController = UIHostingController(rootView: newVirtualKeyboardView())
5859
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
5960

6061
// Spotlight shows that system keyboard has transparent background.

uipanel/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_library(KeyboardUI STATIC
1717
Symbol.swift
1818
ReturnBar.swift
1919
ui.swift
20+
height.swift
2021
)
2122
set_target_properties(KeyboardUI PROPERTIES Swift_MODULE_NAME KeyboardUI)
2223
target_compile_options(KeyboardUI PUBLIC "$<$<COMPILE_LANGUAGE:Swift>:-cxx-interoperability-mode=default>")

uipanel/CandidateBar.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ private func preeditWithCaret(_ preedit: String, _ caret: Int) -> String {
3030

3131
struct CandidateBarView: View {
3232
@Environment(\.colorScheme) var colorScheme
33+
@Environment(\.totalHeight) var totalHeight
34+
3335
let width: CGFloat
3436
let auxUp: String
3537
let preedit: String
@@ -54,6 +56,9 @@ struct CandidateBarView: View {
5456
}
5557

5658
var body: some View {
59+
let barHeight = getBarHeight(totalHeight)
60+
let keyboardHeight = getKeyboardHeight(totalHeight)
61+
5762
ScrollViewReader { proxy in
5863
HStack(spacing: 0) {
5964
let barHeightExcludePreedit =

uipanel/Edit.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ let editKeyGap: CGFloat = 8
55

66
struct EditView: View {
77
@Environment(\.colorScheme) var colorScheme
8+
@Environment(\.totalHeight) var totalHeight
89
let totalWidth: CGFloat
910

1011
var body: some View {
12+
let keyboardHeight = getKeyboardHeight(totalHeight)
1113
let height = keyboardHeight / 4
1214
let width = totalWidth / 4
15+
1316
VStack(spacing: 0) {
1417
ReturnBarView()
1518

@@ -91,7 +94,7 @@ struct EditView: View {
9194
normal ? getFunctionBackground(colorScheme) : getNormalBackground(colorScheme)
9295
let foreground = getNormalForeground(colorScheme)
9396
let p = position(index, width, height)
94-
let size = keyboardHeight / shrink
97+
let size = getKeyboardHeight(totalHeight) / shrink
9598
let useWidth = image == "arrowtriangle.up.fill" || image == "arrowtriangle.down.fill"
9699
let symbol = Image(systemName: image)
97100
.resizable()

uipanel/Key.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ struct BackspaceView: View {
144144

145145
struct GlobeView: View {
146146
@Environment(\.colorScheme) var colorScheme
147+
@Environment(\.totalHeight) var totalHeight
148+
147149
let x: CGFloat
148150
let y: CGFloat
149151
let width: CGFloat
@@ -175,7 +177,8 @@ struct GlobeView: View {
175177
})
176178
}
177179
if !items.isEmpty {
178-
let frame = CGRect(x: x, y: y + barHeight, width: width, height: height)
180+
let frame = CGRect(
181+
x: x, y: y + getBarHeight(totalHeight), width: width, height: height)
179182
virtualKeyboardView.showContextMenu(frame, items)
180183
}
181184
}

uipanel/Keyboard.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ extension Array where Element == CGFloat {
2727
}
2828

2929
struct KeyboardView: View {
30+
@Environment(\.totalHeight) var totalHeight
31+
3032
let width: CGFloat
3133
let layer: String
3234
let lock: Bool
@@ -49,7 +51,9 @@ struct KeyboardView: View {
4951

5052
var body: some View {
5153
let rows = layer == "shift" ? shiftRows : defaultRows
54+
let keyboardHeight = getKeyboardHeight(totalHeight)
5255
let height = keyboardHeight / CGFloat(rows.count)
56+
5357
ZStack {
5458
ForEach(Array(rows.enumerated()), id: \.offset) { i, row in
5559
renderRow(row, CGFloat(i) * height, width, height)

uipanel/ReturnBar.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import SwiftUI
22

33
struct ReturnBarView: View {
44
@Environment(\.colorScheme) var colorScheme
5+
@Environment(\.totalHeight) var totalHeight
56

67
var body: some View {
8+
let barHeight = getBarHeight(totalHeight)
79
HStack {
810
Button {
911
virtualKeyboardView.popDisplayMode()

uipanel/StatusArea.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ private func getActionView(_ icon: String, _ desc: String) -> some View {
4646
}
4747

4848
struct StatusAreaView: View {
49+
@Environment(\.totalHeight) var totalHeight
4950
@Binding var actions: [StatusAreaAction]
5051

5152
private let columns = [
@@ -99,7 +100,7 @@ struct StatusAreaView: View {
99100
}
100101
}
101102
}
102-
}.frame(height: keyboardHeight)
103+
}.frame(height: getKeyboardHeight(totalHeight))
103104
}
104105
}
105106
}

uipanel/Symbol.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ let builtinCategories: [SymbolCategory] = [
3030

3131
struct SymbolButton: View {
3232
@Environment(\.colorScheme) var colorScheme
33+
@Environment(\.totalHeight) var totalHeight
34+
3335
let symbol: String
3436
let action: () -> Void
3537

@@ -39,7 +41,7 @@ struct SymbolButton: View {
3941
var body: some View {
4042
Text(symbol)
4143
.font(.system(size: 24))
42-
.frame(height: keyboardHeight / 5)
44+
.frame(height: getKeyboardHeight(totalHeight) / 5)
4345
.frame(maxWidth: .infinity)
4446
.background(isPressed ? getFunctionBackground(colorScheme) : Color.clear)
4547
// Use simultaneousGesture so that scrolling behavior is preserved.
@@ -66,6 +68,7 @@ struct SymbolButton: View {
6668

6769
struct SymbolView: View {
6870
@Environment(\.colorScheme) var colorScheme
71+
@Environment(\.totalHeight) var totalHeight
6972
let width: CGFloat
7073

7174
@State private var selectedKey = builtinCategories.first!.key
@@ -79,7 +82,7 @@ struct SymbolView: View {
7982
ForEach(builtinCategories) { category in
8083
Text(category.key)
8184
.font(.system(size: 24))
82-
.frame(height: keyboardHeight / 5)
85+
.frame(height: totalHeight / 5)
8386
.frame(maxWidth: .infinity)
8487
.background(
8588
selectedKey == category.key ? getFunctionBackground(colorScheme) : Color.clear

0 commit comments

Comments
 (0)