forked from Blendman974/faceclaw
Fix an iOS issue where depth would be incorrect on first frame of fade-in on wake; also refine the keyboard input dialog
This commit is contained in:
1 parent
22f869d31c
commit
361b514f9a
21 files changed
+546
-138
No files matched your search
@@ -1,18 +1,40 @@
|
||||
<GridLayout rows="auto,*,auto" maxHeight="280" xmlns="http://schemas.nativescript.org/tns.xsd"
|
||||
class="system-name-modal"
|
||||
class="system-name-modal keyboard-input-panel"
|
||||
visibility="{{ keyboardInputVisibility }}"
|
||||
horizontalAlignment="stretch"
|
||||
verticalAlignment="bottom">
|
||||
<Label row="0" text="Keyboard input" class="h2" />
|
||||
<!-- Title, then the history button (recent sent messages) and the
|
||||
visibility button, which cycles both / phone only / glasses only and
|
||||
dims the half of its phone+glasses pair where the dialog is hidden.
|
||||
rows="auto" on the grids: an implicit star row balloons in here. -->
|
||||
<GridLayout row="0" rows="auto" columns="*,auto,auto">
|
||||
<Label col="0" text="Keyboard input" class="h2" verticalAlignment="center" />
|
||||
<GridLayout col="1" rows="auto" class="panel-icon-button" opacity="{{ keyboardInputHistoryOpacity }}"
|
||||
accessible="true" accessibilityRole="button" accessibilityLabel="Recent inputs"
|
||||
tap="{{ onKeyboardInputHistoryTap }}">
|
||||
<Image src="res://ic_input_history" class="panel-icon" />
|
||||
</GridLayout>
|
||||
<StackLayout col="2" orientation="horizontal" class="panel-icon-button"
|
||||
accessible="true" accessibilityRole="button" accessibilityLabel="{{ keyboardInputVisibilityDescription }}"
|
||||
tap="{{ onKeyboardInputVisibilityTap }}">
|
||||
<Image src="res://ic_show_phone" class="panel-icon" opacity="{{ keyboardInputPhoneIconOpacity }}" />
|
||||
<Image src="res://ic_show_glasses" class="panel-icon" opacity="{{ keyboardInputGlassesIconOpacity }}" />
|
||||
</StackLayout>
|
||||
</GridLayout>
|
||||
<TextView row="1"
|
||||
id="keyboardInputField"
|
||||
class="{{ keyboardInputFieldClass }}"
|
||||
text="{{ keyboardInputText }}"
|
||||
hint="Type a message"
|
||||
textChange="{{ onKeyboardInputTextChange }}" />
|
||||
<!-- Wraps onto a second line when the labels don't fit side by side. -->
|
||||
<FlexboxLayout row="2" flexWrap="wrap" class="m-t-8">
|
||||
<Label row="1" text="Shown on the glasses only. Tap to type." textWrap="true"
|
||||
class="keyboard-input-hidden-hint"
|
||||
visibility="{{ keyboardInputGlassesOnlyVisibility }}"
|
||||
tap="{{ onKeyboardInputGlassesOnlyHintTap }}" />
|
||||
<!-- One strip: at most two destinations (assistant, app) plus Discard. -->
|
||||
<FlexboxLayout row="2" flexWrap="nowrap" class="keyboard-input-buttons">
|
||||
<Button text="{{ keyboardInputPrimaryTargetLabel }}" tap="{{ onKeyboardInputPrimarySendTap }}" visibility="{{ keyboardInputPrimaryTargetVisibility }}" flexGrow="1" class="-primary" />
|
||||
<Button text="{{ keyboardInputSecondaryTargetLabel }}" tap="{{ onKeyboardInputSecondarySendTap }}" visibility="{{ keyboardInputSecondaryTargetVisibility }}" flexGrow="1" />
|
||||
<Button text="Discard" tap="{{ onKeyboardInputDiscardTap }}" flexGrow="1" />
|
||||
<Button text="{{ keyboardInputSecondaryTargetLabel }}" tap="{{ onKeyboardInputSecondarySendTap }}" visibility="{{ keyboardInputSecondaryTargetVisibility }}" flexGrow="1" class="keyboard-input-gap" />
|
||||
<Button text="Discard" tap="{{ onKeyboardInputDiscardTap }}" flexGrow="1" class="keyboard-input-gap" />
|
||||
</FlexboxLayout>
|
||||
</GridLayout>
|
||||
@@ -1,7 +1,32 @@
|
||||
import { Observable } from '@nativescript/core'
|
||||
import type { KeyboardInputSession } from '../ui/shell/keyboard-input'
|
||||
import { Dialogs, Observable, type EventData, type TextView, type View } from '@nativescript/core'
|
||||
import type { KeyboardInputSession, KeyboardInputVisibility } from '../ui/shell/keyboard-input'
|
||||
|
||||
/** Phone editor for the shell's keyboard session, using the shared XML panel. */
|
||||
/** The visibility button's cycle: both → phone only → glasses only → both. */
|
||||
const NEXT_VISIBILITY: Record<KeyboardInputVisibility, KeyboardInputVisibility> = { both: 'phone', phone: 'glasses', glasses: 'both' }
|
||||
const VISIBILITY_DESCRIPTIONS: Record<KeyboardInputVisibility, string> = {
|
||||
both: 'Shown on phone and glasses', phone: 'Shown on phone only', glasses: 'Shown on glasses only',
|
||||
}
|
||||
/**
|
||||
* Phone button text for the glasses' send-target labels, short enough for
|
||||
* every button to share one strip. Unlisted labels (the assistant overlay's
|
||||
* "Send") are already short.
|
||||
*/
|
||||
const SHORT_TARGET_LABELS: Record<string, string> = { 'Send to Assistant': 'To Assistant', 'Type Into App': 'To App' }
|
||||
const HISTORY_LABEL_LENGTH = 80
|
||||
const DIMMED_ICON_OPACITY = 0.3
|
||||
|
||||
/** One history entry as a single line, truncated for the picker. */
|
||||
function historyLabel(text: string): string {
|
||||
const line = text.replace(/\s+/g, ' ').trim()
|
||||
return line.length > HISTORY_LABEL_LENGTH ? `${line.slice(0, HISTORY_LABEL_LENGTH - 1)}…` : line
|
||||
}
|
||||
|
||||
/**
|
||||
* Phone editor for the shell's keyboard session: the binding context of the
|
||||
* shared keyboard-input-panel.xml on both platforms (Android's MainViewModel
|
||||
* hands it the session from the dashboard controller, iOS's main page from
|
||||
* the preview controller).
|
||||
*/
|
||||
export class KeyboardInputViewModel extends Observable {
|
||||
private session: KeyboardInputSession | null = null
|
||||
private text = ''
|
||||
@@ -10,17 +35,24 @@ export class KeyboardInputViewModel extends Observable {
|
||||
if (session === this.session) return
|
||||
this.session = session
|
||||
this.text = ''
|
||||
for (const property of ['keyboardInputText', 'keyboardInputVisibility', 'keyboardInputPrimaryTargetLabel',
|
||||
'keyboardInputPrimaryTargetVisibility', 'keyboardInputSecondaryTargetLabel', 'keyboardInputSecondaryTargetVisibility']) {
|
||||
this.notifyPropertyChange(property, this.get(property))
|
||||
}
|
||||
this.notifyPanel(['keyboardInputText', 'keyboardInputVisibility', 'keyboardInputPrimaryTargetLabel',
|
||||
'keyboardInputPrimaryTargetVisibility', 'keyboardInputSecondaryTargetLabel', 'keyboardInputSecondaryTargetVisibility',
|
||||
'keyboardInputHistoryOpacity'])
|
||||
this.notifyVisibilityMode()
|
||||
}
|
||||
private notifyPanel(properties: string[]): void {
|
||||
for (const property of properties) this.notifyPropertyChange(property, this.get(property))
|
||||
}
|
||||
private notifyVisibilityMode(): void {
|
||||
this.notifyPanel(['keyboardInputPhoneIconOpacity', 'keyboardInputGlassesIconOpacity', 'keyboardInputVisibilityDescription',
|
||||
'keyboardInputFieldClass', 'keyboardInputGlassesOnlyVisibility'])
|
||||
}
|
||||
get keyboardInputVisibility(): 'visible' | 'collapse' { return this.session ? 'visible' : 'collapse' }
|
||||
get keyboardInputText(): string { return this.text }
|
||||
set keyboardInputText(text: string) { this.text = text; this.session?.setText(text) }
|
||||
private targetLabel(index: number): string {
|
||||
const target = this.session?.targets[index]
|
||||
return target?.id === 'assistant' ? 'Send to Agent' : target?.id === 'app' ? 'Type into App' : target?.label ?? ''
|
||||
const label = this.session?.targets[index]?.label ?? ''
|
||||
return SHORT_TARGET_LABELS[label] ?? label
|
||||
}
|
||||
get keyboardInputPrimaryTargetLabel(): string { return this.targetLabel(0) }
|
||||
get keyboardInputSecondaryTargetLabel(): string { return this.targetLabel(1) }
|
||||
@@ -38,4 +70,61 @@ export class KeyboardInputViewModel extends Observable {
|
||||
this.session.sendTo(target.id)
|
||||
}
|
||||
onKeyboardInputDiscardTap(): void { this.session?.discard() }
|
||||
|
||||
// ---- visibility button: where the dialog shows ----
|
||||
//
|
||||
// Glasses-only keeps the text field focused (so the IME keeps typing into
|
||||
// it) but shrinks it to an invisible sliver; a hint line stands in for it
|
||||
// and refocuses it if the IME was dismissed.
|
||||
|
||||
private get visibilityMode(): KeyboardInputVisibility { return this.session?.visibility ?? 'both' }
|
||||
get keyboardInputPhoneIconOpacity(): number { return this.visibilityMode === 'glasses' ? DIMMED_ICON_OPACITY : 1 }
|
||||
get keyboardInputGlassesIconOpacity(): number { return this.visibilityMode === 'phone' ? DIMMED_ICON_OPACITY : 1 }
|
||||
get keyboardInputVisibilityDescription(): string { return VISIBILITY_DESCRIPTIONS[this.visibilityMode] }
|
||||
get keyboardInputFieldClass(): string { return this.visibilityMode === 'glasses' ? 'keyboard-input-field-hidden' : '' }
|
||||
get keyboardInputGlassesOnlyVisibility(): 'visible' | 'collapse' { return this.visibilityMode === 'glasses' ? 'visible' : 'collapse' }
|
||||
onKeyboardInputVisibilityTap(): void {
|
||||
if (!this.session) return
|
||||
this.session.setVisibility(NEXT_VISIBILITY[this.visibilityMode])
|
||||
this.notifyVisibilityMode()
|
||||
}
|
||||
onKeyboardInputGlassesOnlyHintTap(args: EventData): void {
|
||||
focusField(args.object as View)
|
||||
}
|
||||
|
||||
// ---- history button: recent sent messages (in memory, newest first) ----
|
||||
|
||||
get keyboardInputHistoryOpacity(): number { return this.session?.history.length ? 1 : DIMMED_ICON_OPACITY }
|
||||
async onKeyboardInputHistoryTap(args: EventData): Promise<void> {
|
||||
const session = this.session
|
||||
if (!session?.history.length) return
|
||||
const entries = new Map<string, string>()
|
||||
for (const entry of session.history) {
|
||||
const label = historyLabel(entry)
|
||||
if (!entries.has(label)) entries.set(label, entry)
|
||||
}
|
||||
const choice = await Dialogs.action({ title: 'Recent inputs', cancelButtonText: 'Cancel', actions: [...entries.keys()] })
|
||||
const text = entries.get(choice)
|
||||
if (text === undefined || session !== this.session) return
|
||||
const field = fieldNear(args.object as View)
|
||||
this.keyboardInputText = text
|
||||
// Through the view, not a property change: its textChange handler then
|
||||
// syncs the model and session the same way typing does.
|
||||
if (field) field.text = text
|
||||
focusField(args.object as View, text.length)
|
||||
}
|
||||
}
|
||||
|
||||
function fieldNear(view: View): TextView | undefined {
|
||||
return view.page?.getViewById<TextView>('keyboardInputField')
|
||||
}
|
||||
|
||||
/** Focus the panel's field (bringing the IME back), optionally placing the caret. */
|
||||
function focusField(view: View, caret?: number): void {
|
||||
setTimeout(() => {
|
||||
const field = fieldNear(view)
|
||||
if (!field) return
|
||||
field.focus()
|
||||
if (caret !== undefined) field.setSelection(caret)
|
||||
}, 0)
|
||||
}
|
||||
@@ -182,7 +182,8 @@
|
||||
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. Enter inserts a newline; the send
|
||||
buttons pick a destination directly. -->
|
||||
<rc:keyboard-input-panel />
|
||||
buttons pick a destination directly. Bound to its own model
|
||||
(KeyboardInputViewModel, shared with iOS). -->
|
||||
<rc:keyboard-input-panel bindingContext="{{ keyboardInputModel }}" />
|
||||
</GridLayout>
|
||||
</Page>
|
||||
@@ -1,4 +1,5 @@
|
||||
import { RemoteControlsViewModel } from './remote-controls-view-model';
|
||||
import { KeyboardInputViewModel } from './keyboard-input-view-model';
|
||||
import { BleBandwidthMeter } from "./ble-bandwidth-meter";
|
||||
import {
|
||||
Application,
|
||||
@@ -52,8 +53,6 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
private _activeTextEditorToggleValue = false;
|
||||
private _activeTextEditorToggleVisible = false;
|
||||
private _keyboardInputActive = false;
|
||||
private _keyboardInputTargets: ReadonlyArray<{ id: string; label: string }> = [];
|
||||
private _keyboardInputText = "";
|
||||
private _evenAppConflictMessage = "";
|
||||
private _evenAppConflictWarningVisible = false;
|
||||
private _firmwareWarningMessage = "";
|
||||
@@ -103,8 +102,8 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
this.activeTextEditorToggleLabel = snapshot.activeTextEditorToggleLabel;
|
||||
this.activeTextEditorToggleValue = snapshot.activeTextEditorToggleValue;
|
||||
this.activeTextEditorToggleVisible = snapshot.activeTextEditorToggleVisible;
|
||||
// Targets before active: the panel's buttons are labelled when it appears.
|
||||
this.keyboardInputTargets = snapshot.keyboardInputTargets;
|
||||
// Session before active: the panel is filled in when it appears.
|
||||
this.keyboardInputModel.setSession(dashboardController.keyboardInputSession);
|
||||
this.keyboardInputActive = snapshot.keyboardInputActive;
|
||||
this.evenAppConflictMessage = snapshot.evenAppConflictMessage;
|
||||
this.evenAppConflictWarningVisible = snapshot.evenAppConflictWarningVisible;
|
||||
@@ -494,11 +493,13 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
|
||||
// ---- keyboard-input panel (the keyboard button beside the mic button) ----
|
||||
//
|
||||
// The dialog lives on the glasses (ui/shell/keyboard-input.ts); this panel
|
||||
// is the phone's end of it: the text field the IME types into and a send
|
||||
// button per destination. The field's text is the panel's own state, never
|
||||
// echoed back from the controller (see setActiveTextSettingValue for why);
|
||||
// it is cleared whenever a dialog opens or closes.
|
||||
// The dialog lives on the glasses (ui/shell/keyboard-input.ts); the panel
|
||||
// is the phone's end of it, bound to keyboardInputModel (shared with iOS).
|
||||
// Its text is the panel's own state, never echoed back from the controller
|
||||
// (see setActiveTextSettingValue for why); it is cleared whenever a dialog
|
||||
// opens or closes.
|
||||
|
||||
readonly keyboardInputModel = new KeyboardInputViewModel();
|
||||
|
||||
get keyboardInputActive(): boolean {
|
||||
return this._keyboardInputActive;
|
||||
@@ -507,78 +508,14 @@ export class MainViewModel extends RemoteControlsViewModel {
|
||||
set keyboardInputActive(value: boolean) {
|
||||
if (this._keyboardInputActive === value) return;
|
||||
this._keyboardInputActive = value;
|
||||
this.keyboardInputText = "";
|
||||
this.notifyPropertyChange("keyboardInputActive", value);
|
||||
this.notifyPropertyChange("keyboardInputVisibility", this.keyboardInputVisibility);
|
||||
this.notifyPropertyChange("controlsVisibility", this.controlsVisibility);
|
||||
}
|
||||
|
||||
get keyboardInputVisibility(): "visible" | "collapse" {
|
||||
return this._keyboardInputActive ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get keyboardInputText(): string {
|
||||
return this._keyboardInputText;
|
||||
}
|
||||
|
||||
set keyboardInputText(value: string) {
|
||||
if (this._keyboardInputText === value) return;
|
||||
this._keyboardInputText = value;
|
||||
this.notifyPropertyChange("keyboardInputText", value);
|
||||
}
|
||||
|
||||
set keyboardInputTargets(value: ReadonlyArray<{ id: string; label: string }>) {
|
||||
this._keyboardInputTargets = value;
|
||||
this.notifyPropertyChange("keyboardInputPrimaryTargetLabel", this.keyboardInputPrimaryTargetLabel);
|
||||
this.notifyPropertyChange("keyboardInputPrimaryTargetVisibility", this.keyboardInputPrimaryTargetVisibility);
|
||||
this.notifyPropertyChange("keyboardInputSecondaryTargetLabel", this.keyboardInputSecondaryTargetLabel);
|
||||
this.notifyPropertyChange("keyboardInputSecondaryTargetVisibility", this.keyboardInputSecondaryTargetVisibility);
|
||||
}
|
||||
|
||||
// The glasses menu has at most two destinations (assistant, app), so the
|
||||
// panel has a fixed pair of buttons rather than a repeater.
|
||||
get keyboardInputPrimaryTargetLabel(): string {
|
||||
return this._keyboardInputTargets[0]?.label ?? "";
|
||||
}
|
||||
|
||||
get keyboardInputPrimaryTargetVisibility(): "visible" | "collapse" {
|
||||
return this._keyboardInputTargets[0] ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get keyboardInputSecondaryTargetLabel(): string {
|
||||
return this._keyboardInputTargets[1]?.label ?? "";
|
||||
}
|
||||
|
||||
get keyboardInputSecondaryTargetVisibility(): "visible" | "collapse" {
|
||||
return this._keyboardInputTargets[1] ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
onKeyboardTap(): void {
|
||||
dashboardController.startKeyboardInput();
|
||||
}
|
||||
|
||||
onKeyboardInputTextChange(args: { value?: string; object?: { text?: string } }): void {
|
||||
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 {
|
||||
const target = this._keyboardInputTargets[0];
|
||||
if (target) dashboardController.sendKeyboardInput(target.id);
|
||||
}
|
||||
|
||||
onKeyboardInputSecondarySendTap(): void {
|
||||
const target = this._keyboardInputTargets[1];
|
||||
if (target) dashboardController.sendKeyboardInput(target.id);
|
||||
}
|
||||
|
||||
onKeyboardInputDiscardTap(): void {
|
||||
dashboardController.discardKeyboardInput();
|
||||
}
|
||||
|
||||
get evenAppConflictMessage(): string {
|
||||
return this._evenAppConflictMessage;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user