Skip to content

Instantly share code, notes, and snippets.

@Dev1an
Created August 11, 2019 15:22
Show Gist options
  • Select an option

  • Save Dev1an/a0aadc5c7ad6af6c8e65a8f45a2c44b7 to your computer and use it in GitHub Desktop.

Select an option

Save Dev1an/a0aadc5c7ad6af6c8e65a8f45a2c44b7 to your computer and use it in GitHub Desktop.
Dynamic creation of new VerticalAlignments
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