Skip to content

Commit 89a90fd

Browse files
committed
Added support vision os.
1 parent 0bc23a5 commit 89a90fd

File tree

6 files changed

+63
-29
lines changed

6 files changed

+63
-29
lines changed

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:5.9
22

33
import PackageDescription
44

55
let package = Package(
66
name: "AlertKit",
77
platforms: [
8-
.iOS(.v13)
8+
.iOS(.v13),
9+
.visionOS(.v1)
910
],
1011
products: [
1112
.library(

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ If you need customisation fonts, icon, colors or any other, make view:
103103

104104
```swift
105105
let alertView = AlertAppleMusic17View(title: "Added to Library", subtitle: nil, icon: .done)
106-
// Change content color
107-
alertView.contentColor = .systemBlue
108-
// Change font
106+
// Change Font
109107
alertView.titleLabel.font = UIFont.systemFont(ofSize: 21)
108+
// Change Color
109+
alertView.titleLabel.textColor = .white
110110
```
111111

112112
## Apps Using

Sources/AlertKit/AlertKitAPI.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ public enum AlertKitAPI {
99

1010
public static func present(title: String? = nil, subtitle: String? = nil, icon: AlertIcon? = nil, style: AlertViewStyle, haptic: AlertHaptic? = nil) {
1111
switch style {
12+
#if os(iOS)
1213
case .iOS16AppleMusic:
1314
guard let window = UIApplication.shared.windows.filter({ $0.isKeyWindow }).first else { return }
1415
let view = AlertAppleMusic16View(title: title, subtitle: subtitle, icon: icon)
1516
view.haptic = haptic
1617
view.present(on: window)
18+
#endif
19+
#if os(iOS) || os(visionOS)
1720
case .iOS17AppleMusic:
1821
guard let window = UIApplication.shared.windows.filter({ $0.isKeyWindow }).first else { return }
1922
let view = AlertAppleMusic17View(title: title, subtitle: subtitle, icon: icon)
2023
view.haptic = haptic
2124
view.present(on: window)
25+
#endif
2226
}
2327
}
2428
}

Sources/AlertKit/AlertViewStyle.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import Foundation
22

33
public enum AlertViewStyle {
44

5+
#if os(iOS)
56
case iOS16AppleMusic
7+
#endif
8+
9+
#if os(iOS) || os(visionOS)
610
case iOS17AppleMusic
11+
#endif
712
}

Sources/AlertKit/Views/AlertAppleMusic16View.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import UIKit
22

3+
@available(iOS 13, *)
34
public class AlertAppleMusic16View: UIView, AlertViewProtocol {
45

56
open var dismissByTap: Bool = true
@@ -11,7 +12,7 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol {
1112
public let subtitleLabel: UILabel?
1213
public let iconView: UIView?
1314

14-
public var contentColor = UIColor { trait in
15+
public static var defaultContentColor = UIColor { trait in
1516
switch trait.userInterfaceStyle {
1617
case .dark: UIColor(red: 127 / 255, green: 127 / 255, blue: 129 / 255, alpha: 1)
1718
default: UIColor(red: 88 / 255, green: 87 / 255, blue: 88 / 255, alpha: 1)
@@ -81,6 +82,10 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol {
8182
layout = AlertLayout(for: icon ?? .heart)
8283
}
8384

85+
self.titleLabel?.textColor = Self.defaultContentColor
86+
self.subtitleLabel?.textColor = Self.defaultContentColor
87+
self.iconView?.tintColor = Self.defaultContentColor
88+
8489
super.init(frame: .zero)
8590

8691
preservesSuperviewLayoutMargins = false
@@ -120,11 +125,6 @@ public class AlertAppleMusic16View: UIView, AlertViewProtocol {
120125
}
121126

122127
open func present(on view: UIView, completion: @escaping ()->Void = {}) {
123-
124-
self.titleLabel?.textColor = contentColor
125-
self.subtitleLabel?.textColor = contentColor
126-
self.iconView?.tintColor = contentColor
127-
128128
self.completion = completion
129129
self.viewForPresent = view
130130
viewForPresent?.addSubview(self)

Sources/AlertKit/Views/AlertAppleMusic17View.swift

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import UIKit
2+
import SwiftUI
23

4+
@available(iOS 13, visionOS 1, *)
35
public class AlertAppleMusic17View: UIView, AlertViewProtocol {
46

57
open var dismissByTap: Bool = true
@@ -11,11 +13,15 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
1113
public let subtitleLabel: UILabel?
1214
public let iconView: UIView?
1315

14-
public var contentColor = UIColor { trait in
16+
public static var defaultContentColor = UIColor { trait in
17+
#if os(visionOS)
18+
return .label
19+
#else
1520
switch trait.userInterfaceStyle {
1621
case .dark: UIColor(red: 127 / 255, green: 127 / 255, blue: 129 / 255, alpha: 1)
1722
default: UIColor(red: 88 / 255, green: 87 / 255, blue: 88 / 255, alpha: 1)
1823
}
24+
#endif
1925
}
2026

2127
fileprivate weak var viewForPresent: UIView?
@@ -24,20 +30,18 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
2430

2531
open var completion: (() -> Void)? = nil
2632

27-
private lazy var backgroundView: UIVisualEffectView = {
28-
let view: UIVisualEffectView = {
29-
#if !os(tvOS)
30-
if #available(iOS 13.0, *) {
31-
return UIVisualEffectView(effect: UIBlurEffect(style: .systemThickMaterial))
32-
} else {
33-
return UIVisualEffectView(effect: UIBlurEffect(style: .light))
34-
}
35-
#else
36-
return UIVisualEffectView(effect: UIBlurEffect(style: .light))
37-
#endif
38-
}()
33+
private lazy var backgroundView: UIView = {
34+
#if os(visionOS)
35+
let swiftUIView = VisionGlassBackgroundView(cornerRadius: 12)
36+
let host = UIHostingController(rootView: swiftUIView)
37+
let hostView = host.view ?? UIView()
38+
hostView.isUserInteractionEnabled = false
39+
return hostView
40+
#else
41+
let view = UIVisualEffectView(effect: UIBlurEffect())
3942
view.isUserInteractionEnabled = false
4043
return view
44+
#endif
4145
}()
4246

4347
public init(title: String?, subtitle: String?, icon: AlertIcon?) {
@@ -75,6 +79,10 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
7579
self.iconView = nil
7680
}
7781

82+
self.titleLabel?.textColor = Self.defaultContentColor
83+
self.subtitleLabel?.textColor = Self.defaultContentColor
84+
self.iconView?.tintColor = Self.defaultContentColor
85+
7886
super.init(frame: .zero)
7987

8088
preservesSuperviewLayoutMargins = false
@@ -89,6 +97,7 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
8997
if let subtitleLabel = self.subtitleLabel {
9098
addSubview(subtitleLabel)
9199
}
100+
92101
if let iconView = self.iconView {
93102
addSubview(iconView)
94103
}
@@ -118,11 +127,6 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
118127
}
119128

120129
open func present(on view: UIView, completion: @escaping ()->Void = {}) {
121-
122-
self.titleLabel?.textColor = contentColor
123-
self.subtitleLabel?.textColor = contentColor
124-
self.iconView?.tintColor = contentColor
125-
126130
self.completion = completion
127131
self.viewForPresent = view
128132
viewForPresent?.addSubview(self)
@@ -131,7 +135,12 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
131135
alpha = 0
132136
sizeToFit()
133137
center.x = viewForPresent.frame.midX
138+
#if os(visionOS)
139+
frame.origin.y = viewForPresent.safeAreaInsets.top + 24
140+
#elseif os(iOS)
134141
frame.origin.y = viewForPresent.frame.height - viewForPresent.safeAreaInsets.bottom - frame.height - 64
142+
#endif
143+
135144
transform = transform.scaledBy(x: self.presentDismissScale, y: self.presentDismissScale)
136145

137146
if dismissByTap {
@@ -258,4 +267,19 @@ public class AlertAppleMusic17View: UIView, AlertViewProtocol {
258267

259268
iconView?.center.y = frame.height / 2
260269
}
270+
271+
#if os(visionOS)
272+
struct VisionGlassBackgroundView: View {
273+
274+
let cornerRadius: CGFloat
275+
276+
var body: some View {
277+
ZStack {
278+
Color.clear
279+
}
280+
.glassBackgroundEffect(in: .rect(cornerRadius: cornerRadius))
281+
.opacity(0.4)
282+
}
283+
}
284+
#endif
261285
}

0 commit comments

Comments
 (0)