| // Copyright 2018 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #import "ios/chrome/browser/ui/table_view/cells/table_view_activity_indicator_header_footer_item.h" |
| |
| #include "base/mac/foundation_util.h" |
| #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| #import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h" |
| #import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h" |
| #import "ios/third_party/material_components_ios/src/components/ActivityIndicator/src/MaterialActivityIndicator.h" |
| |
| #if !defined(__has_feature) || !__has_feature(objc_arc) |
| #error "This file requires ARC support." |
| #endif |
| |
| @implementation TableViewActivityIndicatorHeaderFooterItem |
| @synthesize subtitleText = _subtitleText; |
| @synthesize text = _text; |
| |
| - (instancetype)initWithType:(NSInteger)type { |
| self = [super initWithType:type]; |
| if (self) { |
| self.cellClass = [TableViewActivityIndicatorHeaderFooterView class]; |
| } |
| return self; |
| } |
| |
| - (void)configureHeaderFooterView:(UITableViewHeaderFooterView*)headerFooter |
| withStyler:(ChromeTableViewStyler*)styler { |
| [super configureHeaderFooterView:headerFooter withStyler:styler]; |
| TableViewActivityIndicatorHeaderFooterView* header = |
| base::mac::ObjCCastStrict<TableViewActivityIndicatorHeaderFooterView>( |
| headerFooter); |
| header.titleLabel.text = self.text; |
| header.subtitleLabel.text = self.subtitleText; |
| // Use colors from styler if available. |
| if (styler.tableViewBackgroundColor) |
| header.contentView.backgroundColor = styler.tableViewBackgroundColor; |
| if (styler.headerFooterTitleColor) |
| header.titleLabel.textColor = styler.headerFooterTitleColor; |
| } |
| |
| @end |
| |
| #pragma mark - TableViewActivityIndicatorHeaderFooterView |
| |
| @implementation TableViewActivityIndicatorHeaderFooterView |
| @synthesize subtitleLabel = _subtitleLabel; |
| @synthesize titleLabel = titleLabel; |
| |
| - (instancetype)initWithReuseIdentifier:(NSString*)reuseIdentifier { |
| self = [super initWithReuseIdentifier:reuseIdentifier]; |
| if (self) { |
| // Labels, set font sizes using dynamic type. |
| self.titleLabel = [[UILabel alloc] init]; |
| self.titleLabel.font = |
| [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; |
| self.subtitleLabel = [[UILabel alloc] init]; |
| self.subtitleLabel.font = |
| [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]; |
| self.subtitleLabel.textColor = [UIColor lightGrayColor]; |
| |
| // Vertical StackView. |
| UIStackView* verticalStack = [[UIStackView alloc] |
| initWithArrangedSubviews:@[ self.titleLabel, self.subtitleLabel ]]; |
| verticalStack.axis = UILayoutConstraintAxisVertical; |
| |
| // Activity Indicator. |
| MDCActivityIndicator* activityIndicator = |
| [[MDCActivityIndicator alloc] init]; |
| activityIndicator.cycleColors = @[ [[MDCPalette cr_bluePalette] tint500] ]; |
| [activityIndicator startAnimating]; |
| [activityIndicator |
| setContentHuggingPriority:UILayoutPriorityDefaultHigh |
| forAxis:UILayoutConstraintAxisHorizontal]; |
| |
| // Horizontal StackView. |
| UIStackView* horizontalStack = [[UIStackView alloc] |
| initWithArrangedSubviews:@[ verticalStack, activityIndicator ]]; |
| horizontalStack.axis = UILayoutConstraintAxisHorizontal; |
| horizontalStack.spacing = kTableViewSubViewHorizontalSpacing; |
| horizontalStack.translatesAutoresizingMaskIntoConstraints = NO; |
| horizontalStack.alignment = UIStackViewAlignmentCenter; |
| |
| // Add subviews to View Hierarchy. |
| [self.contentView addSubview:horizontalStack]; |
| |
| // Set and activate constraints. |
| [NSLayoutConstraint activateConstraints:@[ |
| [horizontalStack.leadingAnchor |
| constraintEqualToAnchor:self.contentView.leadingAnchor |
| constant:kTableViewHorizontalSpacing], |
| [horizontalStack.trailingAnchor |
| constraintEqualToAnchor:self.contentView.trailingAnchor |
| constant:-kTableViewHorizontalSpacing], |
| [horizontalStack.topAnchor |
| constraintGreaterThanOrEqualToAnchor:self.contentView.topAnchor |
| constant:kTableViewVerticalSpacing], |
| [horizontalStack.bottomAnchor |
| constraintLessThanOrEqualToAnchor:self.contentView.bottomAnchor |
| constant:-kTableViewVerticalSpacing], |
| [horizontalStack.centerYAnchor |
| constraintEqualToAnchor:self.contentView.centerYAnchor] |
| ]]; |
| } |
| return self; |
| } |
| |
| @end |