├── .gitignore ├── nl.fokkezb.pullToRefresh ├── views │ └── widget.xml ├── widget.json ├── README.md ├── package.json └── controllers │ └── widget.js ├── ios.gif ├── android.gif └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /nl.fokkezb.pullToRefresh/views/widget.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ios.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topener/nl.fokkezb.pullToRefresh/HEAD/ios.gif -------------------------------------------------------------------------------- /android.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Topener/nl.fokkezb.pullToRefresh/HEAD/android.gif -------------------------------------------------------------------------------- /nl.fokkezb.pullToRefresh/widget.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nl.fokkezb.pullToRefresh", 3 | "name": "Pull to Refresh Widget", 4 | "description" : "Uniform wrapper for iOS RefreshControl and Android SwipeRefreshLayout.", 5 | "author": "Fokke Zandbergen", 6 | "version": "3.0.0", 7 | "copyright":"Copyright (c) 2013-2015", 8 | "license":"Apache 2.0", 9 | "min-alloy-version": "1.5", 10 | "min-titanium-version":"3.4", 11 | "tags":"tableview,headerpullview,pulltorefresh,swiperefreshlayout,listview,pullview,refreshcontrol,ticollectionview", 12 | "platforms":"ios,android", 13 | "modules": { 14 | "com.rkam.swiperefreshlayout": "*" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /nl.fokkezb.pullToRefresh/README.md: -------------------------------------------------------------------------------- 1 | # Alloy *Pull to Refresh* Widget 2 | 3 | You can find the README at [https://github.com/fokkezb/nl.fokkezb.drawer](https://github.com/fokkezb/nl.fokkezb.pullToRefresh) 4 | 5 | ## License 6 | 7 |
 8 | Copyright 2013-2014 Fokke Zandbergen
 9 | 
10 | Licensed under the Apache License, Version 2.0 (the "License");
11 | you may not use this file except in compliance with the License.
12 | You may obtain a copy of the License at
13 | 
14 |    http://www.apache.org/licenses/LICENSE-2.0
15 | 
16 | Unless required by applicable law or agreed to in writing, software
17 | distributed under the License is distributed on an "AS IS" BASIS,
18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 | See the License for the specific language governing permissions and
20 | limitations under the License.
21 | 
-------------------------------------------------------------------------------- /nl.fokkezb.pullToRefresh/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "3.0.0", 3 | "appc-npm": { 4 | "target": { 5 | "alloy": "app/widgets/nl.fokkezb.pulltorefresh" 6 | }, 7 | "ignore": [ 8 | "package.json" 9 | ], 10 | "config": { 11 | "nl.fokkezb.pullToRefresh": "2.2.3" 12 | } 13 | }, 14 | "author": "Fokke Zandbergen", 15 | "license": "Apache 2.0", 16 | "name": "nl.fokkezb.pulltorefresh", 17 | "keywords": [ 18 | "alloy", 19 | "alloy-widget", 20 | "appc-npm", 21 | "appcelerator", 22 | "headerpullview", 23 | "listview", 24 | "pulltorefresh", 25 | "pullview", 26 | "refreshcontrol", 27 | "swiperefreshlayout", 28 | "tableview", 29 | "ticollectionview" 30 | ], 31 | "scripts": { 32 | "postinstall": "node ./appc-npm" 33 | }, 34 | "repository": { 35 | "type": "git", 36 | "url": "git+https://github.com/fokkezb/nl.fokkezb.pullToRefresh.git" 37 | }, 38 | "bugs": { 39 | "url": "https://github.com/fokkezb/nl.fokkezb.pullToRefresh/issues" 40 | }, 41 | "homepage": "https://github.com/fokkezb/nl.fokkezb.pullToRefresh#readme", 42 | "description": "Uniform wrapper for iOS RefreshControl and Android SwipeRefreshLayout." 43 | } 44 | -------------------------------------------------------------------------------- /nl.fokkezb.pullToRefresh/controllers/widget.js: -------------------------------------------------------------------------------- 1 | var refreshControl; 2 | var list; 3 | 4 | $.refresh = refresh; 5 | 6 | $.show = show; 7 | $.hide = hide; 8 | $.getList = getList; 9 | $.getControl = getControl; 10 | 11 | (function constructor(args) { 12 | 13 | if (args.dontInit || (!OS_IOS && !OS_ANDROID)){ 14 | if (!args.dontInit) console.warn('[pullToRefresh] only supports iOS and Android.'); 15 | 16 | if (_.isArray(args.children)) { 17 | _.map(args.children, $.addTopLevelView); 18 | } 19 | 20 | return; 21 | } 22 | 23 | if (!_.isArray(args.children) || !_.contains(['Titanium.UI.ListView', 'Titanium.UI.TableView', 'Ti.UI.ListView', 'Ti.UI.TableView', 'de.marcelpociot.CollectionView'], args.children[args.children.length-1].apiName)) { 24 | console.error('[pullToRefresh] is missing required Ti.UI.ListView or Ti.UI.TableView or de.marcelpociot.CollectionView as first child element.'); 25 | return; 26 | } 27 | 28 | list = _.last(args.children); 29 | delete args.children; 30 | 31 | _.extend($, args); 32 | 33 | if (OS_IOS) { 34 | refreshControl = Ti.UI.createRefreshControl(args); 35 | refreshControl.addEventListener('refreshstart', onRefreshstart); 36 | 37 | list.refreshControl = refreshControl; 38 | 39 | $.addTopLevelView(list); 40 | 41 | } else if (OS_ANDROID) { 42 | refreshControl = require('com.rkam.swiperefreshlayout').createSwipeRefresh(_.extend({ 43 | view: list 44 | }, args)); 45 | 46 | refreshControl.addEventListener('refreshing', onRefreshstart); 47 | 48 | $.addTopLevelView(refreshControl); 49 | } 50 | 51 | })(arguments[0] || {}); 52 | 53 | function refresh() { 54 | 55 | if (!list) { 56 | return; 57 | } 58 | 59 | show(); 60 | 61 | onRefreshstart(); 62 | } 63 | 64 | function hide() { 65 | 66 | if (!refreshControl) { 67 | return; 68 | } 69 | 70 | if (OS_IOS) { 71 | refreshControl.endRefreshing(); 72 | 73 | } else if (OS_ANDROID) { 74 | refreshControl.setRefreshing(false); 75 | } 76 | } 77 | 78 | function show() { 79 | 80 | if (!refreshControl) { 81 | return; 82 | } 83 | 84 | if (OS_IOS) { 85 | refreshControl.beginRefreshing(); 86 | 87 | } else if (OS_ANDROID) { 88 | refreshControl.setRefreshing(true); 89 | } 90 | } 91 | 92 | function getList() { 93 | return list; 94 | } 95 | 96 | function getControl() { 97 | return refreshControl; 98 | } 99 | 100 | function onRefreshstart() { 101 | 102 | $.trigger('release', { 103 | source: $, 104 | hide: hide 105 | }); 106 | 107 | } 108 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Alloy *Pull to Refresh* Widget 2 | [![gitTio](http://gitt.io/badge.svg)](http://gitt.io/component/nl.fokkezb.pullToRefresh) [![NPM](https://img.shields.io/npm/v/nl.fokkezb.pulltorefresh.svg?style=flat-square)](https://www.npmjs.com/package/nl.fokkezb.pulltorefresh) [![René Pot](https://img.shields.io/badge/maintainer-René_Pot-yellow.svg?style=flat-square)](https://github.com/Topener) 3 | 4 | **NOTE: Starting TiSDK 6.2 this widget is no longer needed as RefreshControl is build in for Android like previously for iOS, you can stick with the Ti.UI.RefreshControl** 5 | 6 | The [Alloy](http://appcelerator.com/alloy) *Pull to Refresh* widget is a cross-platform no-brainer wrapper of [Ti.UI.RefreshControl](http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.RefreshControl) for iOS and Ivan's fork of [Ti.SwipeRefreshLayout](https://github.com/iskugor/Ti.SwipeRefreshLayout) for Android. 7 | 8 | Before version 2.0.0 this widget emulated the native Pull to Refresh concept for `Ti.UI.TableView` on both platforms. Since 2.0.0 it uses the native controls now available in Titanium Core and through Ivan's module for both `Ti.UI.TableView` and `Ti.UI.ListView`. 9 | 10 | Also take a look at the [Infinite Scroll](https://github.com/FokkeZB/nl.fokkezb.infiniteScroll) widget. 11 | 12 | ## Examples 13 | 14 | ### Android 15 | 16 | ![Android](android.gif) 17 | 18 | ### iOS 19 | 20 | ![iOS](ios.gif) 21 | 22 | ## Usage 23 | 24 | 1. Download and install the [distribution](https://github.com/iskugor/Ti.SwipeRefreshLayout/tree/master/dist) 0.4.1 or later of Ivan's fork of [Ti.SwipeRefreshLayout](http://gitt.io/component/com.rkam.swiperefreshlayout). 25 | 26 | 2. Install the widget via gitTio: [![gitTio](http://gitt.io/badge.svg)](http://gitt.io/component/nl.fokkezb.pullToRefresh) 27 | 28 | `gittio install nl.fokkezb.pullToRefresh` 29 | 30 | Or NPM: [![NPM](https://img.shields.io/npm/v/nl.fokkezb.pulltorefresh.svg?style=flat-square)](https://www.npmjs.com/package/nl.fokkezb.pulltorefresh) 31 | 32 | `npm i --save nl.fokkezb.pulltorefresh` 33 | 34 | 3. Wrap the widget around your `` or `` in the view: 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | **NOTE:** The `` tag can't be the root element due to an Alloy limitation! 50 | 51 | 4. Add your `myRefresher` function to the controller and call the `e.hide()` callback when you're done: 52 | 53 | function myRefresher(e) { 54 | myCollection.fetch({ 55 | success: e.hide, 56 | error: e.hide 57 | }); 58 | } 59 | 60 | 5. Call the widget's `refresh()` to programmatically trigger the (initial) refresh: 61 | 62 | $.ptr.refresh(); 63 | 64 | 6. To pass arguments to [`Ti.UI.createRefreshControl`](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI-method-createRefreshControl) and [`createSwipeRefresh()`](https://github.com/iskugor/Ti.SwipeRefreshLayout#to-initialize) simply pass them to the widget as attributes of `` or second arguments of `createWidget()`. 65 | 66 | ## Methods 67 | Both platforms share the same API: 68 | 69 | | Function | Parameters | Usage | 70 | | ---------- | ---------- | ----- | 71 | | refresh | | Manually trigger pull + release | 72 | | show | | Show the loading indicator | 73 | | hide | | Hide the loading indicator | 74 | | getList | | Get the list the widget is bound to 75 | | getControl | | Get the refresh control 76 | 77 | ## Changelog 78 | * 3.0 79 | * Removes `setTitle()`. 80 | * Passes all arguments/attributes on to `Ti.UI.createRefreshControl()` for iOS (e.g. to set title or tintColor) and `createSwipeRefresh()` for Android. 81 | * 2.2 82 | * [Expose method to set refreshControl title for iOS](https://github.com/FokkeZB/nl.fokkezb.pullToRefresh/pull/53/files). 83 | * [Exposes hide() and get() methods](https://github.com/FokkeZB/nl.fokkezb.pullToRefresh/pull/52). 84 | * Adds [getter for List](https://github.com/FokkeZB/nl.fokkezb.pullToRefresh/pull/51). 85 | * 2.1 86 | * Adds support for [TiCollectionView](https://github.com/mpociot/TiCollectionView) by [@adesugbaa](https://github.com/adesugbaa). 87 | * 2.0 88 | * Rewritten to use native API's. 89 | * 1.5 90 | * Workaround for regression in Alloy 1.3.0-cr 91 | * Closes #17 by checking source of events 92 | * New `top` option for compatibility with `Ti.UI.Window.extendEdges` on iOS7 93 | * Arrow now properly hidden on Android, using opacity 94 | * Default style updated to match Twitter on iOS7 95 | * 1.4 96 | * Now compatible with Android and other OS! 97 | * 1.3 98 | * From now on declared in the XML view instead of the controller! 99 | * Splitted `init` into `setOptions` and `attach` 100 | * Renamed `remove` to `dettach` 101 | * Renamed `trigger` to `refresh` to not interfere with BackBone 102 | * 1.2 103 | * Retina arrow images, including new (default) grey one 104 | * Removed text showing last update for more clear view 105 | * Easier styling 106 | * 1.1 107 | * Exposed new API functions to `show`/`hide` the view, set the `date` and `trigger` the widget manually. 108 | * Renamed `load` parameter to `loader` in line with upcomming widgets. 109 | * 1.0 110 | * Initial version 111 | 112 | ## License 113 | 114 |
115 | Copyright 2013-2015 Fokke Zandbergen
116 | 
117 | Licensed under the Apache License, Version 2.0 (the "License");
118 | you may not use this file except in compliance with the License.
119 | You may obtain a copy of the License at
120 | 
121 |    http://www.apache.org/licenses/LICENSE-2.0
122 | 
123 | Unless required by applicable law or agreed to in writing, software
124 | distributed under the License is distributed on an "AS IS" BASIS,
125 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126 | See the License for the specific language governing permissions and
127 | limitations under the License.
128 | 
129 | --------------------------------------------------------------------------------