MCPcopy Create free account
hub / github.com/Effect-TS/effect / EffectUIProgressView

Class EffectUIProgressView

packages/ui/native/apple/EffectUIProgress.swift:11–152  ·  view source on GitHub ↗

A determinate progress indicator from 0 to 1: a bar (`NSProgressIndicator` or `UIProgressView`), or a ring around a pie that fills clockwise from 12 o'clock. Clicks and touches pass through to the element. `tintColor` colours the circle and the iOS bar; AppKit has no tint for `NSProgressIndicator`.

Source from the content-addressed store, hash-verified

9/// o'clock. Clicks and touches pass through to the element. `tintColor` colours
10/// the circle and the iOS bar; AppKit has no tint for `NSProgressIndicator`.
11final class EffectUIProgressView: EffectUIPlatformView, EffectUIHostedView {
12 #if os(macOS)
13 private let bar = NSProgressIndicator()
14 #else
15 private let bar = UIProgressView(progressViewStyle: .default)
16 #endif
17 private let ring = CAShapeLayer()
18 private let pie = CAShapeLayer()
19 private var value: CGFloat = 0
20 private var tint: KitColor?
21 private var circle = false
22
23 init() {
24 super.init(frame: .zero)
25 #if os(macOS)
26 wantsLayer = true
27 bar.style = .bar
28 bar.isIndeterminate = false
29 bar.minValue = 0
30 bar.maxValue = 1
31 setAccessibilityElement(true)
32 setAccessibilityRole(.progressIndicator)
33 layer?.addSublayer(ring)
34 layer?.addSublayer(pie)
35 #else
36 bar.autoresizingMask = [.flexibleWidth]
37 layer.addSublayer(ring)
38 layer.addSublayer(pie)
39 isUserInteractionEnabled = false
40 isAccessibilityElement = true
41 accessibilityTraits = .updatesFrequently
42 #endif
43 ring.fillColor = nil
44 addSubview(bar)
45 apply()
46 }
47
48 @available(*, unavailable)
49 required init?(coder: NSCoder) {
50 nil
51 }
52
53 func update(_ changed: [String: Any]) {
54 if changed.keys.contains("value") { value = min(max(kitNumber(changed["value"]) ?? 0, 0), 1) }
55 if changed.keys.contains("tintColor") { tint = changed["tintColor"] as? KitColor }
56 if changed.keys.contains("shape") { circle = changed["shape"] as? String == "circle" }
57 apply()
58 }
59
60 override var intrinsicContentSize: CGSize {
61 #if os(macOS)
62 let side: CGFloat = 16
63 #else
64 let side: CGFloat = 20
65 #endif
66 return circle ? CGSize(width: side, height: side) : CGSize(width: -1, height: bar.intrinsicContentSize.height)
67 }
68

Callers 1

registerViewsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected