@@ -65,7 +65,7 @@ public final class GlassBarButtonComponent: Component {
6565 private let genericContainerView : UIView
6666 private let genericBackgroundView : SimpleGlassView
6767 private let glassContainerView : GlassBackgroundContainerView
68- private let glassBackgroundView : GlassBackgroundView
68+ private var glassBackgroundView : GlassBackgroundView ?
6969 private var componentView : ComponentView < Empty > ?
7070
7171 private var component : GlassBarButtonComponent ?
@@ -75,19 +75,16 @@ public final class GlassBarButtonComponent: Component {
7575 self . genericContainerView = UIView ( )
7676 self . genericBackgroundView = SimpleGlassView ( )
7777 self . glassContainerView = GlassBackgroundContainerView ( )
78- self . glassBackgroundView = GlassBackgroundView ( )
7978
8079 super. init ( frame: frame)
8180
82- self . glassBackgroundView. isUserInteractionEnabled = false
8381 self . containerView. isUserInteractionEnabled = false
8482
8583 self . addSubview ( self . containerView)
8684 self . containerView. addSubview ( self . genericContainerView)
8785 self . containerView. addSubview ( self . glassContainerView)
8886
8987 self . genericContainerView. addSubview ( self . genericBackgroundView)
90- self . glassContainerView. contentView. addSubview ( self . glassBackgroundView)
9188
9289 self . addTarget ( self , action: #selector( self . pressed) , for: . touchUpInside)
9390
@@ -184,8 +181,8 @@ public final class GlassBarButtonComponent: Component {
184181
185182 let cornerRadius = containerSize. height * 0.5
186183 self . genericBackgroundView. update ( size: containerSize, cornerRadius: cornerRadius, isDark: component. isDark, tintColor: . init( kind: . custom, color: component. backgroundColor) , transition: transition)
187- self . glassBackgroundView. update ( size: containerSize, cornerRadius: cornerRadius, isDark: component. isDark, tintColor: . init( kind: effectiveState == . tintedGlass ? . custom : . panel , color: component. backgroundColor. withMultipliedAlpha ( effectiveState == . tintedGlass ? 1.0 : 0.7 ) ) , transition: transition)
188184
185+
189186 let bounds = CGRect ( origin: . zero, size: containerSize)
190187 transition. setFrame ( view: self . containerView, frame: bounds)
191188
@@ -197,7 +194,29 @@ public final class GlassBarButtonComponent: Component {
197194 self . glassContainerView. update ( size: bounds. size, isDark: component. isDark, transition: transition)
198195
199196 transition. setFrame ( view: self . genericBackgroundView, frame: bounds)
200- transition. setFrame ( view: self . glassBackgroundView, frame: bounds)
197+
198+ if glassAlpha == 1.0 {
199+ let glassBackgroundView : GlassBackgroundView
200+ var glassBackgroundTransition = transition
201+ if let current = self . glassBackgroundView {
202+ glassBackgroundView = current
203+ } else {
204+ glassBackgroundTransition = . immediate
205+ glassBackgroundView = GlassBackgroundView ( )
206+ glassBackgroundView. isUserInteractionEnabled = false
207+ self . glassContainerView. contentView. addSubview ( glassBackgroundView)
208+ self . glassBackgroundView = glassBackgroundView
209+
210+ transition. animateAlpha ( view: glassBackgroundView, from: 0.0 , to: 1.0 )
211+ }
212+ glassBackgroundView. update ( size: containerSize, cornerRadius: cornerRadius, isDark: component. isDark, tintColor: . init( kind: effectiveState == . tintedGlass ? . custom : . panel , color: component. backgroundColor. withMultipliedAlpha ( effectiveState == . tintedGlass ? 1.0 : 0.7 ) ) , transition: glassBackgroundTransition)
213+ glassBackgroundTransition. setFrame ( view: glassBackgroundView, frame: bounds)
214+ } else if let glassBackgroundView = self . glassBackgroundView {
215+ self . glassBackgroundView = nil
216+ transition. setAlpha ( view: glassBackgroundView, alpha: 0.0 , completion: { _ in
217+ glassBackgroundView. removeFromSuperview ( )
218+ } )
219+ }
201220
202221 return containerSize
203222 }
0 commit comments