Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♿️ Disable Dynamic Type on buttons #806

Merged
merged 14 commits into from
Aug 20, 2019

Conversation

dusi
Copy link
Contributor

@dusi dusi commented Aug 19, 2019

📲 What

Disables Dynamic Type support globally on our buttons.

🤔 Why

Due to quite a few bugs and also the fact that all our buttons resemble Apple Pay button very closely we're temporarily disabling Dynamic Type support.

The majority of our buttons did not use multiline labels and therefore supporting Dynamic Type would result in truncations anyways.

🛠 How

Simply by using UIKit's boldSystemFont API.

👀 See

Project page

Before 🐛 After 🦋
Screen Shot 2019-08-19 at 2 36 50 PM Screen Shot 2019-08-19 at 2 40 27 PM
Screen Shot 2019-08-19 at 2 36 56 PM Screen Shot 2019-08-19 at 2 40 29 PM
Screen Shot 2019-08-19 at 2 36 58 PM Screen Shot 2019-08-19 at 2 40 31 PM
Screen Shot 2019-08-19 at 2 37 00 PM Screen Shot 2019-08-19 at 2 40 34 PM
Before 🐛 After 🦋
Screen Shot 2019-08-19 at 2 43 16 PM Screen Shot 2019-08-19 at 2 45 02 PM
Screen Shot 2019-08-19 at 2 43 18 PM Screen Shot 2019-08-19 at 2 45 13 PM
Screen Shot 2019-08-19 at 2 43 21 PM Screen Shot 2019-08-19 at 2 45 15 PM
Screen Shot 2019-08-19 at 2 43 26 PM Screen Shot 2019-08-19 at 2 45 18 PM

Rewards

Before 🐛 After 🦋
Screen Shot 2019-08-19 at 2 43 56 PM Screen Shot 2019-08-19 at 2 45 46 PM
Screen Shot 2019-08-19 at 2 44 01 PM Screen Shot 2019-08-19 at 2 45 50 PM
Screen Shot 2019-08-19 at 2 44 05 PM Screen Shot 2019-08-19 at 2 45 54 PM
Screen Shot 2019-08-19 at 2 44 09 PM Screen Shot 2019-08-19 at 2 45 56 PM

Pledge screen

Before 🐛 After 🦋
Screen Shot 2019-08-19 at 1 52 13 PM Screen Shot 2019-08-19 at 1 57 51 PM
Screen Shot 2019-08-19 at 1 52 14 PM Screen Shot 2019-08-19 at 1 57 53 PM
Screen Shot 2019-08-19 at 1 52 17 PM Screen Shot 2019-08-19 at 1 57 57 PM
Screen Shot 2019-08-19 at 1 52 20 PM Screen Shot 2019-08-19 at 1 57 59 PM

To illustrate this slightly better here's how before and after looks with a bit of blur (that potentially highlights the distinction of each major element on the screen.

Before 🐛 After 🦋
project-page-before project-page-after
project-page-manage-before project-page-manager-after
rewards-carousel-before rewards-carousel-after

👆 Notes

Please note that you might need to temporarily do the following changes to ProjectPamphlet+Helpers.swift due to an existing problem with our experiments..

public func userCanSeeNativeCheckout() -> Bool {
  return /* experimentNativeCheckoutIsEnabled() && */ featureNativeCheckoutIsEnabled()
}

✅ Acceptance criteria

  • CTA button on Project page does not support Dynamic Type
  • CTA button on Rewards cell does not support Dynamic Type
  • CTA button on Pledge screen does not support Dynamic Type
  • Every other button in the app (random sweep should be done) does not support Dynamic Type

@@ -5,7 +5,7 @@ import Prelude
final class PledgeContinueViewController: UIViewController {
// MARK: - Properties

private let continueButton = MultiLineButton(type: .custom)
private let continueButton = UIButton(type: .custom)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need to use MultiLineButton here...in fact since we've previously added trimming we haven't been using it for a while (so this is just a cleanup).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we're only using this in one place, not time to remove MultiLineButton yet?

|> UIButton.lens.title(for: .normal) %~ { _ in
Strings.Continue()
}
|> continueButtonStyle
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving to // MARK: - Styles for consistency

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that we can start renaming the Styles pragma mark above bindStyles() to Styles Binding or Bind Styles, so it differs from the Styles on the bottom of the file. what do you think?

Strings.Continue()
}
|> (UIButton.lens.titleLabel .. UILabel.lens.font) .~ UIFont.boldSystemFont(ofSize: 16)
|> (UIButton.lens.titleLabel .. UILabel.lens.lineBreakMode) .~ NSLineBreakMode.byTruncatingMiddle
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using consistent truncation in the middle for all our CTA buttons now

isAccessibilityCategory,
amountAndRewardTitleStackViewIsHidden: self.titleAndSubtitleStackView.isHidden
)
|> pledgeCTAButtonStyle
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need to know whether it's accessibility category or what state we're in

@@ -104,8 +104,9 @@ public final class RewardCardContainerView: UIView {
self.viewModel.outputs.pledgeButtonStyleType
.observeForUI()
.observeValues { [weak self] styleType in
guard let self = self else { return }
_ = self.pledgeButton |> styleType.style
_ = self?.pledgeButton
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using optional chaining for consistency between files

|> (UIButton.lens.titleLabel .. UILabel.lens.textAlignment) .~ NSTextAlignment.center
|> (UIButton.lens.titleLabel .. UILabel.lens.lineBreakMode) .~ lineBreakMode
}
private let pledgeCTAButtonStyle: ButtonStyle = { button in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be necessary to set roundedStyle and borderWidth because these are included in our base button styles now. If we want all of our buttons to behave this way shouldn't we move these to the base style?

}
|> (UIButton.lens.titleLabel .. UILabel.lens.font) .~ UIFont.boldSystemFont(ofSize: 16)
|> (UIButton.lens.titleLabel .. UILabel.lens.lineBreakMode) .~ NSLineBreakMode.byTruncatingMiddle
|> ButtonStyleType.green.style
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary to use the ButtonStyleType enum here, that is really just for our VMs to output a button style as something that we can do equality comparison on in tests. Swift doesn't support equality comparison on function types. So this can just be greenButtonStyle 👍

@dusi dusi changed the title ♿️ Disable Dynamic Type on the CTA button ♿️ Disable Dynamic Type on buttons Aug 20, 2019
@Scollaco
Copy link
Contributor

I've noticed, though, that the buttons on the credit card cells still support dynamic type. Was this intentional or supposed to be part of other PR?

|> UIButton.lens.title(for: .normal) %~ { _ in
Strings.Continue()
}
|> continueButtonStyle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that we can start renaming the Styles pragma mark above bindStyles() to Styles Binding or Bind Styles, so it differs from the Styles on the bottom of the file. what do you think?

let spacing: CGFloat = (isAccessibilityCategory ? Styles.grid(1) : 0)

return stackView
|> \.axis .~ axis
|> \.axis .~ NSLayoutConstraint.Axis.horizontal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the compiler giving you trouble here? 😄 I think that |> \.axis .~ .horizontal is more readable and more used on the codebase. Also, we have more styling going on inside the bindStyles() function. To keep consistency and avoid doing the same thing in multiple places, I would either move this code to the bindStyles function (not recommended) or do a small refactor bringing the other styles to the bottom. (recommended, since that's how we are approaching styling).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that the compiler would give us trouble but we've been seeing a lot of warnings lately related to Xcode's type checker...therefore at some point we've decided that for styles it would make more sense to be more explicit.

I'll make the styling more consistent by extracting bindStyles here.

|> UIButton.lens.titleLabel.font .~ UIFont.ksr_callout().bolded
|> (UIButton.lens.titleLabel .. UILabel.lens.textAlignment) .~ NSTextAlignment.center
|> UIButton.lens.contentEdgeInsets .~ .init(all: Styles.grid(2))
|> UIButton.lens.titleLabel .. UILabel.lens.font .~ UIFont.boldSystemFont(ofSize: 16)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lenses give us access to the font property of a UIButton. So this line could simply be |> UIButton.lens.titleLabel.font .~ UIFont.boldSystemFont(ofSize: 16) (this syntax is the most commonly used on our codebase)

Copy link
Contributor Author

@dusi dusi Aug 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to update Prelude so if you can also check it out and approve if everything looks fine - kickstarter/Kickstarter-Prelude#95

@dusi
Copy link
Contributor Author

dusi commented Aug 20, 2019

Thanks for catching up the payment methods issue (I've fixed it and went through all the places we refer to base style in the whole app so now all buttons should in fact not support Dynamic Type 🤞 ).

As for the pragma mark I'd defer this to some future work (it would be great to have a whole team agree on this before changing something we've been doing for some time now. // MARK: - Bind Styles is currently only used in 1 place (PledgePaymentMethodsViewController) and I'm kinda tempted at changing it to Styles for consistency 😅

Copy link
Contributor

@justinswart justinswart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for all the screenshots!

Copy link
Contributor

@Scollaco Scollaco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@dusi
Copy link
Contributor Author

dusi commented Aug 20, 2019

Fun fact, those screenshots did actually not fit on my Desktop (I think I need 15" MBP or the new Pro Display soon) 🤦‍♂

@dusi dusi merged commit 861ea22 into master Aug 20, 2019
@dusi dusi deleted the a11y-cta-button-disable-dynamic-type branch August 20, 2019 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants