Skip to content

Commit

Permalink
[MDCProgressView] Fix indeterminate animation being removed before it…
Browse files Browse the repository at this point in the history
… is presented on screen.

PiperOrigin-RevId: 321083086
  • Loading branch information
attributeshift authored and material-automation committed Jul 14, 2020
1 parent 81b5c39 commit be54e35
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
102 changes: 102 additions & 0 deletions components/ProgressView/examples/ProgressViewInDialogExample.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright 2020-present the Material Components for iOS authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#import <UIKit/UIKit.h>

#import "MaterialButtons.h"
#import "MaterialButtons+Theming.h"
#import "MaterialDialogs.h"
#import "MaterialProgressView.h"
#import "MaterialProgressView+Theming.h"
#import "MaterialColorScheme.h"
#import "MaterialContainerScheme.h"

// static const CGFloat kMDCProgressViewIndeterminateAnimationDuration = 4;
static const CGFloat kMDCProgressViewHeight = 2;

@interface ProgressViewInDialogExample : UIViewController

@property(nonatomic, strong) MDCAlertController *alertViewController;
@property(nonatomic, strong) MDCProgressView *indeterminateProgressView;
@property(nonatomic, strong) MDCContainerScheme *containerScheme;
@property(nonatomic, strong) MDCButton *alertButton;
@end

@implementation ProgressViewInDialogExample

- (void)viewDidLoad {
[super viewDidLoad];

if (!self.containerScheme) {
self.containerScheme = [[MDCContainerScheme alloc] init];
}

self.title = @"Progress View (Dialogs)";
self.view.backgroundColor = self.containerScheme.colorScheme.backgroundColor;

[self setupButton];
[self setupDialog];
}

- (void)setupButton {
MDCButton *alertButton = [[MDCButton alloc] init];
[alertButton setTitle:@"Present Dialog" forState:UIControlStateNormal];
[alertButton applyTextThemeWithScheme:self.containerScheme];
[alertButton addTarget:self
action:@selector(didTapButton)
forControlEvents:UIControlEventTouchUpInside];
alertButton.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:alertButton];
[alertButton.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor].active = YES;
[alertButton.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor].active = YES;
self.alertButton = alertButton;
}

- (void)setupDialog {
MDCProgressView *indeterminateProgressView = [[MDCProgressView alloc] init];
indeterminateProgressView.mode = MDCProgressViewModeIndeterminate;
indeterminateProgressView.translatesAutoresizingMaskIntoConstraints = NO;
indeterminateProgressView.frame = CGRectMake(0, 0, 0, kMDCProgressViewHeight);
[indeterminateProgressView applyThemeWithScheme:self.containerScheme];
[indeterminateProgressView startAnimating];
self.indeterminateProgressView = indeterminateProgressView;

MDCAlertController *alertViewController = [[MDCAlertController alloc] init];
alertViewController.title = @"Dialog with Progress View";
MDCAlertAction *dismissAction = [MDCAlertAction
actionWithTitle:@"OK"
handler:^(MDCAlertAction *_Nonnull action) {
[self.alertViewController dismissViewControllerAnimated:YES completion:nil];
}];
[alertViewController addAction:dismissAction];
alertViewController.accessoryView = indeterminateProgressView;
self.alertViewController = alertViewController;
}

- (void)didTapButton {
[self presentViewController:self.alertViewController animated:YES completion:nil];
}

#pragma mark - CatalogByConvention

+ (NSDictionary *)catalogMetadata {
return @{
@"breadcrumbs" : @[ @"Progress View", @"Progress View In Dialog" ],
@"description" : @"Progress indicators presented in a dialog",
@"primaryDemo" : @NO,
@"presentable" : @YES,
};
}

@end
2 changes: 2 additions & 0 deletions components/ProgressView/src/MDCProgressView.m
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ - (void)startAnimatingBar {
CAAnimationGroup *progressViewAnimationGroup = [[CAAnimationGroup alloc] init];
progressViewAnimationGroup.animations = @[ progressViewHead, progressViewTail ];
progressViewAnimationGroup.duration = 1.8;
progressViewAnimationGroup.removedOnCompletion = NO;
progressViewAnimationGroup.repeatCount = HUGE_VALF;

[self.progressView.shapeLayer addAnimation:progressViewAnimationGroup
Expand Down Expand Up @@ -474,6 +475,7 @@ - (void)startAnimatingBar {
indeterminateProgressViewAnimationGroup.animations =
@[ indeterminateProgressViewHead, indeterminateProgressViewTail ];
indeterminateProgressViewAnimationGroup.duration = 1.8;
indeterminateProgressViewAnimationGroup.removedOnCompletion = NO;
indeterminateProgressViewAnimationGroup.repeatCount = HUGE_VALF;

[self.indeterminateProgressView.shapeLayer addAnimation:indeterminateProgressViewAnimationGroup
Expand Down

0 comments on commit be54e35

Please sign in to comment.