-
Notifications
You must be signed in to change notification settings - Fork 484
Add next label position #273
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,6 +24,8 @@ public class CoachMarkBodyDefaultView: UIControl, | |||||||||||||||||||||||||||||||||||||||||||
public lazy var nextLabel: UILabel = makeNextLabel() | ||||||||||||||||||||||||||||||||||||||||||||
public lazy var hintLabel: UITextView = makeHintTextView() | ||||||||||||||||||||||||||||||||||||||||||||
public lazy var separator: UIView = makeSeparator() | ||||||||||||||||||||||||||||||||||||||||||||
private let nextLabelPosition: CoachMarkNextLabelPosition? | ||||||||||||||||||||||||||||||||||||||||||||
private let spacing: CGFloat = 18 | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
public var background: CoachMarkBodyBackgroundStyle { | ||||||||||||||||||||||||||||||||||||||||||||
get { return bodyBackground } | ||||||||||||||||||||||||||||||||||||||||||||
|
@@ -40,11 +42,15 @@ public class CoachMarkBodyDefaultView: UIControl, | |||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
// MARK: - Initialization | ||||||||||||||||||||||||||||||||||||||||||||
override public init(frame: CGRect) { | ||||||||||||||||||||||||||||||||||||||||||||
self.nextLabelPosition = .none | ||||||||||||||||||||||||||||||||||||||||||||
ong-yue-huei marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
super.init(frame: frame) | ||||||||||||||||||||||||||||||||||||||||||||
initializeViewHierarchy() | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
public init(frame: CGRect, hintText: String, nextText: String?) { | ||||||||||||||||||||||||||||||||||||||||||||
public init(frame: CGRect, hintText: String, nextText: String?, nextLabelPosition: CoachMarkNextLabelPosition?) { | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably want to force users to provide a position that isn't nil.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
self.nextLabelPosition = nextLabelPosition | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
super.init(frame: frame) | ||||||||||||||||||||||||||||||||||||||||||||
initializeViewHierarchy() | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
|
@@ -55,12 +61,19 @@ public class CoachMarkBodyDefaultView: UIControl, | |||||||||||||||||||||||||||||||||||||||||||
hintLabel.text = hintText | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
convenience public init(hintText: String, nextText: String?) { | ||||||||||||||||||||||||||||||||||||||||||||
self.init(frame: CGRect.zero, hintText: hintText, nextText: nextText) | ||||||||||||||||||||||||||||||||||||||||||||
public init(frame: CGRect, nextLabelPosition: CoachMarkNextLabelPosition?) { | ||||||||||||||||||||||||||||||||||||||||||||
self.nextLabelPosition = nextLabelPosition | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
super.init(frame: frame) | ||||||||||||||||||||||||||||||||||||||||||||
initializeViewHierarchy() | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
convenience public init() { | ||||||||||||||||||||||||||||||||||||||||||||
self.init(frame: CGRect.zero) | ||||||||||||||||||||||||||||||||||||||||||||
convenience public init(hintText: String, nextText: String?, nextLabelPosition: CoachMarkNextLabelPosition?) { | ||||||||||||||||||||||||||||||||||||||||||||
self.init(frame: CGRect.zero, hintText: hintText, nextText: nextText, nextLabelPosition: nextLabelPosition) | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
convenience public init(nextLabelPosition: CoachMarkNextLabelPosition?) { | ||||||||||||||||||||||||||||||||||||||||||||
self.init(frame: CGRect.zero, nextLabelPosition: nextLabelPosition) | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
required public init?(coder aDecoder: NSCoder) { | ||||||||||||||||||||||||||||||||||||||||||||
|
@@ -82,12 +95,63 @@ private extension CoachMarkBodyDefaultView { | |||||||||||||||||||||||||||||||||||||||||||
bodyBackground.fillSuperview() | ||||||||||||||||||||||||||||||||||||||||||||
labelStackView.fillSuperview(insets: UIEdgeInsets(top: 10, left: 15, bottom: 10, right: 15)) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addArrangedSubview(hintLabel) | ||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addArrangedSubview(separator) | ||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addArrangedSubview(nextLabel) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
separator.heightAnchor.constraint(equalTo: labelStackView.heightAnchor, | ||||||||||||||||||||||||||||||||||||||||||||
constant: -10).isActive = true | ||||||||||||||||||||||||||||||||||||||||||||
switch nextLabelPosition { | ||||||||||||||||||||||||||||||||||||||||||||
case .topRight: | ||||||||||||||||||||||||||||||||||||||||||||
ong-yue-huei marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addSubview(hintLabel) | ||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addSubview(nextLabel) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
NSLayoutConstraint.activate([ | ||||||||||||||||||||||||||||||||||||||||||||
nextLabel.topAnchor.constraint(equalTo: topAnchor, constant: spacing), | ||||||||||||||||||||||||||||||||||||||||||||
nextLabel.bottomAnchor.constraint(equalTo: hintLabel.topAnchor, constant: -spacing), | ||||||||||||||||||||||||||||||||||||||||||||
nextLabel.rightAnchor.constraint(equalTo: rightAnchor, constant: -spacing), | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -spacing), | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: spacing), | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.rightAnchor.constraint(lessThanOrEqualTo: rightAnchor, constant: -spacing) | ||||||||||||||||||||||||||||||||||||||||||||
]) | ||||||||||||||||||||||||||||||||||||||||||||
case .topLeft: | ||||||||||||||||||||||||||||||||||||||||||||
ong-yue-huei marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addSubview(hintLabel) | ||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addSubview(nextLabel) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
NSLayoutConstraint.activate([ | ||||||||||||||||||||||||||||||||||||||||||||
nextLabel.topAnchor.constraint(equalTo: topAnchor, constant: spacing), | ||||||||||||||||||||||||||||||||||||||||||||
nextLabel.bottomAnchor.constraint(equalTo: hintLabel.topAnchor, constant: -spacing), | ||||||||||||||||||||||||||||||||||||||||||||
nextLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: spacing), | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -spacing), | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: spacing), | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.rightAnchor.constraint(lessThanOrEqualTo: rightAnchor, constant: -spacing) | ||||||||||||||||||||||||||||||||||||||||||||
]) | ||||||||||||||||||||||||||||||||||||||||||||
case .bottomRight: | ||||||||||||||||||||||||||||||||||||||||||||
ong-yue-huei marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addSubview(hintLabel) | ||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addSubview(nextLabel) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
NSLayoutConstraint.activate([ | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.topAnchor.constraint(equalTo: topAnchor, constant: spacing), | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.bottomAnchor.constraint(equalTo: nextLabel.topAnchor, constant: -spacing), | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: spacing), | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.rightAnchor.constraint(lessThanOrEqualTo: rightAnchor, constant: -spacing), | ||||||||||||||||||||||||||||||||||||||||||||
nextLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -spacing), | ||||||||||||||||||||||||||||||||||||||||||||
nextLabel.rightAnchor.constraint(equalTo: rightAnchor, constant: -spacing) | ||||||||||||||||||||||||||||||||||||||||||||
]) | ||||||||||||||||||||||||||||||||||||||||||||
case .bottomLeft: | ||||||||||||||||||||||||||||||||||||||||||||
ong-yue-huei marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addSubview(hintLabel) | ||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addSubview(nextLabel) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
NSLayoutConstraint.activate([ | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.topAnchor.constraint(equalTo: topAnchor, constant: spacing), | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.bottomAnchor.constraint(equalTo: nextLabel.topAnchor, constant: -spacing), | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: spacing), | ||||||||||||||||||||||||||||||||||||||||||||
hintLabel.rightAnchor.constraint(lessThanOrEqualTo: rightAnchor, constant: -spacing), | ||||||||||||||||||||||||||||||||||||||||||||
nextLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -spacing), | ||||||||||||||||||||||||||||||||||||||||||||
nextLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: spacing) | ||||||||||||||||||||||||||||||||||||||||||||
]) | ||||||||||||||||||||||||||||||||||||||||||||
case .none: | ||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addArrangedSubview(hintLabel) | ||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addArrangedSubview(separator) | ||||||||||||||||||||||||||||||||||||||||||||
labelStackView.addArrangedSubview(nextLabel) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
separator.heightAnchor.constraint(equalTo: labelStackView.heightAnchor, | ||||||||||||||||||||||||||||||||||||||||||||
constant: -10).isActive = true | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add the
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
func initializeAccessibilityIdentifier() { | ||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,15 +28,16 @@ public class CoachMarkHelper { | |||||
public func makeDefaultCoachViews( | ||||||
withArrow arrow: Bool = true, | ||||||
withNextText nextText: Bool = true, | ||||||
arrowOrientation: CoachMarkArrowOrientation? = .top | ||||||
arrowOrientation: CoachMarkArrowOrientation? = .top, | ||||||
nextLabelPosition: CoachMarkNextLabelPosition? = .none | ||||||
ong-yue-huei marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
) -> (bodyView: CoachMarkBodyDefaultView, arrowView: CoachMarkArrowDefaultView?) { | ||||||
|
||||||
var coachMarkBodyView: CoachMarkBodyDefaultView | ||||||
|
||||||
if nextText { | ||||||
coachMarkBodyView = CoachMarkBodyDefaultView() | ||||||
coachMarkBodyView = CoachMarkBodyDefaultView(nextLabelPosition: nextLabelPosition) | ||||||
} else { | ||||||
coachMarkBodyView = CoachMarkBodyDefaultView(hintText: "", nextText: nil) | ||||||
coachMarkBodyView = CoachMarkBodyDefaultView(hintText: "", nextText: nil, nextLabelPosition: .none) | ||||||
} | ||||||
|
||||||
var coachMarkArrowView: CoachMarkArrowDefaultView? | ||||||
|
@@ -61,9 +62,10 @@ public class CoachMarkHelper { | |||||
withArrow arrow: Bool = true, | ||||||
arrowOrientation: CoachMarkArrowOrientation? = .top, | ||||||
hintText: String, | ||||||
nextText: String? = nil | ||||||
nextText: String? = nil, | ||||||
nextLabelPosition: CoachMarkNextLabelPosition? = .none | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't need to be optional in my opinion, because there's always going to be a position.
Suggested change
|
||||||
) -> (bodyView: CoachMarkBodyDefaultView, arrowView: CoachMarkArrowDefaultView?) { | ||||||
let coachMarkBodyView = CoachMarkBodyDefaultView(hintText: hintText, nextText: nextText) | ||||||
let coachMarkBodyView = CoachMarkBodyDefaultView(hintText: hintText, nextText: nextText, nextLabelPosition: nextLabelPosition) | ||||||
|
||||||
var coachMarkArrowView: CoachMarkArrowDefaultView? | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,6 @@ | ||||||||||||||||||||||
public enum CoachMarkNextLabelPosition { | ||||||||||||||||||||||
ong-yue-huei marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
case topRight | ||||||||||||||||||||||
case topLeft | ||||||||||||||||||||||
case bottomRight | ||||||||||||||||||||||
case bottomLeft | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest using the leading/trailing terminology, so that it's direction-agnostic. Let's add leading & trailing in it as well!
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||
} |
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'd set the default position (
.trailing
) directly here.