11import  UIKit
2+ import  SwiftUI
23
4+ @available ( iOS 13 ,  visionOS 1 ,  * )  
35public  class  AlertAppleMusic17View :  UIView ,  AlertViewProtocol  { 
46
57    open  var  dismissByTap :  Bool  =  true 
@@ -11,11 +13,15 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
1113    public  let  subtitleLabel :  UILabel ? 
1214    public  let  iconView :  UIView ? 
1315
14-     public  var  contentColor =  UIColor  {  trait in 
16+     public  static  var  defaultContentColor =  UIColor  {  trait in 
17+         #if os(visionOS) 
18+         return  . label
19+         #else 
1520        switch  trait. userInterfaceStyle { 
1621        case  . dark:  UIColor ( red:  127  /  255 ,  green:  127  /  255 ,  blue:  129  /  255 ,  alpha:  1 ) 
1722        default :  UIColor ( red:  88  /  255 ,  green:  87  /  255 ,  blue:  88  /  255 ,  alpha:  1 ) 
1823        } 
24+         #endif 
1925    } 
2026
2127    fileprivate  weak var  viewForPresent :  UIView ? 
@@ -24,20 +30,18 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
2430
2531    open  var  completion :  ( ( )  ->  Void ) ? =  nil 
2632
27-     private  lazy var  backgroundView :  UIVisualEffectView  =  { 
28-         let  view :  UIVisualEffectView  =  { 
29-             #if !os(tvOS) 
30-             if  #available( iOS 13 . 0 ,  * )  { 
31-                 return  UIVisualEffectView ( effect:  UIBlurEffect ( style:  . systemThickMaterial) ) 
32-             }  else  { 
33-                 return  UIVisualEffectView ( effect:  UIBlurEffect ( style:  . light) ) 
34-             } 
35-             #else 
36-             return  UIVisualEffectView ( effect:  UIBlurEffect ( style:  . light) ) 
37-             #endif 
38-         } ( ) 
33+     private  lazy var  backgroundView :  UIView  =  { 
34+         #if os(visionOS) 
35+         let  swiftUIView  =  VisionGlassBackgroundView ( cornerRadius:  12 ) 
36+         let  host  =  UIHostingController ( rootView:  swiftUIView) 
37+         let  hostView  =  host. view ??  UIView ( ) 
38+         hostView. isUserInteractionEnabled =  false 
39+         return  hostView
40+         #else 
41+         let  view  =  UIVisualEffectView ( effect:  UIBlurEffect ( ) ) 
3942        view. isUserInteractionEnabled =  false 
4043        return  view
44+         #endif 
4145    } ( ) 
4246
4347    public  init ( title:  String ? ,  subtitle:  String ? ,  icon:  AlertIcon ? )  { 
@@ -75,6 +79,10 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
7579            self . iconView =  nil 
7680        } 
7781
82+         self . titleLabel? . textColor =  Self . defaultContentColor
83+         self . subtitleLabel? . textColor =  Self . defaultContentColor
84+         self . iconView? . tintColor =  Self . defaultContentColor
85+         
7886        super. init ( frame:  . zero) 
7987
8088        preservesSuperviewLayoutMargins =  false 
@@ -89,6 +97,7 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
8997        if  let  subtitleLabel =  self . subtitleLabel { 
9098            addSubview ( subtitleLabel) 
9199        } 
100+         
92101        if  let  iconView =  self . iconView { 
93102            addSubview ( iconView) 
94103        } 
@@ -118,11 +127,6 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
118127    } 
119128
120129    open  func  present( on view:  UIView ,  completion:  @escaping  ( ) -> Void  =  { } )  { 
121-         
122-         self . titleLabel? . textColor =  contentColor
123-         self . subtitleLabel? . textColor =  contentColor
124-         self . iconView? . tintColor =  contentColor
125-         
126130        self . completion =  completion
127131        self . viewForPresent =  view
128132        viewForPresent? . addSubview ( self ) 
@@ -131,7 +135,12 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
131135        alpha =  0 
132136        sizeToFit ( ) 
133137        center. x =  viewForPresent. frame. midX
138+         #if os(visionOS) 
139+         frame. origin. y =  viewForPresent. safeAreaInsets. top +  24 
140+         #elseif os(iOS) 
134141        frame. origin. y =  viewForPresent. frame. height -  viewForPresent. safeAreaInsets. bottom -  frame. height -  64 
142+         #endif 
143+         
135144        transform =  transform. scaledBy ( x:  self . presentDismissScale,  y:  self . presentDismissScale) 
136145
137146        if  dismissByTap { 
@@ -258,4 +267,19 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
258267
259268        iconView? . center. y =  frame. height /  2 
260269    } 
270+     
271+     #if os(visionOS) 
272+     struct  VisionGlassBackgroundView :  View  { 
273+         
274+         let  cornerRadius :  CGFloat 
275+         
276+         var  body :  some  View  { 
277+             ZStack  { 
278+                 Color . clear
279+             } 
280+             . glassBackgroundEffect ( in:  . rect( cornerRadius:  cornerRadius) ) 
281+             . opacity ( 0.4 ) 
282+         } 
283+     } 
284+     #endif 
261285} 
0 commit comments