|
| 1 | +// Copyright 2020-present the Material Components for iOS authors. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#import "MaterialChips.h" |
| 16 | +#import "MaterialContainerScheme.h" |
| 17 | + |
| 18 | +/* |
| 19 | + An example to demonstrate the bug described in b/133136148 |
| 20 | + To reproduce, repeatedly tap on the chip in this example. |
| 21 | +
|
| 22 | + Expected: The chip returns to its starting state once re-enabled |
| 23 | + Actual: The chip continues to get darker and darker as it is tapped |
| 24 | + */ |
| 25 | +@interface ChipsDisablingExampleViewController : UIViewController |
| 26 | +@property(nonatomic, strong) MDCChipView *chipView; |
| 27 | +@property(nonatomic, strong) id<MDCContainerScheming> containerScheme; |
| 28 | +@end |
| 29 | + |
| 30 | +@implementation ChipsDisablingExampleViewController |
| 31 | + |
| 32 | +- (id)init { |
| 33 | + self = [super init]; |
| 34 | + if (self) { |
| 35 | + _containerScheme = [[MDCContainerScheme alloc] init]; |
| 36 | + } |
| 37 | + return self; |
| 38 | +} |
| 39 | + |
| 40 | +- (void)viewDidLoad { |
| 41 | + [super viewDidLoad]; |
| 42 | + |
| 43 | + self.view.backgroundColor = self.containerScheme.colorScheme.backgroundColor; |
| 44 | + |
| 45 | + self.chipView = [[MDCChipView alloc] init]; |
| 46 | + self.chipView.titleLabel.text = @"I'm a chip"; |
| 47 | + self.chipView.frame = CGRectMake(20, 100, 200, 50); |
| 48 | + [self.chipView addTarget:self |
| 49 | + action:@selector(onChipTapped:) |
| 50 | + forControlEvents:UIControlEventTouchUpInside]; |
| 51 | + |
| 52 | + [self.view addSubview:self.chipView]; |
| 53 | +} |
| 54 | + |
| 55 | +- (void)onChipTapped:(MDCChipView *)chipView { |
| 56 | + chipView.enabled = NO; |
| 57 | + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), |
| 58 | + dispatch_get_main_queue(), ^{ |
| 59 | + chipView.enabled = YES; |
| 60 | + }); |
| 61 | +} |
| 62 | + |
| 63 | +@end |
| 64 | + |
| 65 | +@implementation ChipsDisablingExampleViewController (CatalogByConvention) |
| 66 | + |
| 67 | ++ (NSDictionary *)catalogMetadata { |
| 68 | + return @{ |
| 69 | + @"breadcrumbs" : @[ @"Chips", @"Disabling" ], |
| 70 | + @"primaryDemo" : @NO, |
| 71 | + @"presentable" : @NO, |
| 72 | + }; |
| 73 | +} |
| 74 | + |
| 75 | +@end |
0 commit comments