-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update organization of code in files
- Loading branch information
Showing
6 changed files
with
83 additions
and
147 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ disabled_rules: | |
- type_name | ||
- line_length | ||
- identifier_name | ||
- trailing_comma | ||
opt_in_rules: |
74 changes: 0 additions & 74 deletions
74
Sources/UIViewKit/UIViewDSL/AutoresizingStrategy/InferredConstraintsStrategy.swift
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
.../UIViewDSLEngineConstraintsProtocol.swift → ...UIViewDSL+EngineConstraintsProtocol.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
2 changes: 1 addition & 1 deletion
2
...egy/InferredAttributesOwnerStrategy.swift → ...DSL+InferredAttributesOwnerStrategy.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
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,78 @@ | ||
// | ||
// UIViewDSL+Engine.swift | ||
// | ||
// | ||
// Created by MaxAir on 21/11/2023. | ||
// | ||
|
||
import UIKit | ||
|
||
@MainActor | ||
public class UIViewDSLEngine { | ||
|
||
// MARK: - Public Properties | ||
|
||
public weak var delegate: UIViewDSLEngineConstraintsProtocol? | ||
|
||
// MARK: - Private Properties | ||
|
||
private var ibSubviewsDepthCallCounter: Int = 0 | ||
private var defaultDelegate: UIViewDSLEngineConstraintsProtocol? | ||
|
||
// MARK: - Singleton Instance | ||
|
||
public static let shared: UIViewDSLEngine = { | ||
let instance = UIViewDSLEngine() | ||
instance.setupDefaultDelegate() | ||
return instance | ||
}() | ||
|
||
// MARK: - Initializers | ||
|
||
private init() { } | ||
|
||
// MARK: - Public Methods | ||
|
||
func addSubviews(_ subviews: (UIView) -> [UIView], to owner: UIView) { | ||
beginSubviewsDefinition() | ||
UIViewDSLHelper.addSubviews(subviews(owner), to: owner) | ||
endSubviewsDefinition(on: owner) | ||
} | ||
|
||
func addSubviews(_ subviews: () -> [UIView], to owner: UIView) { | ||
beginSubviewsDefinition() | ||
UIViewDSLHelper.addSubviews(subviews(), to: owner) | ||
endSubviewsDefinition(on: owner) | ||
} | ||
|
||
func addConstraints(for owner: UIView, constraints: [NSLayoutConstraint]) { | ||
delegate?.addConstraints(for: owner, constraints: constraints) | ||
if ibSubviewsDepthCallCounter == 0 { | ||
delegate?.ibAttributesDidExecute(on: owner) | ||
} | ||
} | ||
|
||
#if DEBUG | ||
var constraintsToApplyForDebug: [(UIView, [NSLayoutConstraint])] { | ||
delegate!.constraintsToApplyForDebug | ||
} | ||
#endif | ||
|
||
// MARK: - Private Methods | ||
|
||
private func setupDefaultDelegate() { | ||
defaultDelegate = InferredAttributesOwnerStrategy() | ||
delegate = defaultDelegate | ||
} | ||
|
||
private func beginSubviewsDefinition() { | ||
ibSubviewsDepthCallCounter += 1 | ||
} | ||
|
||
private func endSubviewsDefinition(on owner: UIView) { | ||
ibSubviewsDepthCallCounter -= 1 | ||
if ibSubviewsDepthCallCounter == 0 { | ||
delegate?.ibSubviewsDidExecute(on: owner) | ||
} | ||
} | ||
} |
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