chore: add translatesAutoresizingMaskIntoConstraints = false to all constrain method

This commit is contained in:
sunxiaojian 2021-04-01 10:38:39 +08:00
parent dff874af76
commit fde5baad2e
3 changed files with 42 additions and 30 deletions

View File

@ -97,6 +97,7 @@ extension UIView {
func pinToBottom(to: UIView, height: CGFloat) {
guard superview != nil else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
constraint(.width, toView: to),
constraint(toBottom: to, constant: 0.0),
@ -124,6 +125,7 @@ extension UIView {
func constrainTopCorners(sidePadding: CGFloat, topPadding: CGFloat, topLayoutGuide: UILayoutSupport) {
guard let view = superview else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
constraint(.leading, toView: view, constant: sidePadding),
NSLayoutConstraint(item: self, attribute: .top, relatedBy: .equal, toItem: topLayoutGuide, attribute: .bottom, multiplier: 1.0, constant: topPadding),
@ -133,6 +135,7 @@ extension UIView {
func constrainTopCorners(sidePadding: CGFloat, topPadding: CGFloat) {
guard let view = superview else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
constraint(.leading, toView: view, constant: sidePadding),
constraint(.top, toView: view, constant: topPadding),
@ -142,6 +145,7 @@ extension UIView {
func constrainTopCorners(height: CGFloat) {
guard let view = superview else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
constraint(.leading, toView: view),
constraint(.top, toView: view),
@ -152,6 +156,7 @@ extension UIView {
func constrainBottomCorners(sidePadding: CGFloat, bottomPadding: CGFloat) {
guard let view = superview else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
constraint(.leading, toView: view, constant: sidePadding),
constraint(.bottom, toView: view, constant: -bottomPadding),
@ -161,6 +166,7 @@ extension UIView {
func constrainBottomCorners(height: CGFloat) {
guard let view = superview else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
constraint(.leading, toView: view),
constraint(.bottom, toView: view),
@ -171,6 +177,7 @@ extension UIView {
func constrainLeadingCorners() {
guard let view = superview else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
constraint(.top, toView: view),
constraint(.leading, toView: view),
@ -180,6 +187,7 @@ extension UIView {
func constrainTrailingCorners() {
guard let view = superview else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
constraint(.top, toView: view),
constraint(.trailing, toView: view),
@ -189,6 +197,7 @@ extension UIView {
func constrainToCenter() {
guard let view = superview else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
constraint(.centerX, toView: view),
constraint(.centerY, toView: view)
@ -197,6 +206,7 @@ extension UIView {
func pinTo(viewAbove: UIView, padding: CGFloat = 0.0, height: CGFloat? = nil) {
guard superview != nil else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
constraint(.width, toView: viewAbove),
constraint(toBottom: viewAbove, constant: padding),
@ -207,6 +217,7 @@ extension UIView {
func pin(toSize: CGSize) {
guard superview != nil else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
widthAnchor.constraint(equalToConstant: toSize.width),
heightAnchor.constraint(equalToConstant: toSize.height)])
@ -214,6 +225,7 @@ extension UIView {
func pinTopLeft(padding: CGFloat) {
guard let view = superview else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: padding),
topAnchor.constraint(equalTo: view.topAnchor, constant: padding)])
@ -221,6 +233,7 @@ extension UIView {
func pinTopRight(padding: CGFloat) {
guard let view = superview else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
view.trailingAnchor.constraint(equalTo: trailingAnchor, constant: padding),
topAnchor.constraint(equalTo: view.topAnchor, constant: padding)])
@ -228,6 +241,7 @@ extension UIView {
func pinTopLeft(toView: UIView, topPadding: CGFloat) {
guard superview != nil else { assert(false, "Superview cannot be nil when adding contraints"); return }
translatesAutoresizingMaskIntoConstraints = false
constrain([
leadingAnchor.constraint(equalTo: toView.leadingAnchor),
topAnchor.constraint(equalTo: toView.bottomAnchor, constant: topPadding)])

View File

@ -8,26 +8,25 @@
import Combine
import Foundation
/// Follow suggestions
///
/// Server-generated suggestions on who to follow, based on previous positive interactions.
///
/// Version history:
/// 2.4.3 - added
/// # Reference
/// [Document](https://docs.joinmastodon.org/methods/accounts/suggestions/)
/// - Parameters:
/// - session: `URLSession`
/// - domain: Mastodon instance domain. e.g. "example.com"
/// - query: query
/// - authorization: User token.
/// - Returns: `AnyPublisher` contains `Accounts` nested in the response
extension Mastodon.API.Suggestions {
static func suggestionsURL(domain: String) -> URL {
Mastodon.API.endpointURL(domain: domain).appendingPathComponent("api/v1/suggestions")
}
/// Follow suggestions
///
/// Server-generated suggestions on who to follow, based on previous positive interactions.
///
/// Version history:
/// 2.4.3 - added
/// # Reference
/// [Document](https://docs.joinmastodon.org/methods/accounts/suggestions/)
/// - Parameters:
/// - session: `URLSession`
/// - domain: Mastodon instance domain. e.g. "example.com"
/// - query: query
/// - authorization: User token.
/// - Returns: `AnyPublisher` contains `Accounts` nested in the response
public static func get(
session: URLSession,
domain: String,

View File

@ -8,26 +8,25 @@
import Combine
import Foundation
/// Trending tags
///
/// Tags that are being used more frequently within the past week.
///
/// Version history:
/// 3.0.0 - added
/// # Reference
/// [Document](https://docs.joinmastodon.org/methods/instance/trends/)
/// - Parameters:
/// - session: `URLSession`
/// - domain: Mastodon instance domain. e.g. "example.com"
/// - query: query
/// - authorization: User token.
/// - Returns: `AnyPublisher` contains `Hashtags` nested in the response
extension Mastodon.API.Trends {
static func trendsURL(domain: String) -> URL {
Mastodon.API.endpointURL(domain: domain).appendingPathComponent("api/v1/trends")
}
/// Trending tags
///
/// Tags that are being used more frequently within the past week.
///
/// Version history:
/// 3.0.0 - added
/// # Reference
/// [Document](https://docs.joinmastodon.org/methods/instance/trends/)
/// - Parameters:
/// - session: `URLSession`
/// - domain: Mastodon instance domain. e.g. "example.com"
/// - query: query
/// - Returns: `AnyPublisher` contains `Hashtags` nested in the response
public static func get(
session: URLSession,
domain: String,