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
Merged
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Internal

github "kickstarter/Kickstarter-Prelude" "c96c90b026d45839724e827f881dcba3ec812725"
github "kickstarter/Kickstarter-Prelude" "d03f8831dcec9ad157db4f1c5f769ec17e1a3766"
github "kickstarter/Kickstarter-ReactiveExtensions" "aa994f0921dca1965ae537fe77c2edc798eef230"

### 3rd Party
Expand Down
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github "AgileBits/onepassword-extension" "framework/1.8.4"
github "Alamofire/Alamofire" "5.0.0-beta.6"
github "Alamofire/Alamofire" "5.0.0-beta.7"
github "Alamofire/AlamofireImage" "c41f8b0acfbb3180fe045df73596e4332c338633"
github "ReactiveCocoa/ReactiveSwift" "6.0.0"
github "facebook/facebook-objc-sdk" "v5.0.2"
github "kickstarter/Kickstarter-Prelude" "c96c90b026d45839724e827f881dcba3ec812725"
github "kickstarter/Kickstarter-Prelude" "d03f8831dcec9ad157db4f1c5f769ec17e1a3766"
github "kickstarter/Kickstarter-ReactiveExtensions" "aa994f0921dca1965ae537fe77c2edc798eef230"
github "stripe/stripe-ios" "v13.2.0"
github "thoughtbot/Argo" "39f06f089d25c111444e5a85eef64586e54756ac"
Expand Down
11 changes: 1 addition & 10 deletions Kickstarter-iOS/Views/Controllers/LoginToutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ internal final class LoginToutViewController: UIViewController, MFMailComposeVie
|> fbLoginButtonStyle

_ = self.disclaimerButton
|> baseMultiLineButtonStyle
|> multiLineButtonStyle
|> disclaimerButtonStyle

_ = self.loginButton
Expand Down Expand Up @@ -421,12 +421,3 @@ private let baseLabelStyle: LabelStyle = { label in
|> \.lineBreakMode .~ NSLineBreakMode.byWordWrapping
|> \.numberOfLines .~ 0
}

private let baseMultiLineButtonStyle: ButtonStyle = { button in
_ = button.titleLabel
?|> \.textAlignment .~ NSTextAlignment.center
?|> \.lineBreakMode .~ NSLineBreakMode.byWordWrapping
?|> \.numberOfLines .~ 0

return button
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?

private let viewModel = PledgeContinueViewModel()

// MARK: - Lifecycle
Expand All @@ -25,10 +25,7 @@ final class PledgeContinueViewController: UIViewController {
|> checkoutBackgroundStyle

_ = self.continueButton
|> greenButtonStyle
|> 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?

}

// MARK: - View model
Expand Down Expand Up @@ -74,3 +71,11 @@ final class PledgeContinueViewController: UIViewController {
self.presentViewControllerWithSheetOverlay(navigationController, offset: navigationBarHeight)
}
}

// MARK: - Styles

private let continueButtonStyle: ButtonStyle = { button in
button
|> greenButtonStyle
|> UIButton.lens.title(for: .normal) %~ { _ in Strings.Continue() }
}
69 changes: 34 additions & 35 deletions Kickstarter-iOS/Views/PledgeCTAContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,19 @@ final class PledgeCTAContainerView: UIView {
|> pledgeRetryButtonStyle

_ = self.titleAndSubtitleStackView
|> \.axis .~ NSLayoutConstraint.Axis.vertical
|> \.isLayoutMarginsRelativeArrangement .~ true
|> \.spacing .~ Styles.gridHalf(1)

_ = self.pledgeCTAButton
|> pledgeCTAButtonStyle(
isAccessibilityCategory,
amountAndRewardTitleStackViewIsHidden: self.titleAndSubtitleStackView.isHidden
)
|> titleAndSubtitleStackViewStyle

_ = self.rootStackView
|> adaptableStackViewStyle(isAccessibilityCategory)
|> \.isLayoutMarginsRelativeArrangement .~ true
|> \.layoutMargins .~ UIEdgeInsets.init(topBottom: Styles.grid(3), leftRight: Styles.grid(3))
|> \.alignment .~ .center

_ = self.titleLabel
|> \.font .~ UIFont.ksr_callout().bolded
|> \.numberOfLines .~ 0
|> titleLabelStyle

_ = self.subtitleLabel
|> \.font .~ UIFont.ksr_caption1().bolded
|> \.textColor .~ UIColor.ksr_dark_grey_500
|> \.numberOfLines .~ 0
|> subtitleLabelStyle

_ = self.activityIndicator
|> \.color .~ UIColor.ksr_dark_grey_500
|> activityIndicatorStyle
}

// MARK: - View model
Expand All @@ -122,7 +108,8 @@ final class PledgeCTAContainerView: UIView {
self.viewModel.outputs.buttonStyleType
.observeForUI()
.observeValues { [weak self] buttonStyleType in
_ = self?.pledgeCTAButton ?|> buttonStyleType.style
_ = self?.pledgeCTAButton
?|> buttonStyleType.style
}

self.viewModel.outputs.pledgeCTAButtonIsHidden
Expand Down Expand Up @@ -196,31 +183,43 @@ final class PledgeCTAContainerView: UIView {

// MARK: - Styles

private let activityIndicatorStyle: ActivityIndicatorStyle = { activityIndicator in
activityIndicator
|> \.color .~ UIColor.ksr_dark_grey_500
|> \.hidesWhenStopped .~ true
}

private func adaptableStackViewStyle(_ isAccessibilityCategory: Bool) -> (StackViewStyle) {
return { (stackView: UIStackView) in
let axis: NSLayoutConstraint.Axis = (isAccessibilityCategory ? .vertical : .horizontal)
let spacing: CGFloat = (isAccessibilityCategory ? Styles.grid(1) : 0)

return stackView
|> \.axis .~ axis
|> \.alignment .~ .center
|> \.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.

|> \.isLayoutMarginsRelativeArrangement .~ true
|> \.layoutMargins .~ UIEdgeInsets.init(topBottom: Styles.grid(3), leftRight: Styles.grid(3))
|> \.spacing .~ spacing
}
}

private func pledgeCTAButtonStyle(
_ isAccessibilityCategory: Bool, amountAndRewardTitleStackViewIsHidden: Bool
) -> (ButtonStyle) {
return { (button: UIButton) in
let lineBreakMode: NSLineBreakMode = isAccessibilityCategory || amountAndRewardTitleStackViewIsHidden
? NSLineBreakMode.byWordWrapping : NSLineBreakMode.byTruncatingTail

return button
|> roundedStyle(cornerRadius: 12)
|> UIButton.lens.titleLabel.font .~ UIFont.ksr_headline(size: 15)
|> UIButton.lens.layer.borderWidth .~ 0
|> (UIButton.lens.titleLabel .. UILabel.lens.textAlignment) .~ NSTextAlignment.center
|> (UIButton.lens.titleLabel .. UILabel.lens.lineBreakMode) .~ lineBreakMode
}
private let subtitleLabelStyle: LabelStyle = { label in
label
|> \.font .~ UIFont.ksr_caption1().bolded
|> \.textColor .~ UIColor.ksr_dark_grey_500
|> \.numberOfLines .~ 0
}

private let titleAndSubtitleStackViewStyle: StackViewStyle = { stackView in
stackView
|> \.axis .~ NSLayoutConstraint.Axis.vertical
|> \.isLayoutMarginsRelativeArrangement .~ true
|> \.spacing .~ Styles.gridHalf(1)
}

private let titleLabelStyle: LabelStyle = { label in
label
|> \.font .~ UIFont.ksr_callout().bolded
|> \.numberOfLines .~ 0
}

private let pledgeRetryButtonStyle: ButtonStyle = { button in
Expand Down
11 changes: 4 additions & 7 deletions Kickstarter-iOS/Views/RewardCardContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public final class RewardCardContainerView: UIView {
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()

private let pledgeButton: MultiLineButton = {
MultiLineButton(type: .custom)
private let pledgeButton: UIButton = {
UIButton(type: .custom)
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()

Expand Down Expand Up @@ -65,9 +65,6 @@ public final class RewardCardContainerView: UIView {
(UIColor.white.withAlphaComponent(1.0), 1)
]
self.gradientView.setGradient(gradient)

_ = self.pledgeButton.titleLabel
?|> \.lineBreakMode .~ .byTruncatingTail
}

public override func bindViewModel() {
Expand Down Expand Up @@ -104,8 +101,8 @@ 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

?|> styleType.style
}
}

Expand Down
1 change: 1 addition & 0 deletions Library/Styles/BaseStyles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public enum Styles {
}
}

public typealias ActivityIndicatorStyle = (UIActivityIndicatorView) -> UIActivityIndicatorView
public typealias ButtonStyle = (UIButton) -> UIButton
public typealias CollectionViewStyle = (UICollectionView) -> UICollectionView
public typealias ImageViewStyle = (UIImageView) -> UIImageView
Expand Down
26 changes: 15 additions & 11 deletions Library/Styles/ButtonStyles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public let applePayButtonStyle: ButtonStyle = { button in
public let baseButtonStyle: ButtonStyle = { button in
button
|> roundedStyle(cornerRadius: Styles.grid(2))
|> 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.lineBreakMode .~ NSLineBreakMode.byTruncatingMiddle
|> UIButton.lens.titleLabel .. UILabel.lens.numberOfLines .~ 1
|> UIButton.lens.adjustsImageWhenDisabled .~ false
|> UIButton.lens.adjustsImageWhenHighlighted .~ false
<> UIButton.lens.titleLabel.font .~ UIFont.boldSystemFont(ofSize: 16)
<> UIButton.lens.titleLabel.lineBreakMode .~ NSLineBreakMode.byTruncatingMiddle
<> UIButton.lens.titleLabel.textAlignment .~ NSTextAlignment.center
<> UIButton.lens.titleLabel.numberOfLines .~ 1
}

// MARK: - Apricot
Expand Down Expand Up @@ -89,14 +89,14 @@ public let facebookButtonStyle = baseButtonStyle

<> UIButton.lens.image(for: .normal) %~ { _ in image(named: "fb-logo-white") }

// MARK: - Red
// MARK: - Multiline

public let redButtonStyle = baseButtonStyle
<> UIButton.lens.titleColor(for: .normal) .~ .white
<> UIButton.lens.backgroundColor(for: .normal) .~ .ksr_red_400
<> UIButton.lens.titleColor(for: .highlighted) .~ .white
<> UIButton.lens.backgroundColor(for: .highlighted) .~ UIColor.ksr_red_400.mixDarker(0.36)
<> UIButton.lens.backgroundColor(for: .disabled) .~ UIColor.ksr_red_400.mixLighter(0.36)
public let multiLineButtonStyle =
UIButton.lens.titleLabel.lineBreakMode .~ NSLineBreakMode.byWordWrapping
<> UIButton.lens.titleLabel.numberOfLines .~ 0
<> UIButton.lens.titleLabel.textAlignment .~ NSTextAlignment.center

// MARK: - Save

public let saveButtonStyle =
UIButton.lens.title(for: .normal) .~ nil
Expand All @@ -105,12 +105,16 @@ public let saveButtonStyle =
<> UIButton.lens.image(for: .selected) .~ image(named: "icon--heart")
<> UIButton.lens.accessibilityLabel %~ { _ in Strings.Save_this_project() }

// MARK: - Share

public let shareButtonStyle =
UIButton.lens.title(for: .normal) .~ nil
<> UIButton.lens.image(for: .normal) .~ image(named: "icon--share")
<> UIButton.lens.tintColor .~ .ksr_soft_black
<> UIButton.lens.accessibilityLabel %~ { _ in Strings.dashboard_accessibility_label_share_project() }

// MARK: - Text only

// Remove when DeprecatedRewardShippingPickerViewController is removed.
public let textOnlyButtonStyle = roundedStyle(cornerRadius: 0)
<> UIButton.lens.titleLabel.font %~~ { _, button in
Expand Down
8 changes: 1 addition & 7 deletions Library/Styles/CheckoutStyles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ public func checkoutAdaptableStackViewStyle(_ isAccessibilityCategory: Bool) ->
}
}

public let checkoutSmallBlackButtonStyle: ButtonStyle = { button -> UIButton in
button
|> blackButtonStyle
}

public let checkoutBackgroundStyle: ViewStyle = { (view: UIView) in
view
|> \.backgroundColor .~ UIColor.ksr_grey_300
Expand Down Expand Up @@ -187,8 +182,7 @@ public let cardImageViewStyle: ImageViewStyle = { imageView in

public let cardSelectButtonStyle: ButtonStyle = { button in
button
|> checkoutSmallBlackButtonStyle
|> UIButton.lens.titleLabel .. UILabel.lens.font .~ UIFont.ksr_headline()
|> blackButtonStyle
}

public let pledgeCardViewStyle: ViewStyle = { view in
Expand Down
1 change: 0 additions & 1 deletion Library/Styles/LoginStyles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public func emailFieldAutoFillStyle(_ textField: UITextField) -> UITextField {
}

public let fbLoginButtonStyle = facebookButtonStyle
<> baseButtonStyle
<> UIButton.lens.title(for: .normal) %~ { _ in
Strings.login_tout_buttons_log_in_with_facebook()
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.