-
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
[NT-558][NT-508][NT-532] Indicate Backing state on Manage Pledge View #934
Merged
Merged
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
211a3ab
Add strings for backing status on manage pledge view
justinswart 2a8aed8
Merge branch 'master' into manage-pledge-backing-state-string
justinswart 1b95b41
Add copy for error state
justinswart d2fe813
Formatting
justinswart b1dd8da
Update new snapshots
justinswart 705e402
Merge branch 'master' into manage-pledge-backing-state-string
justinswart aa6584c
Improved sharing of functions, added creator strings
justinswart 329baca
Correct font
justinswart 780791f
Use smart apostrophe
justinswart 6bc8502
Add attributed string tests
justinswart 28a7e86
Remove creator strings
justinswart 83c5f3a
Merge branch 'master' into manage-pledge-backing-state-string
justinswart 292a150
Use Strings functions ahead of translations
justinswart a1a8dce
German, Spanish and French translations
justinswart a37fedc
Use project.stats.needsConversion, fix test
justinswart 4b1123b
Merge branch 'master' into manage-pledge-backing-state-string
justinswart e42b807
Fix tests, record new snapshots
justinswart 1641f6c
Merge branch 'master' into manage-pledge-backing-state-string
justinswart 18c99f7
Merge branch 'master' into manage-pledge-backing-state-string
justinswart 7a725e0
Remove traitCollectionDidChange input
justinswart 0a8d8c7
Merge branch 'master' into manage-pledge-backing-state-string
justinswart c4cdf0a
Formatting
justinswart c709f2c
New snapshots
justinswart 3cfabdb
Use a UIView instead
justinswart 1d2d54b
Rename property
justinswart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
Kickstarter-iOS/Views/Controllers/PledgeStatusLabelViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import KsApi | ||
import Library | ||
import Prelude | ||
import Prelude_UIKit | ||
import UIKit | ||
|
||
final class PledgeStatusLabelViewController: UIViewController { | ||
// MARK: - Properties | ||
|
||
private lazy var containerView: UIView = { UIView(frame: .zero) }() | ||
private lazy var label: UILabel = { UILabel(frame: .zero) }() | ||
|
||
private let viewModel: PledgeStatusLabelViewModelType = PledgeStatusLabelViewModel() | ||
|
||
// MARK: - Lifecycle | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
self.configureSubviews() | ||
|
||
self.viewModel.inputs.viewDidLoad() | ||
} | ||
|
||
// MARK: - Styles | ||
|
||
override func bindStyles() { | ||
super.bindStyles() | ||
|
||
_ = self.containerView | ||
|> containerViewStyle | ||
|
||
_ = self.label | ||
|> labelStyle | ||
} | ||
|
||
private func configureSubviews() { | ||
_ = (self.containerView, self.view) | ||
|> ksr_addSubviewToParent() | ||
|> ksr_constrainViewToEdgesInParent() | ||
|
||
_ = (self.label, self.containerView) | ||
|> ksr_addSubviewToParent() | ||
|> ksr_constrainViewToMarginsInParent() | ||
} | ||
|
||
// MARK: - View model | ||
|
||
override func bindViewModel() { | ||
super.bindViewModel() | ||
|
||
self.label.rac.attributedText = self.viewModel.outputs.labelText | ||
} | ||
|
||
// MARK: - Configuration | ||
|
||
internal func configure(with project: Project) { | ||
self.viewModel.inputs.configure(with: project) | ||
} | ||
} | ||
|
||
// MARK: - Styles | ||
|
||
private let containerViewStyle: ViewStyle = { (view: UIView) in | ||
view | ||
|> \.backgroundColor .~ .ksr_grey_400 | ||
|> \.layoutMargins .~ .init(all: Styles.grid(2)) | ||
|> roundedStyle() | ||
} | ||
|
||
private let labelStyle: LabelStyle = { (label: UILabel) in | ||
label | ||
|> \.adjustsFontForContentSizeCategory .~ true | ||
|> \.isAccessibilityElement .~ true | ||
|> \.numberOfLines .~ 0 | ||
|> \.backgroundColor .~ .ksr_grey_400 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,40 @@ | ||
import Foundation | ||
import UIKit | ||
|
||
public func + (left: NSAttributedString, right: NSAttributedString) -> NSAttributedString { | ||
let combined = NSMutableAttributedString() | ||
combined.append(left) | ||
combined.append(right) | ||
return NSMutableAttributedString(attributedString: combined) | ||
} | ||
|
||
extension String { | ||
func attributed( | ||
with font: UIFont, | ||
foregroundColor: UIColor, | ||
attributes: [NSAttributedString.Key: Any], | ||
bolding strings: [String] | ||
) -> NSAttributedString { | ||
let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: self) | ||
let fullRange = (self as NSString).localizedStandardRange(of: self) | ||
|
||
let regularFontAttributes = [ | ||
NSAttributedString.Key.font: font, | ||
NSAttributedString.Key.foregroundColor: foregroundColor | ||
] | ||
.withAllValuesFrom(attributes) | ||
|
||
attributedString.addAttributes(regularFontAttributes, range: fullRange) | ||
|
||
let boldFontAttribute = [NSAttributedString.Key.font: font.bolded] | ||
|
||
for string in strings { | ||
attributedString.addAttributes( | ||
boldFontAttribute, | ||
range: (self as NSString).localizedStandardRange(of: string) | ||
) | ||
} | ||
|
||
return attributedString | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
@testable import Library | ||
import XCTest | ||
|
||
final class String_AttributedTests: TestCase { | ||
func testCombining() { | ||
let s1 = NSAttributedString(string: "prefix") | ||
let s2 = NSAttributedString(string: "suffix") | ||
|
||
let combined = s1 + s2 | ||
|
||
XCTAssertEqual("prefixsuffix", combined.string) | ||
} | ||
|
||
func testAttributedBolding() { | ||
let string = "My special string of words" | ||
|
||
let paragraphStyle = NSMutableParagraphStyle() | ||
paragraphStyle.alignment = .center | ||
|
||
let attributes = [ | ||
NSAttributedString.Key.paragraphStyle: paragraphStyle | ||
] | ||
|
||
let font = UIFont.ksr_body() | ||
let boldedFont = UIFont.ksr_body().bolded | ||
let foregroundColor = UIColor.ksr_text_black | ||
|
||
let attributed = string.attributed( | ||
with: font, | ||
foregroundColor: foregroundColor, | ||
attributes: attributes, | ||
bolding: ["words"] | ||
) | ||
|
||
let allAttributes = attributed.attributes( | ||
at: 0, | ||
longestEffectiveRange: nil, | ||
in: (string as NSString).range(of: string) | ||
) | ||
|
||
XCTAssertEqual(allAttributes[NSAttributedString.Key.paragraphStyle] as? NSParagraphStyle, paragraphStyle) | ||
XCTAssertEqual(allAttributes[NSAttributedString.Key.font] as? UIFont, font) | ||
XCTAssertEqual(allAttributes[NSAttributedString.Key.foregroundColor] as? UIColor, foregroundColor) | ||
|
||
let boldedRange = (string as NSString).range(of: "words") | ||
|
||
let boldedAttributes = attributed.attributes( | ||
at: boldedRange.location, | ||
longestEffectiveRange: nil, | ||
in: boldedRange | ||
) | ||
|
||
XCTAssertEqual(boldedAttributes[NSAttributedString.Key.font] as? UIFont, boldedFont) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just curious, why did you opt for using a VC here instead of a
UIView
? π€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 just had a good feeling about it π