目录

refresh-header (1090+)

Overview

Pull-to-refresh header container of refresh2.

Application Scope

Item

Description

Applicable devices

Mobile phones, tablets, Vision products, and telematics devices

Applicable regions

Global

Subelements

Supported.

Attributes

In addition to general attributes, the attributes listed in the following table are supported.

Attribute

Type

Default Value

Mandatory

Description

dragRate

number

0.5

No

Drag rate, calculated based on Header movement distance / Gesture movement distance.

triggerRatio

number

0.7

No

Movement rate, which is used to calculate the header movement distance (Header movement distance = Value of triggerRatio x Header height). The priority of triggerRatio is lower than that of triggerSize.

tiggerSize

number

0

No

Movement distance when the refresh is triggered. This attribute, which is valid when its value is greater than 0, has a higher priority than triggerRatio.

Unit: px

maxdragratio

number

1

No

Maximum rate that the header can move. The value of maxdragratio multiplied by header height is equal to the value of maxdragsize.

maxdragsize

number

0

No

Maximum movement distance that a header can move. This attribute, which is valid when its value is greater than 0, has a higher priority than maxdragratio. Unit: px

refreshdisplayratio

number

0.7

No

Header display height rate when the refresh is trigger. The value of refreshdisplayratio multiplied by header height is equal to the value of refreshdisplaysize. The default value is 0.7.

refreshdisplaysize

number

0

No

Header display height when the refresh is triggered. This attribute, which is valid when its value is greater than 0, has a higher priority than refreshdisplayratio.

Unit: px

spinnerstyle

string

translation

No

Header display style. The options are as follows:

  • translation: The content moves with the header.
  • front: The header is displayed above the content, which does not move with the header.
  • behind: The header is displayed below the content, which does not move with the header.

autorefresh

boolean

false

No

Indicates whether to enable automatic loading when the element is scrolled to the top.

translationwithcontent

boolean

false

No

Indicates whether to display the header during the refresh. The default value is false.

Styles

Common styles are supported.

Events

In addition to common events, the events listed in the following table are supported.

Event

Parameter

Triggering Conditions

move

{scrollY:number,percent:number,isDrag:boolean,refreshing:boolean}

The header moves.

scrollY: moving distance of the header relative to the initial position. When the header is pulled down, the value is positive.

percent: movement rate, calculated based on Header movement distance/Movement distance to trigger a refresh. When percent is greater than or equal to 1f (floating-point number), the refresh is triggered.

isDrag: indicates whether to enable gesture drag.

refreshing: indicates whether to process the current refresh status. Movement is supported during the refresh.

Sample Code

<import name="movie-item" src="../Common/SR399/movie-item.ux"></import>
<template>
  <div class="root">
    <refresh2 id="refresh" style="background-color:{{backgroundColor}};progress-color:{{progressColor}};" offset="132px" animationduration="300" class="container" reboundable="true" type="auto" @refresh="refresh" @pulluprefresh="pullUpRefresh" @pulldownrefresh="pullDownRefresh" gesture="true" enablepulldown="true" enablepullup="true">
      <refresh-header class="header" spinnerstyle="behind" translationwithcontent="false" @move="headerMove" autorefresh="true">
        <progress class="circular" type="circular" style="color: #fff" />
      </refresh-header>
      <!-- content -->
      <div class="content-list">
        <list class="list" id="movie-list" @scrollbottom="loadMoreData">
          <list-item type="listItem" for="{{dataList}}" tid="$item.id">
            <movie-item item="{{$item}}"></movie-item>
          </list-item>
        </list>
      </div>
    </refresh2>
  </div>
</template>
<style>
  .root {
    align-items: center;
  }
  .list {
    padding-left: 16px;
    padding-right: 16px;
  }
  .content-list {
    background-color: #D0D0D0;
    flex-direction: column;
    align-items: center;
  }
  .container {
    height: 100%;
    width: 100%;
  }
  .header {
    height: 175%;
    width: 100%;
    background-color: #800000;
    justify-content: center;
    align-items: center;
  }
  .content {
    width: 100%;
    height: 100%;
    background-color: #ffffff;
  }
  .txt {
    width: 100%;
    height: 100px;
  }
  .circular {
    width: 100%;
    height: 75px;
  }
  .footer {
    height: 100px;
    width: 100%;
    background-color: #008000;
    justify-content: center;
    align-items: center;
  }
  .loading {
    color: #ffffff;
  }
</style>
<script>
import api from '../Common/SR399/service.js'
  const LOAD_MORE_INITIAL_INDEX = 1;
  const LOAD_MORE_INCREASE_THRESHOLD = 1;
  module.exports = {
    backgroundColor: "#ffffff",
    progressColor: "#ffffff",
    data: {
      dataList: [],
      currentTotalPages: Number.MAX_SAFE_INTEGER,
      currentPage: LOAD_MORE_INITIAL_INDEX,
    },
    computed: {
      loadMoreEnabled: {
        get() {
          return this.currentPage < this.currentTotalPages
        }
      },
    },
    onReady(options) {
      this.getData(LOAD_MORE_INITIAL_INDEX)
    },
    // Service calls
    loadMoreData: function () {
      if (this.loadMoreEnabled) {
        this.getData(this.currentPage + LOAD_MORE_INCREASE_THRESHOLD)
      }
    },
    clearData: function () {
      this.dataList = []
    },
    getData: function (page) {
      this.currentPage = page
      var app = this
      api.callGet({ page: page }, function (data) {
        if (page > LOAD_MORE_INCREASE_THRESHOLD) {
          data.results.forEach(movie => {
            app.dataList.push(movie)
          });
        } else {
          app.dataList = data.results
        }
        app.currentTotalPages = data.total_pages
      })
    },
    pullDownRefresh: function () {
      console.log("pullDownRefresh");
      console.log("pulldownrefreshing:" + this.$element('refresh').pulldownrefreshing)
      console.log("pulluprefreshing:" + this.$element('refresh').pulluprefreshing)
      this.$element('refresh').startPullDownRefresh()
      setTimeout(() => {
        this.clearData()
        this.getData(LOAD_MORE_INITIAL_INDEX)
        this.finishPullDownRefresh()
      }, 1500);
    },
    pullUpRefresh: function () {
      console.log("pullUpRefresh");
      console.log("pulldownrefreshing:" + this.$element('refresh').pulldownrefreshing)
      console.log("pulluprefreshing:" + this.$element('refresh').pulluprefreshing)
      this.$element('refresh').startPullUpRefresh();
      setTimeout(() => {
        this.finishPullUpRefresh()
      }, 1500);
    },
    refresh: function (e) {
      console.log("refresh:" + e.refreshing);
    },
    headerMove: function (params) {
      console.log("headermove - scrollY:" + params.scrollY + " percent:" + params.percent + " isDrag:" + params.isDrag + " refreshing:" + params.refreshing);
    },
    footerMove: function (params) {
      console.log("footermove - scrollY:" + params.scrollY + " percent:" + params.percent + " isDrag:" + params.isDrag + " refreshing:" + params.refreshing)
    },
    finishPullDownRefresh: function () {
      console.log("finishPullDownRefresh")
      this.$element('refresh').stopPullDownRefresh()
    },
    finishPullUpRefresh: function () {
      console.log("finishPullUpRefresh")
      this.$element('refresh').stopPullUpRefresh()
    },
  }
</script>

Version Change History

Version

Date

Description

1090

2022-05-19

First official version.