Perf: remove unnecessary shadows and mask views
This commit is contained in:
@@ -65,6 +65,8 @@ class ReliefButton: UIButton
|
||||
backgroundView.layer.masksToBounds = true
|
||||
backgroundView.layer.borderWidth = Self.borderWidth
|
||||
backgroundView.layer.cornerCurve = .continuous
|
||||
backgroundView.layer.shouldRasterize = true
|
||||
backgroundView.layer.rasterizationScale = UIScreen.main.scale
|
||||
addSubview(backgroundView)
|
||||
|
||||
traitCollectionDidChange(nil)
|
||||
@@ -151,5 +153,8 @@ class ReliefButton: UIButton
|
||||
}
|
||||
|
||||
shadowView.frame = backgroundView.frame
|
||||
|
||||
let shadowPath = UIBezierPath(roundedRect: shadowView.bounds, cornerRadius: Self.cornerRadius)
|
||||
shadowView.layer.shadowPath = shadowPath.cgPath
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ class SegmentedReliefButton: ReliefButton
|
||||
didSet { children.forEach { addSubview($0) }; setNeedsLayout() }
|
||||
}
|
||||
|
||||
private let backgroundMaskView = UIView(frame: .zero)
|
||||
private let backgroundsContainerView = UIView(frame: .zero)
|
||||
private var childrenHighlighObservations: [NSKeyValueObservation] = []
|
||||
|
||||
@@ -22,12 +21,10 @@ class SegmentedReliefButton: ReliefButton
|
||||
super.init()
|
||||
self.children = children
|
||||
|
||||
backgroundMaskView.backgroundColor = .black
|
||||
backgroundMaskView.layer.masksToBounds = true
|
||||
backgroundMaskView.layer.cornerRadius = Self.cornerRadius - Self.borderWidth
|
||||
|
||||
backgroundsContainerView.clipsToBounds = true
|
||||
backgroundsContainerView.mask = backgroundMaskView
|
||||
backgroundsContainerView.layer.cornerRadius = Self.cornerRadius - Self.borderWidth
|
||||
|
||||
constrainedToSquare = false
|
||||
|
||||
addSubview(backgroundsContainerView)
|
||||
}
|
||||
@@ -57,10 +54,7 @@ class SegmentedReliefButton: ReliefButton
|
||||
super.layoutSubviews()
|
||||
|
||||
backgroundView.colors = [ .clear ]
|
||||
backgroundView.frame = bounds
|
||||
shadowView.frame = bounds
|
||||
|
||||
backgroundMaskView.frame = backgroundView.frame.insetBy(dx: 1.0, dy: 1.0)
|
||||
backgroundsContainerView.frame = backgroundView.frame
|
||||
|
||||
childrenHighlighObservations.removeAll()
|
||||
|
||||
Reference in New Issue
Block a user