export const SECURE_TEXT_REDACTION = '' type KeyboardSpecLike = { secureTextEntry?: boolean | null keyboardType?: string | null } | null type KeyboardStateLike = { layout?: { spec?: KeyboardSpecLike } | null spec?: KeyboardSpecLike focusedInput?: Record | null } | null export function isSecureKeyboardState(state: KeyboardStateLike): boolean { const spec = state?.layout?.spec ?? state?.spec ?? null return !!spec?.secureTextEntry && spec.keyboardType !== 'visible-password' } export function redactTextForKeyboardState( text: string, state: KeyboardStateLike, ): string { return isSecureKeyboardState(state) ? SECURE_TEXT_REDACTION : text } export function redactKeyboardStateForOutput(state: T): T { if (!state || !isSecureKeyboardState(state)) return state const focusedInput = state.focusedInput if (!focusedInput || typeof focusedInput !== 'object') return state return { ...state, focusedInput: { ...focusedInput, secureTextEntry: true, text: typeof focusedInput.text === 'string' ? SECURE_TEXT_REDACTION : focusedInput.text, }, } }