Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-16218] Fix Ti.UI.RefreshControl.beginRefreshing, refactor proxy and docs #8115

Merged
merged 6 commits into from
Jul 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 20 additions & 5 deletions apidoc/Titanium/UI/RefreshControl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Titanium.UI.RefreshControl
summary: The RefreshControl is a representation of the native [UIRefreshControl](https://developer.apple.com/library/ios/documentation/uikit/reference/UIRefreshControl_class/Reference/Reference.html).
description: |

You use a `RefreshControl` with a <Titanium.UI.TableView> or <Titanium.UI.ListView> object.
You use a `RefreshControl` with a <Titanium.UI.TableView>, <Titanium.UI.ListView> or <Titanium.UI.ScrollView> object.
It provides an alternate method to implement **pull to refresh** functionality provided by
<Titanium.UI.TableView.headerPullView> and <Titanium.UI.ListView.pullView> properties.

Expand All @@ -19,14 +19,18 @@ methods:
description: |
Call this method when an external event source triggers a programmatic refresh of your table.
This method updates the state of the refresh control to reflect the in-progress refresh operation.
When the refresh operation ends, be sure to call the [endRefreshing](Titanium.UI.RefreshControl.endRefreshing) method to return the control to its default state.
When the refresh operation ends, be sure to call the [endRefreshing](Titanium.UI.RefreshControl.endRefreshing)
method to return the control to its default state.
Note: When triggering the refreshing programmatically, the styling is not applied and the refresh control is tinted
in the native gray.
- name: endRefreshing
summary: Tells the control that a refresh operation has ended.
description: |
Call this method at the end of any refresh operation (whether it was initiated programmatically or by the user) to return the refresh control to its default state.
Call this method at the end of any refresh operation (whether it was initiated programmatically or by the user)
to return the refresh control to its default state.
properties:
- name: title
summary: The title of the control.
summary: The attributed title of the control.
type: Titanium.UI.AttributedString

- name: tintColor
Expand All @@ -37,7 +41,18 @@ properties:

events:
- name: refreshstart
summary: Fired in response to a user initiated action to refresh the contents of the table view or list view.
summary: |
Fired in response to a user initiated an action to refresh the contents of the
table view, list view or scroll view.
properties:
- name: bubbles
summary: This is false. This event does not bubble
type: Boolean
- name: refreshend
summary: |
Fired in response to a user finished action to refresh the contents of the
table view, list view or scroll view.
since: "6.0.0"
properties:
- name: bubbles
summary: This is false. This event does not bubble
Expand Down
2 changes: 0 additions & 2 deletions iphone/Classes/TiUIRefreshControlProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

@interface TiUIRefreshControlProxy : TiProxy {
UIRefreshControl* _refreshControl;
NSAttributedString* _attributedString;
UIColor* refreshTintColor;
}

#pragma mark - Internal Use Only
Expand Down
64 changes: 27 additions & 37 deletions iphone/Classes/TiUIRefreshControlProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ -(NSString*)apiName
-(void) dealloc
{
RELEASE_TO_NIL(_refreshControl);
RELEASE_TO_NIL(_attributedString);
RELEASE_TO_NIL(refreshTintColor);
[super dealloc];
}

Expand All @@ -32,75 +30,67 @@ -(UIRefreshControl*)control
{
//Must be called on main thread
if (_refreshControl == nil) {
_refreshControl = [[UIRefreshControl alloc] init];
[_refreshControl addTarget:self action:@selector(refreshStart) forControlEvents:UIControlEventValueChanged];
[self refreshControl];
_refreshControl = [UIRefreshControl new];
[_refreshControl addTarget:self action:@selector(refreshingDidStart) forControlEvents:UIControlEventValueChanged];
}

return _refreshControl;
}

-(void)refreshControl
-(void)refreshingDidStart
{
if (_refreshControl != nil) {
[_refreshControl setAttributedTitle:_attributedString];
[_refreshControl setTintColor:refreshTintColor];
if ([self _hasListeners:@"refreshstart"]) {
[self fireEvent:@"refreshstart" withObject:nil propagate:NO reportSuccess:NO errorCode:0 message:nil];
}
}

-(void)refreshStart
-(void)refreshingDidEnd
{
if ([self _hasListeners:@"refreshstart"]) {
[self fireEvent:@"refreshstart" withObject:nil propagate:NO reportSuccess:NO errorCode:0 message:nil];
if ([self _hasListeners:@"refreshend"]) {
[self fireEvent:@"refreshend" withObject:nil propagate:NO reportSuccess:NO errorCode:0 message:nil];
}
}

#pragma mark - Public APIs

#pragma mark - Public API

-(void)setTitle:(id)args
-(void)setTitle:(id)value
{

#ifdef USE_TI_UIATTRIBUTEDSTRING
ENSURE_SINGLE_ARG_OR_NIL(args, TiUIAttributedStringProxy);
[self replaceValue:args forKey:@"title" notification:NO];
RELEASE_TO_NIL(_attributedString);
if (args != nil) {
_attributedString = [[args attributedString] copy];
}
TiThreadPerformOnMainThread(^{
[self refreshControl];
}, NO);
#if defined (USE_TI_UIATTRIBUTEDSTRING) || defined (USE_TI_UIIOSATTRIBUTEDSTRING)
ENSURE_SINGLE_ARG_OR_NIL(value, TiUIAttributedStringProxy);
[self replaceValue:value forKey:@"title" notification:NO];

TiThreadPerformOnMainThread(^{
[[self control] setAttributedTitle:[(TiUIAttributedStringProxy*)value attributedString]];
}, NO);
#endif
}

-(void)setTintColor:(id)args
-(void)setTintColor:(id)value
{
ENSURE_SINGLE_ARG_OR_NIL(args, NSObject);
[self replaceValue:args forKey:@"tintColor" notification:NO];
RELEASE_TO_NIL(refreshTintColor);
refreshTintColor = [[[TiUtils colorValue:args] color] retain];
//Changing tintColor works on iOS6 but not on iOS7. iOS Bug?
ENSURE_SINGLE_ARG_OR_NIL(value, NSString);
[self replaceValue:value forKey:@"tintColor" notification:NO];

TiThreadPerformOnMainThread(^{
[self refreshControl];
[[self control] setTintColor:[[TiUtils colorValue:value] color]];
}, NO);
}

-(void)beginRefreshing:(id)unused
{
TiThreadPerformOnMainThread(^{
[_refreshControl beginRefreshing];
[(UIScrollView*)[[self control] superview] setContentOffset:CGPointMake(0, -([[self control] frame].size.height)) animated:YES];
[[self control] beginRefreshing];
[[self control] sendActionsForControlEvents:UIControlEventValueChanged];
}, NO);
}

-(void)endRefreshing:(id)unused
{
TiThreadPerformOnMainThread(^{
[_refreshControl endRefreshing];
[[self control] endRefreshing];
[self refreshingDidEnd];
}, NO);
}



@end
#endif