Titanium tableview android 和 ios 下拉刷新(pull to refresh )


#====================== 主布局 =================================

    wrapper = Ti.UI.createScrollView

        showVerticalScrollIndicator: true

        showHorizontalScrollIndicator: false

        width: Ti.UI.FILL

        top: 0

        bottom: if Ti.App.is_android then __l(54) else null

        scrollingEnabled: if Ti.App.is_android then false else true



    table_view = Ti.UI.createTableView

        width: '100%'

        backgroundColor: '#fff'

        #bottom: if Ti.App.is_android then __l(54) else null

        data: table_data



    table_header = Ti.UI.createView

        backgroundColor: "#f6f6f6"

        width : Ti.App.platform_width

        height : __l(60)

        textAlign : 'center'



    status_label_of_table_header = Ti.UI.createLabel

        text : "下拉可以刷新..."

        width : __l(200)

        bottom : __l(15)

        height : __l(17)

        color : "#576c89"

        textAlign : 'center'

        textAlign : "center"

        font :

            fontSize : __l(12)



    table_header.add status_label_of_table_header

    table_view.headerPullView = table_header


    pull_to_get_data =(callback) ->

        get_data()

        callback()

    pulling = false
#====================== ios 下拉刷新 =================================


    table_view.addEventListener 'scroll', (e) ->

        console.info "=======  in table_view, scroll event"

        if (Ti.App.is_android)

            return

        offset = e.contentOffset.y

        if (offset <= -65.0 && !pulling)

            pulling = true

            status_label_of_table_header.text = "释放即可更新..."

        else

            if pulling && offset > -65.0 && offset < 0

                pulling = false

                status_label_of_table_header.text = "下拉可以刷新..."



    table_view.addEventListener "dragend", (e) ->

        if pulling

            table_view.setContentInsets

                top : __l(60)

                animated : true

            pull_to_get_data ->

                status_label_of_table_header.text = "下拉可以刷新..."

                table_view.setContentInsets

                    top : __l(0)

                    animated : true

                return

            pulling = false

            return


    #====================== android 下拉刷新 =================================
    if Ti.App.is_android

        swipeRefreshModule = require 'com.rkam.swiperefreshlayout'

        swipeRefresh = swipeRefreshModule.createSwipeRefresh

            view: table_view

            #bottom: __l(54)

            height: Ti.UI.FILL

            width: Ti.UI.FILL

        table_view.bottom = 0

        swipeRefresh.addEventListener 'refreshing', ->

            pull_to_get_data ->

                swipeRefresh.setRefreshing(false)

                return

        wrapper.add swipeRefresh

        change_record_win.add wrapper

    else

        #wrapper.add table_view

        change_record_win.add table_view


 wrapper = Ti.UI.createScrollView({
    showVerticalScrollIndicator: true,
    showHorizontalScrollIndicator: false,
    width: Ti.UI.FILL,
    top: 0,
    bottom: Ti.App.is_android ? __l(54) : null,
    scrollingEnabled: Ti.App.is_android ? false : true
  });
  table_view = Ti.UI.createTableView({
    width: '100%',
    backgroundColor: '#fff',
    data: table_data
  });
  table_header = Ti.UI.createView({
    backgroundColor: "#f6f6f6",
    width: Ti.App.platform_width,
    height: __l(60),
    textAlign: 'center'
  });
  status_label_of_table_header = Ti.UI.createLabel({
    text: "下拉可以刷新...",
    width: __l(200),
    bottom: __l(15),
    height: __l(17),
    color: "#576c89",
    textAlign: 'center',
    textAlign: "center",
    font: {
      fontSize: __l(12)
    }
  });
  table_header.add(status_label_of_table_header);
  table_view.headerPullView = table_header;
  pull_to_get_data = function(callback) {
    get_data();
    return callback();
  };
  pulling = false;

table_view.addEventListener('scroll', function(e) {

    var offset;

    console.info("=======  in table_view, scroll event");

    if (Ti.App.is_android) {

      return;

    }

    offset = e.contentOffset.y;

    if (offset <= -65.0 && !pulling) {

      pulling = true;

      return status_label_of_table_header.text = "释放即可更新...";

    } else {

      if (pulling && offset > -65.0 && offset < 0) {

        pulling = false;

        return status_label_of_table_header.text = "下拉可以刷新...";

      }

    }

  });

  table_view.addEventListener("dragend", function(e) {

    if (pulling) {

      table_view.setContentInsets({

        top: __l(60),

        animated: true

      });

      pull_to_get_data(function() {

        status_label_of_table_header.text = "下拉可以刷新...";

        table_view.setContentInsets({

          top: __l(0),

          animated: true

        });

      });

      pulling = false;

    }

  });

  if (Ti.App.is_android) {

    swipeRefreshModule = require('com.rkam.swiperefreshlayout');

    swipeRefresh = swipeRefreshModule.createSwipeRefresh({

      view: table_view,

      height: Ti.UI.FILL,

      width: Ti.UI.FILL

    });

    table_view.bottom = 0;

    swipeRefresh.addEventListener('refreshing', function() {

      return pull_to_get_data(function() {

        swipeRefresh.setRefreshing(false);

      });

    });

    wrapper.add(swipeRefresh);

    change_record_win.add(wrapper);

  } else {

    change_record_win.add(table_view);

  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值