-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
@@ -5,7 +5,7 @@ import Prelude | |||
final class PledgeContinueViewController: UIViewController { | |||
// MARK: - Properties | |||
|
|||
private let continueButton = MultiLineButton(type: .custom) | |||
private let continueButton = UIButton(type: .custom) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
👍
|> UIButton.lens.title(for: .normal) %~ { _ in | ||
Strings.Continue() | ||
} | ||
|> continueButtonStyle |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
Library/Styles/ButtonStyles.swift
Outdated
|> 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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
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. |
There was a problem hiding this 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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Fun fact, those screenshots did actually not fit on my Desktop (I think I need 15" MBP or the new Pro Display soon) 🤦♂ |
📲 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
Rewards
Pledge screen
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.
👆 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..✅ Acceptance criteria
Project page
does not support Dynamic TypeRewards cell
does not support Dynamic TypePledge screen
does not support Dynamic Type