├── .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 |
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 | [](http://gitt.io/component/nl.fokkezb.pullToRefresh) [](https://www.npmjs.com/package/nl.fokkezb.pulltorefresh) [](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 |  17 | 18 | ### iOS 19 | 20 |  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: [](http://gitt.io/component/nl.fokkezb.pullToRefresh) 27 | 28 | `gittio install nl.fokkezb.pullToRefresh` 29 | 30 | Or NPM: [](https://www.npmjs.com/package/nl.fokkezb.pulltorefresh) 31 | 32 | `npm i --save nl.fokkezb.pulltorefresh` 33 | 34 | 3. Wrap the widget around your `
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 | --------------------------------------------------------------------------------