List Pull Refresh Plugin for Sencha Touch

本文介绍了一种在移动应用中优化用户体验的方法,即通过实现Pull-to-Refresh交互替代传统的刷新按钮,减少界面杂乱并提升用户操作流畅性。文中详细解释了如何通过自定义插件来实现场景转换,从正常状态到拉取刷新直至加载完成的过程,并提供了使用示例和代码实现。同时,文章还讨论了如何确保用户在不希望刷新时可以轻松退出此操作,以及如何集成该插件到现有应用中。


List Pull Refresh Plugin for Sencha Touch

by Shea Frederick on January 10th, 2011

One thing that you find out quickly when developing for mobile, is that mobile devices require us to be much more creative with our usage of UI features. It's not all about adding another button here, or a form field there - that takes up too much space - it's about harnessing simple and natural gestures to perform the functionality we need.

Be Gone Refresh Button!

Refresh ButtonA simple thing we can do to get rid of extra button clutter is get rid of that "Refresh" button that is eating up space and ugifying the top right corner of our toolbar. Luckily someone has already come up with a UX to deal with this problem, the "Pull to Refresh" interaction pioneered by Loren Brichter of Tweetie fame. I just needed to implement it into Sencha Touch.

Pull to Refresh

Pull to RefreshThe solution to this UX problem is quite simple, make a plugin that monitors scroll and adds the appropriate visual indicators, but I wanted to see how others implemented it first and follow that same pattern. This way whatever I developed would follow the exact same interaction as other established implementations and not confuse users.

What I found was the EGOTableViewPullRefresh , a JAVA implementation developed by enormego and used by Facebook for their Android mobile app, this provided me with the appropriate logic, styling and interaction to match the current widely accepted user interaction.

After careful examination (the code is actually quite small) I found that there are three stages to the "Pull to Refresh" concept:

  • Normal
  • Pulling
  • Loading

The "Normal" state is when the user is pulling down on the list, but has not yet reached the required distance pulling the list to cause a refresh if released.

The "Pulling" state is when the user has pulled down on the list past the required distance, and releasing it would cause a refresh. If the user were to pull the list back up past the required distance and release it would return to the Normal state and a refresh would not be triggered - this is the "escape" for users that do not want to refresh.

The "Loading" state is quite self explanatory, it's when the user has released the list from the "Pulling" state and a refresh has been triggered, but data has not yet been re-populated. Also, a last updated date is updated when this happens.

With all of this laid out now, I can write the code needed to make it happen, and create the styles to mimic what currently exists.

The plugin

The first thing I had to do was add the HTML element to the top of the scrolling list that would provide feedback to the user when they pulled the list. After that, monitoring the 'offsetchange' event of the scroller element of the list is where the logic of when to show the feedback HTML elements is handled.

this.cmp.scroller.on('offsetchange', this.handlePull, this);

The handlePull method is where the logic went for determining which of the three states we were in. Take a look at my code on Github for all the details - all said and done it's only 125 lines.

Pull to Refresh

I hope this code proves useful to you in your mobile development projects. This code is available to the public at my Github repository.

https://github.com/VinylFox/Ext.ux.touch.ListPullRefresh

Using the plugin is quite simple, just listen for the 'released' event on the plugin and reload your data.

{
    xtype: 'list',
    ...,
    plugins: [new Ext.ux.touch.ListPullRefresh({
      listeners: {
         'released': function(plugin,list){
           // call the plugins processComplete method to hide the 'loading' indicator
           your_store.on('load', plugin.processComplete, plugin, {single:true});
           // do whatever needs to happen for reload
           your_store.load();
         }
      }
    })],
    ...
}

DEMO (Must be viewed on phone):http://www.codetick.com/demos/refresh/index.html

Enjoy!

From JavaScriptTouch

16 Comments 
  1. Martin  permalink

    Hey Looks very promising but the link to the demo seems to be broken

  2. MCD  permalink

    demo is broken surely, for me..
    Broken Details: I am clicking the link claiming that it is the demo link.
    Although every page I want to open is open, this little link persistently is not opened.
    Well, for somebody it works, for others it doesn’t,I think there is a server issue..
    Thank you Shea…

  3. Sujay  permalink

    Hi Shea,

    Preety cool. The plugin did work however its breaking the itemtap listener which I have put on the list.

    Not sure if I am doing something wrong or if you have already noticed it.

    thanks

    • I have not experienced this problem, the itemtap event still works for me. Can you provide a sample and version.

  4. Oleg  permalink

    Is this plugin works only with List? I am trying to add this feature to the Component class.

  5. Dean Wild  permalink

    Hey, brilliant code, exactly what I was looking for.

    I do not like the built in List in sencha so I tend to use a panel and render my own HTML. I have successfully added this plugin to a panel and it works on the first drag but after that the refresh message element disappears permanently. Any ideas?

  6. Premier  permalink

    Hello,
    it works with my list, but it hides default list loading mask.

    How can i fix it? i want list loading mask!

  7. Jach  permalink

    Thank you. It works like a charm.
    I don’t use load() function like you in the release event but loadData() (of the store) and I can call one time only the pull refresh. Is that normal?

    • Jach  permalink

      I should view the plugin code before post.
      I solve my problem with a manual call of the processComplete() function of the plugin.

      Code:
      {
      xtype: ‘list’,
      …,
      plugins: [new Ext.ux.touch.ListPullRefresh({
      listeners: {
      'released': function(plugin,list){
      myRefreshListFunc();
      plugin.processComplete();
      }
      }
      })],

      }




内容概要:本文介绍了一种基于多目标粒子群算法(MOPSO)的微电网优化调度模型,综合考虑风能、光伏、储能系统、柴油发电机、燃气轮机以及与主电网之间的能量交互等多种分布式能源的协同运行。通过构建以运行成本最小化、碳排放最低化和系统可靠性最优化为目标的多目标优化模型,利用Matlab平台实现MOPSO算法求解,完成对微电网在不同运行场景下的能量管理与调度方案优化。该模型能够有效平衡经济性与环保性之间的关系,适用于含多类型分布式电源的复杂微电网系统,具有较强的工程应用价值和科研参考意义; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及工程技术人员,尤其适合从事微电网、智能电网、综合能源系统、可再生能源集成与优化调度等领域研究的专业人士; 使用场景及目标:①用于多能源耦合微电网系统的协同优化调度研究;②支持多目标智能优化算法在能源系统中的建模与求解实践,帮助用户掌握MOPSO在实际工程问题中的应用方法;③为学术论文复现、毕业设计、科研项目开发提供完整的代码实例与技术支撑; 阅读建议:建议读者结合Matlab代码与理论文档,深入理解目标函数构建、约束条件处理及Pareto最优解集生成机制,重点关注算法参数设置、多目标权衡分析与结果可视化,并可通过调整能源配置或引入新约束进行二次开发与创新研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值