enterprise_loading_screen_view_controller.mm 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #import "ios/chrome/app/enterprise_loading_screen_view_controller.h"
  5. #import "ios/chrome/browser/ui/first_run/first_run_constants.h"
  6. #import "ios/chrome/common/ui/colors/semantic_color_names.h"
  7. #import "ios/chrome/common/ui/util/constraints_ui_util.h"
  8. #include "ios/chrome/common/ui/util/dynamic_type_util.h"
  9. #include "ios/chrome/grit/ios_chromium_strings.h"
  10. #if !defined(__has_feature) || !__has_feature(objc_arc)
  11. #error "This file requires ARC support."
  12. #endif
  13. namespace {
  14. // All the following values are from "ios/chrome/app/resources/LaunchScreen.xib"
  15. // and should be in sync so that the transition between app launch screen and
  16. // the enterprise launch screen is invisible for the users.
  17. constexpr CGFloat kBottomMargin = 20;
  18. constexpr CGFloat kLogoMultiplier = 0.381966;
  19. constexpr CGFloat kBrandWidth = 107;
  20. constexpr CGFloat kStatusWidth = 195;
  21. constexpr CGFloat kSpacingHeight = 10;
  22. constexpr CGFloat kPaddingHeight = 50;
  23. } // namespace
  24. @interface EnterpriseLoadScreenViewController ()
  25. // Text displayed during the loading.
  26. @property(nonatomic, strong) UILabel* loadingLabel;
  27. @end
  28. @implementation EnterpriseLoadScreenViewController
  29. #pragma mark - UIViewController
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. self.view.accessibilityIdentifier =
  33. first_run::kEnterpriseLoadingScreenAccessibilityIdentifier;
  34. self.view.backgroundColor = [UIColor colorNamed:kBackgroundColor];
  35. UIImageView* logo = [self createLogoView];
  36. UIImageView* brand = [self createBrandView];
  37. UIStackView* status = [self createStatusView];
  38. UIStackView* mainStackView =
  39. [[UIStackView alloc] initWithArrangedSubviews:@[ logo, status, brand ]];
  40. mainStackView.axis = UILayoutConstraintAxisVertical;
  41. mainStackView.translatesAutoresizingMaskIntoConstraints = NO;
  42. mainStackView.distribution = UIStackViewDistributionEqualSpacing;
  43. mainStackView.alignment = UIStackViewAlignmentCenter;
  44. [self.view addSubview:mainStackView];
  45. [NSLayoutConstraint activateConstraints:@[
  46. [logo.widthAnchor constraintEqualToAnchor:self.view.widthAnchor
  47. multiplier:kLogoMultiplier],
  48. [logo.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor],
  49. [brand.bottomAnchor
  50. constraintEqualToAnchor:self.view.layoutMarginsGuide.bottomAnchor
  51. constant:-kBottomMargin],
  52. [brand.widthAnchor constraintEqualToConstant:kBrandWidth],
  53. [status.widthAnchor constraintEqualToConstant:kStatusWidth],
  54. [mainStackView.widthAnchor constraintEqualToAnchor:self.view.widthAnchor],
  55. [mainStackView.centerXAnchor
  56. constraintEqualToAnchor:self.view.centerXAnchor],
  57. ]];
  58. }
  59. - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
  60. [super traitCollectionDidChange:previousTraitCollection];
  61. // Limit the size of text to avoid truncation.
  62. self.loadingLabel.font = PreferredFontForTextStyleWithMaxCategory(
  63. UIFontTextStyleBody, self.traitCollection.preferredContentSizeCategory,
  64. UIContentSizeCategoryExtraExtraExtraLarge);
  65. }
  66. #pragma mark - Private
  67. // Creates and configures the logo image.
  68. - (UIImageView*)createLogoView {
  69. UIImage* logo = [UIImage imageNamed:@"launchscreen_app_logo"];
  70. UIImageView* logoImageView = [[UIImageView alloc] initWithImage:logo];
  71. logoImageView.contentMode = UIViewContentModeScaleAspectFit;
  72. logoImageView.translatesAutoresizingMaskIntoConstraints = NO;
  73. return logoImageView;
  74. }
  75. // Creates and configures the brand name image.
  76. - (UIImageView*)createBrandView {
  77. UIImage* brandNameLogo = [UIImage imageNamed:@"launchscreen_brand_name"];
  78. UIImageView* brandImageView =
  79. [[UIImageView alloc] initWithImage:brandNameLogo];
  80. brandImageView.contentMode = UIViewContentModeScaleAspectFit;
  81. brandImageView.translatesAutoresizingMaskIntoConstraints = NO;
  82. return brandImageView;
  83. }
  84. // Creates and configures the status view which contains the loading spinner and
  85. // loading text.
  86. - (UIStackView*)createStatusView {
  87. self.loadingLabel = [[UILabel alloc] init];
  88. // Chrome's localization utilities aren't available at this stage, so this
  89. // method uses the native iOS API.
  90. self.loadingLabel.text =
  91. NSLocalizedString(@"IDS_IOS_FIRST_RUN_LAUNCH_SCREEN_ENTERPRISE", @"");
  92. // Limit the size of text to avoid truncation.
  93. self.loadingLabel.font = PreferredFontForTextStyleWithMaxCategory(
  94. UIFontTextStyleBody, self.traitCollection.preferredContentSizeCategory,
  95. UIContentSizeCategoryExtraExtraExtraLarge);
  96. self.loadingLabel.numberOfLines = 0;
  97. self.loadingLabel.textColor = [UIColor colorNamed:kTextSecondaryColor];
  98. self.loadingLabel.textAlignment = NSTextAlignmentCenter;
  99. UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] init];
  100. [spinner startAnimating];
  101. UIView* spacing = [[UIView alloc] init];
  102. spacing.translatesAutoresizingMaskIntoConstraints = NO;
  103. UIView* bottomPadding = [[UIView alloc] init];
  104. bottomPadding.translatesAutoresizingMaskIntoConstraints = NO;
  105. UIStackView* statusStackView =
  106. [[UIStackView alloc] initWithArrangedSubviews:@[
  107. spinner, spacing, self.loadingLabel, bottomPadding
  108. ]];
  109. statusStackView.axis = UILayoutConstraintAxisVertical;
  110. statusStackView.translatesAutoresizingMaskIntoConstraints = NO;
  111. statusStackView.alignment = UIStackViewAlignmentCenter;
  112. statusStackView.spacing = UIStackViewSpacingUseSystem;
  113. [NSLayoutConstraint activateConstraints:@[
  114. [spacing.heightAnchor constraintEqualToConstant:kSpacingHeight],
  115. [bottomPadding.heightAnchor constraintEqualToConstant:kPaddingHeight]
  116. ]];
  117. return statusStackView;
  118. }
  119. @end