Skip to content

Commit

Permalink
added refreshControlEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
k0sukey committed Sep 6, 2013
1 parent 4d83c6c commit d22dbde
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 14 deletions.
16 changes: 8 additions & 8 deletions Classes/BeK0sukeTiisrefreshcontrolModuleAssets.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ - (NSData*) moduleAsset
//##TI_AUTOGEN_BEGIN asset

static UInt8 data[] = {
0xa2,0x60,0xc8,0x93,0x36,0x09,0x81,0x90,0xc8,0xb5,0x87,0x29,0xd8,0xf2,0x25,0xd9,0xb1,0x35,0xf2,0x41
,0xd4,0x78,0x70,0x8a,0xb8,0x2c,0x65,0xb6,0x9d,0xd0,0x78,0xef,0xd5,0x22,0x93,0x5f,0x10,0x5f,0xf5,0x78
,0x44,0x27,0x7c,0x8b,0xce,0x48,0x21,0xe6,0xf7,0x69,0xd4,0x65,0xc8,0xf0,0x67,0x9e,0xcc,0x05,0xcc,0x0e
,0x25,0x7d,0x5c,0x60,0xa6,0x36,0x60,0xed,0x36,0x8e,0xd8,0x2e,0x19,0x9e,0x69,0xca,0x75,0xa2,0x76,0x5b };
0x31,0x2a,0x5b,0xa8,0x82,0x05,0xfa,0x01,0x47,0xdd,0x36,0x15,0xcb,0x5e,0x47,0x85,0x73,0x91,0x39,0x76
,0xcb,0x1b,0x8a,0x32,0x00,0x65,0xce,0x0c,0x1d,0xcf,0xe4,0x84,0x11,0xc8,0x9a,0x6c,0x2f,0x57,0xf7,0xf0
,0x1c,0x8b,0xd6,0xdf,0x1c,0x1c,0x80,0x3a,0x43,0x18,0x75,0x0a,0xc7,0xa0,0x7a,0xf8,0x1a,0x51,0x44,0x34
,0xa0,0x06,0x92,0x6b,0x70,0x48,0x89,0x5f,0xb1,0x37,0x03,0x82,0x90,0x8f,0x78,0x79,0x67,0xb2,0x34,0x3b };
static NSRange ranges[] = {
{0,48}
};
Expand All @@ -36,10 +36,10 @@ - (NSData*) resolveModuleAsset:(NSString*)path
//##TI_AUTOGEN_BEGIN resolve_asset

static UInt8 data[] = {
0x41,0xc7,0xde,0xe2,0x42,0x08,0xfd,0xd1,0xd2,0x75,0x4d,0x94,0xea,0xd6,0xe8,0x9e,0xd8,0x47,0xca,0xdb
,0x88,0x53,0xfe,0xa4,0xa8,0x2d,0xda,0xca,0x11,0xdd,0x5d,0xa8,0xbc,0x95,0x6d,0xab,0xa3,0xa2,0x42,0x95
,0x59,0x18,0x05,0x41,0xf9,0x37,0x8c,0xc3,0x78,0x59,0x48,0x03,0x8f,0x7c,0x36,0xee,0x97,0xdc,0x61,0x1e
,0x55,0xe3,0x21,0x46,0xde,0x0a,0x34,0xfe,0x7a,0x05,0x59,0x39,0x6f,0x91,0x4a,0xf4,0x61,0x84,0xc1,0x17 };
0xab,0xc2,0x9a,0xc4,0x28,0x16,0xd1,0xad,0xdc,0xbe,0x8c,0xcd,0x46,0x1a,0x74,0xe0,0xc7,0x1d,0x14,0x02
,0x90,0x10,0x35,0xa1,0x27,0x59,0x8d,0x9a,0x81,0x36,0x9e,0x51,0xc1,0xde,0x04,0xc9,0x10,0xe6,0x1d,0xb2
,0x02,0x89,0x46,0x41,0x31,0x4a,0x4f,0xc1,0x12,0xa8,0x5a,0x69,0x2d,0x51,0x68,0x59,0xa9,0x68,0x06,0xf0
,0x87,0x46,0xf1,0x5f,0x74,0x23,0xcd,0x81,0x63,0xe2,0x3b,0x79,0xa8,0x20,0x67,0xad,0x04,0xe0,0x18,0xe1 };
static NSRange ranges[] = {
{0,48}
};
Expand Down
1 change: 1 addition & 0 deletions Classes/TiUIListView+ISRefreshControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@interface TiUIListView (TiUIListView_ISRefreshControl)

-(void)setRefreshControlTintColor_:(id)args;
-(void)setRefreshControlEnabled_:(id)args;

-(void)refreshBegin:(id)args;
-(void)refreshFinish:(id)args;
Expand Down
36 changes: 35 additions & 1 deletion Classes/TiUIListView+ISRefreshControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ -(void)initializeState
if (self)
{
refreshControl = (id)[[ISRefreshControl alloc] init];
[[self tableView] addSubview:refreshControl];
[refreshControl addTarget:self
action:@selector(refreshStart)
forControlEvents:UIControlEventValueChanged];
Expand All @@ -39,8 +38,33 @@ -(void)setRefreshControlTintColor_:(id)args
}
}

-(void)setRefreshControlEnabled_:(id)args
{
BOOL val = [TiUtils boolValue:args def:YES];

if (val == YES)
{
if ([refreshControl isDescendantOfView:[self tableView]] == NO)
{
[[self tableView] addSubview:refreshControl];
}
}
else
{
if ([refreshControl isDescendantOfView:[self tableView]] == YES)
{
[refreshControl removeFromSuperview];
}
}
}

-(void)refreshStart
{
if ([refreshControl isDescendantOfView:[self tableView]] == NO)
{
return;
}

[refreshControl beginRefreshing];

if ([self.proxy _hasListeners:@"refreshstart"])
Expand All @@ -51,6 +75,11 @@ -(void)refreshStart

-(void)refreshBegin:(id)args
{
if ([refreshControl isDescendantOfView:[self tableView]] == NO)
{
return;
}

if (refreshControl.isRefreshing == NO)
{
[self refreshStart];
Expand All @@ -59,6 +88,11 @@ -(void)refreshBegin:(id)args

-(void)refreshFinish:(id)args
{
if ([refreshControl isDescendantOfView:[self tableView]] == NO)
{
return;
}

if (refreshControl.isRefreshing == YES)
{
[refreshControl endRefreshing];
Expand Down
1 change: 1 addition & 0 deletions Classes/TiUITableView+ISRefreshControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@interface TiUITableView (TiUITableView_ISRefreshControl)

-(void)setRefreshControlTintColor_:(id)args;
-(void)setRefreshControlEnabled_:(id)args;

-(void)refreshBegin:(id)args;
-(void)refreshFinish:(id)args;
Expand Down
36 changes: 35 additions & 1 deletion Classes/TiUITableView+ISRefreshControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ -(void)initializeState
if (self)
{
refreshControl = (id)[[ISRefreshControl alloc] init];
[[self tableView] addSubview:refreshControl];
[refreshControl addTarget:self
action:@selector(refreshStart)
forControlEvents:UIControlEventValueChanged];
Expand All @@ -39,8 +38,33 @@ -(void)setRefreshControlTintColor_:(id)args
}
}

-(void)setRefreshControlEnabled_:(id)args
{
BOOL val = [TiUtils boolValue:args def:YES];

if (val == YES)
{
if ([refreshControl isDescendantOfView:[self tableView]] == NO)
{
[[self tableView] addSubview:refreshControl];
}
}
else
{
if ([refreshControl isDescendantOfView:[self tableView]] == YES)
{
[refreshControl removeFromSuperview];
}
}
}

-(void)refreshStart
{
if ([refreshControl isDescendantOfView:[self tableView]] == NO)
{
return;
}

[refreshControl beginRefreshing];

if ([self.proxy _hasListeners:@"refreshstart"])
Expand All @@ -51,6 +75,11 @@ -(void)refreshStart

-(void)refreshBegin:(id)args
{
if ([refreshControl isDescendantOfView:[self tableView]] == NO)
{
return;
}

if (refreshControl.isRefreshing == NO)
{
[self refreshStart];
Expand All @@ -59,6 +88,11 @@ -(void)refreshBegin:(id)args

-(void)refreshFinish:(id)args
{
if ([refreshControl isDescendantOfView:[self tableView]] == NO)
{
return;
}

if (refreshControl.isRefreshing == YES)
{
[refreshControl endRefreshing];
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This is a very simply :D
### Classic style(for Ti.UI.TableView)
```
var tableView = Ti.UI.createTableView({
refreshControlEnabled: true, // optional
refreshControlTintColor: '#f00', // optional
data: [
{ title: 'row0' },
Expand Down Expand Up @@ -112,10 +113,16 @@ var lists = Alloy.Collections.lists = Alloy.createCollection('lists');
```

### Properties
#### refreshControlEnabled
TiISRefreshControl enable or disable.

#### refreshControlTintColor
The tint color for the refresh control.

### Methods
#### getRefreshControlEnabled / setRefreshControlEnabled
getter / setter for refreshControlEnabled.

#### getRefreshControlTintColor / setRefreshControlTintColor
getter / setter for refreshControlTintColor.

Expand Down
Binary file not shown.
Binary file modified be.k0suke.tiisrefreshcontrol-iphone-0.1.zip
Binary file not shown.
33 changes: 29 additions & 4 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ var TiISRefreshControl = require('be.k0suke.tiisrefreshcontrol');
Ti.API.info("module is => " + TiISRefreshControl);

var win = Ti.UI.createWindow();

/*
var tableView = Ti.UI.createTableView({
refreshControlEnabled: false,
data: [
{ title: 'row0' },
{ title: 'row1' },
Expand All @@ -20,15 +20,27 @@ var tableView = Ti.UI.createTableView({
});
win.add(tableView);
var enabled = false;
tableView.addEventListener('click', function(){
if (enabled) {
tableView.setRefreshControlEnabled(false);
enabled = false;
} else {
tableView.setRefreshControlEnabled(true);
enabled = true;
}
});
tableView.addEventListener('refreshstart', function(){
setTimeout(function(){
tableView.refreshFinish();
win.remove(tableView);
}, 5000);
});
*/

var listView = Ti.UI.createListView();
var listView = Ti.UI.createListView({
refreshControlEnabled: false
});
var sections = [];

var fruitSection = Ti.UI.createListSection({ headerTitle: 'Fruits'});
Expand Down Expand Up @@ -58,6 +70,17 @@ var fishDataSet = [
fishSection.setItems(fishDataSet);
listView.appendSection(fishSection);

var enabled = false;
listView.addEventListener('itemclick', function(){
if (enabled) {
listView.setRefreshControlEnabled(false);
enabled = false;
} else {
listView.setRefreshControlEnabled(true);
enabled = true;
}
});

listView.addEventListener('refreshstart', function(){
console.log('isRefreshing: ' + listView.isRefreshing());
setTimeout(function(){
Expand All @@ -70,4 +93,6 @@ listView.addEventListener('refreshstart', function(){
});
console.log('isRefreshing: ' + listView.isRefreshing());

win.open();
listView.refreshBegin();

win.open();

0 comments on commit d22dbde

Please sign in to comment.