ViewBuilder.swift.gyb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // This file was generated using gyb. Do not edit it directly. Edit
  2. // ViewBuilder.swift.gyb instead.
  3. // swiftformat:options --allow-partial-wrapping true
  4. %{
  5. maximum_view_count = 20
  6. }%
  7. /// A result builder used to compose views together into composite views in
  8. /// a declarative manner.
  9. @resultBuilder
  10. public struct ViewBuilder {
  11. public static func buildBlock() -> some View {
  12. return EmptyView()
  13. }
  14. % for i in range(maximum_view_count):
  15. %{
  16. type_parameters = ", ".join(["V%d: View" % j for j in range(i + 1)])
  17. parameters = ", ".join(["_ view%d: V%d" % (j, j) for j in range(i + 1)])
  18. return_type_parameters = ", ".join(["V%d" % j for j in range(i + 1)])
  19. return_type = "TupleView%d<\n %s\n >" % (i + 1, return_type_parameters)
  20. return_type_init_parameters = ", ".join(["view%d" % j for j in range(i + 1)])
  21. }%
  22. public static func buildBlock<
  23. ${type_parameters}
  24. >(
  25. ${parameters}
  26. ) -> ${return_type} {
  27. return ${return_type}(${return_type_init_parameters})
  28. }
  29. % end
  30. public static func buildEither<A: View, B: View>(first component: A) -> EitherView<A, B> {
  31. return EitherView(component)
  32. }
  33. public static func buildEither<A: View, B: View>(second component: B) -> EitherView<A, B> {
  34. return EitherView(component)
  35. }
  36. public static func buildIf<V: View>(_ content: V?) -> OptionalView<V> {
  37. return OptionalView(content)
  38. }
  39. }