View+InsetGroupedListStyle.swift 934 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. // NOTE: In iOS 13, the InsetGroupedListStyle is "hacked" by using "GroupedListStyle" with a horizontal size class override.
  10. extension View {
  11. public func insetGroupedListStyle() -> some View {
  12. modifier(CustomInsetGroupedListStyle())
  13. }
  14. }
  15. fileprivate struct CustomInsetGroupedListStyle: ViewModifier, HorizontalSizeClassOverride {
  16. @ViewBuilder func body(content: Content) -> some View {
  17. if #available(iOSApplicationExtension 14.0, *) {
  18. content
  19. .listStyle(InsetGroupedListStyle())
  20. } else {
  21. // Fallback on earlier versions
  22. content
  23. .listStyle(GroupedListStyle())
  24. .environment(\.horizontalSizeClass, horizontalOverride)
  25. }
  26. }
  27. }