blob: fcd2ef8e87d52079a8264dee193df8c31748d387 [file] [log] [blame]
// Copyright 2016 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/settings/cells/version_item.h"
#import "ios/chrome/browser/experimental_flags.h"
#include "ios/chrome/browser/ui/collection_view/cells/collection_view_cell_constants.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation VersionItem
@synthesize text = _text;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
if (self) {
self.accessibilityIdentifier = @"Version cell";
self.cellClass = [VersionCell class];
}
return self;
}
#pragma mark CollectionViewItem
- (void)configureCell:(VersionCell*)cell {
[super configureCell:cell];
cell.textLabel.text = self.text;
}
@end
@implementation VersionCell
@synthesize textLabel = _textLabel;
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.isAccessibilityElement = YES;
self.accessibilityTraits |= UIAccessibilityTraitButton;
self.accessibilityHint = l10n_util::GetNSString(IDS_IOS_COPY_VERSION_HINT);
_textLabel = [[UILabel alloc] init];
_textLabel.translatesAutoresizingMaskIntoConstraints = NO;
_textLabel.backgroundColor = [UIColor clearColor];
_textLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:_textLabel];
// Fonts and colors vary when the UI reboot experiment is enabled.
if (experimental_flags::IsSettingsUIRebootEnabled()) {
_textLabel.font = [UIFont systemFontOfSize:kUIKitFooterFontSize];
_textLabel.textColor = UIColorFromRGB(kUIKitFooterTextColor);
} else {
_textLabel.shadowOffset = CGSizeMake(1, 0);
_textLabel.shadowColor = [UIColor whiteColor];
_textLabel.font = [[MDCTypography fontLoader] mediumFontOfSize:14];
_textLabel.textColor = [[MDCPalette greyPalette] tint900];
}
// Set up the constraints.
[NSLayoutConstraint activateConstraints:@[
[_textLabel.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
[_textLabel.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
]];
self.shouldHideSeparator = YES;
}
return self;
}
- (NSString*)accessibilityLabel {
return self.textLabel.text;
}
@end