Created
August 11, 2019 15:22
-
-
Save Dev1an/a0aadc5c7ad6af6c8e65a8f45a2c44b7 to your computer and use it in GitHub Desktop.
Dynamic creation of new VerticalAlignments
This file contains hidden or 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
| import SwiftUI | |
| enum Recurse<X>: AlignmentID { | |
| static func defaultValue(in context: ViewDimensions) -> CGFloat { | |
| return 0 | |
| } | |
| } | |
| extension VerticalAlignment { | |
| private static func create<A>(depth: UInt, continuation: A) -> AlignmentID.Type { | |
| if depth == 0 { return Recurse<A>.self } | |
| else { return create(depth: depth-1, continuation: Recurse<A>.self) } | |
| } | |
| static func create(depth: UInt) -> VerticalAlignment { | |
| VerticalAlignment(create(depth: depth, continuation: Self.self)) | |
| } | |
| } | |
| VerticalAlignment.create(depth: 1) == VerticalAlignment.create(depth: 0) | |
| VerticalAlignment.create(depth: 2) == VerticalAlignment.create(depth: 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment