Skip to content

Commit

Permalink
fix(modal): better scroll behaviour for scrollable areas (iOS)
Browse files Browse the repository at this point in the history
  • Loading branch information
BowlingX committed Mar 6, 2016
1 parent 6b47305 commit f29b4a1
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 26 deletions.
2 changes: 1 addition & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ <h3>Build-Status</h3>
ga('send', 'pageview');
</script>
<script src="//cdn.polyfill.io/v1/polyfill.min.js" async defer></script>
<script type="application/javascript" src="{{ site.baseurl }}/build/js/flexcss.min.js"></script>
<script type="application/javascript" src="{{ site.baseurl }}/build/js/flexcss.js"></script>
<script type="application/javascript">
(function (document) {
document.addEventListener('DOMContentLoaded', function () {
Expand Down
39 changes: 34 additions & 5 deletions build/js/flexcss.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions build/js/flexcss.min.js

Large diffs are not rendered by default.

39 changes: 34 additions & 5 deletions build/js/modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/js/modal.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/maps/flexcss.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/maps/flexcss.min.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/maps/form.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/maps/form.min.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/maps/modal.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/maps/modal.min.map

Large diffs are not rendered by default.

38 changes: 33 additions & 5 deletions src/main/lib/FixedWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ export default class FixedWindow {
e.preventDefault();
};

let shouldNotMove = false;
let shouldNotMoveUp = false;
let shouldNotMoveDown = false;
let neverScroll = false;
let lastClientY = 0;
this.touchStartListener = (e) => {
let { element } = this.getCurrentWidget();
const closestOverflow = Util.closestCallback(e.target,
Expand All @@ -111,11 +114,17 @@ export default class FixedWindow {
element = closestOverflow;
}
if (Util.isPartOfNode(e.target, element)) {
neverScroll = element.scrollHeight === element.offsetHeight;
lastClientY = e.touches[0].clientY;
// never allow scrolling when there is nothing to scroll
if (neverScroll) {
return false;
}
if (element.scrollTop === 0) {
element.scrollTop = 1;
shouldNotMove = true;
shouldNotMoveUp = true;
} else if (element.scrollHeight === element.scrollTop + element.offsetHeight) {
shouldNotMove = true;
shouldNotMoveDown = true;
element.scrollTop -= 1;
}
}
Expand All @@ -127,10 +136,29 @@ export default class FixedWindow {
this.touchMoveListener = (e) => {
const { element } = this.getCurrentWidget();
if (Util.isPartOfNode(e.target, element)) {
if (!shouldNotMove) {
const { clientY } = e.touches[0];
const isScrollingDown = (lastClientY - clientY) > 0;
lastClientY = clientY;

if (neverScroll) {
neverScroll = false;
return false;
}

if (!shouldNotMoveDown && isScrollingDown) {
e.stopImmediatePropagation();
}
shouldNotMove = false;

if (shouldNotMoveDown && !isScrollingDown) {
e.stopImmediatePropagation();
}

if (!shouldNotMoveDown && !shouldNotMoveUp && !isScrollingDown) {
e.stopImmediatePropagation();
}

shouldNotMoveUp = false;
shouldNotMoveDown = false;
}
};
global.document.body.addEventListener('touchmove', this.touchMoveListener);
Expand Down

0 comments on commit f29b4a1

Please sign in to comment.