Skip to content

Commit bad65a2

Browse files
committedJul 19, 2017
fix(MdApp): fix fixed-last not revealing the first row after scroll up
1 parent f537e12 commit bad65a2

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed
 

‎src/components/MdApp/MdAppMixin.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ export default {
4646
top: 0,
4747
titleSize: 20,
4848
hasElevation: true,
49-
revealActive: false
49+
revealActive: false,
50+
fixedLastActive: false,
51+
fixedLastHeigth: false
5052
},
5153
drawer: {
5254
active: false,
@@ -188,28 +190,25 @@ export default {
188190
}
189191
},
190192
handleFixedLastMode ($event) {
191-
let { scrollTop, toolbarHeight } = this.getToolbarConstrants($event)
193+
let { scrollTop, toolbarHeight, safeAmount } = this.getToolbarConstrants($event)
192194
const toolbar = this.MdApp.toolbar.element
193195
const firstRow = toolbar.querySelector('.md-toolbar-row:first-child')
194196
const firstRowHeight = firstRow.offsetHeight
195197

196-
if (scrollTop > firstRowHeight) {
197-
this.setToolbarMarginAndHeight(scrollTop - firstRowHeight, toolbarHeight)
198-
} else {
199-
this.setToolbarMarginAndHeight(0, toolbarHeight)
200-
}
198+
window.clearTimeout(this.revealTimer)
201199

202-
/* if (firstRowHeight) {
203-
if (scrollTop < initialHeight - firstRowHeight) {
204-
toolbar.style.height = scrollAmount + 'px'
205-
} else {
206-
toolbar.style.height = firstRowHeight + 'px'
207-
}
208-
}
200+
this.revealTimer = window.setTimeout(() => {
201+
this.revealLastPos = scrollTop
202+
}, 100)
209203

210-
let { threshold, toolbarHeight } = this.getToolbarConstrants($event)
204+
this.setToolbarMarginAndHeight(scrollTop - firstRowHeight, toolbarHeight)
205+
this.MdApp.toolbar.fixedLastHeigth = firstRowHeight
211206

212-
this.setToolbarMarginAndHeight(scrollTop - threshold, toolbarHeight) */
207+
if (scrollTop >= firstRowHeight) {
208+
this.MdApp.toolbar.fixedLastActive = this.revealLastPos > scrollTop + safeAmount
209+
} else {
210+
this.MdApp.toolbar.fixedLastActive = true
211+
}
213212
},
214213
handleModeScroll ($event) {
215214
if (this.mdMode === 'reveal') {
@@ -253,6 +252,7 @@ export default {
253252
}
254253

255254
if (this.mdMode === 'fixed-last') {
255+
this.MdApp.toolbar.fixedLastActive = true
256256
this.handleFixedLastMode({
257257
target: {
258258
scrollTop: 0

‎src/components/MdApp/MdAppToolbar.vue

+15-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@
1212
toolbarClasses () {
1313
return {
1414
'md-no-elevation': !this.MdApp.toolbar.hasElevation,
15-
'md-reveal-active': this.MdApp.toolbar.revealActive
15+
'md-reveal-active': this.MdApp.toolbar.revealActive,
16+
'md-fixed-last-active': this.MdApp.toolbar.fixedLastActive
1617
}
1718
},
1819
toolbarStyles () {
19-
return {
20+
let styles = {
2021
'top': `${this.MdApp.toolbar.top}px`
2122
}
23+
24+
if (this.MdApp.toolbar.fixedLastActive) {
25+
styles['transform'] = `translate3D(0, ${this.MdApp.toolbar.fixedLastHeigth}px, 0)`
26+
}
27+
28+
return styles
2229
}
2330
},
2431
mounted () {
@@ -51,4 +58,10 @@
5158
will-change: height, box-shadow, transform;
5259
}
5360
}
61+
62+
.md-fixed-last-active {
63+
transition: .3s $md-transition-stand-timing;
64+
transition-property: box-shadow, transform;
65+
will-change: height, box-shadow, transform;
66+
}
5467
</style>

0 commit comments

Comments
 (0)