Skip to content

Commit 923b606

Browse files
committed
fix: operate on view model instead of view
1 parent 5045577 commit 923b606

9 files changed

Lines changed: 167 additions & 174 deletions

keyboard/KeyboardViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class KeyboardViewController: UIInputViewController, FcitxProtocol {
3535
(textDocumentProxy.documentContextBeforeInput ?? "")
3636
+ (textDocumentProxy.selectedText ?? "")
3737
+ (textDocumentProxy.documentContextAfterInput ?? "")
38-
virtualKeyboardView.setTextIsEmpty(text.isEmpty)
38+
vm.setTextIsEmpty(text.isEmpty)
3939
}
4040

4141
override func updateViewConstraints() {
@@ -57,7 +57,7 @@ class KeyboardViewController: UIInputViewController, FcitxProtocol {
5757
startFcitx(appBundlePath, "\(Bundle.main.bundlePath)/share", appGroup.path)
5858

5959
// Must recreate SwiftUI view, otherwise rotating may have old height which can't be updated.
60-
hostingController = UIHostingController(rootView: newVirtualKeyboardView())
60+
hostingController = UIHostingController(rootView: VirtualKeyboardView())
6161
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
6262

6363
// Spotlight shows that system keyboard has transparent background.
@@ -83,14 +83,14 @@ class KeyboardViewController: UIInputViewController, FcitxProtocol {
8383

8484
hostingController.didMove(toParent: self)
8585

86-
virtualKeyboardView.setReturnKeyType(textDocumentProxy.returnKeyType)
86+
vm.setReturnKeyType(textDocumentProxy.returnKeyType)
8787
super.viewWillAppear(animated)
8888
let keyboard = Bundle.main.bundleURL.deletingPathExtension().lastPathComponent
8989
if removeFile(appGroupTmp.appendingPathComponent("\(keyboard).reload")) {
9090
logger.info("Reload accepted")
9191
reload()
9292
}
93-
virtualKeyboardView.setDisplayMode(.initial)
93+
vm.setDisplayMode(.initial)
9494
self.resetInput() // Avoid old context carried over, since focusOut is dummy.
9595
focusIn()
9696
}

uipanel/ContextMenu.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct LongPressMeasureModifier: ViewModifier {
111111
if items.isEmpty {
112112
return
113113
}
114-
virtualKeyboardView.showContextMenu(frame, items)
114+
vm.showContextMenu(frame, items)
115115
}
116116
}
117117
}

uipanel/Key.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct KeyView: View {
4545
shadow: getShadow(colorScheme),
4646
action: GestureAction(
4747
onTap: {
48-
virtualKeyboardView.resetLayerIfNotLocked()
48+
vm.resetLayerIfNotLocked()
4949
client.keyPressed(key, "")
5050
},
5151
onLongPress: { highlight in
@@ -95,7 +95,7 @@ struct SpaceView: View {
9595
shadow: getShadow(colorScheme),
9696
action: GestureAction(
9797
onTap: {
98-
virtualKeyboardView.resetLayerIfNotLocked()
98+
vm.resetLayerIfNotLocked()
9999
client.keyPressed(" ", "")
100100
},
101101
onSlide: { step in
@@ -129,7 +129,7 @@ struct BackspaceView: View {
129129
func startDelete() {
130130
stopDelete()
131131
deleteTimer = Timer.scheduledTimer(withTimeInterval: 0.08, repeats: true) { _ in
132-
virtualKeyboardView.resetLayerIfNotLocked()
132+
vm.resetLayerIfNotLocked()
133133
client.keyPressed("", "Backspace")
134134
}
135135
}
@@ -155,14 +155,14 @@ struct BackspaceView: View {
155155
shadow: getShadow(colorScheme),
156156
action: GestureAction(
157157
onTap: {
158-
virtualKeyboardView.resetLayerIfNotLocked()
158+
vm.resetLayerIfNotLocked()
159159
client.keyPressed("", "Backspace")
160160
},
161161
onLongPress: { _ in
162162
startDelete()
163163
},
164164
onSlide: { step in
165-
virtualKeyboardView.slideBackspace(step)
165+
vm.slideBackspace(step)
166166
},
167167
onRelease: {
168168
stopDelete()
@@ -201,22 +201,22 @@ struct GlobeView: View {
201201
shadow: getShadow(colorScheme),
202202
action: GestureAction(
203203
onTap: {
204-
virtualKeyboardView.resetLayerIfNotLocked()
204+
vm.resetLayerIfNotLocked()
205205
client.globe()
206206
},
207207
onLongPress: { _ in
208-
let items = virtualKeyboardView.viewModel.inputMethods.map { inputMethod in
208+
let items = vm.inputMethods.map { inputMethod in
209209
MenuItem(
210210
text: inputMethod.displayName,
211211
action: {
212-
virtualKeyboardView.resetLayerIfNotLocked()
212+
vm.resetLayerIfNotLocked()
213213
client.setCurrentInputMethod(inputMethod.name)
214214
})
215215
}
216216
if !items.isEmpty {
217217
let frame = CGRect(
218218
x: x, y: y + getBarHeight(totalHeight), width: width, height: height)
219-
virtualKeyboardView.showContextMenu(frame, items)
219+
vm.showContextMenu(frame, items)
220220
}
221221
}
222222
)
@@ -263,7 +263,7 @@ struct EnterView: View {
263263
// When !cr && disable, still allow key press, because text empty detection is not reliable.
264264
// e.g. In WeChat when the first line is empty and caret is there and the second line is not empty,
265265
// it says text is empty but should be sendable.
266-
virtualKeyboardView.resetLayerIfNotLocked()
266+
vm.resetLayerIfNotLocked()
267267
client.keyPressed("\r", "Enter")
268268
}
269269
),
@@ -302,12 +302,12 @@ struct ShiftView: View {
302302
shadow: getShadow(colorScheme),
303303
action: GestureAction(
304304
onPress: {
305-
virtualKeyboardView.setLayer(
305+
vm.setLayer(
306306
state == .normal ? "shift" : "default"
307307
)
308308
},
309309
onDoubleTap: {
310-
virtualKeyboardView.setLayer("shift", lock: true)
310+
vm.setLayer("shift", lock: true)
311311
}
312312
)
313313
)
@@ -331,7 +331,7 @@ struct SymbolKeyView: View {
331331
shadow: getShadow(colorScheme),
332332
action: GestureAction(
333333
onTap: {
334-
virtualKeyboardView.setDisplayMode(.symbol)
334+
vm.setDisplayMode(.symbol)
335335
}
336336
)
337337
)

uipanel/KeyModifier.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private func getNStep(_ start: CGFloat, _ end: CGFloat, _ step: CGFloat) -> Int
2828

2929
@MainActor
3030
private func clearBubble() {
31-
virtualKeyboardView.setBubble(0, 0, 0, 0, .clear, .light, .clear, nil, [], 0, 0)
31+
vm.setBubble(0, 0, 0, 0, .clear, .light, .clear, nil, [], 0, 0)
3232
}
3333

3434
struct KeyModifier: ViewModifier {
@@ -108,7 +108,7 @@ struct KeyModifier: ViewModifier {
108108
startLocation = value.startLocation
109109
lastLocation = value.startLocation.x
110110

111-
virtualKeyboardView.setBubble(
111+
vm.setBubble(
112112
bubbleX, bubbleY, bubbleWidth, bubbleHeight,
113113
background, colorScheme, shadow,
114114
bubbleLabel, [], 0, 0)
@@ -123,7 +123,7 @@ struct KeyModifier: ViewModifier {
123123
didTriggerLongPress = true
124124
if longPressIndex >= 0 && longPressIndex < longPressLabels.count {
125125
bubbleHighlight = longPressIndex
126-
virtualKeyboardView.setBubble(
126+
vm.setBubble(
127127
bubbleX, bubbleY, bubbleWidth, bubbleHeight,
128128
background, colorScheme, shadow, nil, longPressLabels, longPressIndex,
129129
bubbleHighlight)
@@ -153,7 +153,7 @@ struct KeyModifier: ViewModifier {
153153
}
154154
if didMoveFarEnough {
155155
if getSwipeDirection(dx, dy) == .up {
156-
virtualKeyboardView.setBubble(
156+
vm.setBubble(
157157
bubbleX, bubbleY, bubbleWidth, bubbleHeight, background, colorScheme,
158158
shadow, swipeUpLabel, [], 0, 0)
159159
} else {
@@ -185,7 +185,7 @@ struct KeyModifier: ViewModifier {
185185
if delta != 0 {
186186
bubbleHighlight = max(
187187
0, min(bubbleHighlight + delta, longPressLabels.count - 1))
188-
virtualKeyboardView.setBubble(
188+
vm.setBubble(
189189
bubbleX, bubbleY, bubbleWidth, bubbleHeight,
190190
background, colorScheme, shadow, nil, longPressLabels, longPressIndex,
191191
bubbleHighlight)

uipanel/ReturnBar.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct ReturnBarView: View {
88
let barHeight = getBarHeight(totalHeight)
99
HStack {
1010
Button {
11-
virtualKeyboardView.popDisplayMode()
11+
vm.popDisplayMode()
1212
} label: {
1313
Image(systemName: "arrow.backward")
1414
.foregroundColor(getNormalForeground(colorScheme))

uipanel/Symbol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct SymbolView: View {
103103
SymbolButton(symbol: symbol) {
104104
client.resetInput()
105105
client.commitString(symbol)
106-
virtualKeyboardView.popDisplayMode()
106+
vm.popDisplayMode()
107107
}
108108
}
109109
}

uipanel/Toolbar.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ struct ToolbarView: View {
1111
HStack(spacing: width / 6) {
1212
Spacer()
1313
Button {
14-
virtualKeyboardView.setDisplayMode(.edit)
14+
vm.setDisplayMode(.edit)
1515
} label: {
1616
Image(systemName: "character.cursor.ibeam")
1717
.foregroundColor(getNormalForeground(colorScheme))
1818
.frame(width: barHeight, height: barHeight)
1919
}
2020
Button {
21-
virtualKeyboardView.setDisplayMode(.statusArea)
21+
vm.setDisplayMode(.statusArea)
2222
} label: {
2323
Image(systemName: "ellipsis")
2424
.foregroundColor(getNormalForeground(colorScheme))

0 commit comments

Comments
 (0)