UNPKG

react-native-acoustic-connect-beta

Version:

BETA: React native plugin for Acoustic Connect

110 lines (107 loc) 3.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _reactNative = require("react-native"); var _TLTRN2 = _interopRequireDefault(require("../TLTRN")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /******************************************************************************************** * Copyright (C) 2025 Acoustic, L.P. All rights reserved. * * NOTICE: This file contains material that is confidential and proprietary to * Acoustic, L.P. and/or other developers. No license is granted under any intellectual or * industrial property rights of Acoustic, L.P. except as may be provided in an agreement with * Acoustic, L.P. Any unauthorized copying or distribution of content from this file is * prohibited. ********************************************************************************************/ class KeyboardListener { static TLTRN = null; static listener = null; static _instance(_TLTRN) { if (!KeyboardListener.listener) { KeyboardListener.listener = new KeyboardListener(_TLTRN); } return KeyboardListener.listener; } constructor(_TLTRN) { KeyboardListener.TLTRN = _TLTRN; this.enabled = false; let _x = {}; let _i = {}; const sanitize = (target, text) => { if (!_x[target].secureTextEntry || typeof _x[target].secureTextEntry === "undefined") { return text; } return new Array(text.length).fill("*").join(""); }; const flushData = () => { _i = {}; _x = {}; }; const keyListener = (evt, bubbledEvent) => { let _nativeTag = evt?.target?._nativeTag; let valid = this.enabled && (!_i[_nativeTag] || _i[_nativeTag] === bubbledEvent); if (!valid) { return; } _i[_nativeTag] = bubbledEvent; if (!_x[_nativeTag]) { _x[_nativeTag] = { text: "" }; } _x[_nativeTag].target = evt?.target?._nativeTag; _x[_nativeTag].controlId = evt?._targetInst?.memoizedProps?.id; _x[_nativeTag].ariaLabel = evt?._targetInst?.memoizedProps?.accessible?.accessibilityLabel; _x[_nativeTag].secureTextEntry = evt?._targetInst?.memoizedProps?.secureTextEntry; const anon = _k => { if (_k !== "Backspace" && _k.length === 1) { return _x[_nativeTag].text += sanitize(_nativeTag, _k); } else if (_k !== "Backspace" && _k.length > 1) { return sanitize(_nativeTag, _k); } else { return _x[_nativeTag].text.slice(0, -1); } }; let text = null; switch (bubbledEvent) { case "onTextInput": text = evt?.nativeEvent?.text; _x[_nativeTag].text = sanitize(_nativeTag, text || ""); break; case "onKeyPress": text = evt?.nativeEvent?.key; _x[_nativeTag].text = anon(text || ""); break; case "onChange": text = evt?.nativeEvent?.text; _x[_nativeTag].text = sanitize(_nativeTag, text || ""); break; } }; const keyboardDidHide = async () => { let values = Object.values(_x); for (let value of values) { let { text, controlId, ariaLabel, target } = value; _TLTRN2.default.logTextChangeEvent(target, controlId, text, ariaLabel); } flushData(); }; // @ts-ignore: Ignore TypeScript error for defaultProps _reactNative.TextInput.defaultProps = _reactNative.TextInput.defaultProps || {}; // @ts-ignore: Ignore TypeScript error for defaultProps _reactNative.TextInput.defaultProps.onChange = evt => keyListener(evt, "onChange"); _reactNative.Keyboard.addListener("keyboardDidHide", keyboardDidHide); } interceptKeyboardEvents(enable) { this.enabled = enable; } } var _default = exports.default = KeyboardListener; //# sourceMappingURL=KeyboardListener.js.map