Skip to content

Commit

Permalink
💲[Native Checkout] UITextView bottom padding improvements (#723)
Browse files Browse the repository at this point in the history
* Pledge Summary Cell layout

* SwiftFormat

* Fix test

* Open links in web view

* Add tests

* DRY it up a little

* Formatting

* Handle amount state between cells

* swiftlint

* Add tests

* Move parentheses

* Pass ShippingRule to delegate

* total -> pledgeTotal

* Use the same output for reloading and updating the tableview

* Move a brace

* 💲[Native Checkout] Pledge Summary Cell Handle Links (#717)

* Open links in web view

* Add tests

* DRY it up a little

* Formatting

* Remove PledgeRowCell

* Add minimumScaleFactor to total label

* Fix textview voiceover

* Fix amount label voice-over

* Improve UITextView bottom padding

* Add ksr_ prefix
  • Loading branch information
justinswart authored and ifbarrera committed Aug 6, 2019
1 parent d2c486c commit a576696
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Kickstarter-iOS/Views/Cells/PledgeDescriptionCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ final class PledgeDescriptionCell: UITableViewCell, ValueCell {
private lazy var dateLabel: UILabel = { UILabel(frame: .zero) }()
private lazy var spacerView = UIView(frame: .zero)
private lazy var learnMoreTextView: UITextView = { UITextView(frame: .zero) |> \.delegate .~ self }()
private var learnMoreTextViewHeightConstraint: NSLayoutConstraint?

// MARK: - Lifecycle

Expand Down Expand Up @@ -85,6 +86,9 @@ final class PledgeDescriptionCell: UITableViewCell, ValueCell {

_ = self.learnMoreTextView
|> learnMoreTextViewStyle

self.learnMoreTextViewHeightConstraint?.constant = self.learnMoreTextView.ksr_sizeThatFitsCurrentWidth()
.height
}

private func configureSubviews() {
Expand All @@ -101,10 +105,14 @@ final class PledgeDescriptionCell: UITableViewCell, ValueCell {

self.configureStackView()

let learnMoreTextViewHeightConstraint = self.learnMoreTextView.heightAnchor.constraint(equalToConstant: 0)
self.learnMoreTextViewHeightConstraint = learnMoreTextViewHeightConstraint

NSLayoutConstraint.activate([
self.containerImageView.widthAnchor.constraint(equalToConstant: Layout.ImageView.width),
self.containerImageView.heightAnchor.constraint(equalToConstant: Layout.ImageView.height),
self.pledgeImageView.centerXAnchor.constraint(equalTo: self.containerImageView.centerXAnchor)
self.pledgeImageView.centerXAnchor.constraint(equalTo: self.containerImageView.centerXAnchor),
learnMoreTextViewHeightConstraint
])
}

Expand Down
5 changes: 5 additions & 0 deletions Kickstarter-iOS/Views/Cells/PledgeSummaryCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ final class PledgeSummaryCell: UITableViewCell, ValueCell {

_ = self.amountLabel
|> amountLabelStyle

self.termsTextViewHeightConstraint?.constant = self.termsTextView.ksr_sizeThatFitsCurrentWidth().height
}

private func configureSubviews() {
Expand All @@ -75,6 +77,9 @@ final class PledgeSummaryCell: UITableViewCell, ValueCell {

_ = ([self.termsTextView, self.amountLabel], self.adaptableStackView)
|> ksr_addArrangedSubviewsToStackView()

self.termsTextViewHeightConstraint = self.termsTextView.heightAnchor.constraint(equalToConstant: 0)
self.termsTextViewHeightConstraint?.isActive = true
}

// MARK: - Binding
Expand Down
6 changes: 5 additions & 1 deletion Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@
D00A3765225BCE2600F46F47 /* Prelude.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0D58D792257FADE00532AC1 /* Prelude.framework */; };
D00A3766225BCE8400F46F47 /* ReactiveSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0D58D7F2257FADF00532AC1 /* ReactiveSwift.framework */; };
D00A376E225BDAF800F46F47 /* UIAlertControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D69BACEF21C856F2006EAA00 /* UIAlertControllerTests.swift */; };
D013D44A22C2DF1C00B317D8 /* UITextView+SizeThatFits.swift in Sources */ = {isa = PBXBuildFile; fileRef = D013D44922C2DF1C00B317D8 /* UITextView+SizeThatFits.swift */; };
D01587591EEB2DE4006E7684 /* KsApi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D01587501EEB2DE4006E7684 /* KsApi.framework */; };
D015882B1EEB2ED7006E7684 /* NSURLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = D015876A1EEB2ED6006E7684 /* NSURLSession.swift */; };
D015882D1EEB2ED7006E7684 /* BasicHTTPAuth.swift in Sources */ = {isa = PBXBuildFile; fileRef = D015876D1EEB2ED6006E7684 /* BasicHTTPAuth.swift */; };
Expand Down Expand Up @@ -1941,6 +1942,7 @@
D002CAE4218CF951009783F2 /* GraphMutationWatchProjectResponseEnvelope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphMutationWatchProjectResponseEnvelope.swift; sourceTree = "<group>"; };
D00A371F225815FA00F46F47 /* AlamofireImage.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AlamofireImage.framework; path = Carthage/Build/iOS/AlamofireImage.framework; sourceTree = "<group>"; };
D00A373E2258270600F46F47 /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = Carthage/Build/iOS/Alamofire.framework; sourceTree = "<group>"; };
D013D44922C2DF1C00B317D8 /* UITextView+SizeThatFits.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextView+SizeThatFits.swift"; sourceTree = "<group>"; };
D01587501EEB2DE4006E7684 /* KsApi.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = KsApi.framework; sourceTree = BUILT_PRODUCTS_DIR; };
D01587531EEB2DE4006E7684 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D01587581EEB2DE4006E7684 /* KsApiTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = KsApiTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -2999,10 +3001,11 @@
A78537E11CB5422100385B73 /* UIScreenType.swift */,
A7169BF51DDD064200480C0D /* UIScrollView+Extensions.swift */,
37FDAF702273B7FF00662CC8 /* UIStackView.swift */,
37FDAFAA2273B86800662CC8 /* UIStackView+Tests.swift */,
D6508F342049C45D002DCC01 /* UIStackView+BackgroundColor.swift */,
37FDAFAA2273B86800662CC8 /* UIStackView+Tests.swift */,
D0A787BE2204D975006AE4F4 /* UITableView+AutoLayoutHeaderView.swift */,
01A7A4BF1C9690220036E553 /* UITextField+LocalizedPlaceholderKey.swift */,
D013D44922C2DF1C00B317D8 /* UITextView+SizeThatFits.swift */,
37BB45C82243031100E7392A /* UIView+AutoLayout.swift */,
778CCCD92285BF8900FB8D35 /* UIView+AutoLayoutTests.swift */,
A733795F1D0EDFEE00C91445 /* UIViewController-Preparation.swift */,
Expand Down Expand Up @@ -4335,6 +4338,7 @@
A755115E1C8642C3005355CF /* Environment.swift in Sources */,
A7F441D11D005A9400FE6FC5 /* MessageThreadsViewModel.swift in Sources */,
D6DC653321768B6E008CF69C /* ChangeEmailViewModel.swift in Sources */,
D013D44A22C2DF1C00B317D8 /* UITextView+SizeThatFits.swift in Sources */,
A71F59E81D2424CA00909BE3 /* KSCache.swift in Sources */,
A757EB2B1D1AD89E00A5C978 /* DiscoveryStyles.swift in Sources */,
80E8EAC81D3EC65A007BDA4B /* Image.swift in Sources */,
Expand Down
10 changes: 10 additions & 0 deletions Library/UITextView+SizeThatFits.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Foundation
import UIKit

public extension UITextView {
func ksr_sizeThatFitsCurrentWidth() -> CGSize {
return self.sizeThatFits(
CGSize(width: self.bounds.size.width, height: .greatestFiniteMagnitude)
)
}
}

0 comments on commit a576696

Please sign in to comment.