View+InsetGroupedListStyle.swift 942 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // View+InsetGroupedListStyle.swift
  3. // LoopKitUI
  4. //
  5. // Created by Rick Pasetto on 11/25/20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. extension View {
  10. public func insetGroupedListStyle() -> some View {
  11. modifier(CustomInsetGroupedListStyle())
  12. }
  13. }
  14. fileprivate struct CustomInsetGroupedListStyle: ViewModifier, HorizontalSizeClassOverride {
  15. @ViewBuilder func body(content: Content) -> some View {
  16. // For compact sizes (e.g. iPod Touch), don't inset, in order to more efficiently utilize limited real estate
  17. if horizontalOverride == .compact {
  18. content
  19. .listStyle(GroupedListStyle())
  20. .environment(\.horizontalSizeClass, horizontalOverride)
  21. } else {
  22. content
  23. .listStyle(InsetGroupedListStyle())
  24. .environment(\.horizontalSizeClass, horizontalOverride)
  25. }
  26. }
  27. }