Skip to content

Commit 2c0da7d

Browse files
committed
Use SoftUI as option
1 parent ade7a59 commit 2c0da7d

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

Example/SoftUIExample/Base.lproj/Main.storyboard

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<userDefinedRuntimeAttribute type="number" keyPath="distance">
4040
<real key="value" value="20"/>
4141
</userDefinedRuntimeAttribute>
42+
<userDefinedRuntimeAttribute type="boolean" keyPath="useSoftUI" value="YES"/>
4243
</userDefinedRuntimeAttributes>
4344
</view>
4445
</subviews>

Framework/SoftUI/Core/Shared/CALayer+SoftUI.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ typealias Holder<T> = [Int: T]
1212

1313
// swiftlint:disable identifier_name
1414
internal extension CALayer {
15+
private static var _soft_useSoftUI = Holder<Bool>()
16+
var soft_useSoftUI: Bool {
17+
set (value) {
18+
CALayer._soft_useSoftUI[self.hash] = value
19+
self.soft_update()
20+
}
21+
get {
22+
return CALayer._soft_useSoftUI[self.hash] ?? false
23+
}
24+
}
25+
1526
private static var _soft_tag = Holder<Int>()
1627
var soft_tag: Int {
1728
set (value) {
@@ -141,6 +152,8 @@ internal extension CALayer {
141152
}
142153

143154
private func soft_update() {
155+
if !self.soft_useSoftUI { return }
156+
144157
self.sublayers?.removeAll(where: { $0.soft_tag > 0 })
145158

146159
// Main layer

Framework/SoftUI/Core/Shared/UIView+SoftUI.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import UIKit
1010

1111
@IBDesignable
1212
public extension UIView {
13+
@IBInspectable
14+
var useSoftUI: Bool {
15+
set (value) {
16+
self.layer.soft_useSoftUI = value
17+
}
18+
get {
19+
return self.layer.soft_useSoftUI
20+
}
21+
}
22+
1323
@IBInspectable
1424
var cornerRadius: CGFloat {
1525
set (radius) {

0 commit comments

Comments
 (0)