Skip to content

Commit

Permalink
old ios optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
yamaha252 committed Dec 10, 2018
1 parent a8244c2 commit d64443b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions css/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ html, body {
background: #e5e5e5;
font-family: 'Lato', sans-serif;
margin: 0 auto;
-webkit-overflow-scrolling: touch;
}

html, body,
Expand Down
3 changes: 3 additions & 0 deletions src/widget/chat-frame.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { h, Component } from 'preact';
import {mobileOpenWrapperStyle} from "./style";

export default class ChatFrame extends Component {

Expand All @@ -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',
}}>
</iframe>
);
Expand Down
1 change: 1 addition & 0 deletions src/widget/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const mobileClosedWrapperStyle = {
};

export const mobileOpenWrapperStyle = {
'-webkit-overflow-scrolling': 'touch',
display: 'flex',
flexDirection: 'column',
position: 'fixed',
Expand Down
12 changes: 12 additions & 0 deletions src/widget/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit d64443b

Please sign in to comment.