Skip to content

Commit

Permalink
Patch 2.5.0
Browse files Browse the repository at this point in the history
feat:
- Added support for visionOS
- Added support for watchOS
  • Loading branch information
FulcrumOne authored Jun 18, 2024
1 parent 2465a5a commit e18cbd9
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 11 deletions.
2 changes: 1 addition & 1 deletion MijickPopupView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pod::Spec.new do |s|
PopupView is a free and open-source library dedicated for SwiftUI that makes the process of presenting popups easier and much cleaner.
DESC

s.version = '2.4.2'
s.version = '2.5.0'
s.ios.deployment_target = '14.0'
s.osx.deployment_target = '12.0'
s.swift_version = '5.0'
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ let package = Package(
platforms: [
.iOS(.v14),
.macOS(.v12),
.tvOS(.v15)
.tvOS(.v15),
.watchOS(.v4)
],
products: [
.library(name: "MijickPopupView", targets: ["MijickPopupView"])
Expand Down
18 changes: 17 additions & 1 deletion Sources/Internal/Extensions/View++.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fileprivate extension Edge {
// MARK: - Actions
extension View {
func focusSectionIfAvailable() -> some View {
#if os(iOS) || os(macOS)
#if os(iOS) || os(macOS) || os(visionOS) || os(watchOS)
self
#elseif os(tvOS)
focusSection()
Expand All @@ -40,3 +40,19 @@ extension View {
extension View {
@ViewBuilder func active(if condition: Bool) -> some View { if condition { self } }
}
extension View {
func onChange<T: Equatable>(_ value: T, completion: @escaping (T) -> Void) -> some View {
#if os(visionOS)
onChange(of: value) { completion(value) }
#else
onChange(of: value) { _ in completion(value) }
#endif
}
func overlay<V: View>(view: V) -> some View {
#if os(visionOS)
overlay { view }
#else
overlay(view)
#endif
}
}
10 changes: 8 additions & 2 deletions Sources/Internal/Extensions/View.Gestures++.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import SwiftUI

// MARK: - iOS + macOS Implementation
#if os(iOS) || os(macOS)
#if os(iOS) || os(macOS) || os(visionOS) || os(watchOS)
extension View {
func onTapGesture(perform action: @escaping () -> ()) -> some View { onTapGesture(count: 1, perform: action) }
func onDragGesture(_ state: GestureState<Bool>, onChanged actionOnChanged: @escaping (CGFloat) -> (), onEnded actionOnEnded: @escaping (CGFloat) -> ()) -> some View { simultaneousGesture(createDragGesture(state, actionOnChanged, actionOnEnded)).onStateChange(state, actionOnEnded) }
Expand All @@ -23,7 +23,13 @@ private extension View {
.onChanged { actionOnChanged($0.translation.height) }
.onEnded { actionOnEnded($0.translation.height) }
}
func onStateChange(_ state: GestureState<Bool>, _ actionOnEnded: @escaping (CGFloat) -> ()) -> some View { onChange(of: state.wrappedValue) { $0 ? () : actionOnEnded(.zero) } }
func onStateChange(_ state: GestureState<Bool>, _ actionOnEnded: @escaping (CGFloat) -> ()) -> some View {
#if os(visionOS)
onChange(of: state.wrappedValue) { state.wrappedValue ? () : actionOnEnded(.zero) }
#else
onChange(of: state.wrappedValue) { $0 ? () : actionOnEnded(.zero) }
#endif
}
}


Expand Down
4 changes: 2 additions & 2 deletions Sources/Internal/Managers/KeyboardManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SwiftUI
import Combine

// MARK: -iOS Implementation
#if os(iOS)
#if os(iOS) || os(visionOS)
class KeyboardManager: ObservableObject {
@Published private(set) var height: CGFloat = 0
private var subscription: [AnyCancellable] = []
Expand Down Expand Up @@ -60,7 +60,7 @@ extension KeyboardManager {


// MARK: - tvOS Implementation
#elseif os(tvOS)
#elseif os(tvOS) || os(watchOS)
class KeyboardManager: ObservableObject {
private(set) var height: CGFloat = 0

Expand Down
22 changes: 22 additions & 0 deletions Sources/Internal/Managers/ScreenManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,29 @@ private extension ScreenManager {
.store(in: &subscription)
}
}
// MARK: - visionOS Implementation
#elseif os(visionOS)
class ScreenManager: ObservableObject {
@Published var size: CGSize = .init()
@Published var safeArea: UIEdgeInsets = .init()
private(set) var cornerRadius: CGFloat? = 0
private(set) var animationsDisabled: Bool = false

static let shared: ScreenManager = .init()
private init() {}
}

// MARK: - watchOS Implementation
#elseif os(watchOS)
class ScreenManager: ObservableObject {
@Published var size: CGSize = .init()
@Published var safeArea: UIEdgeInsets = .init()
private(set) var cornerRadius: CGFloat? = 0
private(set) var animationsDisabled: Bool = false

static let shared: ScreenManager = .init()
private init() { }
}

// MARK: - tvOS Implementation
#elseif os(tvOS)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Internal/Views/PopupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import SwiftUI

// MARK: - iOS / macOS Implementation
#if os(iOS) || os(macOS)
#if os(iOS) || os(macOS) || os(visionOS) || os(watchOS)
struct PopupView: View {
let globalConfig: GlobalConfig
@State private var zIndex: ZIndex = .init()
Expand Down Expand Up @@ -46,7 +46,7 @@ private extension PopupView {
.ignoresSafeArea()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.animation(stackAnimation, value: popupManager.views.map(\.id))
.onChange(of: popupManager.views.count, perform: onViewsCountChange)
.onChange(popupManager.views.count, completion: onViewsCountChange)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Public/Extensions/Public+View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import SwiftUI
public extension View {
/// Initialises the library. Use directly with the view in your @main structure
func implementPopupView(config: (GlobalConfig) -> GlobalConfig = { $0 }) -> some View {
#if os(iOS) || os(macOS)
#if os(iOS) || os(macOS) || os(visionOS) || os(watchOS)
updateScreenSize()
.frame(maxWidth: .infinity)
.overlay(PopupView(globalConfig: config(.init())))
.overlay(view: PopupView(globalConfig: config(.init())))
#elseif os(tvOS)
PopupView(rootView: updateScreenSize(), globalConfig: config(.init()))
#endif
Expand Down

0 comments on commit e18cbd9

Please sign in to comment.