Keyboard input via phone is multiline and clears between inputs

This commit is contained in:
James Babcock committed 2026-09-06 21:47:19 -07:00
1 parent 9b70880a5b
commit 8e4d887186
3 files changed
+14 -23

No files matched your search

+5 -5
View File
@@ -1,4 +1,4 @@
import { Application, Color, EventData, isAndroid, Observable, Page, TextField } from '@nativescript/core' import { Application, Color, EventData, isAndroid, Observable, Page, TextField, TextView } from '@nativescript/core'
import { MainViewModel } from './main-view-model' import { MainViewModel } from './main-view-model'
import { dashboardController } from '../g2/dashboard-controller' import { dashboardController } from '../g2/dashboard-controller'
@@ -44,7 +44,7 @@ function cleanupPage(page: Page): void {
* suits replacing an existing setting value; a message being composed keeps * suits replacing an existing setting value; a message being composed keeps
* its caret where the user taps. * its caret where the user taps.
*/ */
function applySettingsTextFieldContrast(textField: TextField, selectAllOnFocus = true): void { function applySettingsTextFieldContrast(textField: TextField | TextView, selectAllOnFocus = true): void {
textField.color = SETTINGS_TEXT_COLOR textField.color = SETTINGS_TEXT_COLOR
textField.backgroundColor = SETTINGS_BACKGROUND_COLOR textField.backgroundColor = SETTINGS_BACKGROUND_COLOR
textField.placeholderColor = SETTINGS_PLACEHOLDER_COLOR textField.placeholderColor = SETTINGS_PLACEHOLDER_COLOR
@@ -53,7 +53,7 @@ function applySettingsTextFieldContrast(textField: TextField, selectAllOnFocus =
return return
} }
const nativeTextField = (textField as TextField & { nativeView?: android.widget.EditText }).nativeView const nativeTextField = (textField as (TextField | TextView) & { nativeView?: android.widget.EditText }).nativeView
if (!nativeTextField) { if (!nativeTextField) {
return return
} }
@@ -90,13 +90,13 @@ function focusTextEditor(page: Page): void {
/** The keyboard dialog closed on the glasses (sent, discarded, or screen off). */ /** The keyboard dialog closed on the glasses (sent, discarded, or screen off). */
function dismissKeyboardInputKeyboard(page: Page): void { function dismissKeyboardInputKeyboard(page: Page): void {
page.getViewById<TextField>('keyboardInputField')?.dismissSoftInput() page.getViewById<TextView>('keyboardInputField')?.dismissSoftInput()
} }
/** The keyboard dialog opened: bring up the IME on its field right away. */ /** The keyboard dialog opened: bring up the IME on its field right away. */
function focusKeyboardInput(page: Page): void { function focusKeyboardInput(page: Page): void {
setTimeout(() => { setTimeout(() => {
const textField = page.getViewById<TextField>('keyboardInputField') const textField = page.getViewById<TextView>('keyboardInputField')
if (textField) { if (textField) {
applySettingsTextFieldContrast(textField, false) applySettingsTextFieldContrast(textField, false)
textField.focus() textField.focus()
+4 -6
View File
@@ -153,22 +153,20 @@
<!-- Keyboard-input panel (the keyboard button beside the mic button): <!-- Keyboard-input panel (the keyboard button beside the mic button):
the phone's end of the keyboard dialog on the glasses the phone's end of the keyboard dialog on the glasses
(ui/shell/keyboard-input.ts). Same placement and collapsing rules (ui/shell/keyboard-input.ts). Same placement and collapsing rules
as the setting editor above. The IME's send key goes to whichever as the setting editor above. Enter inserts a newline; the send
destination is highlighted on the glasses; the buttons pick one buttons pick a destination directly. -->
directly. -->
<StackLayout <StackLayout
class="system-name-modal" class="system-name-modal"
visibility="{{ keyboardInputVisibility }}" visibility="{{ keyboardInputVisibility }}"
horizontalAlignment="stretch" horizontalAlignment="stretch"
verticalAlignment="bottom"> verticalAlignment="bottom">
<Label text="Keyboard input" class="h2" /> <Label text="Keyboard input" class="h2" />
<TextField <TextView
id="keyboardInputField" id="keyboardInputField"
text="{{ keyboardInputText }}" text="{{ keyboardInputText }}"
hint="Type a message" hint="Type a message"
textChange="{{ onKeyboardInputTextChange }}" textChange="{{ onKeyboardInputTextChange }}"
returnPress="{{ onKeyboardInputReturnPress }}" height="120" />
returnKeyType="send" />
<!-- Wraps onto a second line when the labels don't fit side by side. --> <!-- Wraps onto a second line when the labels don't fit side by side. -->
<FlexboxLayout flexWrap="wrap" class="m-t-8"> <FlexboxLayout flexWrap="wrap" class="m-t-8">
<Button text="{{ keyboardInputPrimaryTargetLabel }}" tap="{{ onKeyboardInputPrimarySendTap }}" visibility="{{ keyboardInputPrimaryTargetVisibility }}" flexGrow="1" class="-primary" /> <Button text="{{ keyboardInputPrimaryTargetLabel }}" tap="{{ onKeyboardInputPrimarySendTap }}" visibility="{{ keyboardInputPrimaryTargetVisibility }}" flexGrow="1" class="-primary" />
+5 -12
View File
@@ -540,18 +540,11 @@ export class MainViewModel extends Observable {
} }
onKeyboardInputTextChange(args: { value?: string; object?: { text?: string } }): void { onKeyboardInputTextChange(args: { value?: string; object?: { text?: string } }): void {
dashboardController.setKeyboardInputText(args.object?.text ?? args.value ?? ""); const text = args.object?.text ?? args.value ?? "";
} // Track the draft so closing the dialog emits a clear even when the
// binding hasn't updated the model. Avoid echoing edits into the IME.
/** The IME's send key: the destination highlighted on the glasses. */ this._keyboardInputText = text;
onKeyboardInputReturnPress(args: { object?: { text?: string } }): void { dashboardController.setKeyboardInputText(text);
// Commit the field's actual text at send-time, in case the final
// keystroke's textChange hadn't landed yet.
const text = args?.object?.text;
if (typeof text === "string") {
dashboardController.setKeyboardInputText(text);
}
dashboardController.sendKeyboardInput();
} }
onKeyboardInputPrimarySendTap(): void { onKeyboardInputPrimarySendTap(): void {