Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Toast/Example/CSViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@interface CSViewController ()

@property (assign, nonatomic, getter=isShowingActivity) BOOL showingActivity;
@property (assign, nonatomic, getter=isShowingActivityWithCustomStyle) BOOL showingActivityWithCustomStyle;

@end

Expand All @@ -44,6 +45,7 @@ - (instancetype)initWithStyle:(UITableViewStyle)style {
if (self) {
self.title = @"Toast";
self.showingActivity = NO;
self.showingActivityWithCustomStyle = NO;
}
return self;
}
Expand Down Expand Up @@ -81,7 +83,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
if (section == 0) {
return 2;
} else {
return 9;
return 10;
}
}

Expand Down Expand Up @@ -156,6 +158,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.textLabel.text = @"Show an image as toast at point\n(110, 110)";
} else if (indexPath.row == 8) {
cell.textLabel.text = (self.isShowingActivity) ? @"Hide toast activity" : @"Show toast activity";
} else if (indexPath.row == 9) {
cell.textLabel.text = (self.isShowingActivityWithCustomStyle) ? @"Hide toast activity with a custom style" : @"Show toast activity with a custom style";
}

return cell;
Expand Down Expand Up @@ -267,6 +271,18 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}
_showingActivity = !self.isShowingActivity;

[tableView reloadData];
} else if (indexPath.row == 9) {
// Make toast activity
if (!self.isShowingActivityWithCustomStyle) {
CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle];
style.backgroundColor = nil;
[self.navigationController.view makeToastActivity:CSToastPositionCenter style:style indicatorStyle:UIActivityIndicatorViewStyleGray];
} else {
[self.navigationController.view hideToastActivity];
}
_showingActivityWithCustomStyle = !self.isShowingActivityWithCustomStyle;

[tableView reloadData];
}
}
Expand Down
33 changes: 33 additions & 0 deletions Toast/Toast/UIView+Toast.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,39 @@ extern const NSString * CSToastPositionBottom;
*/
- (void)makeToastActivity:(id)position;

/**
Creates and displays a new toast activity indicator view at a specified position.

@warning Only one toast activity indicator view can be presented per superview. Subsequent
calls to `makeToastActivity:` will be ignored until hideToastActivity is called.

@warning `makeToastActivity:` works independently of the showToast: methods. Toast activity
views can be presented and dismissed while toast views are being displayed. `makeToastActivity:`
has no effect on the queueing behavior of the showToast: methods.

@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
@param style The style. The shared style will be used when nil
*/
- (void)makeToastActivity:(id)position style: (CSToastStyle *)style;

/**
Creates and displays a new toast activity indicator view at a specified position.

@warning Only one toast activity indicator view can be presented per superview. Subsequent
calls to `makeToastActivity:` will be ignored until hideToastActivity is called.

@warning `makeToastActivity:` works independently of the showToast: methods. Toast activity
views can be presented and dismissed while toast views are being displayed. `makeToastActivity:`
has no effect on the queueing behavior of the showToast: methods.

@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
@param style The style. The shared style will be used when nil
@param indicatorStyle The UIActivatyIndicatorViewStyle.
*/
- (void)makeToastActivity:(id)position style:(CSToastStyle *)style indicatorStyle:(UIActivityIndicatorViewStyle)indicatorStyle;

/**
Dismisses the active toast activity indicator view.
*/
Expand Down
16 changes: 14 additions & 2 deletions Toast/Toast/UIView+Toast.m
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,21 @@ - (void)cs_handleToastTapped:(UITapGestureRecognizer *)recognizer {
#pragma mark - Activity Methods

- (void)makeToastActivity:(id)position {
[self makeToastActivity:position style:nil];
}

- (void)makeToastActivity:(id)position style:(CSToastStyle *)style {
[self makeToastActivity:position style:style indicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
}

- (void)makeToastActivity:(id)position style:(CSToastStyle *)style indicatorStyle:(UIActivityIndicatorViewStyle)indicatorStyle {
// sanity
UIView *existingActivityView = (UIView *)objc_getAssociatedObject(self, &CSToastActivityViewKey);
if (existingActivityView != nil) return;

CSToastStyle *style = [CSToastManager sharedStyle];
if (style == nil) {
style = [CSToastManager sharedStyle];
}

UIView *activityView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, style.activitySize.width, style.activitySize.height)];
activityView.center = [self cs_centerPointForPosition:position withToast:activityView];
Expand All @@ -374,7 +384,7 @@ - (void)makeToastActivity:(id)position {
activityView.layer.shadowOffset = style.shadowOffset;
}

UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:indicatorStyle];
activityIndicatorView.center = CGPointMake(activityView.bounds.size.width / 2, activityView.bounds.size.height / 2);
[activityView addSubview:activityIndicatorView];
[activityIndicatorView startAnimating];
Expand All @@ -392,6 +402,8 @@ - (void)makeToastActivity:(id)position {
} completion:nil];
}



- (void)hideToastActivity {
UIView *existingActivityView = (UIView *)objc_getAssociatedObject(self, &CSToastActivityViewKey);
if (existingActivityView != nil) {
Expand Down