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

AutoLayout helper methods #15

Merged
merged 3 commits into from
Sep 2, 2021
Merged

AutoLayout helper methods #15

merged 3 commits into from
Sep 2, 2021

Conversation

mdb1
Copy link
Owner

@mdb1 mdb1 commented Aug 31, 2021

πŸ‘‹ Intro

Add a couple of lightweight classes with helper methods for programmatic AutoLayout

πŸ€” What changed?

  • Added convenience methods to add constrained views
  • Added convenience methods to pin views using constraints
  • Moved Spacing out of Constants to an enum
  • Use the new methods for everything UI related in the project
  • Added unit tests

Example

Before

stackView.translatesAutoresizingMaskIntoConstraints = false
addSubview(stackView)
NSLayoutConstraint.activate([
    stackView.topAnchor.constraint(equalTo: topAnchor),
    stackView.leadingAnchor.constraint(equalTo: leadingAnchor),
    stackView.trailingAnchor.constraint(equalTo: trailingAnchor),
    stackView.bottomAnchor.constraint(equalTo: bottomAnchor)
])

After

addSubview(stackView, insets: .none)

Using different spacings / relationships

addSubview(
    hexaLabel,
    constrainedBy: [
        .top: .medium,
        .bottom: .medium,
        .trailing: .medium
    ]
)
hexaLabel.pin(
    .leading,
    to: .trailing,
    of: nameLabel,
    relatedBy: .greaterThanOrEqual,
    constant: Spacing.large.rawValue
)

πŸ’ How to cherry-pick to another project

Check the docs on Documentation/AutoLayout.md

βœ… Checklist

  • Documentation on how to cherry-pick to another project added in Documentation/
  • README updated
  • Tests added for the new additions

πŸ“± Screenshots

iPhone 11 iPod

Coverage

Screen Shot 2021-08-31 at 19 38 07
Screen Shot 2021-08-31 at 19 38 15

@mdb1 mdb1 self-assigned this Aug 31, 2021
@mdb1 mdb1 added feature New feature tests don't merge The PR is not ready to be merged labels Aug 31, 2021
@mdb-danger-bot
Copy link

mdb-danger-bot commented Aug 31, 2021

Warnings
⚠️ PR size seems relatively large. βœ‚οΈ If this PR contains multiple changes, please split each into separate PR will helps faster, easier review.
Messages
πŸ“– πŸŽ‰ The PR added 815 and removed 69 lines. πŸ—‚ 18 files changed.

Generated by 🚫 Danger Swift against 5eaf06b

@mdb1 mdb1 force-pushed the feature/autolayout-extensions branch 7 times, most recently from d010ec7 to 04329fe Compare September 1, 2021 23:42
@mdb1 mdb1 removed the don't merge The PR is not ready to be merged label Sep 2, 2021
@mdb1 mdb1 force-pushed the feature/autolayout-extensions branch from 2b4074c to 3f4f803 Compare September 2, 2021 03:04
* Move Spacings to an enum
* Add two convenience `addSubview` methods
* Add several convenience `pin` methods
* Fix the build errors in the tests due to the change in Spacing
* Port all the UI code to use the new methods
Also Add a post action to the Test run to sort the project files
@mdb1 mdb1 force-pushed the feature/autolayout-extensions branch from 3f4f803 to 5eaf06b Compare September 2, 2021 03:08
@mdb1 mdb1 merged commit 538edf9 into main Sep 2, 2021
@mdb1 mdb1 deleted the feature/autolayout-extensions branch September 2, 2021 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants