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,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)
|
||||
}
|
||||
Reference in new issue
Block a user