From daedd2b5be132c7d035f27d598908ac9c421270d Mon Sep 17 00:00:00 2001 From: Jeff Verkoeyen Date: Sat, 12 Nov 2022 13:41:01 -0800 Subject: [PATCH 1/2] [Welcome] Allow buttons to grow with Dynamic Type. The buttons now have a minimum height rather than a constant height. Also made a couple minor improvements / bug fixes: - Both buttons now react to Dynamic Type settings changes (enabled `adjustsFontForContentSizeCategory`). - A layout pass is now enforced in traitCollectionDidChange to ensure that setupButtonShadowView is using the right bounds. - signUpButtonShadowView now uses signUpButtonShadowView's bounds. --- .../Onboarding/Welcome/WelcomeViewController.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift b/Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift index a2b8df83a..225f2f9ef 100644 --- a/Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift +++ b/Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift @@ -51,6 +51,7 @@ final class WelcomeViewController: UIViewController, NeedsDependency { private(set) lazy var signUpButton: PrimaryActionButton = { let button = PrimaryActionButton() button.adjustsBackgroundImageWhenUserInterfaceStyleChanges = false + button.titleLabel?.adjustsFontForContentSizeCategory = true button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold)) button.setTitle(L10n.Common.Controls.Actions.signUp, for: .normal) let backgroundImageColor: UIColor = .white @@ -65,6 +66,7 @@ final class WelcomeViewController: UIViewController, NeedsDependency { private(set) lazy var signInButton: PrimaryActionButton = { let button = PrimaryActionButton() button.adjustsBackgroundImageWhenUserInterfaceStyleChanges = false + button.titleLabel?.adjustsFontForContentSizeCategory = true button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold)) button.setTitle(L10n.Scene.Welcome.logIn, for: .normal) let backgroundImageColor = Asset.Scene.Welcome.signInButtonBackground.color @@ -113,12 +115,12 @@ extension WelcomeViewController { signUpButton.translatesAutoresizingMaskIntoConstraints = false buttonContainer.addArrangedSubview(signUpButton) NSLayoutConstraint.activate([ - signUpButton.heightAnchor.constraint(equalToConstant: WelcomeViewController.actionButtonHeight).priority(.required - 1), + signUpButton.heightAnchor.constraint(greaterThanOrEqualToConstant: WelcomeViewController.actionButtonHeight).priority(.required - 1), ]) signInButton.translatesAutoresizingMaskIntoConstraints = false buttonContainer.addArrangedSubview(signInButton) NSLayoutConstraint.activate([ - signInButton.heightAnchor.constraint(equalToConstant: WelcomeViewController.actionButtonHeight).priority(.required - 1), + signInButton.heightAnchor.constraint(greaterThanOrEqualToConstant: WelcomeViewController.actionButtonHeight).priority(.required - 1), ]) signUpButtonShadowView.translatesAutoresizingMaskIntoConstraints = false @@ -172,7 +174,9 @@ extension WelcomeViewController { override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) - + + view.layoutIfNeeded() + setupIllustrationLayout() setupButtonShadowView() } @@ -189,7 +193,7 @@ extension WelcomeViewController { y: 1, blur: 2, spread: 0, - roundedRect: signInButtonShadowView.bounds, + roundedRect: signUpButtonShadowView.bounds, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: 10, height: 10) ) From 87df13987a6970f6b7d4a29e5445082141e25e79 Mon Sep 17 00:00:00 2001 From: Jeff Verkoeyen Date: Sat, 12 Nov 2022 20:30:57 -0800 Subject: [PATCH 2/2] Ensure that the welcome buttons have adequate padding at larger Dynamic Type configurations. --- .../Onboarding/Share/OnboardingViewControllerAppearance.swift | 4 ++++ Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Mastodon/Scene/Onboarding/Share/OnboardingViewControllerAppearance.swift b/Mastodon/Scene/Onboarding/Share/OnboardingViewControllerAppearance.swift index ba1eecfc5..ee01b99e8 100644 --- a/Mastodon/Scene/Onboarding/Share/OnboardingViewControllerAppearance.swift +++ b/Mastodon/Scene/Onboarding/Share/OnboardingViewControllerAppearance.swift @@ -22,6 +22,10 @@ extension OnboardingViewControllerAppearance { static var actionButtonMarginExtend: CGFloat { return 80 } static var viewBottomPaddingHeight: CGFloat { return 11 } static var viewBottomPaddingHeightExtend: CGFloat { return 22 } + + // Typically assigned to the button's contentEdgeInsets. Ensures space around content, even when + // content is large due to Dynamic Type. + static var actionButtonPadding: UIEdgeInsets { return UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8) } static var largeTitleFont: UIFont { return UIFontMetrics(forTextStyle: .largeTitle).scaledFont(for: .systemFont(ofSize: 28, weight: .bold)) diff --git a/Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift b/Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift index 225f2f9ef..a7703bfaa 100644 --- a/Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift +++ b/Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift @@ -51,6 +51,7 @@ final class WelcomeViewController: UIViewController, NeedsDependency { private(set) lazy var signUpButton: PrimaryActionButton = { let button = PrimaryActionButton() button.adjustsBackgroundImageWhenUserInterfaceStyleChanges = false + button.contentEdgeInsets = WelcomeViewController.actionButtonPadding button.titleLabel?.adjustsFontForContentSizeCategory = true button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold)) button.setTitle(L10n.Common.Controls.Actions.signUp, for: .normal) @@ -66,6 +67,7 @@ final class WelcomeViewController: UIViewController, NeedsDependency { private(set) lazy var signInButton: PrimaryActionButton = { let button = PrimaryActionButton() button.adjustsBackgroundImageWhenUserInterfaceStyleChanges = false + button.contentEdgeInsets = WelcomeViewController.actionButtonPadding button.titleLabel?.adjustsFontForContentSizeCategory = true button.titleLabel?.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold)) button.setTitle(L10n.Scene.Welcome.logIn, for: .normal)