UNPKG

@botonic/react

Version:

Build Chatbots using React

44 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeviceAdapter = void 0; const dom_1 = require("../../util/dom"); const _1 = require("."); const scrollbar_controller_1 = require("./scrollbar-controller"); const webchat_resizer_1 = require("./webchat-resizer"); class DeviceAdapter { constructor() { this.currentDevice = this.getCurrentDevice(); } init(host) { this.webchatResizer = new webchat_resizer_1.WebchatResizer(this.currentDevice, host); this.scrollbarController = new scrollbar_controller_1.ScrollbarController(this.currentDevice, host); this.scrollbarController.handleScrollEvents(); } getCurrentDevice() { // navigator.platform deprecated. Ref: (https://erikmartinjordan.com/navigator-platform-deprecated-alternative) if (navigator.userAgentData) return navigator.userAgentData.platform; return navigator.platform; } onFocus() { setTimeout(() => { var _a; // Place onFocus logic to be run the last on the queue of asynchronous events to give enough time to init method to be called. Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#zero_delays (_a = this.webchatResizer) === null || _a === void 0 ? void 0 : _a.onFocus(() => this.scrollbarController.handleOnTouchMoveEvents()); }, 0); } onBlur() { if (this.currentDevice !== _1.DEVICES.MOBILE.IPHONE) return; this.webchatResizer.onBlur(); this.scrollbarController.handleOnTouchMoveEvents(); } fontSize(defaultFontSize = 14) { if (this.currentDevice !== _1.DEVICES.MOBILE.IPHONE) return defaultFontSize; // Disabling auto-zoom on input (iPhone devices): https://stackoverflow.com/a/25614477, https://stackoverflow.com/a/6394497 return 'initial'; } } exports.DeviceAdapter = DeviceAdapter; //# sourceMappingURL=device-adapter.js.map