From d64443bef5d47bc13d44c21d58315959a51d07bd Mon Sep 17 00:00:00 2001 From: yamaha252 Date: Mon, 10 Dec 2018 22:03:41 +0500 Subject: [PATCH] old ios optimisations --- css/chat.css | 1 + src/widget/chat-frame.js | 3 +++ src/widget/style.js | 1 + src/widget/widget.js | 12 ++++++++++++ 4 files changed, 17 insertions(+) diff --git a/css/chat.css b/css/chat.css index fe76117..4e9e8db 100644 --- a/css/chat.css +++ b/css/chat.css @@ -5,6 +5,7 @@ html, body { background: #e5e5e5; font-family: 'Lato', sans-serif; margin: 0 auto; + -webkit-overflow-scrolling: touch; } html, body, diff --git a/src/widget/chat-frame.js b/src/widget/chat-frame.js index 3a10206..c5e86f0 100644 --- a/src/widget/chat-frame.js +++ b/src/widget/chat-frame.js @@ -1,4 +1,5 @@ import { h, Component } from 'preact'; +import {mobileOpenWrapperStyle} from "./style"; export default class ChatFrame extends Component { @@ -17,6 +18,8 @@ export default class ChatFrame extends Component { flex: '1', width: '100%', height: 0, + // ios position fixed hack + maxHeight: isMobile ? document.body.clientHeight : 'auto', }}> ); diff --git a/src/widget/style.js b/src/widget/style.js index 62cf8b3..006f607 100644 --- a/src/widget/style.js +++ b/src/widget/style.js @@ -35,6 +35,7 @@ export const mobileClosedWrapperStyle = { }; export const mobileOpenWrapperStyle = { + '-webkit-overflow-scrolling': 'touch', display: 'flex', flexDirection: 'column', position: 'fixed', diff --git a/src/widget/widget.js b/src/widget/widget.js index 173f246..6e32c76 100644 --- a/src/widget/widget.js +++ b/src/widget/widget.js @@ -16,6 +16,7 @@ export default class Widget extends Component { constructor() { super(); + this.scrollPosition = 0; this.state.isChatOpen = false; this.state.pristine = true; this.state.wasChatOpened = this.wasChatOpened(); @@ -73,6 +74,17 @@ export default class Widget extends Component { this.setCookie(); stateData.wasChatOpened = true; } + + // reset and restore scroll position for position fixed bug on old ios + if (this.props.isMobile) { + if (stateData.isChatOpen) { + this.scrollPosition = document.body.scrollHeight; + window.scrollTo(0, 0); + } else { + window.scrollTo(0, this.scrollPosition); + } + } + this.setState(stateData); }