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 { 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
* 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.backgroundColor = SETTINGS_BACKGROUND_COLOR
textField.placeholderColor = SETTINGS_PLACEHOLDER_COLOR
@@ -53,7 +53,7 @@ function applySettingsTextFieldContrast(textField: TextField, selectAllOnFocus =
return
}
const nativeTextField = (textField as TextField & { nativeView?: android.widget.EditText }).nativeView
const nativeTextField = (textField as (TextField | TextView) & { nativeView?: android.widget.EditText }).nativeView
if (!nativeTextField) {
return
}
@@ -90,13 +90,13 @@ function focusTextEditor(page: Page): void {
/** The keyboard dialog closed on the glasses (sent, discarded, or screen off). */
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. */
function focusKeyboardInput(page: Page): void {
setTimeout(() => {
const textField = page.getViewById<TextField>('keyboardInputField')
const textField = page.getViewById<TextView>('keyboardInputField')
if (textField) {
applySettingsTextFieldContrast(textField, false)
textField.focus()
+4 -6
View File
@@ -153,22 +153,20 @@
<!-- Keyboard-input panel (the keyboard button beside the mic button):
the phone's end of the keyboard dialog on the glasses
(ui/shell/keyboard-input.ts). Same placement and collapsing rules
as the setting editor above. The IME's send key goes to whichever
destination is highlighted on the glasses; the buttons pick one
directly. -->
as the setting editor above. Enter inserts a newline; the send
buttons pick a destination directly. -->
<StackLayout
class="system-name-modal"
visibility="{{ keyboardInputVisibility }}"
horizontalAlignment="stretch"
verticalAlignment="bottom">
<Label text="Keyboard input" class="h2" />
<TextField
<TextView
id="keyboardInputField"
text="{{ keyboardInputText }}"
hint="Type a message"
textChange="{{ onKeyboardInputTextChange }}"
returnPress="{{ onKeyboardInputReturnPress }}"
returnKeyType="send" />
height="120" />
<!-- Wraps onto a second line when the labels don't fit side by side. -->
<FlexboxLayout flexWrap="wrap" class="m-t-8">
<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 {
dashboardController.setKeyboardInputText(args.object?.text ?? args.value ?? "");
}
/** The IME's send key: the destination highlighted on the glasses. */
onKeyboardInputReturnPress(args: { object?: { text?: string } }): void {
// 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();
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.
this._keyboardInputText = text;
dashboardController.setKeyboardInputText(text);
}
onKeyboardInputPrimarySendTap(): void {