-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fd502e3
Showing
8 changed files
with
191 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata |
8 changes: 8 additions & 0 deletions
8
.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
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,24 @@ | ||
// swift-tools-version:5.5 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "ViewModifierBuilder", | ||
platforms: [ | ||
.iOS(.v13), | ||
.macOS(.v10_15), | ||
.tvOS(.v13), | ||
.watchOS(.v6) | ||
], | ||
products: [ | ||
.library( | ||
name: "ViewModifierBuilder", | ||
targets: ["ViewModifierBuilder"]), | ||
], | ||
targets: [ | ||
.target( | ||
name: "ViewModifierBuilder", | ||
dependencies: [], | ||
path: "Sources") | ||
] | ||
) |
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,5 @@ | ||
# ViewModifierBuilder | ||
|
||
[](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat-square) | ||
|
||
A [result builder](https://github.com/apple/swift-evolution/blob/main/proposals/0289-result-builders.md) for [ViewModifiers](https://developer.apple.com/documentation/swiftui/viewmodifier/). |
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,24 @@ | ||
# ``ViewModifierBuilder`` | ||
|
||
A custom parameter attribute that concatenates many [`ViewModifers`](https://developer.apple.com/documentation/swiftui/viewmodifier). | ||
|
||
## Topics | ||
|
||
### Applying Modifications | ||
- ``ViewModifierBuilder/ApplyViewModifiers`` | ||
|
||
### Building Modifications | ||
- ``ViewModifierBuilder/ViewModifierBuilder/buildBlock()`` | ||
- ``ViewModifierBuilder/ViewModifierBuilder/buildBlock(_:)`` | ||
- ``ViewModifierBuilder/ViewModifierBuilder/buildBlock(_:_:)`` | ||
- ``ViewModifierBuilder/ViewModifierBuilder/buildBlock(_:_:_:)`` | ||
- ``ViewModifierBuilder/ViewModifierBuilder/buildBlock(_:_:_:_:)`` | ||
- ``ViewModifierBuilder/ViewModifierBuilder/buildBlock(_:_:_:_:_:)`` | ||
- ``ViewModifierBuilder/ViewModifierBuilder/buildBlock(_:_:_:_:_:_:)`` | ||
- ``ViewModifierBuilder/ViewModifierBuilder/buildBlock(_:_:_:_:_:_:_:)`` | ||
- ``ViewModifierBuilder/ViewModifierBuilder/buildBlock(_:_:_:_:_:_:_:_:)`` | ||
- ``ViewModifierBuilder/ViewModifierBuilder/buildBlock(_:_:_:_:_:_:_:_:_:)`` | ||
- ``ViewModifierBuilder/ViewModifierBuilder/buildBlock(_:_:_:_:_:_:_:_:_:_:)`` | ||
|
||
### Supporting Types | ||
- ``ViewModifierBuilder/ViewModifierBuilder`` |
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,13 @@ | ||
import SwiftUI | ||
|
||
extension View { | ||
/// Applies a set of modifiers to a view and returns a new view. | ||
/// | ||
/// - Parameters | ||
/// - modifiers: closure returning a modifier | ||
public func modifiers<Modifiers>(@ViewModifierBuilder _ modifiers: () -> Modifiers) -> some View | ||
where Modifiers: ViewModifier { | ||
modifier(ApplyViewModifiers(modifiers)) | ||
} | ||
} | ||
|
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,92 @@ | ||
import SwiftUI | ||
|
||
/// A custom parameter attribute that concats many ViewModifers. | ||
@resultBuilder public enum ViewModifierBuilder { | ||
|
||
/// Builds an empty ViewModifer from a block containing no statements. | ||
@inlinable public static func buildBlock() -> EmptyModifier { | ||
EmptyModifier() | ||
} | ||
|
||
/// Passes a single view written as a child view through unmodified. | ||
@inlinable public static func buildBlock<Modifier>(_ modifier: Modifier) -> Modifier | ||
where Modifier: ViewModifier { | ||
modifier | ||
} | ||
|
||
@inlinable public static func buildBlock<M0, M1>(_ m0: M0, _ m1: M1) -> some ViewModifier | ||
where M0: ViewModifier, M1: ViewModifier { | ||
m0.concat(m1) | ||
} | ||
|
||
@inlinable public static func buildBlock<M0, M1, M2>(_ m0: M0, _ m1: M1, _ m2: M2) | ||
-> some ViewModifier where M0: ViewModifier, M1: ViewModifier, M2: ViewModifier | ||
{ | ||
m0.concat(m1).concat(m2) | ||
} | ||
|
||
@inlinable public static func buildBlock<M0, M1, M2, M3>(_ m0: M0, _ m1: M1, _ m2: M2, _ m3: M3) | ||
-> some ViewModifier | ||
where M0: ViewModifier, M1: ViewModifier, M2: ViewModifier, M3: ViewModifier { | ||
m0.concat(m1).concat(m2).concat(m3) | ||
} | ||
|
||
@inlinable public static func buildBlock<M0, M1, M2, M3, M4>( | ||
_ m0: M0, _ m1: M1, _ m2: M2, _ m3: M3, _ m4: M4 | ||
) -> some ViewModifier | ||
where M0: ViewModifier, M1: ViewModifier, M2: ViewModifier, M3: ViewModifier, M4: ViewModifier { | ||
m0.concat(m1).concat(m2).concat(m3).concat(m4) | ||
} | ||
|
||
@inlinable public static func buildBlock<M0, M1, M2, M3, M4, M5>( | ||
_ m0: M0, _ m1: M1, _ m2: M2, _ m3: M3, _ m4: M4, _ m5: M5 | ||
) -> some ViewModifier | ||
where | ||
M0: ViewModifier, M1: ViewModifier, M2: ViewModifier, M3: ViewModifier, M4: ViewModifier, | ||
M5: ViewModifier | ||
{ | ||
m0.concat(m1).concat(m2).concat(m3).concat(m4).concat(m5) | ||
} | ||
|
||
@inlinable public static func buildBlock<M0, M1, M2, M3, M4, M5, M6>( | ||
_ m0: M0, _ m1: M1, _ m2: M2, _ m3: M3, _ m4: M4, _ m5: M5, _ m6: M6 | ||
) -> some ViewModifier | ||
where | ||
M0: ViewModifier, M1: ViewModifier, M2: ViewModifier, M3: ViewModifier, M4: ViewModifier, | ||
M5: ViewModifier, M6: ViewModifier | ||
{ | ||
m0.concat(m1).concat(m2).concat(m3).concat(m4).concat(m5).concat(m6) | ||
} | ||
|
||
@inlinable public static func buildBlock<M0, M1, M2, M3, M4, M5, M6, M7>( | ||
_ m0: M0, _ m1: M1, _ m2: M2, _ m3: M3, _ m4: M4, _ m5: M5, _ m6: M6, _ m7: M7 | ||
) -> some ViewModifier | ||
where | ||
M0: ViewModifier, M1: ViewModifier, M2: ViewModifier, M3: ViewModifier, M4: ViewModifier, | ||
M5: ViewModifier, M6: ViewModifier, M7: ViewModifier | ||
{ | ||
m0.concat(m1).concat(m2).concat(m3).concat(m4).concat(m5).concat(m6).concat(m7) | ||
} | ||
|
||
@inlinable public static func buildBlock<M0, M1, M2, M3, M4, M5, M6, M7, M8>( | ||
_ m0: M0, _ m1: M1, _ m2: M2, _ m3: M3, _ m4: M4, _ m5: M5, _ m6: M6, _ m7: M7, _ m8: M8 | ||
) -> some ViewModifier | ||
where | ||
M0: ViewModifier, M1: ViewModifier, M2: ViewModifier, M3: ViewModifier, M4: ViewModifier, | ||
M5: ViewModifier, M6: ViewModifier, M7: ViewModifier, M8: ViewModifier | ||
{ | ||
m0.concat(m1).concat(m2).concat(m3).concat(m4).concat(m5).concat(m6).concat(m7).concat(m8) | ||
} | ||
|
||
@inlinable public static func buildBlock<M0, M1, M2, M3, M4, M5, M6, M7, M8, M9>( | ||
_ m0: M0, _ m1: M1, _ m2: M2, _ m3: M3, _ m4: M4, _ m5: M5, _ m6: M6, _ m7: M7, _ m8: M8, | ||
_ m9: M9 | ||
) -> some ViewModifier | ||
where | ||
M0: ViewModifier, M1: ViewModifier, M2: ViewModifier, M3: ViewModifier, M4: ViewModifier, | ||
M5: ViewModifier, M6: ViewModifier, M7: ViewModifier, M8: ViewModifier, M9: ViewModifier | ||
{ | ||
m0.concat(m1).concat(m2).concat(m3).concat(m4).concat(m5).concat(m6).concat(m7).concat(m8) | ||
.concat(m9) | ||
} | ||
} |
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,18 @@ | ||
import SwiftUI | ||
|
||
/// Applies set of modifiers to a view and returns a new view. | ||
public struct ApplyViewModifiers<Modifiers>: ViewModifier where Modifiers: ViewModifier { | ||
private let modifiers: Modifiers | ||
|
||
/// Structure to apply a set of modifiers to a view. | ||
/// | ||
/// - Parameters | ||
/// - modifiers: closure returning a modifier | ||
public init(@ViewModifierBuilder _ modifiers: () -> Modifiers) { | ||
self.modifiers = modifiers() | ||
} | ||
|
||
public func body(content: Content) -> some View { | ||
content.modifier(modifiers) | ||
} | ||
} |