UNPKG

@botonic/react

Version:

Build Chatbots using React

47 lines 2.08 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(host) { if (this.currentDevice !== _1.DEVICES.MOBILE.IPHONE) { (0, dom_1.scrollToBottom)({ host, timeout: 800 }); return; } setTimeout(() => { // 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 this.webchatResizer.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