sussyswiftui

Untitled

Jul 28th, 2025
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.96 KB | Source Code | 0 0
  1. struct ConditionalGlassEffect: ViewModifier {
  2. ‪    struct GlassEffectConfiguration {
  3. ‪        static let clear = GlassEffectConfiguration()
  4. ‪    }
  5. ‪    ‬
  6. ‪    let configuration: GlassEffectConfiguration‬
  7. ‪    ‬
  8. ‪    func body(content: Content) -> some View {
  9. ‪        if #available(iOS 26.0, macOS 26.0, *) {
  10. ‪            return content‬
  11. ‪                .glassEffect(.clear.interactive())
  12. ‪                .eraseToAnyView()
  13. ‪        } else {
  14. ‪            return content.eraseToAnyView()
  15. ‪        }
  16. ‪    }
  17. }
  18.  
  19. extension View {
  20. ‪    func eraseToAnyView() -> AnyView {
  21. ‪        AnyView(self)
  22. ‪    }
  23. }
  24.  
  25. extension View {
  26. ‪    func conditionalGlassEffect(_ configuration: ConditionalGlassEffect.GlassEffectConfiguration = .clear) -> some View {
  27. ‪        modifier(ConditionalGlassEffect(configuration: configuration))
  28. ‪    }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment