all files / src/scroll/ pulldown.js

62.96% Statements 17/27
38.46% Branches 5/13
57.14% Functions 4/7
62.96% Lines 17/27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54                                                                         
import { ease } from '../util/ease'
import { DIRECTION_DOWN, PROBE_REALTIME } from '../util/const'
 
export function pullDownMixin (BScroll) {
  BScroll.prototype._initPullDown = function () {
    // must watch scroll in real time
    this.options.probeType = PROBE_REALTIME
  }
 
  BScroll.prototype._checkPullDown = function () {
    const { threshold = 90, stop = 40 } = this.options.pullDownRefresh
 
    // check if a real pull down action
    if (this.directionY !== DIRECTION_DOWN || this.y < threshold) {
      return false
    }
 
    Eif (!this.pulling) {
      this.pulling = true
      this.trigger('pullingDown')
    }
    this.scrollTo(this.x, stop, this.options.bounceTime, ease.bounce)
 
    return this.pulling
  }
 
  BScroll.prototype.finishPullDown = function () {
    this.pulling = false
    this.resetPosition(this.options.bounceTime, ease.bounce)
  }
 
  BScroll.prototype.openPullDown = function (config = true) {
    this.options.pullDownRefresh = config
    this._initPullDown()
  }
 
  BScroll.prototype.closePullDown = function () {
    this.options.pullDownRefresh = false
  }
 
  BScroll.prototype.autoPullDownRefresh = function () {
    const { threshold = 90, stop = 40 } = this.options.pullDownRefresh
 
    if (this.pulling) {
      return
    }
    this.pulling = true
 
    this.scrollTo(this.x, threshold)
    this.trigger('pullingDown')
    this.scrollTo(this.x, stop, this.options.bounceTime, ease.bounce)
  }
}