From ce72aa9efb0165e8eb1b685c857a9a2c516a44ed Mon Sep 17 00:00:00 2001 From: Alina P Date: Mon, 4 Nov 2024 13:19:53 +0100 Subject: [PATCH] Patch 3.0.1 fix: - Fixed the problem with a drag gesture docs: - Updated in-app documentation --- MijickPopups.podspec | 2 +- .../Local/LocalConfig+Centre.swift | 6 ++ .../Local/LocalConfig+Vertical.swift | 13 +++ .../Internal/Extensions/View+Gestures.swift | 22 ++--- .../Internal/UI/PopupVerticalStackView.swift | 2 +- .../Public/Popup/Public+Popup+Config.swift | 2 +- Sources/Public/Popup/Public+Popup+Main.swift | 82 +++++++++++++++++++ .../Public/Present/Public+Present+Popup.swift | 2 + 8 files changed, 118 insertions(+), 13 deletions(-) diff --git a/MijickPopups.podspec b/MijickPopups.podspec index d03e093f06..b5f3103bba 100644 --- a/MijickPopups.podspec +++ b/MijickPopups.podspec @@ -5,7 +5,7 @@ Pod::Spec.new do |s| MijickPopups is a free and open-source library dedicated for SwiftUI that makes the process of presenting popups easier and much cleaner. DESC - s.version = '3.0.0' + s.version = '3.0.1' s.ios.deployment_target = '14.0' s.osx.deployment_target = '12.0' s.tvos.deployment_target = '15.0' diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift index c464bbe335..d4545bef8e 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift @@ -22,6 +22,12 @@ public extension LocalConfig { class Centre: LocalConfig { }} // MARK: Typealias +/** + Configures the popup. + See the list of available methods in ``LocalConfig``. + +- important: If a certain method is not called here, the popup inherits the configuration from ``GlobalConfigContainer``. + */ public typealias CentrePopupConfig = LocalConfig.Centre diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift index f1e1dc2241..618cdd0434 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift @@ -28,7 +28,20 @@ public extension LocalConfig { class Vertical: LocalConfig { }} // MARK: Subclasses & Typealiases +/** + Configures the popup. + See the list of available methods in ``LocalConfig`` and ``LocalConfig/Vertical``. + +- important: If a certain method is not called here, the popup inherits the configuration from ``GlobalConfigContainer``. + */ public typealias TopPopupConfig = LocalConfig.Vertical.Top + +/** + Configures the popup. + See the list of available methods in ``LocalConfig`` and ``LocalConfig/Vertical``. + +- important: If a certain method is not called here, the popup inherits the configuration from ``GlobalConfigContainer``. + */ public typealias BottomPopupConfig = LocalConfig.Vertical.Bottom public extension LocalConfig.Vertical { class Top: LocalConfig.Vertical {} diff --git a/Sources/Internal/Extensions/View+Gestures.swift b/Sources/Internal/Extensions/View+Gestures.swift index f7e8ae0604..09933debef 100644 --- a/Sources/Internal/Extensions/View+Gestures.swift +++ b/Sources/Internal/Extensions/View+Gestures.swift @@ -14,24 +14,26 @@ import SwiftUI // MARK: On Tap Gesture extension View { func onTapGesture(perform action: @escaping () -> ()) -> some View { - #if os(iOS) || os(macOS) || os(visionOS) || os(watchOS) - onTapGesture(count: 1, perform: action) - #elseif os(tvOS) + #if os(tvOS) self + #else + onTapGesture(count: 1, perform: action) #endif } } // MARK: On Drag Gesture extension View { - func onDragGesture(onChanged actionOnChanged: @escaping (CGFloat) -> (), onEnded actionOnEnded: @escaping (CGFloat) -> ()) -> some View { - #if os(iOS) || os(macOS) || os(visionOS) || os(watchOS) - highPriorityGesture(DragGesture() - .onChanged { actionOnChanged($0.translation.height) } - .onEnded { actionOnEnded($0.translation.height) } - ) - #elseif os(tvOS) + func onDragGesture(onChanged actionOnChanged: @escaping (CGFloat) -> (), onEnded actionOnEnded: @escaping (CGFloat) -> (), isEnabled: Bool) -> some View { + #if os(tvOS) self + #else + highPriorityGesture( + DragGesture() + .onChanged { actionOnChanged($0.translation.height) } + .onEnded { actionOnEnded($0.translation.height) }, + isEnabled: isEnabled + ) #endif } } diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index 2ea25d664a..6cf7245577 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -18,7 +18,7 @@ struct PopupVerticalStackView: View { var body: some View { ZStack(alignment: (!viewModel.alignment).toAlignment(), content: createPopupStack) .frame(height: viewModel.screen.height, alignment: viewModel.alignment.toAlignment()) - .onDragGesture(onChanged: viewModel.onPopupDragGestureChanged, onEnded: viewModel.onPopupDragGestureEnded) + .onDragGesture(onChanged: viewModel.onPopupDragGestureChanged, onEnded: viewModel.onPopupDragGestureEnded, isEnabled: viewModel.dragGestureEnabled) } } private extension PopupVerticalStackView { diff --git a/Sources/Public/Popup/Public+Popup+Config.swift b/Sources/Public/Popup/Public+Popup+Config.swift index 17e01bed88..02a75adc12 100644 --- a/Sources/Public/Popup/Public+Popup+Config.swift +++ b/Sources/Public/Popup/Public+Popup+Config.swift @@ -94,7 +94,7 @@ public extension LocalConfig.Vertical { func heightMode(_ value: HeightMode) -> Self { self.heightMode = value; return self } /** - Sets the available detents for the popup. + Sets the available detents for the popup. Enables drag and drop functionality. ## Visualisation ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/drag-detent.png?raw=true) diff --git a/Sources/Public/Popup/Public+Popup+Main.swift b/Sources/Public/Popup/Public+Popup+Main.swift index b5f84301ab..d69ccb5215 100644 --- a/Sources/Public/Popup/Public+Popup+Main.swift +++ b/Sources/Public/Popup/Public+Popup+Main.swift @@ -100,6 +100,88 @@ public extension Popup { } // MARK: Available Types +/** + The view to be displayed as a Top popup. + + # Optional Methods + - ``Popup/configurePopup(config:)-98ha0`` + - ``Popup/onFocus()-6krqs`` + - ``Popup/onDismiss()-3bufs`` + + # Usage Examples + + ## TopPopup + ```swift + struct TopPopupExample: TopPopup { + func onFocus() { print("Popup is now active") } + func onDismiss() { print("Popup was dismissed") } + func configurePopup(config: TopPopupConfig) -> TopPopupConfig { config + .heightMode(.auto) + .cornerRadius(44) + .dragDetents([.fraction(1.2), .fraction(1.4), .large]) + } + var body: some View { + Text("Hello Kitty") + } + } + ``` + ![TopPopup](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/top-popup.png?raw=true) +*/ public protocol TopPopup: Popup { associatedtype Config = TopPopupConfig } + +/** + The view to be displayed as a Centre popup. + + # Optional Methods + - ``Popup/configurePopup(config:)-3ze4`` + - ``Popup/onFocus()-loq5`` + - ``Popup/onDismiss()-3bufs`` + + # Usage Examples + + ## CentrePopup + ```swift + struct CentrePopupExample: CentrePopup { + func onFocus() { print("Popup is now active") } + func onDismiss() { print("Popup was dismissed") } + func configurePopup(config: CentrePopupConfig) -> CentrePopupConfig { config + .cornerRadius(44) + .tapOutsideToDismissPopup(true) + } + var body: some View { + Text("Hello Kitty") + } + } + ``` + ![CentrePopup](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/centre-popup.png?raw=true) + */ public protocol CentrePopup: Popup { associatedtype Config = CentrePopupConfig } + +/** + The view to be displayed as a Bottom popup. + + # Optional Methods + - ``Popup/configurePopup(config:)-98ha0`` + - ``Popup/onFocus()-loq5`` + - ``Popup/onDismiss()-254h8`` + + # Usage Examples + + ## BottomPopup + ```swift + struct BottomPopupExample: BottomPopup { + func onFocus() { print("Popup is now active") } + func onDismiss() { print("Popup was dismissed") } + func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config + .heightMode(.auto) + .cornerRadius(44) + .dragDetents([.fraction(1.2), .fraction(1.4), .large]) + } + var body: some View { + Text("Hello Kitty") + } + } + ``` + ![BottomPopup](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/bottom-popup.png?raw=true) + */ public protocol BottomPopup: Popup { associatedtype Config = BottomPopupConfig } diff --git a/Sources/Public/Present/Public+Present+Popup.swift b/Sources/Public/Present/Public+Present+Popup.swift index b00dfadf4b..fb3894be26 100644 --- a/Sources/Public/Present/Public+Present+Popup.swift +++ b/Sources/Public/Present/Public+Present+Popup.swift @@ -29,6 +29,8 @@ public extension Popup { ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-9mkd5``, ``SwiftUICore/View/dismissAllPopups(popupManagerID:)`` should be called with the same **popupManagerID** as the one used here. + + - Warning: To present multiple popups of the same type, set a unique identifier using the method ``Popup/setCustomID(_:)``. */ func present(popupManagerID: PopupManagerID = .shared) { PopupManager.fetchInstance(id: popupManagerID)?.stack(.insertPopup(self)) } }