PullUpLoadMore.ets 1.21 KB
import PageModel from '../viewmodel/PageModel';
import { RefreshConstants as Const } from './RefreshConstants';
import PageHelper from '../viewmodel/PageHelper';

export function touchMoveLoadMore(model: PageModel, event: TouchEvent) {
  // list size +1
  if (model.endIndex === model.compList.totalCount() || model.endIndex === model.compList.totalCount() + 1) {
    model.offsetY = event.touches[0].y - model.downY;
    if (Math.abs(model.offsetY) > vp2px(model.pullUpLoadHeight) / 2) {
      model.isCanLoadMore = true;
      model.isVisiblePullUpLoad = true;
      model.offsetY = -vp2px(model.pullUpLoadHeight) + model.offsetY * Const.Y_OFF_SET_COEFFICIENT;
    }
  }
}

export function touchUpLoadMore(model: PageModel) {
  let self: PageModel = model;
  animateTo({
    duration: Const.ANIMATION_DURATION,
  }, () => {
    self.offsetY = 0;
  })
  if ((self.isCanLoadMore === true) && (self.hasMore === true)) {
    self.isLoading = true;
    setTimeout(() => {
      closeLoadMore(model);
      PageHelper.loadMore(self)
    }, Const.DELAY_TIME);
  } else {
    closeLoadMore(self);
  }
}

export function closeLoadMore(model: PageModel) {
  model.isCanLoadMore = false;
  model.isLoading = false;
  model.isVisiblePullUpLoad = false;
}