nitro-ui-macos 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +56 -0
- package/LICENSE +3 -3
- package/PARITY.md +373 -0
- package/README.md +144 -5
- package/native/nitro-core/Package.swift +78 -0
- package/native/nitro-ui-core/Package.swift +112 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/AnimationFrameDisplayLink.swift +127 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridAnimationFrameScheduler.swift +91 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridLinking.swift +18 -0
- package/native/nitro-ui-dev/Package.swift +102 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoad.swift +14 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoader.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevLauncher.swift +192 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevMenu.swift +172 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevServerBrowser.swift +86 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevSession.swift +151 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevShortcuts.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevToast.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevTools.swift +141 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorModels.swift +97 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorOverlay.swift +698 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevBundles.swift +64 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevErrors.swift +56 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevLoadingView.swift +27 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevMenu.swift +40 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevToast.swift +19 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/LauncherWindowController.swift +217 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/LoadingOverlay.swift +104 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/RegisterDevLoader.swift +22 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/SavedBundles.swift +70 -0
- package/native/nitro-ui-glass/Package.swift +103 -0
- package/native/nitro-ui-glass/macos/HybridLiquidGlass.swift +5 -0
- package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassContainerView.swift +40 -0
- package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassView.swift +80 -0
- package/native/nitro-ui-glass/macos/LiquidGlassEffectView.swift +181 -0
- package/native/nitro-ui-glass/macos/LiquidGlassSupport.swift +17 -0
- package/native/nitro-ui-navigation/Package.swift +105 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationScreen.swift +199 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSharedElement.swift +17 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSplit.swift +889 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationStack.swift +404 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationTabs.swift +186 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/MacStackContainerController.swift +260 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/NavigationSharedElementView.swift +28 -0
- package/native/nitro-ui-renderer/Package.swift +105 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/HybridAnimator.swift +502 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/NitroAnimationContext.swift +54 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/View+Animations.swift +35 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/AssetFonts.swift +36 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/FlippedView.swift +360 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridContainerView.swift +28 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridFonts.swift +7 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridLabel.swift +127 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridMaskedView.swift +185 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollView.swift +255 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollViewContent.swift +22 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridView.swift +18 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImage.swift +281 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageFactory.swift +132 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageLoader.swift +149 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageView.swift +601 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/ImagePixelSupport.swift +418 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/LabelView.swift +198 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/HybridListView.swift +177 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListCell.swift +98 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListContentView.swift +12 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListFenwickTree.swift +94 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListScrollView.swift +1100 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListSnapshot.swift +24 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListUpdate.swift +11 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListView.swift +260 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NativeContainerView.swift +443 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NitroViewProtocols.swift +275 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/ShadowLayers.swift +338 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/HybridTextInput.swift +252 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/NitroTextInputView.swift +447 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/View.swift +660 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/CustomViewController.swift +254 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/DesktopHostDelegate.swift +14 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Extensions.swift +102 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/GestureRecognizerDelegate.swift +24 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridGestureRecognizer.swift +41 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridLongPressGestureRecognizer.swift +172 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridPanGestureRecognizer.swift +193 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridTapGestureRecognizer.swift +165 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridAppearance.swift +75 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridApplication.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridKeyboard.swift +26 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridScreen.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridViewController.swift +232 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindow.swift +61 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindowScene.swift +17 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/LayoutNode.swift +73 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/NSColor+rgba.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RegisterRootCallback.swift +27 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RuntimeReloadableAppDelegate.swift +7 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SafeAreaInsetsListeners.swift +26 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SizeListeners.swift +27 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/UIErrorHandler.swift +15 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/ViewController.swift +6 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Window.swift +156 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/WindowScene.swift +23 -0
- package/native/nitro-ui-runtime/Package.swift +67 -0
- package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/DevLoader.swift +16 -0
- package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/NitroUIAppDelegate.swift +253 -0
- package/package.json +57 -8
- package/src/Platform.ts +43 -0
- package/src/bin.js +18 -0
- package/src/build.ts +453 -0
- package/src/bundleWorker.ts +80 -0
- package/src/cli.ts +157 -0
- package/src/config.ts +233 -0
- package/src/create.ts +67 -0
- package/src/files.ts +70 -0
- package/src/index.ts +1 -0
- package/src/init.ts +301 -0
- package/src/inlinePlatform.ts +140 -0
- package/src/modules.ts +385 -0
- package/src/packageApp.ts +103 -0
- package/src/packageDirectory.ts +61 -0
- package/src/preload.ts +40 -0
- package/src/prepare.ts +433 -0
- package/src/run.ts +41 -0
- package/src/runApp.ts +81 -0
- package/src/start.ts +152 -0
- package/src/toolchain.ts +83 -0
- package/src/versions.ts +103 -0
- package/templates/AppIcon.icns +0 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
public import AppKit
|
|
2
|
+
internal import QuartzCore
|
|
3
|
+
|
|
4
|
+
open class FlippedView: NSView, InteractionControllableView, TransformableView {
|
|
5
|
+
public var isUserInteractionEnabled: Bool = true
|
|
6
|
+
public var nitroTransform = NitroTransformState()
|
|
7
|
+
public var nitroAccessibilityLabel: String?
|
|
8
|
+
public var nitroAccessibilityRole: NSAccessibility.Role?
|
|
9
|
+
var onFrameSizeChanged: ((CGSize) -> Void)?
|
|
10
|
+
|
|
11
|
+
/// The fill of this view's own layer. Subclasses with shadows override `nitroBackgroundColor`
|
|
12
|
+
/// to return the fill of their content view instead.
|
|
13
|
+
private var layerBackgroundColor: NSColor?
|
|
14
|
+
|
|
15
|
+
var nitroBackgroundColor: NSColor? {
|
|
16
|
+
didSet {
|
|
17
|
+
layerBackgroundColor = nitroBackgroundColor
|
|
18
|
+
effectiveAppearance.performAsCurrentDrawingAppearance {
|
|
19
|
+
NitroAnimationContext.performWithoutImplicitAnimations {
|
|
20
|
+
self.ensureLayer().backgroundColor = self.nitroBackgroundColor?.cgColor
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public func setSystemBackgroundColor(_ color: NSColor?) {
|
|
27
|
+
nitroBackgroundColor = color
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var nitroBorderColor: NSColor? {
|
|
31
|
+
didSet {
|
|
32
|
+
NitroAnimationContext.performWithoutImplicitAnimations {
|
|
33
|
+
self.ensureLayer().borderColor = self.nitroBorderColor?.cgColor
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public override init(frame frameRect: NSRect) {
|
|
39
|
+
super.init(frame: frameRect)
|
|
40
|
+
wantsLayer = true
|
|
41
|
+
_ = ensureLayer()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@available(*, unavailable)
|
|
45
|
+
public required init?(coder: NSCoder) {
|
|
46
|
+
fatalError("init(coder:) has not been implemented")
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public override var isFlipped: Bool { true }
|
|
50
|
+
|
|
51
|
+
public override func acceptsFirstMouse(for event: NSEvent?) -> Bool {
|
|
52
|
+
return isUserInteractionEnabled
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
open override func setFrameOrigin(_ newOrigin: NSPoint) {
|
|
56
|
+
super.setFrameOrigin(newOrigin)
|
|
57
|
+
applyNitroTransform()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
open override func setFrameSize(_ newSize: NSSize) {
|
|
61
|
+
super.setFrameSize(newSize)
|
|
62
|
+
applyNitroTransform()
|
|
63
|
+
onFrameSizeChanged?(newSize)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
open override func layout() {
|
|
67
|
+
super.layout()
|
|
68
|
+
applyNitroTransform()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public override func viewDidMoveToSuperview() {
|
|
72
|
+
super.viewDidMoveToSuperview()
|
|
73
|
+
applyNitroTransform()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
open override func viewDidMoveToWindow() {
|
|
77
|
+
super.viewDidMoveToWindow()
|
|
78
|
+
applyNitroTransform()
|
|
79
|
+
refreshLayerColors()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public override func viewWillDraw() {
|
|
83
|
+
super.viewWillDraw()
|
|
84
|
+
applyNitroTransform()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public func applyNitroTransform() {
|
|
88
|
+
let layer = ensureLayer()
|
|
89
|
+
let target = nitroTransform.makeCATransform3D(for: bounds.size)
|
|
90
|
+
if NitroAnimationContext.isAnimating, let session = NitroAnimationContext.activeSession {
|
|
91
|
+
let fromValue = session.currentPresentedValue(
|
|
92
|
+
for: layer,
|
|
93
|
+
keyPath: "transform",
|
|
94
|
+
fallback: { NSValue(caTransform3D: layer.transform) }
|
|
95
|
+
)
|
|
96
|
+
NitroAnimationContext.performApplyingModel {
|
|
97
|
+
layer.transform = target
|
|
98
|
+
}
|
|
99
|
+
session.recordLayerChange(
|
|
100
|
+
layer: layer,
|
|
101
|
+
keyPath: "transform",
|
|
102
|
+
fromValue: fromValue,
|
|
103
|
+
readToValue: { [weak layer] in NSValue(caTransform3D: layer?.transform ?? target) },
|
|
104
|
+
syncModel: { [weak self, weak layer] value in
|
|
105
|
+
guard let self, let layer, let nsValue = value as? NSValue else { return }
|
|
106
|
+
let matrix = nsValue.caTransform3DValue
|
|
107
|
+
self.nitroTransform = NitroTransformState.from(
|
|
108
|
+
caTransform3D: matrix,
|
|
109
|
+
size: self.bounds.size,
|
|
110
|
+
previous: self.nitroTransform
|
|
111
|
+
)
|
|
112
|
+
layer.transform = matrix
|
|
113
|
+
}
|
|
114
|
+
)
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
if !NitroAnimationRegistry.hasActiveAnimation(on: layer, keyPath: "transform"),
|
|
118
|
+
CATransform3DEqualToTransform(layer.transform, target) {
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
NitroAnimationContext.performWithoutImplicitAnimations {
|
|
122
|
+
layer.transform = target
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
public override func hitTest(_ point: NSPoint) -> NSView? {
|
|
127
|
+
return NitroViewGeometry.hitTest(
|
|
128
|
+
self,
|
|
129
|
+
point: point,
|
|
130
|
+
isUserInteractionEnabled: isUserInteractionEnabled
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public override func viewDidChangeEffectiveAppearance() {
|
|
135
|
+
super.viewDidChangeEffectiveAppearance()
|
|
136
|
+
refreshLayerColors()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private func refreshLayerColors() {
|
|
140
|
+
effectiveAppearance.performAsCurrentDrawingAppearance {
|
|
141
|
+
NitroAnimationContext.performWithoutImplicitAnimations {
|
|
142
|
+
self.layer?.backgroundColor = self.layerBackgroundColor?.cgColor
|
|
143
|
+
self.layer?.borderColor = self.nitroBorderColor?.cgColor
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@discardableResult
|
|
149
|
+
func ensureLayer() -> CALayer {
|
|
150
|
+
if !wantsLayer {
|
|
151
|
+
wantsLayer = true
|
|
152
|
+
}
|
|
153
|
+
if let existing = layer {
|
|
154
|
+
return existing
|
|
155
|
+
}
|
|
156
|
+
let created = makeBackingLayer()
|
|
157
|
+
layer = created
|
|
158
|
+
return created
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public override var acceptsFirstResponder: Bool {
|
|
162
|
+
guard isKeyboardFocusablePressable else { return false }
|
|
163
|
+
// Like NSButton, a click presses without taking focus away from a text input.
|
|
164
|
+
switch NSApp.currentEvent?.type {
|
|
165
|
+
case .leftMouseDown, .rightMouseDown, .otherMouseDown: return false
|
|
166
|
+
default: return true
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public override var canBecomeKeyView: Bool {
|
|
171
|
+
return isKeyboardFocusablePressable
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public override var focusRingMaskBounds: NSRect {
|
|
175
|
+
return isKeyboardFocusablePressable ? bounds : .zero
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
public override func drawFocusRingMask() {
|
|
179
|
+
guard isKeyboardFocusablePressable else { return }
|
|
180
|
+
let radius = layer?.cornerRadius ?? 0
|
|
181
|
+
if radius > 0 {
|
|
182
|
+
NSBezierPath(roundedRect: bounds, xRadius: radius, yRadius: radius).fill()
|
|
183
|
+
} else {
|
|
184
|
+
bounds.fill()
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public override func keyDown(with event: NSEvent) {
|
|
189
|
+
let flags = event.modifierFlags.intersection([.command, .option, .control, .shift])
|
|
190
|
+
if event.keyCode == 48 || event.charactersIgnoringModifiers == "\t" {
|
|
191
|
+
let forward = !flags.contains(.shift)
|
|
192
|
+
if NitroKeyboardFocusRing.moveFocus(from: self, forward: forward, includePressables: true) {
|
|
193
|
+
return
|
|
194
|
+
}
|
|
195
|
+
} else if isKeyboardFocusablePressable,
|
|
196
|
+
flags.isEmpty,
|
|
197
|
+
let chars = event.charactersIgnoringModifiers,
|
|
198
|
+
chars == " " || chars == "\r" || chars == "\u{03}" {
|
|
199
|
+
if accessibilityPerformPress() {
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
super.keyDown(with: event)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
public override func insertTab(_ sender: Any?) {
|
|
207
|
+
if !NitroKeyboardFocusRing.moveFocus(from: self, forward: true, includePressables: true) {
|
|
208
|
+
super.insertTab(sender)
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
public override func insertBacktab(_ sender: Any?) {
|
|
213
|
+
if !NitroKeyboardFocusRing.moveFocus(from: self, forward: false, includePressables: true) {
|
|
214
|
+
super.insertBacktab(sender)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// MARK: - Accessibility
|
|
219
|
+
|
|
220
|
+
var isKeyboardFocusablePressable: Bool {
|
|
221
|
+
guard !isHidden, alphaValue > 0.01, isUserInteractionEnabled else { return false }
|
|
222
|
+
if self is LabelView || self is NitroTextInputHostView { return false }
|
|
223
|
+
return activeTapRecognizer != nil
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private var activeTapRecognizer: NitroTapGestureRecognizer? {
|
|
227
|
+
for recognizer in gestureRecognizers {
|
|
228
|
+
if let tap = recognizer as? NitroTapGestureRecognizer,
|
|
229
|
+
tap.isEnabled,
|
|
230
|
+
tap.numberOfTouchesRequired <= 1 {
|
|
231
|
+
return tap
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return nil
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private static func collectAccessibleText(in view: NSView, into parts: inout [String]) {
|
|
238
|
+
if view.isHidden || view.alphaValue <= 0.01 {
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
if let label = view as? LabelView {
|
|
242
|
+
if let text = label.text?.trimmingCharacters(in: .whitespacesAndNewlines), !text.isEmpty {
|
|
243
|
+
parts.append(text)
|
|
244
|
+
}
|
|
245
|
+
return
|
|
246
|
+
}
|
|
247
|
+
for subview in view.subviews {
|
|
248
|
+
collectAccessibleText(in: subview, into: &parts)
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
open override func isAccessibilityElement() -> Bool {
|
|
253
|
+
if isHidden {
|
|
254
|
+
return false
|
|
255
|
+
}
|
|
256
|
+
if nitroAccessibilityRole != nil || nitroAccessibilityLabel != nil {
|
|
257
|
+
return true
|
|
258
|
+
}
|
|
259
|
+
if activeTapRecognizer != nil && isUserInteractionEnabled {
|
|
260
|
+
return true
|
|
261
|
+
}
|
|
262
|
+
return super.isAccessibilityElement()
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
open override func accessibilityRole() -> NSAccessibility.Role? {
|
|
266
|
+
if let nitroAccessibilityRole {
|
|
267
|
+
return nitroAccessibilityRole
|
|
268
|
+
}
|
|
269
|
+
if activeTapRecognizer != nil && isUserInteractionEnabled {
|
|
270
|
+
return .button
|
|
271
|
+
}
|
|
272
|
+
return super.accessibilityRole()
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
open override func accessibilityLabel() -> String? {
|
|
276
|
+
if let nitroAccessibilityLabel {
|
|
277
|
+
return nitroAccessibilityLabel
|
|
278
|
+
}
|
|
279
|
+
if activeTapRecognizer != nil {
|
|
280
|
+
var parts: [String] = []
|
|
281
|
+
Self.collectAccessibleText(in: self, into: &parts)
|
|
282
|
+
if !parts.isEmpty {
|
|
283
|
+
return parts.joined(separator: " ")
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return super.accessibilityLabel()
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
open override func accessibilityPerformPress() -> Bool {
|
|
290
|
+
guard !isHidden, isUserInteractionEnabled, let tap = activeTapRecognizer else {
|
|
291
|
+
return super.accessibilityPerformPress()
|
|
292
|
+
}
|
|
293
|
+
return tap.accessibilityPressHandler?() ?? false
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/// Shared macOS Tab / Shift-Tab keyboard focus ring across Nitro text inputs, pressables, and native controls.
|
|
298
|
+
@MainActor
|
|
299
|
+
enum NitroKeyboardFocusRing {
|
|
300
|
+
static func focusableViews(in root: NSView, includePressables: Bool) -> [NSView] {
|
|
301
|
+
var result: [NSView] = []
|
|
302
|
+
collectFocusableViews(in: root, includePressables: includePressables, into: &result)
|
|
303
|
+
return result
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
@discardableResult
|
|
307
|
+
static func moveFocus(from current: NSView, forward: Bool, includePressables: Bool) -> Bool {
|
|
308
|
+
guard let window = current.window, let contentView = window.contentView else { return false }
|
|
309
|
+
let items = focusableViews(in: contentView, includePressables: includePressables)
|
|
310
|
+
guard items.count > 1, let index = items.firstIndex(where: { $0 === current }) else {
|
|
311
|
+
return false
|
|
312
|
+
}
|
|
313
|
+
let nextIndex = forward
|
|
314
|
+
? (index + 1) % items.count
|
|
315
|
+
: (index - 1 + items.count) % items.count
|
|
316
|
+
return window.makeFirstResponder(items[nextIndex])
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
@discardableResult
|
|
320
|
+
static func focusFirst(in window: NSWindow, forward: Bool) -> Bool {
|
|
321
|
+
guard let contentView = window.contentView else { return false }
|
|
322
|
+
let includePressables = NSApp.isFullKeyboardAccessEnabled
|
|
323
|
+
var items = focusableViews(in: contentView, includePressables: includePressables)
|
|
324
|
+
if items.isEmpty && !includePressables {
|
|
325
|
+
items = focusableViews(in: contentView, includePressables: true)
|
|
326
|
+
}
|
|
327
|
+
guard let target = forward ? items.first : items.last else { return false }
|
|
328
|
+
return window.makeFirstResponder(target)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
private static func collectFocusableViews(
|
|
332
|
+
in view: NSView,
|
|
333
|
+
includePressables: Bool,
|
|
334
|
+
into result: inout [NSView]
|
|
335
|
+
) {
|
|
336
|
+
if view.isHidden || view.alphaValue <= 0.01 {
|
|
337
|
+
return
|
|
338
|
+
}
|
|
339
|
+
if let controllable = view as? any InteractionControllableView, !controllable.isUserInteractionEnabled {
|
|
340
|
+
return
|
|
341
|
+
}
|
|
342
|
+
if let editor = view as? NitroTextEditorView, editor.isEditable {
|
|
343
|
+
result.append(editor)
|
|
344
|
+
return
|
|
345
|
+
}
|
|
346
|
+
if includePressables {
|
|
347
|
+
if let flipped = view as? FlippedView, flipped.isKeyboardFocusablePressable {
|
|
348
|
+
result.append(flipped)
|
|
349
|
+
return
|
|
350
|
+
}
|
|
351
|
+
if let control = view as? NSControl, control.isEnabled, control.canBecomeKeyView {
|
|
352
|
+
result.append(control)
|
|
353
|
+
return
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
for subview in view.subviews {
|
|
357
|
+
collectFocusableViews(in: subview, includePressables: includePressables, into: &result)
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridContainerView.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
internal import AppKit
|
|
2
|
+
internal import NitroModules
|
|
3
|
+
|
|
4
|
+
final class HybridContainerView: HybridContainerViewSpec {
|
|
5
|
+
typealias AllowedChildrenType = any View
|
|
6
|
+
|
|
7
|
+
let view = NativeContainerView()
|
|
8
|
+
let layoutNode = LayoutNode()
|
|
9
|
+
var parentReference: (any HybridViewSpec)?
|
|
10
|
+
var gestureRecognizers: [any HybridGestureRecognizerSpec] = []
|
|
11
|
+
|
|
12
|
+
var cornerRadius: Double {
|
|
13
|
+
get { Double(view.requestedCornerRadius) }
|
|
14
|
+
set { view.setRequestedCornerRadius(CGFloat(newValue)) }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
override init() throws {
|
|
18
|
+
try super.init()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func setBackgroundGradient(gradient: LinearGradientOptions) throws {
|
|
22
|
+
try view.setBackgroundGradient(gradient)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func setBoxShadows(shadows: [BoxShadowOptions]) throws {
|
|
26
|
+
try view.setBoxShadows(shadows)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
internal import AppKit
|
|
2
|
+
internal import Foundation
|
|
3
|
+
internal import NitroLayout
|
|
4
|
+
internal import NitroModules
|
|
5
|
+
|
|
6
|
+
final class HybridLabel: HybridLabelSpec {
|
|
7
|
+
typealias AllowedChildrenType = Never
|
|
8
|
+
|
|
9
|
+
let view: LabelView
|
|
10
|
+
let layoutNode: LayoutNode
|
|
11
|
+
var parentReference: (any HybridViewSpec)?
|
|
12
|
+
var gestureRecognizers: [any HybridGestureRecognizerSpec] = []
|
|
13
|
+
|
|
14
|
+
override init() throws {
|
|
15
|
+
let label = LabelView()
|
|
16
|
+
view = label
|
|
17
|
+
|
|
18
|
+
layoutNode = LayoutNode(measure: { width, widthMode, height, heightMode in
|
|
19
|
+
let availableWidth = widthMode == NLMeasureUndefined
|
|
20
|
+
? CGFloat.greatestFiniteMagnitude
|
|
21
|
+
: CGFloat(width)
|
|
22
|
+
let availableHeight = heightMode == NLMeasureUndefined
|
|
23
|
+
? CGFloat.greatestFiniteMagnitude
|
|
24
|
+
: CGFloat(height)
|
|
25
|
+
let availableSize = CGSize(width: availableWidth, height: availableHeight)
|
|
26
|
+
let measuredSize = label.sizeThatFits(availableSize)
|
|
27
|
+
var measuredWidth = Float(measuredSize.width)
|
|
28
|
+
var measuredHeight = Float(measuredSize.height)
|
|
29
|
+
|
|
30
|
+
if widthMode == NLMeasureExactly {
|
|
31
|
+
measuredWidth = width
|
|
32
|
+
} else if widthMode == NLMeasureAtMost {
|
|
33
|
+
measuredWidth = min(measuredWidth, width)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if heightMode == NLMeasureExactly {
|
|
37
|
+
measuredHeight = height
|
|
38
|
+
} else if heightMode == NLMeasureAtMost {
|
|
39
|
+
measuredHeight = min(measuredHeight, height)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return NLSize(width: measuredWidth, height: measuredHeight)
|
|
43
|
+
})
|
|
44
|
+
try super.init()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
func setFrame(frame: Frame) throws {
|
|
48
|
+
view.contentInsets = layoutNode.contentInsets
|
|
49
|
+
applyAnimatedFrame(NSRect(x: frame.x, y: frame.y, width: frame.width, height: frame.height))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private var needsTextUpdate = true
|
|
53
|
+
|
|
54
|
+
var text: String? {
|
|
55
|
+
get { view.text }
|
|
56
|
+
set {
|
|
57
|
+
guard view.text != newValue else { return }
|
|
58
|
+
view.text = newValue
|
|
59
|
+
needsTextUpdate = true
|
|
60
|
+
NLMarkDirty(layoutNode.ref)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var color: Double = 0x000000ff { didSet { needsTextUpdate = true } }
|
|
65
|
+
var fontSize: Double = 17 { didSet { needsTextUpdate = true } }
|
|
66
|
+
var fontWeight: FontWeight = .regular { didSet { needsTextUpdate = true } }
|
|
67
|
+
var font: String? { didSet { needsTextUpdate = true } }
|
|
68
|
+
var lineHeight: Double? { didSet { needsTextUpdate = true } }
|
|
69
|
+
var textAlign: TextAlignment? {
|
|
70
|
+
get { view.paragraphAlignment }
|
|
71
|
+
set {
|
|
72
|
+
view.paragraphAlignment = newValue
|
|
73
|
+
needsTextUpdate = true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
var numberOfLines: Double = 0 { didSet { needsTextUpdate = true } }
|
|
77
|
+
var ellipsizeMode: EllipsizeMode = .tail { didSet { needsTextUpdate = true } }
|
|
78
|
+
|
|
79
|
+
func afterUpdate() throws {
|
|
80
|
+
guard needsTextUpdate else { return }
|
|
81
|
+
guard fontSize.isFinite && fontSize > 0 else {
|
|
82
|
+
throw RuntimeError("fontSize must be a positive, finite number.")
|
|
83
|
+
}
|
|
84
|
+
guard let lines = Int(exactly: numberOfLines), lines >= 0 else {
|
|
85
|
+
throw RuntimeError("numberOfLines must be a nonnegative integer.")
|
|
86
|
+
}
|
|
87
|
+
guard let rgba = UInt32(exactly: color) else {
|
|
88
|
+
throw RuntimeError("Text color must be an integer in 0xRRGGBBAA format.")
|
|
89
|
+
}
|
|
90
|
+
if let lineHeight {
|
|
91
|
+
guard lineHeight.isFinite && lineHeight > 0 else {
|
|
92
|
+
throw RuntimeError("lineHeight must be a positive, finite number.")
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let resolvedFont: NSFont
|
|
97
|
+
if let font {
|
|
98
|
+
resolvedFont = try AssetFonts.load(name: font, size: CGFloat(fontSize))
|
|
99
|
+
} else {
|
|
100
|
+
resolvedFont = NSFont.systemFont(ofSize: CGFloat(fontSize), weight: fontWeight.toNSFontWeight())
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let textColor = NSColor(rgba: rgba)
|
|
104
|
+
let paragraph = NSMutableParagraphStyle()
|
|
105
|
+
paragraph.alignment = view.resolvedParagraphAlignment
|
|
106
|
+
let containerBreakMode: NSLineBreakMode = ellipsizeMode == .tail ? .byTruncatingTail : .byClipping
|
|
107
|
+
// Multi-line TextKit requires word wrapping on the paragraph style so lines wrap up to
|
|
108
|
+
// `maximumNumberOfLines` and only the final visible line truncates via `textContainer.lineBreakMode`.
|
|
109
|
+
paragraph.lineBreakMode = lines == 1 ? containerBreakMode : .byWordWrapping
|
|
110
|
+
if let lineHeight {
|
|
111
|
+
paragraph.minimumLineHeight = CGFloat(lineHeight)
|
|
112
|
+
paragraph.maximumLineHeight = CGFloat(lineHeight)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let attributes: [NSAttributedString.Key: Any] = [
|
|
116
|
+
.font: resolvedFont,
|
|
117
|
+
.foregroundColor: textColor,
|
|
118
|
+
.paragraphStyle: paragraph,
|
|
119
|
+
]
|
|
120
|
+
let content = text ?? ""
|
|
121
|
+
view.numberOfLines = lines
|
|
122
|
+
view.lineBreakMode = containerBreakMode
|
|
123
|
+
view.attributedText = NSAttributedString(string: content, attributes: attributes)
|
|
124
|
+
NLMarkDirty(layoutNode.ref)
|
|
125
|
+
needsTextUpdate = false
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
internal import AppKit
|
|
2
|
+
internal import CoreGraphics
|
|
3
|
+
internal import NitroModules
|
|
4
|
+
internal import QuartzCore
|
|
5
|
+
|
|
6
|
+
final class NitroMaskedView: FlippedView {
|
|
7
|
+
private var maskView: NSView?
|
|
8
|
+
|
|
9
|
+
func setMaskView(_ view: NSView?) {
|
|
10
|
+
if maskView === view {
|
|
11
|
+
refreshMask()
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
maskView = view
|
|
15
|
+
refreshMask()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override func setFrameSize(_ newSize: NSSize) {
|
|
19
|
+
super.setFrameSize(newSize)
|
|
20
|
+
refreshMask()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
override func layout() {
|
|
24
|
+
super.layout()
|
|
25
|
+
refreshMask()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override func viewDidMoveToWindow() {
|
|
29
|
+
super.viewDidMoveToWindow()
|
|
30
|
+
refreshMask()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override func viewDidChangeBackingProperties() {
|
|
34
|
+
super.viewDidChangeBackingProperties()
|
|
35
|
+
refreshMask()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func refreshMask() {
|
|
39
|
+
let hostLayer = ensureLayer()
|
|
40
|
+
guard let maskView else {
|
|
41
|
+
NitroAnimationContext.performWithoutImplicitAnimations {
|
|
42
|
+
hostLayer.mask = nil
|
|
43
|
+
}
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
let scale = window?.backingScaleFactor ?? NSScreen.main?.backingScaleFactor ?? 2
|
|
47
|
+
maskView.layoutSubtreeIfNeeded()
|
|
48
|
+
let maskLayer = buildSyncedLayerTree(for: maskView, scale: scale)
|
|
49
|
+
NitroAnimationContext.performWithoutImplicitAnimations {
|
|
50
|
+
maskLayer.frame = maskView.frame
|
|
51
|
+
hostLayer.mask = maskLayer
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private func buildSyncedLayerTree(for view: NSView, scale: CGFloat) -> CALayer {
|
|
56
|
+
if !view.wantsLayer {
|
|
57
|
+
view.wantsLayer = true
|
|
58
|
+
}
|
|
59
|
+
let layer: CALayer
|
|
60
|
+
if let flipped = view as? FlippedView {
|
|
61
|
+
layer = flipped.ensureLayer()
|
|
62
|
+
} else if let existing = view.layer {
|
|
63
|
+
layer = existing
|
|
64
|
+
} else {
|
|
65
|
+
let created = view.makeBackingLayer()
|
|
66
|
+
view.layer = created
|
|
67
|
+
layer = created
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
NitroAnimationContext.performWithoutImplicitAnimations {
|
|
71
|
+
layer.contentsScale = scale
|
|
72
|
+
layer.frame = view.frame
|
|
73
|
+
layer.opacity = Float(view.alphaValue)
|
|
74
|
+
layer.isHidden = view.isHidden
|
|
75
|
+
|
|
76
|
+
if let label = view as? LabelView {
|
|
77
|
+
// Leaf label mask: keep layer non-flipped so the upright CGImage renders right-side up.
|
|
78
|
+
layer.isGeometryFlipped = false
|
|
79
|
+
layer.contents = renderLabelToCGImage(label, scale: scale)
|
|
80
|
+
} else {
|
|
81
|
+
layer.isGeometryFlipped = view.isFlipped
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
for subview in view.subviews {
|
|
85
|
+
let sublayer = buildSyncedLayerTree(for: subview, scale: scale)
|
|
86
|
+
if sublayer.superlayer !== layer {
|
|
87
|
+
sublayer.removeFromSuperlayer()
|
|
88
|
+
layer.addSublayer(sublayer)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return layer
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private func renderLabelToCGImage(_ label: LabelView, scale: CGFloat) -> CGImage? {
|
|
96
|
+
let width = Int(ceil(label.bounds.width * scale))
|
|
97
|
+
let height = Int(ceil(label.bounds.height * scale))
|
|
98
|
+
guard width > 0, height > 0 else { return nil }
|
|
99
|
+
let colorSpace = CGColorSpaceCreateDeviceRGB()
|
|
100
|
+
let bitmapInfo = CGImageAlphaInfo.premultipliedFirst.rawValue | CGBitmapInfo.byteOrder32Little.rawValue
|
|
101
|
+
guard let context = CGContext(
|
|
102
|
+
data: nil,
|
|
103
|
+
width: width,
|
|
104
|
+
height: height,
|
|
105
|
+
bitsPerComponent: 8,
|
|
106
|
+
bytesPerRow: width * 4,
|
|
107
|
+
space: colorSpace,
|
|
108
|
+
bitmapInfo: bitmapInfo
|
|
109
|
+
) else {
|
|
110
|
+
return nil
|
|
111
|
+
}
|
|
112
|
+
context.scaleBy(x: scale, y: scale)
|
|
113
|
+
context.translateBy(x: 0, y: label.bounds.height)
|
|
114
|
+
context.scaleBy(x: 1, y: -1)
|
|
115
|
+
let graphicsContext = NSGraphicsContext(cgContext: context, flipped: true)
|
|
116
|
+
let previous = NSGraphicsContext.current
|
|
117
|
+
NSGraphicsContext.current = graphicsContext
|
|
118
|
+
label.draw(label.bounds)
|
|
119
|
+
NSGraphicsContext.current = previous
|
|
120
|
+
return context.makeImage()
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
final class HybridMaskedView: HybridMaskedViewSpec {
|
|
125
|
+
typealias AllowedChildrenType = any View
|
|
126
|
+
|
|
127
|
+
let view = NitroMaskedView()
|
|
128
|
+
let layoutNode = LayoutNode()
|
|
129
|
+
var parentReference: (any HybridViewSpec)?
|
|
130
|
+
var gestureRecognizers: [any HybridGestureRecognizerSpec] = []
|
|
131
|
+
private var children: [NSView] = []
|
|
132
|
+
|
|
133
|
+
override init() throws {
|
|
134
|
+
try super.init()
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
func appendChild(child: any HybridViewSpec) throws {
|
|
138
|
+
let childView = child.view
|
|
139
|
+
children.removeAll { $0 === childView }
|
|
140
|
+
children.append(childView)
|
|
141
|
+
child.parentReference = self
|
|
142
|
+
updateMask()
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
func insertBefore(child: any HybridViewSpec, beforeChild: any HybridViewSpec) throws {
|
|
146
|
+
if child === beforeChild { return }
|
|
147
|
+
let childView = child.view
|
|
148
|
+
let beforeView = beforeChild.view
|
|
149
|
+
guard children.contains(where: { $0 === beforeView }) else {
|
|
150
|
+
throw RuntimeError("Mask sibling is missing.")
|
|
151
|
+
}
|
|
152
|
+
children.removeAll { $0 === childView }
|
|
153
|
+
guard let index = children.firstIndex(where: { $0 === beforeView }) else {
|
|
154
|
+
throw RuntimeError("Mask sibling is missing.")
|
|
155
|
+
}
|
|
156
|
+
children.insert(childView, at: index)
|
|
157
|
+
child.parentReference = self
|
|
158
|
+
updateMask()
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
func removeChild(child: any HybridViewSpec) throws {
|
|
162
|
+
let childView = child.view
|
|
163
|
+
children.removeAll { $0 === childView }
|
|
164
|
+
childView.removeFromSuperview()
|
|
165
|
+
child.parentReference = nil
|
|
166
|
+
updateMask()
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
func afterUpdate() {
|
|
170
|
+
view.refreshMask()
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private func updateMask() {
|
|
174
|
+
view.setMaskView(nil)
|
|
175
|
+
for (index, child) in children.enumerated() {
|
|
176
|
+
if index == 0 {
|
|
177
|
+
child.removeFromSuperview()
|
|
178
|
+
view.setMaskView(child)
|
|
179
|
+
} else if child.superview !== view {
|
|
180
|
+
view.addSubview(child)
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
view.refreshMask()
|
|
184
|
+
}
|
|
185
|
+
}
|