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

Add next label position #273

Merged
merged 2 commits into from
May 25, 2022
Merged

Conversation

ong-yue-huei
Copy link
Contributor

@ong-yue-huei ong-yue-huei commented May 12, 2022

Motivation & Context

Can the "next" control be at the bottom right corner of each coach mark screen? #272

Desctiption

  • Added options to set the position of nextLabel :

    • trailing (default)
    • leading
    • topTrailing
    • topLeading
    • bottomTrailing
    • bottomLeading
  • Example:

    func coachMarksController(
        _ coachMarksController: CoachMarksController,
        coachMarkViewsAt index: Int,
        madeFrom coachMark: CoachMark
    ) -> (bodyView: UIView & CoachMarkBodyView, arrowView: (UIView & CoachMarkArrowView)?) {
        let coachViews = coachMarksController.helper.makeDefaultCoachViews(
            withArrow: true,
            arrowOrientation: coachMark.arrowOrientation,
            nextLabelPosition: .trailing // .leading .topTrailing .topLeading .bottomTrailing .bottomLeading
        )

        coachViews.bodyView.hintLabel.text = "Hello! \n\nI'm a Coach Mark!"
        coachViews.bodyView.nextLabel.text = "Ok!"

        return (bodyView: coachViews.bodyView, arrowView: coachViews.arrowView)
    }
trailing(default) leading
topTrailing topLeading bottomTrailing bottomLeading

Copy link
Owner

@ephread ephread left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @ong-yue-huei, sorry for the late response, and thank you so much for your work!

I really appreciate that you have taken the time to provide an example and screenshots.

It's looking good; I think we can replace left and right with leading and trailing and make a couple of adjustments while we're at it, but otherwise, it looks good to me. 🚀

I've added a couple of suggestions. I tried to be thorough; sorry for the 10+ comments. I hope I didn't miss anything in them, and applying them all won't result in a compilation error.

Comment on lines 2 to 5
case topRight
case topLeft
case bottomRight
case bottomLeft
Copy link
Owner

Choose a reason for hiding this comment

The 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
case topRight
case topLeft
case bottomRight
case bottomLeft
case leading
case trailing
case topTrailing
case topLeading
case bottomTrailing
case bottomLeading

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ephread! Thanks for the feedback!
The leading/trailing terminology seems good to me!
I have made some changes at 89584d2, feel free to check it out. :)

@@ -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
Copy link
Owner

Choose a reason for hiding this comment

The 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
nextLabelPosition: CoachMarkNextLabelPosition? = .none
nextLabelPosition: CoachMarkNextLabelPosition = .trailing

Comment on lines 147 to 153
case .none:
labelStackView.addArrangedSubview(hintLabel)
labelStackView.addArrangedSubview(separator)
labelStackView.addArrangedSubview(nextLabel)

separator.heightAnchor.constraint(equalTo: labelStackView.heightAnchor,
constant: -10).isActive = true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add the .leading case as well!

Suggested change
case .none:
labelStackView.addArrangedSubview(hintLabel)
labelStackView.addArrangedSubview(separator)
labelStackView.addArrangedSubview(nextLabel)
separator.heightAnchor.constraint(equalTo: labelStackView.heightAnchor,
constant: -10).isActive = true
case .trailing:
labelStackView.addArrangedSubview(hintLabel)
labelStackView.addArrangedSubview(separator)
labelStackView.addArrangedSubview(nextLabel)
separator.heightAnchor.constraint(equalTo: labelStackView.heightAnchor,
constant: -10).isActive = true
case .leading:
labelStackView.addArrangedSubview(nextLabel)
labelStackView.addArrangedSubview(separator)
labelStackView.addArrangedSubview(hintLabel)
separator.heightAnchor.constraint(equalTo: labelStackView.heightAnchor,
constant: -10).isActive = true

@@ -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?
Copy link
Owner

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.

Suggested change
private let nextLabelPosition: CoachMarkNextLabelPosition?
private let nextLabelPosition: CoachMarkNextLabelPosition = .trailing

super.init(frame: frame)
initializeViewHierarchy()
}

public init(frame: CGRect, hintText: String, nextText: String?) {
public init(frame: CGRect, hintText: String, nextText: String?, nextLabelPosition: CoachMarkNextLabelPosition?) {
Copy link
Owner

Choose a reason for hiding this comment

The 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
public init(frame: CGRect, hintText: String, nextText: String?, nextLabelPosition: CoachMarkNextLabelPosition?) {
public init(frame: CGRect, hintText: String, nextText: String?, nextLabelPosition: CoachMarkNextLabelPosition) {

- add summary for `CoachMarkNextLabelPosition`
@ong-yue-huei ong-yue-huei requested a review from ephread May 25, 2022 17:12
Copy link
Owner

@ephread ephread left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ong-yue-huei LGTM 👍

I just realised CoachMarkNextLabelPosition is not part of the Instructions target in Xcode, but that's okay; I'm going to merge this. 🎉

Thanks again for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants