Skip to content

Commit

Permalink
Foreground detection mixin service for widgets (#1404)
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Also-by: Yannick Schaus <github@schaus.net>
  • Loading branch information
digitaldan authored Jun 22, 2022
1 parent 78d6090 commit 182aada
Showing 1 changed file with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export default {
data () {
return {
pageEl: null,
inForeground: false
}
},
mounted () {
const isInModal = this.$el.closest('.framework7-modals')
if (isInModal) {
this.inForeground = true
this.startForegroundActivity()
return
}

this.pageEl = this.$el.closest('.page')
if (this.pageEl && this.pageEl.classList.contains('page-current')) {
this.inForeground = true
this.startForegroundActivity()
}

this.$f7.on('pageAfterIn', this.onPageAfterIn)
this.$f7.on('pageBeforeOut', this.onPageBeforeOut)
},
beforeDestroy () {
this.$f7.off('pageAfterIn', this.onPageAfterIn)
this.$f7.off('pageBeforeOut', this.onPageBeforeOut)
this.stopForegroundActivity()
},
methods: {
startForegroundActivity () {
// override this in your widget
},
stopForegroundActivity () {
// override this in your widget
},
onPageAfterIn (page) {
if (page.el === this.pageEl) {
this.inForeground = true
this.startForegroundActivity()
}
},
onPageBeforeOut (page) {
if (page.el === this.pageEl) {
this.inForeground = false
this.stopForegroundActivity()
}
}
}
}

0 comments on commit 182aada

Please sign in to comment.