Skip to content

Commit efca853

Browse files
committed
feat: Prevent body scroll when on mobile (like on Android platform)
1 parent 8e05716 commit efca853

File tree

6 files changed

+36
-32
lines changed

6 files changed

+36
-32
lines changed

src/components/layout/QLayoutDrawer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ModelToggleMixin from '../../mixins/model-toggle'
66
import PreventScroll from '../../mixins/prevent-scroll'
77

88
const
9-
bodyClass = 'q-drawer-scroll',
9+
bodyClass = 'q-body-drawer-toggle',
1010
duration = 150
1111

1212
export default {
@@ -396,6 +396,7 @@ export default {
396396
if (otherSide && otherSide.mobileOpened) {
397397
otherSide.hide()
398398
}
399+
399400
if (this.belowBreakpoint) {
400401
this.mobileOpened = true
401402
this.applyBackdrop(1)

src/components/layout/layout.ios.styl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,19 @@ $layout-transition = all .12s ease-in
5555
> span
5656
pointer-events auto
5757

58-
body
59-
&.q-layout-animate .q-layout-transition
60-
transition $layout-transition
58+
body.cordova.platform-ios
59+
.q-layout-header > .q-toolbar:first-child,
60+
.q-layout-header > .q-tabs:first-child .q-tabs-head
61+
.q-layout-drawer.top-padding
62+
padding-top $ios-statusbar-height
63+
min-height ($toolbar-min-height + $ios-statusbar-height)
6164

62-
&.cordova.platform-ios
63-
.q-layout-header > .q-toolbar:first-child,
64-
.q-layout-header > .q-tabs:first-child .q-tabs-head
65-
.q-layout-drawer.top-padding
66-
padding-top $ios-statusbar-height
67-
min-height ($toolbar-min-height + $ios-statusbar-height)
68-
69-
.q-drawer-scroll
65+
/* body */
66+
.q-layout-animate .q-layout-transition
67+
transition $layout-transition
68+
.q-body-drawer-toggle
7069
overflow-x hidden
70+
/* body - end */
7171

7272
.layout-padding
7373
@media (max-width $breakpoint-sm-max)

src/components/layout/layout.mat.styl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ $layout-transition = all .12s ease-in
5353
> span
5454
pointer-events auto
5555

56-
body
57-
&.q-layout-animate .q-layout-transition
58-
transition $layout-transition
56+
body.cordova.platform-ios
57+
.q-layout-header > .q-toolbar:first-child,
58+
.q-layout-header > .q-tabs:first-child .q-tabs-head
59+
.q-layout-drawer.top-padding
60+
padding-top $ios-statusbar-height
61+
min-height ($toolbar-min-height + $ios-statusbar-height)
5962

60-
&.cordova.platform-ios
61-
.q-layout-header > .q-toolbar:first-child,
62-
.q-layout-header > .q-tabs:first-child .q-tabs-head
63-
.q-layout-drawer.top-padding
64-
padding-top $ios-statusbar-height
65-
min-height ($toolbar-min-height + $ios-statusbar-height)
66-
67-
.q-drawer-scroll
63+
/* body */
64+
.q-layout-animate .q-layout-transition
65+
transition $layout-transition
66+
.q-body-drawer-toggle
6867
overflow-x hidden
68+
/* body - end */
6969

7070
.layout-padding
7171
@media (max-width $breakpoint-sm-max)

src/css/core/helpers.styl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
color inherit
4040
opacity .5
4141

42-
body.with-mixin-fullscreen
42+
/* body */
43+
.q-body-fullscreen-mixin, .q-body-prevent-scroll
4344
overflow hidden !important
4445

4546
.q-no-input-spinner

src/mixins/fullscreen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default {
2929
this.container = this.$el.parentNode
3030
this.container.replaceChild(this.fullscreenFillerNode, this.$el)
3131
document.body.appendChild(this.$el)
32-
document.body.classList.add('with-mixin-fullscreen')
32+
document.body.classList.add('q-body-fullscreen-mixin')
3333

3434
this.__historyFullscreen = {
3535
handler: this.exitFullscreen
@@ -46,7 +46,7 @@ export default {
4646
this.__historyFullscreen = null
4747
}
4848
this.container.replaceChild(this.$el, this.fullscreenFillerNode)
49-
document.body.classList.remove('with-mixin-fullscreen')
49+
document.body.classList.remove('q-body-fullscreen-mixin')
5050
this.inFullscreen = false
5151
}
5252
},

src/mixins/prevent-scroll.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ function shouldPreventScroll (e) {
3434
export default {
3535
methods: {
3636
__preventScroll (register) {
37-
if (!this.$q.platform.is.desktop) {
38-
return
39-
}
40-
4137
registered += register ? 1 : -1
4238
if (registered > 1) { return }
4339

44-
const action = `${register ? 'add' : 'remove'}EventListener`
45-
window[action]('wheel', onWheel)
40+
const action = register ? 'add' : 'remove'
41+
42+
if (this.$q.platform.is.mobile) {
43+
document.body.classList[action]('q-body-prevent-scroll')
44+
}
45+
else if (this.$q.platform.is.desktop) {
46+
window[`${action}EventListener`]('wheel', onWheel)
47+
}
4648
}
4749
}
4850
}

0 commit comments

Comments
 (0)