From fb3eca0b637bfd0f956a8be2f2ea1b653c2ed87f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 12:44:59 +0100 Subject: [PATCH 001/407] DANGER --- Sources/Internal/Containers/PopupManagerContainer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/Containers/PopupManagerContainer.swift b/Sources/Internal/Containers/PopupManagerContainer.swift index 603c8142c5..c9c753687d 100644 --- a/Sources/Internal/Containers/PopupManagerContainer.swift +++ b/Sources/Internal/Containers/PopupManagerContainer.swift @@ -11,7 +11,7 @@ import Foundation -@MainActor class PopupManagerContainer { +actor PopupManagerContainer { static private(set) var instances: [PopupManager] = [] } From 9527544aea5bf8046bd36610a7c00bcbbbe71d22 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 18:18:36 +0100 Subject: [PATCH 002/407] 1 --- Sources/Internal/View Models/ViewModelObject.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModelObject.swift b/Sources/Internal/View Models/ViewModelObject.swift index d917d39a60..a72f92b555 100644 --- a/Sources/Internal/View Models/ViewModelObject.swift +++ b/Sources/Internal/View Models/ViewModelObject.swift @@ -12,12 +12,8 @@ import SwiftUI @MainActor protocol ViewModelObject: ObservableObject { - associatedtype Config = LocalConfig - func setup(updatePopupAction: @escaping (AnyPopup) -> (), closePopupAction: @escaping (AnyPopup) -> ()) func updatePopupsValue(_ newPopups: [AnyPopup]) func updateScreenValue(_ newScreen: Screen) func updateKeyboardValue(_ isActive: Bool) - func getConfig(_ item: AnyPopup?) -> Config - func getActivePopupConfig() -> Config } From 3a824a63571b66fe5e551c1a886129e1db0b595f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 18:39:17 +0100 Subject: [PATCH 003/407] 1 --- Sources/Internal/Extensions/EdgeInsets++.swift | 1 + Sources/Internal/Models/StackPriority.swift | 8 ++++---- Sources/Internal/UI/PopupVerticalStackView.swift | 2 +- Sources/Internal/View Models/ViewModel+CentreStack.swift | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/Extensions/EdgeInsets++.swift b/Sources/Internal/Extensions/EdgeInsets++.swift index ee0178dd7f..55f4ed35c0 100644 --- a/Sources/Internal/Extensions/EdgeInsets++.swift +++ b/Sources/Internal/Extensions/EdgeInsets++.swift @@ -14,6 +14,7 @@ import SwiftUI extension EdgeInsets { subscript(_ edge: VerticalEdge) -> CGFloat { switch edge { case .top: top + case .centre: 0 case .bottom: bottom }} } diff --git a/Sources/Internal/Models/StackPriority.swift b/Sources/Internal/Models/StackPriority.swift index b2fb3b5808..c26cbbec57 100644 --- a/Sources/Internal/Models/StackPriority.swift +++ b/Sources/Internal/Models/StackPriority.swift @@ -22,10 +22,10 @@ struct StackPriority: Equatable { // MARK: Reshuffle extension StackPriority { - @MainActor mutating func reshuffle(newPopups: [AnyPopup]) { switch newPopups.last { - case .some(let popup) where popup.config is TopPopupConfig: reshuffle(0) - case .some(let popup) where popup.config is CentrePopupConfig: reshuffle(1) - case .some(let popup) where popup.config is BottomPopupConfig: reshuffle(2) + @MainActor mutating func reshuffle(newPopups: [AnyPopup]) { switch newPopups.last?.alignment { + case .top: reshuffle(0) + case .centre: reshuffle(1) + case .bottom: reshuffle(2) default: return }} } diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index 6cf7245577..2637b4567a 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -11,7 +11,7 @@ import SwiftUI -struct PopupVerticalStackView: View { +struct PopupVerticalStackView: View { @ObservedObject var viewModel: VM.VerticalStack diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index c305029f65..cb5dcb2a75 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -11,7 +11,7 @@ import SwiftUI -extension VM { class CentreStack: ViewModel { +extension VM { class CentreStack: ViewModel { // MARK: Overridden Methods override func recalculateAndSave(height: CGFloat, for popup: AnyPopup) { _recalculateAndSave(height: height, for: popup) } override func calculateHeightForActivePopup() -> CGFloat? { _calculateHeightForActivePopup() } From 5c778ba7bb60ec9b104cbc8bb6a1457f33d61362 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 18:47:31 +0100 Subject: [PATCH 004/407] 1 --- Sources/Internal/Extensions/EdgeInsets++.swift | 2 +- Sources/Internal/Extensions/View+Background.swift | 4 ++-- .../{VerticalEdge.swift => PopupAlignment.swift} | 13 +++++++++---- .../View Models/ViewModel+CentreStack.swift | 8 ++++---- Sources/Public/Popup/Public+Popup+Utilities.swift | 4 ++-- Tests/Tests+ViewModel+PopupCentreStack.swift | 2 +- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 7 files changed, 20 insertions(+), 15 deletions(-) rename Sources/Internal/Utilities/{VerticalEdge.swift => PopupAlignment.swift} (76%) diff --git a/Sources/Internal/Extensions/EdgeInsets++.swift b/Sources/Internal/Extensions/EdgeInsets++.swift index 55f4ed35c0..436d763bed 100644 --- a/Sources/Internal/Extensions/EdgeInsets++.swift +++ b/Sources/Internal/Extensions/EdgeInsets++.swift @@ -12,7 +12,7 @@ import SwiftUI extension EdgeInsets { - subscript(_ edge: VerticalEdge) -> CGFloat { switch edge { + subscript(_ edge: PopupAlignment) -> CGFloat { switch edge { case .top: top case .centre: 0 case .bottom: bottom diff --git a/Sources/Internal/Extensions/View+Background.swift b/Sources/Internal/Extensions/View+Background.swift index e05a3be3b2..d535924c0b 100644 --- a/Sources/Internal/Extensions/View+Background.swift +++ b/Sources/Internal/Extensions/View+Background.swift @@ -12,7 +12,7 @@ import SwiftUI extension View { - func background(backgroundColor: Color, overlayColor: Color, corners: [VerticalEdge: CGFloat]) -> some View { background( + func background(backgroundColor: Color, overlayColor: Color, corners: [PopupAlignment: CGFloat]) -> some View { background( backgroundColor .overlay(overlayColor) .mask(RoundedCorner(corners: corners)) @@ -21,7 +21,7 @@ extension View { // MARK: Background Shape fileprivate struct RoundedCorner: Shape { - var corners: [VerticalEdge: CGFloat] + var corners: [PopupAlignment: CGFloat] var animatableData: CGFloat { diff --git a/Sources/Internal/Utilities/VerticalEdge.swift b/Sources/Internal/Utilities/PopupAlignment.swift similarity index 76% rename from Sources/Internal/Utilities/VerticalEdge.swift rename to Sources/Internal/Utilities/PopupAlignment.swift index 6aaf2ea879..cb389a8714 100644 --- a/Sources/Internal/Utilities/VerticalEdge.swift +++ b/Sources/Internal/Utilities/PopupAlignment.swift @@ -1,5 +1,5 @@ // -// VerticalEdge.swift of MijickPopups +// PopupAlignment.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com @@ -11,33 +11,38 @@ import SwiftUI -enum VerticalEdge { +enum PopupAlignment { case top + case centre case bottom init(_ config: LocalConfig.Type) { switch config.self { case is TopPopupConfig.Type: self = .top + case is CentrePopupConfig.Type: self = .centre case is BottomPopupConfig.Type: self = .bottom default: fatalError() }} } // MARK: Negation -extension VerticalEdge { +extension PopupAlignment { static prefix func !(lhs: Self) -> Self { switch lhs { case .top: .bottom + case .centre: .centre case .bottom: .top }} } // MARK: Type Casting -extension VerticalEdge { +extension PopupAlignment { func toEdge() -> Edge { switch self { case .top: .top + case .centre: .bottom case .bottom: .bottom }} func toAlignment() -> Alignment { switch self { case .top: .top + case .centre: .center case .bottom: .bottom }} } diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index cb5dcb2a75..c8d78d057e 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -16,7 +16,7 @@ extension VM { class CentreStack: ViewModel { override func recalculateAndSave(height: CGFloat, for popup: AnyPopup) { _recalculateAndSave(height: height, for: popup) } override func calculateHeightForActivePopup() -> CGFloat? { _calculateHeightForActivePopup() } override func calculatePopupPadding() -> EdgeInsets { _calculatePopupPadding() } - override func calculateCornerRadius() -> [VerticalEdge : CGFloat] { _calculateCornerRadius() } + override func calculateCornerRadius() -> [PopupAlignment : CGFloat] { _calculateCornerRadius() } override func calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { _calculateVerticalFixedSize(for: popup) } }} @@ -56,7 +56,7 @@ private extension VM.CentreStack { )} } private extension VM.CentreStack { - func calculateVerticalPopupPadding(for edge: VerticalEdge) -> CGFloat { + func calculateVerticalPopupPadding(for edge: PopupAlignment) -> CGFloat { guard let activePopupHeight, isKeyboardActive && edge == .bottom else { return 0 } @@ -75,7 +75,7 @@ private extension VM.CentreStack { // MARK: Corner Radius private extension VM.CentreStack { - func _calculateCornerRadius() -> [VerticalEdge : CGFloat] {[ + func _calculateCornerRadius() -> [PopupAlignment : CGFloat] {[ .top: getActivePopupConfig().cornerRadius, .bottom: getActivePopupConfig().cornerRadius ]} @@ -119,7 +119,7 @@ private extension VM.CentreStack { extension VM.CentreStack { func t_calculateHeight(heightCandidate: CGFloat) -> CGFloat { calculateHeight(heightCandidate) } func t_calculatePopupPadding() -> EdgeInsets { calculatePopupPadding() } - func t_calculateCornerRadius() -> [VerticalEdge: CGFloat] { calculateCornerRadius() } + func t_calculateCornerRadius() -> [PopupAlignment: CGFloat] { calculateCornerRadius() } func t_calculateOpacity(for popup: AnyPopup) -> CGFloat { calculateOpacity(for: popup) } func t_calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { calculateVerticalFixedSize(for: popup) } } diff --git a/Sources/Public/Popup/Public+Popup+Utilities.swift b/Sources/Public/Popup/Public+Popup+Utilities.swift index 9209854162..39f80ff36e 100644 --- a/Sources/Public/Popup/Public+Popup+Utilities.swift +++ b/Sources/Public/Popup/Public+Popup+Utilities.swift @@ -12,7 +12,7 @@ import Foundation // MARK: Height Mode -public enum HeightMode { +public enum HeightMode: Sendable { /** Popup height is calculated based on its content. @@ -41,7 +41,7 @@ public enum HeightMode { } // MARK: Drag Detent -public enum DragDetent { +public enum DragDetent: Sendable { /** A detent with the specified height. diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index 4ddbc39b32..e51847aa29 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -135,7 +135,7 @@ extension PopupCentreStackViewModelTests { } } private extension PopupCentreStackViewModelTests { - func appendPopupsAndCheckCornerRadius(popups: [AnyPopup], expectedValue: [MijickPopups.VerticalEdge: CGFloat]) { + func appendPopupsAndCheckCornerRadius(popups: [AnyPopup], expectedValue: [MijickPopups.PopupAlignment: CGFloat]) { appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 3961fc31b0..fa04178aa3 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -900,7 +900,7 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckCornerRadius(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: [MijickPopups.VerticalEdge: CGFloat]) { + func appendPopupsAndCheckCornerRadius(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: [MijickPopups.PopupAlignment: CGFloat]) { appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, From 9b5d89ff97bec22a5a717d08964d401e503cbb5b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 18:57:53 +0100 Subject: [PATCH 005/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 74f336732a..c113918b47 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -180,6 +180,7 @@ private extension VM.VerticalStack { return switch alignment { case .top: min(gestureTranslation + lastPopupDragHeight, 0) case .bottom: max(gestureTranslation - lastPopupDragHeight, 0) + case .centre: fatalError() } } func calculateOffsetForStackedPopup(_ popup: AnyPopup) -> CGFloat { @@ -188,6 +189,7 @@ private extension VM.VerticalStack { let alignmentMultiplier = switch alignment { case .top: 1.0 case .bottom: -1.0 + case .centre: fatalError() } return offsetValue * alignmentMultiplier @@ -229,10 +231,12 @@ private extension VM.VerticalStack { func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat) -> CGFloat { switch alignment { case .top: calculatePopupPadding().top != 0 ? cornerRadiusValue : 0 case .bottom: cornerRadiusValue + case .centre: fatalError() }} func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat) -> CGFloat { switch alignment { case .top: cornerRadiusValue case .bottom: calculatePopupPadding().bottom != 0 ? cornerRadiusValue : 0 + case .centre: fatalError() }} } @@ -293,6 +297,7 @@ private extension VM.VerticalStack { func getDragTranslationMultiplier() -> CGFloat { switch alignment { case .top: 1 case .bottom: -1 + case .centre: fatalError() }} } @@ -301,6 +306,7 @@ private extension VM.VerticalStack { func calculateTranslationProgress() -> CGFloat { guard let activePopupHeight = popups.last?.height else { return 0 }; return switch alignment { case .top: abs(min(gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight case .bottom: max(gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight + case .centre: fatalError() }} } @@ -365,6 +371,7 @@ private extension VM.VerticalStack { func calculateDragExtremeValue(_ value1: CGFloat, _ value2: CGFloat) -> CGFloat { switch alignment { case .top: min(value1, value2) case .bottom: max(value1, value2) + case .centre: fatalError() }} } private extension VM.VerticalStack { @@ -454,12 +461,12 @@ private extension VM.VerticalStack { extension VM.VerticalStack { func t_calculatePopupPadding() -> EdgeInsets { calculatePopupPadding() } func t_calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { calculateBodyPadding(for: popup) } - func t_calculateHeight(heightCandidate: CGFloat, popupConfig: Config) -> CGFloat { calculateHeight(heightCandidate, popupConfig) } + func t_calculateHeight(heightCandidate: CGFloat, popupConfig: AnyPopupConfig) -> CGFloat { calculateHeight(heightCandidate, popupConfig) } func t_calculateOffsetY(for popup: AnyPopup) -> CGFloat { calculateOffsetY(for: popup) } func t_calculateScaleX(for popup: AnyPopup) -> CGFloat { calculateScaleX(for: popup) } func t_calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { calculateVerticalFixedSize(for: popup) } func t_calculateStackOverlayOpacity(for popup: AnyPopup) -> CGFloat { calculateStackOverlayOpacity(for: popup) } - func t_calculateCornerRadius() -> [VerticalEdge: CGFloat] { calculateCornerRadius() } + func t_calculateCornerRadius() -> [PopupAlignment: CGFloat] { calculateCornerRadius() } func t_calculateTranslationProgress() -> CGFloat { calculateTranslationProgress() } func t_getInvertedIndex(of popup: AnyPopup) -> Int { getInvertedIndex(of: popup) } From d45a9496cc18f4f8b54c6aaadf9688c921ac458b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:00:26 +0100 Subject: [PATCH 006/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index c113918b47..f3cdab77d3 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -96,7 +96,7 @@ private extension VM.VerticalStack { )} } private extension VM.VerticalStack { - func calculateVerticalPopupPadding(for edge: VerticalEdge) -> CGFloat { + func calculateVerticalPopupPadding(for edge: PopupAlignment) -> CGFloat { guard let activePopupHeight else { return 0 } let largeScreenHeight = calculateLargeScreenHeight(), @@ -114,7 +114,7 @@ private extension VM.VerticalStack { } } private extension VM.VerticalStack { - func calculatePriorityPopupPaddingValue(for edge: VerticalEdge) -> CGFloat { switch edge == alignment { + func calculatePriorityPopupPaddingValue(for edge: PopupAlignment) -> CGFloat { switch edge == alignment { case true: 0 case false: getActivePopupConfig().popupPadding[!edge] }} @@ -215,7 +215,7 @@ private extension VM.VerticalStack { // MARK: Corner Radius private extension VM.VerticalStack { - func _calculateCornerRadius() -> [VerticalEdge: CGFloat] { + func _calculateCornerRadius() -> [PopupAlignment: CGFloat] { let cornerRadiusValue = calculateCornerRadiusValue(getActivePopupConfig()) return [ .top: calculateTopCornerRadius(cornerRadiusValue), @@ -224,7 +224,7 @@ private extension VM.VerticalStack { } } private extension VM.VerticalStack { - func calculateCornerRadiusValue(_ activePopupConfig: Config) -> CGFloat { switch activePopupConfig.heightMode { + func calculateCornerRadiusValue(_ activePopupConfig: AnyPopupConfig) -> CGFloat { switch activePopupConfig.heightMode { case .auto, .large: activePopupConfig.cornerRadius case .fullscreen: 0 }} From 6f51c1893792663c6d1fca3601d35138ae078125 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:02:33 +0100 Subject: [PATCH 007/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index f3cdab77d3..45e25137f7 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -60,7 +60,7 @@ private extension VM.VerticalStack { }} } private extension VM.VerticalStack { - func calculateHeight(_ heightCandidate: CGFloat, _ popupConfig: Config) -> CGFloat { switch popupConfig.heightMode { + func calculateHeight(_ heightCandidate: CGFloat, _ popupConfig: AnyPopupConfig) -> CGFloat { switch popupConfig.heightMode { case .auto: min(heightCandidate, calculateLargeScreenHeight()) case .large: calculateLargeScreenHeight() case .fullscreen: getFullscreenHeight() @@ -130,27 +130,29 @@ extension VM.VerticalStack { )} } private extension VM.VerticalStack { - func calculateTopBodyPadding(activePopupHeight: CGFloat, popupConfig: Config) -> CGFloat { + func calculateTopBodyPadding(activePopupHeight: CGFloat, popupConfig: AnyPopupConfig) -> CGFloat { if popupConfig.ignoredSafeAreaEdges.contains(.top) { return 0 } return switch alignment { case .top: calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupPadding: calculatePopupPadding().top) case .bottom: calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight, safeArea: screen.safeArea.top) + case .centre: fatalError() } } - func calculateBottomBodyPadding(activePopupHeight: CGFloat, popupConfig: Config) -> CGFloat { + func calculateBottomBodyPadding(activePopupHeight: CGFloat, popupConfig: AnyPopupConfig) -> CGFloat { if popupConfig.ignoredSafeAreaEdges.contains(.bottom) && !isKeyboardActive { return 0 } return switch alignment { case .top: calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight, safeArea: screen.safeArea.bottom) case .bottom: calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupPadding: calculatePopupPadding().bottom) + case .centre: fatalError() } } - func calculateLeadingBodyPadding(popupConfig: Config) -> CGFloat { switch popupConfig.ignoredSafeAreaEdges.contains(.leading) { + func calculateLeadingBodyPadding(popupConfig: AnyPopupConfig) -> CGFloat { switch popupConfig.ignoredSafeAreaEdges.contains(.leading) { case true: 0 case false: screen.safeArea.leading }} - func calculateTrailingBodyPadding(popupConfig: Config) -> CGFloat { switch popupConfig.ignoredSafeAreaEdges.contains(.trailing) { + func calculateTrailingBodyPadding(popupConfig: AnyPopupConfig) -> CGFloat { switch popupConfig.ignoredSafeAreaEdges.contains(.trailing) { case true: 0 case false: screen.safeArea.trailing }} From b48420e5cc9cbf2c07c3534efd26de787e807263 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:03:53 +0100 Subject: [PATCH 008/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 45e25137f7..36315dcf91 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -11,9 +11,8 @@ import SwiftUI -extension VM { class VerticalStack: ViewModel { +extension VM { class VerticalStack: ViewModel { // MARK: Attributes - private(set) var alignment: VerticalEdge private(set) var gestureTranslation: CGFloat = 0 private(set) var translationProgress: CGFloat = 0 From ce20b7ecb5a3d80c9e7d3a33df530ee8fd2be2ec Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:04:08 +0100 Subject: [PATCH 009/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 36315dcf91..347e400085 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -20,11 +20,8 @@ extension VM { class VerticalStack: ViewModel CGFloat? { _calculateHeightForActivePopup() } override func calculatePopupPadding() -> EdgeInsets { _calculatePopupPadding() } - override func calculateCornerRadius() -> [VerticalEdge : CGFloat] { _calculateCornerRadius() } + override func calculateCornerRadius() -> [PopupAlignment : CGFloat] { _calculateCornerRadius() } override func calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { _calculateVerticalFixedSize(for: popup) } - - // MARK: Initialise - override init() { self.alignment = .init(Config.self) } }} From 8e3487fd041a16c17fbbb4f6d2d895eae0297920 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:07:23 +0100 Subject: [PATCH 010/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index c8650c81b4..05d5f869b5 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -14,6 +14,7 @@ import SwiftUI enum VM {} class ViewModel: ViewModelObject { // MARK: Attributes + private(set) var alignment: PopupAlignment private(set) var popups: [AnyPopup] = [] private(set) var updatePopupAction: ((AnyPopup) -> ())! private(set) var closePopupAction: ((AnyPopup) -> ())! @@ -27,8 +28,11 @@ class ViewModel: ViewModelObject { func recalculateAndSave(height: CGFloat, for popup: AnyPopup) { fatalError() } func calculateHeightForActivePopup() -> CGFloat? { fatalError() } func calculatePopupPadding() -> EdgeInsets { fatalError() } - func calculateCornerRadius() -> [VerticalEdge: CGFloat] { fatalError() } + func calculateCornerRadius() -> [PopupAlignment: CGFloat] { fatalError() } func calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { fatalError() } + + // MARK: Initializer + init() { self.alignment = .init(Config.self) } } // MARK: Setup @@ -42,7 +46,7 @@ extension ViewModel { // MARK: Update extension ViewModel { func updatePopupsValue(_ newPopups: [AnyPopup]) { - popups = newPopups.filter { $0.config is Config } + popups = newPopups.filter { $0.alignment == alignment } activePopupHeight = calculateHeightForActivePopup() withAnimation(.transition) { objectWillChange.send() } @@ -66,11 +70,11 @@ extension ViewModel { }} } extension ViewModel { - func getConfig(_ item: AnyPopup?) -> Config { - let config = item?.config as? Config + func getConfig(_ item: AnyPopup?) -> AnyPopupConfig { + let config = item?.config return config ?? .init() } - func getActivePopupConfig() -> Config { + func getActivePopupConfig() -> AnyPopupConfig { getConfig(popups.last) } } From 74fa7f98978c019d8ea4154e15aff5b9957ed88c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:27:05 +0100 Subject: [PATCH 011/407] 1 --- .../Configurables/Local/LocalConfig.swift | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/Configurables/Local/LocalConfig.swift b/Sources/Internal/Configurables/Local/LocalConfig.swift index eaf824c455..4b280cd8ff 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig.swift @@ -11,10 +11,17 @@ import SwiftUI -public class LocalConfig { required init() {} - var popupPadding: EdgeInsets = .init() - var cornerRadius: CGFloat = 0 - var backgroundColor: Color = .clear - var overlayColor: Color = .clear - var isTapOutsideToDismissEnabled: Bool = false +public protocol LocalConfig { init() + // MARK: Content + var popupPadding: EdgeInsets { get set } + var cornerRadius: CGFloat { get set } + var ignoredSafeAreaEdges: Edge.Set { get set } + var backgroundColor: Color { get set } + var overlayColor: Color { get set } + var heightMode: HeightMode { get set } + var dragDetents: [DragDetent] { get set } + + // MARK: Gestures + var isTapOutsideToDismissEnabled: Bool { get set } + var isDragGestureEnabled: Bool { get set } } From 60266296113e5ad9ae12effc66b5bba5e0910e79 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:31:54 +0100 Subject: [PATCH 012/407] 1 --- .../Internal/Configurables/Local/LocalConfig+Centre.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift index d4545bef8e..337c0196cd 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift @@ -28,7 +28,7 @@ public extension LocalConfig { class Centre: LocalConfig { - important: If a certain method is not called here, the popup inherits the configuration from ``GlobalConfigContainer``. */ -public typealias CentrePopupConfig = LocalConfig.Centre +public typealias CentrePopupConfig = LocalConfigCentre @@ -37,9 +37,9 @@ public typealias CentrePopupConfig = LocalConfig.Centre -extension LocalConfig.Centre { - static func t_createNew(popupPadding: EdgeInsets, cornerRadius: CGFloat) -> LocalConfig.Centre { - let config = LocalConfig.Centre() +extension LocalConfigCentre { + static func t_createNew(popupPadding: EdgeInsets, cornerRadius: CGFloat) -> LocalConfigCentre { + let config = LocalConfigCentre() config.popupPadding = popupPadding config.cornerRadius = cornerRadius return config From 6defb1f403eb66446c07f431879ee4a0edc597e3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:33:08 +0100 Subject: [PATCH 013/407] 1 --- .../Local/LocalConfig+Centre.swift | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift index 337c0196cd..d6604bf0d5 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift @@ -11,15 +11,20 @@ import SwiftUI -public extension LocalConfig { class Centre: LocalConfig { - required init() { super.init() - self.popupPadding = GlobalConfigContainer.centre.popupPadding - self.cornerRadius = GlobalConfigContainer.centre.cornerRadius - self.backgroundColor = GlobalConfigContainer.centre.backgroundColor - self.overlayColor = GlobalConfigContainer.centre.overlayColor - self.isTapOutsideToDismissEnabled = GlobalConfigContainer.centre.isTapOutsideToDismissEnabled - } -}} +public class LocalConfigCentre: LocalConfig { required public init() {} + // MARK: Active Variables + public var popupPadding: EdgeInsets = GlobalConfigContainer.centre.popupPadding + public var cornerRadius: CGFloat = GlobalConfigContainer.centre.cornerRadius + public var backgroundColor: Color = GlobalConfigContainer.centre.backgroundColor + public var overlayColor: Color = GlobalConfigContainer.centre.overlayColor + public var isTapOutsideToDismissEnabled: Bool = GlobalConfigContainer.centre.isTapOutsideToDismissEnabled + + // MARK: Inactive Variables + public var ignoredSafeAreaEdges: Edge.Set = [] + public var heightMode: HeightMode = .auto + public var dragDetents: [DragDetent] = [] + public var isDragGestureEnabled: Bool = false +} // MARK: Typealias /** From 19d07dd3b3d059b80169e006a705dfeb4274762a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:36:43 +0100 Subject: [PATCH 014/407] 1 --- .../Configurables/Local/LocalConfig+Vertical.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift index 618cdd0434..187a508c81 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift @@ -34,7 +34,7 @@ public extension LocalConfig { class Vertical: LocalConfig { - important: If a certain method is not called here, the popup inherits the configuration from ``GlobalConfigContainer``. */ -public typealias TopPopupConfig = LocalConfig.Vertical.Top +public typealias TopPopupConfig = LocalConfigVertical.Top /** Configures the popup. @@ -42,10 +42,10 @@ public typealias TopPopupConfig = LocalConfig.Vertical.Top - 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 {} - class Bottom: LocalConfig.Vertical {} +public typealias BottomPopupConfig = LocalConfigVertical.Bottom +public extension LocalConfigVertical { + class Top: LocalConfigVertical {} + class Bottom: LocalConfigVertical {} } @@ -55,8 +55,8 @@ public extension LocalConfig.Vertical { -extension LocalConfig.Vertical { - static func t_createNew(popupPadding: EdgeInsets, cornerRadius: CGFloat, ignoredSafeAreaEdges: Edge.Set, heightMode: HeightMode, dragDetents: [DragDetent], isDragGestureEnabled: Bool) -> C { +extension LocalConfigVertical { + static func t_createNew(popupPadding: EdgeInsets, cornerRadius: CGFloat, ignoredSafeAreaEdges: Edge.Set, heightMode: HeightMode, dragDetents: [DragDetent], isDragGestureEnabled: Bool) -> C { let config = C() config.popupPadding = popupPadding config.cornerRadius = cornerRadius From 1c57125160f7f44f0e793fe58c90acd41177ba74 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:42:40 +0100 Subject: [PATCH 015/407] 1 --- .../Local/LocalConfig+Vertical.swift | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift index 187a508c81..55da79b34c 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift @@ -11,21 +11,20 @@ import SwiftUI -public extension LocalConfig { class Vertical: LocalConfig { - var ignoredSafeAreaEdges: Edge.Set = [] - var heightMode: HeightMode = .auto - var dragDetents: [DragDetent] = [] - var isDragGestureEnabled: Bool = GlobalConfigContainer.vertical.isDragGestureEnabled +public class LocalConfigVertical: LocalConfig { required public init() {} + // MARK: Content + public var popupPadding: EdgeInsets = GlobalConfigContainer.vertical.popupPadding + public var cornerRadius: CGFloat = GlobalConfigContainer.vertical.cornerRadius + public var ignoredSafeAreaEdges: Edge.Set = [] + public var backgroundColor: Color = GlobalConfigContainer.vertical.backgroundColor + public var overlayColor: Color = GlobalConfigContainer.vertical.overlayColor + public var heightMode: HeightMode = .auto + public var dragDetents: [DragDetent] = [] - - required init() { super.init() - self.popupPadding = GlobalConfigContainer.vertical.popupPadding - self.cornerRadius = GlobalConfigContainer.vertical.cornerRadius - self.backgroundColor = GlobalConfigContainer.vertical.backgroundColor - self.overlayColor = GlobalConfigContainer.vertical.overlayColor - self.isTapOutsideToDismissEnabled = GlobalConfigContainer.vertical.isTapOutsideToDismissEnabled - } -}} + // MARK: Gestures + public var isTapOutsideToDismissEnabled: Bool = GlobalConfigContainer.vertical.isTapOutsideToDismissEnabled + public var isDragGestureEnabled: Bool = GlobalConfigContainer.vertical.isDragGestureEnabled +} // MARK: Subclasses & Typealiases /** From 73b777c2905a924137e0a9af70643bd77f348574 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:44:56 +0100 Subject: [PATCH 016/407] 1 --- .../Public/Popup/Public+Popup+Config.swift | 59 ++++++++++++++++++- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/Sources/Public/Popup/Public+Popup+Config.swift b/Sources/Public/Popup/Public+Popup+Config.swift index 02a75adc12..a11b444ce8 100644 --- a/Sources/Public/Popup/Public+Popup+Config.swift +++ b/Sources/Public/Popup/Public+Popup+Config.swift @@ -11,8 +11,61 @@ import SwiftUI -// MARK: Vertical & Centre -public extension LocalConfig { +// MARK: Centre +public extension LocalConfigCentre { + /** + Distance of the entire popup (including its background) from the horizontal edges of the screen. + + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/horizontal-padding.png?raw=true) + */ + func popupHorizontalPadding(_ value: CGFloat) -> Self { self.popupPadding = .init(top: popupPadding.top, leading: value, bottom: popupPadding.bottom, trailing: value); return self } + + /** + Corner radius of the background of the active popup. + + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/corner-radius.png?raw=true) + */ + func cornerRadius(_ value: CGFloat) -> Self { self.cornerRadius = value; return self } + + /** + Background color of the popup. + + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/background-color.png?raw=true) + */ + func backgroundColor(_ color: Color) -> Self { self.backgroundColor = color; return self } + + /** + The color of the overlay covering the view behind the popup. + + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/overlay-color.png?raw=true) + + - tip: Use .clear to hide the overlay. + */ + func overlayColor(_ color: Color) -> Self { self.overlayColor = color; return self } + + /** + If enabled, dismisses the active popup when touched outside its area. + + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/tap-to-close.png?raw=true) + */ + func tapOutsideToDismissPopup(_ value: Bool) -> Self { self.isTapOutsideToDismissEnabled = value; return self } +} + + + + + + + + + +// MARK: Vertical +public extension LocalConfigVertical { /** Distance of the entire popup (including its background) from the horizontal edges of the screen. @@ -57,7 +110,7 @@ public extension LocalConfig { } // MARK: Only Vertical -public extension LocalConfig.Vertical { +public extension LocalConfigVertical { /** Distance of the entire popup (including its background) from the top edge of the screen. From 14103cce3de4b056fdf1f3c7acc33a17eb4c2081 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:48:03 +0100 Subject: [PATCH 017/407] 1 --- .../Public/Popup/Public+Popup+Config.swift | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/Sources/Public/Popup/Public+Popup+Config.swift b/Sources/Public/Popup/Public+Popup+Config.swift index a11b444ce8..f49cc34b5e 100644 --- a/Sources/Public/Popup/Public+Popup+Config.swift +++ b/Sources/Public/Popup/Public+Popup+Config.swift @@ -56,16 +56,24 @@ public extension LocalConfigCentre { func tapOutsideToDismissPopup(_ value: Bool) -> Self { self.isTapOutsideToDismissEnabled = value; return self } } +// MARK: Vertical +public extension LocalConfigVertical { + /** + Distance of the entire popup (including its background) from the top edge of the screen. + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/top-padding.png?raw=true) + */ + func popupTopPadding(_ value: CGFloat) -> Self { self.popupPadding = .init(top: value, leading: popupPadding.leading, bottom: popupPadding.bottom, trailing: popupPadding.trailing); return self } + /** + Distance of the entire popup (including its background) from the bottom edge of the screen. + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/bottom-padding.png?raw=true) + */ + func popupBottomPadding(_ value: CGFloat) -> Self { self.popupPadding = .init(top: popupPadding.top, leading: popupPadding.leading, bottom: value, trailing: popupPadding.trailing); return self } - - - - -// MARK: Vertical -public extension LocalConfigVertical { /** Distance of the entire popup (including its background) from the horizontal edges of the screen. @@ -111,22 +119,6 @@ public extension LocalConfigVertical { // MARK: Only Vertical public extension LocalConfigVertical { - /** - Distance of the entire popup (including its background) from the top edge of the screen. - - ## Visualisation - ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/top-padding.png?raw=true) - */ - func popupTopPadding(_ value: CGFloat) -> Self { self.popupPadding = .init(top: value, leading: popupPadding.leading, bottom: popupPadding.bottom, trailing: popupPadding.trailing); return self } - - /** - Distance of the entire popup (including its background) from the bottom edge of the screen. - - ## Visualisation - ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/bottom-padding.png?raw=true) - */ - func popupBottomPadding(_ value: CGFloat) -> Self { self.popupPadding = .init(top: popupPadding.top, leading: popupPadding.leading, bottom: value, trailing: popupPadding.trailing); return self } - /** Expands the safe area of a popup. From f0fcf1037d4d18f639cf35b95d142d90a9e0a367 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:49:28 +0100 Subject: [PATCH 018/407] 1 --- .../Public/Popup/Public+Popup+Config.swift | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/Sources/Public/Popup/Public+Popup+Config.swift b/Sources/Public/Popup/Public+Popup+Config.swift index f49cc34b5e..9cf9df520a 100644 --- a/Sources/Public/Popup/Public+Popup+Config.swift +++ b/Sources/Public/Popup/Public+Popup+Config.swift @@ -90,6 +90,17 @@ public extension LocalConfigVertical { */ func cornerRadius(_ value: CGFloat) -> Self { self.cornerRadius = value; return self } + /** + Expands the safe area of a popup. + + - Parameters: + - edges: The regions to expand the popup’s safe area into. + + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/ignore-safe-area.png?raw=true) + */ + func ignoreSafeArea(edges: Edge.Set) -> Self { self.ignoredSafeAreaEdges = edges; return self } + /** Background color of the popup. @@ -108,28 +119,6 @@ public extension LocalConfigVertical { */ func overlayColor(_ color: Color) -> Self { self.overlayColor = color; return self } - /** - If enabled, dismisses the active popup when touched outside its area. - - ## Visualisation - ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/tap-to-close.png?raw=true) - */ - func tapOutsideToDismissPopup(_ value: Bool) -> Self { self.isTapOutsideToDismissEnabled = value; return self } -} - -// MARK: Only Vertical -public extension LocalConfigVertical { - /** - Expands the safe area of a popup. - - - Parameters: - - edges: The regions to expand the popup’s safe area into. - - ## Visualisation - ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/ignore-safe-area.png?raw=true) - */ - func ignoreSafeArea(edges: Edge.Set) -> Self { self.ignoredSafeAreaEdges = edges; return self } - /** Sets the height for the popup. By default, the height of the popup is calculated based on its content. @@ -146,6 +135,14 @@ public extension LocalConfigVertical { */ func dragDetents(_ value: [DragDetent]) -> Self { self.dragDetents = value; return self } + /** + If enabled, dismisses the active popup when touched outside its area. + + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/tap-to-close.png?raw=true) + */ + func tapOutsideToDismissPopup(_ value: Bool) -> Self { self.isTapOutsideToDismissEnabled = value; return self } + /** Determines whether it's possible to interact with popups using a drag gesture. From fe849670eddcf827a5162bec60ea5fc4c1864d72 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:50:38 +0100 Subject: [PATCH 019/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 76c1b145da..be4a2ce67b 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -67,7 +67,7 @@ private extension AnyPopup { // MARK: Popup -extension AnyPopup { typealias Config = LocalConfig +extension AnyPopup { typealias Config = AnyPopupConfig var body: some View { _body } func onFocus() { _onFocus() } From 8e199172902dd639ff3301efe768064428da5724 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:50:53 +0100 Subject: [PATCH 020/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index be4a2ce67b..2d74e68721 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -13,7 +13,8 @@ import SwiftUI struct AnyPopup: Popup { private(set) var id: PopupID - private(set) var config: LocalConfig + private(set) var alignment: PopupAlignment + private(set) var config: AnyPopupConfig private(set) var height: CGFloat? = nil private(set) var dragHeight: CGFloat? = nil From b493e30cb026f23127f48d4fe112b430f0b2b755 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:51:51 +0100 Subject: [PATCH 021/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 2d74e68721..593dc42004 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -36,7 +36,8 @@ extension AnyPopup { if let popup = popup as? AnyPopup { self = popup } else { self.id = .create(from: P.self) - self.config = popup.configurePopup(config: .init()) + self.alignment = .init(P.Config.self) + self.config = .init(popup.configurePopup(config: .init())) self._body = AnyView(popup) self._onFocus = popup.onFocus self._onDismiss = popup.onDismiss @@ -92,7 +93,8 @@ extension AnyPopup: Hashable { extension AnyPopup { static func t_createNew(id: String = UUID().uuidString, config: LocalConfig) -> AnyPopup { .init( id: .create(from: id), - config: config, + alignment: .init(Config.self), + config: .init(config), height: nil, dragHeight: nil, dismissTimer: nil, From 829edd646a09135c83e8b69fa3be19fa0c265454 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:56:05 +0100 Subject: [PATCH 022/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 347e400085..7631d30e00 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -118,7 +118,7 @@ private extension VM.VerticalStack { // MARK: Body Padding extension VM.VerticalStack { - func calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { let activePopupHeight = activePopupHeight ?? 0, popupConfig = getConfig(popup); return .init( + func calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { let activePopupHeight = activePopupHeight ?? 0, popupConfig = popup.config; return .init( top: calculateTopBodyPadding(activePopupHeight: activePopupHeight, popupConfig: popupConfig), leading: calculateLeadingBodyPadding(popupConfig: popupConfig), bottom: calculateBottomBodyPadding(activePopupHeight: activePopupHeight, popupConfig: popupConfig), @@ -240,7 +240,7 @@ private extension VM.VerticalStack { // MARK: Fixed Size private extension VM.VerticalStack { - func _calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { switch getConfig(popup).heightMode { + func _calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { switch popup.config.heightMode { case .fullscreen, .large: false case .auto: activePopupHeight != calculateLargeScreenHeight() }} From aafe9aa71435ef4e6cb7be183983ac085ee7b464 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 19:56:40 +0100 Subject: [PATCH 023/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 7631d30e00..b1efd227b5 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -50,8 +50,7 @@ private extension VM.VerticalStack { // MARK: Recalculate & Update Popup Height private extension VM.VerticalStack { func _recalculateAndSave(height: CGFloat, for popup: AnyPopup) { if gestureTranslation.isZero, height != popup.height { - let popupConfig = getConfig(popup) - let newHeight = calculateHeight(height, popupConfig) + let newHeight = calculateHeight(height, popup.config) updateHeight(newHeight, popup) }} } From dd8b0e30cdb795707779fb6760fdfc4bfa79699f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 20:04:15 +0100 Subject: [PATCH 024/407] 1 --- Sources/Internal/Models/AnyPopupConfig.swift | 40 ++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Sources/Internal/Models/AnyPopupConfig.swift diff --git a/Sources/Internal/Models/AnyPopupConfig.swift b/Sources/Internal/Models/AnyPopupConfig.swift new file mode 100644 index 0000000000..8d6db1de08 --- /dev/null +++ b/Sources/Internal/Models/AnyPopupConfig.swift @@ -0,0 +1,40 @@ +// +// AnyPopupConfig.swift of MijickPopups +// +// Created by Tomasz Kurylik. Sending ❤️ from Kraków! +// - Mail: tomasz.kurylik@mijick.com +// - GitHub: https://github.com/FulcrumOne +// - Medium: https://medium.com/@mijick +// +// Copyright ©2024 Mijick. All rights reserved. + + +import SwiftUI + +struct AnyPopupConfig: LocalConfig, Sendable { init() {} + // MARK: Content + var popupPadding: EdgeInsets = .init() + var cornerRadius: CGFloat = 0 + var ignoredSafeAreaEdges: Edge.Set = [] + var backgroundColor: Color = .clear + var overlayColor: Color = .clear + var heightMode: HeightMode = .auto + var dragDetents: [DragDetent] = [] + + // MARK: Gestures + var isTapOutsideToDismissEnabled: Bool = false + var isDragGestureEnabled: Bool = false + + // MARK: Initializer + init(_ config: any LocalConfig) { + self.popupPadding = config.popupPadding + self.cornerRadius = config.cornerRadius + self.ignoredSafeAreaEdges = config.ignoredSafeAreaEdges + self.backgroundColor = config.backgroundColor + self.overlayColor = config.overlayColor + self.heightMode = config.heightMode + self.dragDetents = config.dragDetents + self.isTapOutsideToDismissEnabled = config.isTapOutsideToDismissEnabled + self.isDragGestureEnabled = config.isDragGestureEnabled + } +} From 487600a6bbd52991922118cf9965828269bbd3e3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 20:06:40 +0100 Subject: [PATCH 025/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 593dc42004..e5a6cf64bf 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -13,7 +13,6 @@ import SwiftUI struct AnyPopup: Popup { private(set) var id: PopupID - private(set) var alignment: PopupAlignment private(set) var config: AnyPopupConfig private(set) var height: CGFloat? = nil private(set) var dragHeight: CGFloat? = nil @@ -36,7 +35,6 @@ extension AnyPopup { if let popup = popup as? AnyPopup { self = popup } else { self.id = .create(from: P.self) - self.alignment = .init(P.Config.self) self.config = .init(popup.configurePopup(config: .init())) self._body = AnyView(popup) self._onFocus = popup.onFocus @@ -93,7 +91,6 @@ extension AnyPopup: Hashable { extension AnyPopup { static func t_createNew(id: String = UUID().uuidString, config: LocalConfig) -> AnyPopup { .init( id: .create(from: id), - alignment: .init(Config.self), config: .init(config), height: nil, dragHeight: nil, From e4c2c9cc7366ac0388c7e6dcd628e5eea5a936cb Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 20:06:53 +0100 Subject: [PATCH 026/407] 1 --- Sources/Internal/Models/StackPriority.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/Models/StackPriority.swift b/Sources/Internal/Models/StackPriority.swift index c26cbbec57..d891a878e5 100644 --- a/Sources/Internal/Models/StackPriority.swift +++ b/Sources/Internal/Models/StackPriority.swift @@ -22,7 +22,7 @@ struct StackPriority: Equatable { // MARK: Reshuffle extension StackPriority { - @MainActor mutating func reshuffle(newPopups: [AnyPopup]) { switch newPopups.last?.alignment { + @MainActor mutating func reshuffle(newPopups: [AnyPopup]) { switch newPopups.last?.config.alignment { case .top: reshuffle(0) case .centre: reshuffle(1) case .bottom: reshuffle(2) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 05d5f869b5..3ef0c1054d 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -46,7 +46,7 @@ extension ViewModel { // MARK: Update extension ViewModel { func updatePopupsValue(_ newPopups: [AnyPopup]) { - popups = newPopups.filter { $0.alignment == alignment } + popups = newPopups.filter { $0.config.alignment == alignment } activePopupHeight = calculateHeightForActivePopup() withAnimation(.transition) { objectWillChange.send() } From 0bafdcea6fd718e226df0be81680ec651a9d99f3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 20:07:23 +0100 Subject: [PATCH 027/407] 1 --- Sources/Internal/Models/AnyPopupConfig.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Internal/Models/AnyPopupConfig.swift b/Sources/Internal/Models/AnyPopupConfig.swift index 8d6db1de08..1a1b1094a9 100644 --- a/Sources/Internal/Models/AnyPopupConfig.swift +++ b/Sources/Internal/Models/AnyPopupConfig.swift @@ -26,7 +26,8 @@ struct AnyPopupConfig: LocalConfig, Sendable { init() {} var isDragGestureEnabled: Bool = false // MARK: Initializer - init(_ config: any LocalConfig) { + init(_ config: Config) { + self.alignment = .init(Config.self) self.popupPadding = config.popupPadding self.cornerRadius = config.cornerRadius self.ignoredSafeAreaEdges = config.ignoredSafeAreaEdges From 08030852b283200cb460df3f00db1becf35d5d16 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 20:07:54 +0100 Subject: [PATCH 028/407] 1 --- Sources/Internal/Models/AnyPopupConfig.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Internal/Models/AnyPopupConfig.swift b/Sources/Internal/Models/AnyPopupConfig.swift index 1a1b1094a9..2009dbed2a 100644 --- a/Sources/Internal/Models/AnyPopupConfig.swift +++ b/Sources/Internal/Models/AnyPopupConfig.swift @@ -13,6 +13,7 @@ import SwiftUI struct AnyPopupConfig: LocalConfig, Sendable { init() {} // MARK: Content + var alignment: PopupAlignment = .centre var popupPadding: EdgeInsets = .init() var cornerRadius: CGFloat = 0 var ignoredSafeAreaEdges: Edge.Set = [] From a8189d566634df6f56518c92070d9a4f5820c24c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 20:15:06 +0100 Subject: [PATCH 029/407] 1 --- Sources/Internal/UI/PopupView.swift | 6 +++--- Sources/Internal/View Models/ViewModel+CentreStack.swift | 2 +- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index d477887a6d..77f445efdd 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -17,9 +17,9 @@ struct PopupView: View { #endif @ObservedObject var popupManager: PopupManager - private let topStackViewModel: VM.VerticalStack = .init() - private let centreStackViewModel: VM.CentreStack = .init() - private let bottomStackViewModel: VM.VerticalStack = .init() + private let topStackViewModel: VM.VerticalStack = .init(TopPopupConfig.self) + private let centreStackViewModel: VM.CentreStack = .init(CentrePopupConfig.self) + private let bottomStackViewModel: VM.VerticalStack = .init(BottomPopupConfig.self) var body: some View { diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index c8d78d057e..54cd6f6ced 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -11,7 +11,7 @@ import SwiftUI -extension VM { class CentreStack: ViewModel { +extension VM { class CentreStack: ViewModel { // MARK: Overridden Methods override func recalculateAndSave(height: CGFloat, for popup: AnyPopup) { _recalculateAndSave(height: height, for: popup) } override func calculateHeightForActivePopup() -> CGFloat? { _calculateHeightForActivePopup() } diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index b1efd227b5..7afb03c948 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -11,7 +11,7 @@ import SwiftUI -extension VM { class VerticalStack: ViewModel { +extension VM { class VerticalStack: ViewModel { // MARK: Attributes private(set) var gestureTranslation: CGFloat = 0 private(set) var translationProgress: CGFloat = 0 diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 3ef0c1054d..97274ceb63 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -12,7 +12,7 @@ import SwiftUI enum VM {} -class ViewModel: ViewModelObject { +class ViewModel: ViewModelObject { // MARK: Attributes private(set) var alignment: PopupAlignment private(set) var popups: [AnyPopup] = [] @@ -32,7 +32,7 @@ class ViewModel: ViewModelObject { func calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { fatalError() } // MARK: Initializer - init() { self.alignment = .init(Config.self) } + init(_ config: Config.Type) { self.alignment = .init(Config.self) } } // MARK: Setup From 886de59997528a4922073c0f33e5604172a30ff8 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 20:15:26 +0100 Subject: [PATCH 030/407] 1 --- Sources/Internal/UI/PopupVerticalStackView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index 2637b4567a..d4c7cdfc83 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -11,8 +11,8 @@ import SwiftUI -struct PopupVerticalStackView: View { - @ObservedObject var viewModel: VM.VerticalStack +struct PopupVerticalStackView: View { + @ObservedObject var viewModel: VM.VerticalStack var body: some View { From 5cddadd11faef7c988c9793ba050e8751ba3eeef Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 20:16:41 +0100 Subject: [PATCH 031/407] 1 --- Sources/Internal/UI/PopupView.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 2 +- .../View Models/ViewModelObject.swift | 19 ------------------- 3 files changed, 2 insertions(+), 21 deletions(-) delete mode 100644 Sources/Internal/View Models/ViewModelObject.swift diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 77f445efdd..43dfa29b35 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -114,7 +114,7 @@ private extension PopupView { func closePopup(_ popup: AnyPopup) { popupManager.stack(.removePopupInstance(popup)) } - func updateViewModels(_ updateBuilder: (any ViewModelObject) -> ()) { + func updateViewModels(_ updateBuilder: (ViewModel) -> ()) { [topStackViewModel, centreStackViewModel, bottomStackViewModel].forEach(updateBuilder) } } diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 97274ceb63..55067d694e 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -12,7 +12,7 @@ import SwiftUI enum VM {} -class ViewModel: ViewModelObject { +@MainActor class ViewModel: ObservableObject { // MARK: Attributes private(set) var alignment: PopupAlignment private(set) var popups: [AnyPopup] = [] diff --git a/Sources/Internal/View Models/ViewModelObject.swift b/Sources/Internal/View Models/ViewModelObject.swift deleted file mode 100644 index a72f92b555..0000000000 --- a/Sources/Internal/View Models/ViewModelObject.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// ViewModelObject.swift of MijickPopups -// -// Created by Tomasz Kurylik. Sending ❤️ from Kraków! -// - Mail: tomasz.kurylik@mijick.com -// - GitHub: https://github.com/FulcrumOne -// - Medium: https://medium.com/@mijick -// -// Copyright ©2024 Mijick. All rights reserved. - - -import SwiftUI - -@MainActor protocol ViewModelObject: ObservableObject { - func setup(updatePopupAction: @escaping (AnyPopup) -> (), closePopupAction: @escaping (AnyPopup) -> ()) - func updatePopupsValue(_ newPopups: [AnyPopup]) - func updateScreenValue(_ newScreen: Screen) - func updateKeyboardValue(_ isActive: Bool) -} From 22d996da40550252cd3cbbb7eeb3433c9a27fd77 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 6 Nov 2024 23:38:52 +0100 Subject: [PATCH 032/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 55067d694e..0a987ca853 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -70,12 +70,8 @@ extension ViewModel { }} } extension ViewModel { - func getConfig(_ item: AnyPopup?) -> AnyPopupConfig { - let config = item?.config - return config ?? .init() - } func getActivePopupConfig() -> AnyPopupConfig { - getConfig(popups.last) + popups.last?.config ?? .init() } } From 5dee1f828a94cfd9f471c224365975ef3e7cdfef Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 00:57:54 +0100 Subject: [PATCH 033/407] 1 --- .../Internal/Configurables/Local/LocalConfig+Centre.swift | 8 ++++---- Sources/Internal/Containers/GlobalConfigContainer.swift | 6 +++--- Sources/Public/Setup/Public+Setup+Config.swift | 2 +- Sources/Public/Setup/Public+Setup+ConfigContainer.swift | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift index d6604bf0d5..e30b85e00d 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift @@ -20,10 +20,10 @@ public class LocalConfigCentre: LocalConfig { required public init() {} public var isTapOutsideToDismissEnabled: Bool = GlobalConfigContainer.centre.isTapOutsideToDismissEnabled // MARK: Inactive Variables - public var ignoredSafeAreaEdges: Edge.Set = [] - public var heightMode: HeightMode = .auto - public var dragDetents: [DragDetent] = [] - public var isDragGestureEnabled: Bool = false + public var ignoredSafeAreaEdges: Edge.Set = GlobalConfigContainer.centre.ignoredSafeAreaEdges + public var heightMode: HeightMode = GlobalConfigContainer.centre.heightMode + public var dragDetents: [DragDetent] = GlobalConfigContainer.centre.dragDetents + public var isDragGestureEnabled: Bool = GlobalConfigContainer.centre.isDragGestureEnabled } // MARK: Typealias diff --git a/Sources/Internal/Containers/GlobalConfigContainer.swift b/Sources/Internal/Containers/GlobalConfigContainer.swift index 27347b4d27..4f1f3f8285 100644 --- a/Sources/Internal/Containers/GlobalConfigContainer.swift +++ b/Sources/Internal/Containers/GlobalConfigContainer.swift @@ -9,7 +9,7 @@ // Copyright ©2023 Mijick. All rights reserved. -public class GlobalConfigContainer { - nonisolated(unsafe) static var centre: GlobalConfig.Centre = .init() - nonisolated(unsafe) static var vertical: GlobalConfig.Vertical = .init() +public actor GlobalConfigContainer { + static var centre: GlobalConfigCentre = .init() + static var vertical: GlobalConfigVertical = .init() } diff --git a/Sources/Public/Setup/Public+Setup+Config.swift b/Sources/Public/Setup/Public+Setup+Config.swift index 4c1485233d..47314dba90 100644 --- a/Sources/Public/Setup/Public+Setup+Config.swift +++ b/Sources/Public/Setup/Public+Setup+Config.swift @@ -12,7 +12,7 @@ import SwiftUI // MARK: Vertical & Centre -public extension GlobalConfig { +public extension GlobalConfigCentre { /** Distance of the entire popup (including its background) from the horizontal edges of the screen. diff --git a/Sources/Public/Setup/Public+Setup+ConfigContainer.swift b/Sources/Public/Setup/Public+Setup+ConfigContainer.swift index cbf5d77940..05549e1ad7 100644 --- a/Sources/Public/Setup/Public+Setup+ConfigContainer.swift +++ b/Sources/Public/Setup/Public+Setup+ConfigContainer.swift @@ -15,12 +15,12 @@ public extension GlobalConfigContainer { Use the ``Popup/configurePopup(config:)-98ha0`` method to change the configuration for a specific popup. See the list of available methods in ``GlobalConfig``. */ - func centre(_ builder: (GlobalConfig.Centre) -> GlobalConfig.Centre) -> Self { Self.centre = builder(.init()); return self } + func centre(_ builder: (GlobalConfigCentre) -> GlobalConfigCentre) -> Self { Self.centre = builder(.init()); return self } /** Default configuration for all top and bottom popups. Use the ``Popup/configurePopup(config:)-98ha0`` method to change the configuration for a specific popup. See the list of available methods in ``GlobalConfig`` and ``GlobalConfig/Vertical``. */ - func vertical(_ builder: (GlobalConfig.Vertical) -> GlobalConfig.Vertical) -> Self { Self.vertical = builder(.init()); return self } + func vertical(_ builder: (GlobalConfigVertical) -> GlobalConfigVertical) -> Self { Self.vertical = builder(.init()); return self } } From 0371b4f266b50cade92c37577534ccec1d8813a6 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 00:58:59 +0100 Subject: [PATCH 034/407] 1 --- .../Internal/Configurables/Local/LocalConfig+Vertical.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift index 55da79b34c..77fac00eba 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift @@ -15,11 +15,11 @@ public class LocalConfigVertical: LocalConfig { required public init() {} // MARK: Content public var popupPadding: EdgeInsets = GlobalConfigContainer.vertical.popupPadding public var cornerRadius: CGFloat = GlobalConfigContainer.vertical.cornerRadius - public var ignoredSafeAreaEdges: Edge.Set = [] + public var ignoredSafeAreaEdges: Edge.Set = GlobalConfigContainer.vertical.ignoredSafeAreaEdges public var backgroundColor: Color = GlobalConfigContainer.vertical.backgroundColor public var overlayColor: Color = GlobalConfigContainer.vertical.overlayColor - public var heightMode: HeightMode = .auto - public var dragDetents: [DragDetent] = [] + public var heightMode: HeightMode = GlobalConfigContainer.vertical.heightMode + public var dragDetents: [DragDetent] = GlobalConfigContainer.vertical.dragDetents // MARK: Gestures public var isTapOutsideToDismissEnabled: Bool = GlobalConfigContainer.vertical.isTapOutsideToDismissEnabled From b6e98e96229f03f17fcf924040356d0808a27538 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 00:59:57 +0100 Subject: [PATCH 035/407] 1 --- Sources/Internal/Configurables/Global/GlobalConfig.swift | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/Configurables/Global/GlobalConfig.swift b/Sources/Internal/Configurables/Global/GlobalConfig.swift index 37bbcc426d..6177de2428 100644 --- a/Sources/Internal/Configurables/Global/GlobalConfig.swift +++ b/Sources/Internal/Configurables/Global/GlobalConfig.swift @@ -11,10 +11,7 @@ import SwiftUI -public class GlobalConfig { required init() {} - var popupPadding: EdgeInsets = .init() - var cornerRadius: CGFloat = 28 - var backgroundColor: Color = .white - var overlayColor: Color = .black.opacity(0.44) - var isTapOutsideToDismissEnabled: Bool = false +public protocol GlobalConfig: LocalConfig { + var dragThreshold: CGFloat { get set } + var isStackingEnabled: Bool { get set } } From ad83053c5481794119e0378cd81ffeffd0cb8754 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 01:03:13 +0100 Subject: [PATCH 036/407] 1 --- .../Global/GlobalConfig+Centre.swift | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/Configurables/Global/GlobalConfig+Centre.swift b/Sources/Internal/Configurables/Global/GlobalConfig+Centre.swift index 5685037481..40c9d4987f 100644 --- a/Sources/Internal/Configurables/Global/GlobalConfig+Centre.swift +++ b/Sources/Internal/Configurables/Global/GlobalConfig+Centre.swift @@ -9,11 +9,21 @@ // Copyright ©2024 Mijick. All rights reserved. -import Foundation +import SwiftUI -public extension GlobalConfig { class Centre: GlobalConfig { - required init() { super.init() - self.popupPadding = .init(top: 0, leading: 16, bottom: 0, trailing: 16) - self.cornerRadius = 24 - } -}} +public final class GlobalConfigCentre: GlobalConfig { required public init() {} + // MARK: Active Variables + public var popupPadding: EdgeInsets = .init(top: 0, leading: 16, bottom: 0, trailing: 16) + public var cornerRadius: CGFloat = 24 + public var backgroundColor: Color = .init(.secondarySystemBackground) + public var overlayColor: Color = .black.opacity(0.5) + public var isTapOutsideToDismissEnabled: Bool = false + + // MARK: Inactive Variables + public var ignoredSafeAreaEdges: Edge.Set = [] + public var heightMode: HeightMode = .auto + public var dragDetents: [DragDetent] = [] + public var isDragGestureEnabled: Bool = false + public var dragThreshold: CGFloat = 0 + public var isStackingEnabled: Bool = false +} From 12f19cf7f77d8731652e02500c69ab0c3b638fbb Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 01:06:00 +0100 Subject: [PATCH 037/407] 1 --- .../Global/GlobalConfig+Vertical.swift | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Sources/Internal/Configurables/Global/GlobalConfig+Vertical.swift b/Sources/Internal/Configurables/Global/GlobalConfig+Vertical.swift index bd2758af18..70992c710d 100644 --- a/Sources/Internal/Configurables/Global/GlobalConfig+Vertical.swift +++ b/Sources/Internal/Configurables/Global/GlobalConfig+Vertical.swift @@ -9,16 +9,21 @@ // Copyright ©2024 Mijick. All rights reserved. -import Foundation +import SwiftUI -public extension GlobalConfig { class Vertical: GlobalConfig { - var dragThreshold: CGFloat = 1/3 - var isStackingEnabled: Bool = true - var isDragGestureEnabled: Bool = true +public final class GlobalConfigVertical: GlobalConfig { required public init() {} + // MARK: Content + public var popupPadding: EdgeInsets = .init() + public var cornerRadius: CGFloat = 40 + public var ignoredSafeAreaEdges: Edge.Set = [] + public var backgroundColor: Color = .init(.secondarySystemBackground) + public var overlayColor: Color = .black.opacity(0.5) + public var heightMode: HeightMode = .auto + public var dragDetents: [DragDetent] = [] + public var isStackingEnabled: Bool = true - - required init() { super.init() - self.popupPadding = .init() - self.cornerRadius = 40 - } -}} + // MARK: Gestures + public var isTapOutsideToDismissEnabled: Bool = false + public var isDragGestureEnabled: Bool = true + public var dragThreshold: CGFloat = 1/3 +} From e1966210224f255008d653c38d158689ab5d3c51 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 01:10:05 +0100 Subject: [PATCH 038/407] 1 --- .../Public/Setup/Public+Setup+Config.swift | 56 ++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/Sources/Public/Setup/Public+Setup+Config.swift b/Sources/Public/Setup/Public+Setup+Config.swift index 47314dba90..e9ddcfc602 100644 --- a/Sources/Public/Setup/Public+Setup+Config.swift +++ b/Sources/Public/Setup/Public+Setup+Config.swift @@ -11,7 +11,7 @@ import SwiftUI -// MARK: Vertical & Centre +// MARK: Centre public extension GlobalConfigCentre { /** Distance of the entire popup (including its background) from the horizontal edges of the screen. @@ -56,8 +56,8 @@ public extension GlobalConfigCentre { func tapOutsideToDismissPopup(_ value: Bool) -> Self { self.isTapOutsideToDismissEnabled = value; return self } } -// MARK: Only Vertical -public extension GlobalConfig.Vertical { +// MARK: Vertical +public extension GlobalConfigVertical { /** Distance of the entire popup (including its background) from the top edge of the screen. @@ -75,14 +75,38 @@ public extension GlobalConfig.Vertical { func popupBottomPadding(_ value: CGFloat) -> Self { self.popupPadding = .init(top: popupPadding.top, leading: popupPadding.leading, bottom: value, trailing: popupPadding.trailing); return self } /** - The drag progress value above which the popup will either be dismissed or move to the next drag detent value. + Distance of the entire popup (including its background) from the horizontal edges of the screen. ## Visualisation - ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/drag-threshold.png?raw=true) + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/horizontal-padding.png?raw=true) + */ + func popupHorizontalPadding(_ value: CGFloat) -> Self { self.popupPadding = .init(top: popupPadding.top, leading: value, bottom: popupPadding.bottom, trailing: value); return self } - - important: Drag progress is calculated as **dragTranslation** / **popupHeight**, therefore drag threshold value is expected to be between 0 and 1. + /** + Corner radius of the background of the active popup. + + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/corner-radius.png?raw=true) */ - func dragThreshold(_ value: CGFloat) -> Self { self.dragThreshold = value; return self } + func cornerRadius(_ value: CGFloat) -> Self { self.cornerRadius = value; return self } + + /** + Background color of the popup. + + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/background-color.png?raw=true) + */ + func backgroundColor(_ color: Color) -> Self { self.backgroundColor = color; return self } + + /** + The color of the overlay covering the view behind the popup. + + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/overlay-color.png?raw=true) + + - tip: Use .clear to hide the overlay. + */ + func overlayColor(_ color: Color) -> Self { self.overlayColor = color; return self } /** Indicates whether stacked popups should be visible in the view. @@ -92,6 +116,14 @@ public extension GlobalConfig.Vertical { */ func enableStacking(_ value: Bool) -> Self { self.isStackingEnabled = value; return self } + /** + If enabled, dismisses the active popup when touched outside its area. + + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/tap-to-close.png?raw=true) + */ + func tapOutsideToDismissPopup(_ value: Bool) -> Self { self.isTapOutsideToDismissEnabled = value; return self } + /** Determines whether it's possible to interact with popups using a drag gesture. @@ -99,4 +131,14 @@ public extension GlobalConfig.Vertical { ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/enable-drag-gesture.png?raw=true) */ func enableDragGesture(_ value: Bool) -> Self { self.isDragGestureEnabled = value; return self } + + /** + The drag progress value above which the popup will either be dismissed or move to the next drag detent value. + + ## Visualisation + ![image](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/drag-threshold.png?raw=true) + + - important: Drag progress is calculated as **dragTranslation** / **popupHeight**, therefore drag threshold value is expected to be between 0 and 1. + */ + func dragThreshold(_ value: CGFloat) -> Self { self.dragThreshold = value; return self } } From 244a248fef8cba10d14e6a2d9e9679b81b58392d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 01:12:36 +0100 Subject: [PATCH 039/407] 1 --- .../Configurables/Global/GlobalConfig+Vertical.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/Configurables/Global/GlobalConfig+Vertical.swift b/Sources/Internal/Configurables/Global/GlobalConfig+Vertical.swift index 70992c710d..2e663e0818 100644 --- a/Sources/Internal/Configurables/Global/GlobalConfig+Vertical.swift +++ b/Sources/Internal/Configurables/Global/GlobalConfig+Vertical.swift @@ -15,15 +15,17 @@ public final class GlobalConfigVertical: GlobalConfig { required public init() { // MARK: Content public var popupPadding: EdgeInsets = .init() public var cornerRadius: CGFloat = 40 - public var ignoredSafeAreaEdges: Edge.Set = [] public var backgroundColor: Color = .init(.secondarySystemBackground) public var overlayColor: Color = .black.opacity(0.5) - public var heightMode: HeightMode = .auto - public var dragDetents: [DragDetent] = [] public var isStackingEnabled: Bool = true // MARK: Gestures public var isTapOutsideToDismissEnabled: Bool = false public var isDragGestureEnabled: Bool = true public var dragThreshold: CGFloat = 1/3 + + // MARK: Non-Customizable + public var ignoredSafeAreaEdges: Edge.Set = [] + public var heightMode: HeightMode = .auto + public var dragDetents: [DragDetent] = [] } From 47f6acbc3f62ffc3facb295fecdaa481fc83aba5 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 01:17:14 +0100 Subject: [PATCH 040/407] 1 --- Sources/Internal/Models/AnyPopupConfig.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/Internal/Models/AnyPopupConfig.swift b/Sources/Internal/Models/AnyPopupConfig.swift index 2009dbed2a..a3a320d54c 100644 --- a/Sources/Internal/Models/AnyPopupConfig.swift +++ b/Sources/Internal/Models/AnyPopupConfig.swift @@ -25,8 +25,10 @@ struct AnyPopupConfig: LocalConfig, Sendable { init() {} // MARK: Gestures var isTapOutsideToDismissEnabled: Bool = false var isDragGestureEnabled: Bool = false +} - // MARK: Initializer +// MARK: Initialization +extension AnyPopupConfig { init(_ config: Config) { self.alignment = .init(Config.self) self.popupPadding = config.popupPadding From 8485b71dc8d3bdb3f0166be0a802688c0a26b800 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 01:21:03 +0100 Subject: [PATCH 041/407] 1 --- Sources/Public/Setup/Public+Setup+ConfigContainer.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Public/Setup/Public+Setup+ConfigContainer.swift b/Sources/Public/Setup/Public+Setup+ConfigContainer.swift index 05549e1ad7..0c2ebab30d 100644 --- a/Sources/Public/Setup/Public+Setup+ConfigContainer.swift +++ b/Sources/Public/Setup/Public+Setup+ConfigContainer.swift @@ -15,12 +15,12 @@ public extension GlobalConfigContainer { Use the ``Popup/configurePopup(config:)-98ha0`` method to change the configuration for a specific popup. See the list of available methods in ``GlobalConfig``. */ - func centre(_ builder: (GlobalConfigCentre) -> GlobalConfigCentre) -> Self { Self.centre = builder(.init()); return self } + nonisolated func centre(_ builder: (GlobalConfigCentre) -> GlobalConfigCentre) -> Self { Self.centre = builder(.init()); return self } /** Default configuration for all top and bottom popups. Use the ``Popup/configurePopup(config:)-98ha0`` method to change the configuration for a specific popup. See the list of available methods in ``GlobalConfig`` and ``GlobalConfig/Vertical``. */ - func vertical(_ builder: (GlobalConfigVertical) -> GlobalConfigVertical) -> Self { Self.vertical = builder(.init()); return self } + nonisolated func vertical(_ builder: (GlobalConfigVertical) -> GlobalConfigVertical) -> Self { Self.vertical = builder(.init()); return self } } From df8dc7f82e0b8cc2b1e89bb6a1d3a64e64d57f78 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 02:14:22 +0100 Subject: [PATCH 042/407] 1 --- Sources/Internal/UI/PopupCentreStackView.swift | 2 +- Sources/Internal/UI/PopupVerticalStackView.swift | 2 +- .../Internal/View Models/ViewModel+CentreStack.swift | 12 +++--------- .../View Models/ViewModel+VerticalStack.swift | 2 +- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Sources/Internal/UI/PopupCentreStackView.swift b/Sources/Internal/UI/PopupCentreStackView.swift index aee1e515eb..c69451f776 100644 --- a/Sources/Internal/UI/PopupCentreStackView.swift +++ b/Sources/Internal/UI/PopupCentreStackView.swift @@ -31,7 +31,7 @@ private extension PopupCentreStackView { func createPopup(_ popup: AnyPopup) -> some View { popup.body .fixedSize(horizontal: false, vertical: viewModel.calculateVerticalFixedSize(for: popup)) - .onHeightChange { viewModel.recalculateAndSave(height: $0, for: popup) } + .onHeightChange { viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopupHeight) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupHeight) .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.calculateCornerRadius()) diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index d4c7cdfc83..93d9dbebc5 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -31,7 +31,7 @@ private extension PopupVerticalStackView { popup.body .padding(viewModel.calculateBodyPadding(for: popup)) .fixedSize(horizontal: false, vertical: viewModel.calculateVerticalFixedSize(for: popup)) - .onHeightChange { viewModel.recalculateAndSave(height: $0, for: popup) } + .onHeightChange { viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: viewModel.calculateCornerRadius()) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 54cd6f6ced..40a7469369 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -13,7 +13,7 @@ import SwiftUI extension VM { class CentreStack: ViewModel { // MARK: Overridden Methods - override func recalculateAndSave(height: CGFloat, for popup: AnyPopup) { _recalculateAndSave(height: height, for: popup) } + override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) -> CGFloat { recalculatePopupHeight(heightCandidate) } override func calculateHeightForActivePopup() -> CGFloat? { _calculateHeightForActivePopup() } override func calculatePopupPadding() -> EdgeInsets { _calculatePopupPadding() } override func calculateCornerRadius() -> [PopupAlignment : CGFloat] { _calculateCornerRadius() } @@ -28,13 +28,7 @@ extension VM { class CentreStack: ViewModel { // MARK: Recalculate & Update Popup Height private extension VM.CentreStack { - func _recalculateAndSave(height: CGFloat, for popup: AnyPopup) { - let newHeight = calculateHeight(height) - updateHeight(newHeight, popup) - } -} -private extension VM.CentreStack { - func calculateHeight(_ heightCandidate: CGFloat) -> CGFloat { + func recalculatePopupHeight(_ heightCandidate: CGFloat) -> CGFloat { min(heightCandidate, calculateLargeScreenHeight()) } } @@ -117,7 +111,7 @@ private extension VM.CentreStack { // MARK: Methods extension VM.CentreStack { - func t_calculateHeight(heightCandidate: CGFloat) -> CGFloat { calculateHeight(heightCandidate) } + func t_calculateHeight(heightCandidate: CGFloat) -> CGFloat { recalculatePopupHeight(heightCandidate) } func t_calculatePopupPadding() -> EdgeInsets { calculatePopupPadding() } func t_calculateCornerRadius() -> [PopupAlignment: CGFloat] { calculateCornerRadius() } func t_calculateOpacity(for popup: AnyPopup) -> CGFloat { calculateOpacity(for: popup) } diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 7afb03c948..5f1578a25e 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -17,7 +17,7 @@ extension VM { class VerticalStack: ViewModel { private(set) var translationProgress: CGFloat = 0 // MARK: Overridden Methods - override func recalculateAndSave(height: CGFloat, for popup: AnyPopup) { _recalculateAndSave(height: height, for: popup) } + override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) -> CGFloat { _recalculatePopupHeight(heightCandidate, popup) } override func calculateHeightForActivePopup() -> CGFloat? { _calculateHeightForActivePopup() } override func calculatePopupPadding() -> EdgeInsets { _calculatePopupPadding() } override func calculateCornerRadius() -> [PopupAlignment : CGFloat] { _calculateCornerRadius() } From e79ffb985d656203557b3af5a387d10b08ad0693 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 02:15:47 +0100 Subject: [PATCH 043/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 0a987ca853..69e98f4b50 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -25,7 +25,7 @@ enum VM {} var isKeyboardActive: Bool = false // MARK: Methods to Override - func recalculateAndSave(height: CGFloat, for popup: AnyPopup) { fatalError() } + func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) -> CGFloat { fatalError() } func calculateHeightForActivePopup() -> CGFloat? { fatalError() } func calculatePopupPadding() -> EdgeInsets { fatalError() } func calculateCornerRadius() -> [PopupAlignment: CGFloat] { fatalError() } From 2c4247c7d214bb0504001f007a6df0bb1ead382c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 02:16:43 +0100 Subject: [PATCH 044/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 69e98f4b50..033753a584 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -61,14 +61,13 @@ extension ViewModel { withAnimation(.transition) { objectWillChange.send() } } + func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) { + let recalculatedPopupHeight = recalculatePopupHeight(heightCandidate, popup) + if popup.height != recalculatedPopupHeight { updatePopupAction(popup.settingHeight(recalculatedPopupHeight)) } + } } // MARK: Helpers -extension ViewModel { - func updateHeight(_ newHeight: CGFloat, _ popup: AnyPopup) { if popup.height != newHeight { - updatePopupAction(popup.settingHeight(newHeight)) - }} -} extension ViewModel { func getActivePopupConfig() -> AnyPopupConfig { popups.last?.config ?? .init() From 2633d5945c0bed88ab690df36f8f557642b1dbe5 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 02:25:11 +0100 Subject: [PATCH 045/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 2 +- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 40a7469369..695a3050f9 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -26,7 +26,7 @@ extension VM { class CentreStack: ViewModel { -// MARK: Recalculate & Update Popup Height +// MARK: Recalculate Popup Height private extension VM.CentreStack { func recalculatePopupHeight(_ heightCandidate: CGFloat) -> CGFloat { min(heightCandidate, calculateLargeScreenHeight()) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 5f1578a25e..60a7c26503 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -458,7 +458,6 @@ private extension VM.VerticalStack { extension VM.VerticalStack { func t_calculatePopupPadding() -> EdgeInsets { calculatePopupPadding() } func t_calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { calculateBodyPadding(for: popup) } - func t_calculateHeight(heightCandidate: CGFloat, popupConfig: AnyPopupConfig) -> CGFloat { calculateHeight(heightCandidate, popupConfig) } func t_calculateOffsetY(for popup: AnyPopup) -> CGFloat { calculateOffsetY(for: popup) } func t_calculateScaleX(for popup: AnyPopup) -> CGFloat { calculateScaleX(for: popup) } func t_calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { calculateVerticalFixedSize(for: popup) } From 8b39e147edc4fe68f9f116311d7034d16fd35aa5 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 02:27:46 +0100 Subject: [PATCH 046/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 60a7c26503..88c759aa03 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -47,19 +47,19 @@ private extension VM.VerticalStack { -// MARK: Recalculate & Update Popup Height +// MARK: Recalculate Popup Height private extension VM.VerticalStack { - func _recalculateAndSave(height: CGFloat, for popup: AnyPopup) { if gestureTranslation.isZero, height != popup.height { - let newHeight = calculateHeight(height, popup.config) - updateHeight(newHeight, popup) - }} -} -private extension VM.VerticalStack { - func calculateHeight(_ heightCandidate: CGFloat, _ popupConfig: AnyPopupConfig) -> CGFloat { switch popupConfig.heightMode { - case .auto: min(heightCandidate, calculateLargeScreenHeight()) - case .large: calculateLargeScreenHeight() - case .fullscreen: getFullscreenHeight() - }} + func _recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) -> CGFloat { + guard gestureTranslation.isZero, + heightCandidate != popup.height + else { return popup.height ?? 0 } + + return switch popup.config.heightMode { + case .auto: min(heightCandidate, calculateLargeScreenHeight()) + case .large: calculateLargeScreenHeight() + case .fullscreen: getFullscreenHeight() + } + } } private extension VM.VerticalStack { func calculateLargeScreenHeight() -> CGFloat { From 3d936b5106660139de49459edb205a851c28dadc Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 02:54:36 +0100 Subject: [PATCH 047/407] 1 --- Tests/Tests+ViewModel+PopupCentreStack.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index e51847aa29..3d7402e52f 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -14,7 +14,7 @@ import SwiftUI @testable import MijickPopups @MainActor final class PopupCentreStackViewModelTests: XCTestCase { - @ObservedObject private var viewModel: ViewModel = .init() + @ObservedObject private var viewModel: ViewModel = .init(CentrePopupConfig.self) override func setUp() async throws { viewModel.t_updateScreenValue(screen) @@ -247,7 +247,7 @@ private extension PopupCentreStackViewModelTests { } } private extension PopupCentreStackViewModelTests { - func getConfigForPopupHeightTests(cornerRadius: CGFloat, popupPadding: EdgeInsets) -> Config { .t_createNew( + func getConfigForPopupHeightTests(cornerRadius: CGFloat, popupPadding: EdgeInsets) -> CentrePopupConfig { .t_createNew( popupPadding: popupPadding, cornerRadius: cornerRadius )} @@ -270,6 +270,5 @@ private extension PopupCentreStackViewModelTests { // MARK: Typealiases private extension PopupCentreStackViewModelTests { - typealias Config = LocalConfig.Centre typealias ViewModel = VM.CentreStack } From e7d91b480946de4439880ebc45266ec6639bff83 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 02:56:06 +0100 Subject: [PATCH 048/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index fa04178aa3..ca342e06ee 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -14,8 +14,8 @@ import SwiftUI @testable import MijickPopups @MainActor final class PopupVerticalStackViewModelTests: XCTestCase { - @ObservedObject private var topViewModel: ViewModel = .init() - @ObservedObject private var bottomViewModel: ViewModel = .init() + @ObservedObject private var topViewModel: ViewModel = .init(TopPopupConfig.self) + @ObservedObject private var bottomViewModel: ViewModel = .init(BottomPopupConfig.self) override func setUp() async throws { setup(topViewModel) @@ -23,20 +23,20 @@ import SwiftUI } } private extension PopupVerticalStackViewModelTests { - func setup(_ viewModel: ViewModel) { + func setup(_ viewModel: ViewModel) { viewModel.t_updateScreenValue(screen) viewModel.t_setup(updatePopupAction: { self.updatePopupAction(viewModel, $0) }, closePopupAction: { self.closePopupAction(viewModel, $0) }) } } private extension PopupVerticalStackViewModelTests { - func updatePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) { if let index = viewModel.t_popups.firstIndex(of: popup) { + func updatePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) { if let index = viewModel.t_popups.firstIndex(of: popup) { var popups = viewModel.t_popups popups[index] = popup viewModel.t_updatePopupsValue(popups) viewModel.t_calculateAndUpdateActivePopupHeight() }} - func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) { if let index = viewModel.t_popups.firstIndex(of: popup) { + func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) { if let index = viewModel.t_popups.firstIndex(of: popup) { var popups = viewModel.t_popups popups.remove(at: index) @@ -132,7 +132,7 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckPopups(viewModel: ViewModel, popups: [AnyPopup], updatedPopup: AnyPopup, expectedValue: (height: CGFloat?, dragHeight: CGFloat?)) { + func appendPopupsAndCheckPopups(viewModel: ViewModel, popups: [AnyPopup], updatedPopup: AnyPopup, expectedValue: (height: CGFloat?, dragHeight: CGFloat?)) { viewModel.t_updatePopupsValue(popups) viewModel.t_updatePopup(updatedPopup) @@ -272,8 +272,8 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func calculateLastPopupHeight(_ viewModel: ViewModel) -> CGFloat { - viewModel.t_calculateHeight(heightCandidate: viewModel.t_popups.last!.height!, popupConfig: viewModel.t_popups.last!.config as! C) + func calculateLastPopupHeight(_ viewModel: ViewModel) -> CGFloat { + viewModel.t_calculateHeight(heightCandidate: viewModel.t_popups.last!.height!, popupConfig: viewModel.t_popups.last!.config) } } @@ -1482,8 +1482,8 @@ private extension PopupVerticalStackViewModelTests { dragDetents: dragDetents, isDragGestureEnabled: dragGestureEnabled )} - func recalculatePopupHeights(_ viewModel: ViewModel) -> [AnyPopup] { viewModel.t_popups.map { - $0.settingHeight(viewModel.t_calculateHeight(heightCandidate: $0.height!, popupConfig: $0.config as! C)) + func recalculatePopupHeights(_ viewModel: ViewModel) -> [AnyPopup] { viewModel.t_popups.map { + $0.settingHeight(viewModel.t_calculateHeight(heightCandidate: $0.height!, popupConfig: $0.config)) }} } @@ -1497,6 +1497,5 @@ private extension PopupVerticalStackViewModelTests { // MARK: Typealiases private extension PopupVerticalStackViewModelTests { - typealias Config = LocalConfig.Vertical typealias ViewModel = VM.VerticalStack } From b60942ce36cc918b1c47d0fa954d3dc8f35e78c3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 02:56:49 +0100 Subject: [PATCH 049/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index ca342e06ee..68d26c66d2 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -422,7 +422,7 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckActivePopupHeight(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: CGFloat) { + func appendPopupsAndCheckActivePopupHeight(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: CGFloat) { appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, @@ -623,7 +623,7 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckPopupPadding(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: EdgeInsets) { + func appendPopupsAndCheckPopupPadding(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: EdgeInsets) { appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, @@ -734,7 +734,7 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckBodyPadding(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: EdgeInsets) { + func appendPopupsAndCheckBodyPadding(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: EdgeInsets) { appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, @@ -809,7 +809,7 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckTranslationProgress(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: CGFloat) { + func appendPopupsAndCheckTranslationProgress(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: CGFloat) { appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, @@ -900,7 +900,7 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckCornerRadius(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: [MijickPopups.PopupAlignment: CGFloat]) { + func appendPopupsAndCheckCornerRadius(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: [MijickPopups.PopupAlignment: CGFloat]) { appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, From ac490963eb2e411091d6efca53da1c26a963d9d1 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 02:57:57 +0100 Subject: [PATCH 050/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 68d26c66d2..731d5de2d3 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -979,7 +979,7 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckScaleX(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValueBuilder: @escaping (ViewModel) -> CGFloat) { + func appendPopupsAndCheckScaleX(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValueBuilder: @escaping (ViewModel) -> CGFloat) { appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, @@ -1054,7 +1054,7 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckVerticalFixedSize(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValue: Bool) { + func appendPopupsAndCheckVerticalFixedSize(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValue: Bool) { appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, @@ -1169,7 +1169,7 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckStackOverlayOpacity(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValueBuilder: @escaping (ViewModel) -> CGFloat) { + func appendPopupsAndCheckStackOverlayOpacity(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValueBuilder: @escaping (ViewModel) -> CGFloat) { appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, @@ -1268,7 +1268,7 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckGestureTranslationOnChange(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat, gestureTranslation: CGFloat)) { + func appendPopupsAndCheckGestureTranslationOnChange(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat, gestureTranslation: CGFloat)) { viewModel.t_updatePopupsValue(popups) viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) viewModel.t_onPopupDragGestureChanged(gestureValue) @@ -1438,7 +1438,7 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckGestureTranslationOnEnd(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat?, shouldPopupBeDismissed: Bool)) { + func appendPopupsAndCheckGestureTranslationOnEnd(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat?, shouldPopupBeDismissed: Bool)) { viewModel.t_updatePopupsValue(popups) viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) viewModel.t_updateGestureTranslation(gestureValue) From 25c7a98d5740e7d319ac5a0a63cb246f2f6a7e63 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 03:01:49 +0100 Subject: [PATCH 051/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 1 + Tests/Tests+ViewModel+PopupVerticalStack.swift | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 88c759aa03..a14825de29 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -458,6 +458,7 @@ private extension VM.VerticalStack { extension VM.VerticalStack { func t_calculatePopupPadding() -> EdgeInsets { calculatePopupPadding() } func t_calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { calculateBodyPadding(for: popup) } + func t_calculateHeight(heightCandidate: CGFloat, popup: AnyPopup) -> CGFloat { recalculatePopupHeight(heightCandidate, popup) } func t_calculateOffsetY(for popup: AnyPopup) -> CGFloat { calculateOffsetY(for: popup) } func t_calculateScaleX(for popup: AnyPopup) -> CGFloat { calculateScaleX(for: popup) } func t_calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { calculateVerticalFixedSize(for: popup) } diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 731d5de2d3..efeefae81b 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -273,7 +273,7 @@ extension PopupVerticalStackViewModelTests { } private extension PopupVerticalStackViewModelTests { func calculateLastPopupHeight(_ viewModel: ViewModel) -> CGFloat { - viewModel.t_calculateHeight(heightCandidate: viewModel.t_popups.last!.height!, popupConfig: viewModel.t_popups.last!.config) + viewModel.t_calculateHeight(heightCandidate: viewModel.t_popups.last!.height!, popup: viewModel.t_popups.last!) } } @@ -1458,14 +1458,14 @@ private extension PopupVerticalStackViewModelTests { // MARK: Methods private extension PopupVerticalStackViewModelTests { - func createPopupInstanceForPopupHeightTests(type: C.Type, heightMode: HeightMode, popupHeight: CGFloat, popupDragHeight: CGFloat? = nil, ignoredSafeAreaEdges: Edge.Set = [], popupPadding: EdgeInsets = .init(), cornerRadius: CGFloat = 0, dragGestureEnabled: Bool = true, dragDetents: [DragDetent] = []) -> AnyPopup { + func createPopupInstanceForPopupHeightTests(type: C.Type, heightMode: HeightMode, popupHeight: CGFloat, popupDragHeight: CGFloat? = nil, ignoredSafeAreaEdges: Edge.Set = [], popupPadding: EdgeInsets = .init(), cornerRadius: CGFloat = 0, dragGestureEnabled: Bool = true, dragDetents: [DragDetent] = []) -> AnyPopup { let config = getConfigForPopupHeightTests(type: type, heightMode: heightMode, ignoredSafeAreaEdges: ignoredSafeAreaEdges, popupPadding: popupPadding, cornerRadius: cornerRadius, dragGestureEnabled: dragGestureEnabled, dragDetents: dragDetents) return AnyPopup.t_createNew(config: config) .settingHeight(popupHeight) .settingDragHeight(popupDragHeight) } - func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) -> (Value), expectedValueBuilder: @escaping (ViewModel) -> Value) { + func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) -> (Value), expectedValueBuilder: @escaping (ViewModel) -> Value) { viewModel.t_updatePopupsValue(popups) viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) viewModel.t_updateGestureTranslation(gestureTranslation) @@ -1474,7 +1474,7 @@ private extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func getConfigForPopupHeightTests(type: C.Type, heightMode: HeightMode, ignoredSafeAreaEdges: Edge.Set, popupPadding: EdgeInsets, cornerRadius: CGFloat, dragGestureEnabled: Bool, dragDetents: [DragDetent]) -> C { .t_createNew( + func getConfigForPopupHeightTests(type: C.Type, heightMode: HeightMode, ignoredSafeAreaEdges: Edge.Set, popupPadding: EdgeInsets, cornerRadius: CGFloat, dragGestureEnabled: Bool, dragDetents: [DragDetent]) -> C { .t_createNew( popupPadding: popupPadding, cornerRadius: cornerRadius, ignoredSafeAreaEdges: ignoredSafeAreaEdges, @@ -1483,7 +1483,7 @@ private extension PopupVerticalStackViewModelTests { isDragGestureEnabled: dragGestureEnabled )} func recalculatePopupHeights(_ viewModel: ViewModel) -> [AnyPopup] { viewModel.t_popups.map { - $0.settingHeight(viewModel.t_calculateHeight(heightCandidate: $0.height!, popupConfig: $0.config)) + $0.settingHeight(viewModel.t_calculateHeight(heightCandidate: $0.height!, popup: $0)) }} } From c17a4a7db1983d9af5130b14a1799fb6780c3427 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 11:29:00 +0100 Subject: [PATCH 052/407] 1 --- .../Containers/GlobalConfigContainer.swift | 4 +-- .../Containers/PopupManagerContainer.swift | 2 +- Tests/Tests+PopupManager.swift | 36 +++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Sources/Internal/Containers/GlobalConfigContainer.swift b/Sources/Internal/Containers/GlobalConfigContainer.swift index 4f1f3f8285..eaddfcf374 100644 --- a/Sources/Internal/Containers/GlobalConfigContainer.swift +++ b/Sources/Internal/Containers/GlobalConfigContainer.swift @@ -10,6 +10,6 @@ public actor GlobalConfigContainer { - static var centre: GlobalConfigCentre = .init() - static var vertical: GlobalConfigVertical = .init() + nonisolated(unsafe) static var centre: GlobalConfigCentre = .init() + nonisolated(unsafe) static var vertical: GlobalConfigVertical = .init() } diff --git a/Sources/Internal/Containers/PopupManagerContainer.swift b/Sources/Internal/Containers/PopupManagerContainer.swift index c9c753687d..7df41fb6ec 100644 --- a/Sources/Internal/Containers/PopupManagerContainer.swift +++ b/Sources/Internal/Containers/PopupManagerContainer.swift @@ -12,7 +12,7 @@ import Foundation actor PopupManagerContainer { - static private(set) var instances: [PopupManager] = [] + nonisolated(unsafe) static private(set) var instances: [PopupManager] = [] } // MARK: Register diff --git a/Tests/Tests+PopupManager.swift b/Tests/Tests+PopupManager.swift index f172a83983..bd21aa2804 100644 --- a/Tests/Tests+PopupManager.swift +++ b/Tests/Tests+PopupManager.swift @@ -104,9 +104,9 @@ extension PopupManagerTests { extension PopupManagerTests { func test_presentPopup_withThreePopupsToBePresented() { registerNewInstanceAndPresentPopups(popups: [ - AnyPopup.t_createNew(config: .init()), - AnyPopup.t_createNew(config: .init()), - AnyPopup.t_createNew(config: .init()) + AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), + AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), + AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()) ]) let popupsOnStack = getPopupsForActiveInstance() @@ -114,9 +114,9 @@ extension PopupManagerTests { } func test_presentPopup_withPopupsWithSameID() { registerNewInstanceAndPresentPopups(popups: [ - AnyPopup.t_createNew(id: "2137", config: .init()), - AnyPopup.t_createNew(id: "2137", config: .init()), - AnyPopup.t_createNew(id: "2331", config: .init()) + AnyPopup.t_createNew(id: "2137", config: LocalConfigVertical.Bottom()), + AnyPopup.t_createNew(id: "2137", config: LocalConfigVertical.Bottom()), + AnyPopup.t_createNew(id: "2331", config: LocalConfigVertical.Bottom()) ]) let popupsOnStack = getPopupsForActiveInstance() @@ -124,9 +124,9 @@ extension PopupManagerTests { } func test_presentPopup_withCustomID() { registerNewInstanceAndPresentPopups(popups: [ - AnyPopup.t_createNew(id: "2137", config: .init()).setCustomID("1"), - AnyPopup.t_createNew(id: "2137", config: .init()), - AnyPopup.t_createNew(id: "2137", config: .init()).setCustomID("3") + AnyPopup.t_createNew(id: "2137", config: LocalConfigVertical.Bottom()).setCustomID("1"), + AnyPopup.t_createNew(id: "2137", config: LocalConfigVertical.Bottom()), + AnyPopup.t_createNew(id: "2137", config: LocalConfigVertical.Bottom()).setCustomID("3") ]) let popupsOnStack = getPopupsForActiveInstance() @@ -134,9 +134,9 @@ extension PopupManagerTests { } func test_presentPopup_withDismissAfter() async { registerNewInstanceAndPresentPopups(popups: [ - AnyPopup.t_createNew(config: .init()).dismissAfter(0.7), - AnyPopup.t_createNew(config: .init()), - AnyPopup.t_createNew(config: .init()).dismissAfter(1.5) + AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()).dismissAfter(0.7), + AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), + AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()).dismissAfter(1.5) ]) let popupsOnStack1 = getPopupsForActiveInstance() @@ -165,9 +165,9 @@ extension PopupManagerTests { } func test_dismissLastPopup_withThreePopupsOnStack() { registerNewInstanceAndPresentPopups(popups: [ - AnyPopup.t_createNew(config: .init()), - AnyPopup.t_createNew(config: .init()), - AnyPopup.t_createNew(config: .init()) + AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), + AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), + AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()) ]) PopupManager.dismissLastPopup(popupManagerID: defaultPopupManagerID) @@ -237,9 +237,9 @@ extension PopupManagerTests { } func test_dismissAllPopups() { registerNewInstanceAndPresentPopups(popups: [ - AnyPopup.t_createNew(config: .init()), - AnyPopup.t_createNew(config: .init()), - AnyPopup.t_createNew(config: .init()) + AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), + AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), + AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()) ]) PopupManager.dismissAllPopups(popupManagerID: defaultPopupManagerID) From 28b31a6ad576c1594fabd3bd68b156dba6bb94d0 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 11:49:11 +0100 Subject: [PATCH 053/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index a14825de29..e2e590b9e5 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -54,13 +54,17 @@ private extension VM.VerticalStack { heightCandidate != popup.height else { return popup.height ?? 0 } - return switch popup.config.heightMode { - case .auto: min(heightCandidate, calculateLargeScreenHeight()) - case .large: calculateLargeScreenHeight() - case .fullscreen: getFullscreenHeight() - } + let popupHeight = calculateNewPopupHeight(heightCandidate, popup.config) + return popupHeight } } +private extension VM.VerticalStack { + func calculateNewPopupHeight(_ heightCandidate: CGFloat, _ popupConfig: AnyPopupConfig) -> CGFloat { switch popupConfig.heightMode { + case .auto: min(heightCandidate, calculateLargeScreenHeight()) + case .large: calculateLargeScreenHeight() + case .fullscreen: getFullscreenHeight() + }} +} private extension VM.VerticalStack { func calculateLargeScreenHeight() -> CGFloat { let fullscreenHeight = getFullscreenHeight(), @@ -458,7 +462,7 @@ private extension VM.VerticalStack { extension VM.VerticalStack { func t_calculatePopupPadding() -> EdgeInsets { calculatePopupPadding() } func t_calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { calculateBodyPadding(for: popup) } - func t_calculateHeight(heightCandidate: CGFloat, popup: AnyPopup) -> CGFloat { recalculatePopupHeight(heightCandidate, popup) } + func t_calculateHeight(heightCandidate: CGFloat, popup: AnyPopup) -> CGFloat { calculateNewPopupHeight(heightCandidate, popup.config) } func t_calculateOffsetY(for popup: AnyPopup) -> CGFloat { calculateOffsetY(for: popup) } func t_calculateScaleX(for popup: AnyPopup) -> CGFloat { calculateScaleX(for: popup) } func t_calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { calculateVerticalFixedSize(for: popup) } From 5ec575414e5146a53e0a783919eaff3c9083e8d7 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 11:50:25 +0100 Subject: [PATCH 054/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index e2e590b9e5..6a3f425d98 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -50,9 +50,7 @@ private extension VM.VerticalStack { // MARK: Recalculate Popup Height private extension VM.VerticalStack { func _recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) -> CGFloat { - guard gestureTranslation.isZero, - heightCandidate != popup.height - else { return popup.height ?? 0 } + guard gestureTranslation.isZero, heightCandidate != popup.height else { return popup.height ?? 0 } let popupHeight = calculateNewPopupHeight(heightCandidate, popup.config) return popupHeight From 9a0e7fa6576a7d2337027be7b0392f7095b00b1f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 12:31:01 +0100 Subject: [PATCH 055/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 2 +- .../Internal/View Models/ViewModel+VerticalStack.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 695a3050f9..b3f59cb661 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -13,7 +13,7 @@ import SwiftUI extension VM { class CentreStack: ViewModel { // MARK: Overridden Methods - override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) -> CGFloat { recalculatePopupHeight(heightCandidate) } + override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await recalculatePopupHeight(heightCandidate) } override func calculateHeightForActivePopup() -> CGFloat? { _calculateHeightForActivePopup() } override func calculatePopupPadding() -> EdgeInsets { _calculatePopupPadding() } override func calculateCornerRadius() -> [PopupAlignment : CGFloat] { _calculateCornerRadius() } diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 6a3f425d98..3d25c6271e 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -17,7 +17,7 @@ extension VM { class VerticalStack: ViewModel { private(set) var translationProgress: CGFloat = 0 // MARK: Overridden Methods - override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) -> CGFloat { _recalculatePopupHeight(heightCandidate, popup) } + override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _recalculatePopupHeight(heightCandidate, popup) } override func calculateHeightForActivePopup() -> CGFloat? { _calculateHeightForActivePopup() } override func calculatePopupPadding() -> EdgeInsets { _calculatePopupPadding() } override func calculateCornerRadius() -> [PopupAlignment : CGFloat] { _calculateCornerRadius() } diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 033753a584..ca3f3f3421 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -25,7 +25,7 @@ enum VM {} var isKeyboardActive: Bool = false // MARK: Methods to Override - func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) -> CGFloat { fatalError() } + nonisolated func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { fatalError() } func calculateHeightForActivePopup() -> CGFloat? { fatalError() } func calculatePopupPadding() -> EdgeInsets { fatalError() } func calculateCornerRadius() -> [PopupAlignment: CGFloat] { fatalError() } @@ -61,10 +61,10 @@ extension ViewModel { withAnimation(.transition) { objectWillChange.send() } } - func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) { - let recalculatedPopupHeight = recalculatePopupHeight(heightCandidate, popup) + func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) { Task { + let recalculatedPopupHeight = await recalculatePopupHeight(heightCandidate, popup) if popup.height != recalculatedPopupHeight { updatePopupAction(popup.settingHeight(recalculatedPopupHeight)) } - } + }} } // MARK: Helpers From 96163e01b32aad73730de4145344b4776af9cc25 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 12:33:59 +0100 Subject: [PATCH 056/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index b3f59cb661..210a60d427 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -28,8 +28,8 @@ extension VM { class CentreStack: ViewModel { // MARK: Recalculate Popup Height private extension VM.CentreStack { - func recalculatePopupHeight(_ heightCandidate: CGFloat) -> CGFloat { - min(heightCandidate, calculateLargeScreenHeight()) + nonisolated func recalculatePopupHeight(_ heightCandidate: CGFloat) async -> CGFloat { + await min(heightCandidate, calculateLargeScreenHeight()) } } private extension VM.CentreStack { From 6032833f1ad793bec8c379759cbb5daa1a3814ea Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 12:34:50 +0100 Subject: [PATCH 057/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 3d25c6271e..abd3da84ed 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -49,10 +49,10 @@ private extension VM.VerticalStack { // MARK: Recalculate Popup Height private extension VM.VerticalStack { - func _recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) -> CGFloat { - guard gestureTranslation.isZero, heightCandidate != popup.height else { return popup.height ?? 0 } + nonisolated func _recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { + guard await gestureTranslation.isZero, heightCandidate != popup.height else { return popup.height ?? 0 } - let popupHeight = calculateNewPopupHeight(heightCandidate, popup.config) + let popupHeight = await calculateNewPopupHeight(heightCandidate, popup.config) return popupHeight } } From a763d3b17af04c9bb15e9ed44f0c03a5312f00b1 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 12:38:57 +0100 Subject: [PATCH 058/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 210a60d427..2b384111b0 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -111,7 +111,7 @@ private extension VM.CentreStack { // MARK: Methods extension VM.CentreStack { - func t_calculateHeight(heightCandidate: CGFloat) -> CGFloat { recalculatePopupHeight(heightCandidate) } + func t_calculateHeight(heightCandidate: CGFloat) -> CGFloat { min(heightCandidate, calculateLargeScreenHeight()) } func t_calculatePopupPadding() -> EdgeInsets { calculatePopupPadding() } func t_calculateCornerRadius() -> [PopupAlignment: CGFloat] { calculateCornerRadius() } func t_calculateOpacity(for popup: AnyPopup) -> CGFloat { calculateOpacity(for: popup) } From e563efe1e29ef8407f404bacd86cd2568a9a153f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 12:46:46 +0100 Subject: [PATCH 059/407] 1 --- .../View Models/ViewModel+CentreStack.swift | 15 ++++++--------- .../View Models/ViewModel+VerticalStack.swift | 15 ++++++--------- Sources/Internal/View Models/ViewModel.swift | 3 --- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 2b384111b0..9f2f22e558 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -15,9 +15,6 @@ extension VM { class CentreStack: ViewModel { // MARK: Overridden Methods override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await recalculatePopupHeight(heightCandidate) } override func calculateHeightForActivePopup() -> CGFloat? { _calculateHeightForActivePopup() } - override func calculatePopupPadding() -> EdgeInsets { _calculatePopupPadding() } - override func calculateCornerRadius() -> [PopupAlignment : CGFloat] { _calculateCornerRadius() } - override func calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { _calculateVerticalFixedSize(for: popup) } }} @@ -41,8 +38,8 @@ private extension VM.CentreStack { } // MARK: Popup Padding -private extension VM.CentreStack { - func _calculatePopupPadding() -> EdgeInsets { .init( +extension VM.CentreStack { + func calculatePopupPadding() -> EdgeInsets { .init( top: calculateVerticalPopupPadding(for: .top), leading: calculateLeadingPopupPadding(), bottom: calculateVerticalPopupPadding(for: .bottom), @@ -68,8 +65,8 @@ private extension VM.CentreStack { } // MARK: Corner Radius -private extension VM.CentreStack { - func _calculateCornerRadius() -> [PopupAlignment : CGFloat] {[ +extension VM.CentreStack { + func calculateCornerRadius() -> [PopupAlignment : CGFloat] {[ .top: getActivePopupConfig().cornerRadius, .bottom: getActivePopupConfig().cornerRadius ]} @@ -83,8 +80,8 @@ extension VM.CentreStack { } // MARK: Fixed Size -private extension VM.CentreStack { - func _calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { +extension VM.CentreStack { + func calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { activePopupHeight != calculateLargeScreenHeight() } } diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index abd3da84ed..57c3e28a70 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -19,9 +19,6 @@ extension VM { class VerticalStack: ViewModel { // MARK: Overridden Methods override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _recalculatePopupHeight(heightCandidate, popup) } override func calculateHeightForActivePopup() -> CGFloat? { _calculateHeightForActivePopup() } - override func calculatePopupPadding() -> EdgeInsets { _calculatePopupPadding() } - override func calculateCornerRadius() -> [PopupAlignment : CGFloat] { _calculateCornerRadius() } - override func calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { _calculateVerticalFixedSize(for: popup) } }} @@ -84,8 +81,8 @@ private extension VM.VerticalStack { } // MARK: Popup Padding -private extension VM.VerticalStack { - func _calculatePopupPadding() -> EdgeInsets { .init( +extension VM.VerticalStack { + func calculatePopupPadding() -> EdgeInsets { .init( top: calculateVerticalPopupPadding(for: .top), leading: calculateLeadingPopupPadding(), bottom: calculateVerticalPopupPadding(for: .bottom), @@ -213,8 +210,8 @@ private extension VM.VerticalStack { } // MARK: Corner Radius -private extension VM.VerticalStack { - func _calculateCornerRadius() -> [PopupAlignment: CGFloat] { +extension VM.VerticalStack { + func calculateCornerRadius() -> [PopupAlignment: CGFloat] { let cornerRadiusValue = calculateCornerRadiusValue(getActivePopupConfig()) return [ .top: calculateTopCornerRadius(cornerRadiusValue), @@ -240,8 +237,8 @@ private extension VM.VerticalStack { } // MARK: Fixed Size -private extension VM.VerticalStack { - func _calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { switch popup.config.heightMode { +extension VM.VerticalStack { + func calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { switch popup.config.heightMode { case .fullscreen, .large: false case .auto: activePopupHeight != calculateLargeScreenHeight() }} diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index ca3f3f3421..d5a5310401 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -27,9 +27,6 @@ enum VM {} // MARK: Methods to Override nonisolated func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { fatalError() } func calculateHeightForActivePopup() -> CGFloat? { fatalError() } - func calculatePopupPadding() -> EdgeInsets { fatalError() } - func calculateCornerRadius() -> [PopupAlignment: CGFloat] { fatalError() } - func calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { fatalError() } // MARK: Initializer init(_ config: Config.Type) { self.alignment = .init(Config.self) } From ab0c73329db1aea9a41ccf1d6ddaf50a288e68aa Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 13:03:24 +0100 Subject: [PATCH 060/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index e5a6cf64bf..be6b6ede3e 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -18,7 +18,7 @@ struct AnyPopup: Popup { private(set) var dragHeight: CGFloat? = nil private var dismissTimer: PopupActionScheduler? = nil - private var _body: AnyView + private var _body: any View private let _onFocus: () -> () private let _onDismiss: () -> () } @@ -36,7 +36,7 @@ extension AnyPopup { else { self.id = .create(from: P.self) self.config = .init(popup.configurePopup(config: .init())) - self._body = AnyView(popup) + self._body = popup self._onFocus = popup.onFocus self._onDismiss = popup.onDismiss } @@ -50,7 +50,7 @@ extension AnyPopup { func startingDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updatingPopup { $0.dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} func settingHeight(_ newHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.height = newHeight }} func settingDragHeight(_ newDragHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.dragHeight = newDragHeight }} - func settingEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updatingPopup { $0._body = AnyView(_body.environmentObject(environmentObject)) }} + func settingEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updatingPopup { $0._body = _body.environmentObject(environmentObject) }} } private extension AnyPopup { func updatingPopup(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { From 2542a32cafb4cbc79afb85b7a3e8e233dbcbceba Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 13:05:13 +0100 Subject: [PATCH 061/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index be6b6ede3e..d05baece2b 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -95,7 +95,7 @@ extension AnyPopup { height: nil, dragHeight: nil, dismissTimer: nil, - _body: .init(EmptyView()), + _body: EmptyView(), _onFocus: {}, _onDismiss: {} )} From de62622d25f05113aa57ffefc68dd8b682c09032 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 13:20:13 +0100 Subject: [PATCH 062/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index d05baece2b..6d2eabae35 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -18,7 +18,7 @@ struct AnyPopup: Popup { private(set) var dragHeight: CGFloat? = nil private var dismissTimer: PopupActionScheduler? = nil - private var _body: any View + private var _body: AnyView private let _onFocus: () -> () private let _onDismiss: () -> () } @@ -36,7 +36,7 @@ extension AnyPopup { else { self.id = .create(from: P.self) self.config = .init(popup.configurePopup(config: .init())) - self._body = popup + self._body = .init(popup) self._onFocus = popup.onFocus self._onDismiss = popup.onDismiss } @@ -50,7 +50,7 @@ extension AnyPopup { func startingDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updatingPopup { $0.dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} func settingHeight(_ newHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.height = newHeight }} func settingDragHeight(_ newDragHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.dragHeight = newDragHeight }} - func settingEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updatingPopup { $0._body = _body.environmentObject(environmentObject) }} + func settingEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updatingPopup { $0._body = .init(_body.environmentObject(environmentObject)) }} } private extension AnyPopup { func updatingPopup(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { @@ -95,7 +95,7 @@ extension AnyPopup { height: nil, dragHeight: nil, dismissTimer: nil, - _body: EmptyView(), + _body: .init(EmptyView()), _onFocus: {}, _onDismiss: {} )} From 63beef6dad9defbee0d56328443f3fe36790e24d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 14:20:34 +0100 Subject: [PATCH 063/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 2 +- .../Internal/View Models/ViewModel+VerticalStack.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 9f2f22e558..110b12b7b8 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -14,7 +14,7 @@ import SwiftUI extension VM { class CentreStack: ViewModel { // MARK: Overridden Methods override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await recalculatePopupHeight(heightCandidate) } - override func calculateHeightForActivePopup() -> CGFloat? { _calculateHeightForActivePopup() } + override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } }} diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 57c3e28a70..ca70fd0079 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -18,7 +18,7 @@ extension VM { class VerticalStack: ViewModel { // MARK: Overridden Methods override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _recalculatePopupHeight(heightCandidate, popup) } - override func calculateHeightForActivePopup() -> CGFloat? { _calculateHeightForActivePopup() } + override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } }} diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index d5a5310401..922032c184 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -26,7 +26,7 @@ enum VM {} // MARK: Methods to Override nonisolated func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { fatalError() } - func calculateHeightForActivePopup() -> CGFloat? { fatalError() } + nonisolated func calculateHeightForActivePopup() async -> CGFloat? { fatalError() } // MARK: Initializer init(_ config: Config.Type) { self.alignment = .init(Config.self) } @@ -42,12 +42,12 @@ extension ViewModel { // MARK: Update extension ViewModel { - func updatePopupsValue(_ newPopups: [AnyPopup]) { + func updatePopupsValue(_ newPopups: [AnyPopup]) { Task { popups = newPopups.filter { $0.config.alignment == alignment } - activePopupHeight = calculateHeightForActivePopup() + await activePopupHeight = calculateHeightForActivePopup() withAnimation(.transition) { objectWillChange.send() } - } + }} func updateScreenValue(_ newScreen: Screen) { screen = newScreen From 7e1d6efe14445e6d8ffd2daf2b06724209b7223a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 14:21:15 +0100 Subject: [PATCH 064/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 922032c184..6fb0e6ec67 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -85,7 +85,7 @@ extension ViewModel { func t_updateScreenValue(_ newScreen: Screen) { updateScreenValue(newScreen) } func t_updateKeyboardValue(_ isActive: Bool) { updateKeyboardValue(isActive) } func t_updatePopup(_ popup: AnyPopup) { updatePopupAction(popup) } - func t_calculateAndUpdateActivePopupHeight() { activePopupHeight = calculateHeightForActivePopup() } + func t_calculateAndUpdateActivePopupHeight() { Task { activePopupHeight = await calculateHeightForActivePopup() }} } // MARK: Variables From 31e08696591afaadf1ffa3d15ca3a6935190811a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 14:22:01 +0100 Subject: [PATCH 065/407] 1 --- .../Internal/View Models/ViewModel+CentreStack.swift | 4 ++-- .../Internal/View Models/ViewModel+VerticalStack.swift | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 110b12b7b8..cb19d68df0 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -94,8 +94,8 @@ extension VM.CentreStack { // MARK: Active Popup Height private extension VM.CentreStack { - func _calculateHeightForActivePopup() -> CGFloat? { - popups.last?.height + nonisolated func _calculateHeightForActivePopup() async -> CGFloat? { + await popups.last?.height } } diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index ca70fd0079..d01486adb7 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -278,14 +278,14 @@ private extension VM.VerticalStack { // MARK: Active Popup Height private extension VM.VerticalStack { - func _calculateHeightForActivePopup() -> CGFloat? { - guard let activePopupHeight = popups.last?.height else { return nil } + nonisolated func _calculateHeightForActivePopup() async -> CGFloat? { + guard let activePopupHeight = await popups.last?.height else { return nil } - let activePopupDragHeight = popups.last?.dragHeight ?? 0 - let popupHeightFromGestureTranslation = activePopupHeight + activePopupDragHeight + gestureTranslation * getDragTranslationMultiplier() + let activePopupDragHeight = await popups.last?.dragHeight ?? 0 + let popupHeightFromGestureTranslation = await activePopupHeight + activePopupDragHeight + gestureTranslation * getDragTranslationMultiplier() let newHeightCandidate1 = max(activePopupHeight, popupHeightFromGestureTranslation), - newHeightCanditate2 = screen.height + newHeightCanditate2 = await screen.height return min(newHeightCandidate1, newHeightCanditate2) } } From c3bc1cc83868e4382ff55fa18b1c5344ec908e44 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 14:24:15 +0100 Subject: [PATCH 066/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index d01486adb7..718bfe23e7 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -29,13 +29,13 @@ extension VM { class VerticalStack: ViewModel { // MARK: Update private extension VM.VerticalStack { - func updateGestureTranslation(_ newGestureTranslation: CGFloat) { + func updateGestureTranslation(_ newGestureTranslation: CGFloat) { Task { gestureTranslation = newGestureTranslation translationProgress = calculateTranslationProgress() - activePopupHeight = calculateHeightForActivePopup() + activePopupHeight = await calculateHeightForActivePopup() withAnimation(gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } - } + }} } From a58b19a7a5abf666cb3c89f3c874a3af221387b3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 14:48:39 +0100 Subject: [PATCH 067/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 6fb0e6ec67..19ecef4358 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -14,7 +14,7 @@ import SwiftUI enum VM {} @MainActor class ViewModel: ObservableObject { // MARK: Attributes - private(set) var alignment: PopupAlignment + nonisolated let alignment: PopupAlignment private(set) var popups: [AnyPopup] = [] private(set) var updatePopupAction: ((AnyPopup) -> ())! private(set) var closePopupAction: ((AnyPopup) -> ())! @@ -43,8 +43,8 @@ extension ViewModel { // MARK: Update extension ViewModel { func updatePopupsValue(_ newPopups: [AnyPopup]) { Task { - popups = newPopups.filter { $0.config.alignment == alignment } - await activePopupHeight = calculateHeightForActivePopup() + popups = await filterPopups(newPopups) + activePopupHeight = await calculateHeightForActivePopup() withAnimation(.transition) { objectWillChange.send() } }} @@ -63,6 +63,11 @@ extension ViewModel { if popup.height != recalculatedPopupHeight { updatePopupAction(popup.settingHeight(recalculatedPopupHeight)) } }} } +private extension ViewModel { + nonisolated func filterPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { + popups.filter { $0.config.alignment == alignment } + } +} // MARK: Helpers extension ViewModel { From 4963d825999cf49940ad0f8f848b8da8e348f2ae Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 15:23:47 +0100 Subject: [PATCH 068/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 718bfe23e7..e261dd0974 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -31,7 +31,7 @@ extension VM { class VerticalStack: ViewModel { private extension VM.VerticalStack { func updateGestureTranslation(_ newGestureTranslation: CGFloat) { Task { gestureTranslation = newGestureTranslation - translationProgress = calculateTranslationProgress() + translationProgress = await calculateTranslationProgress() activePopupHeight = await calculateHeightForActivePopup() withAnimation(gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } @@ -299,9 +299,9 @@ private extension VM.VerticalStack { // MARK: Translation Progress private extension VM.VerticalStack { - func calculateTranslationProgress() -> CGFloat { guard let activePopupHeight = popups.last?.height else { return 0 }; return switch alignment { - case .top: abs(min(gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight - case .bottom: max(gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight + nonisolated func calculateTranslationProgress() async -> CGFloat { guard let activePopupHeight = await popups.last?.height else { return 0 }; return switch alignment { + case .top: await abs(min(gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight + case .bottom: await max(gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight case .centre: fatalError() }} } From 8343e5527989238536d42ba0cd5b5d1dbfcbd05e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 15:49:39 +0100 Subject: [PATCH 069/407] 1 --- Sources/Internal/UI/PopupVerticalStackView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index 93d9dbebc5..51e59b484a 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -38,7 +38,7 @@ private extension PopupVerticalStackView { .offset(y: viewModel.calculateOffsetY(for: popup)) .scaleEffect(x: viewModel.calculateScaleX(for: popup)) .focusSection_tvOS() - .padding(viewModel.calculatePopupPadding()) + .padding(popup.popupPadding) .transition(transition) .zIndex(viewModel.calculateZIndex()) .compositingGroup() From fddff25cdb7f4f996d0e796cf768c09f2ff5f430 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 16:12:55 +0100 Subject: [PATCH 070/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index e261dd0974..6edadf1e19 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -19,6 +19,7 @@ extension VM { class VerticalStack: ViewModel { // MARK: Overridden Methods override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _recalculatePopupHeight(heightCandidate, popup) } override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } + override func recalculatePopupPadding() async -> EdgeInsets { calculatePopupPadding() } }} @@ -81,7 +82,7 @@ private extension VM.VerticalStack { } // MARK: Popup Padding -extension VM.VerticalStack { +private extension VM.VerticalStack { func calculatePopupPadding() -> EdgeInsets { .init( top: calculateVerticalPopupPadding(for: .top), leading: calculateLeadingPopupPadding(), From 06ef76d8cf68ee08c45a7607e51f9ae3e33a0bd3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 16:16:13 +0100 Subject: [PATCH 071/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 46 ++++++++++--------- Sources/Internal/View Models/ViewModel.swift | 1 + 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 6edadf1e19..9e6cd0ff66 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -117,37 +117,37 @@ private extension VM.VerticalStack { // MARK: Body Padding extension VM.VerticalStack { - func calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { let activePopupHeight = activePopupHeight ?? 0, popupConfig = popup.config; return .init( - top: calculateTopBodyPadding(activePopupHeight: activePopupHeight, popupConfig: popupConfig), - leading: calculateLeadingBodyPadding(popupConfig: popupConfig), - bottom: calculateBottomBodyPadding(activePopupHeight: activePopupHeight, popupConfig: popupConfig), - trailing: calculateTrailingBodyPadding(popupConfig: popupConfig) + func calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { let activePopupHeight = activePopupHeight ?? 0; return .init( + top: calculateTopBodyPadding(activePopupHeight: activePopupHeight, popup: popup), + leading: calculateLeadingBodyPadding(popup: popup), + bottom: calculateBottomBodyPadding(activePopupHeight: activePopupHeight, popup: popup), + trailing: calculateTrailingBodyPadding(popup: popup) )} } private extension VM.VerticalStack { - func calculateTopBodyPadding(activePopupHeight: CGFloat, popupConfig: AnyPopupConfig) -> CGFloat { - if popupConfig.ignoredSafeAreaEdges.contains(.top) { return 0 } + func calculateTopBodyPadding(activePopupHeight: CGFloat, popup: AnyPopup) -> CGFloat { + if popup.config.ignoredSafeAreaEdges.contains(.top) { return 0 } return switch alignment { - case .top: calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupPadding: calculatePopupPadding().top) + case .top: calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupPadding: popup.popupPadding.top) case .bottom: calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight, safeArea: screen.safeArea.top) case .centre: fatalError() } } - func calculateBottomBodyPadding(activePopupHeight: CGFloat, popupConfig: AnyPopupConfig) -> CGFloat { - if popupConfig.ignoredSafeAreaEdges.contains(.bottom) && !isKeyboardActive { return 0 } + func calculateBottomBodyPadding(activePopupHeight: CGFloat, popup: AnyPopup) -> CGFloat { + if popup.config.ignoredSafeAreaEdges.contains(.bottom) && !isKeyboardActive { return 0 } return switch alignment { case .top: calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight, safeArea: screen.safeArea.bottom) - case .bottom: calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupPadding: calculatePopupPadding().bottom) + case .bottom: calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupPadding: popup.popupPadding.bottom) case .centre: fatalError() } } - func calculateLeadingBodyPadding(popupConfig: AnyPopupConfig) -> CGFloat { switch popupConfig.ignoredSafeAreaEdges.contains(.leading) { + func calculateLeadingBodyPadding(popup: AnyPopup) -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.leading) { case true: 0 case false: screen.safeArea.leading }} - func calculateTrailingBodyPadding(popupConfig: AnyPopupConfig) -> CGFloat { switch popupConfig.ignoredSafeAreaEdges.contains(.trailing) { + func calculateTrailingBodyPadding(popup: AnyPopup) -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.trailing) { case true: 0 case false: screen.safeArea.trailing }} @@ -213,26 +213,28 @@ private extension VM.VerticalStack { // MARK: Corner Radius extension VM.VerticalStack { func calculateCornerRadius() -> [PopupAlignment: CGFloat] { - let cornerRadiusValue = calculateCornerRadiusValue(getActivePopupConfig()) + guard let activePopup = popups.last else { return [:] } + + let cornerRadiusValue = calculateCornerRadiusValue(activePopup) return [ - .top: calculateTopCornerRadius(cornerRadiusValue), - .bottom: calculateBottomCornerRadius(cornerRadiusValue) + .top: calculateTopCornerRadius(cornerRadiusValue, activePopup), + .bottom: calculateBottomCornerRadius(cornerRadiusValue, activePopup) ] } } private extension VM.VerticalStack { - func calculateCornerRadiusValue(_ activePopupConfig: AnyPopupConfig) -> CGFloat { switch activePopupConfig.heightMode { - case .auto, .large: activePopupConfig.cornerRadius + func calculateCornerRadiusValue(_ activePopup: AnyPopup) -> CGFloat { switch activePopup.config.heightMode { + case .auto, .large: activePopup.config.cornerRadius case .fullscreen: 0 }} - func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat) -> CGFloat { switch alignment { - case .top: calculatePopupPadding().top != 0 ? cornerRadiusValue : 0 + func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat, _ activePopup: AnyPopup) -> CGFloat { switch alignment { + case .top: activePopup.popupPadding.top != 0 ? cornerRadiusValue : 0 case .bottom: cornerRadiusValue case .centre: fatalError() }} - func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat) -> CGFloat { switch alignment { + func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat, _ activePopup: AnyPopup) -> CGFloat { switch alignment { case .top: cornerRadiusValue - case .bottom: calculatePopupPadding().bottom != 0 ? cornerRadiusValue : 0 + case .bottom: activePopup.popupPadding.bottom != 0 ? cornerRadiusValue : 0 case .centre: fatalError() }} } diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 19ecef4358..d0897f38e0 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -27,6 +27,7 @@ enum VM {} // MARK: Methods to Override nonisolated func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { fatalError() } nonisolated func calculateHeightForActivePopup() async -> CGFloat? { fatalError() } + nonisolated func recalculatePopupPadding() async -> EdgeInsets { fatalError() } // MARK: Initializer init(_ config: Config.Type) { self.alignment = .init(Config.self) } From b91555f933df78d3cac86c0f87d364d62ffe5939 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 16:34:48 +0100 Subject: [PATCH 072/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 9e6cd0ff66..d6523cde7d 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -18,8 +18,8 @@ extension VM { class VerticalStack: ViewModel { // MARK: Overridden Methods override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _recalculatePopupHeight(heightCandidate, popup) } - override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } override func recalculatePopupPadding() async -> EdgeInsets { calculatePopupPadding() } + override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } }} @@ -45,7 +45,7 @@ private extension VM.VerticalStack { -// MARK: Recalculate Popup Height +// MARK: Popup Height private extension VM.VerticalStack { nonisolated func _recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { guard await gestureTranslation.isZero, heightCandidate != popup.height else { return popup.height ?? 0 } @@ -83,29 +83,27 @@ private extension VM.VerticalStack { // MARK: Popup Padding private extension VM.VerticalStack { - func calculatePopupPadding() -> EdgeInsets { .init( - top: calculateVerticalPopupPadding(for: .top), - leading: calculateLeadingPopupPadding(), - bottom: calculateVerticalPopupPadding(for: .bottom), - trailing: calculateTrailingPopupPadding() + func calculatePopupPadding() -> EdgeInsets { guard let activePopupConfig = popups.last?.config, let activePopupHeight else { return .init() }; return .init( + top: calculateVerticalPopupPadding(for: .top, activePopupHeight: activePopupHeight, activePopupConfig: activePopupConfig), + leading: calculateLeadingPopupPadding(activePopupConfig: activePopupConfig), + bottom: calculateVerticalPopupPadding(for: .bottom, activePopupHeight: activePopupHeight, activePopupConfig: activePopupConfig), + trailing: calculateTrailingPopupPadding(activePopupConfig: activePopupConfig) )} } private extension VM.VerticalStack { - func calculateVerticalPopupPadding(for edge: PopupAlignment) -> CGFloat { - guard let activePopupHeight else { return 0 } - + func calculateVerticalPopupPadding(for edge: PopupAlignment, activePopupHeight: CGFloat, activePopupConfig: AnyPopupConfig) -> CGFloat { let largeScreenHeight = calculateLargeScreenHeight(), priorityPopupPaddingValue = calculatePriorityPopupPaddingValue(for: edge), remainingHeight = largeScreenHeight - activePopupHeight - priorityPopupPaddingValue - let popupPaddingCandidate = min(remainingHeight, getActivePopupConfig().popupPadding[edge]) + let popupPaddingCandidate = min(remainingHeight, activePopupConfig.popupPadding[edge]) return max(popupPaddingCandidate, 0) } - func calculateLeadingPopupPadding() -> CGFloat { - getActivePopupConfig().popupPadding.leading + func calculateLeadingPopupPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { + activePopupConfig.popupPadding.leading } - func calculateTrailingPopupPadding() -> CGFloat { - getActivePopupConfig().popupPadding.trailing + func calculateTrailingPopupPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { + activePopupConfig.popupPadding.trailing } } private extension VM.VerticalStack { From 653ffc37400c88476d7b178950b691ce7c110ba7 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 17:28:52 +0100 Subject: [PATCH 073/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index d6523cde7d..68a3b2ae49 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -19,6 +19,7 @@ extension VM { class VerticalStack: ViewModel { // MARK: Overridden Methods override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _recalculatePopupHeight(heightCandidate, popup) } override func recalculatePopupPadding() async -> EdgeInsets { calculatePopupPadding() } + override func recalculateBodyPadding(for popup: AnyPopup) async -> EdgeInsets { calculateBodyPadding(for: popup) } override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } }} @@ -83,16 +84,17 @@ private extension VM.VerticalStack { // MARK: Popup Padding private extension VM.VerticalStack { - func calculatePopupPadding() -> EdgeInsets { guard let activePopupConfig = popups.last?.config, let activePopupHeight else { return .init() }; return .init( - top: calculateVerticalPopupPadding(for: .top, activePopupHeight: activePopupHeight, activePopupConfig: activePopupConfig), + func calculatePopupPadding() -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return .init( + top: calculateVerticalPopupPadding(for: .top, activePopupConfig: activePopupConfig), leading: calculateLeadingPopupPadding(activePopupConfig: activePopupConfig), - bottom: calculateVerticalPopupPadding(for: .bottom, activePopupHeight: activePopupHeight, activePopupConfig: activePopupConfig), + bottom: calculateVerticalPopupPadding(for: .bottom, activePopupConfig: activePopupConfig), trailing: calculateTrailingPopupPadding(activePopupConfig: activePopupConfig) )} } private extension VM.VerticalStack { - func calculateVerticalPopupPadding(for edge: PopupAlignment, activePopupHeight: CGFloat, activePopupConfig: AnyPopupConfig) -> CGFloat { + func calculateVerticalPopupPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) -> CGFloat { let largeScreenHeight = calculateLargeScreenHeight(), + activePopupHeight = activePopupHeight ?? 0, priorityPopupPaddingValue = calculatePriorityPopupPaddingValue(for: edge), remainingHeight = largeScreenHeight - activePopupHeight - priorityPopupPaddingValue From 7143257bdbab8bd81567c68352cdb20c286e201e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 17:34:40 +0100 Subject: [PATCH 074/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 68a3b2ae49..1d95e2e6b0 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -117,28 +117,28 @@ private extension VM.VerticalStack { // MARK: Body Padding extension VM.VerticalStack { - func calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { let activePopupHeight = activePopupHeight ?? 0; return .init( - top: calculateTopBodyPadding(activePopupHeight: activePopupHeight, popup: popup), + func calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { .init( + top: calculateTopBodyPadding(popup: popup), leading: calculateLeadingBodyPadding(popup: popup), - bottom: calculateBottomBodyPadding(activePopupHeight: activePopupHeight, popup: popup), + bottom: calculateBottomBodyPadding(popup: popup), trailing: calculateTrailingBodyPadding(popup: popup) )} } private extension VM.VerticalStack { - func calculateTopBodyPadding(activePopupHeight: CGFloat, popup: AnyPopup) -> CGFloat { + func calculateTopBodyPadding(popup: AnyPopup) -> CGFloat { if popup.config.ignoredSafeAreaEdges.contains(.top) { return 0 } return switch alignment { case .top: calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupPadding: popup.popupPadding.top) - case .bottom: calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight, safeArea: screen.safeArea.top) + case .bottom: calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight ?? 0, safeArea: screen.safeArea.top) case .centre: fatalError() } } - func calculateBottomBodyPadding(activePopupHeight: CGFloat, popup: AnyPopup) -> CGFloat { + func calculateBottomBodyPadding(popup: AnyPopup) -> CGFloat { if popup.config.ignoredSafeAreaEdges.contains(.bottom) && !isKeyboardActive { return 0 } return switch alignment { - case .top: calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight, safeArea: screen.safeArea.bottom) + case .top: calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight ?? 0, safeArea: screen.safeArea.bottom) case .bottom: calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupPadding: popup.popupPadding.bottom) case .centre: fatalError() } From bc09411db2f1b55726cfcfc77edf0de285c7a684 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 18:03:05 +0100 Subject: [PATCH 075/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 1d95e2e6b0..789c43c2ed 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -19,7 +19,6 @@ extension VM { class VerticalStack: ViewModel { // MARK: Overridden Methods override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _recalculatePopupHeight(heightCandidate, popup) } override func recalculatePopupPadding() async -> EdgeInsets { calculatePopupPadding() } - override func recalculateBodyPadding(for popup: AnyPopup) async -> EdgeInsets { calculateBodyPadding(for: popup) } override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } }} From 7c5c5613268044fcdf5af9f88e2d1ecfb7d429eb Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 18:04:23 +0100 Subject: [PATCH 076/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 789c43c2ed..85c6c5bde2 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -17,8 +17,8 @@ extension VM { class VerticalStack: ViewModel { private(set) var translationProgress: CGFloat = 0 // MARK: Overridden Methods - override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _recalculatePopupHeight(heightCandidate, popup) } - override func recalculatePopupPadding() async -> EdgeInsets { calculatePopupPadding() } + override func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _calculatePopupHeight(heightCandidate, popup) } + override func calculatePopupPadding() async -> EdgeInsets { _calculatePopupPadding() } override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } }} @@ -47,7 +47,7 @@ private extension VM.VerticalStack { // MARK: Popup Height private extension VM.VerticalStack { - nonisolated func _recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { + nonisolated func _calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { guard await gestureTranslation.isZero, heightCandidate != popup.height else { return popup.height ?? 0 } let popupHeight = await calculateNewPopupHeight(heightCandidate, popup.config) @@ -83,7 +83,7 @@ private extension VM.VerticalStack { // MARK: Popup Padding private extension VM.VerticalStack { - func calculatePopupPadding() -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return .init( + func _calculatePopupPadding() -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return .init( top: calculateVerticalPopupPadding(for: .top, activePopupConfig: activePopupConfig), leading: calculateLeadingPopupPadding(activePopupConfig: activePopupConfig), bottom: calculateVerticalPopupPadding(for: .bottom, activePopupConfig: activePopupConfig), From bad5e3362f8e066f650a66271886ab63aedf04bf Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 18:09:39 +0100 Subject: [PATCH 077/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 85c6c5bde2..5b4c34b52d 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -18,7 +18,7 @@ extension VM { class VerticalStack: ViewModel { // MARK: Overridden Methods override func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _calculatePopupHeight(heightCandidate, popup) } - override func calculatePopupPadding() async -> EdgeInsets { _calculatePopupPadding() } + override func calculatePopupPadding() async -> EdgeInsets { await _calculatePopupPadding() } override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } }} @@ -83,7 +83,7 @@ private extension VM.VerticalStack { // MARK: Popup Padding private extension VM.VerticalStack { - func _calculatePopupPadding() -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return .init( + nonisolated func _calculatePopupPadding() async -> EdgeInsets { guard let activePopupConfig = await popups.last?.config else { return .init() }; return await .init( top: calculateVerticalPopupPadding(for: .top, activePopupConfig: activePopupConfig), leading: calculateLeadingPopupPadding(activePopupConfig: activePopupConfig), bottom: calculateVerticalPopupPadding(for: .bottom, activePopupConfig: activePopupConfig), @@ -91,26 +91,26 @@ private extension VM.VerticalStack { )} } private extension VM.VerticalStack { - func calculateVerticalPopupPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) -> CGFloat { - let largeScreenHeight = calculateLargeScreenHeight(), - activePopupHeight = activePopupHeight ?? 0, - priorityPopupPaddingValue = calculatePriorityPopupPaddingValue(for: edge), + nonisolated func calculateVerticalPopupPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { + let largeScreenHeight = await calculateLargeScreenHeight(), + activePopupHeight = await activePopupHeight ?? 0, + priorityPopupPaddingValue = await calculatePriorityPopupPaddingValue(for: edge, activePopupConfig: activePopupConfig), remainingHeight = largeScreenHeight - activePopupHeight - priorityPopupPaddingValue let popupPaddingCandidate = min(remainingHeight, activePopupConfig.popupPadding[edge]) return max(popupPaddingCandidate, 0) } - func calculateLeadingPopupPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { + nonisolated func calculateLeadingPopupPadding(activePopupConfig: AnyPopupConfig) async -> CGFloat { activePopupConfig.popupPadding.leading } - func calculateTrailingPopupPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { + nonisolated func calculateTrailingPopupPadding(activePopupConfig: AnyPopupConfig) async -> CGFloat { activePopupConfig.popupPadding.trailing } } private extension VM.VerticalStack { - func calculatePriorityPopupPaddingValue(for edge: PopupAlignment) -> CGFloat { switch edge == alignment { + nonisolated func calculatePriorityPopupPaddingValue(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { switch edge == alignment { case true: 0 - case false: getActivePopupConfig().popupPadding[!edge] + case false: activePopupConfig.popupPadding[!edge] }} } From ebc18ef6a096ae7e7dd38f7f074e61fd0d5920d5 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 18:48:53 +0100 Subject: [PATCH 078/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 2 +- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index cb19d68df0..e50aebcc98 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -13,7 +13,7 @@ import SwiftUI extension VM { class CentreStack: ViewModel { // MARK: Overridden Methods - override func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await recalculatePopupHeight(heightCandidate) } + override func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await recalculatePopupHeight(heightCandidate) } override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } }} diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 5b4c34b52d..78be90067b 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -457,7 +457,7 @@ private extension VM.VerticalStack { // MARK: Methods extension VM.VerticalStack { - func t_calculatePopupPadding() -> EdgeInsets { calculatePopupPadding() } + func t_calculatePopupPadding() async -> EdgeInsets { await calculatePopupPadding() } func t_calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { calculateBodyPadding(for: popup) } func t_calculateHeight(heightCandidate: CGFloat, popup: AnyPopup) -> CGFloat { calculateNewPopupHeight(heightCandidate, popup.config) } func t_calculateOffsetY(for popup: AnyPopup) -> CGFloat { calculateOffsetY(for: popup) } @@ -465,10 +465,10 @@ extension VM.VerticalStack { func t_calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { calculateVerticalFixedSize(for: popup) } func t_calculateStackOverlayOpacity(for popup: AnyPopup) -> CGFloat { calculateStackOverlayOpacity(for: popup) } func t_calculateCornerRadius() -> [PopupAlignment: CGFloat] { calculateCornerRadius() } - func t_calculateTranslationProgress() -> CGFloat { calculateTranslationProgress() } + func t_calculateTranslationProgress() async -> CGFloat { await calculateTranslationProgress() } func t_getInvertedIndex(of popup: AnyPopup) -> Int { getInvertedIndex(of: popup) } - func t_calculateAndUpdateTranslationProgress() { translationProgress = calculateTranslationProgress() } + func t_calculateAndUpdateTranslationProgress() { Task { translationProgress = await calculateTranslationProgress() }} func t_updateGestureTranslation(_ newGestureTranslation: CGFloat) { updateGestureTranslation(newGestureTranslation) } func t_onPopupDragGestureChanged(_ value: CGFloat) { onPopupDragGestureChanged(value) } From 178f11015f5449580ae479a440892cbbff483978 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 19:31:59 +0100 Subject: [PATCH 079/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 200 +++++++++--------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index efeefae81b..d119ece196 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -52,8 +52,8 @@ private extension PopupVerticalStackViewModelTests { // MARK: Inverted Index extension PopupVerticalStackViewModelTests { - func test_getInvertedIndex_1() { - bottomViewModel.t_updatePopupsValue([ + func test_getInvertedIndex_1() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150) ]) @@ -62,8 +62,8 @@ extension PopupVerticalStackViewModelTests { 0 ) } - func test_getInvertedIndex_2() { - bottomViewModel.t_updatePopupsValue([ + func test_getInvertedIndex_2() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), @@ -80,7 +80,7 @@ extension PopupVerticalStackViewModelTests { // MARK: Update Popup extension PopupVerticalStackViewModelTests { - func test_updatePopup_1() { + func test_updatePopup_1() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 0) ] @@ -88,14 +88,14 @@ extension PopupVerticalStackViewModelTests { .settingHeight(100) .settingDragHeight(100) - appendPopupsAndCheckPopups( + await appendPopupsAndCheckPopups( viewModel: bottomViewModel, popups: popups, updatedPopup: updatedPopup, expectedValue: (height: 100, dragHeight: 100) ) } - func test_updatePopup_2() { + func test_updatePopup_2() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 50), @@ -105,14 +105,14 @@ extension PopupVerticalStackViewModelTests { ] let updatedPopup = popups[2].settingHeight(1371) - appendPopupsAndCheckPopups( + await appendPopupsAndCheckPopups( viewModel: bottomViewModel, popups: popups, updatedPopup: updatedPopup, expectedValue: (height: 1371, dragHeight: nil) ) } - func test_updatePopup_3() { + func test_updatePopup_3() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 50), @@ -123,7 +123,7 @@ extension PopupVerticalStackViewModelTests { ] let updatedPopup = popups[4].settingHeight(nil) - appendPopupsAndCheckPopups( + await appendPopupsAndCheckPopups( viewModel: bottomViewModel, popups: popups, updatedPopup: updatedPopup, @@ -132,9 +132,9 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckPopups(viewModel: ViewModel, popups: [AnyPopup], updatedPopup: AnyPopup, expectedValue: (height: CGFloat?, dragHeight: CGFloat?)) { - viewModel.t_updatePopupsValue(popups) - viewModel.t_updatePopup(updatedPopup) + func appendPopupsAndCheckPopups(viewModel: ViewModel, popups: [AnyPopup], updatedPopup: AnyPopup, expectedValue: (height: CGFloat?, dragHeight: CGFloat?)) async { + await viewModel.t_updatePopupsValue(popups) + await viewModel.t_updatePopup(updatedPopup) if let index = viewModel.t_popups.firstIndex(of: updatedPopup) { XCTAssertEqual(viewModel.t_popups[index].height, expectedValue.height) @@ -145,8 +145,8 @@ private extension PopupVerticalStackViewModelTests { // MARK: Popup Height extension PopupVerticalStackViewModelTests { - func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_onePopupStacked() { - bottomViewModel.t_updatePopupsValue([ + func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_onePopupStacked() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150) ]) @@ -155,8 +155,8 @@ extension PopupVerticalStackViewModelTests { 150.0 ) } - func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_fourPopupsStacked() { - bottomViewModel.t_updatePopupsValue([ + func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_fourPopupsStacked() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 200), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), @@ -168,8 +168,8 @@ extension PopupVerticalStackViewModelTests { 100.0 ) } - func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_onePopupStacked() { - bottomViewModel.t_updatePopupsValue([ + func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_onePopupStacked() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2000) ]) @@ -178,8 +178,8 @@ extension PopupVerticalStackViewModelTests { screen.height - screen.safeArea.top ) } - func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_fivePopupStacked() { - bottomViewModel.t_updatePopupsValue([ + func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_fivePopupStacked() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 200), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), @@ -192,8 +192,8 @@ extension PopupVerticalStackViewModelTests { screen.height - screen.safeArea.top - bottomViewModel.t_stackOffset * 4 ) } - func test_calculatePopupHeight_withLargeHeightMode_whenOnePopupStacked() { - bottomViewModel.t_updatePopupsValue([ + func test_calculatePopupHeight_withLargeHeightMode_whenOnePopupStacked() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 100) ]) @@ -202,8 +202,8 @@ extension PopupVerticalStackViewModelTests { screen.height - screen.safeArea.top ) } - func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupStacked() { - bottomViewModel.t_updatePopupsValue([ + func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupStacked() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 700), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 1000) @@ -214,8 +214,8 @@ extension PopupVerticalStackViewModelTests { screen.height - screen.safeArea.top - bottomViewModel.t_stackOffset * 2 ) } - func test_calculatePopupHeight_withFullscreenHeightMode_whenOnePopupStacked() { - bottomViewModel.t_updatePopupsValue([ + func test_calculatePopupHeight_withFullscreenHeightMode_whenOnePopupStacked() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100) ]) @@ -224,8 +224,8 @@ extension PopupVerticalStackViewModelTests { screen.height ) } - func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked() { - bottomViewModel.t_updatePopupsValue([ + func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 2000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 3000) @@ -236,8 +236,8 @@ extension PopupVerticalStackViewModelTests { screen.height ) } - func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupsStacked_popupPadding() { - bottomViewModel.t_updatePopupsValue([ + func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupsStacked_popupPadding() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 2000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 3000, popupPadding: .init(top: 33, leading: 15, bottom: 21, trailing: 15)) @@ -248,8 +248,8 @@ extension PopupVerticalStackViewModelTests { screen.height - screen.safeArea.top - 2 * bottomViewModel.t_stackOffset ) } - func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked_popupPadding() { - bottomViewModel.t_updatePopupsValue([ + func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked_popupPadding() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 2000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 3000, popupPadding: .init(top: 33, leading: 15, bottom: 21, trailing: 15)) @@ -260,8 +260,8 @@ extension PopupVerticalStackViewModelTests { screen.height ) } - func test_calculatePopupHeight_withLargeHeightMode_whenPopupsHaveTopAlignment() { - topViewModel.t_updatePopupsValue([ + func test_calculatePopupHeight_withLargeHeightMode_whenPopupsHaveTopAlignment() async { + await topViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .large, popupHeight: 100) ]) @@ -279,141 +279,141 @@ private extension PopupVerticalStackViewModelTests { // MARK: Active Popup Height extension PopupVerticalStackViewModelTests { - func test_calculateActivePopupHeight_withAutoHeightMode_whenLessThanScreen_onePopupStacked() { + func test_calculateActivePopupHeight_withAutoHeightMode_whenLessThanScreen_onePopupStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100) ] - appendPopupsAndCheckActivePopupHeight( + await appendPopupsAndCheckActivePopupHeight( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: 100 ) } - func test_calculateActivePopupHeight_withAutoHeightMode_whenBiggerThanScreen_threePopupsStacked() { + func test_calculateActivePopupHeight_withAutoHeightMode_whenBiggerThanScreen_threePopupsStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 3000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2000) ] - appendPopupsAndCheckActivePopupHeight( + await appendPopupsAndCheckActivePopupHeight( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: screen.height - screen.safeArea.top - 2 * bottomViewModel.t_stackOffset ) } - func test_calculateActivePopupHeight_withLargeHeightMode_whenThreePopupsStacked() { + func test_calculateActivePopupHeight_withLargeHeightMode_whenThreePopupsStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 2000) ] - appendPopupsAndCheckActivePopupHeight( + await appendPopupsAndCheckActivePopupHeight( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: screen.height - screen.safeArea.top - 2 * bottomViewModel.t_stackOffset ) } - func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsNegative_twoPopupsStacked() { + func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsNegative_twoPopupsStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2000) ] - appendPopupsAndCheckActivePopupHeight( + await appendPopupsAndCheckActivePopupHeight( viewModel: bottomViewModel, popups: popups, gestureTranslation: -51, expectedValue: screen.height - screen.safeArea.top - bottomViewModel.t_stackOffset * 1 + 51 ) } - func test_calculateActivePopupHeight_withLargeHeightMode_whenGestureIsNegative_onePopupStacked() { + func test_calculateActivePopupHeight_withLargeHeightMode_whenGestureIsNegative_onePopupStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 350) ] - appendPopupsAndCheckActivePopupHeight( + await appendPopupsAndCheckActivePopupHeight( viewModel: bottomViewModel, popups: popups, gestureTranslation: -99, expectedValue: screen.height - screen.safeArea.top + 99 ) } - func test_calculateActivePopupHeight_withFullscreenHeightMode_whenGestureIsNegative_twoPopupsStacked() { + func test_calculateActivePopupHeight_withFullscreenHeightMode_whenGestureIsNegative_twoPopupsStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 250) ] - appendPopupsAndCheckActivePopupHeight( + await appendPopupsAndCheckActivePopupHeight( viewModel: bottomViewModel, popups: popups, gestureTranslation: -21, expectedValue: screen.height ) } - func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsPositive_threePopupsStacked() { + func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsPositive_threePopupsStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 350), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 850) ] - appendPopupsAndCheckActivePopupHeight( + await appendPopupsAndCheckActivePopupHeight( viewModel: bottomViewModel, popups: popups, gestureTranslation: 100, expectedValue: 850 ) } - func test_calculateActivePopupHeight_withFullscreenHeightMode_whenGestureIsPositive_onePopupStacked() { + func test_calculateActivePopupHeight_withFullscreenHeightMode_whenGestureIsPositive_onePopupStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 350) ] - appendPopupsAndCheckActivePopupHeight( + await appendPopupsAndCheckActivePopupHeight( viewModel: bottomViewModel, popups: popups, gestureTranslation: 31, expectedValue: screen.height ) } - func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsNegative_hasDragHeightStored_twoPopupsStacked() { + func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsNegative_hasDragHeightStored_twoPopupsStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 350), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 500, popupDragHeight: 100) ] - appendPopupsAndCheckActivePopupHeight( + await appendPopupsAndCheckActivePopupHeight( viewModel: bottomViewModel, popups: popups, gestureTranslation: -93, expectedValue: 500 + 100 + 93 ) } - func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsPositive_hasDragHeightStored_onePopupStacked() { + func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsPositive_hasDragHeightStored_onePopupStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1300, popupDragHeight: 100) ] - appendPopupsAndCheckActivePopupHeight( + await appendPopupsAndCheckActivePopupHeight( viewModel: bottomViewModel, popups: popups, gestureTranslation: 350, expectedValue: screen.height - screen.safeArea.top ) } - func test_calculateActivePopupHeight_withPopupsHaveTopAlignment() { + func test_calculateActivePopupHeight_withPopupsHaveTopAlignment() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .large, popupHeight: 1300) ] - appendPopupsAndCheckActivePopupHeight( + await appendPopupsAndCheckActivePopupHeight( viewModel: topViewModel, popups: popups, gestureTranslation: 0, @@ -422,8 +422,8 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckActivePopupHeight(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: CGFloat) { - appendPopupsAndPerformChecks( + func appendPopupsAndCheckActivePopupHeight(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: CGFloat) async { + await appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, @@ -435,8 +435,8 @@ private extension PopupVerticalStackViewModelTests { // MARK: Offset extension PopupVerticalStackViewModelTests { - func test_calculateOffsetY_withZeroGestureTranslation_fivePopupsStacked_thirdElement() { - bottomViewModel.t_updatePopupsValue([ + func test_calculateOffsetY_withZeroGestureTranslation_fivePopupsStacked_thirdElement() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 240), @@ -449,8 +449,8 @@ extension PopupVerticalStackViewModelTests { -bottomViewModel.t_stackOffset * 2 ) } - func test_calculateOffsetY_withZeroGestureTranslation_fivePopupsStacked_lastElement() { - bottomViewModel.t_updatePopupsValue([ + func test_calculateOffsetY_withZeroGestureTranslation_fivePopupsStacked_lastElement() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 240), @@ -463,11 +463,11 @@ extension PopupVerticalStackViewModelTests { 0 ) } - func test_calculateOffsetY_withNegativeGestureTranslation_dragHeight_onePopupStacked() { - bottomViewModel.t_updatePopupsValue([ + func test_calculateOffsetY_withNegativeGestureTranslation_dragHeight_onePopupStacked() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 100) ]) - bottomViewModel.t_updateGestureTranslation(-100) + await bottomViewModel.t_updateGestureTranslation(-100) XCTAssertEqual( bottomViewModel.t_calculateOffsetY(for: bottomViewModel.t_popups[0]), @@ -1268,10 +1268,10 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckGestureTranslationOnChange(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat, gestureTranslation: CGFloat)) { - viewModel.t_updatePopupsValue(popups) - viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) - viewModel.t_onPopupDragGestureChanged(gestureValue) + func appendPopupsAndCheckGestureTranslationOnChange(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat, gestureTranslation: CGFloat)) async { + await viewModel.t_updatePopupsValue(popups) + await viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) + await viewModel.t_onPopupDragGestureChanged(gestureValue) XCTAssertEqual(viewModel.t_activePopupHeight, expectedValues.popupHeight) XCTAssertEqual(viewModel.t_gestureTranslation, expectedValues.gestureTranslation) @@ -1280,144 +1280,144 @@ private extension PopupVerticalStackViewModelTests { // MARK: On Drag Gesture Ended extension PopupVerticalStackViewModelTests { - func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenNoDragDetents() { + func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenNoDragDetents() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: bottomViewModel, popups: popups, gestureValue: -200, expectedValues: (popupHeight: 344, shouldPopupBeDismissed: false) ) } - func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_1() { + func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_1() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440)]) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: bottomViewModel, popups: popups, gestureValue: -200, expectedValues: (popupHeight: 440, shouldPopupBeDismissed: false) ) } - func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_2() { + func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_2() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520)]) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: bottomViewModel, popups: popups, gestureValue: -120, expectedValues: (popupHeight: 520, shouldPopupBeDismissed: false) ) } - func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_3() { + func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_3() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520)]) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: bottomViewModel, popups: popups, gestureValue: -42, expectedValues: (popupHeight: 440, shouldPopupBeDismissed: false) ) } - func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_4() { + func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_4() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520), .large, .fullscreen]) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: bottomViewModel, popups: popups, gestureValue: -300, expectedValues: (popupHeight: screen.height - screen.safeArea.top, shouldPopupBeDismissed: false) ) } - func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_5() { + func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_5() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520), .large, .fullscreen]) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: bottomViewModel, popups: popups, gestureValue: -600, expectedValues: (popupHeight: screen.height, shouldPopupBeDismissed: false) ) } - func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_topPopupsAlignment_1() { + func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_topPopupsAlignment_1() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520), .large, .fullscreen]) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: topViewModel, popups: popups, gestureValue: -300, expectedValues: (popupHeight: nil, shouldPopupBeDismissed: true) ) } - func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_topPopupsAlignment_2() { + func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_topPopupsAlignment_2() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520), .large, .fullscreen]) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: topViewModel, popups: popups, gestureValue: -15, expectedValues: (popupHeight: 344, shouldPopupBeDismissed: false) ) } - func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_bottomPopupsAlignment_1() { + func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_bottomPopupsAlignment_1() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 400) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: bottomViewModel, popups: popups, gestureValue: 50, expectedValues: (popupHeight: 400, shouldPopupBeDismissed: false) ) } - func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_bottomPopupsAlignment_2() { + func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_bottomPopupsAlignment_2() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 400) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: bottomViewModel, popups: popups, gestureValue: 300, expectedValues: (popupHeight: nil, shouldPopupBeDismissed: true) ) } - func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_topPopupsAlignment_1() { + func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_topPopupsAlignment_1() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 400) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: topViewModel, popups: popups, gestureValue: 400, expectedValues: (popupHeight: 400, shouldPopupBeDismissed: false) ) } - func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_topPopupsAlignment_2() { + func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_topPopupsAlignment_2() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 400, dragDetents: [.large]) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: topViewModel, popups: popups, gestureValue: 100, @@ -1438,12 +1438,12 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckGestureTranslationOnEnd(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat?, shouldPopupBeDismissed: Bool)) { - viewModel.t_updatePopupsValue(popups) - viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) - viewModel.t_updateGestureTranslation(gestureValue) - viewModel.t_calculateAndUpdateTranslationProgress() - viewModel.t_onPopupDragGestureEnded(gestureValue) + func appendPopupsAndCheckGestureTranslationOnEnd(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat?, shouldPopupBeDismissed: Bool)) async { + await viewModel.t_updatePopupsValue(popups) + await viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) + await viewModel.t_updateGestureTranslation(gestureValue) + await viewModel.t_calculateAndUpdateTranslationProgress() + await viewModel.t_onPopupDragGestureEnded(gestureValue) XCTAssertEqual(viewModel.t_popups.count, expectedValues.shouldPopupBeDismissed ? 0 : 1) XCTAssertEqual(viewModel.t_activePopupHeight, expectedValues.popupHeight) From 53741458d00604be39dbaa14bda75538d2f88f43 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 19:33:57 +0100 Subject: [PATCH 080/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 132 +++++++++--------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index d119ece196..ed13b2bfad 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -822,76 +822,76 @@ private extension PopupVerticalStackViewModelTests { // MARK: Corner Radius extension PopupVerticalStackViewModelTests { - func test_calculateCornerRadius_withTwoPopupsStacked() { + func test_calculateCornerRadius_withTwoPopupsStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 1), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 12) ] - appendPopupsAndCheckCornerRadius( + await appendPopupsAndCheckCornerRadius( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: [.top: 12, .bottom: 0] ) } - func test_calculateCornerRadius_withPopupPadding_bottom_first() { + func test_calculateCornerRadius_withPopupPadding_bottom_first() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupPadding: .init(top: 0, leading: 0, bottom: 12, trailing: 0), cornerRadius: 1), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 12) ] - appendPopupsAndCheckCornerRadius( + await appendPopupsAndCheckCornerRadius( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: [.top: 12, .bottom: 0] ) } - func test_calculateCornerRadius_withPopupPadding_bottom_last() { + func test_calculateCornerRadius_withPopupPadding_bottom_last() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 1), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupPadding: .init(top: 0, leading: 0, bottom: 12, trailing: 0), cornerRadius: 12) ] - appendPopupsAndCheckCornerRadius( + await appendPopupsAndCheckCornerRadius( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: [.top: 12, .bottom: 12] ) } - func test_calculateCornerRadius_withPopupPadding_all() { + func test_calculateCornerRadius_withPopupPadding_all() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 1), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupPadding: .init(top: 12, leading: 24, bottom: 12, trailing: 24), cornerRadius: 12) ] - appendPopupsAndCheckCornerRadius( + await appendPopupsAndCheckCornerRadius( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: [.top: 12, .bottom: 12] ) } - func test_calculateCornerRadius_fullscreen() { + func test_calculateCornerRadius_fullscreen() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 300, cornerRadius: 13) ] - appendPopupsAndCheckCornerRadius( + await appendPopupsAndCheckCornerRadius( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: [.top: 0, .bottom: 0] ) } - func test_calculateCornerRadius_whenPopupsHaveTopAlignment() { + func test_calculateCornerRadius_whenPopupsHaveTopAlignment() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 12) ] - appendPopupsAndCheckCornerRadius( + await appendPopupsAndCheckCornerRadius( viewModel: topViewModel, popups: popups, gestureTranslation: 0, @@ -900,8 +900,8 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckCornerRadius(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: [MijickPopups.PopupAlignment: CGFloat]) { - appendPopupsAndPerformChecks( + func appendPopupsAndCheckCornerRadius(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: [MijickPopups.PopupAlignment: CGFloat]) async { + await appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, @@ -913,14 +913,14 @@ private extension PopupVerticalStackViewModelTests { // MARK: Scale X extension PopupVerticalStackViewModelTests { - func test_calculateScaleX_withNoGestureTranslation_threePopupsStacked_last() { + func test_calculateScaleX_withNoGestureTranslation_threePopupsStacked_last() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 360) ] - appendPopupsAndCheckScaleX( + await appendPopupsAndCheckScaleX( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, @@ -928,7 +928,7 @@ extension PopupVerticalStackViewModelTests { expectedValueBuilder: {_ in 1 } ) } - func test_calculateScaleX_withNoGestureTranslation_fourPopupsStacked_second() { + func test_calculateScaleX_withNoGestureTranslation_fourPopupsStacked_second() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), @@ -936,7 +936,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1360) ] - appendPopupsAndCheckScaleX( + await appendPopupsAndCheckScaleX( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, @@ -944,7 +944,7 @@ extension PopupVerticalStackViewModelTests { expectedValueBuilder: { 1 - $0.t_stackScaleFactor * 2 } ) } - func test_calculateScaleX_withNegativeGestureTranslation_fourPopupsStacked_third() { + func test_calculateScaleX_withNegativeGestureTranslation_fourPopupsStacked_third() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), @@ -952,7 +952,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1360) ] - appendPopupsAndCheckScaleX( + await appendPopupsAndCheckScaleX( viewModel: bottomViewModel, popups: popups, gestureTranslation: -100, @@ -960,7 +960,7 @@ extension PopupVerticalStackViewModelTests { expectedValueBuilder: { 1 - $0.t_stackScaleFactor * 1 } ) } - func test_calculateScaleX_withPositiveGestureTranslation_fivePopupsStacked_second() { + func test_calculateScaleX_withPositiveGestureTranslation_fivePopupsStacked_second() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), @@ -969,18 +969,18 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 123) ] - appendPopupsAndCheckScaleX( + await appendPopupsAndCheckScaleX( viewModel: bottomViewModel, popups: popups, gestureTranslation: 100, calculateForIndex: 1, - expectedValueBuilder: { 1 - $0.t_stackScaleFactor * 3 * max(1 - $0.t_calculateTranslationProgress(), $0.t_minScaleProgressMultiplier) } + expectedValueBuilder: { await 1 - $0.t_stackScaleFactor * 3 * max(1 - $0.t_calculateTranslationProgress(), $0.t_minScaleProgressMultiplier) } ) } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckScaleX(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValueBuilder: @escaping (ViewModel) -> CGFloat) { - appendPopupsAndPerformChecks( + func appendPopupsAndCheckScaleX(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValueBuilder: @escaping (ViewModel) async -> CGFloat) async { + await appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, @@ -992,13 +992,13 @@ private extension PopupVerticalStackViewModelTests { // MARK: Fixed Size extension PopupVerticalStackViewModelTests { - func test_calculateFixedSize_withAutoHeightMode_whenLessThanScreen_twoPopupsStacked() { + func test_calculateFixedSize_withAutoHeightMode_whenLessThanScreen_twoPopupsStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1360), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 123) ] - appendPopupsAndCheckVerticalFixedSize( + await appendPopupsAndCheckVerticalFixedSize( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, @@ -1006,13 +1006,13 @@ extension PopupVerticalStackViewModelTests { expectedValue: true ) } - func test_calculateFixedSize_withAutoHeightMode_whenBiggerThanScreen_twoPopupsStacked() { + func test_calculateFixedSize_withAutoHeightMode_whenBiggerThanScreen_twoPopupsStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1360), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1223) ] - appendPopupsAndCheckVerticalFixedSize( + await appendPopupsAndCheckVerticalFixedSize( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, @@ -1020,14 +1020,14 @@ extension PopupVerticalStackViewModelTests { expectedValue: false ) } - func test_calculateFixedSize_withLargeHeightMode_threePopupsStacked() { + func test_calculateFixedSize_withLargeHeightMode_threePopupsStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1223), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 1223) ] - appendPopupsAndCheckVerticalFixedSize( + await appendPopupsAndCheckVerticalFixedSize( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, @@ -1035,7 +1035,7 @@ extension PopupVerticalStackViewModelTests { expectedValue: false ) } - func test_calculateFixedSize_withFullscreenHeightMode_fivePopupsStacked() { + func test_calculateFixedSize_withFullscreenHeightMode_fivePopupsStacked() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1223), @@ -1044,7 +1044,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1223) ] - appendPopupsAndCheckVerticalFixedSize( + await appendPopupsAndCheckVerticalFixedSize( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, @@ -1054,8 +1054,8 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckVerticalFixedSize(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValue: Bool) { - appendPopupsAndPerformChecks( + func appendPopupsAndCheckVerticalFixedSize(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValue: Bool) async { + await appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, @@ -1067,14 +1067,14 @@ private extension PopupVerticalStackViewModelTests { // MARK: Stack Overlay Opacity extension PopupVerticalStackViewModelTests { - func test_calculateStackOverlayOpacity_withThreePopupsStacked_whenNoGestureTranslation_last() { + func test_calculateStackOverlayOpacity_withThreePopupsStacked_whenNoGestureTranslation_last() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 233), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 512) ] - appendPopupsAndCheckStackOverlayOpacity( + await appendPopupsAndCheckStackOverlayOpacity( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, @@ -1082,7 +1082,7 @@ extension PopupVerticalStackViewModelTests { expectedValueBuilder: { _ in 0 } ) } - func test_calculateStackOverlayOpacity_withFourPopupsStacked_whenNoGestureTranslation_second() { + func test_calculateStackOverlayOpacity_withFourPopupsStacked_whenNoGestureTranslation_second() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 233), @@ -1090,7 +1090,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 812) ] - appendPopupsAndCheckStackOverlayOpacity( + await appendPopupsAndCheckStackOverlayOpacity( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, @@ -1098,7 +1098,7 @@ extension PopupVerticalStackViewModelTests { expectedValueBuilder: { $0.t_stackOverlayFactor * 2 } ) } - func test_calculateStackOverlayOpacity_withFourPopupsStacked_whenGestureTranslationIsNegative_last() { + func test_calculateStackOverlayOpacity_withFourPopupsStacked_whenGestureTranslationIsNegative_last() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 233), @@ -1106,7 +1106,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 812) ] - appendPopupsAndCheckStackOverlayOpacity( + await appendPopupsAndCheckStackOverlayOpacity( viewModel: bottomViewModel, popups: popups, gestureTranslation: -123, @@ -1114,7 +1114,7 @@ extension PopupVerticalStackViewModelTests { expectedValueBuilder: { _ in 0 } ) } - func test_calculateStackOverlayOpacity_withTenPopupsStacked_whenGestureTranslationIsNegative_first() { + func test_calculateStackOverlayOpacity_withTenPopupsStacked_whenGestureTranslationIsNegative_first() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 55), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 233), @@ -1128,7 +1128,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 356) ] - appendPopupsAndCheckStackOverlayOpacity( + await appendPopupsAndCheckStackOverlayOpacity( viewModel: bottomViewModel, popups: popups, gestureTranslation: -123, @@ -1136,14 +1136,14 @@ extension PopupVerticalStackViewModelTests { expectedValueBuilder: { min($0.t_stackOverlayFactor * 9, $0.t_maxStackOverlayFactor) } ) } - func test_calculateStackOverlayOpacity_withThreePopupsStacked_whenGestureTranslationIsPositive_last() { + func test_calculateStackOverlayOpacity_withThreePopupsStacked_whenGestureTranslationIsPositive_last() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 233), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 512) ] - appendPopupsAndCheckStackOverlayOpacity( + await appendPopupsAndCheckStackOverlayOpacity( viewModel: bottomViewModel, popups: popups, gestureTranslation: 494, @@ -1151,7 +1151,7 @@ extension PopupVerticalStackViewModelTests { expectedValueBuilder: { _ in 0 } ) } - func test_calculateStackOverlayOpacity_withFourPopupsStacked_whenGestureTranslationIsPositive_nextToLast() { + func test_calculateStackOverlayOpacity_withFourPopupsStacked_whenGestureTranslationIsPositive_nextToLast() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 233), @@ -1159,18 +1159,18 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 343) ] - appendPopupsAndCheckStackOverlayOpacity( + await appendPopupsAndCheckStackOverlayOpacity( viewModel: bottomViewModel, popups: popups, gestureTranslation: 241, calculateForIndex: 2, - expectedValueBuilder: { (1 - $0.t_calculateTranslationProgress()) * $0.t_stackOverlayFactor } + expectedValueBuilder: { await (1 - $0.t_calculateTranslationProgress()) * $0.t_stackOverlayFactor } ) } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckStackOverlayOpacity(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValueBuilder: @escaping (ViewModel) -> CGFloat) { - appendPopupsAndPerformChecks( + func appendPopupsAndCheckStackOverlayOpacity(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValueBuilder: @escaping (ViewModel) async -> CGFloat) async { + await appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, @@ -1182,84 +1182,84 @@ private extension PopupVerticalStackViewModelTests { // MARK: On Drag Gesture Changed extension PopupVerticalStackViewModelTests { - func test_calculateValuesOnDragGestureChanged_withPositiveDragValue_whenDragGestureDisabled() { + func test_calculateValuesOnDragGestureChanged_withPositiveDragValue_whenDragGestureDisabled() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragGestureEnabled: false) ] - appendPopupsAndCheckGestureTranslationOnChange( + await appendPopupsAndCheckGestureTranslationOnChange( viewModel: bottomViewModel, popups: popups, gestureValue: 11, expectedValues: (popupHeight: 344, gestureTranslation: 0) ) } - func test_calculateValuesOnDragGestureChanged_withPositiveDragValue_whenDragGestureEnabled_bottomPopupsAlignment() { + func test_calculateValuesOnDragGestureChanged_withPositiveDragValue_whenDragGestureEnabled_bottomPopupsAlignment() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344) ] - appendPopupsAndCheckGestureTranslationOnChange( + await appendPopupsAndCheckGestureTranslationOnChange( viewModel: bottomViewModel, popups: popups, gestureValue: 11, expectedValues: (popupHeight: 344, gestureTranslation: 11) ) } - func test_calculateValuesOnDragGestureChanged_withPositiveDragValue_whenDragGestureEnabled_topPopupsAlignment() { + func test_calculateValuesOnDragGestureChanged_withPositiveDragValue_whenDragGestureEnabled_topPopupsAlignment() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 344) ] - appendPopupsAndCheckGestureTranslationOnChange( + await appendPopupsAndCheckGestureTranslationOnChange( viewModel: topViewModel, popups: popups, gestureValue: 11, expectedValues: (popupHeight: 344, gestureTranslation: 0) ) } - func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenNoDragDetents() { + func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenNoDragDetents() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: []) ] - appendPopupsAndCheckGestureTranslationOnChange( + await appendPopupsAndCheckGestureTranslationOnChange( viewModel: bottomViewModel, popups: popups, gestureValue: -133, expectedValues: (popupHeight: 344, gestureTranslation: 0) ) } - func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenDragDetents() { + func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenDragDetents() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(450)]) ] - appendPopupsAndCheckGestureTranslationOnChange( + await appendPopupsAndCheckGestureTranslationOnChange( viewModel: bottomViewModel, popups: popups, gestureValue: -40, expectedValues: (popupHeight: 384, gestureTranslation: -40) ) } - func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenDragDetentsLessThanDragValue_bottomPopupsAlignment() { + func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenDragDetentsLessThanDragValue_bottomPopupsAlignment() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(370)]) ] - appendPopupsAndCheckGestureTranslationOnChange( + await appendPopupsAndCheckGestureTranslationOnChange( viewModel: bottomViewModel, popups: popups, gestureValue: -133, expectedValues: (popupHeight: 370 + bottomViewModel.t_dragTranslationThreshold, gestureTranslation: 344 - 370 - bottomViewModel.t_dragTranslationThreshold) ) } - func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenDragDetentsLessThanDragValue_topPopupsAlignment() { + func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenDragDetentsLessThanDragValue_topPopupsAlignment() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(370)]) ] - appendPopupsAndCheckGestureTranslationOnChange( + await appendPopupsAndCheckGestureTranslationOnChange( viewModel: topViewModel, popups: popups, gestureValue: -133, @@ -1424,12 +1424,12 @@ extension PopupVerticalStackViewModelTests { expectedValues: (popupHeight: 400, shouldPopupBeDismissed: false) ) } - func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_topPopupsAlignment_3() { + func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_topPopupsAlignment_3() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 400, dragDetents: [.large]) ] - appendPopupsAndCheckGestureTranslationOnEnd( + await appendPopupsAndCheckGestureTranslationOnEnd( viewModel: topViewModel, popups: popups, gestureValue: 400, From b9a0154dbfff6585f8fcf33348cf4145812ed877 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 19:35:07 +0100 Subject: [PATCH 081/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 116 +++++++++--------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index ed13b2bfad..e5d94a99e9 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -474,32 +474,32 @@ extension PopupVerticalStackViewModelTests { 0 ) } - func test_calculateOffsetY_withPositiveGestureTranslation_dragHeight_twoPopupsStacked_firstElement() { - bottomViewModel.t_updatePopupsValue([ + func test_calculateOffsetY_withPositiveGestureTranslation_dragHeight_twoPopupsStacked_firstElement() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) - bottomViewModel.t_updateGestureTranslation(100) + await bottomViewModel.t_updateGestureTranslation(100) XCTAssertEqual( bottomViewModel.t_calculateOffsetY(for: bottomViewModel.t_popups[0]), -bottomViewModel.t_stackOffset ) } - func test_calculateOffsetY_withPositiveGestureTranslation_dragHeight_twoPopupsStacked_lastElement() { - bottomViewModel.t_updatePopupsValue([ + func test_calculateOffsetY_withPositiveGestureTranslation_dragHeight_twoPopupsStacked_lastElement() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) - bottomViewModel.t_updateGestureTranslation(100) + await bottomViewModel.t_updateGestureTranslation(100) XCTAssertEqual( bottomViewModel.t_calculateOffsetY(for: bottomViewModel.t_popups[1]), 100 - 21 ) } - func test_calculateOffsetY_withStackingDisabled() { - bottomViewModel.t_updatePopupsValue([ + func test_calculateOffsetY_withStackingDisabled() async { + await bottomViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) @@ -510,8 +510,8 @@ extension PopupVerticalStackViewModelTests { 0 ) } - func test_calculateOffsetY_withPopupsHaveTopAlignment_1() { - topViewModel.t_updatePopupsValue([ + func test_calculateOffsetY_withPopupsHaveTopAlignment_1() async { + await topViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) @@ -521,12 +521,12 @@ extension PopupVerticalStackViewModelTests { topViewModel.t_stackOffset ) } - func test_calculateOffsetY_withPopupsHaveTopAlignment_2() { - topViewModel.t_updatePopupsValue([ + func test_calculateOffsetY_withPopupsHaveTopAlignment_2() async { + await topViewModel.t_updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) - topViewModel.t_updateGestureTranslation(-100) + await topViewModel.t_updateGestureTranslation(-100) XCTAssertEqual( topViewModel.t_calculateOffsetY(for: topViewModel.t_popups[1]), @@ -537,84 +537,84 @@ extension PopupVerticalStackViewModelTests { // MARK: Popup Padding extension PopupVerticalStackViewModelTests { - func test_calculatePopupPadding_withAutoHeightMode_whenLessThanScreen() { + func test_calculatePopupPadding_withAutoHeightMode_whenLessThanScreen() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckPopupPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 12, leading: 17, bottom: 33, trailing: 17) ) } - func test_calculatePopupPadding_withAutoHeightMode_almostLikeScreen_onlyOnePaddingShouldBeNonZero() { + func test_calculatePopupPadding_withAutoHeightMode_almostLikeScreen_onlyOnePaddingShouldBeNonZero() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 877, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckPopupPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: 17, bottom: 23, trailing: 17) ) } - func test_calculatePopupPadding_withAutoHeightMode_almostLikeScreen_bothPaddingsShouldBeNonZero() { + func test_calculatePopupPadding_withAutoHeightMode_almostLikeScreen_bothPaddingsShouldBeNonZero() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 861, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckPopupPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 6, leading: 17, bottom: 33, trailing: 17) ) } - func test_calculatePopupPadding_withAutoHeightMode_almostLikeScreen_topPopupsAlignment() { + func test_calculatePopupPadding_withAutoHeightMode_almostLikeScreen_topPopupsAlignment() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 911, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckPopupPadding( viewModel: topViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 12, leading: 17, bottom: 27, trailing: 17) ) } - func test_calculatePopupPadding_withAutoHeightMode_whenBiggerThanScreen() { + func test_calculatePopupPadding_withAutoHeightMode_whenBiggerThanScreen() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1100, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckPopupPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: 17, bottom: 0, trailing: 17) ) } - func test_calculatePopupPadding_withLargeHeightMode() { + func test_calculatePopupPadding_withLargeHeightMode() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckPopupPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: 17, bottom: 0, trailing: 17) ) } - func test_calculatePopupPadding_withFullscreenHeightMode() { + func test_calculatePopupPadding_withFullscreenHeightMode() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckPopupPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, @@ -623,12 +623,12 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckPopupPadding(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: EdgeInsets) { - appendPopupsAndPerformChecks( + func appendPopupsAndCheckPopupPadding(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: EdgeInsets) async { + await appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.t_calculatePopupPadding() }, + calculatedValue: { await $0.t_calculatePopupPadding() }, expectedValueBuilder: { _ in expectedValue } ) } @@ -636,96 +636,96 @@ private extension PopupVerticalStackViewModelTests { // MARK: Body Padding extension PopupVerticalStackViewModelTests { - func test_calculateBodyPadding_withDefaultSettings() { + func test_calculateBodyPadding_withDefaultSettings() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 350) ] - appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckBodyPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: screen.safeArea.top, leading: screen.safeArea.leading, bottom: screen.safeArea.bottom, trailing: screen.safeArea.trailing) ) } - func test_calculateBodyPadding_withIgnoringSafeArea_bottom() { + func test_calculateBodyPadding_withIgnoringSafeArea_bottom() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 200, ignoredSafeAreaEdges: .bottom) ] - appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckBodyPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: screen.safeArea.leading, bottom: 0, trailing: screen.safeArea.trailing) ) } - func test_calculateBodyPadding_withIgnoringSafeArea_all() { + func test_calculateBodyPadding_withIgnoringSafeArea_all() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1200, ignoredSafeAreaEdges: .all) ] - appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckBodyPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: 0, bottom: 0, trailing: 0) ) } - func test_calculateBodyPadding_withPopupPadding() { + func test_calculateBodyPadding_withPopupPadding() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1200, popupPadding: .init(top: 21, leading: 12, bottom: 37, trailing: 12)) ] - appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckBodyPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: screen.safeArea.leading, bottom: screen.safeArea.bottom, trailing: screen.safeArea.trailing) ) } - func test_calculateBodyPadding_withFullscreenHeightMode_ignoringSafeArea_top() { + func test_calculateBodyPadding_withFullscreenHeightMode_ignoringSafeArea_top() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100, ignoredSafeAreaEdges: .top) ] - appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckBodyPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: screen.safeArea.leading, bottom: screen.safeArea.bottom, trailing: screen.safeArea.trailing) ) } - func test_calculateBodyPadding_withGestureTranslation() { + func test_calculateBodyPadding_withGestureTranslation() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 800) ] - appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckBodyPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: -300, expectedValue: .init(top: screen.safeArea.top, leading: screen.safeArea.leading, bottom: screen.safeArea.bottom, trailing: screen.safeArea.trailing) ) } - func test_calculateBodyPadding_withGestureTranslation_dragHeight() { + func test_calculateBodyPadding_withGestureTranslation_dragHeight() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupDragHeight: 700) ] - appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckBodyPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 21, expectedValue: .init(top: screen.safeArea.top - 21, leading: screen.safeArea.leading, bottom: screen.safeArea.bottom, trailing: screen.safeArea.trailing) ) } - func test_calculateBodyPadding_withGestureTranslation_dragHeight_topPopupsAlignment() { + func test_calculateBodyPadding_withGestureTranslation_dragHeight_topPopupsAlignment() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 300, popupDragHeight: 700) ] - appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckBodyPadding( viewModel: topViewModel, popups: popups, gestureTranslation: -21, @@ -734,8 +734,8 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckBodyPadding(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: EdgeInsets) { - appendPopupsAndPerformChecks( + func appendPopupsAndCheckBodyPadding(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: EdgeInsets) async { + await appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, @@ -747,60 +747,60 @@ private extension PopupVerticalStackViewModelTests { // MARK: Translation Progress extension PopupVerticalStackViewModelTests { - func test_calculateTranslationProgress_withNoGestureTranslation() { + func test_calculateTranslationProgress_withNoGestureTranslation() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300) ] - appendPopupsAndCheckTranslationProgress( + await appendPopupsAndCheckTranslationProgress( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: 0 ) } - func test_calculateTranslationProgress_withPositiveGestureTranslation() { + func test_calculateTranslationProgress_withPositiveGestureTranslation() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300) ] - appendPopupsAndCheckTranslationProgress( + await appendPopupsAndCheckTranslationProgress( viewModel: bottomViewModel, popups: popups, gestureTranslation: 250, expectedValue: 250 / 300 ) } - func test_calculateTranslationProgress_withPositiveGestureTranslation_dragHeight() { + func test_calculateTranslationProgress_withPositiveGestureTranslation_dragHeight() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupDragHeight: 120) ] - appendPopupsAndCheckTranslationProgress( + await appendPopupsAndCheckTranslationProgress( viewModel: bottomViewModel, popups: popups, gestureTranslation: 250, expectedValue: (250 - 120) / 300 ) } - func test_calculateTranslationProgress_withNegativeGestureTranslation() { + func test_calculateTranslationProgress_withNegativeGestureTranslation() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300) ] - appendPopupsAndCheckTranslationProgress( + await appendPopupsAndCheckTranslationProgress( viewModel: bottomViewModel, popups: popups, gestureTranslation: -175, expectedValue: 0 ) } - func test_calculateTranslationProgress_withNegativeGestureTranslation_whenTopPopupsAlignment() { + func test_calculateTranslationProgress_withNegativeGestureTranslation_whenTopPopupsAlignment() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 300) ] - appendPopupsAndCheckTranslationProgress( + await appendPopupsAndCheckTranslationProgress( viewModel: topViewModel, popups: popups, gestureTranslation: -175, From 930678e1c8d825f3ea1ca2f84f411c364140c9a3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 19:35:34 +0100 Subject: [PATCH 082/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index e5d94a99e9..641eb3f12b 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -25,22 +25,22 @@ import SwiftUI private extension PopupVerticalStackViewModelTests { func setup(_ viewModel: ViewModel) { viewModel.t_updateScreenValue(screen) - viewModel.t_setup(updatePopupAction: { self.updatePopupAction(viewModel, $0) }, closePopupAction: { self.closePopupAction(viewModel, $0) }) + viewModel.t_setup(updatePopupAction: { await self.updatePopupAction(viewModel, $0) }, closePopupAction: { await self.closePopupAction(viewModel, $0) }) } } private extension PopupVerticalStackViewModelTests { - func updatePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) { if let index = viewModel.t_popups.firstIndex(of: popup) { + func updatePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.t_popups.firstIndex(of: popup) { var popups = viewModel.t_popups popups[index] = popup - viewModel.t_updatePopupsValue(popups) - viewModel.t_calculateAndUpdateActivePopupHeight() + await viewModel.t_updatePopupsValue(popups) + await viewModel.t_calculateAndUpdateActivePopupHeight() }} - func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) { if let index = viewModel.t_popups.firstIndex(of: popup) { + func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.t_popups.firstIndex(of: popup) { var popups = viewModel.t_popups popups.remove(at: index) - viewModel.t_updatePopupsValue(popups) + await viewModel.t_updatePopupsValue(popups) }} } @@ -809,12 +809,12 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckTranslationProgress(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: CGFloat) { - appendPopupsAndPerformChecks( + func appendPopupsAndCheckTranslationProgress(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: CGFloat) async { + await appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.t_calculateTranslationProgress() }, + calculatedValue: { await $0.t_calculateTranslationProgress() }, expectedValueBuilder: { _ in expectedValue } ) } From 87de6ab52884d57d05adf51db55dead014582c6f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 19:35:49 +0100 Subject: [PATCH 083/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 641eb3f12b..32ebcfe9f8 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1465,12 +1465,14 @@ private extension PopupVerticalStackViewModelTests { .settingHeight(popupHeight) .settingDragHeight(popupDragHeight) } - func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) -> (Value), expectedValueBuilder: @escaping (ViewModel) -> Value) { - viewModel.t_updatePopupsValue(popups) - viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) - viewModel.t_updateGestureTranslation(gestureTranslation) + func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { + await viewModel.t_updatePopupsValue(popups) + await viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) + await viewModel.t_updateGestureTranslation(gestureTranslation) - XCTAssertEqual(calculatedValue(viewModel), expectedValueBuilder(viewModel)) + let calculatedValue = await calculatedValue(viewModel) + let expectedValue = await expectedValueBuilder(viewModel) + XCTAssertEqual(calculatedValue, expectedValue) } } private extension PopupVerticalStackViewModelTests { From 3b20f218d88ec2fbccc5be3e67ded4a7093fb0a9 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 19:38:57 +0100 Subject: [PATCH 084/407] 1 --- Tests/Tests+ViewModel+PopupCentreStack.swift | 74 ++++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index 3d7402e52f..91e1a96908 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -18,22 +18,22 @@ import SwiftUI override func setUp() async throws { viewModel.t_updateScreenValue(screen) - viewModel.t_setup(updatePopupAction: { [self] in updatePopupAction(viewModel, $0) }, closePopupAction: { [self] in closePopupAction(viewModel, $0) }) + viewModel.t_setup(updatePopupAction: { [self] in await updatePopupAction(viewModel, $0) }, closePopupAction: { [self] in await closePopupAction(viewModel, $0) }) } } private extension PopupCentreStackViewModelTests { - func updatePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) { if let index = viewModel.t_popups.firstIndex(of: popup) { + func updatePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.t_popups.firstIndex(of: popup) { var popups = viewModel.t_popups popups[index] = popup - viewModel.t_updatePopupsValue(popups) - viewModel.t_calculateAndUpdateActivePopupHeight() + await viewModel.t_updatePopupsValue(popups) + await viewModel.t_calculateAndUpdateActivePopupHeight() }} - func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) { if let index = viewModel.t_popups.firstIndex(of: popup) { + func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.t_popups.firstIndex(of: popup) { var popups = viewModel.t_popups popups.remove(at: index) - viewModel.t_updatePopupsValue(popups) + await viewModel.t_updatePopupsValue(popups) }} } @@ -45,53 +45,53 @@ private extension PopupCentreStackViewModelTests { // MARK: Popup Padding extension PopupCentreStackViewModelTests { - func test_calculatePopupPadding_withKeyboardHidden_whenCustomPaddingNotSet() { + func test_calculatePopupPadding_withKeyboardHidden_whenCustomPaddingNotSet() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72), createPopupInstanceForPopupHeightTests(popupHeight: 400) ] - appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckPopupPadding( popups: popups, isKeyboardActive: false, expectedValue: .init() ) } - func test_calculatePopupPadding_withKeyboardHidden_whenCustomPaddingSet() { + func test_calculatePopupPadding_withKeyboardHidden_whenCustomPaddingSet() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72, popupPadding: .init(top: 0, leading: 11, bottom: 0, trailing: 11)), createPopupInstanceForPopupHeightTests(popupHeight: 400, popupPadding: .init(top: 0, leading: 16, bottom: 0, trailing: 16)) ] - appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckPopupPadding( popups: popups, isKeyboardActive: false, expectedValue: .init(top: 0, leading: 16, bottom: 0, trailing: 16) ) } - func test_calculatePopupPadding_withKeyboardShown_whenKeyboardNotOverlapingPopup() { + func test_calculatePopupPadding_withKeyboardShown_whenKeyboardNotOverlapingPopup() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72, popupPadding: .init(top: 0, leading: 11, bottom: 0, trailing: 11)), createPopupInstanceForPopupHeightTests(popupHeight: 400, popupPadding: .init(top: 0, leading: 16, bottom: 0, trailing: 16)) ] - appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckPopupPadding( popups: popups, isKeyboardActive: true, expectedValue: .init(top: 0, leading: 16, bottom: 0, trailing: 16) ) } - func test_calculatePopupPadding_withKeyboardShown_whenKeyboardOverlapingPopup() { + func test_calculatePopupPadding_withKeyboardShown_whenKeyboardOverlapingPopup() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72, popupPadding: .init(top: 0, leading: 11, bottom: 0, trailing: 11)), createPopupInstanceForPopupHeightTests(popupHeight: 1000, popupPadding: .init(top: 0, leading: 16, bottom: 0, trailing: 16)) ] - appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckPopupPadding( popups: popups, isKeyboardActive: true, expectedValue: .init(top: 0, leading: 16, bottom: 250, trailing: 16) @@ -99,8 +99,8 @@ extension PopupCentreStackViewModelTests { } } private extension PopupCentreStackViewModelTests { - func appendPopupsAndCheckPopupPadding(popups: [AnyPopup], isKeyboardActive: Bool, expectedValue: EdgeInsets) { - appendPopupsAndPerformChecks( + func appendPopupsAndCheckPopupPadding(popups: [AnyPopup], isKeyboardActive: Bool, expectedValue: EdgeInsets) async { + await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: isKeyboardActive, calculatedValue: { $0.t_calculatePopupPadding() }, @@ -111,32 +111,32 @@ private extension PopupCentreStackViewModelTests { // MARK: Corner Radius extension PopupCentreStackViewModelTests { - func test_calculateCornerRadius_withCornerRadiusZero() { + func test_calculateCornerRadius_withCornerRadiusZero() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 20), createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 0), ] - appendPopupsAndCheckCornerRadius( + await appendPopupsAndCheckCornerRadius( popups: popups, expectedValue: [.top: 0, .bottom: 0] ) } - func test_calculateCornerRadius_withCornerRadiusNonZero() { + func test_calculateCornerRadius_withCornerRadiusNonZero() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 20), createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 24), ] - appendPopupsAndCheckCornerRadius( + await appendPopupsAndCheckCornerRadius( popups: popups, expectedValue: [.top: 24, .bottom: 24] ) } } private extension PopupCentreStackViewModelTests { - func appendPopupsAndCheckCornerRadius(popups: [AnyPopup], expectedValue: [MijickPopups.PopupAlignment: CGFloat]) { - appendPopupsAndPerformChecks( + func appendPopupsAndCheckCornerRadius(popups: [AnyPopup], expectedValue: [MijickPopups.PopupAlignment: CGFloat]) async { + await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, calculatedValue: { $0.t_calculateCornerRadius() }, @@ -147,27 +147,27 @@ private extension PopupCentreStackViewModelTests { // MARK: Opacity extension PopupCentreStackViewModelTests { - func test_calculatePopupOpacity_1() { + func test_calculatePopupOpacity_1() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72), createPopupInstanceForPopupHeightTests(popupHeight: 400) ] - appendPopupsAndCheckOpacity( + await appendPopupsAndCheckOpacity( popups: popups, calculateForIndex: 1, expectedValue: 0 ) } - func test_calculatePopupOpacity_2() { + func test_calculatePopupOpacity_2() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72), createPopupInstanceForPopupHeightTests(popupHeight: 400) ] - appendPopupsAndCheckOpacity( + await appendPopupsAndCheckOpacity( popups: popups, calculateForIndex: 2, expectedValue: 1 @@ -175,8 +175,8 @@ extension PopupCentreStackViewModelTests { } } private extension PopupCentreStackViewModelTests { - func appendPopupsAndCheckOpacity(popups: [AnyPopup], calculateForIndex index: Int, expectedValue: CGFloat) { - appendPopupsAndPerformChecks( + func appendPopupsAndCheckOpacity(popups: [AnyPopup], calculateForIndex index: Int, expectedValue: CGFloat) async { + await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, calculatedValue: { [self] in $0.t_calculateOpacity(for: viewModel.t_popups[index]) }, @@ -187,27 +187,27 @@ private extension PopupCentreStackViewModelTests { // MARK: Vertical Fixed Size extension PopupCentreStackViewModelTests { - func test_calculateVerticalFixedSize_withHeightSmallerThanScreen() { + func test_calculateVerticalFixedSize_withHeightSmallerThanScreen() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 913), createPopupInstanceForPopupHeightTests(popupHeight: 400) ] - appendPopupsAndCheckVerticalFixedSize( + await appendPopupsAndCheckVerticalFixedSize( popups: popups, calculateForIndex: 2, expectedValue: true ) } - func test_calculateVerticalFixedSize_withHeightLargerThanScreen() { + func test_calculateVerticalFixedSize_withHeightLargerThanScreen() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72), createPopupInstanceForPopupHeightTests(popupHeight: 913) ] - appendPopupsAndCheckVerticalFixedSize( + await appendPopupsAndCheckVerticalFixedSize( popups: popups, calculateForIndex: 2, expectedValue: false @@ -215,8 +215,8 @@ extension PopupCentreStackViewModelTests { } } private extension PopupCentreStackViewModelTests { - func appendPopupsAndCheckVerticalFixedSize(popups: [AnyPopup], calculateForIndex index: Int, expectedValue: Bool) { - appendPopupsAndPerformChecks( + func appendPopupsAndCheckVerticalFixedSize(popups: [AnyPopup], calculateForIndex index: Int, expectedValue: Bool) async { + await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, calculatedValue: { $0.t_calculateVerticalFixedSize(for: $0.t_popups[index]) }, @@ -237,9 +237,9 @@ private extension PopupCentreStackViewModelTests { let config = getConfigForPopupHeightTests(cornerRadius: cornerRadius, popupPadding: popupPadding) return AnyPopup.t_createNew(config: config).settingHeight(popupHeight) } - func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) -> (Value), expectedValueBuilder: @escaping (ViewModel) -> Value) { - viewModel.t_updatePopupsValue(popups) - viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) + func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) -> (Value), expectedValueBuilder: @escaping (ViewModel) -> Value) async { + await viewModel.t_updatePopupsValue(popups) + await viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) viewModel.t_updateKeyboardValue(isKeyboardActive) viewModel.t_updateScreenValue(isKeyboardActive ? screenWithKeyboard : screen) From d31d741200c61470e97b959a9de961aa185329cd Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:07:41 +0100 Subject: [PATCH 085/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 32ebcfe9f8..9f0a72a57b 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1270,7 +1270,7 @@ extension PopupVerticalStackViewModelTests { private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnChange(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat, gestureTranslation: CGFloat)) async { await viewModel.t_updatePopupsValue(popups) - await viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) + await recalculatePopupHeights(viewModel) await viewModel.t_onPopupDragGestureChanged(gestureValue) XCTAssertEqual(viewModel.t_activePopupHeight, expectedValues.popupHeight) @@ -1440,7 +1440,7 @@ extension PopupVerticalStackViewModelTests { private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnEnd(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat?, shouldPopupBeDismissed: Bool)) async { await viewModel.t_updatePopupsValue(popups) - await viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) + await recalculatePopupHeights(viewModel) await viewModel.t_updateGestureTranslation(gestureValue) await viewModel.t_calculateAndUpdateTranslationProgress() await viewModel.t_onPopupDragGestureEnded(gestureValue) @@ -1467,7 +1467,7 @@ private extension PopupVerticalStackViewModelTests { } func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.t_updatePopupsValue(popups) - await viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) + await recalculatePopupHeights(viewModel) await viewModel.t_updateGestureTranslation(gestureTranslation) let calculatedValue = await calculatedValue(viewModel) From 321b9d02794e043e38e752220fbf7b329224666e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:10:15 +0100 Subject: [PATCH 086/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 9f0a72a57b..62ca803ad4 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1270,7 +1270,7 @@ extension PopupVerticalStackViewModelTests { private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnChange(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat, gestureTranslation: CGFloat)) async { await viewModel.t_updatePopupsValue(popups) - await recalculatePopupHeights(viewModel) + await updatePopups(viewModel) await viewModel.t_onPopupDragGestureChanged(gestureValue) XCTAssertEqual(viewModel.t_activePopupHeight, expectedValues.popupHeight) @@ -1440,7 +1440,7 @@ extension PopupVerticalStackViewModelTests { private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnEnd(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat?, shouldPopupBeDismissed: Bool)) async { await viewModel.t_updatePopupsValue(popups) - await recalculatePopupHeights(viewModel) + await updatePopups(viewModel) await viewModel.t_updateGestureTranslation(gestureValue) await viewModel.t_calculateAndUpdateTranslationProgress() await viewModel.t_onPopupDragGestureEnded(gestureValue) @@ -1467,7 +1467,7 @@ private extension PopupVerticalStackViewModelTests { } func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.t_updatePopupsValue(popups) - await recalculatePopupHeights(viewModel) + await updatePopups(viewModel) await viewModel.t_updateGestureTranslation(gestureTranslation) let calculatedValue = await calculatedValue(viewModel) @@ -1484,9 +1484,9 @@ private extension PopupVerticalStackViewModelTests { dragDetents: dragDetents, isDragGestureEnabled: dragGestureEnabled )} - func recalculatePopupHeights(_ viewModel: ViewModel) -> [AnyPopup] { viewModel.t_popups.map { - $0.settingHeight(viewModel.t_calculateHeight(heightCandidate: $0.height!, popup: $0)) - }} + func updatePopups(_ viewModel: ViewModel) async { + for popup in viewModel.t_popups { await viewModel.recalculateAndUpdatePopupHeight(popup.height!, popup) } + } } // MARK: Screen From faf82f4cb4fe815fafc1e3b0796e151bc9dc2411 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:25:59 +0100 Subject: [PATCH 087/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 6 ++++-- Sources/Internal/UI/PopupCentreStackView.swift | 2 +- Sources/Internal/UI/PopupVerticalStackView.swift | 2 +- .../View Models/ViewModel+VerticalStack.swift | 14 +++++++------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 6d2eabae35..69864be2c5 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -14,8 +14,10 @@ import SwiftUI struct AnyPopup: Popup { private(set) var id: PopupID private(set) var config: AnyPopupConfig - private(set) var height: CGFloat? = nil - private(set) var dragHeight: CGFloat? = nil + var height: CGFloat? = nil + var dragHeight: CGFloat? = nil + var popupPadding: EdgeInsets = .init() + var cornerRadius: CGFloat = 0 private var dismissTimer: PopupActionScheduler? = nil private var _body: AnyView diff --git a/Sources/Internal/UI/PopupCentreStackView.swift b/Sources/Internal/UI/PopupCentreStackView.swift index c69451f776..52fee48dbd 100644 --- a/Sources/Internal/UI/PopupCentreStackView.swift +++ b/Sources/Internal/UI/PopupCentreStackView.swift @@ -31,7 +31,7 @@ private extension PopupCentreStackView { func createPopup(_ popup: AnyPopup) -> some View { popup.body .fixedSize(horizontal: false, vertical: viewModel.calculateVerticalFixedSize(for: popup)) - .onHeightChange { viewModel.recalculateAndUpdatePopupHeight($0, popup) } + .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopupHeight) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupHeight) .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.calculateCornerRadius()) diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index 51e59b484a..f773490227 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -31,7 +31,7 @@ private extension PopupVerticalStackView { popup.body .padding(viewModel.calculateBodyPadding(for: popup)) .fixedSize(horizontal: false, vertical: viewModel.calculateVerticalFixedSize(for: popup)) - .onHeightChange { viewModel.recalculateAndUpdatePopupHeight($0, popup) } + .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: viewModel.calculateCornerRadius()) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 78be90067b..6f6ac71da0 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -30,13 +30,13 @@ extension VM { class VerticalStack: ViewModel { // MARK: Update private extension VM.VerticalStack { - func updateGestureTranslation(_ newGestureTranslation: CGFloat) { Task { + func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { gestureTranslation = newGestureTranslation translationProgress = await calculateTranslationProgress() activePopupHeight = await calculateHeightForActivePopup() withAnimation(gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } - }} + } } @@ -48,7 +48,7 @@ private extension VM.VerticalStack { // MARK: Popup Height private extension VM.VerticalStack { nonisolated func _calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { - guard await gestureTranslation.isZero, heightCandidate != popup.height else { return popup.height ?? 0 } + guard await gestureTranslation.isZero else { return popup.height ?? 0 } let popupHeight = await calculateNewPopupHeight(heightCandidate, popup.config) return popupHeight @@ -468,11 +468,11 @@ extension VM.VerticalStack { func t_calculateTranslationProgress() async -> CGFloat { await calculateTranslationProgress() } func t_getInvertedIndex(of popup: AnyPopup) -> Int { getInvertedIndex(of: popup) } - func t_calculateAndUpdateTranslationProgress() { Task { translationProgress = await calculateTranslationProgress() }} - func t_updateGestureTranslation(_ newGestureTranslation: CGFloat) { updateGestureTranslation(newGestureTranslation) } + func t_calculateAndUpdateTranslationProgress() async { translationProgress = await calculateTranslationProgress() } + func t_updateGestureTranslation(_ newGestureTranslation: CGFloat) async { await updateGestureTranslation(newGestureTranslation) } - func t_onPopupDragGestureChanged(_ value: CGFloat) { onPopupDragGestureChanged(value) } - func t_onPopupDragGestureEnded(_ value: CGFloat) { onPopupDragGestureEnded(value) } + func t_onPopupDragGestureChanged(_ value: CGFloat) async { await onPopupDragGestureChanged(value) } + func t_onPopupDragGestureEnded(_ value: CGFloat) async { await onPopupDragGestureEnded(value) } } // MARK: Variables From 2b35384c3cc926cb5038f8895d537eb5a0eb0ee0 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:27:11 +0100 Subject: [PATCH 088/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 12 +++++------ Sources/Internal/View Models/ViewModel.swift | 21 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 6f6ac71da0..5c7cb2efce 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -335,9 +335,9 @@ extension VM.VerticalStack { // MARK: On Changed extension VM.VerticalStack { - func onPopupDragGestureChanged(_ value: CGFloat) { if dragGestureEnabled { + func onPopupDragGestureChanged(_ value: CGFloat) async { if dragGestureEnabled { let newGestureTranslation = calculateGestureTranslation(value) - updateGestureTranslation(newGestureTranslation) + await updateGestureTranslation(newGestureTranslation) }} } private extension VM.VerticalStack { @@ -437,11 +437,11 @@ private extension VM.VerticalStack { func calculateTargetDragHeight(_ targetHeight: CGFloat, _ activePopupHeight: CGFloat) -> CGFloat { targetHeight - activePopupHeight } - func updateDragHeight(_ targetDragHeight: CGFloat) { if let activePopup = popups.last { - updatePopupAction(activePopup.settingDragHeight(targetDragHeight)) + func updateDragHeight(_ targetDragHeight: CGFloat) async { if let activePopup = popups.last { + await updatePopupAction(activePopup.settingDragHeight(targetDragHeight)) }} - func resetGestureTranslation() { - updateGestureTranslation(0) + func resetGestureTranslation() async { + await updateGestureTranslation(0) } func shouldDismissPopup() -> Bool { translationProgress >= dragThreshold diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index d0897f38e0..fdea71740c 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -16,8 +16,8 @@ enum VM {} // MARK: Attributes nonisolated let alignment: PopupAlignment private(set) var popups: [AnyPopup] = [] - private(set) var updatePopupAction: ((AnyPopup) -> ())! - private(set) var closePopupAction: ((AnyPopup) -> ())! + private(set) var updatePopupAction: ((AnyPopup) async -> ())! + private(set) var closePopupAction: ((AnyPopup) async -> ())! // MARK: Subclass Attributes var activePopupHeight: CGFloat? = nil @@ -25,7 +25,8 @@ enum VM {} var isKeyboardActive: Bool = false // MARK: Methods to Override - nonisolated func recalculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { fatalError() } + nonisolated func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { fatalError() } + nonisolated func calculatePopupPadding() async -> EdgeInsets { fatalError() } nonisolated func calculateHeightForActivePopup() async -> CGFloat? { fatalError() } nonisolated func recalculatePopupPadding() async -> EdgeInsets { fatalError() } @@ -35,7 +36,7 @@ enum VM {} // MARK: Setup extension ViewModel { - func setup(updatePopupAction: @escaping (AnyPopup) -> (), closePopupAction: @escaping (AnyPopup) -> ()) { + func setup(updatePopupAction: @escaping (AnyPopup) async -> (), closePopupAction: @escaping (AnyPopup) async -> ()) { self.updatePopupAction = updatePopupAction self.closePopupAction = closePopupAction } @@ -43,12 +44,12 @@ extension ViewModel { // MARK: Update extension ViewModel { - func updatePopupsValue(_ newPopups: [AnyPopup]) { Task { + func updatePopupsValue(_ newPopups: [AnyPopup]) async { popups = await filterPopups(newPopups) activePopupHeight = await calculateHeightForActivePopup() withAnimation(.transition) { objectWillChange.send() } - }} + } func updateScreenValue(_ newScreen: Screen) { screen = newScreen @@ -86,12 +87,12 @@ extension ViewModel { // MARK: Methods extension ViewModel { - func t_setup(updatePopupAction: @escaping (AnyPopup) -> (), closePopupAction: @escaping (AnyPopup) -> ()) { setup(updatePopupAction: updatePopupAction, closePopupAction: closePopupAction) } - func t_updatePopupsValue(_ newPopups: [AnyPopup]) { updatePopupsValue(newPopups) } + func t_setup(updatePopupAction: @escaping (AnyPopup) async -> (), closePopupAction: @escaping (AnyPopup) async -> ()) { setup(updatePopupAction: updatePopupAction, closePopupAction: closePopupAction) } + func t_updatePopupsValue(_ newPopups: [AnyPopup]) async { await updatePopupsValue(newPopups) } func t_updateScreenValue(_ newScreen: Screen) { updateScreenValue(newScreen) } func t_updateKeyboardValue(_ isActive: Bool) { updateKeyboardValue(isActive) } - func t_updatePopup(_ popup: AnyPopup) { updatePopupAction(popup) } - func t_calculateAndUpdateActivePopupHeight() { Task { activePopupHeight = await calculateHeightForActivePopup() }} + func t_updatePopup(_ popup: AnyPopup) async { await updatePopupAction(popup) } + func t_calculateAndUpdateActivePopupHeight() async { activePopupHeight = await calculateHeightForActivePopup() } } // MARK: Variables From b9ac70d2f3bcdb050bde9803abc1d606295a2c21 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:28:10 +0100 Subject: [PATCH 089/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 5c7cb2efce..17e0645b4d 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -378,23 +378,23 @@ private extension VM.VerticalStack { // MARK: On Ended extension VM.VerticalStack { - func onPopupDragGestureEnded(_ value: CGFloat) { if value != 0 { - dismissLastItemIfNeeded() - updateTranslationValues() + func onPopupDragGestureEnded(_ value: CGFloat) async { if value != 0 { + await dismissLastItemIfNeeded() + await updateTranslationValues() }} } private extension VM.VerticalStack { - func dismissLastItemIfNeeded() { if shouldDismissPopup() { if let popup = popups.last { - closePopupAction(popup) + func dismissLastItemIfNeeded() async { if shouldDismissPopup() { if let popup = popups.last { + await closePopupAction(popup) }}} - func updateTranslationValues() { if let activePopupHeight = popups.last?.height { + func updateTranslationValues() async { if let activePopupHeight = popups.last?.height { let currentPopupHeight = calculateCurrentPopupHeight(activePopupHeight) let popupTargetHeights = calculatePopupTargetHeightsFromDragDetents(activePopupHeight) let targetHeight = calculateTargetPopupHeight(currentPopupHeight, popupTargetHeights) let targetDragHeight = calculateTargetDragHeight(targetHeight, activePopupHeight) - resetGestureTranslation() - updateDragHeight(targetDragHeight) + await resetGestureTranslation() + await updateDragHeight(targetDragHeight) }} } private extension VM.VerticalStack { From 40eb402b18a1edcd937bc5322f3b80d25f126bd0 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:29:55 +0100 Subject: [PATCH 090/407] 1 --- Sources/Internal/Extensions/View+Gestures.swift | 6 +++--- Sources/Internal/Extensions/View+ReadHeight.swift | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/Extensions/View+Gestures.swift b/Sources/Internal/Extensions/View+Gestures.swift index 09933debef..11140692be 100644 --- a/Sources/Internal/Extensions/View+Gestures.swift +++ b/Sources/Internal/Extensions/View+Gestures.swift @@ -24,14 +24,14 @@ extension View { // MARK: On Drag Gesture extension View { - func onDragGesture(onChanged actionOnChanged: @escaping (CGFloat) -> (), onEnded actionOnEnded: @escaping (CGFloat) -> (), isEnabled: Bool) -> some View { + func onDragGesture(onChanged actionOnChanged: @escaping (CGFloat) async -> (), onEnded actionOnEnded: @escaping (CGFloat) async -> (), isEnabled: Bool) -> some View { #if os(tvOS) self #else highPriorityGesture( DragGesture() - .onChanged { actionOnChanged($0.translation.height) } - .onEnded { actionOnEnded($0.translation.height) }, + .onChanged { newValue in Task { @MainActor in await actionOnChanged(newValue.translation.height) }} + .onEnded { newValue in Task { @MainActor in await actionOnEnded(newValue.translation.height) }}, isEnabled: isEnabled ) #endif diff --git a/Sources/Internal/Extensions/View+ReadHeight.swift b/Sources/Internal/Extensions/View+ReadHeight.swift index 5b28069781..28d10e980a 100644 --- a/Sources/Internal/Extensions/View+ReadHeight.swift +++ b/Sources/Internal/Extensions/View+ReadHeight.swift @@ -12,9 +12,12 @@ import SwiftUI extension View { - func onHeightChange(perform action: @escaping (CGFloat) -> ()) -> some View { background( + func onHeightChange(perform action: @escaping (CGFloat) async -> ()) -> some View { background( GeometryReader { proxy in - DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { action(proxy.size.height) } + Task { @MainActor in + try await Task.sleep(nanoseconds: 10_000_000) + await action(proxy.size.height) + } return Color.clear } )} From 47e3a9c9590eb82eaded27d6db3b6e5dda1547a9 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:34:11 +0100 Subject: [PATCH 091/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 6 --- Tests/Tests+ViewModel+PopupCentreStack.swift | 14 ++--- .../Tests+ViewModel+PopupVerticalStack.swift | 52 +++++++++---------- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index fdea71740c..d47d75f8c7 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -94,10 +94,4 @@ extension ViewModel { func t_updatePopup(_ popup: AnyPopup) async { await updatePopupAction(popup) } func t_calculateAndUpdateActivePopupHeight() async { activePopupHeight = await calculateHeightForActivePopup() } } - -// MARK: Variables -extension ViewModel { - var t_popups: [AnyPopup] { popups } - var t_activePopupHeight: CGFloat? { activePopupHeight } -} #endif diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index 91e1a96908..7269885004 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -22,15 +22,15 @@ import SwiftUI } } private extension PopupCentreStackViewModelTests { - func updatePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.t_popups.firstIndex(of: popup) { - var popups = viewModel.t_popups + func updatePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.popups.firstIndex(of: popup) { + var popups = viewModel.popups popups[index] = popup await viewModel.t_updatePopupsValue(popups) await viewModel.t_calculateAndUpdateActivePopupHeight() }} - func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.t_popups.firstIndex(of: popup) { - var popups = viewModel.t_popups + func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.popups.firstIndex(of: popup) { + var popups = viewModel.popups popups.remove(at: index) await viewModel.t_updatePopupsValue(popups) @@ -179,7 +179,7 @@ private extension PopupCentreStackViewModelTests { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, - calculatedValue: { [self] in $0.t_calculateOpacity(for: viewModel.t_popups[index]) }, + calculatedValue: { [self] in $0.t_calculateOpacity(for: viewModel.popups[index]) }, expectedValueBuilder: { _ in expectedValue } ) } @@ -219,7 +219,7 @@ private extension PopupCentreStackViewModelTests { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, - calculatedValue: { $0.t_calculateVerticalFixedSize(for: $0.t_popups[index]) }, + calculatedValue: { $0.t_calculateVerticalFixedSize(for: $0.popups[index]) }, expectedValueBuilder: { _ in expectedValue } ) } @@ -251,7 +251,7 @@ private extension PopupCentreStackViewModelTests { popupPadding: popupPadding, cornerRadius: cornerRadius )} - func recalculatePopupHeights(_ viewModel: ViewModel) -> [AnyPopup] { viewModel.t_popups.map { + func recalculatePopupHeights(_ viewModel: ViewModel) -> [AnyPopup] { viewModel.popups.map { $0.settingHeight(viewModel.t_calculateHeight(heightCandidate: $0.height!)) }} } diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 62ca803ad4..b02d245ee7 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -29,15 +29,15 @@ private extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func updatePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.t_popups.firstIndex(of: popup) { - var popups = viewModel.t_popups + func updatePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.popups.firstIndex(of: popup) { + var popups = viewModel.popups popups[index] = popup await viewModel.t_updatePopupsValue(popups) await viewModel.t_calculateAndUpdateActivePopupHeight() }} - func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.t_popups.firstIndex(of: popup) { - var popups = viewModel.t_popups + func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.popups.firstIndex(of: popup) { + var popups = viewModel.popups popups.remove(at: index) await viewModel.t_updatePopupsValue(popups) @@ -58,7 +58,7 @@ extension PopupVerticalStackViewModelTests { ]) XCTAssertEqual( - bottomViewModel.t_getInvertedIndex(of: bottomViewModel.t_popups[0]), + bottomViewModel.t_getInvertedIndex(of: bottomViewModel.popups[0]), 0 ) } @@ -72,7 +72,7 @@ extension PopupVerticalStackViewModelTests { ]) XCTAssertEqual( - bottomViewModel.t_getInvertedIndex(of: bottomViewModel.t_popups[3]), + bottomViewModel.t_getInvertedIndex(of: bottomViewModel.popups[3]), 1 ) } @@ -136,9 +136,9 @@ private extension PopupVerticalStackViewModelTests { await viewModel.t_updatePopupsValue(popups) await viewModel.t_updatePopup(updatedPopup) - if let index = viewModel.t_popups.firstIndex(of: updatedPopup) { - XCTAssertEqual(viewModel.t_popups[index].height, expectedValue.height) - XCTAssertEqual(viewModel.t_popups[index].dragHeight, expectedValue.dragHeight) + if let index = viewModel.popups.firstIndex(of: updatedPopup) { + XCTAssertEqual(viewModel.popups[index].height, expectedValue.height) + XCTAssertEqual(viewModel.popups[index].dragHeight, expectedValue.dragHeight) } } } @@ -273,7 +273,7 @@ extension PopupVerticalStackViewModelTests { } private extension PopupVerticalStackViewModelTests { func calculateLastPopupHeight(_ viewModel: ViewModel) -> CGFloat { - viewModel.t_calculateHeight(heightCandidate: viewModel.t_popups.last!.height!, popup: viewModel.t_popups.last!) + viewModel.t_calculateHeight(heightCandidate: viewModel.popups.last!.height!, popup: viewModel.popups.last!) } } @@ -427,7 +427,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.t_activePopupHeight }, + calculatedValue: { $0.activePopupHeight }, expectedValueBuilder: { _ in expectedValue } ) } @@ -445,7 +445,7 @@ extension PopupVerticalStackViewModelTests { ]) XCTAssertEqual( - bottomViewModel.t_calculateOffsetY(for: bottomViewModel.t_popups[2]), + bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[2]), -bottomViewModel.t_stackOffset * 2 ) } @@ -459,7 +459,7 @@ extension PopupVerticalStackViewModelTests { ]) XCTAssertEqual( - bottomViewModel.t_calculateOffsetY(for: bottomViewModel.t_popups[4]), + bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[4]), 0 ) } @@ -470,7 +470,7 @@ extension PopupVerticalStackViewModelTests { await bottomViewModel.t_updateGestureTranslation(-100) XCTAssertEqual( - bottomViewModel.t_calculateOffsetY(for: bottomViewModel.t_popups[0]), + bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[0]), 0 ) } @@ -482,7 +482,7 @@ extension PopupVerticalStackViewModelTests { await bottomViewModel.t_updateGestureTranslation(100) XCTAssertEqual( - bottomViewModel.t_calculateOffsetY(for: bottomViewModel.t_popups[0]), + bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[0]), -bottomViewModel.t_stackOffset ) } @@ -494,7 +494,7 @@ extension PopupVerticalStackViewModelTests { await bottomViewModel.t_updateGestureTranslation(100) XCTAssertEqual( - bottomViewModel.t_calculateOffsetY(for: bottomViewModel.t_popups[1]), + bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[1]), 100 - 21 ) } @@ -506,7 +506,7 @@ extension PopupVerticalStackViewModelTests { GlobalConfigContainer.vertical.isStackingEnabled = false XCTAssertEqual( - bottomViewModel.t_calculateOffsetY(for: bottomViewModel.t_popups[0]), + bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[0]), 0 ) } @@ -517,7 +517,7 @@ extension PopupVerticalStackViewModelTests { ]) XCTAssertEqual( - topViewModel.t_calculateOffsetY(for: topViewModel.t_popups[0]), + topViewModel.t_calculateOffsetY(for: topViewModel.popups[0]), topViewModel.t_stackOffset ) } @@ -529,7 +529,7 @@ extension PopupVerticalStackViewModelTests { await topViewModel.t_updateGestureTranslation(-100) XCTAssertEqual( - topViewModel.t_calculateOffsetY(for: topViewModel.t_popups[1]), + topViewModel.t_calculateOffsetY(for: topViewModel.popups[1]), 21 - 100 ) } @@ -984,7 +984,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.t_calculateScaleX(for: $0.t_popups[index]) }, + calculatedValue: { $0.t_calculateScaleX(for: $0.popups[index]) }, expectedValueBuilder: expectedValueBuilder ) } @@ -1059,7 +1059,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.t_calculateVerticalFixedSize(for: $0.t_popups[index]) }, + calculatedValue: { $0.t_calculateVerticalFixedSize(for: $0.popups[index]) }, expectedValueBuilder: { _ in expectedValue } ) } @@ -1174,7 +1174,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.t_calculateStackOverlayOpacity(for: $0.t_popups[index]) }, + calculatedValue: { $0.t_calculateStackOverlayOpacity(for: $0.popups[index]) }, expectedValueBuilder: expectedValueBuilder ) } @@ -1273,7 +1273,7 @@ private extension PopupVerticalStackViewModelTests { await updatePopups(viewModel) await viewModel.t_onPopupDragGestureChanged(gestureValue) - XCTAssertEqual(viewModel.t_activePopupHeight, expectedValues.popupHeight) + XCTAssertEqual(viewModel.activePopupHeight, expectedValues.popupHeight) XCTAssertEqual(viewModel.t_gestureTranslation, expectedValues.gestureTranslation) } } @@ -1445,8 +1445,8 @@ private extension PopupVerticalStackViewModelTests { await viewModel.t_calculateAndUpdateTranslationProgress() await viewModel.t_onPopupDragGestureEnded(gestureValue) - XCTAssertEqual(viewModel.t_popups.count, expectedValues.shouldPopupBeDismissed ? 0 : 1) - XCTAssertEqual(viewModel.t_activePopupHeight, expectedValues.popupHeight) + XCTAssertEqual(viewModel.popups.count, expectedValues.shouldPopupBeDismissed ? 0 : 1) + XCTAssertEqual(viewModel.activePopupHeight, expectedValues.popupHeight) } } @@ -1485,7 +1485,7 @@ private extension PopupVerticalStackViewModelTests { isDragGestureEnabled: dragGestureEnabled )} func updatePopups(_ viewModel: ViewModel) async { - for popup in viewModel.t_popups { await viewModel.recalculateAndUpdatePopupHeight(popup.height!, popup) } + for popup in viewModel.popups { await viewModel.recalculateAndUpdatePopupHeight(popup.height!, popup) } } } From 1bce89672f4941758836d7408d55f2dad3a85d3f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:37:44 +0100 Subject: [PATCH 092/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 3 +- Tests/Tests+ViewModel+PopupCentreStack.swift | 12 ++-- .../Tests+ViewModel+PopupVerticalStack.swift | 58 +++++++++---------- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index d47d75f8c7..5f31d6b264 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -87,8 +87,7 @@ extension ViewModel { // MARK: Methods extension ViewModel { - func t_setup(updatePopupAction: @escaping (AnyPopup) async -> (), closePopupAction: @escaping (AnyPopup) async -> ()) { setup(updatePopupAction: updatePopupAction, closePopupAction: closePopupAction) } - func t_updatePopupsValue(_ newPopups: [AnyPopup]) async { await updatePopupsValue(newPopups) } + func t_updateScreenValue(_ newScreen: Screen) { updateScreenValue(newScreen) } func t_updateKeyboardValue(_ isActive: Bool) { updateKeyboardValue(isActive) } func t_updatePopup(_ popup: AnyPopup) async { await updatePopupAction(popup) } diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index 7269885004..da19f14cb4 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -17,8 +17,8 @@ import SwiftUI @ObservedObject private var viewModel: ViewModel = .init(CentrePopupConfig.self) override func setUp() async throws { - viewModel.t_updateScreenValue(screen) - viewModel.t_setup(updatePopupAction: { [self] in await updatePopupAction(viewModel, $0) }, closePopupAction: { [self] in await closePopupAction(viewModel, $0) }) + viewModel.updateScreenValue(screen) + viewModel.setup(updatePopupAction: { [self] in await updatePopupAction(viewModel, $0) }, closePopupAction: { [self] in await closePopupAction(viewModel, $0) }) } } private extension PopupCentreStackViewModelTests { @@ -26,14 +26,14 @@ private extension PopupCentreStackViewModelTests { var popups = viewModel.popups popups[index] = popup - await viewModel.t_updatePopupsValue(popups) + await viewModel.updatePopupsValue(popups) await viewModel.t_calculateAndUpdateActivePopupHeight() }} func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.popups.firstIndex(of: popup) { var popups = viewModel.popups popups.remove(at: index) - await viewModel.t_updatePopupsValue(popups) + await viewModel.updatePopupsValue(popups) }} } @@ -238,8 +238,8 @@ private extension PopupCentreStackViewModelTests { return AnyPopup.t_createNew(config: config).settingHeight(popupHeight) } func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) -> (Value), expectedValueBuilder: @escaping (ViewModel) -> Value) async { - await viewModel.t_updatePopupsValue(popups) - await viewModel.t_updatePopupsValue(recalculatePopupHeights(viewModel)) + await viewModel.updatePopupsValue(popups) + await viewModel.updatePopupsValue(recalculatePopupHeights(viewModel)) viewModel.t_updateKeyboardValue(isKeyboardActive) viewModel.t_updateScreenValue(isKeyboardActive ? screenWithKeyboard : screen) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index b02d245ee7..cd74588b46 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -24,8 +24,8 @@ import SwiftUI } private extension PopupVerticalStackViewModelTests { func setup(_ viewModel: ViewModel) { - viewModel.t_updateScreenValue(screen) - viewModel.t_setup(updatePopupAction: { await self.updatePopupAction(viewModel, $0) }, closePopupAction: { await self.closePopupAction(viewModel, $0) }) + viewModel.updateScreenValue(screen) + viewModel.setup(updatePopupAction: { await self.updatePopupAction(viewModel, $0) }, closePopupAction: { await self.closePopupAction(viewModel, $0) }) } } private extension PopupVerticalStackViewModelTests { @@ -33,14 +33,14 @@ private extension PopupVerticalStackViewModelTests { var popups = viewModel.popups popups[index] = popup - await viewModel.t_updatePopupsValue(popups) + await viewModel.updatePopupsValue(popups) await viewModel.t_calculateAndUpdateActivePopupHeight() }} func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.popups.firstIndex(of: popup) { var popups = viewModel.popups popups.remove(at: index) - await viewModel.t_updatePopupsValue(popups) + await viewModel.updatePopupsValue(popups) }} } @@ -53,7 +53,7 @@ private extension PopupVerticalStackViewModelTests { // MARK: Inverted Index extension PopupVerticalStackViewModelTests { func test_getInvertedIndex_1() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150) ]) @@ -63,7 +63,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_getInvertedIndex_2() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), @@ -133,7 +133,7 @@ extension PopupVerticalStackViewModelTests { } private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckPopups(viewModel: ViewModel, popups: [AnyPopup], updatedPopup: AnyPopup, expectedValue: (height: CGFloat?, dragHeight: CGFloat?)) async { - await viewModel.t_updatePopupsValue(popups) + await viewModel.updatePopupsValue(popups) await viewModel.t_updatePopup(updatedPopup) if let index = viewModel.popups.firstIndex(of: updatedPopup) { @@ -146,7 +146,7 @@ private extension PopupVerticalStackViewModelTests { // MARK: Popup Height extension PopupVerticalStackViewModelTests { func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_onePopupStacked() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150) ]) @@ -156,7 +156,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_fourPopupsStacked() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 200), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), @@ -169,7 +169,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_onePopupStacked() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2000) ]) @@ -179,7 +179,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_fivePopupStacked() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 200), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), @@ -193,7 +193,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withLargeHeightMode_whenOnePopupStacked() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 100) ]) @@ -203,7 +203,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupStacked() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 700), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 1000) @@ -215,7 +215,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withFullscreenHeightMode_whenOnePopupStacked() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100) ]) @@ -225,7 +225,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 2000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 3000) @@ -237,7 +237,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupsStacked_popupPadding() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 2000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 3000, popupPadding: .init(top: 33, leading: 15, bottom: 21, trailing: 15)) @@ -249,7 +249,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked_popupPadding() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 2000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 3000, popupPadding: .init(top: 33, leading: 15, bottom: 21, trailing: 15)) @@ -261,7 +261,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withLargeHeightMode_whenPopupsHaveTopAlignment() async { - await topViewModel.t_updatePopupsValue([ + await topViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .large, popupHeight: 100) ]) @@ -436,7 +436,7 @@ private extension PopupVerticalStackViewModelTests { // MARK: Offset extension PopupVerticalStackViewModelTests { func test_calculateOffsetY_withZeroGestureTranslation_fivePopupsStacked_thirdElement() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 240), @@ -450,7 +450,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withZeroGestureTranslation_fivePopupsStacked_lastElement() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 240), @@ -464,7 +464,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withNegativeGestureTranslation_dragHeight_onePopupStacked() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 100) ]) await bottomViewModel.t_updateGestureTranslation(-100) @@ -475,7 +475,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withPositiveGestureTranslation_dragHeight_twoPopupsStacked_firstElement() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) @@ -487,7 +487,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withPositiveGestureTranslation_dragHeight_twoPopupsStacked_lastElement() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) @@ -499,7 +499,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withStackingDisabled() async { - await bottomViewModel.t_updatePopupsValue([ + await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) @@ -511,7 +511,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withPopupsHaveTopAlignment_1() async { - await topViewModel.t_updatePopupsValue([ + await topViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) @@ -522,7 +522,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withPopupsHaveTopAlignment_2() async { - await topViewModel.t_updatePopupsValue([ + await topViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) @@ -1269,7 +1269,7 @@ extension PopupVerticalStackViewModelTests { } private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnChange(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat, gestureTranslation: CGFloat)) async { - await viewModel.t_updatePopupsValue(popups) + await viewModel.updatePopupsValue(popups) await updatePopups(viewModel) await viewModel.t_onPopupDragGestureChanged(gestureValue) @@ -1439,7 +1439,7 @@ extension PopupVerticalStackViewModelTests { } private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnEnd(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat?, shouldPopupBeDismissed: Bool)) async { - await viewModel.t_updatePopupsValue(popups) + await viewModel.updatePopupsValue(popups) await updatePopups(viewModel) await viewModel.t_updateGestureTranslation(gestureValue) await viewModel.t_calculateAndUpdateTranslationProgress() @@ -1466,7 +1466,7 @@ private extension PopupVerticalStackViewModelTests { .settingDragHeight(popupDragHeight) } func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { - await viewModel.t_updatePopupsValue(popups) + await viewModel.updatePopupsValue(popups) await updatePopups(viewModel) await viewModel.t_updateGestureTranslation(gestureTranslation) From 216648914d341c2779471437edb4e9c9ac55f5b7 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:38:25 +0100 Subject: [PATCH 093/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 3 +-- Tests/Tests+ViewModel+PopupCentreStack.swift | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 5f31d6b264..0dfb0c1af8 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -88,8 +88,7 @@ extension ViewModel { // MARK: Methods extension ViewModel { - func t_updateScreenValue(_ newScreen: Screen) { updateScreenValue(newScreen) } - func t_updateKeyboardValue(_ isActive: Bool) { updateKeyboardValue(isActive) } + func t_updatePopup(_ popup: AnyPopup) async { await updatePopupAction(popup) } func t_calculateAndUpdateActivePopupHeight() async { activePopupHeight = await calculateHeightForActivePopup() } } diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index da19f14cb4..2a35e5e735 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -240,8 +240,8 @@ private extension PopupCentreStackViewModelTests { func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) -> (Value), expectedValueBuilder: @escaping (ViewModel) -> Value) async { await viewModel.updatePopupsValue(popups) await viewModel.updatePopupsValue(recalculatePopupHeights(viewModel)) - viewModel.t_updateKeyboardValue(isKeyboardActive) - viewModel.t_updateScreenValue(isKeyboardActive ? screenWithKeyboard : screen) + viewModel.updateKeyboardValue(isKeyboardActive) + viewModel.updateScreenValue(isKeyboardActive ? screenWithKeyboard : screen) XCTAssertEqual(calculatedValue(viewModel), expectedValueBuilder(viewModel)) } From 956707e76dace72184bf3b6f0daf31d7832ec572 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:39:05 +0100 Subject: [PATCH 094/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 2 -- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 0dfb0c1af8..8149fa7de1 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -88,8 +88,6 @@ extension ViewModel { // MARK: Methods extension ViewModel { - - func t_updatePopup(_ popup: AnyPopup) async { await updatePopupAction(popup) } func t_calculateAndUpdateActivePopupHeight() async { activePopupHeight = await calculateHeightForActivePopup() } } #endif diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index cd74588b46..20cb8d8460 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -134,7 +134,7 @@ extension PopupVerticalStackViewModelTests { private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckPopups(viewModel: ViewModel, popups: [AnyPopup], updatedPopup: AnyPopup, expectedValue: (height: CGFloat?, dragHeight: CGFloat?)) async { await viewModel.updatePopupsValue(popups) - await viewModel.t_updatePopup(updatedPopup) + await viewModel.updatePopupAction(updatedPopup) if let index = viewModel.popups.firstIndex(of: updatedPopup) { XCTAssertEqual(viewModel.popups[index].height, expectedValue.height) From a1ab44ad8f269e9a6fedb1a49c97fddb07904050 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:41:16 +0100 Subject: [PATCH 095/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 14 -------------- Tests/Tests+ViewModel+PopupCentreStack.swift | 1 - Tests/Tests+ViewModel+PopupVerticalStack.swift | 1 - 3 files changed, 16 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 8149fa7de1..c1d588cfb1 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -77,17 +77,3 @@ extension ViewModel { popups.last?.config ?? .init() } } - - - -// MARK: - TESTS -#if DEBUG - - - -// MARK: Methods -extension ViewModel { - - func t_calculateAndUpdateActivePopupHeight() async { activePopupHeight = await calculateHeightForActivePopup() } -} -#endif diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index 2a35e5e735..076b6ab564 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -27,7 +27,6 @@ private extension PopupCentreStackViewModelTests { popups[index] = popup await viewModel.updatePopupsValue(popups) - await viewModel.t_calculateAndUpdateActivePopupHeight() }} func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.popups.firstIndex(of: popup) { var popups = viewModel.popups diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 20cb8d8460..82153d362a 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -34,7 +34,6 @@ private extension PopupVerticalStackViewModelTests { popups[index] = popup await viewModel.updatePopupsValue(popups) - await viewModel.t_calculateAndUpdateActivePopupHeight() }} func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.popups.firstIndex(of: popup) { var popups = viewModel.popups From 409c1dd867a1f3bcb54a8a54e3342e26ab92f378 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:42:41 +0100 Subject: [PATCH 096/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 3 +-- Tests/Tests+ViewModel+PopupVerticalStack.swift | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 17e0645b4d..9001cabf40 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -471,7 +471,7 @@ extension VM.VerticalStack { func t_calculateAndUpdateTranslationProgress() async { translationProgress = await calculateTranslationProgress() } func t_updateGestureTranslation(_ newGestureTranslation: CGFloat) async { await updateGestureTranslation(newGestureTranslation) } - func t_onPopupDragGestureChanged(_ value: CGFloat) async { await onPopupDragGestureChanged(value) } + func t_onPopupDragGestureEnded(_ value: CGFloat) async { await onPopupDragGestureEnded(value) } } @@ -484,6 +484,5 @@ extension VM.VerticalStack { var t_minStackOverlayProgressMultiplier: CGFloat { minStackOverlayProgressMultiplier } var t_maxStackOverlayFactor: CGFloat { maxStackOverlayFactor } var t_dragTranslationThreshold: CGFloat { dragTranslationThreshold } - var t_gestureTranslation: CGFloat { gestureTranslation } } #endif diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 82153d362a..02e241a0d7 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1270,10 +1270,10 @@ private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnChange(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat, gestureTranslation: CGFloat)) async { await viewModel.updatePopupsValue(popups) await updatePopups(viewModel) - await viewModel.t_onPopupDragGestureChanged(gestureValue) + await viewModel.onPopupDragGestureChanged(gestureValue) XCTAssertEqual(viewModel.activePopupHeight, expectedValues.popupHeight) - XCTAssertEqual(viewModel.t_gestureTranslation, expectedValues.gestureTranslation) + XCTAssertEqual(viewModel.gestureTranslation, expectedValues.gestureTranslation) } } From 38d3e449babafb692a5c23bc73f1ef87050e1bf6 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:43:35 +0100 Subject: [PATCH 097/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 2 -- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 9001cabf40..229d892642 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -471,8 +471,6 @@ extension VM.VerticalStack { func t_calculateAndUpdateTranslationProgress() async { translationProgress = await calculateTranslationProgress() } func t_updateGestureTranslation(_ newGestureTranslation: CGFloat) async { await updateGestureTranslation(newGestureTranslation) } - - func t_onPopupDragGestureEnded(_ value: CGFloat) async { await onPopupDragGestureEnded(value) } } // MARK: Variables diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 02e241a0d7..4aabfa3ad1 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1442,7 +1442,7 @@ private extension PopupVerticalStackViewModelTests { await updatePopups(viewModel) await viewModel.t_updateGestureTranslation(gestureValue) await viewModel.t_calculateAndUpdateTranslationProgress() - await viewModel.t_onPopupDragGestureEnded(gestureValue) + await viewModel.onPopupDragGestureEnded(gestureValue) XCTAssertEqual(viewModel.popups.count, expectedValues.shouldPopupBeDismissed ? 0 : 1) XCTAssertEqual(viewModel.activePopupHeight, expectedValues.popupHeight) From 61d2b78c5633b8559e0edee89e17a9686bd1f49e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:45:02 +0100 Subject: [PATCH 098/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 6 ++---- Tests/Tests+ViewModel+PopupVerticalStack.swift | 10 +++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 229d892642..a32e87de9c 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -300,7 +300,7 @@ private extension VM.VerticalStack { } // MARK: Translation Progress -private extension VM.VerticalStack { +extension VM.VerticalStack { nonisolated func calculateTranslationProgress() async -> CGFloat { guard let activePopupHeight = await popups.last?.height else { return 0 }; return switch alignment { case .top: await abs(min(gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight case .bottom: await max(gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight @@ -309,7 +309,7 @@ private extension VM.VerticalStack { } // MARK: Others -private extension VM.VerticalStack { +extension VM.VerticalStack { func getInvertedIndex(of popup: AnyPopup) -> Int { let index = popups.firstIndex(of: popup) ?? 0 let invertedIndex = popups.count - 1 - index @@ -465,8 +465,6 @@ extension VM.VerticalStack { func t_calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { calculateVerticalFixedSize(for: popup) } func t_calculateStackOverlayOpacity(for popup: AnyPopup) -> CGFloat { calculateStackOverlayOpacity(for: popup) } func t_calculateCornerRadius() -> [PopupAlignment: CGFloat] { calculateCornerRadius() } - func t_calculateTranslationProgress() async -> CGFloat { await calculateTranslationProgress() } - func t_getInvertedIndex(of popup: AnyPopup) -> Int { getInvertedIndex(of: popup) } func t_calculateAndUpdateTranslationProgress() async { translationProgress = await calculateTranslationProgress() } func t_updateGestureTranslation(_ newGestureTranslation: CGFloat) async { await updateGestureTranslation(newGestureTranslation) } diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 4aabfa3ad1..ab48dfd683 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -57,7 +57,7 @@ extension PopupVerticalStackViewModelTests { ]) XCTAssertEqual( - bottomViewModel.t_getInvertedIndex(of: bottomViewModel.popups[0]), + bottomViewModel.getInvertedIndex(of: bottomViewModel.popups[0]), 0 ) } @@ -71,7 +71,7 @@ extension PopupVerticalStackViewModelTests { ]) XCTAssertEqual( - bottomViewModel.t_getInvertedIndex(of: bottomViewModel.popups[3]), + bottomViewModel.getInvertedIndex(of: bottomViewModel.popups[3]), 1 ) } @@ -813,7 +813,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { await $0.t_calculateTranslationProgress() }, + calculatedValue: { await $0.calculateTranslationProgress() }, expectedValueBuilder: { _ in expectedValue } ) } @@ -973,7 +973,7 @@ extension PopupVerticalStackViewModelTests { popups: popups, gestureTranslation: 100, calculateForIndex: 1, - expectedValueBuilder: { await 1 - $0.t_stackScaleFactor * 3 * max(1 - $0.t_calculateTranslationProgress(), $0.t_minScaleProgressMultiplier) } + expectedValueBuilder: { await 1 - $0.t_stackScaleFactor * 3 * max(1 - $0.calculateTranslationProgress(), $0.t_minScaleProgressMultiplier) } ) } } @@ -1163,7 +1163,7 @@ extension PopupVerticalStackViewModelTests { popups: popups, gestureTranslation: 241, calculateForIndex: 2, - expectedValueBuilder: { await (1 - $0.t_calculateTranslationProgress()) * $0.t_stackOverlayFactor } + expectedValueBuilder: { await (1 - $0.calculateTranslationProgress()) * $0.t_stackOverlayFactor } ) } } From 941aa891c2d5f04b7d925c377ceea770be976d87 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:47:37 +0100 Subject: [PATCH 099/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 6 +----- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index a32e87de9c..9b1cba1f79 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -325,6 +325,7 @@ extension VM.VerticalStack { var stackOffset: CGFloat { GlobalConfigContainer.vertical.isStackingEnabled ? 8 : 0 } var dragThreshold: CGFloat { GlobalConfigContainer.vertical.dragThreshold } var dragGestureEnabled: Bool { getActivePopupConfig().isDragGestureEnabled } + var dragTranslationThreshold: CGFloat { 8 } } @@ -372,9 +373,6 @@ private extension VM.VerticalStack { case .centre: fatalError() }} } -private extension VM.VerticalStack { - var dragTranslationThreshold: CGFloat { 8 } -} // MARK: On Ended extension VM.VerticalStack { @@ -477,8 +475,6 @@ extension VM.VerticalStack { var t_stackScaleFactor: CGFloat { stackScaleFactor } var t_stackOverlayFactor: CGFloat { stackOverlayFactor } var t_minScaleProgressMultiplier: CGFloat { minScaleProgressMultiplier } - var t_minStackOverlayProgressMultiplier: CGFloat { minStackOverlayProgressMultiplier } var t_maxStackOverlayFactor: CGFloat { maxStackOverlayFactor } - var t_dragTranslationThreshold: CGFloat { dragTranslationThreshold } } #endif diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index ab48dfd683..71e2886041 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1250,7 +1250,7 @@ extension PopupVerticalStackViewModelTests { viewModel: bottomViewModel, popups: popups, gestureValue: -133, - expectedValues: (popupHeight: 370 + bottomViewModel.t_dragTranslationThreshold, gestureTranslation: 344 - 370 - bottomViewModel.t_dragTranslationThreshold) + expectedValues: (popupHeight: 370 + bottomViewModel.dragTranslationThreshold, gestureTranslation: 344 - 370 - bottomViewModel.dragTranslationThreshold) ) } func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenDragDetentsLessThanDragValue_topPopupsAlignment() async { From 15500a9c926d5477147f603832262a216f03ddcd Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:49:02 +0100 Subject: [PATCH 100/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 6 +----- Tests/Tests+ViewModel+PopupVerticalStack.swift | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 9b1cba1f79..f46daa73ef 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -205,9 +205,6 @@ extension VM.VerticalStack { return 1 - scaleValue } } -private extension VM.VerticalStack { - var minScaleProgressMultiplier: CGFloat { 0.7 } -} // MARK: Corner Radius extension VM.VerticalStack { @@ -326,6 +323,7 @@ extension VM.VerticalStack { var dragThreshold: CGFloat { GlobalConfigContainer.vertical.dragThreshold } var dragGestureEnabled: Bool { getActivePopupConfig().isDragGestureEnabled } var dragTranslationThreshold: CGFloat { 8 } + var minScaleProgressMultiplier: CGFloat { 0.7 } } @@ -474,7 +472,5 @@ extension VM.VerticalStack { var t_stackOffset: CGFloat { stackOffset } var t_stackScaleFactor: CGFloat { stackScaleFactor } var t_stackOverlayFactor: CGFloat { stackOverlayFactor } - var t_minScaleProgressMultiplier: CGFloat { minScaleProgressMultiplier } - var t_maxStackOverlayFactor: CGFloat { maxStackOverlayFactor } } #endif diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 71e2886041..5a3e826226 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -973,7 +973,7 @@ extension PopupVerticalStackViewModelTests { popups: popups, gestureTranslation: 100, calculateForIndex: 1, - expectedValueBuilder: { await 1 - $0.t_stackScaleFactor * 3 * max(1 - $0.calculateTranslationProgress(), $0.t_minScaleProgressMultiplier) } + expectedValueBuilder: { await 1 - $0.stackScaleFactor * 3 * max(1 - $0.calculateTranslationProgress(), $0.minScaleProgressMultiplier) } ) } } @@ -1132,7 +1132,7 @@ extension PopupVerticalStackViewModelTests { popups: popups, gestureTranslation: -123, calculateForIndex: 0, - expectedValueBuilder: { min($0.t_stackOverlayFactor * 9, $0.t_maxStackOverlayFactor) } + expectedValueBuilder: { min($0.t_stackOverlayFactor * 9, $0.maxStackOverlayFactor) } ) } func test_calculateStackOverlayOpacity_withThreePopupsStacked_whenGestureTranslationIsPositive_last() async { From 20322b9a1a6f150ecb9b0ef6b63ab1fb7cc0fcc3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:51:52 +0100 Subject: [PATCH 101/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 7 ---- .../Tests+ViewModel+PopupVerticalStack.swift | 38 +++++++++---------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index f46daa73ef..9e03d40cf5 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -466,11 +466,4 @@ extension VM.VerticalStack { func t_updateGestureTranslation(_ newGestureTranslation: CGFloat) async { await updateGestureTranslation(newGestureTranslation) } } - -// MARK: Variables -extension VM.VerticalStack { - var t_stackOffset: CGFloat { stackOffset } - var t_stackScaleFactor: CGFloat { stackScaleFactor } - var t_stackOverlayFactor: CGFloat { stackOverlayFactor } -} #endif diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 5a3e826226..e4a0a20905 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -188,7 +188,7 @@ extension PopupVerticalStackViewModelTests { XCTAssertEqual( calculateLastPopupHeight(bottomViewModel), - screen.height - screen.safeArea.top - bottomViewModel.t_stackOffset * 4 + screen.height - screen.safeArea.top - bottomViewModel.stackOffset * 4 ) } func test_calculatePopupHeight_withLargeHeightMode_whenOnePopupStacked() async { @@ -210,7 +210,7 @@ extension PopupVerticalStackViewModelTests { XCTAssertEqual( calculateLastPopupHeight(bottomViewModel), - screen.height - screen.safeArea.top - bottomViewModel.t_stackOffset * 2 + screen.height - screen.safeArea.top - bottomViewModel.stackOffset * 2 ) } func test_calculatePopupHeight_withFullscreenHeightMode_whenOnePopupStacked() async { @@ -244,7 +244,7 @@ extension PopupVerticalStackViewModelTests { XCTAssertEqual( calculateLastPopupHeight(bottomViewModel), - screen.height - screen.safeArea.top - 2 * bottomViewModel.t_stackOffset + screen.height - screen.safeArea.top - 2 * bottomViewModel.stackOffset ) } func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked_popupPadding() async { @@ -301,7 +301,7 @@ extension PopupVerticalStackViewModelTests { viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, - expectedValue: screen.height - screen.safeArea.top - 2 * bottomViewModel.t_stackOffset + expectedValue: screen.height - screen.safeArea.top - 2 * bottomViewModel.stackOffset ) } func test_calculateActivePopupHeight_withLargeHeightMode_whenThreePopupsStacked() async { @@ -315,7 +315,7 @@ extension PopupVerticalStackViewModelTests { viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, - expectedValue: screen.height - screen.safeArea.top - 2 * bottomViewModel.t_stackOffset + expectedValue: screen.height - screen.safeArea.top - 2 * bottomViewModel.stackOffset ) } func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsNegative_twoPopupsStacked() async { @@ -328,7 +328,7 @@ extension PopupVerticalStackViewModelTests { viewModel: bottomViewModel, popups: popups, gestureTranslation: -51, - expectedValue: screen.height - screen.safeArea.top - bottomViewModel.t_stackOffset * 1 + 51 + expectedValue: screen.height - screen.safeArea.top - bottomViewModel.stackOffset * 1 + 51 ) } func test_calculateActivePopupHeight_withLargeHeightMode_whenGestureIsNegative_onePopupStacked() async { @@ -444,8 +444,8 @@ extension PopupVerticalStackViewModelTests { ]) XCTAssertEqual( - bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[2]), - -bottomViewModel.t_stackOffset * 2 + bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[2]), + -bottomViewModel.stackOffset * 2 ) } func test_calculateOffsetY_withZeroGestureTranslation_fivePopupsStacked_lastElement() async { @@ -481,8 +481,8 @@ extension PopupVerticalStackViewModelTests { await bottomViewModel.t_updateGestureTranslation(100) XCTAssertEqual( - bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[0]), - -bottomViewModel.t_stackOffset + bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[0]), + -bottomViewModel.stackOffset ) } func test_calculateOffsetY_withPositiveGestureTranslation_dragHeight_twoPopupsStacked_lastElement() async { @@ -493,7 +493,7 @@ extension PopupVerticalStackViewModelTests { await bottomViewModel.t_updateGestureTranslation(100) XCTAssertEqual( - bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[1]), + bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[1]), 100 - 21 ) } @@ -505,7 +505,7 @@ extension PopupVerticalStackViewModelTests { GlobalConfigContainer.vertical.isStackingEnabled = false XCTAssertEqual( - bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[0]), + bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[0]), 0 ) } @@ -516,8 +516,8 @@ extension PopupVerticalStackViewModelTests { ]) XCTAssertEqual( - topViewModel.t_calculateOffsetY(for: topViewModel.popups[0]), - topViewModel.t_stackOffset + topViewModel.calculateOffsetY(for: topViewModel.popups[0]), + topViewModel.stackOffset ) } func test_calculateOffsetY_withPopupsHaveTopAlignment_2() async { @@ -940,7 +940,7 @@ extension PopupVerticalStackViewModelTests { popups: popups, gestureTranslation: 0, calculateForIndex: 1, - expectedValueBuilder: { 1 - $0.t_stackScaleFactor * 2 } + expectedValueBuilder: { 1 - $0.stackScaleFactor * 2 } ) } func test_calculateScaleX_withNegativeGestureTranslation_fourPopupsStacked_third() async { @@ -956,7 +956,7 @@ extension PopupVerticalStackViewModelTests { popups: popups, gestureTranslation: -100, calculateForIndex: 2, - expectedValueBuilder: { 1 - $0.t_stackScaleFactor * 1 } + expectedValueBuilder: { 1 - $0.stackScaleFactor * 1 } ) } func test_calculateScaleX_withPositiveGestureTranslation_fivePopupsStacked_second() async { @@ -1094,7 +1094,7 @@ extension PopupVerticalStackViewModelTests { popups: popups, gestureTranslation: 0, calculateForIndex: 1, - expectedValueBuilder: { $0.t_stackOverlayFactor * 2 } + expectedValueBuilder: { $0.stackOverlayFactor * 2 } ) } func test_calculateStackOverlayOpacity_withFourPopupsStacked_whenGestureTranslationIsNegative_last() async { @@ -1132,7 +1132,7 @@ extension PopupVerticalStackViewModelTests { popups: popups, gestureTranslation: -123, calculateForIndex: 0, - expectedValueBuilder: { min($0.t_stackOverlayFactor * 9, $0.maxStackOverlayFactor) } + expectedValueBuilder: { min($0.stackOverlayFactor * 9, $0.maxStackOverlayFactor) } ) } func test_calculateStackOverlayOpacity_withThreePopupsStacked_whenGestureTranslationIsPositive_last() async { @@ -1163,7 +1163,7 @@ extension PopupVerticalStackViewModelTests { popups: popups, gestureTranslation: 241, calculateForIndex: 2, - expectedValueBuilder: { await (1 - $0.calculateTranslationProgress()) * $0.t_stackOverlayFactor } + expectedValueBuilder: { await (1 - $0.calculateTranslationProgress()) * $0.stackOverlayFactor } ) } } From 8b7c6e5a5508c65884972821c5c3c2c365628a6d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:53:28 +0100 Subject: [PATCH 102/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 4 ++-- Tests/Tests+ViewModel+PopupVerticalStack.swift | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 9e03d40cf5..49309c85b8 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -29,7 +29,7 @@ extension VM { class VerticalStack: ViewModel { // MARK: Update -private extension VM.VerticalStack { +extension VM.VerticalStack { func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { gestureTranslation = newGestureTranslation translationProgress = await calculateTranslationProgress() @@ -463,7 +463,7 @@ extension VM.VerticalStack { func t_calculateCornerRadius() -> [PopupAlignment: CGFloat] { calculateCornerRadius() } func t_calculateAndUpdateTranslationProgress() async { translationProgress = await calculateTranslationProgress() } - func t_updateGestureTranslation(_ newGestureTranslation: CGFloat) async { await updateGestureTranslation(newGestureTranslation) } + } #endif diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index e4a0a20905..e3140cb297 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -466,7 +466,7 @@ extension PopupVerticalStackViewModelTests { await bottomViewModel.updatePopupsValue([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 100) ]) - await bottomViewModel.t_updateGestureTranslation(-100) + await bottomViewModel.updateGestureTranslation(-100) XCTAssertEqual( bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[0]), @@ -478,7 +478,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) - await bottomViewModel.t_updateGestureTranslation(100) + await bottomViewModel.updateGestureTranslation(100) XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[0]), @@ -490,7 +490,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) - await bottomViewModel.t_updateGestureTranslation(100) + await bottomViewModel.updateGestureTranslation(100) XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[1]), @@ -525,7 +525,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) - await topViewModel.t_updateGestureTranslation(-100) + await topViewModel.updateGestureTranslation(-100) XCTAssertEqual( topViewModel.t_calculateOffsetY(for: topViewModel.popups[1]), @@ -1440,7 +1440,7 @@ private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnEnd(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat?, shouldPopupBeDismissed: Bool)) async { await viewModel.updatePopupsValue(popups) await updatePopups(viewModel) - await viewModel.t_updateGestureTranslation(gestureValue) + await viewModel.updateGestureTranslation(gestureValue) await viewModel.t_calculateAndUpdateTranslationProgress() await viewModel.onPopupDragGestureEnded(gestureValue) @@ -1467,7 +1467,7 @@ private extension PopupVerticalStackViewModelTests { func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.updatePopupsValue(popups) await updatePopups(viewModel) - await viewModel.t_updateGestureTranslation(gestureTranslation) + await viewModel.updateGestureTranslation(gestureTranslation) let calculatedValue = await calculatedValue(viewModel) let expectedValue = await expectedValueBuilder(viewModel) From f7d53132a1c4e41c17c0dabf94b00dec02f51c8d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:53:41 +0100 Subject: [PATCH 103/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 69864be2c5..d57d8d80dc 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -54,7 +54,7 @@ extension AnyPopup { func settingDragHeight(_ newDragHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.dragHeight = newDragHeight }} func settingEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updatingPopup { $0._body = .init(_body.environmentObject(environmentObject)) }} } -private extension AnyPopup { +extension AnyPopup { func updatingPopup(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { var popup = self customBuilder(&popup) From 136857fbdda6ddd03326aee0c3aa8e592c51d7e3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:53:50 +0100 Subject: [PATCH 104/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index c1d588cfb1..2d1fa4a63a 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -60,10 +60,13 @@ extension ViewModel { withAnimation(.transition) { objectWillChange.send() } } - func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) { Task { - let recalculatedPopupHeight = await recalculatePopupHeight(heightCandidate, popup) - if popup.height != recalculatedPopupHeight { updatePopupAction(popup.settingHeight(recalculatedPopupHeight)) } - }} + func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { + var newPopup = popup + newPopup.popupPadding = await calculatePopupPadding() + newPopup.height = await calculatePopupHeight(heightCandidate, newPopup) + + await updatePopupAction(newPopup) + } } private extension ViewModel { nonisolated func filterPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { From 19bd7a26ea573936d02c63097c23914997b38200 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:56:24 +0100 Subject: [PATCH 105/407] 1 --- Sources/Internal/UI/PopupView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 43dfa29b35..e6ab609093 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -114,8 +114,8 @@ private extension PopupView { func closePopup(_ popup: AnyPopup) { popupManager.stack(.removePopupInstance(popup)) } - func updateViewModels(_ updateBuilder: (ViewModel) -> ()) { - [topStackViewModel, centreStackViewModel, bottomStackViewModel].forEach(updateBuilder) + func updateViewModels(_ updateBuilder: (ViewModel) async -> ()) async { + for viewModel in [topStackViewModel, centreStackViewModel, bottomStackViewModel] { await updateBuilder(viewModel) } } } private extension PopupView { From 353ecabe277d33c40353f21660eefc08f748724b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 21:58:09 +0100 Subject: [PATCH 106/407] 1 --- Sources/Internal/UI/PopupView.swift | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index e6ab609093..bac312de25 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -82,15 +82,15 @@ private extension PopupView { } private extension PopupView { - func onAppear() { - updateViewModels { $0.setup(updatePopupAction: updatePopup, closePopupAction: closePopup) } - } - func onScreenChange(_ reader: GeometryProxy) { - updateViewModels { $0.updateScreenValue(.init(reader)) } - } - func onPopupsHeightChange(_ p: Any) { - updateViewModels { $0.updatePopupsValue(popupManager.stack) } - } + func onAppear() { Task { @MainActor in + await updateViewModels { $0.setup(updatePopupAction: updatePopup, closePopupAction: closePopup) } + }} + func onScreenChange(_ reader: GeometryProxy) { Task { @MainActor in + await updateViewModels { $0.updateScreenValue(.init(reader)) } + }} + func onPopupsHeightChange(_ p: Any) { Task { @MainActor in + await updateViewModels { await $0.updatePopupsValue(popupManager.stack) } + }} func onStackChange(_ oldStack: [AnyPopup], _ newStack: [AnyPopup]) { newStack .difference(from: oldStack) @@ -100,9 +100,9 @@ private extension PopupView { }} newStack.last?.onFocus() } - func onKeyboardStateChange(_ isKeyboardActive: Bool) { - updateViewModels { $0.updateKeyboardValue(isKeyboardActive) } - } + func onKeyboardStateChange(_ isKeyboardActive: Bool) { Task { @MainActor in + await updateViewModels { $0.updateKeyboardValue(isKeyboardActive) } + }} func onTap() { if tapOutsideClosesPopup { popupManager.stack(.removeLastPopup) }} From 76c4e3e6e5414e6cda0688dbada7ff9721947ef2 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:03:42 +0100 Subject: [PATCH 107/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index e3140cb297..0de08b89a6 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -904,7 +904,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.t_calculateCornerRadius() }, + calculatedValue: { $0.calculateCornerRadius() }, expectedValueBuilder: { _ in expectedValue } ) } From be344d6fc104a4accb0d55c1064961f3e93d2cb0 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:04:53 +0100 Subject: [PATCH 108/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 8 +++----- Tests/Tests+ViewModel+PopupVerticalStack.swift | 10 +++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 49309c85b8..ca889db1cd 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -456,12 +456,10 @@ extension VM.VerticalStack { func t_calculatePopupPadding() async -> EdgeInsets { await calculatePopupPadding() } func t_calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { calculateBodyPadding(for: popup) } func t_calculateHeight(heightCandidate: CGFloat, popup: AnyPopup) -> CGFloat { calculateNewPopupHeight(heightCandidate, popup.config) } - func t_calculateOffsetY(for popup: AnyPopup) -> CGFloat { calculateOffsetY(for: popup) } - func t_calculateScaleX(for popup: AnyPopup) -> CGFloat { calculateScaleX(for: popup) } - func t_calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { calculateVerticalFixedSize(for: popup) } - func t_calculateStackOverlayOpacity(for popup: AnyPopup) -> CGFloat { calculateStackOverlayOpacity(for: popup) } - func t_calculateCornerRadius() -> [PopupAlignment: CGFloat] { calculateCornerRadius() } + + + func t_calculateStackOverlayOpacity(for popup: AnyPopup) -> CGFloat { calculateStackOverlayOpacity(for: popup) } func t_calculateAndUpdateTranslationProgress() async { translationProgress = await calculateTranslationProgress() } diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 0de08b89a6..c9fcbdbd6e 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -458,7 +458,7 @@ extension PopupVerticalStackViewModelTests { ]) XCTAssertEqual( - bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[4]), + bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[4]), 0 ) } @@ -469,7 +469,7 @@ extension PopupVerticalStackViewModelTests { await bottomViewModel.updateGestureTranslation(-100) XCTAssertEqual( - bottomViewModel.t_calculateOffsetY(for: bottomViewModel.popups[0]), + bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[0]), 0 ) } @@ -528,7 +528,7 @@ extension PopupVerticalStackViewModelTests { await topViewModel.updateGestureTranslation(-100) XCTAssertEqual( - topViewModel.t_calculateOffsetY(for: topViewModel.popups[1]), + topViewModel.calculateOffsetY(for: topViewModel.popups[1]), 21 - 100 ) } @@ -983,7 +983,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.t_calculateScaleX(for: $0.popups[index]) }, + calculatedValue: { $0.calculateScaleX(for: $0.popups[index]) }, expectedValueBuilder: expectedValueBuilder ) } @@ -1058,7 +1058,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.t_calculateVerticalFixedSize(for: $0.popups[index]) }, + calculatedValue: { $0.calculateVerticalFixedSize(for: $0.popups[index]) }, expectedValueBuilder: { _ in expectedValue } ) } From 9d8d10e6154b7848086dcf1fc4cde9c69e73422d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:05:58 +0100 Subject: [PATCH 109/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 2 -- Tests/Tests+ViewModel+PopupVerticalStack.swift | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index ca889db1cd..113f5e40b9 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -453,8 +453,6 @@ private extension VM.VerticalStack { // MARK: Methods extension VM.VerticalStack { - func t_calculatePopupPadding() async -> EdgeInsets { await calculatePopupPadding() } - func t_calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { calculateBodyPadding(for: popup) } func t_calculateHeight(heightCandidate: CGFloat, popup: AnyPopup) -> CGFloat { calculateNewPopupHeight(heightCandidate, popup.config) } diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index c9fcbdbd6e..0e265cdbf1 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -627,7 +627,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { await $0.t_calculatePopupPadding() }, + calculatedValue: { await $0.calculatePopupPadding() }, expectedValueBuilder: { _ in expectedValue } ) } @@ -738,7 +738,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.t_calculateBodyPadding(for: popups.last!) }, + calculatedValue: { $0.calculateBodyPadding(for: popups.last!) }, expectedValueBuilder: { _ in expectedValue } ) } From d9aac9e44923a99040e9e01f49a08af155f4d15b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:09:19 +0100 Subject: [PATCH 110/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 4 +--- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 113f5e40b9..878e31a23d 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -252,7 +252,7 @@ extension VM.VerticalStack { // MARK: - Stack Overlay Opacity extension VM.VerticalStack { - func calculateStackOverlayOpacity(for popup: AnyPopup) -> Double { + func calculateStackOverlayOpacity(for popup: AnyPopup) -> CGFloat { guard popup != popups.last else { return 0 } let invertedIndex = getInvertedIndex(of: popup), @@ -456,8 +456,6 @@ extension VM.VerticalStack { func t_calculateHeight(heightCandidate: CGFloat, popup: AnyPopup) -> CGFloat { calculateNewPopupHeight(heightCandidate, popup.config) } - - func t_calculateStackOverlayOpacity(for popup: AnyPopup) -> CGFloat { calculateStackOverlayOpacity(for: popup) } func t_calculateAndUpdateTranslationProgress() async { translationProgress = await calculateTranslationProgress() } diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 0e265cdbf1..c12ed32d23 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1173,7 +1173,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.t_calculateStackOverlayOpacity(for: $0.popups[index]) }, + calculatedValue: { $0.calculateStackOverlayOpacity(for: $0.popups[index]) }, expectedValueBuilder: expectedValueBuilder ) } From 25cea907a15322285b3c5dd6857b1662143edd76 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:10:28 +0100 Subject: [PATCH 111/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 2 -- Tests/Tests+ViewModel+PopupVerticalStack.swift | 1 - 2 files changed, 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 878e31a23d..12b4280455 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -456,8 +456,6 @@ extension VM.VerticalStack { func t_calculateHeight(heightCandidate: CGFloat, popup: AnyPopup) -> CGFloat { calculateNewPopupHeight(heightCandidate, popup.config) } - func t_calculateAndUpdateTranslationProgress() async { translationProgress = await calculateTranslationProgress() } - } #endif diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index c12ed32d23..b32220e3b6 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1441,7 +1441,6 @@ private extension PopupVerticalStackViewModelTests { await viewModel.updatePopupsValue(popups) await updatePopups(viewModel) await viewModel.updateGestureTranslation(gestureValue) - await viewModel.t_calculateAndUpdateTranslationProgress() await viewModel.onPopupDragGestureEnded(gestureValue) XCTAssertEqual(viewModel.popups.count, expectedValues.shouldPopupBeDismissed ? 0 : 1) From 634f3223fe8cf918e3739bafea6ada3825647fe2 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:28:33 +0100 Subject: [PATCH 112/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index b32220e3b6..dad9a16fcc 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -271,8 +271,14 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func calculateLastPopupHeight(_ viewModel: ViewModel) -> CGFloat { - viewModel.t_calculateHeight(heightCandidate: viewModel.popups.last!.height!, popup: viewModel.popups.last!) + func appendPopupsAndCheckPopupHeight(viewModel: ViewModel, popups: [AnyPopup], calculateForIndex index: Int, expectedValue: CGFloat) async { + await appendPopupsAndPerformChecks( + viewModel: viewModel, + popups: popups, + gestureTranslation: 0, + calculatedValue: { $0.popups[index].height }, + expectedValueBuilder: { _ in expectedValue } + ) } } From fd225c6df18e9298c8fefae611f8c97471828a35 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:30:11 +0100 Subject: [PATCH 113/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index dad9a16fcc..8a017208ad 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -214,59 +214,69 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withFullscreenHeightMode_whenOnePopupStacked() async { - await bottomViewModel.updatePopupsValue([ + let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100) - ]) + ] - XCTAssertEqual( - calculateLastPopupHeight(bottomViewModel), - screen.height + await appendPopupsAndCheckPopupHeight( + viewModel: bottomViewModel, + popups: popups, + calculateForIndex: 0, + expectedValue: screen.height ) } func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked() async { - await bottomViewModel.updatePopupsValue([ + let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 2000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 3000) - ]) + ] - XCTAssertEqual( - calculateLastPopupHeight(bottomViewModel), - screen.height + await appendPopupsAndCheckPopupHeight( + viewModel: bottomViewModel, + popups: popups, + calculateForIndex: 2, + expectedValue: screen.height ) } func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupsStacked_popupPadding() async { - await bottomViewModel.updatePopupsValue([ + let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 2000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 3000, popupPadding: .init(top: 33, leading: 15, bottom: 21, trailing: 15)) - ]) + ] - XCTAssertEqual( - calculateLastPopupHeight(bottomViewModel), - screen.height - screen.safeArea.top - 2 * bottomViewModel.stackOffset + await appendPopupsAndCheckPopupHeight( + viewModel: bottomViewModel, + popups: popups, + calculateForIndex: 2, + expectedValue: screen.height - screen.safeArea.top - 2 * bottomViewModel.stackOffset ) } func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked_popupPadding() async { - await bottomViewModel.updatePopupsValue([ + let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 2000), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 3000, popupPadding: .init(top: 33, leading: 15, bottom: 21, trailing: 15)) - ]) + ] - XCTAssertEqual( - calculateLastPopupHeight(bottomViewModel), - screen.height + await appendPopupsAndCheckPopupHeight( + viewModel: bottomViewModel, + popups: popups, + calculateForIndex: 2, + expectedValue: screen.height ) } func test_calculatePopupHeight_withLargeHeightMode_whenPopupsHaveTopAlignment() async { - await topViewModel.updatePopupsValue([ + let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .large, popupHeight: 100) - ]) + ] - XCTAssertEqual( - calculateLastPopupHeight(topViewModel), - screen.height - screen.safeArea.bottom + await appendPopupsAndCheckPopupHeight( + viewModel: topViewModel, + popups: popups, + calculateForIndex: 0, + expectedValue: screen.height - screen.safeArea.bottom ) } } From fb1daceeacbcd752088d11c24e38aa63f1dfc4e6 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:31:46 +0100 Subject: [PATCH 114/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 8a017208ad..546f589619 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -202,15 +202,17 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupStacked() async { - await bottomViewModel.updatePopupsValue([ + let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 700), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 1000) - ]) + ] - XCTAssertEqual( - calculateLastPopupHeight(bottomViewModel), - screen.height - screen.safeArea.top - bottomViewModel.stackOffset * 2 + await appendPopupsAndCheckPopupHeight( + viewModel: bottomViewModel, + popups: popups, + calculateForIndex: 2, + expectedValue: screen.height - screen.safeArea.top - bottomViewModel.stackOffset * 2 ) } func test_calculatePopupHeight_withFullscreenHeightMode_whenOnePopupStacked() async { From 5b3ee3929797bd376b52390aa88e2d24e84be6eb Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:32:42 +0100 Subject: [PATCH 115/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 546f589619..5d9071e897 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -192,13 +192,15 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withLargeHeightMode_whenOnePopupStacked() async { - await bottomViewModel.updatePopupsValue([ + let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 100) - ]) + ] - XCTAssertEqual( - calculateLastPopupHeight(bottomViewModel), - screen.height - screen.safeArea.top + await appendPopupsAndCheckPopupHeight( + viewModel: bottomViewModel, + popups: popups, + calculateForIndex: 0, + expectedValue: screen.height - screen.safeArea.top ) } func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupStacked() async { From 1702ca04b35dcdbb1716d9fde8e474a093b28ed6 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:33:37 +0100 Subject: [PATCH 116/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 5d9071e897..3f5d78fa34 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -178,17 +178,19 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_fivePopupStacked() async { - await bottomViewModel.updatePopupsValue([ + let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 200), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2000) - ]) + ] - XCTAssertEqual( - calculateLastPopupHeight(bottomViewModel), - screen.height - screen.safeArea.top - bottomViewModel.stackOffset * 4 + await appendPopupsAndCheckPopupHeight( + viewModel: bottomViewModel, + popups: popups, + calculateForIndex: 4, + expectedValue: screen.height - screen.safeArea.top - bottomViewModel.stackOffset * 4 ) } func test_calculatePopupHeight_withLargeHeightMode_whenOnePopupStacked() async { From 42e04278a70605ef949e15179bad1fe46b72e617 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:34:23 +0100 Subject: [PATCH 117/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 3f5d78fa34..cfa5e3a1bc 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -145,9 +145,9 @@ private extension PopupVerticalStackViewModelTests { // MARK: Popup Height extension PopupVerticalStackViewModelTests { func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_onePopupStacked() async { - await bottomViewModel.updatePopupsValue([ + let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150) - ]) + ] XCTAssertEqual( calculateLastPopupHeight(bottomViewModel), @@ -155,12 +155,12 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_fourPopupsStacked() async { - await bottomViewModel.updatePopupsValue([ + let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 200), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100) - ]) + ] XCTAssertEqual( calculateLastPopupHeight(bottomViewModel), @@ -168,9 +168,9 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_onePopupStacked() async { - await bottomViewModel.updatePopupsValue([ + let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2000) - ]) + ] XCTAssertEqual( calculateLastPopupHeight(bottomViewModel), From 8673a705bc73fc1bb3f661b4eb6116c2c917ac65 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:34:57 +0100 Subject: [PATCH 118/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index cfa5e3a1bc..a7f1763716 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -172,9 +172,11 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2000) ] - XCTAssertEqual( - calculateLastPopupHeight(bottomViewModel), - screen.height - screen.safeArea.top + await appendPopupsAndCheckPopupHeight( + viewModel: bottomViewModel, + popups: popups, + calculateForIndex: 0, + expectedValue: screen.height - screen.safeArea.top ) } func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_fivePopupStacked() async { From f3c27a8d915ed38fd004e44ec1f1eccc31dd721c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:36:33 +0100 Subject: [PATCH 119/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index a7f1763716..27412a0dec 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -149,9 +149,11 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150) ] - XCTAssertEqual( - calculateLastPopupHeight(bottomViewModel), - 150.0 + await appendPopupsAndCheckPopupHeight( + viewModel: bottomViewModel, + popups: popups, + calculateForIndex: 0, + expectedValue: 150 ) } func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_fourPopupsStacked() async { @@ -162,9 +164,11 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100) ] - XCTAssertEqual( - calculateLastPopupHeight(bottomViewModel), - 100.0 + await appendPopupsAndCheckPopupHeight( + viewModel: bottomViewModel, + popups: popups, + calculateForIndex: 3, + expectedValue: 100 ) } func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_onePopupStacked() async { From ffff97d85c3247e1710faffa5c199607c61fb843 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:37:57 +0100 Subject: [PATCH 120/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 12b4280455..871129c5c7 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -443,19 +443,3 @@ private extension VM.VerticalStack { translationProgress >= dragThreshold } } - - - -// MARK: - TESTS -#if DEBUG - - - -// MARK: Methods -extension VM.VerticalStack { - func t_calculateHeight(heightCandidate: CGFloat, popup: AnyPopup) -> CGFloat { calculateNewPopupHeight(heightCandidate, popup.config) } - - - -} -#endif From f8a620d2a81f37b211d5fd655b34f8506d60ed15 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:47:04 +0100 Subject: [PATCH 121/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 4 ---- Tests/Tests+ViewModel+PopupCentreStack.swift | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index e50aebcc98..66618e3cb4 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -109,9 +109,5 @@ private extension VM.CentreStack { // MARK: Methods extension VM.CentreStack { func t_calculateHeight(heightCandidate: CGFloat) -> CGFloat { min(heightCandidate, calculateLargeScreenHeight()) } - func t_calculatePopupPadding() -> EdgeInsets { calculatePopupPadding() } - func t_calculateCornerRadius() -> [PopupAlignment: CGFloat] { calculateCornerRadius() } - func t_calculateOpacity(for popup: AnyPopup) -> CGFloat { calculateOpacity(for: popup) } - func t_calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { calculateVerticalFixedSize(for: popup) } } #endif diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index 076b6ab564..c0e59f86d0 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -102,7 +102,7 @@ private extension PopupCentreStackViewModelTests { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: isKeyboardActive, - calculatedValue: { $0.t_calculatePopupPadding() }, + calculatedValue: { $0.calculatePopupPadding() }, expectedValueBuilder: { _ in expectedValue } ) } @@ -138,7 +138,7 @@ private extension PopupCentreStackViewModelTests { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, - calculatedValue: { $0.t_calculateCornerRadius() }, + calculatedValue: { $0.calculateCornerRadius() }, expectedValueBuilder: { _ in expectedValue } ) } @@ -178,7 +178,7 @@ private extension PopupCentreStackViewModelTests { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, - calculatedValue: { [self] in $0.t_calculateOpacity(for: viewModel.popups[index]) }, + calculatedValue: { [self] in $0.calculateOpacity(for: viewModel.popups[index]) }, expectedValueBuilder: { _ in expectedValue } ) } @@ -218,7 +218,7 @@ private extension PopupCentreStackViewModelTests { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, - calculatedValue: { $0.t_calculateVerticalFixedSize(for: $0.popups[index]) }, + calculatedValue: { $0.calculateVerticalFixedSize(for: $0.popups[index]) }, expectedValueBuilder: { _ in expectedValue } ) } From b5b92a1a3385681a76c1da9d5de13fe27aa6ebd4 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:52:59 +0100 Subject: [PATCH 122/407] 1 --- .../View Models/ViewModel+CentreStack.swift | 13 ------------- Sources/Internal/View Models/ViewModel.swift | 1 - 2 files changed, 14 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 66618e3cb4..cab2f0de4e 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -98,16 +98,3 @@ private extension VM.CentreStack { await popups.last?.height } } - - - -// MARK: - TESTS -#if DEBUG - - - -// MARK: Methods -extension VM.CentreStack { - func t_calculateHeight(heightCandidate: CGFloat) -> CGFloat { min(heightCandidate, calculateLargeScreenHeight()) } -} -#endif diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 2d1fa4a63a..5c01e80e9a 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -28,7 +28,6 @@ enum VM {} nonisolated func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { fatalError() } nonisolated func calculatePopupPadding() async -> EdgeInsets { fatalError() } nonisolated func calculateHeightForActivePopup() async -> CGFloat? { fatalError() } - nonisolated func recalculatePopupPadding() async -> EdgeInsets { fatalError() } // MARK: Initializer init(_ config: Config.Type) { self.alignment = .init(Config.self) } From a00db14829deb6e661de21555348006818f0df0e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:58:53 +0100 Subject: [PATCH 123/407] 1 --- Sources/Internal/UI/PopupCentreStackView.swift | 2 +- .../Internal/View Models/ViewModel+CentreStack.swift | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/UI/PopupCentreStackView.swift b/Sources/Internal/UI/PopupCentreStackView.swift index 52fee48dbd..62d43666b9 100644 --- a/Sources/Internal/UI/PopupCentreStackView.swift +++ b/Sources/Internal/UI/PopupCentreStackView.swift @@ -37,7 +37,7 @@ private extension PopupCentreStackView { .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.calculateCornerRadius()) .opacity(viewModel.calculateOpacity(for: popup)) .focusSection_tvOS() - .padding(viewModel.calculatePopupPadding()) + .padding(popup.popupPadding) .compositingGroup() } } diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index cab2f0de4e..bce7a5f65a 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -13,7 +13,8 @@ import SwiftUI extension VM { class CentreStack: ViewModel { // MARK: Overridden Methods - override func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await recalculatePopupHeight(heightCandidate) } + override func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _calculatePopupHeight(heightCandidate) } + override func calculatePopupPadding() async -> EdgeInsets { await _calculatePopupPadding() } override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } }} @@ -23,9 +24,9 @@ extension VM { class CentreStack: ViewModel { -// MARK: Recalculate Popup Height +// MARK: Popup Height private extension VM.CentreStack { - nonisolated func recalculatePopupHeight(_ heightCandidate: CGFloat) async -> CGFloat { + nonisolated func _calculatePopupHeight(_ heightCandidate: CGFloat) async -> CGFloat { await min(heightCandidate, calculateLargeScreenHeight()) } } @@ -38,8 +39,8 @@ private extension VM.CentreStack { } // MARK: Popup Padding -extension VM.CentreStack { - func calculatePopupPadding() -> EdgeInsets { .init( +private extension VM.CentreStack { + nonisolated func _calculatePopupPadding() async -> EdgeInsets { await .init( top: calculateVerticalPopupPadding(for: .top), leading: calculateLeadingPopupPadding(), bottom: calculateVerticalPopupPadding(for: .bottom), From e36f04d0aaebe47a2f3736883bcc38e7057afc2d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:59:19 +0100 Subject: [PATCH 124/407] 1 --- Tests/Tests+ViewModel+PopupCentreStack.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index c0e59f86d0..b15a246626 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -102,7 +102,7 @@ private extension PopupCentreStackViewModelTests { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: isKeyboardActive, - calculatedValue: { $0.calculatePopupPadding() }, + calculatedValue: { await $0.calculatePopupPadding() }, expectedValueBuilder: { _ in expectedValue } ) } @@ -236,13 +236,15 @@ private extension PopupCentreStackViewModelTests { let config = getConfigForPopupHeightTests(cornerRadius: cornerRadius, popupPadding: popupPadding) return AnyPopup.t_createNew(config: config).settingHeight(popupHeight) } - func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) -> (Value), expectedValueBuilder: @escaping (ViewModel) -> Value) async { + func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.updatePopupsValue(popups) - await viewModel.updatePopupsValue(recalculatePopupHeights(viewModel)) + await updatePopups(viewModel) viewModel.updateKeyboardValue(isKeyboardActive) viewModel.updateScreenValue(isKeyboardActive ? screenWithKeyboard : screen) - XCTAssertEqual(calculatedValue(viewModel), expectedValueBuilder(viewModel)) + let calculatedValue = await calculatedValue(viewModel) + let expectedValue = await expectedValueBuilder(viewModel) + XCTAssertEqual(calculatedValue, expectedValue) } } private extension PopupCentreStackViewModelTests { From ffa090e1c6e630bf397bdcf7ea1e62c9a31ad90c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 22:59:31 +0100 Subject: [PATCH 125/407] 1 --- Tests/Tests+ViewModel+PopupCentreStack.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index b15a246626..8326e726b4 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -252,9 +252,9 @@ private extension PopupCentreStackViewModelTests { popupPadding: popupPadding, cornerRadius: cornerRadius )} - func recalculatePopupHeights(_ viewModel: ViewModel) -> [AnyPopup] { viewModel.popups.map { - $0.settingHeight(viewModel.t_calculateHeight(heightCandidate: $0.height!)) - }} + func updatePopups(_ viewModel: ViewModel) async { + for popup in viewModel.popups { await viewModel.recalculateAndUpdatePopupHeight(popup.height!, popup) } + } } // MARK: Screen From beb6f9b87cec535b31974279d83ef80a04ba12a3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 23:08:00 +0100 Subject: [PATCH 126/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index d57d8d80dc..6401d24db8 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -50,7 +50,6 @@ extension AnyPopup { func settingCustomID(_ customID: String) -> AnyPopup { updatingPopup { $0.id = .create(from: customID) }} func settingDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updatingPopup { $0.dismissTimer = .prepare(time: secondsToDismiss) }} func startingDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updatingPopup { $0.dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} - func settingHeight(_ newHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.height = newHeight }} func settingDragHeight(_ newDragHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.dragHeight = newDragHeight }} func settingEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updatingPopup { $0._body = .init(_body.environmentObject(environmentObject)) }} } From 74160254d4b1944dace70d16b1cbe1a9ab6434ab Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 23:18:20 +0100 Subject: [PATCH 127/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 2 +- Sources/Internal/UI/PopupVerticalStackView.swift | 2 +- .../View Models/ViewModel+VerticalStack.swift | 11 ++++++----- Sources/Internal/View Models/ViewModel.swift | 2 ++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 6401d24db8..c599c85254 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -17,7 +17,7 @@ struct AnyPopup: Popup { var height: CGFloat? = nil var dragHeight: CGFloat? = nil var popupPadding: EdgeInsets = .init() - var cornerRadius: CGFloat = 0 + var cornerRadius: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] private var dismissTimer: PopupActionScheduler? = nil private var _body: AnyView diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index f773490227..17e0959aa3 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -34,7 +34,7 @@ private extension PopupVerticalStackView { .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) - .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: viewModel.calculateCornerRadius()) + .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: popup.cornerRadius) .offset(y: viewModel.calculateOffsetY(for: popup)) .scaleEffect(x: viewModel.calculateScaleX(for: popup)) .focusSection_tvOS() diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 871129c5c7..611b774295 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -20,6 +20,7 @@ extension VM { class VerticalStack: ViewModel { override func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _calculatePopupHeight(heightCandidate, popup) } override func calculatePopupPadding() async -> EdgeInsets { await _calculatePopupPadding() } override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } + override func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { await _calculateCornerRadius() } }} @@ -207,12 +208,12 @@ extension VM.VerticalStack { } // MARK: Corner Radius -extension VM.VerticalStack { - func calculateCornerRadius() -> [PopupAlignment: CGFloat] { - guard let activePopup = popups.last else { return [:] } +private extension VM.VerticalStack { + nonisolated func _calculateCornerRadius() async -> [PopupAlignment: CGFloat] { + guard let activePopup = await popups.last else { return [:] } - let cornerRadiusValue = calculateCornerRadiusValue(activePopup) - return [ + let cornerRadiusValue = await calculateCornerRadiusValue(activePopup) + return await [ .top: calculateTopCornerRadius(cornerRadiusValue, activePopup), .bottom: calculateBottomCornerRadius(cornerRadiusValue, activePopup) ] diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 5c01e80e9a..dad21e8890 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -27,6 +27,7 @@ enum VM {} // MARK: Methods to Override nonisolated func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { fatalError() } nonisolated func calculatePopupPadding() async -> EdgeInsets { fatalError() } + nonisolated func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { fatalError() } nonisolated func calculateHeightForActivePopup() async -> CGFloat? { fatalError() } // MARK: Initializer @@ -63,6 +64,7 @@ extension ViewModel { var newPopup = popup newPopup.popupPadding = await calculatePopupPadding() newPopup.height = await calculatePopupHeight(heightCandidate, newPopup) + newPopup.cornerRadius = await calculateCornerRadius() await updatePopupAction(newPopup) } From e39a0fc6ad109c3db3bc03186ac5a142188e0618 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 23:21:42 +0100 Subject: [PATCH 128/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 1 + Sources/Internal/UI/PopupCentreStackView.swift | 2 +- Sources/Internal/View Models/ViewModel+CentreStack.swift | 5 +++-- Tests/Tests+ViewModel+PopupCentreStack.swift | 2 +- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index c599c85254..52d9e5aff7 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -50,6 +50,7 @@ extension AnyPopup { func settingCustomID(_ customID: String) -> AnyPopup { updatingPopup { $0.id = .create(from: customID) }} func settingDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updatingPopup { $0.dismissTimer = .prepare(time: secondsToDismiss) }} func startingDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updatingPopup { $0.dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} + func settingHeight(_ newHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.height = newHeight }} func settingDragHeight(_ newDragHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.dragHeight = newDragHeight }} func settingEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updatingPopup { $0._body = .init(_body.environmentObject(environmentObject)) }} } diff --git a/Sources/Internal/UI/PopupCentreStackView.swift b/Sources/Internal/UI/PopupCentreStackView.swift index 62d43666b9..8c9f9518ec 100644 --- a/Sources/Internal/UI/PopupCentreStackView.swift +++ b/Sources/Internal/UI/PopupCentreStackView.swift @@ -34,7 +34,7 @@ private extension PopupCentreStackView { .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopupHeight) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupHeight) - .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.calculateCornerRadius()) + .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: popup.cornerRadius) .opacity(viewModel.calculateOpacity(for: popup)) .focusSection_tvOS() .padding(popup.popupPadding) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index bce7a5f65a..5fe38c9d93 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -16,6 +16,7 @@ extension VM { class CentreStack: ViewModel { override func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _calculatePopupHeight(heightCandidate) } override func calculatePopupPadding() async -> EdgeInsets { await _calculatePopupPadding() } override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } + override func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { await _calculateCornerRadius() } }} @@ -66,8 +67,8 @@ private extension VM.CentreStack { } // MARK: Corner Radius -extension VM.CentreStack { - func calculateCornerRadius() -> [PopupAlignment : CGFloat] {[ +private extension VM.CentreStack { + nonisolated func _calculateCornerRadius() async -> [PopupAlignment : CGFloat] { await [ .top: getActivePopupConfig().cornerRadius, .bottom: getActivePopupConfig().cornerRadius ]} diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index 8326e726b4..a880c309b1 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -138,7 +138,7 @@ private extension PopupCentreStackViewModelTests { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, - calculatedValue: { $0.calculateCornerRadius() }, + calculatedValue: { await $0.calculateCornerRadius() }, expectedValueBuilder: { _ in expectedValue } ) } diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 27412a0dec..f3e4eadecd 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -932,7 +932,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.calculateCornerRadius() }, + calculatedValue: { await $0.calculateCornerRadius() }, expectedValueBuilder: { _ in expectedValue } ) } From 3fdad86b06b5930eef5327324ea3dc269e38412e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 23:25:23 +0100 Subject: [PATCH 129/407] 1 --- MijickPopups.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MijickPopups.podspec b/MijickPopups.podspec index 5cced8735a..82f2d49049 100644 --- a/MijickPopups.podspec +++ b/MijickPopups.podspec @@ -5,7 +5,7 @@ Pod::Spec.new do |s| MijickPopups solves two seemingly contradictory problems - to allow developers to create fully customizable popup, and to make the process as simple as possible. DESC - s.version = '3.0.2' + s.version = '4.0.0' s.ios.deployment_target = '14.0' s.osx.deployment_target = '12.0' s.tvos.deployment_target = '15.0' From 6e90fc37d7c97ef78912465fc980c0f6c5a7abbc Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 23:48:27 +0100 Subject: [PATCH 130/407] 1 --- .../Configurables/Global/GlobalConfig+Centre.swift | 2 +- .../Configurables/Global/GlobalConfig+Vertical.swift | 2 +- .../Internal/View Models/ViewModel+VerticalStack.swift | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/Configurables/Global/GlobalConfig+Centre.swift b/Sources/Internal/Configurables/Global/GlobalConfig+Centre.swift index 40c9d4987f..24929fba87 100644 --- a/Sources/Internal/Configurables/Global/GlobalConfig+Centre.swift +++ b/Sources/Internal/Configurables/Global/GlobalConfig+Centre.swift @@ -15,7 +15,7 @@ public final class GlobalConfigCentre: GlobalConfig { required public init() {} // MARK: Active Variables public var popupPadding: EdgeInsets = .init(top: 0, leading: 16, bottom: 0, trailing: 16) public var cornerRadius: CGFloat = 24 - public var backgroundColor: Color = .init(.secondarySystemBackground) + public var backgroundColor: Color = .white public var overlayColor: Color = .black.opacity(0.5) public var isTapOutsideToDismissEnabled: Bool = false diff --git a/Sources/Internal/Configurables/Global/GlobalConfig+Vertical.swift b/Sources/Internal/Configurables/Global/GlobalConfig+Vertical.swift index 2e663e0818..faf8e529ed 100644 --- a/Sources/Internal/Configurables/Global/GlobalConfig+Vertical.swift +++ b/Sources/Internal/Configurables/Global/GlobalConfig+Vertical.swift @@ -15,7 +15,7 @@ public final class GlobalConfigVertical: GlobalConfig { required public init() { // MARK: Content public var popupPadding: EdgeInsets = .init() public var cornerRadius: CGFloat = 40 - public var backgroundColor: Color = .init(.secondarySystemBackground) + public var backgroundColor: Color = .white public var overlayColor: Color = .black.opacity(0.5) public var isStackingEnabled: Bool = true diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 611b774295..a25ffda4a9 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -56,10 +56,10 @@ private extension VM.VerticalStack { } } private extension VM.VerticalStack { - func calculateNewPopupHeight(_ heightCandidate: CGFloat, _ popupConfig: AnyPopupConfig) -> CGFloat { switch popupConfig.heightMode { - case .auto: min(heightCandidate, calculateLargeScreenHeight()) - case .large: calculateLargeScreenHeight() - case .fullscreen: getFullscreenHeight() + nonisolated func calculateNewPopupHeight(_ heightCandidate: CGFloat, _ popupConfig: AnyPopupConfig) async -> CGFloat { switch popupConfig.heightMode { + case .auto: await min(heightCandidate, calculateLargeScreenHeight()) + case .large: await calculateLargeScreenHeight() + case .fullscreen: await getFullscreenHeight() }} } private extension VM.VerticalStack { From 84dcbc704a008cbb7ab00c803162f34a55789eb8 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 7 Nov 2024 23:53:26 +0100 Subject: [PATCH 131/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index a25ffda4a9..ce3b5a6d97 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -220,16 +220,16 @@ private extension VM.VerticalStack { } } private extension VM.VerticalStack { - func calculateCornerRadiusValue(_ activePopup: AnyPopup) -> CGFloat { switch activePopup.config.heightMode { + nonisolated func calculateCornerRadiusValue(_ activePopup: AnyPopup) async -> CGFloat { switch activePopup.config.heightMode { case .auto, .large: activePopup.config.cornerRadius case .fullscreen: 0 }} - func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat, _ activePopup: AnyPopup) -> CGFloat { switch alignment { + nonisolated func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat, _ activePopup: AnyPopup) async -> CGFloat { switch alignment { case .top: activePopup.popupPadding.top != 0 ? cornerRadiusValue : 0 case .bottom: cornerRadiusValue case .centre: fatalError() }} - func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat, _ activePopup: AnyPopup) -> CGFloat { switch alignment { + nonisolated func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat, _ activePopup: AnyPopup) async -> CGFloat { switch alignment { case .top: cornerRadiusValue case .bottom: activePopup.popupPadding.bottom != 0 ? cornerRadiusValue : 0 case .centre: fatalError() From d7c846747f2ecec9c3f0b061eb73eabdca56b9b0 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 15:10:28 +0100 Subject: [PATCH 132/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index ce3b5a6d97..0fa0a71337 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -335,38 +335,38 @@ extension VM.VerticalStack { // MARK: On Changed extension VM.VerticalStack { - func onPopupDragGestureChanged(_ value: CGFloat) async { if dragGestureEnabled { - let newGestureTranslation = calculateGestureTranslation(value) + nonisolated func onPopupDragGestureChanged(_ value: CGFloat) async { if await dragGestureEnabled { + let newGestureTranslation = await calculateGestureTranslation(value) await updateGestureTranslation(newGestureTranslation) }} } private extension VM.VerticalStack { - func calculateGestureTranslation(_ value: CGFloat) -> CGFloat { switch getActivePopupConfig().dragDetents.isEmpty { - case true: calculateGestureTranslationWhenNoDragDetents(value) - case false: calculateGestureTranslationWhenDragDetents(value) + nonisolated func calculateGestureTranslation(_ value: CGFloat) async -> CGFloat { switch await getActivePopupConfig().dragDetents.isEmpty { + case true: await calculateGestureTranslationWhenNoDragDetents(value) + case false: await calculateGestureTranslationWhenDragDetents(value) }} } private extension VM.VerticalStack { - func calculateGestureTranslationWhenNoDragDetents(_ value: CGFloat) -> CGFloat { - calculateDragExtremeValue(value, 0) + nonisolated func calculateGestureTranslationWhenNoDragDetents(_ value: CGFloat) async -> CGFloat { + await calculateDragExtremeValue(value, 0) } - func calculateGestureTranslationWhenDragDetents(_ value: CGFloat) -> CGFloat { guard value * getDragTranslationMultiplier() > 0, let activePopupHeight = popups.last?.height else { return value } - let maxHeight = calculateMaxHeightForDragGesture(activePopupHeight) - let dragTranslation = calculateDragTranslation(maxHeight, activePopupHeight) - return calculateDragExtremeValue(dragTranslation, value) + nonisolated func calculateGestureTranslationWhenDragDetents(_ value: CGFloat) async -> CGFloat { guard await value * getDragTranslationMultiplier() > 0, let activePopupHeight = await popups.last?.height else { return value } + let maxHeight = await calculateMaxHeightForDragGesture(activePopupHeight) + let dragTranslation = await calculateDragTranslation(maxHeight, activePopupHeight) + return await calculateDragExtremeValue(dragTranslation, value) } } private extension VM.VerticalStack { - func calculateMaxHeightForDragGesture(_ activePopupHeight: CGFloat) -> CGFloat { - let maxHeight1 = (calculatePopupTargetHeightsFromDragDetents(activePopupHeight).max() ?? 0) + dragTranslationThreshold - let maxHeight2 = screen.height + nonisolated func calculateMaxHeightForDragGesture(_ activePopupHeight: CGFloat) async -> CGFloat { + let maxHeight1 = await (calculatePopupTargetHeightsFromDragDetents(activePopupHeight).max() ?? 0) + dragTranslationThreshold + let maxHeight2 = await screen.height return min(maxHeight1, maxHeight2) } - func calculateDragTranslation(_ maxHeight: CGFloat, _ activePopupHeight: CGFloat) -> CGFloat { - let translation = maxHeight - activePopupHeight - (popups.last?.dragHeight ?? 0) - return translation * getDragTranslationMultiplier() + nonisolated func calculateDragTranslation(_ maxHeight: CGFloat, _ activePopupHeight: CGFloat) async -> CGFloat { + let translation = await maxHeight - activePopupHeight - (popups.last?.dragHeight ?? 0) + return await translation * getDragTranslationMultiplier() } - func calculateDragExtremeValue(_ value1: CGFloat, _ value2: CGFloat) -> CGFloat { switch alignment { + nonisolated func calculateDragExtremeValue(_ value1: CGFloat, _ value2: CGFloat) async -> CGFloat { switch alignment { case .top: min(value1, value2) case .bottom: max(value1, value2) case .centre: fatalError() From 84b2540a041211d799aa46827de1ba4c2b5cf110 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 15:10:39 +0100 Subject: [PATCH 133/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 0fa0a71337..30aace8bf3 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -375,7 +375,7 @@ private extension VM.VerticalStack { // MARK: On Ended extension VM.VerticalStack { - func onPopupDragGestureEnded(_ value: CGFloat) async { if value != 0 { + nonisolated func onPopupDragGestureEnded(_ value: CGFloat) async { if value != 0 { await dismissLastItemIfNeeded() await updateTranslationValues() }} From d87c8b227bec3ae4080b036317c51a5bd1d714a1 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 15:24:22 +0100 Subject: [PATCH 134/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 1 - Sources/Internal/UI/PopupCentreStackView.swift | 2 +- Sources/Internal/UI/PopupVerticalStackView.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 3 ++- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 52d9e5aff7..70c2ed645d 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -17,7 +17,6 @@ struct AnyPopup: Popup { var height: CGFloat? = nil var dragHeight: CGFloat? = nil var popupPadding: EdgeInsets = .init() - var cornerRadius: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] private var dismissTimer: PopupActionScheduler? = nil private var _body: AnyView diff --git a/Sources/Internal/UI/PopupCentreStackView.swift b/Sources/Internal/UI/PopupCentreStackView.swift index 8c9f9518ec..c0bf8b1dec 100644 --- a/Sources/Internal/UI/PopupCentreStackView.swift +++ b/Sources/Internal/UI/PopupCentreStackView.swift @@ -34,7 +34,7 @@ private extension PopupCentreStackView { .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopupHeight) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupHeight) - .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: popup.cornerRadius) + .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.activePopupCornerRadius) .opacity(viewModel.calculateOpacity(for: popup)) .focusSection_tvOS() .padding(popup.popupPadding) diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index 17e0959aa3..3920876e34 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -34,7 +34,7 @@ private extension PopupVerticalStackView { .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) - .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: popup.cornerRadius) + .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: viewModel.activePopupCornerRadius) .offset(y: viewModel.calculateOffsetY(for: popup)) .scaleEffect(x: viewModel.calculateScaleX(for: popup)) .focusSection_tvOS() diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index dad21e8890..52af05f44f 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -21,6 +21,7 @@ enum VM {} // MARK: Subclass Attributes var activePopupHeight: CGFloat? = nil + var activePopupCornerRadius: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] var screen: Screen = .init() var isKeyboardActive: Bool = false @@ -47,6 +48,7 @@ extension ViewModel { func updatePopupsValue(_ newPopups: [AnyPopup]) async { popups = await filterPopups(newPopups) activePopupHeight = await calculateHeightForActivePopup() + activePopupCornerRadius = await calculateCornerRadius() withAnimation(.transition) { objectWillChange.send() } } @@ -64,7 +66,6 @@ extension ViewModel { var newPopup = popup newPopup.popupPadding = await calculatePopupPadding() newPopup.height = await calculatePopupHeight(heightCandidate, newPopup) - newPopup.cornerRadius = await calculateCornerRadius() await updatePopupAction(newPopup) } From 5bfc70153767557eaa2cc5c01769d8a9c36bc9ff Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 16:57:52 +0100 Subject: [PATCH 135/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 1 - Sources/Internal/UI/PopupCentreStackView.swift | 2 +- Sources/Internal/UI/PopupVerticalStackView.swift | 4 ++-- .../Internal/View Models/ViewModel+VerticalStack.swift | 9 +++++---- Sources/Internal/View Models/ViewModel.swift | 4 +++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 70c2ed645d..f8ee602532 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -16,7 +16,6 @@ struct AnyPopup: Popup { private(set) var config: AnyPopupConfig var height: CGFloat? = nil var dragHeight: CGFloat? = nil - var popupPadding: EdgeInsets = .init() private var dismissTimer: PopupActionScheduler? = nil private var _body: AnyView diff --git a/Sources/Internal/UI/PopupCentreStackView.swift b/Sources/Internal/UI/PopupCentreStackView.swift index c0bf8b1dec..8cc15a86b5 100644 --- a/Sources/Internal/UI/PopupCentreStackView.swift +++ b/Sources/Internal/UI/PopupCentreStackView.swift @@ -37,7 +37,7 @@ private extension PopupCentreStackView { .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.activePopupCornerRadius) .opacity(viewModel.calculateOpacity(for: popup)) .focusSection_tvOS() - .padding(popup.popupPadding) + .padding(viewModel.activePopupPadding) .compositingGroup() } } diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index 3920876e34..26049a4374 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -29,7 +29,7 @@ private extension PopupVerticalStackView { private extension PopupVerticalStackView { func createPopup(_ popup: AnyPopup) -> some View { popup.body - .padding(viewModel.calculateBodyPadding(for: popup)) + .padding(viewModel.activePopupBodyPadding) .fixedSize(horizontal: false, vertical: viewModel.calculateVerticalFixedSize(for: popup)) .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) @@ -38,7 +38,7 @@ private extension PopupVerticalStackView { .offset(y: viewModel.calculateOffsetY(for: popup)) .scaleEffect(x: viewModel.calculateScaleX(for: popup)) .focusSection_tvOS() - .padding(popup.popupPadding) + .padding(viewModel.activePopupPadding) .transition(transition) .zIndex(viewModel.calculateZIndex()) .compositingGroup() diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 30aace8bf3..d27af59e75 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -21,6 +21,7 @@ extension VM { class VerticalStack: ViewModel { override func calculatePopupPadding() async -> EdgeInsets { await _calculatePopupPadding() } override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } override func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { await _calculateCornerRadius() } + override func calculateBodyPadding() async -> EdgeInsets { await _calculateBodyPadding() } }} @@ -116,8 +117,8 @@ private extension VM.VerticalStack { } // MARK: Body Padding -extension VM.VerticalStack { - func calculateBodyPadding(for popup: AnyPopup) -> EdgeInsets { .init( +private extension VM.VerticalStack { + nonisolated func _calculateBodyPadding() async -> EdgeInsets { guard let popup = await popups.last else { return .init() }; return await .init( top: calculateTopBodyPadding(popup: popup), leading: calculateLeadingBodyPadding(popup: popup), bottom: calculateBottomBodyPadding(popup: popup), @@ -225,13 +226,13 @@ private extension VM.VerticalStack { case .fullscreen: 0 }} nonisolated func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat, _ activePopup: AnyPopup) async -> CGFloat { switch alignment { - case .top: activePopup.popupPadding.top != 0 ? cornerRadiusValue : 0 + case .top: await activePopupPadding.top != 0 ? cornerRadiusValue : 0 case .bottom: cornerRadiusValue case .centre: fatalError() }} nonisolated func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat, _ activePopup: AnyPopup) async -> CGFloat { switch alignment { case .top: cornerRadiusValue - case .bottom: activePopup.popupPadding.bottom != 0 ? cornerRadiusValue : 0 + case .bottom: await activePopupPadding.bottom != 0 ? cornerRadiusValue : 0 case .centre: fatalError() }} } diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 52af05f44f..5239b6c33d 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -22,6 +22,8 @@ enum VM {} // MARK: Subclass Attributes var activePopupHeight: CGFloat? = nil var activePopupCornerRadius: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] + var activePopupBodyPadding: EdgeInsets = .init() + var activePopupPadding: EdgeInsets = .init() var screen: Screen = .init() var isKeyboardActive: Bool = false @@ -30,6 +32,7 @@ enum VM {} nonisolated func calculatePopupPadding() async -> EdgeInsets { fatalError() } nonisolated func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { fatalError() } nonisolated func calculateHeightForActivePopup() async -> CGFloat? { fatalError() } + nonisolated func calculateBodyPadding() async -> EdgeInsets { fatalError() } // MARK: Initializer init(_ config: Config.Type) { self.alignment = .init(Config.self) } @@ -64,7 +67,6 @@ extension ViewModel { } func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { var newPopup = popup - newPopup.popupPadding = await calculatePopupPadding() newPopup.height = await calculatePopupHeight(heightCandidate, newPopup) await updatePopupAction(newPopup) From 4722677000216c8076dd5265ff422b570bca0c7e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 17:02:38 +0100 Subject: [PATCH 136/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index d27af59e75..7931c3dd2e 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -126,39 +126,39 @@ private extension VM.VerticalStack { )} } private extension VM.VerticalStack { - func calculateTopBodyPadding(popup: AnyPopup) -> CGFloat { + nonisolated func calculateTopBodyPadding(popup: AnyPopup) async -> CGFloat { if popup.config.ignoredSafeAreaEdges.contains(.top) { return 0 } return switch alignment { - case .top: calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupPadding: popup.popupPadding.top) - case .bottom: calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight ?? 0, safeArea: screen.safeArea.top) + case .top: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupPadding: activePopupPadding.top) + case .bottom: await calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight ?? 0, safeArea: screen.safeArea.top) case .centre: fatalError() } } - func calculateBottomBodyPadding(popup: AnyPopup) -> CGFloat { + func calculateBottomBodyPadding(popup: AnyPopup) async -> CGFloat { if popup.config.ignoredSafeAreaEdges.contains(.bottom) && !isKeyboardActive { return 0 } return switch alignment { - case .top: calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight ?? 0, safeArea: screen.safeArea.bottom) - case .bottom: calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupPadding: popup.popupPadding.bottom) + case .top: await calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight ?? 0, safeArea: screen.safeArea.bottom) + case .bottom: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupPadding: activePopupPadding.bottom) case .centre: fatalError() } } - func calculateLeadingBodyPadding(popup: AnyPopup) -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.leading) { + nonisolated func calculateLeadingBodyPadding(popup: AnyPopup) async -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.leading) { case true: 0 - case false: screen.safeArea.leading + case false: await screen.safeArea.leading }} - func calculateTrailingBodyPadding(popup: AnyPopup) -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.trailing) { + nonisolated func calculateTrailingBodyPadding(popup: AnyPopup) async -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.trailing) { case true: 0 - case false: screen.safeArea.trailing + case false: await screen.safeArea.trailing }} } private extension VM.VerticalStack { - func calculateVerticalPaddingCounterEdge(popupHeight: CGFloat, safeArea: CGFloat) -> CGFloat { - let paddingValueCandidate = safeArea + popupHeight - screen.height + nonisolated func calculateVerticalPaddingCounterEdge(popupHeight: CGFloat, safeArea: CGFloat) async -> CGFloat { + let paddingValueCandidate = await safeArea + popupHeight - screen.height return max(paddingValueCandidate, 0) } - func calculateVerticalPaddingAdhereEdge(safeAreaHeight: CGFloat, popupPadding: CGFloat) -> CGFloat { + nonisolated func calculateVerticalPaddingAdhereEdge(safeAreaHeight: CGFloat, popupPadding: CGFloat) async -> CGFloat { let paddingValueCandidate = safeAreaHeight - popupPadding return max(paddingValueCandidate, 0) } From 7a863652a191deddb6bc16d1d24ddf918a5fa2d3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 17:11:19 +0100 Subject: [PATCH 137/407] 1 --- Sources/Internal/UI/PopupView.swift | 4 ++-- .../Internal/View Models/ViewModel+CentreStack.swift | 6 ++++++ Sources/Internal/View Models/ViewModel.swift | 11 +++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index bac312de25..8d7d66be7f 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -86,7 +86,7 @@ private extension PopupView { await updateViewModels { $0.setup(updatePopupAction: updatePopup, closePopupAction: closePopup) } }} func onScreenChange(_ reader: GeometryProxy) { Task { @MainActor in - await updateViewModels { $0.updateScreenValue(.init(reader)) } + await updateViewModels { await $0.updateScreenValue(.init(reader)) } }} func onPopupsHeightChange(_ p: Any) { Task { @MainActor in await updateViewModels { await $0.updatePopupsValue(popupManager.stack) } @@ -101,7 +101,7 @@ private extension PopupView { newStack.last?.onFocus() } func onKeyboardStateChange(_ isKeyboardActive: Bool) { Task { @MainActor in - await updateViewModels { $0.updateKeyboardValue(isKeyboardActive) } + await updateViewModels { await $0.updateKeyboardValue(isKeyboardActive) } }} func onTap() { if tapOutsideClosesPopup { popupManager.stack(.removeLastPopup) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 5fe38c9d93..19a2ea85cd 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -17,6 +17,7 @@ extension VM { class CentreStack: ViewModel { override func calculatePopupPadding() async -> EdgeInsets { await _calculatePopupPadding() } override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } override func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { await _calculateCornerRadius() } + override func calculateBodyPadding() async -> EdgeInsets { await _calculateBodyPadding() } }} @@ -66,6 +67,11 @@ private extension VM.CentreStack { } } +// MARK: Body Padding +private extension VM.CentreStack { + nonisolated func _calculateBodyPadding() async -> EdgeInsets { .init() } +} + // MARK: Corner Radius private extension VM.CentreStack { nonisolated func _calculateCornerRadius() async -> [PopupAlignment : CGFloat] { await [ diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 5239b6c33d..f43bb14cb0 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -50,18 +50,25 @@ extension ViewModel { extension ViewModel { func updatePopupsValue(_ newPopups: [AnyPopup]) async { popups = await filterPopups(newPopups) + + activePopupPadding = await calculatePopupPadding() + activePopupBodyPadding = await calculateBodyPadding() activePopupHeight = await calculateHeightForActivePopup() activePopupCornerRadius = await calculateCornerRadius() withAnimation(.transition) { objectWillChange.send() } } - func updateScreenValue(_ newScreen: Screen) { + func updateScreenValue(_ newScreen: Screen) async { screen = newScreen + activePopupPadding = await calculatePopupPadding() + activePopupBodyPadding = await calculateBodyPadding() withAnimation(.transition) { objectWillChange.send() } } - func updateKeyboardValue(_ isActive: Bool) { + func updateKeyboardValue(_ isActive: Bool) async { isKeyboardActive = isActive + activePopupPadding = await calculatePopupPadding() + activePopupBodyPadding = await calculateBodyPadding() withAnimation(.transition) { objectWillChange.send() } } From 161aecdade8bf353787af096ec0c243ec8d872cb Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 17:17:36 +0100 Subject: [PATCH 138/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 7931c3dd2e..b5eab3d614 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -403,8 +403,8 @@ private extension VM.VerticalStack { let currentPopupHeight = activePopupHeight + currentDragHeight return currentPopupHeight } - func calculatePopupTargetHeightsFromDragDetents(_ activePopupHeight: CGFloat) -> [CGFloat] { - getActivePopupConfig().dragDetents + func calculatePopupTargetHeightsFromDragDetents(_ activePopupHeight: CGFloat) -> [CGFloat] { guard let dragDetents = popups.last?.config.dragDetents else { return [activePopupHeight] }; return + dragDetents .map { switch $0 { case .height(let targetHeight): min(targetHeight, calculateLargeScreenHeight()) case .fraction(let fraction): min(fraction * activePopupHeight, calculateLargeScreenHeight()) From 47a8aaa14ee7407ccbd7e5346a686f4b3bc1c506 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 17:25:29 +0100 Subject: [PATCH 139/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 19a2ea85cd..ae77782c61 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -60,10 +60,10 @@ private extension VM.CentreStack { return abs(min(paddingCandidate, 0)) } func calculateLeadingPopupPadding() -> CGFloat { - getActivePopupConfig().popupPadding.leading + popups.last?.config.popupPadding.leading ?? 0 } func calculateTrailingPopupPadding() -> CGFloat { - getActivePopupConfig().popupPadding.trailing + popups.last?.config.popupPadding.trailing ?? 0 } } @@ -75,8 +75,8 @@ private extension VM.CentreStack { // MARK: Corner Radius private extension VM.CentreStack { nonisolated func _calculateCornerRadius() async -> [PopupAlignment : CGFloat] { await [ - .top: getActivePopupConfig().cornerRadius, - .bottom: getActivePopupConfig().cornerRadius + .top: popups.last?.config.cornerRadius ?? 0, + .bottom: popups.last?.config.cornerRadius ?? 0 ]} } From da20fb99de03278aa68ebfe6ac47f507c0e6d544 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 17:25:50 +0100 Subject: [PATCH 140/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 4 ++-- Sources/Internal/View Models/ViewModel.swift | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index b5eab3d614..c9d12972e6 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -323,7 +323,7 @@ extension VM.VerticalStack { var maxStackOverlayFactor: CGFloat { 0.48 } var stackOffset: CGFloat { GlobalConfigContainer.vertical.isStackingEnabled ? 8 : 0 } var dragThreshold: CGFloat { GlobalConfigContainer.vertical.dragThreshold } - var dragGestureEnabled: Bool { getActivePopupConfig().isDragGestureEnabled } + var dragGestureEnabled: Bool { popups.last?.config.isDragGestureEnabled ?? false } var dragTranslationThreshold: CGFloat { 8 } var minScaleProgressMultiplier: CGFloat { 0.7 } } @@ -342,7 +342,7 @@ extension VM.VerticalStack { }} } private extension VM.VerticalStack { - nonisolated func calculateGestureTranslation(_ value: CGFloat) async -> CGFloat { switch await getActivePopupConfig().dragDetents.isEmpty { + nonisolated func calculateGestureTranslation(_ value: CGFloat) async -> CGFloat { switch await popups.last?.config.dragDetents.isEmpty ?? true { case true: await calculateGestureTranslationWhenNoDragDetents(value) case false: await calculateGestureTranslationWhenDragDetents(value) }} diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index f43bb14cb0..cec8c52bae 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -84,10 +84,3 @@ private extension ViewModel { popups.filter { $0.config.alignment == alignment } } } - -// MARK: Helpers -extension ViewModel { - func getActivePopupConfig() -> AnyPopupConfig { - popups.last?.config ?? .init() - } -} From 9d837701077656bb45a221bec0f1fb4c68ff1a11 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 17:28:38 +0100 Subject: [PATCH 141/407] 1 --- Sources/Internal/Extensions/View+ReadHeight.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/Extensions/View+ReadHeight.swift b/Sources/Internal/Extensions/View+ReadHeight.swift index 28d10e980a..442bfe8d5e 100644 --- a/Sources/Internal/Extensions/View+ReadHeight.swift +++ b/Sources/Internal/Extensions/View+ReadHeight.swift @@ -15,7 +15,7 @@ extension View { func onHeightChange(perform action: @escaping (CGFloat) async -> ()) -> some View { background( GeometryReader { proxy in Task { @MainActor in - try await Task.sleep(nanoseconds: 10_000_000) + try await Task.sleep(nanoseconds: 100_000_000) await action(proxy.size.height) } return Color.clear From 9519459e7d432b47a68c3658f8ec2bf78496d441 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 18:33:34 +0100 Subject: [PATCH 142/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 6 ++++-- Sources/Internal/View Models/ViewModel.swift | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index c9d12972e6..f2e01f554a 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -436,9 +436,11 @@ private extension VM.VerticalStack { targetHeight - activePopupHeight } func updateDragHeight(_ targetDragHeight: CGFloat) async { if let activePopup = popups.last { - await updatePopupAction(activePopup.settingDragHeight(targetDragHeight)) + var newPopup = activePopup + newPopup.dragHeight = targetDragHeight + await updatePopupAction(newPopup) }} - func resetGestureTranslation() async { + nonisolated func resetGestureTranslation() async { await updateGestureTranslation(0) } func shouldDismissPopup() -> Bool { diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index cec8c52bae..06b40adb62 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -76,6 +76,7 @@ extension ViewModel { var newPopup = popup newPopup.height = await calculatePopupHeight(heightCandidate, newPopup) + guard newPopup.height != popup.height else { return } await updatePopupAction(newPopup) } } From 0668943b7935ad39d353a0703148d80bd291e80e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 19:31:54 +0100 Subject: [PATCH 143/407] 1 --- .../View Models/ViewModel+CentreStack.swift | 6 +++++ .../View Models/ViewModel+VerticalStack.swift | 26 +++---------------- Sources/Internal/View Models/ViewModel.swift | 13 ++++++++++ 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index ae77782c61..414ad26bc5 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -18,6 +18,7 @@ extension VM { class CentreStack: ViewModel { override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } override func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { await _calculateCornerRadius() } override func calculateBodyPadding() async -> EdgeInsets { await _calculateBodyPadding() } + override func calculateTranslationProgress() async -> CGFloat { await _calculateTranslationProgress() } }} @@ -94,6 +95,11 @@ extension VM.CentreStack { } } +// MARK: Translation Progress +private extension VM.CentreStack { + nonisolated func _calculateTranslationProgress() async -> CGFloat { 0 } +} + // MARK: - HELPERS diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index f2e01f554a..22abae26cb 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -12,37 +12,17 @@ import SwiftUI extension VM { class VerticalStack: ViewModel { - // MARK: Attributes - private(set) var gestureTranslation: CGFloat = 0 - private(set) var translationProgress: CGFloat = 0 - // MARK: Overridden Methods override func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _calculatePopupHeight(heightCandidate, popup) } override func calculatePopupPadding() async -> EdgeInsets { await _calculatePopupPadding() } override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } override func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { await _calculateCornerRadius() } override func calculateBodyPadding() async -> EdgeInsets { await _calculateBodyPadding() } + override func calculateTranslationProgress() async -> CGFloat { await _calculateTranslationProgress() } }} -// MARK: - SETUP & UPDATE - - - -// MARK: Update -extension VM.VerticalStack { - func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { - gestureTranslation = newGestureTranslation - translationProgress = await calculateTranslationProgress() - activePopupHeight = await calculateHeightForActivePopup() - - withAnimation(gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } - } -} - - - // MARK: - VIEW METHODS @@ -299,8 +279,8 @@ private extension VM.VerticalStack { } // MARK: Translation Progress -extension VM.VerticalStack { - nonisolated func calculateTranslationProgress() async -> CGFloat { guard let activePopupHeight = await popups.last?.height else { return 0 }; return switch alignment { +private extension VM.VerticalStack { + nonisolated func _calculateTranslationProgress() async -> CGFloat { guard let activePopupHeight = await popups.last?.height else { return 0 }; return switch alignment { case .top: await abs(min(gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight case .bottom: await max(gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight case .centre: fatalError() diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 06b40adb62..001eb314bc 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -20,6 +20,8 @@ enum VM {} private(set) var closePopupAction: ((AnyPopup) async -> ())! // MARK: Subclass Attributes + var gestureTranslation: CGFloat = 0 + var translationProgress: CGFloat = 0 var activePopupHeight: CGFloat? = nil var activePopupCornerRadius: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] var activePopupBodyPadding: EdgeInsets = .init() @@ -33,6 +35,7 @@ enum VM {} nonisolated func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { fatalError() } nonisolated func calculateHeightForActivePopup() async -> CGFloat? { fatalError() } nonisolated func calculateBodyPadding() async -> EdgeInsets { fatalError() } + nonisolated func calculateTranslationProgress() async -> CGFloat { fatalError()} // MARK: Initializer init(_ config: Config.Type) { self.alignment = .init(Config.self) } @@ -73,12 +76,22 @@ extension ViewModel { withAnimation(.transition) { objectWillChange.send() } } func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { + guard gestureTranslation == 0 else { return } + + var newPopup = popup newPopup.height = await calculatePopupHeight(heightCandidate, newPopup) guard newPopup.height != popup.height else { return } await updatePopupAction(newPopup) } + func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { + gestureTranslation = newGestureTranslation + translationProgress = await calculateTranslationProgress() + activePopupHeight = await calculateHeightForActivePopup() + + withAnimation(gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } + } } private extension ViewModel { nonisolated func filterPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { From bf702a7e23125a5b23ed1822c6eacbcec7925ede Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 20:26:53 +0100 Subject: [PATCH 144/407] 1 --- Sources/Internal/UI/PopupVerticalStackView.swift | 2 +- Sources/Internal/View Models/ViewModel+CentreStack.swift | 1 + Sources/Internal/View Models/ViewModel+VerticalStack.swift | 5 +++-- Sources/Internal/View Models/ViewModel.swift | 5 ++++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index 26049a4374..4d5858ddc3 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -30,7 +30,7 @@ private extension PopupVerticalStackView { func createPopup(_ popup: AnyPopup) -> some View { popup.body .padding(viewModel.activePopupBodyPadding) - .fixedSize(horizontal: false, vertical: viewModel.calculateVerticalFixedSize(for: popup)) + .fixedSize(horizontal: false, vertical: viewModel.activePopupVerticalFixedSize) .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 414ad26bc5..0562d5bad7 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -19,6 +19,7 @@ extension VM { class CentreStack: ViewModel { override func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { await _calculateCornerRadius() } override func calculateBodyPadding() async -> EdgeInsets { await _calculateBodyPadding() } override func calculateTranslationProgress() async -> CGFloat { await _calculateTranslationProgress() } + override func calculateVerticalFixedSize() async -> Bool { false } }} diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 22abae26cb..d90cde106f 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -19,6 +19,7 @@ extension VM { class VerticalStack: ViewModel { override func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { await _calculateCornerRadius() } override func calculateBodyPadding() async -> EdgeInsets { await _calculateBodyPadding() } override func calculateTranslationProgress() async -> CGFloat { await _calculateTranslationProgress() } + override func calculateVerticalFixedSize() async -> Bool { await _calculateVerticalFixedSize() } }} @@ -219,9 +220,9 @@ private extension VM.VerticalStack { // MARK: Fixed Size extension VM.VerticalStack { - func calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { switch popup.config.heightMode { + nonisolated func _calculateVerticalFixedSize() async -> Bool { guard let popup = await popups.last else { return true }; return switch popup.config.heightMode { case .fullscreen, .large: false - case .auto: activePopupHeight != calculateLargeScreenHeight() + case .auto: await activePopupHeight != calculateLargeScreenHeight() }} } diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 001eb314bc..b653f6bda0 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -26,6 +26,7 @@ enum VM {} var activePopupCornerRadius: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] var activePopupBodyPadding: EdgeInsets = .init() var activePopupPadding: EdgeInsets = .init() + var activePopupVerticalFixedSize: Bool = true var screen: Screen = .init() var isKeyboardActive: Bool = false @@ -35,7 +36,8 @@ enum VM {} nonisolated func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { fatalError() } nonisolated func calculateHeightForActivePopup() async -> CGFloat? { fatalError() } nonisolated func calculateBodyPadding() async -> EdgeInsets { fatalError() } - nonisolated func calculateTranslationProgress() async -> CGFloat { fatalError()} + nonisolated func calculateTranslationProgress() async -> CGFloat { fatalError() } + nonisolated func calculateVerticalFixedSize() async -> Bool { fatalError() } // MARK: Initializer init(_ config: Config.Type) { self.alignment = .init(Config.self) } @@ -58,6 +60,7 @@ extension ViewModel { activePopupBodyPadding = await calculateBodyPadding() activePopupHeight = await calculateHeightForActivePopup() activePopupCornerRadius = await calculateCornerRadius() + activePopupVerticalFixedSize = await calculateVerticalFixedSize() withAnimation(.transition) { objectWillChange.send() } } From d3dc7cb806e93ffe833930d9fa631be9d10d253f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 20:32:48 +0100 Subject: [PATCH 145/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index b653f6bda0..c6ad268ea8 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -57,8 +57,8 @@ extension ViewModel { popups = await filterPopups(newPopups) activePopupPadding = await calculatePopupPadding() - activePopupBodyPadding = await calculateBodyPadding() activePopupHeight = await calculateHeightForActivePopup() + activePopupBodyPadding = await calculateBodyPadding() activePopupCornerRadius = await calculateCornerRadius() activePopupVerticalFixedSize = await calculateVerticalFixedSize() From 4e5bf8c2ce8af1cb01cd4e6f88887e356428bab7 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 20:36:09 +0100 Subject: [PATCH 146/407] 1 --- Sources/Internal/Extensions/View+ReadHeight.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/Extensions/View+ReadHeight.swift b/Sources/Internal/Extensions/View+ReadHeight.swift index 442bfe8d5e..28d10e980a 100644 --- a/Sources/Internal/Extensions/View+ReadHeight.swift +++ b/Sources/Internal/Extensions/View+ReadHeight.swift @@ -15,7 +15,7 @@ extension View { func onHeightChange(perform action: @escaping (CGFloat) async -> ()) -> some View { background( GeometryReader { proxy in Task { @MainActor in - try await Task.sleep(nanoseconds: 100_000_000) + try await Task.sleep(nanoseconds: 10_000_000) await action(proxy.size.height) } return Color.clear From 89eac4a842c55ec0ee13cfb6e77afa89e8025968 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 23:53:32 +0100 Subject: [PATCH 147/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index c6ad268ea8..7a0cfcc992 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -22,11 +22,7 @@ enum VM {} // MARK: Subclass Attributes var gestureTranslation: CGFloat = 0 var translationProgress: CGFloat = 0 - var activePopupHeight: CGFloat? = nil - var activePopupCornerRadius: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] - var activePopupBodyPadding: EdgeInsets = .init() - var activePopupPadding: EdgeInsets = .init() - var activePopupVerticalFixedSize: Bool = true + var activePopup: ActivePopup = .init() var screen: Screen = .init() var isKeyboardActive: Bool = false @@ -66,15 +62,15 @@ extension ViewModel { } func updateScreenValue(_ newScreen: Screen) async { screen = newScreen - activePopupPadding = await calculatePopupPadding() - activePopupBodyPadding = await calculateBodyPadding() + activePopup.outerPadding = await calculatePopupPadding() + activePopup.innerPadding = await calculateBodyPadding() withAnimation(.transition) { objectWillChange.send() } } func updateKeyboardValue(_ isActive: Bool) async { isKeyboardActive = isActive - activePopupPadding = await calculatePopupPadding() - activePopupBodyPadding = await calculateBodyPadding() + activePopup.outerPadding = await calculatePopupPadding() + activePopup.innerPadding = await calculateBodyPadding() withAnimation(.transition) { objectWillChange.send() } } From be8c4a40d7b9691a8393ed755cad4d586f1096b6 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 23:55:59 +0100 Subject: [PATCH 148/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 8 ++--- Sources/Internal/View Models/ViewModel.swift | 33 +++++++++++++++---- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index d90cde106f..517799b8b0 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -76,7 +76,7 @@ private extension VM.VerticalStack { private extension VM.VerticalStack { nonisolated func calculateVerticalPopupPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { let largeScreenHeight = await calculateLargeScreenHeight(), - activePopupHeight = await activePopupHeight ?? 0, + activePopupHeight = await activePopup.height ?? 0, priorityPopupPaddingValue = await calculatePriorityPopupPaddingValue(for: edge, activePopupConfig: activePopupConfig), remainingHeight = largeScreenHeight - activePopupHeight - priorityPopupPaddingValue @@ -120,8 +120,8 @@ private extension VM.VerticalStack { if popup.config.ignoredSafeAreaEdges.contains(.bottom) && !isKeyboardActive { return 0 } return switch alignment { - case .top: await calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight ?? 0, safeArea: screen.safeArea.bottom) - case .bottom: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupPadding: activePopupPadding.bottom) + case .top: await calculateVerticalPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.bottom) + case .bottom: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupPadding: activePopup.outerPadding.bottom) case .centre: fatalError() } } @@ -222,7 +222,7 @@ private extension VM.VerticalStack { extension VM.VerticalStack { nonisolated func _calculateVerticalFixedSize() async -> Bool { guard let popup = await popups.last else { return true }; return switch popup.config.heightMode { case .fullscreen, .large: false - case .auto: await activePopupHeight != calculateLargeScreenHeight() + case .auto: await activePopup.height != calculateLargeScreenHeight() }} } diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 7a0cfcc992..f5896c73e5 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -52,11 +52,11 @@ extension ViewModel { func updatePopupsValue(_ newPopups: [AnyPopup]) async { popups = await filterPopups(newPopups) - activePopupPadding = await calculatePopupPadding() - activePopupHeight = await calculateHeightForActivePopup() - activePopupBodyPadding = await calculateBodyPadding() - activePopupCornerRadius = await calculateCornerRadius() - activePopupVerticalFixedSize = await calculateVerticalFixedSize() + activePopup.outerPadding = await calculatePopupPadding() + activePopup.height = await calculateHeightForActivePopup() + activePopup.innerPadding = await calculateBodyPadding() + activePopup.cornerRadius = await calculateCornerRadius() + activePopup.verticalFixedSize = await calculateVerticalFixedSize() withAnimation(.transition) { objectWillChange.send() } } @@ -87,7 +87,7 @@ extension ViewModel { func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { gestureTranslation = newGestureTranslation translationProgress = await calculateTranslationProgress() - activePopupHeight = await calculateHeightForActivePopup() + activePopup.height = await calculateHeightForActivePopup() withAnimation(gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } } @@ -97,3 +97,24 @@ private extension ViewModel { popups.filter { $0.config.alignment == alignment } } } + + + +protocol VV: ObservableObject { + var alignment: PopupAlignment { get } + var popups: [AnyPopup] { get } + var updatePopupAction: ((AnyPopup) async -> ())! { get set } + var closePopupAction: ((AnyPopup) async -> ())! { get set } +} + + + + + +@MainActor class ActivePopup { + var height: CGFloat? = nil + var innerPadding: EdgeInsets = .init() + var outerPadding: EdgeInsets = .init() + var cornerRadius: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] + var verticalFixedSize: Bool = true +} From 94000f83fa51e8ce879c71f8e03afa9ebba05322 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 23:56:32 +0100 Subject: [PATCH 149/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 4 ++-- .../Internal/View Models/ViewModel+VerticalStack.swift | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 0562d5bad7..ca11d7cf93 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -53,7 +53,7 @@ private extension VM.CentreStack { } private extension VM.CentreStack { func calculateVerticalPopupPadding(for edge: PopupAlignment) -> CGFloat { - guard let activePopupHeight, + guard let activePopupHeight = activePopup.height, isKeyboardActive && edge == .bottom else { return 0 } @@ -92,7 +92,7 @@ extension VM.CentreStack { // MARK: Fixed Size extension VM.CentreStack { func calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { - activePopupHeight != calculateLargeScreenHeight() + activePopup.height != calculateLargeScreenHeight() } } diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 517799b8b0..586f987161 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -111,8 +111,8 @@ private extension VM.VerticalStack { if popup.config.ignoredSafeAreaEdges.contains(.top) { return 0 } return switch alignment { - case .top: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupPadding: activePopupPadding.top) - case .bottom: await calculateVerticalPaddingCounterEdge(popupHeight: activePopupHeight ?? 0, safeArea: screen.safeArea.top) + case .top: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupPadding: activePopup.outerPadding.top) + case .bottom: await calculateVerticalPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.top) case .centre: fatalError() } } @@ -196,8 +196,8 @@ private extension VM.VerticalStack { let cornerRadiusValue = await calculateCornerRadiusValue(activePopup) return await [ - .top: calculateTopCornerRadius(cornerRadiusValue, activePopup), - .bottom: calculateBottomCornerRadius(cornerRadiusValue, activePopup) + .top: calculateTopCornerRadius(cornerRadiusValue), + .bottom: calculateBottomCornerRadius(cornerRadiusValue) ] } } From 7d8f1457ee778861d1ae432ca0c9caa87bf0c4a4 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 23:57:21 +0100 Subject: [PATCH 150/407] 1 --- Sources/Internal/UI/PopupCentreStackView.swift | 8 ++++---- .../Internal/View Models/ViewModel+VerticalStack.swift | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Internal/UI/PopupCentreStackView.swift b/Sources/Internal/UI/PopupCentreStackView.swift index 8cc15a86b5..013d1f7ab4 100644 --- a/Sources/Internal/UI/PopupCentreStackView.swift +++ b/Sources/Internal/UI/PopupCentreStackView.swift @@ -32,12 +32,12 @@ private extension PopupCentreStackView { popup.body .fixedSize(horizontal: false, vertical: viewModel.calculateVerticalFixedSize(for: popup)) .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } - .frame(height: viewModel.activePopupHeight) - .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupHeight) - .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.activePopupCornerRadius) + .frame(height: viewModel.activePopup.height) + .frame(maxWidth: .infinity, maxHeight: viewModel.activePopup.height) + .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.activePopup.cornerRadius) .opacity(viewModel.calculateOpacity(for: popup)) .focusSection_tvOS() - .padding(viewModel.activePopupPadding) + .padding(viewModel.activePopup.outerPadding) .compositingGroup() } } diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 586f987161..9b78165dcd 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -206,14 +206,14 @@ private extension VM.VerticalStack { case .auto, .large: activePopup.config.cornerRadius case .fullscreen: 0 }} - nonisolated func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat, _ activePopup: AnyPopup) async -> CGFloat { switch alignment { - case .top: await activePopupPadding.top != 0 ? cornerRadiusValue : 0 + nonisolated func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat) async -> CGFloat { switch alignment { + case .top: await activePopup.outerPadding.top != 0 ? cornerRadiusValue : 0 case .bottom: cornerRadiusValue case .centre: fatalError() }} - nonisolated func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat, _ activePopup: AnyPopup) async -> CGFloat { switch alignment { + nonisolated func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat) async -> CGFloat { switch alignment { case .top: cornerRadiusValue - case .bottom: await activePopupPadding.bottom != 0 ? cornerRadiusValue : 0 + case .bottom: await activePopup.outerPadding.bottom != 0 ? cornerRadiusValue : 0 case .centre: fatalError() }} } From dbc5391467867e534dbc0140198dc230a9a53409 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 23:57:40 +0100 Subject: [PATCH 151/407] 1 --- Sources/Internal/UI/PopupVerticalStackView.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index 4d5858ddc3..57e7a3ac4b 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -29,16 +29,16 @@ private extension PopupVerticalStackView { private extension PopupVerticalStackView { func createPopup(_ popup: AnyPopup) -> some View { popup.body - .padding(viewModel.activePopupBodyPadding) - .fixedSize(horizontal: false, vertical: viewModel.activePopupVerticalFixedSize) + .padding(viewModel.activePopup.innerPadding) + .fixedSize(horizontal: false, vertical: viewModel.activePopup.verticalFixedSize) .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } - .frame(height: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) - .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupHeight, alignment: (!viewModel.alignment).toAlignment()) - .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: viewModel.activePopupCornerRadius) + .frame(height: viewModel.activePopup.height, alignment: (!viewModel.alignment).toAlignment()) + .frame(maxWidth: .infinity, maxHeight: viewModel.activePopup.height, alignment: (!viewModel.alignment).toAlignment()) + .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: viewModel.activePopup.cornerRadius) .offset(y: viewModel.calculateOffsetY(for: popup)) .scaleEffect(x: viewModel.calculateScaleX(for: popup)) .focusSection_tvOS() - .padding(viewModel.activePopupPadding) + .padding(viewModel.activePopup.outerPadding) .transition(transition) .zIndex(viewModel.calculateZIndex()) .compositingGroup() From 957bb5f3dbb5878ee622b5c6041238ce4f0db83c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 8 Nov 2024 23:58:37 +0100 Subject: [PATCH 152/407] 1 --- Sources/Internal/UI/PopupCentreStackView.swift | 2 +- Sources/Internal/UI/PopupVerticalStackView.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/UI/PopupCentreStackView.swift b/Sources/Internal/UI/PopupCentreStackView.swift index 013d1f7ab4..756ea3fd37 100644 --- a/Sources/Internal/UI/PopupCentreStackView.swift +++ b/Sources/Internal/UI/PopupCentreStackView.swift @@ -34,7 +34,7 @@ private extension PopupCentreStackView { .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopup.height) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopup.height) - .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.activePopup.cornerRadius) + .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.activePopup.corners) .opacity(viewModel.calculateOpacity(for: popup)) .focusSection_tvOS() .padding(viewModel.activePopup.outerPadding) diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index 57e7a3ac4b..f7aa8f6a5e 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -34,7 +34,7 @@ private extension PopupVerticalStackView { .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopup.height, alignment: (!viewModel.alignment).toAlignment()) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopup.height, alignment: (!viewModel.alignment).toAlignment()) - .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: viewModel.activePopup.cornerRadius) + .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: viewModel.activePopup.corners) .offset(y: viewModel.calculateOffsetY(for: popup)) .scaleEffect(x: viewModel.calculateScaleX(for: popup)) .focusSection_tvOS() diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index f5896c73e5..ceccf7399e 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -55,7 +55,7 @@ extension ViewModel { activePopup.outerPadding = await calculatePopupPadding() activePopup.height = await calculateHeightForActivePopup() activePopup.innerPadding = await calculateBodyPadding() - activePopup.cornerRadius = await calculateCornerRadius() + activePopup.corners = await calculateCornerRadius() activePopup.verticalFixedSize = await calculateVerticalFixedSize() withAnimation(.transition) { objectWillChange.send() } @@ -115,6 +115,6 @@ protocol VV: ObservableObject { var height: CGFloat? = nil var innerPadding: EdgeInsets = .init() var outerPadding: EdgeInsets = .init() - var cornerRadius: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] + var corners: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] var verticalFixedSize: Bool = true } From 741537435ae46e9d4f1554113e373222bda4d4a0 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 9 Nov 2024 00:18:40 +0100 Subject: [PATCH 153/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 2 +- .../Internal/View Models/ViewModel+VerticalStack.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index ca11d7cf93..ca81ff50ba 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -54,7 +54,7 @@ private extension VM.CentreStack { private extension VM.CentreStack { func calculateVerticalPopupPadding(for edge: PopupAlignment) -> CGFloat { guard let activePopupHeight = activePopup.height, - isKeyboardActive && edge == .bottom + screen.isKeyboardActive && edge == .bottom else { return 0 } let remainingHeight = screen.height - activePopupHeight diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 9b78165dcd..460f8763b8 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -117,7 +117,7 @@ private extension VM.VerticalStack { } } func calculateBottomBodyPadding(popup: AnyPopup) async -> CGFloat { - if popup.config.ignoredSafeAreaEdges.contains(.bottom) && !isKeyboardActive { return 0 } + if popup.config.ignoredSafeAreaEdges.contains(.bottom) && !screen.isKeyboardActive { return 0 } return switch alignment { case .top: await calculateVerticalPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.bottom) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index ceccf7399e..015213670e 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -24,7 +24,6 @@ enum VM {} var translationProgress: CGFloat = 0 var activePopup: ActivePopup = .init() var screen: Screen = .init() - var isKeyboardActive: Bool = false // MARK: Methods to Override nonisolated func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { fatalError() } @@ -68,7 +67,7 @@ extension ViewModel { withAnimation(.transition) { objectWillChange.send() } } func updateKeyboardValue(_ isActive: Bool) async { - isKeyboardActive = isActive + screen.isKeyboardActive = isActive activePopup.outerPadding = await calculatePopupPadding() activePopup.innerPadding = await calculateBodyPadding() @@ -105,6 +104,11 @@ protocol VV: ObservableObject { var popups: [AnyPopup] { get } var updatePopupAction: ((AnyPopup) async -> ())! { get set } var closePopupAction: ((AnyPopup) async -> ())! { get set } + + var gestureTranslation: CGFloat { get set } + var translationProgress: CGFloat { get set } + var activePopup: ActivePopup { get set } + var screen: Screen { get set } } From 76551aa483bd2a9c5329372b704e7c1aba2e666b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 9 Nov 2024 00:24:50 +0100 Subject: [PATCH 154/407] 1 --- Sources/Internal/Models/Screen.swift | 16 +++++++++++----- Sources/Internal/UI/PopupView.swift | 4 ++-- Sources/Internal/View Models/ViewModel.swift | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Sources/Internal/Models/Screen.swift b/Sources/Internal/Models/Screen.swift index 5259ed7c99..b2e339ac90 100644 --- a/Sources/Internal/Models/Screen.swift +++ b/Sources/Internal/Models/Screen.swift @@ -12,16 +12,22 @@ import SwiftUI struct Screen { - let height: CGFloat - let safeArea: EdgeInsets + var height: CGFloat + var safeArea: EdgeInsets + var isKeyboardActive: Bool init(height: CGFloat = .zero, safeArea: EdgeInsets = .init()) { self.height = height self.safeArea = safeArea + self.isKeyboardActive = false } - init(_ reader: GeometryProxy) { - self.height = reader.size.height + reader.safeAreaInsets.top + reader.safeAreaInsets.bottom - self.safeArea = reader.safeAreaInsets +} + +// MARK: Update +extension Screen { + mutating func update(_ screenReader: GeometryProxy) { + self.height = screenReader.size.height + screenReader.safeAreaInsets.top + screenReader.safeAreaInsets.bottom + self.safeArea = screenReader.safeAreaInsets } } diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 8d7d66be7f..6d9609c3d6 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -85,8 +85,8 @@ private extension PopupView { func onAppear() { Task { @MainActor in await updateViewModels { $0.setup(updatePopupAction: updatePopup, closePopupAction: closePopup) } }} - func onScreenChange(_ reader: GeometryProxy) { Task { @MainActor in - await updateViewModels { await $0.updateScreenValue(.init(reader)) } + func onScreenChange(_ screenReader: GeometryProxy) { Task { @MainActor in + await updateViewModels { await $0.updateScreenValue(screenReader) } }} func onPopupsHeightChange(_ p: Any) { Task { @MainActor in await updateViewModels { await $0.updatePopupsValue(popupManager.stack) } diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 015213670e..d6a5f1b997 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -59,8 +59,8 @@ extension ViewModel { withAnimation(.transition) { objectWillChange.send() } } - func updateScreenValue(_ newScreen: Screen) async { - screen = newScreen + func updateScreenValue(_ screenReader: GeometryProxy) async { + screen.update(screenReader) activePopup.outerPadding = await calculatePopupPadding() activePopup.innerPadding = await calculateBodyPadding() From 8564c8ebba606d53a18cc31e387b10a1eb6d5b45 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 9 Nov 2024 00:33:26 +0100 Subject: [PATCH 155/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 30 ++++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index d6a5f1b997..c49329b101 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -99,9 +99,9 @@ private extension ViewModel { -protocol VV: ObservableObject { - var alignment: PopupAlignment { get } - var popups: [AnyPopup] { get } +protocol VV: ObservableObject { init() + var alignment: PopupAlignment { get set } + var popups: [AnyPopup] { get set } var updatePopupAction: ((AnyPopup) async -> ())! { get set } var closePopupAction: ((AnyPopup) async -> ())! { get set } @@ -109,6 +109,30 @@ protocol VV: ObservableObject { var translationProgress: CGFloat { get set } var activePopup: ActivePopup { get set } var screen: Screen { get set } + + init(_ config: Config.Type) + + + +} + + +extension VV { + func setup(updatePopupAction: @escaping (AnyPopup) async -> (), closePopupAction: @escaping (AnyPopup) async -> ()) { + self.updatePopupAction = updatePopupAction + self.closePopupAction = closePopupAction + } +} + +extension VV { + +} + + + + +extension VV { + init(_ config: Config.Type) { self.init(); self.alignment = .init(Config.self) } } From 4ea7d84143e4e34d60f7558a984f3ad89d2ec9af Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 9 Nov 2024 00:38:27 +0100 Subject: [PATCH 156/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index c49329b101..c901293b48 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -113,6 +113,15 @@ protocol VV: ObservableObject { init() init(_ config: Config.Type) + func calculateActivePopupHeight() async -> CGFloat? + func calculateActivePopupInnerPadding() async -> EdgeInsets + func calculateActivePopupOuterPadding() async -> EdgeInsets + func calculateActivePopupCorners() async -> [PopupAlignment: CGFloat] + func calculateActivePopupVerticalFixedSize() async -> Bool + + func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat + func calculateTranslationProgress() async -> CGFloat + } From d437c3e38a78062a4f05db86a5245d8a3ad906e9 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 9 Nov 2024 12:07:04 +0100 Subject: [PATCH 157/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 52 +++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index c901293b48..14ebf8072e 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -10,6 +10,7 @@ import SwiftUI +import Combine enum VM {} @MainActor class ViewModel: ObservableObject { @@ -125,7 +126,7 @@ protocol VV: ObservableObject { init() } - +// MARK: Setup extension VV { func setup(updatePopupAction: @escaping (AnyPopup) async -> (), closePopupAction: @escaping (AnyPopup) async -> ()) { self.updatePopupAction = updatePopupAction @@ -133,8 +134,55 @@ extension VV { } } -extension VV { +// MARK: Update +extension VV where Self.ObjectWillChangePublisher == ObservableObjectPublisher { + func updatePopupsValue(_ newPopups: [AnyPopup]) async { + popups = await filterPopups(newPopups) + + activePopup.outerPadding = await calculateActivePopupOuterPadding() + activePopup.height = await calculateActivePopupHeight() + activePopup.innerPadding = await calculateActivePopupInnerPadding() + activePopup.corners = await calculateActivePopupCorners() + activePopup.verticalFixedSize = await calculateActivePopupVerticalFixedSize() + + withAnimation(.transition) { objectWillChange.send() } + } + func updateScreenValue(_ screenReader: GeometryProxy) async { + screen.update(screenReader) + activePopup.outerPadding = await calculateActivePopupOuterPadding() + activePopup.innerPadding = await calculateActivePopupInnerPadding() + + withAnimation(.transition) { objectWillChange.send() } + } + func updateKeyboardValue(_ isActive: Bool) async { + screen.isKeyboardActive = isActive + activePopup.outerPadding = await calculateActivePopupOuterPadding() + activePopup.innerPadding = await calculateActivePopupInnerPadding() + + withAnimation(.transition) { objectWillChange.send() } + } + func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { + guard gestureTranslation == 0 else { return } + + + var newPopup = popup + newPopup.height = await calculatePopupHeight(heightCandidate, newPopup) + guard newPopup.height != popup.height else { return } + await updatePopupAction(newPopup) + } + func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { + gestureTranslation = newGestureTranslation + translationProgress = await calculateTranslationProgress() + activePopup.height = await calculateActivePopupHeight() + + withAnimation(gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } + } +} +private extension VV { + func filterPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { + popups.filter { $0.config.alignment == alignment } + } } From 0bd6f3ed29d8e487b449f265df1e1966e31a1acd Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 9 Nov 2024 12:12:55 +0100 Subject: [PATCH 158/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 14ebf8072e..bd0dc92c62 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -136,7 +136,7 @@ extension VV { // MARK: Update extension VV where Self.ObjectWillChangePublisher == ObservableObjectPublisher { - func updatePopupsValue(_ newPopups: [AnyPopup]) async { + @MainActor func updatePopupsValue(_ newPopups: [AnyPopup]) async { Task { @MainActor in popups = await filterPopups(newPopups) activePopup.outerPadding = await calculateActivePopupOuterPadding() @@ -146,22 +146,22 @@ extension VV where Self.ObjectWillChangePublisher == ObservableObjectPublisher { activePopup.verticalFixedSize = await calculateActivePopupVerticalFixedSize() withAnimation(.transition) { objectWillChange.send() } - } - func updateScreenValue(_ screenReader: GeometryProxy) async { + }} + @MainActor func updateScreenValue(_ screenReader: GeometryProxy) async { Task { @MainActor in screen.update(screenReader) activePopup.outerPadding = await calculateActivePopupOuterPadding() activePopup.innerPadding = await calculateActivePopupInnerPadding() withAnimation(.transition) { objectWillChange.send() } - } - func updateKeyboardValue(_ isActive: Bool) async { + }} + @MainActor func updateKeyboardValue(_ isActive: Bool) async { Task { @MainActor in screen.isKeyboardActive = isActive activePopup.outerPadding = await calculateActivePopupOuterPadding() activePopup.innerPadding = await calculateActivePopupInnerPadding() withAnimation(.transition) { objectWillChange.send() } - } - func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { + }} + @MainActor func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { Task { @MainActor in guard gestureTranslation == 0 else { return } @@ -170,14 +170,14 @@ extension VV where Self.ObjectWillChangePublisher == ObservableObjectPublisher { guard newPopup.height != popup.height else { return } await updatePopupAction(newPopup) - } - func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { + }} + @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { Task { @MainActor in gestureTranslation = newGestureTranslation translationProgress = await calculateTranslationProgress() activePopup.height = await calculateActivePopupHeight() withAnimation(gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } - } + }} } private extension VV { func filterPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { From dd4205ed2cd0e93366433404e819cf157d84cdd8 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 9 Nov 2024 12:20:30 +0100 Subject: [PATCH 159/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index bd0dc92c62..da9e916002 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -100,20 +100,24 @@ private extension ViewModel { -protocol VV: ObservableObject { init() +protocol VV: ObservableObject { + // MARK: Attributes var alignment: PopupAlignment { get set } var popups: [AnyPopup] { get set } - var updatePopupAction: ((AnyPopup) async -> ())! { get set } - var closePopupAction: ((AnyPopup) async -> ())! { get set } - var gestureTranslation: CGFloat { get set } var translationProgress: CGFloat { get set } var activePopup: ActivePopup { get set } var screen: Screen { get set } - init(_ config: Config.Type) + // MARK: Actions + var updatePopupAction: ((AnyPopup) async -> ())! { get set } + var closePopupAction: ((AnyPopup) async -> ())! { get set } + // MARK: Initializers + init() + init(_ config: Config.Type) + // MARK: Methods func calculateActivePopupHeight() async -> CGFloat? func calculateActivePopupInnerPadding() async -> EdgeInsets func calculateActivePopupOuterPadding() async -> EdgeInsets @@ -122,8 +126,6 @@ protocol VV: ObservableObject { init() func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat func calculateTranslationProgress() async -> CGFloat - - } // MARK: Setup From 2b1a1072cd9ae5249ee289bd2fddb8db48ba9985 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 9 Nov 2024 12:39:20 +0100 Subject: [PATCH 160/407] 1 --- .../Internal/UI/PopupCentreStackView.swift | 2 +- .../View Models/ViewModel+CentreStack.swift | 64 +++++++++---------- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/Sources/Internal/UI/PopupCentreStackView.swift b/Sources/Internal/UI/PopupCentreStackView.swift index 756ea3fd37..e2fa98496b 100644 --- a/Sources/Internal/UI/PopupCentreStackView.swift +++ b/Sources/Internal/UI/PopupCentreStackView.swift @@ -30,7 +30,7 @@ private extension PopupCentreStackView { private extension PopupCentreStackView { func createPopup(_ popup: AnyPopup) -> some View { popup.body - .fixedSize(horizontal: false, vertical: viewModel.calculateVerticalFixedSize(for: popup)) + .fixedSize(horizontal: false, vertical: viewModel.activePopup.verticalFixedSize) .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } .frame(height: viewModel.activePopup.height) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopup.height) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index ca81ff50ba..860bd7c3ed 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -11,15 +11,15 @@ import SwiftUI -extension VM { class CentreStack: ViewModel { - // MARK: Overridden Methods - override func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _calculatePopupHeight(heightCandidate) } - override func calculatePopupPadding() async -> EdgeInsets { await _calculatePopupPadding() } - override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } - override func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { await _calculateCornerRadius() } - override func calculateBodyPadding() async -> EdgeInsets { await _calculateBodyPadding() } - override func calculateTranslationProgress() async -> CGFloat { await _calculateTranslationProgress() } - override func calculateVerticalFixedSize() async -> Bool { false } +extension VM { class CentreStack: VV { required init() {} + var alignment: PopupAlignment = .centre + var popups: [AnyPopup] = [] + var gestureTranslation: CGFloat = 0 + var translationProgress: CGFloat = 0 + var activePopup: ActivePopup = .init() + var screen: Screen = .init() + var updatePopupAction: ((AnyPopup) async -> ())! + var closePopupAction: ((AnyPopup) async -> ())! }} @@ -29,9 +29,9 @@ extension VM { class CentreStack: ViewModel { // MARK: Popup Height -private extension VM.CentreStack { - nonisolated func _calculatePopupHeight(_ heightCandidate: CGFloat) async -> CGFloat { - await min(heightCandidate, calculateLargeScreenHeight()) +extension VM.CentreStack { + func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { + min(heightCandidate, calculateLargeScreenHeight()) } } private extension VM.CentreStack { @@ -42,9 +42,9 @@ private extension VM.CentreStack { } } -// MARK: Popup Padding -private extension VM.CentreStack { - nonisolated func _calculatePopupPadding() async -> EdgeInsets { await .init( +// MARK: Outer Padding +extension VM.CentreStack { + func calculateActivePopupOuterPadding() async -> EdgeInsets { await .init( top: calculateVerticalPopupPadding(for: .top), leading: calculateLeadingPopupPadding(), bottom: calculateVerticalPopupPadding(for: .bottom), @@ -52,8 +52,8 @@ private extension VM.CentreStack { )} } private extension VM.CentreStack { - func calculateVerticalPopupPadding(for edge: PopupAlignment) -> CGFloat { - guard let activePopupHeight = activePopup.height, + func calculateVerticalPopupPadding(for edge: PopupAlignment) async -> CGFloat { + guard let activePopupHeight = await activePopup.height, screen.isKeyboardActive && edge == .bottom else { return 0 } @@ -69,14 +69,14 @@ private extension VM.CentreStack { } } -// MARK: Body Padding -private extension VM.CentreStack { - nonisolated func _calculateBodyPadding() async -> EdgeInsets { .init() } +// MARK: Inner Padding +extension VM.CentreStack { + func calculateActivePopupInnerPadding() async -> EdgeInsets { .init() } } // MARK: Corner Radius -private extension VM.CentreStack { - nonisolated func _calculateCornerRadius() async -> [PopupAlignment : CGFloat] { await [ +extension VM.CentreStack { + func calculateActivePopupCorners() async -> [PopupAlignment : CGFloat] { [ .top: popups.last?.config.cornerRadius ?? 0, .bottom: popups.last?.config.cornerRadius ?? 0 ]} @@ -91,25 +91,19 @@ extension VM.CentreStack { // MARK: Fixed Size extension VM.CentreStack { - func calculateVerticalFixedSize(for popup: AnyPopup) -> Bool { - activePopup.height != calculateLargeScreenHeight() + func calculateActivePopupVerticalFixedSize() async -> Bool { + await activePopup.height != calculateLargeScreenHeight() } } // MARK: Translation Progress -private extension VM.CentreStack { - nonisolated func _calculateTranslationProgress() async -> CGFloat { 0 } +extension VM.CentreStack { + func calculateTranslationProgress() async -> CGFloat { 0 } } - - -// MARK: - HELPERS - - - // MARK: Active Popup Height -private extension VM.CentreStack { - nonisolated func _calculateHeightForActivePopup() async -> CGFloat? { - await popups.last?.height +extension VM.CentreStack { + func calculateActivePopupHeight() async -> CGFloat? { + popups.last?.height } } From 47206acfb200181ce21e3d05f7b1554bafb1ebc1 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 9 Nov 2024 13:31:02 +0100 Subject: [PATCH 161/407] 1 --- Sources/Internal/UI/PopupView.swift | 4 +- .../View Models/ViewModel+VerticalStack.swift | 169 +++++++++--------- Sources/Internal/View Models/ViewModel.swift | 4 +- 3 files changed, 90 insertions(+), 87 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 6d9609c3d6..9ef4aba457 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -114,8 +114,8 @@ private extension PopupView { func closePopup(_ popup: AnyPopup) { popupManager.stack(.removePopupInstance(popup)) } - func updateViewModels(_ updateBuilder: (ViewModel) async -> ()) async { - for viewModel in [topStackViewModel, centreStackViewModel, bottomStackViewModel] { await updateBuilder(viewModel) } + func updateViewModels(_ updateBuilder: @escaping (any VV) async -> ()) async { + for viewModel in [topStackViewModel, centreStackViewModel, bottomStackViewModel] { Task { @MainActor in await updateBuilder(viewModel as! any VV) }} } } private extension PopupView { diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 460f8763b8..5419d83236 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -11,15 +11,15 @@ import SwiftUI -extension VM { class VerticalStack: ViewModel { - // MARK: Overridden Methods - override func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { await _calculatePopupHeight(heightCandidate, popup) } - override func calculatePopupPadding() async -> EdgeInsets { await _calculatePopupPadding() } - override func calculateHeightForActivePopup() async -> CGFloat? { await _calculateHeightForActivePopup() } - override func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { await _calculateCornerRadius() } - override func calculateBodyPadding() async -> EdgeInsets { await _calculateBodyPadding() } - override func calculateTranslationProgress() async -> CGFloat { await _calculateTranslationProgress() } - override func calculateVerticalFixedSize() async -> Bool { await _calculateVerticalFixedSize() } +extension VM { class VerticalStack: VV { required init() {} + var alignment: PopupAlignment = .centre + var popups: [AnyPopup] = [] + var gestureTranslation: CGFloat = 0 + var translationProgress: CGFloat = 0 + var activePopup: ActivePopup = .init() + var screen: Screen = .init() + var updatePopupAction: ((AnyPopup) async -> ())! + var closePopupAction: ((AnyPopup) async -> ())! }} @@ -29,19 +29,19 @@ extension VM { class VerticalStack: ViewModel { // MARK: Popup Height -private extension VM.VerticalStack { - nonisolated func _calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { - guard await gestureTranslation.isZero else { return popup.height ?? 0 } +extension VM.VerticalStack { + func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { + guard gestureTranslation.isZero else { return popup.height ?? 0 } - let popupHeight = await calculateNewPopupHeight(heightCandidate, popup.config) + let popupHeight = calculateNewPopupHeight(heightCandidate, popup.config) return popupHeight } } private extension VM.VerticalStack { - nonisolated func calculateNewPopupHeight(_ heightCandidate: CGFloat, _ popupConfig: AnyPopupConfig) async -> CGFloat { switch popupConfig.heightMode { - case .auto: await min(heightCandidate, calculateLargeScreenHeight()) - case .large: await calculateLargeScreenHeight() - case .fullscreen: await getFullscreenHeight() + func calculateNewPopupHeight(_ heightCandidate: CGFloat, _ popupConfig: AnyPopupConfig) -> CGFloat { switch popupConfig.heightMode { + case .auto: min(heightCandidate, calculateLargeScreenHeight()) + case .large: calculateLargeScreenHeight() + case .fullscreen: getFullscreenHeight() }} } private extension VM.VerticalStack { @@ -64,9 +64,9 @@ private extension VM.VerticalStack { } } -// MARK: Popup Padding -private extension VM.VerticalStack { - nonisolated func _calculatePopupPadding() async -> EdgeInsets { guard let activePopupConfig = await popups.last?.config else { return .init() }; return await .init( +// MARK: Outer Padding +extension VM.VerticalStack { + func calculateActivePopupOuterPadding() async -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return await .init( top: calculateVerticalPopupPadding(for: .top, activePopupConfig: activePopupConfig), leading: calculateLeadingPopupPadding(activePopupConfig: activePopupConfig), bottom: calculateVerticalPopupPadding(for: .bottom, activePopupConfig: activePopupConfig), @@ -74,8 +74,8 @@ private extension VM.VerticalStack { )} } private extension VM.VerticalStack { - nonisolated func calculateVerticalPopupPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { - let largeScreenHeight = await calculateLargeScreenHeight(), + func calculateVerticalPopupPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { + let largeScreenHeight = calculateLargeScreenHeight(), activePopupHeight = await activePopup.height ?? 0, priorityPopupPaddingValue = await calculatePriorityPopupPaddingValue(for: edge, activePopupConfig: activePopupConfig), remainingHeight = largeScreenHeight - activePopupHeight - priorityPopupPaddingValue @@ -83,10 +83,10 @@ private extension VM.VerticalStack { let popupPaddingCandidate = min(remainingHeight, activePopupConfig.popupPadding[edge]) return max(popupPaddingCandidate, 0) } - nonisolated func calculateLeadingPopupPadding(activePopupConfig: AnyPopupConfig) async -> CGFloat { + func calculateLeadingPopupPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { activePopupConfig.popupPadding.leading } - nonisolated func calculateTrailingPopupPadding(activePopupConfig: AnyPopupConfig) async -> CGFloat { + func calculateTrailingPopupPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { activePopupConfig.popupPadding.trailing } } @@ -97,9 +97,9 @@ private extension VM.VerticalStack { }} } -// MARK: Body Padding -private extension VM.VerticalStack { - nonisolated func _calculateBodyPadding() async -> EdgeInsets { guard let popup = await popups.last else { return .init() }; return await .init( +// MARK: Inner Padding +extension VM.VerticalStack { + func calculateActivePopupInnerPadding() async -> EdgeInsets { guard let popup = popups.last else { return .init() }; return await .init( top: calculateTopBodyPadding(popup: popup), leading: calculateLeadingBodyPadding(popup: popup), bottom: calculateBottomBodyPadding(popup: popup), @@ -107,7 +107,7 @@ private extension VM.VerticalStack { )} } private extension VM.VerticalStack { - nonisolated func calculateTopBodyPadding(popup: AnyPopup) async -> CGFloat { + func calculateTopBodyPadding(popup: AnyPopup) async -> CGFloat { if popup.config.ignoredSafeAreaEdges.contains(.top) { return 0 } return switch alignment { @@ -125,21 +125,21 @@ private extension VM.VerticalStack { case .centre: fatalError() } } - nonisolated func calculateLeadingBodyPadding(popup: AnyPopup) async -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.leading) { + func calculateLeadingBodyPadding(popup: AnyPopup) -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.leading) { case true: 0 - case false: await screen.safeArea.leading + case false: screen.safeArea.leading }} - nonisolated func calculateTrailingBodyPadding(popup: AnyPopup) async -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.trailing) { + func calculateTrailingBodyPadding(popup: AnyPopup) async -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.trailing) { case true: 0 - case false: await screen.safeArea.trailing + case false: screen.safeArea.trailing }} } private extension VM.VerticalStack { - nonisolated func calculateVerticalPaddingCounterEdge(popupHeight: CGFloat, safeArea: CGFloat) async -> CGFloat { - let paddingValueCandidate = await safeArea + popupHeight - screen.height + func calculateVerticalPaddingCounterEdge(popupHeight: CGFloat, safeArea: CGFloat) -> CGFloat { + let paddingValueCandidate = safeArea + popupHeight - screen.height return max(paddingValueCandidate, 0) } - nonisolated func calculateVerticalPaddingAdhereEdge(safeAreaHeight: CGFloat, popupPadding: CGFloat) async -> CGFloat { + func calculateVerticalPaddingAdhereEdge(safeAreaHeight: CGFloat, popupPadding: CGFloat) -> CGFloat { let paddingValueCandidate = safeAreaHeight - popupPadding return max(paddingValueCandidate, 0) } @@ -190,9 +190,9 @@ extension VM.VerticalStack { } // MARK: Corner Radius -private extension VM.VerticalStack { - nonisolated func _calculateCornerRadius() async -> [PopupAlignment: CGFloat] { - guard let activePopup = await popups.last else { return [:] } +extension VM.VerticalStack { + func calculateActivePopupCorners() async -> [PopupAlignment: CGFloat] { + guard let activePopup = popups.last else { return [:] } let cornerRadiusValue = await calculateCornerRadiusValue(activePopup) return await [ @@ -202,16 +202,16 @@ private extension VM.VerticalStack { } } private extension VM.VerticalStack { - nonisolated func calculateCornerRadiusValue(_ activePopup: AnyPopup) async -> CGFloat { switch activePopup.config.heightMode { + func calculateCornerRadiusValue(_ activePopup: AnyPopup) async -> CGFloat { switch activePopup.config.heightMode { case .auto, .large: activePopup.config.cornerRadius case .fullscreen: 0 }} - nonisolated func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat) async -> CGFloat { switch alignment { + func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat) async -> CGFloat { switch alignment { case .top: await activePopup.outerPadding.top != 0 ? cornerRadiusValue : 0 case .bottom: cornerRadiusValue case .centre: fatalError() }} - nonisolated func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat) async -> CGFloat { switch alignment { + func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat) async -> CGFloat { switch alignment { case .top: cornerRadiusValue case .bottom: await activePopup.outerPadding.bottom != 0 ? cornerRadiusValue : 0 case .centre: fatalError() @@ -220,7 +220,7 @@ private extension VM.VerticalStack { // MARK: Fixed Size extension VM.VerticalStack { - nonisolated func _calculateVerticalFixedSize() async -> Bool { guard let popup = await popups.last else { return true }; return switch popup.config.heightMode { + func calculateActivePopupVerticalFixedSize() async -> Bool { guard let popup = popups.last else { return true }; return switch popup.config.heightMode { case .fullscreen, .large: false case .auto: await activePopup.height != calculateLargeScreenHeight() }} @@ -259,15 +259,15 @@ private extension VM.VerticalStack { // MARK: Active Popup Height -private extension VM.VerticalStack { - nonisolated func _calculateHeightForActivePopup() async -> CGFloat? { - guard let activePopupHeight = await popups.last?.height else { return nil } +extension VM.VerticalStack { + func calculateActivePopupHeight() async -> CGFloat? { + guard let activePopupHeight = popups.last?.height else { return nil } - let activePopupDragHeight = await popups.last?.dragHeight ?? 0 - let popupHeightFromGestureTranslation = await activePopupHeight + activePopupDragHeight + gestureTranslation * getDragTranslationMultiplier() + let activePopupDragHeight = popups.last?.dragHeight ?? 0 + let popupHeightFromGestureTranslation = activePopupHeight + activePopupDragHeight + gestureTranslation * getDragTranslationMultiplier() let newHeightCandidate1 = max(activePopupHeight, popupHeightFromGestureTranslation), - newHeightCanditate2 = await screen.height + newHeightCanditate2 = screen.height return min(newHeightCandidate1, newHeightCanditate2) } } @@ -280,10 +280,10 @@ private extension VM.VerticalStack { } // MARK: Translation Progress -private extension VM.VerticalStack { - nonisolated func _calculateTranslationProgress() async -> CGFloat { guard let activePopupHeight = await popups.last?.height else { return 0 }; return switch alignment { - case .top: await abs(min(gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight - case .bottom: await max(gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight +extension VM.VerticalStack { + func calculateTranslationProgress() async -> CGFloat { guard let activePopupHeight = popups.last?.height else { return 0 }; return switch alignment { + case .top: abs(min(gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight + case .bottom: max(gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight case .centre: fatalError() }} } @@ -317,38 +317,38 @@ extension VM.VerticalStack { // MARK: On Changed extension VM.VerticalStack { - nonisolated func onPopupDragGestureChanged(_ value: CGFloat) async { if await dragGestureEnabled { + @MainActor func onPopupDragGestureChanged(_ value: CGFloat) async { Task { @MainActor in if dragGestureEnabled { let newGestureTranslation = await calculateGestureTranslation(value) await updateGestureTranslation(newGestureTranslation) - }} + }}} } private extension VM.VerticalStack { - nonisolated func calculateGestureTranslation(_ value: CGFloat) async -> CGFloat { switch await popups.last?.config.dragDetents.isEmpty ?? true { - case true: await calculateGestureTranslationWhenNoDragDetents(value) + func calculateGestureTranslation(_ value: CGFloat) async -> CGFloat { switch popups.last?.config.dragDetents.isEmpty ?? true { + case true: calculateGestureTranslationWhenNoDragDetents(value) case false: await calculateGestureTranslationWhenDragDetents(value) }} } private extension VM.VerticalStack { - nonisolated func calculateGestureTranslationWhenNoDragDetents(_ value: CGFloat) async -> CGFloat { - await calculateDragExtremeValue(value, 0) + func calculateGestureTranslationWhenNoDragDetents(_ value: CGFloat) -> CGFloat { + calculateDragExtremeValue(value, 0) } - nonisolated func calculateGestureTranslationWhenDragDetents(_ value: CGFloat) async -> CGFloat { guard await value * getDragTranslationMultiplier() > 0, let activePopupHeight = await popups.last?.height else { return value } + func calculateGestureTranslationWhenDragDetents(_ value: CGFloat) async -> CGFloat { guard value * getDragTranslationMultiplier() > 0, let activePopupHeight = popups.last?.height else { return value } let maxHeight = await calculateMaxHeightForDragGesture(activePopupHeight) - let dragTranslation = await calculateDragTranslation(maxHeight, activePopupHeight) - return await calculateDragExtremeValue(dragTranslation, value) + let dragTranslation = calculateDragTranslation(maxHeight, activePopupHeight) + return calculateDragExtremeValue(dragTranslation, value) } } private extension VM.VerticalStack { - nonisolated func calculateMaxHeightForDragGesture(_ activePopupHeight: CGFloat) async -> CGFloat { + func calculateMaxHeightForDragGesture(_ activePopupHeight: CGFloat) async -> CGFloat { let maxHeight1 = await (calculatePopupTargetHeightsFromDragDetents(activePopupHeight).max() ?? 0) + dragTranslationThreshold - let maxHeight2 = await screen.height + let maxHeight2 = screen.height return min(maxHeight1, maxHeight2) } - nonisolated func calculateDragTranslation(_ maxHeight: CGFloat, _ activePopupHeight: CGFloat) async -> CGFloat { - let translation = await maxHeight - activePopupHeight - (popups.last?.dragHeight ?? 0) - return await translation * getDragTranslationMultiplier() + func calculateDragTranslation(_ maxHeight: CGFloat, _ activePopupHeight: CGFloat) -> CGFloat { + let translation = maxHeight - activePopupHeight - (popups.last?.dragHeight ?? 0) + return translation * getDragTranslationMultiplier() } - nonisolated func calculateDragExtremeValue(_ value1: CGFloat, _ value2: CGFloat) async -> CGFloat { switch alignment { + func calculateDragExtremeValue(_ value1: CGFloat, _ value2: CGFloat) -> CGFloat { switch alignment { case .top: min(value1, value2) case .bottom: max(value1, value2) case .centre: fatalError() @@ -357,34 +357,37 @@ private extension VM.VerticalStack { // MARK: On Ended extension VM.VerticalStack { - nonisolated func onPopupDragGestureEnded(_ value: CGFloat) async { if value != 0 { + @MainActor func onPopupDragGestureEnded(_ value: CGFloat) async { Task { @MainActor in if value != 0 { await dismissLastItemIfNeeded() await updateTranslationValues() - }} + }}} } private extension VM.VerticalStack { func dismissLastItemIfNeeded() async { if shouldDismissPopup() { if let popup = popups.last { await closePopupAction(popup) }}} - func updateTranslationValues() async { if let activePopupHeight = popups.last?.height { - let currentPopupHeight = calculateCurrentPopupHeight(activePopupHeight) - let popupTargetHeights = calculatePopupTargetHeightsFromDragDetents(activePopupHeight) - let targetHeight = calculateTargetPopupHeight(currentPopupHeight, popupTargetHeights) - let targetDragHeight = calculateTargetDragHeight(targetHeight, activePopupHeight) - - await resetGestureTranslation() - await updateDragHeight(targetDragHeight) + @MainActor func updateTranslationValues() async { if let activePopupHeight = popups.last?.height { + Task { + let currentPopupHeight = await calculateCurrentPopupHeight(activePopupHeight) + let popupTargetHeights = await calculatePopupTargetHeightsFromDragDetents(activePopupHeight) + let targetHeight = await calculateTargetPopupHeight(currentPopupHeight, popupTargetHeights) + let targetDragHeight = await calculateTargetDragHeight(targetHeight, activePopupHeight) + + await resetGestureTranslation() + await updateDragHeight(targetDragHeight) + } + }} } private extension VM.VerticalStack { - func calculateCurrentPopupHeight(_ activePopupHeight: CGFloat) -> CGFloat { + func calculateCurrentPopupHeight(_ activePopupHeight: CGFloat) async -> CGFloat { let activePopupDragHeight = popups.last?.dragHeight ?? 0 let currentDragHeight = activePopupDragHeight + gestureTranslation * getDragTranslationMultiplier() let currentPopupHeight = activePopupHeight + currentDragHeight return currentPopupHeight } - func calculatePopupTargetHeightsFromDragDetents(_ activePopupHeight: CGFloat) -> [CGFloat] { guard let dragDetents = popups.last?.config.dragDetents else { return [activePopupHeight] }; return + func calculatePopupTargetHeightsFromDragDetents(_ activePopupHeight: CGFloat) async -> [CGFloat] { guard let dragDetents = popups.last?.config.dragDetents else { return [activePopupHeight] }; return dragDetents .map { switch $0 { case .height(let targetHeight): min(targetHeight, calculateLargeScreenHeight()) @@ -395,7 +398,7 @@ private extension VM.VerticalStack { .appending(activePopupHeight) .sorted(by: <) } - func calculateTargetPopupHeight(_ currentPopupHeight: CGFloat, _ popupTargetHeights: [CGFloat]) -> CGFloat { + func calculateTargetPopupHeight(_ currentPopupHeight: CGFloat, _ popupTargetHeights: [CGFloat]) async -> CGFloat { guard let activePopupHeight = popups.last?.height, currentPopupHeight < screen.height else { return popupTargetHeights.last ?? 0 } @@ -413,15 +416,15 @@ private extension VM.VerticalStack { } return popupTargetHeights[targetIndex] } - func calculateTargetDragHeight(_ targetHeight: CGFloat, _ activePopupHeight: CGFloat) -> CGFloat { + func calculateTargetDragHeight(_ targetHeight: CGFloat, _ activePopupHeight: CGFloat) async -> CGFloat { targetHeight - activePopupHeight } - func updateDragHeight(_ targetDragHeight: CGFloat) async { if let activePopup = popups.last { + @MainActor func updateDragHeight(_ targetDragHeight: CGFloat) async { if let activePopup = popups.last { var newPopup = activePopup newPopup.dragHeight = targetDragHeight await updatePopupAction(newPopup) }} - nonisolated func resetGestureTranslation() async { + @MainActor func resetGestureTranslation() async { await updateGestureTranslation(0) } func shouldDismissPopup() -> Bool { diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index da9e916002..0ae1198989 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -100,7 +100,7 @@ private extension ViewModel { -protocol VV: ObservableObject { +protocol VV: ObservableObject where Self.ObjectWillChangePublisher == ObservableObjectPublisher { // MARK: Attributes var alignment: PopupAlignment { get set } var popups: [AnyPopup] { get set } @@ -137,7 +137,7 @@ extension VV { } // MARK: Update -extension VV where Self.ObjectWillChangePublisher == ObservableObjectPublisher { +extension VV { @MainActor func updatePopupsValue(_ newPopups: [AnyPopup]) async { Task { @MainActor in popups = await filterPopups(newPopups) From 362207f478c5974a1cad6f6e93f2e029a22f8836 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 9 Nov 2024 13:32:06 +0100 Subject: [PATCH 162/407] 1 --- Sources/Internal/UI/PopupView.swift | 4 +- .../View Models/ViewModel+CentreStack.swift | 2 +- .../View Models/ViewModel+VerticalStack.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 89 +------------------ 4 files changed, 5 insertions(+), 92 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 9ef4aba457..41d09cd5c8 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -114,8 +114,8 @@ private extension PopupView { func closePopup(_ popup: AnyPopup) { popupManager.stack(.removePopupInstance(popup)) } - func updateViewModels(_ updateBuilder: @escaping (any VV) async -> ()) async { - for viewModel in [topStackViewModel, centreStackViewModel, bottomStackViewModel] { Task { @MainActor in await updateBuilder(viewModel as! any VV) }} + func updateViewModels(_ updateBuilder: @escaping (any ViewModel) async -> ()) async { + for viewModel in [topStackViewModel, centreStackViewModel, bottomStackViewModel] { Task { @MainActor in await updateBuilder(viewModel as! any ViewModel) }} } } private extension PopupView { diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 860bd7c3ed..d5679feb56 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -11,7 +11,7 @@ import SwiftUI -extension VM { class CentreStack: VV { required init() {} +extension VM { class CentreStack: ViewModel { required init() {} var alignment: PopupAlignment = .centre var popups: [AnyPopup] = [] var gestureTranslation: CGFloat = 0 diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 5419d83236..6d6d3652b8 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -11,7 +11,7 @@ import SwiftUI -extension VM { class VerticalStack: VV { required init() {} +extension VM { class VerticalStack: ViewModel { required init() {} var alignment: PopupAlignment = .centre var popups: [AnyPopup] = [] var gestureTranslation: CGFloat = 0 diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 0ae1198989..3d2699d7e8 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -13,94 +13,7 @@ import SwiftUI import Combine enum VM {} -@MainActor class ViewModel: ObservableObject { - // MARK: Attributes - nonisolated let alignment: PopupAlignment - private(set) var popups: [AnyPopup] = [] - private(set) var updatePopupAction: ((AnyPopup) async -> ())! - private(set) var closePopupAction: ((AnyPopup) async -> ())! - - // MARK: Subclass Attributes - var gestureTranslation: CGFloat = 0 - var translationProgress: CGFloat = 0 - var activePopup: ActivePopup = .init() - var screen: Screen = .init() - - // MARK: Methods to Override - nonisolated func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { fatalError() } - nonisolated func calculatePopupPadding() async -> EdgeInsets { fatalError() } - nonisolated func calculateCornerRadius() async -> [PopupAlignment: CGFloat] { fatalError() } - nonisolated func calculateHeightForActivePopup() async -> CGFloat? { fatalError() } - nonisolated func calculateBodyPadding() async -> EdgeInsets { fatalError() } - nonisolated func calculateTranslationProgress() async -> CGFloat { fatalError() } - nonisolated func calculateVerticalFixedSize() async -> Bool { fatalError() } - - // MARK: Initializer - init(_ config: Config.Type) { self.alignment = .init(Config.self) } -} - -// MARK: Setup -extension ViewModel { - func setup(updatePopupAction: @escaping (AnyPopup) async -> (), closePopupAction: @escaping (AnyPopup) async -> ()) { - self.updatePopupAction = updatePopupAction - self.closePopupAction = closePopupAction - } -} - -// MARK: Update -extension ViewModel { - func updatePopupsValue(_ newPopups: [AnyPopup]) async { - popups = await filterPopups(newPopups) - - activePopup.outerPadding = await calculatePopupPadding() - activePopup.height = await calculateHeightForActivePopup() - activePopup.innerPadding = await calculateBodyPadding() - activePopup.corners = await calculateCornerRadius() - activePopup.verticalFixedSize = await calculateVerticalFixedSize() - - withAnimation(.transition) { objectWillChange.send() } - } - func updateScreenValue(_ screenReader: GeometryProxy) async { - screen.update(screenReader) - activePopup.outerPadding = await calculatePopupPadding() - activePopup.innerPadding = await calculateBodyPadding() - - withAnimation(.transition) { objectWillChange.send() } - } - func updateKeyboardValue(_ isActive: Bool) async { - screen.isKeyboardActive = isActive - activePopup.outerPadding = await calculatePopupPadding() - activePopup.innerPadding = await calculateBodyPadding() - - withAnimation(.transition) { objectWillChange.send() } - } - func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { - guard gestureTranslation == 0 else { return } - - - var newPopup = popup - newPopup.height = await calculatePopupHeight(heightCandidate, newPopup) - - guard newPopup.height != popup.height else { return } - await updatePopupAction(newPopup) - } - func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { - gestureTranslation = newGestureTranslation - translationProgress = await calculateTranslationProgress() - activePopup.height = await calculateHeightForActivePopup() - - withAnimation(gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } - } -} -private extension ViewModel { - nonisolated func filterPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { - popups.filter { $0.config.alignment == alignment } - } -} - - - -protocol VV: ObservableObject where Self.ObjectWillChangePublisher == ObservableObjectPublisher { +protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == ObservableObjectPublisher { // MARK: Attributes var alignment: PopupAlignment { get set } var popups: [AnyPopup] { get set } From 077a1e9740d0adb517c666c92fd2e9e6e3448d74 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 9 Nov 2024 22:01:11 +0100 Subject: [PATCH 163/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 3d2699d7e8..69e5ea0e29 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -42,7 +42,7 @@ protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == Obs } // MARK: Setup -extension VV { +extension ViewModel { func setup(updatePopupAction: @escaping (AnyPopup) async -> (), closePopupAction: @escaping (AnyPopup) async -> ()) { self.updatePopupAction = updatePopupAction self.closePopupAction = closePopupAction @@ -50,7 +50,7 @@ extension VV { } // MARK: Update -extension VV { +extension ViewModel { @MainActor func updatePopupsValue(_ newPopups: [AnyPopup]) async { Task { @MainActor in popups = await filterPopups(newPopups) @@ -94,7 +94,7 @@ extension VV { withAnimation(gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } }} } -private extension VV { +private extension ViewModel { func filterPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { popups.filter { $0.config.alignment == alignment } } @@ -103,7 +103,7 @@ private extension VV { -extension VV { +extension ViewModel { init(_ config: Config.Type) { self.init(); self.alignment = .init(Config.self) } } From deb7f6ac229c2a7f1c668e3c4a5b9344a9c83f7f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 00:14:04 +0100 Subject: [PATCH 164/407] 1 --- Sources/Internal/UI/PopupView.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 41d09cd5c8..f9c4287acb 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -108,11 +108,11 @@ private extension PopupView { }} } private extension PopupView { - func updatePopup(_ popup: AnyPopup) { - popupManager.updateStack(popup) + nonisolated func updatePopup(_ popup: AnyPopup) async { + await popupManager.updateStack(popup) } - func closePopup(_ popup: AnyPopup) { - popupManager.stack(.removePopupInstance(popup)) + nonisolated func closePopup(_ popup: AnyPopup) async { + await popupManager.stack(.removePopupInstance(popup)) } func updateViewModels(_ updateBuilder: @escaping (any ViewModel) async -> ()) async { for viewModel in [topStackViewModel, centreStackViewModel, bottomStackViewModel] { Task { @MainActor in await updateBuilder(viewModel as! any ViewModel) }} From 807e2f527df0179e02a358b79250c8a2e9ee98f2 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 01:41:31 +0100 Subject: [PATCH 165/407] 1 --- .../View Models/ViewModel+CentreStack.swift | 2 -- Sources/Internal/View Models/ViewModel.swift | 13 +++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index d5679feb56..503a6b9757 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -14,8 +14,6 @@ import SwiftUI extension VM { class CentreStack: ViewModel { required init() {} var alignment: PopupAlignment = .centre var popups: [AnyPopup] = [] - var gestureTranslation: CGFloat = 0 - var translationProgress: CGFloat = 0 var activePopup: ActivePopup = .init() var screen: Screen = .init() var updatePopupAction: ((AnyPopup) async -> ())! diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 69e5ea0e29..ee6f03b3b1 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -17,8 +17,6 @@ protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == Obs // MARK: Attributes var alignment: PopupAlignment { get set } var popups: [AnyPopup] { get set } - var gestureTranslation: CGFloat { get set } - var translationProgress: CGFloat { get set } var activePopup: ActivePopup { get set } var screen: Screen { get set } @@ -77,7 +75,7 @@ extension ViewModel { withAnimation(.transition) { objectWillChange.send() } }} @MainActor func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { Task { @MainActor in - guard gestureTranslation == 0 else { return } + guard activePopup.gestureTranslation == 0 else { return } var newPopup = popup @@ -87,11 +85,11 @@ extension ViewModel { await updatePopupAction(newPopup) }} @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { Task { @MainActor in - gestureTranslation = newGestureTranslation - translationProgress = await calculateTranslationProgress() + activePopup.gestureTranslation = newGestureTranslation + activePopup.translationProgress = await calculateTranslationProgress() activePopup.height = await calculateActivePopupHeight() - withAnimation(gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } + withAnimation(activePopup.gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } }} } private extension ViewModel { @@ -117,4 +115,7 @@ extension ViewModel { var outerPadding: EdgeInsets = .init() var corners: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] var verticalFixedSize: Bool = true + + var gestureTranslation: CGFloat = 0 + var translationProgress: CGFloat = 0 } From 830e8900e55c5e4513f4ed7fef61498f27345d6b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 01:43:10 +0100 Subject: [PATCH 166/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 6d6d3652b8..ef4466e6e1 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -31,7 +31,7 @@ extension VM { class VerticalStack: ViewModel { required init() {} // MARK: Popup Height extension VM.VerticalStack { func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { - guard gestureTranslation.isZero else { return popup.height ?? 0 } + guard await activePopup.gestureTranslation.isZero else { return popup.height ?? 0 } let popupHeight = calculateNewPopupHeight(heightCandidate, popup.config) return popupHeight @@ -147,18 +147,18 @@ private extension VM.VerticalStack { // MARK: Offset Y extension VM.VerticalStack { - func calculateOffsetY(for popup: AnyPopup) -> CGFloat { switch popup == popups.last { + @MainActor func calculateOffsetY(for popup: AnyPopup) -> CGFloat { switch popup == popups.last { case true: calculateOffsetForActivePopup() case false: calculateOffsetForStackedPopup(popup) }} } private extension VM.VerticalStack { - func calculateOffsetForActivePopup() -> CGFloat { + @MainActor func calculateOffsetForActivePopup() -> CGFloat { let lastPopupDragHeight = popups.last?.dragHeight ?? 0 return switch alignment { - case .top: min(gestureTranslation + lastPopupDragHeight, 0) - case .bottom: max(gestureTranslation - lastPopupDragHeight, 0) + case .top: min(activePopup.gestureTranslation + lastPopupDragHeight, 0) + case .bottom: max(activePopup.gestureTranslation - lastPopupDragHeight, 0) case .centre: fatalError() } } @@ -177,11 +177,11 @@ private extension VM.VerticalStack { // MARK: Scale X extension VM.VerticalStack { - func calculateScaleX(for popup: AnyPopup) -> CGFloat { + @MainActor func calculateScaleX(for popup: AnyPopup) -> CGFloat { guard popup != popups.last else { return 1 } let invertedIndex = getInvertedIndex(of: popup), - remainingTranslationProgress = 1 - translationProgress + remainingTranslationProgress = 1 - activePopup.translationProgress let progressMultiplier = invertedIndex == 1 ? remainingTranslationProgress : max(minScaleProgressMultiplier, remainingTranslationProgress) let scaleValue = .init(invertedIndex) * stackScaleFactor * progressMultiplier @@ -235,11 +235,11 @@ extension VM.VerticalStack { // MARK: - Stack Overlay Opacity extension VM.VerticalStack { - func calculateStackOverlayOpacity(for popup: AnyPopup) -> CGFloat { + @MainActor func calculateStackOverlayOpacity(for popup: AnyPopup) -> CGFloat { guard popup != popups.last else { return 0 } let invertedIndex = getInvertedIndex(of: popup), - remainingTranslationProgress = 1 - translationProgress + remainingTranslationProgress = 1 - activePopup.translationProgress let progressMultiplier = invertedIndex == 1 ? remainingTranslationProgress : max(minStackOverlayProgressMultiplier, remainingTranslationProgress) let overlayValue = min(stackOverlayFactor * .init(invertedIndex), maxStackOverlayFactor) @@ -264,7 +264,7 @@ extension VM.VerticalStack { guard let activePopupHeight = popups.last?.height else { return nil } let activePopupDragHeight = popups.last?.dragHeight ?? 0 - let popupHeightFromGestureTranslation = activePopupHeight + activePopupDragHeight + gestureTranslation * getDragTranslationMultiplier() + let popupHeightFromGestureTranslation = await activePopupHeight + activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() let newHeightCandidate1 = max(activePopupHeight, popupHeightFromGestureTranslation), newHeightCanditate2 = screen.height @@ -282,8 +282,8 @@ private extension VM.VerticalStack { // MARK: Translation Progress extension VM.VerticalStack { func calculateTranslationProgress() async -> CGFloat { guard let activePopupHeight = popups.last?.height else { return 0 }; return switch alignment { - case .top: abs(min(gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight - case .bottom: max(gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight + case .top: await abs(min(activePopup.gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight + case .bottom: await max(activePopup.gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight case .centre: fatalError() }} } @@ -363,7 +363,7 @@ extension VM.VerticalStack { }}} } private extension VM.VerticalStack { - func dismissLastItemIfNeeded() async { if shouldDismissPopup() { if let popup = popups.last { + func dismissLastItemIfNeeded() async { if await shouldDismissPopup() { if let popup = popups.last { await closePopupAction(popup) }}} @MainActor func updateTranslationValues() async { if let activePopupHeight = popups.last?.height { @@ -382,7 +382,7 @@ private extension VM.VerticalStack { private extension VM.VerticalStack { func calculateCurrentPopupHeight(_ activePopupHeight: CGFloat) async -> CGFloat { let activePopupDragHeight = popups.last?.dragHeight ?? 0 - let currentDragHeight = activePopupDragHeight + gestureTranslation * getDragTranslationMultiplier() + let currentDragHeight = await activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() let currentPopupHeight = activePopupHeight + currentDragHeight return currentPopupHeight @@ -404,14 +404,14 @@ private extension VM.VerticalStack { else { return popupTargetHeights.last ?? 0 } let initialIndex = popupTargetHeights.firstIndex(where: { $0 >= currentPopupHeight }) ?? popupTargetHeights.count - 1, - targetIndex = gestureTranslation * getDragTranslationMultiplier() > 0 ? initialIndex : max(0, initialIndex - 1) + targetIndex = await activePopup.gestureTranslation * getDragTranslationMultiplier() > 0 ? initialIndex : max(0, initialIndex - 1) let previousPopupHeight = (popups.last?.dragHeight ?? 0) + activePopupHeight, popupTargetHeight = popupTargetHeights[targetIndex], deltaHeight = abs(previousPopupHeight - popupTargetHeight) let progress = abs(currentPopupHeight - previousPopupHeight) / deltaHeight if progress < dragThreshold { - let index = gestureTranslation * getDragTranslationMultiplier() > 0 ? max(0, initialIndex - 1) : initialIndex + let index = await activePopup.gestureTranslation * getDragTranslationMultiplier() > 0 ? max(0, initialIndex - 1) : initialIndex return popupTargetHeights[index] } return popupTargetHeights[targetIndex] From 7d6f03e62d262a90cb89bc9247a5f325f563029e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 01:43:22 +0100 Subject: [PATCH 167/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index ef4466e6e1..9832294b87 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -14,8 +14,6 @@ import SwiftUI extension VM { class VerticalStack: ViewModel { required init() {} var alignment: PopupAlignment = .centre var popups: [AnyPopup] = [] - var gestureTranslation: CGFloat = 0 - var translationProgress: CGFloat = 0 var activePopup: ActivePopup = .init() var screen: Screen = .init() var updatePopupAction: ((AnyPopup) async -> ())! From a21a02445550a0c512301b4f371c60dab881bf3f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 01:43:45 +0100 Subject: [PATCH 168/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 9832294b87..fdd9381316 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -425,7 +425,7 @@ private extension VM.VerticalStack { @MainActor func resetGestureTranslation() async { await updateGestureTranslation(0) } - func shouldDismissPopup() -> Bool { - translationProgress >= dragThreshold + func shouldDismissPopup() async -> Bool { + await activePopup.translationProgress >= dragThreshold } } From b4a887649fbba5730dfa8ecd6453b739743b443e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 13:37:20 +0100 Subject: [PATCH 169/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 2 +- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 4 ++-- Tests/Tests+ViewModel+PopupVerticalStack.swift | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 503a6b9757..c6a425f7fe 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -96,7 +96,7 @@ extension VM.CentreStack { // MARK: Translation Progress extension VM.CentreStack { - func calculateTranslationProgress() async -> CGFloat { 0 } + func calculateActivePopupTranslationProgress() async -> CGFloat { 0 } } // MARK: Active Popup Height diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index fdd9381316..2a98c2eb38 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -279,7 +279,7 @@ private extension VM.VerticalStack { // MARK: Translation Progress extension VM.VerticalStack { - func calculateTranslationProgress() async -> CGFloat { guard let activePopupHeight = popups.last?.height else { return 0 }; return switch alignment { + func calculateActivePopupTranslationProgress() async -> CGFloat { guard let activePopupHeight = popups.last?.height else { return 0 }; return switch alignment { case .top: await abs(min(activePopup.gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight case .bottom: await max(activePopup.gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight case .centre: fatalError() diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index ee6f03b3b1..efa72f6df8 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -34,9 +34,9 @@ protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == Obs func calculateActivePopupOuterPadding() async -> EdgeInsets func calculateActivePopupCorners() async -> [PopupAlignment: CGFloat] func calculateActivePopupVerticalFixedSize() async -> Bool + func calculateActivePopupTranslationProgress() async -> CGFloat func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat - func calculateTranslationProgress() async -> CGFloat } // MARK: Setup @@ -86,7 +86,7 @@ extension ViewModel { }} @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { Task { @MainActor in activePopup.gestureTranslation = newGestureTranslation - activePopup.translationProgress = await calculateTranslationProgress() + activePopup.translationProgress = await calculateActivePopupTranslationProgress() activePopup.height = await calculateActivePopupHeight() withAnimation(activePopup.gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index f3e4eadecd..3bfec3cdbb 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -841,7 +841,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { await $0.calculateTranslationProgress() }, + calculatedValue: { await $0.calculateActivePopupTranslationProgress() }, expectedValueBuilder: { _ in expectedValue } ) } @@ -1001,7 +1001,7 @@ extension PopupVerticalStackViewModelTests { popups: popups, gestureTranslation: 100, calculateForIndex: 1, - expectedValueBuilder: { await 1 - $0.stackScaleFactor * 3 * max(1 - $0.calculateTranslationProgress(), $0.minScaleProgressMultiplier) } + expectedValueBuilder: { await 1 - $0.stackScaleFactor * 3 * max(1 - $0.calculateActivePopupTranslationProgress(), $0.minScaleProgressMultiplier) } ) } } @@ -1191,7 +1191,7 @@ extension PopupVerticalStackViewModelTests { popups: popups, gestureTranslation: 241, calculateForIndex: 2, - expectedValueBuilder: { await (1 - $0.calculateTranslationProgress()) * $0.stackOverlayFactor } + expectedValueBuilder: { await (1 - $0.calculateActivePopupTranslationProgress()) * $0.stackOverlayFactor } ) } } From 20834193df621dc245b75ef20a34aca6ac90e8f3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 14:06:08 +0100 Subject: [PATCH 170/407] 1 --- Sources/Internal/Models/Screen.swift | 21 ++++++++++++-------- Sources/Internal/UI/PopupView.swift | 4 ++-- Sources/Internal/View Models/ViewModel.swift | 11 ++-------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Sources/Internal/Models/Screen.swift b/Sources/Internal/Models/Screen.swift index b2e339ac90..e45499bdcb 100644 --- a/Sources/Internal/Models/Screen.swift +++ b/Sources/Internal/Models/Screen.swift @@ -12,22 +12,27 @@ import SwiftUI struct Screen { - var height: CGFloat - var safeArea: EdgeInsets - var isKeyboardActive: Bool + private(set) var height: CGFloat + private(set) var safeArea: EdgeInsets + private(set) var isKeyboardActive: Bool - init(height: CGFloat = .zero, safeArea: EdgeInsets = .init()) { + init(height: CGFloat = .zero, safeArea: EdgeInsets = .init(), isKeyboardActive: Bool = false) { self.height = height self.safeArea = safeArea - self.isKeyboardActive = false + self.isKeyboardActive = isKeyboardActive } } // MARK: Update extension Screen { - mutating func update(_ screenReader: GeometryProxy) { - self.height = screenReader.size.height + screenReader.safeAreaInsets.top + screenReader.safeAreaInsets.bottom - self.safeArea = screenReader.safeAreaInsets + mutating func update(screenReader: GeometryProxy?, isKeyboardActive: Bool?) { + if let screenReader { + self.height = screenReader.size.height + screenReader.safeAreaInsets.top + screenReader.safeAreaInsets.bottom + self.safeArea = screenReader.safeAreaInsets + } + if let isKeyboardActive { + self.isKeyboardActive = isKeyboardActive + } } } diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index f9c4287acb..b9480332ce 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -86,7 +86,7 @@ private extension PopupView { await updateViewModels { $0.setup(updatePopupAction: updatePopup, closePopupAction: closePopup) } }} func onScreenChange(_ screenReader: GeometryProxy) { Task { @MainActor in - await updateViewModels { await $0.updateScreenValue(screenReader) } + await updateViewModels { await $0.updateScreenValue(screenReader: screenReader) } }} func onPopupsHeightChange(_ p: Any) { Task { @MainActor in await updateViewModels { await $0.updatePopupsValue(popupManager.stack) } @@ -101,7 +101,7 @@ private extension PopupView { newStack.last?.onFocus() } func onKeyboardStateChange(_ isKeyboardActive: Bool) { Task { @MainActor in - await updateViewModels { await $0.updateKeyboardValue(isKeyboardActive) } + await updateViewModels { await $0.updateScreenValue(isKeyboardActive: isKeyboardActive) } }} func onTap() { if tapOutsideClosesPopup { popupManager.stack(.removeLastPopup) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index efa72f6df8..2be3f2ebfe 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -60,15 +60,8 @@ extension ViewModel { withAnimation(.transition) { objectWillChange.send() } }} - @MainActor func updateScreenValue(_ screenReader: GeometryProxy) async { Task { @MainActor in - screen.update(screenReader) - activePopup.outerPadding = await calculateActivePopupOuterPadding() - activePopup.innerPadding = await calculateActivePopupInnerPadding() - - withAnimation(.transition) { objectWillChange.send() } - }} - @MainActor func updateKeyboardValue(_ isActive: Bool) async { Task { @MainActor in - screen.isKeyboardActive = isActive + @MainActor func updateScreenValue(screenReader: GeometryProxy? = nil, isKeyboardActive: Bool? = nil) async { Task { @MainActor in + screen.update(screenReader: screenReader, isKeyboardActive: isKeyboardActive) activePopup.outerPadding = await calculateActivePopupOuterPadding() activePopup.innerPadding = await calculateActivePopupInnerPadding() From 7f9327e8bad4e35b017779f63a4585afe5a1d2b0 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 14:08:59 +0100 Subject: [PATCH 171/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 2a98c2eb38..f29c3179c0 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -226,7 +226,7 @@ extension VM.VerticalStack { // MARK: Z Index extension VM.VerticalStack { - func calculateZIndex() -> CGFloat { + @MainActor func calculateZIndex() -> CGFloat { popups.last == nil ? 2137 : .init(popups.count) } } From a86e7c9dffcb3a4ca79dcfdf4c4148492f3f9971 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 14:20:16 +0100 Subject: [PATCH 172/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 2be3f2ebfe..93447918a7 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -26,7 +26,6 @@ protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == Obs // MARK: Initializers init() - init(_ config: Config.Type) // MARK: Methods func calculateActivePopupHeight() async -> CGFloat? From 505a3ed21e9abad7decf416d5b00fa637d50d5da Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 16:23:11 +0100 Subject: [PATCH 173/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 93447918a7..7de8754be1 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -34,7 +34,6 @@ protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == Obs func calculateActivePopupCorners() async -> [PopupAlignment: CGFloat] func calculateActivePopupVerticalFixedSize() async -> Bool func calculateActivePopupTranslationProgress() async -> CGFloat - func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat } From 7a47b846cf0d7c185a6cb287661bce801a21d436 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 16:24:17 +0100 Subject: [PATCH 174/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 7de8754be1..ef58f8013e 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -13,7 +13,7 @@ import SwiftUI import Combine enum VM {} -protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == ObservableObjectPublisher { +protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == ObservableObjectPublisher { init() // MARK: Attributes var alignment: PopupAlignment { get set } var popups: [AnyPopup] { get set } @@ -24,9 +24,6 @@ protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == Obs var updatePopupAction: ((AnyPopup) async -> ())! { get set } var closePopupAction: ((AnyPopup) async -> ())! { get set } - // MARK: Initializers - init() - // MARK: Methods func calculateActivePopupHeight() async -> CGFloat? func calculateActivePopupInnerPadding() async -> EdgeInsets From 8a1559432029dfd31740813c399c8432f7fa18b7 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 17:06:18 +0100 Subject: [PATCH 175/407] 1 --- .../Configurables/Local/LocalConfig+Vertical.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift index 77fac00eba..25110e95e7 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift @@ -27,6 +27,11 @@ public class LocalConfigVertical: LocalConfig { required public init() {} } // MARK: Subclasses & Typealiases +public extension LocalConfigVertical { + class Top: LocalConfigVertical {} + class Bottom: LocalConfigVertical {} +} + /** Configures the popup. See the list of available methods in ``LocalConfig`` and ``LocalConfig/Vertical``. @@ -42,10 +47,6 @@ public typealias TopPopupConfig = LocalConfigVertical.Top - important: If a certain method is not called here, the popup inherits the configuration from ``GlobalConfigContainer``. */ public typealias BottomPopupConfig = LocalConfigVertical.Bottom -public extension LocalConfigVertical { - class Top: LocalConfigVertical {} - class Bottom: LocalConfigVertical {} -} From 1a4ac90b03bb0123c64d10048fd5ffcd686268c0 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 17:44:35 +0100 Subject: [PATCH 176/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 6 +++--- .../Internal/View Models/ViewModel+VerticalStack.swift | 4 +--- Sources/Internal/View Models/ViewModel.swift | 8 +++----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index f8ee602532..6d2eabae35 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -14,8 +14,8 @@ import SwiftUI struct AnyPopup: Popup { private(set) var id: PopupID private(set) var config: AnyPopupConfig - var height: CGFloat? = nil - var dragHeight: CGFloat? = nil + private(set) var height: CGFloat? = nil + private(set) var dragHeight: CGFloat? = nil private var dismissTimer: PopupActionScheduler? = nil private var _body: AnyView @@ -52,7 +52,7 @@ extension AnyPopup { func settingDragHeight(_ newDragHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.dragHeight = newDragHeight }} func settingEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updatingPopup { $0._body = .init(_body.environmentObject(environmentObject)) }} } -extension AnyPopup { +private extension AnyPopup { func updatingPopup(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { var popup = self customBuilder(&popup) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index f29c3179c0..c5aa68e9fc 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -418,9 +418,7 @@ private extension VM.VerticalStack { targetHeight - activePopupHeight } @MainActor func updateDragHeight(_ targetDragHeight: CGFloat) async { if let activePopup = popups.last { - var newPopup = activePopup - newPopup.dragHeight = targetDragHeight - await updatePopupAction(newPopup) + await updatePopupAction(activePopup.settingDragHeight(targetDragHeight)) }} @MainActor func resetGestureTranslation() async { await updateGestureTranslation(0) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index ef58f8013e..776657cb1d 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -65,12 +65,10 @@ extension ViewModel { @MainActor func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { Task { @MainActor in guard activePopup.gestureTranslation == 0 else { return } + let newHeight = await calculatePopupHeight(heightCandidate, popup) + guard newHeight != popup.height else { return } - var newPopup = popup - newPopup.height = await calculatePopupHeight(heightCandidate, newPopup) - - guard newPopup.height != popup.height else { return } - await updatePopupAction(newPopup) + await updatePopupAction(popup.settingHeight(newHeight)) }} @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { Task { @MainActor in activePopup.gestureTranslation = newGestureTranslation From 7ee56500eaf7748912a97fdaa1a4e244d22e87fc Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 17:46:11 +0100 Subject: [PATCH 177/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 6d2eabae35..1e48c3a9e6 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -25,11 +25,11 @@ struct AnyPopup: Popup { -// MARK: - INITIALISE & UPDATE +// MARK: - INITIALIZE & UPDATE -// MARK: Initialise +// MARK: Initialize extension AnyPopup { init(_ popup: P) { if let popup = popup as? AnyPopup { self = popup } From a9012895202c221da7bd26760035bc25bcb75981 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 17:46:52 +0100 Subject: [PATCH 178/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 1e48c3a9e6..b063666a83 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -17,7 +17,7 @@ struct AnyPopup: Popup { private(set) var height: CGFloat? = nil private(set) var dragHeight: CGFloat? = nil - private var dismissTimer: PopupActionScheduler? = nil + private var _dismissTimer: PopupActionScheduler? = nil private var _body: AnyView private let _onFocus: () -> () private let _onDismiss: () -> () @@ -46,8 +46,8 @@ extension AnyPopup { // MARK: Update extension AnyPopup { func settingCustomID(_ customID: String) -> AnyPopup { updatingPopup { $0.id = .create(from: customID) }} - func settingDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updatingPopup { $0.dismissTimer = .prepare(time: secondsToDismiss) }} - func startingDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updatingPopup { $0.dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} + func settingDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updatingPopup { $0._dismissTimer = .prepare(time: secondsToDismiss) }} + func startingDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updatingPopup { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} func settingHeight(_ newHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.height = newHeight }} func settingDragHeight(_ newDragHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.dragHeight = newDragHeight }} func settingEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updatingPopup { $0._body = .init(_body.environmentObject(environmentObject)) }} @@ -94,7 +94,7 @@ extension AnyPopup { config: .init(config), height: nil, dragHeight: nil, - dismissTimer: nil, + _dismissTimer: nil, _body: .init(EmptyView()), _onFocus: {}, _onDismiss: {} From 4c0c852bcba78967284e6cc0167b0ce71227c94e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 17:59:14 +0100 Subject: [PATCH 179/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index b063666a83..ebf5db52fb 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -45,19 +45,25 @@ extension AnyPopup { // MARK: Update extension AnyPopup { - func settingCustomID(_ customID: String) -> AnyPopup { updatingPopup { $0.id = .create(from: customID) }} - func settingDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updatingPopup { $0._dismissTimer = .prepare(time: secondsToDismiss) }} - func startingDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updatingPopup { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} - func settingHeight(_ newHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.height = newHeight }} - func settingDragHeight(_ newDragHeight: CGFloat?) -> AnyPopup { updatingPopup { $0.dragHeight = newDragHeight }} - func settingEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updatingPopup { $0._body = .init(_body.environmentObject(environmentObject)) }} + nonisolated func settingHeight(_ newHeight: CGFloat?) async -> AnyPopup { await updatedAsync { $0.height = newHeight }} + nonisolated func settingDragHeight(_ newDragHeight: CGFloat?) async -> AnyPopup { await updatedAsync { $0.dragHeight = newDragHeight }} + + func settingCustomID(_ customID: String) -> AnyPopup { updated { $0.id = .create(from: customID) }} + func settingDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} + func startingDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} + func settingEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} } private extension AnyPopup { - func updatingPopup(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { + func updated(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { var popup = self customBuilder(&popup) return popup } + nonisolated func updatedAsync(_ customBuilder: (inout AnyPopup) async -> ()) async -> AnyPopup { + var popup = self + await customBuilder(&popup) + return popup + } } From 77914c619ba323abb4d3ee2789c721d5810c2121 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 18:01:42 +0100 Subject: [PATCH 180/407] 1 --- Sources/Internal/Managers/PopupManager.swift | 2 +- Sources/Internal/Models/AnyPopup.swift | 13 ++++++------- .../View Models/ViewModel+VerticalStack.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 2 +- Sources/Public/Present/Public+Present+Popup.swift | 6 +++--- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Sources/Internal/Managers/PopupManager.swift b/Sources/Internal/Managers/PopupManager.swift index 9a023935a0..6b9665cc65 100644 --- a/Sources/Internal/Managers/PopupManager.swift +++ b/Sources/Internal/Managers/PopupManager.swift @@ -71,7 +71,7 @@ private extension PopupManager { let erasedPopup = AnyPopup(popup) let canPopupBeInserted = !stack.contains(where: { $0.id.isSameType(as: erasedPopup.id) }) - if canPopupBeInserted { stack.append(erasedPopup.startingDismissTimerIfNeeded(self)) } + if canPopupBeInserted { stack.append(erasedPopup.startDismissTimerIfNeeded(self)) } } func removeLastPopup() { if !stack.isEmpty { stack.removeLast() diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index ebf5db52fb..508a2cf697 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -45,13 +45,12 @@ extension AnyPopup { // MARK: Update extension AnyPopup { - nonisolated func settingHeight(_ newHeight: CGFloat?) async -> AnyPopup { await updatedAsync { $0.height = newHeight }} - nonisolated func settingDragHeight(_ newDragHeight: CGFloat?) async -> AnyPopup { await updatedAsync { $0.dragHeight = newDragHeight }} - - func settingCustomID(_ customID: String) -> AnyPopup { updated { $0.id = .create(from: customID) }} - func settingDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} - func startingDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} - func settingEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} + nonisolated func updatedHeight(_ newHeight: CGFloat?) async -> AnyPopup { await updatedAsync { $0.height = newHeight }} + nonisolated func updatedDragHeight(_ newDragHeight: CGFloat?) async -> AnyPopup { await updatedAsync { $0.dragHeight = newDragHeight }} + func updatedID(_ customID: String) -> AnyPopup { updated { $0.id = .create(from: customID) }} + func updatedDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} + func updatedEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} + func startDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} } private extension AnyPopup { func updated(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index c5aa68e9fc..3e0b692d86 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -418,7 +418,7 @@ private extension VM.VerticalStack { targetHeight - activePopupHeight } @MainActor func updateDragHeight(_ targetDragHeight: CGFloat) async { if let activePopup = popups.last { - await updatePopupAction(activePopup.settingDragHeight(targetDragHeight)) + await updatePopupAction(activePopup.updatedDragHeight(targetDragHeight)) }} @MainActor func resetGestureTranslation() async { await updateGestureTranslation(0) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 776657cb1d..926c0e64f8 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -68,7 +68,7 @@ extension ViewModel { let newHeight = await calculatePopupHeight(heightCandidate, popup) guard newHeight != popup.height else { return } - await updatePopupAction(popup.settingHeight(newHeight)) + await updatePopupAction(popup.updatedHeight(newHeight)) }} @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { Task { @MainActor in activePopup.gestureTranslation = newGestureTranslation diff --git a/Sources/Public/Present/Public+Present+Popup.swift b/Sources/Public/Present/Public+Present+Popup.swift index fb3894be26..1c9cf3aee5 100644 --- a/Sources/Public/Present/Public+Present+Popup.swift +++ b/Sources/Public/Present/Public+Present+Popup.swift @@ -43,12 +43,12 @@ public extension Popup { - important: To dismiss a popup with a custom ID set, use methods ``PopupManager/dismissPopup(_:popupManagerID:)-1atvy`` or ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-55ubm`` - tip: Useful if you want to display several different popups of the same type. */ - func setCustomID(_ id: String) -> some Popup { AnyPopup(self).settingCustomID(id) } + func setCustomID(_ id: String) -> some Popup { AnyPopup(self).updatedID(id) } /** Supplies an observable object to a popup's hierarchy. */ - func setEnvironmentObject(_ object: T) -> some Popup { AnyPopup(self).settingEnvironmentObject(object) } + func setEnvironmentObject(_ object: T) -> some Popup { AnyPopup(self).updatedEnvironmentObject(object) } /** Dismisses the popup after a specified period of time. @@ -56,5 +56,5 @@ public extension Popup { - Parameters: - seconds: Time in seconds after which the popup will be closed. */ - func dismissAfter(_ seconds: Double) -> some Popup { AnyPopup(self).settingDismissTimer(seconds) } + func dismissAfter(_ seconds: Double) -> some Popup { AnyPopup(self).updatedDismissTimer(seconds) } } From cab2b41f83e2a3b3d6fd168c0a1c88f622d8e1e4 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 18:21:25 +0100 Subject: [PATCH 181/407] 1 --- Sources/Internal/Extensions/View+ReadHeight.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Sources/Internal/Extensions/View+ReadHeight.swift b/Sources/Internal/Extensions/View+ReadHeight.swift index 28d10e980a..04b9e9a07d 100644 --- a/Sources/Internal/Extensions/View+ReadHeight.swift +++ b/Sources/Internal/Extensions/View+ReadHeight.swift @@ -14,10 +14,7 @@ import SwiftUI extension View { func onHeightChange(perform action: @escaping (CGFloat) async -> ()) -> some View { background( GeometryReader { proxy in - Task { @MainActor in - try await Task.sleep(nanoseconds: 10_000_000) - await action(proxy.size.height) - } + Task { @MainActor in await action(proxy.size.height) } return Color.clear } )} From 73b72a6746c68015338b364bbb99d92f36c0f55e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 19:16:26 +0100 Subject: [PATCH 182/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 6 +++--- Sources/Internal/Models/ID+Popup.swift | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 508a2cf697..5f529e3a85 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -34,7 +34,7 @@ extension AnyPopup { init(_ popup: P) { if let popup = popup as? AnyPopup { self = popup } else { - self.id = .create(from: P.self) + self.id = .init(P.self) self.config = .init(popup.configurePopup(config: .init())) self._body = .init(popup) self._onFocus = popup.onFocus @@ -47,7 +47,7 @@ extension AnyPopup { extension AnyPopup { nonisolated func updatedHeight(_ newHeight: CGFloat?) async -> AnyPopup { await updatedAsync { $0.height = newHeight }} nonisolated func updatedDragHeight(_ newDragHeight: CGFloat?) async -> AnyPopup { await updatedAsync { $0.dragHeight = newDragHeight }} - func updatedID(_ customID: String) -> AnyPopup { updated { $0.id = .create(from: customID) }} + func updatedID(_ customID: String) -> AnyPopup { updated { $0.id = .init(customID) }} func updatedDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} func updatedEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} func startDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} @@ -95,7 +95,7 @@ extension AnyPopup: Hashable { // MARK: New Object extension AnyPopup { static func t_createNew(id: String = UUID().uuidString, config: LocalConfig) -> AnyPopup { .init( - id: .create(from: id), + id: .init(id), config: .init(config), height: nil, dragHeight: nil, diff --git a/Sources/Internal/Models/ID+Popup.swift b/Sources/Internal/Models/ID+Popup.swift index e01b899ded..bb1fcfa551 100644 --- a/Sources/Internal/Models/ID+Popup.swift +++ b/Sources/Internal/Models/ID+Popup.swift @@ -17,14 +17,14 @@ struct PopupID { // MARK: Create extension PopupID { - static func create(from id: String) -> Self { + init(_ id: String) { let firstComponent = id, - secondComponent = separator, + secondComponent = Self.separator, thirdComponent = String(describing: Date()) - return .init(rawValue: firstComponent + secondComponent + thirdComponent) + self.init(rawValue: firstComponent + secondComponent + thirdComponent) } - static func create(from popupType: any Popup.Type) -> Self { - create(from: .init(describing: popupType)) + init(_ popupType: any Popup.Type) { + self.init(.init(describing: popupType)) } } From 77860364407617867f13839d1dfaf2b1f5e039ca Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 19:18:28 +0100 Subject: [PATCH 183/407] 1 --- Sources/Internal/Extensions/View+ReadHeight.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/Internal/Extensions/View+ReadHeight.swift b/Sources/Internal/Extensions/View+ReadHeight.swift index 04b9e9a07d..28d10e980a 100644 --- a/Sources/Internal/Extensions/View+ReadHeight.swift +++ b/Sources/Internal/Extensions/View+ReadHeight.swift @@ -14,7 +14,10 @@ import SwiftUI extension View { func onHeightChange(perform action: @escaping (CGFloat) async -> ()) -> some View { background( GeometryReader { proxy in - Task { @MainActor in await action(proxy.size.height) } + Task { @MainActor in + try await Task.sleep(nanoseconds: 10_000_000) + await action(proxy.size.height) + } return Color.clear } )} From 62ac4b5bcd27a5d889df8c0852be74bf6040caa2 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 19:33:33 +0100 Subject: [PATCH 184/407] 1 --- Sources/Internal/Extensions/View+Keyboard.swift | 6 +++--- Sources/Internal/Managers/PopupManager.swift | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/Extensions/View+Keyboard.swift b/Sources/Internal/Extensions/View+Keyboard.swift index e57e92d6f7..1a45401cd8 100644 --- a/Sources/Internal/Extensions/View+Keyboard.swift +++ b/Sources/Internal/Extensions/View+Keyboard.swift @@ -41,11 +41,11 @@ fileprivate extension View { // MARK: Hide Keyboard extension AnyView { - @MainActor static func hideKeyboard() { + nonisolated static func hideKeyboard() async { #if os(iOS) - UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) + await UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) #elseif os(macOS) - NSApp.keyWindow?.makeFirstResponder(nil) + await NSApp.keyWindow?.makeFirstResponder(nil) #endif } } diff --git a/Sources/Internal/Managers/PopupManager.swift b/Sources/Internal/Managers/PopupManager.swift index 6b9665cc65..9a48467ad8 100644 --- a/Sources/Internal/Managers/PopupManager.swift +++ b/Sources/Internal/Managers/PopupManager.swift @@ -47,9 +47,9 @@ extension PopupManager { } } private extension PopupManager { - func hideKeyboard() { - AnyView.hideKeyboard() - } + func hideKeyboard() { Task { + await AnyView.hideKeyboard() + }} func perform(_ operation: StackOperation) { switch operation { case .insertPopup(let popup): insertPopup(popup) case .removeLastPopup: removeLastPopup() From 44c12e6f281938141479a8d2f24fafcb1c57cabe Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 20:22:53 +0100 Subject: [PATCH 185/407] 1 --- {Tests => Sources/Internal}/Extensions/Task++.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename {Tests => Sources/Internal}/Extensions/Task++.swift (90%) diff --git a/Tests/Extensions/Task++.swift b/Sources/Internal/Extensions/Task++.swift similarity index 90% rename from Tests/Extensions/Task++.swift rename to Sources/Internal/Extensions/Task++.swift index 62f5d9e2ed..7b70c6cf35 100644 --- a/Tests/Extensions/Task++.swift +++ b/Sources/Internal/Extensions/Task++.swift @@ -12,7 +12,7 @@ import SwiftUI extension Task where Success == Never, Failure == Never { - static func sleep(seconds: Double) async { + static func sleep(seconds: CGFloat) async { try! await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000)) } } From af8d5bd84286f70ffa2fcebe66c0a96b77417e24 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 10 Nov 2024 20:33:47 +0100 Subject: [PATCH 186/407] DANGER --- Sources/Internal/Managers/PopupManager.swift | 34 ++++++++----------- Sources/Internal/Models/AnyPopup.swift | 2 +- Sources/Internal/UI/PopupView.swift | 6 ++-- .../Dismiss/Public+Dismiss+PopupManager.swift | 8 ++--- .../Public/Present/Public+Present+Popup.swift | 2 +- 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/Sources/Internal/Managers/PopupManager.swift b/Sources/Internal/Managers/PopupManager.swift index 9a48467ad8..fd2ee6dc33 100644 --- a/Sources/Internal/Managers/PopupManager.swift +++ b/Sources/Internal/Managers/PopupManager.swift @@ -34,23 +34,23 @@ extension PopupManager { // MARK: Available Operations extension PopupManager { enum StackOperation { - case insertPopup(any Popup) + case insertPopup(AnyPopup) case removeLastPopup, removePopupInstance(AnyPopup), removeAllPopupsOfType(any Popup.Type), removeAllPopupsWithID(String), removeAllPopups }} // MARK: Perform Operation extension PopupManager { - func stack(_ operation: StackOperation) { let oldStackCount = stack.count - hideKeyboard() - perform(operation) - reshuffleStackPriority(oldStackCount) + func stack(_ operation: StackOperation) async { let oldStackCount = stack.count + await hideKeyboard() + await perform(operation) + await reshuffleStackPriority(oldStackCount) } } private extension PopupManager { - func hideKeyboard() { Task { + func hideKeyboard() async { await AnyView.hideKeyboard() - }} - func perform(_ operation: StackOperation) { switch operation { + } + func perform(_ operation: StackOperation) async { switch operation { case .insertPopup(let popup): insertPopup(popup) case .removeLastPopup: removeLastPopup() case .removePopupInstance(let popup): removePopupInstance(popup) @@ -58,21 +58,17 @@ private extension PopupManager { case .removeAllPopupsWithID(let id): removeAllPopupsWithID(id) case .removeAllPopups: removeAllPopups() }} - func reshuffleStackPriority(_ oldStackCount: Int) { + func reshuffleStackPriority(_ oldStackCount: Int) async { let delayDuration = oldStackCount > stack.count ? Animation.duration : 0 - - DispatchQueue.main.asyncAfter(deadline: .now() + delayDuration) { [self] in - stackPriority.reshuffle(newPopups: stack) - } + await Task.sleep(seconds: delayDuration) + + stackPriority.reshuffle(newPopups: stack) } } private extension PopupManager { - func insertPopup(_ popup: any Popup) { - let erasedPopup = AnyPopup(popup) - let canPopupBeInserted = !stack.contains(where: { $0.id.isSameType(as: erasedPopup.id) }) - - if canPopupBeInserted { stack.append(erasedPopup.startDismissTimerIfNeeded(self)) } - } + func insertPopup(_ erasedPopup: AnyPopup) { if !stack.contains(where: { $0.id.isSameType(as: erasedPopup.id) }) { + stack.append(erasedPopup.startDismissTimerIfNeeded(self)) + }} func removeLastPopup() { if !stack.isEmpty { stack.removeLast() }} diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 5f529e3a85..919e566d28 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -50,7 +50,7 @@ extension AnyPopup { func updatedID(_ customID: String) -> AnyPopup { updated { $0.id = .init(customID) }} func updatedDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} func updatedEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} - func startDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} + func startDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updated { $0._dismissTimer?.schedule { Task { await popupManager.stack(.removePopupInstance(self)) }}}} } private extension AnyPopup { func updated(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index b9480332ce..a9a6a791c8 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -103,9 +103,9 @@ private extension PopupView { func onKeyboardStateChange(_ isKeyboardActive: Bool) { Task { @MainActor in await updateViewModels { await $0.updateScreenValue(isKeyboardActive: isKeyboardActive) } }} - func onTap() { if tapOutsideClosesPopup { - popupManager.stack(.removeLastPopup) - }} + func onTap() { if tapOutsideClosesPopup { Task { + await popupManager.stack(.removeLastPopup) + }}} } private extension PopupView { nonisolated func updatePopup(_ popup: AnyPopup) async { diff --git a/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift b/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift index ba9b81a243..b3d2bbe844 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift @@ -21,7 +21,7 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - static func dismissLastPopup(popupManagerID: PopupManagerID = .shared) { fetchInstance(id: popupManagerID)?.stack(.removeLastPopup) } + static func dismissLastPopup(popupManagerID: PopupManagerID = .shared) { Task { await fetchInstance(id: popupManagerID)?.stack(.removeLastPopup) }} /** Removes all popups with the specified identifier from the stack. @@ -32,7 +32,7 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - static func dismissPopup(_ id: String, popupManagerID: PopupManagerID = .shared) { fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsWithID(id)) } + static func dismissPopup(_ id: String, popupManagerID: PopupManagerID = .shared) { Task { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsWithID(id)) }} /** Removes all popups of the provided type from the stack. @@ -44,7 +44,7 @@ public extension PopupManager { - Important: If a custom ID (``Popup/setCustomID(_:)``) is set for the popup, use the ``dismissPopup(_:popupManagerID:)-1atvy`` method instead. - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - static func dismissPopup(_ type: P.Type, popupManagerID: PopupManagerID = .shared) { fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsOfType(type)) } + static func dismissPopup(_ type: P.Type, popupManagerID: PopupManagerID = .shared) { Task { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsOfType(type)) }} /** Removes all popups from the stack. @@ -54,5 +54,5 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popups. */ - static func dismissAllPopups(popupManagerID: PopupManagerID = .shared) { fetchInstance(id: popupManagerID)?.stack(.removeAllPopups) } + static func dismissAllPopups(popupManagerID: PopupManagerID = .shared) { Task { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopups) }} } diff --git a/Sources/Public/Present/Public+Present+Popup.swift b/Sources/Public/Present/Public+Present+Popup.swift index 1c9cf3aee5..889fe55176 100644 --- a/Sources/Public/Present/Public+Present+Popup.swift +++ b/Sources/Public/Present/Public+Present+Popup.swift @@ -32,7 +32,7 @@ public extension Popup { - 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)) } + func present(popupManagerID: PopupManagerID = .shared) { Task { await PopupManager.fetchInstance(id: popupManagerID)?.stack(.insertPopup(.init(self))) }} } // MARK: Configure Popup From 0390a03af645c8baf6427431693066f8f8ead6ed Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Mon, 11 Nov 2024 15:34:08 +0100 Subject: [PATCH 187/407] 1 --- Sources/Internal/Extensions/Array++.swift | 6 +++++- Sources/Internal/Models/StackPriority.swift | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/Extensions/Array++.swift b/Sources/Internal/Extensions/Array++.swift index 49e1dd99f0..655dee66bb 100644 --- a/Sources/Internal/Extensions/Array++.swift +++ b/Sources/Internal/Extensions/Array++.swift @@ -10,5 +10,9 @@ extension Array { - @inlinable func appending(_ newElement: Element) -> Self { self + [newElement] } + func modified(if value: Bool = true, _ builder: (inout [Element]) async -> ()) async -> [Element] { guard value else { return self } + var array = self + await builder(&array) + return array + } } diff --git a/Sources/Internal/Models/StackPriority.swift b/Sources/Internal/Models/StackPriority.swift index d891a878e5..416352c075 100644 --- a/Sources/Internal/Models/StackPriority.swift +++ b/Sources/Internal/Models/StackPriority.swift @@ -11,7 +11,7 @@ import Foundation -struct StackPriority: Equatable { +struct StackPriority: Equatable, Sendable { var top: CGFloat { values[0] } var centre: CGFloat { values[1] } var bottom: CGFloat { values[2] } From 05e8534da824ca77cacebf541e00e0ca5cf9c2eb Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Mon, 11 Nov 2024 15:34:51 +0100 Subject: [PATCH 188/407] 1 --- Sources/Internal/Models/StackPriority.swift | 18 +++++++++--------- .../View Models/ViewModel+VerticalStack.swift | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/Internal/Models/StackPriority.swift b/Sources/Internal/Models/StackPriority.swift index 416352c075..6296030d98 100644 --- a/Sources/Internal/Models/StackPriority.swift +++ b/Sources/Internal/Models/StackPriority.swift @@ -20,21 +20,21 @@ struct StackPriority: Equatable, Sendable { private var values: [CGFloat] = [0, 0, 0] } -// MARK: Reshuffle +// MARK: Reshuffled extension StackPriority { - @MainActor mutating func reshuffle(newPopups: [AnyPopup]) { switch newPopups.last?.config.alignment { - case .top: reshuffle(0) - case .centre: reshuffle(1) - case .bottom: reshuffle(2) - default: return + func reshuffled(_ newPopups: [AnyPopup]) -> StackPriority { switch newPopups.last?.config.alignment { + case .top: reshuffled(0) + case .centre: reshuffled(1) + case .bottom: reshuffled(2) + default: self }} } private extension StackPriority { - mutating func reshuffle(_ index: Int) { - guard values[index] != maxPriority else { return } + func reshuffled(_ index: Int) -> StackPriority { + guard values[index] != maxPriority else { return self } let newValues = values.enumerated().map { $0.offset == index ? maxPriority : $0.element - 2 } - values = newValues + return .init(values: newValues) } } private extension StackPriority { diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 3e0b692d86..59f18b75ea 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -386,14 +386,14 @@ private extension VM.VerticalStack { return currentPopupHeight } func calculatePopupTargetHeightsFromDragDetents(_ activePopupHeight: CGFloat) async -> [CGFloat] { guard let dragDetents = popups.last?.config.dragDetents else { return [activePopupHeight] }; return - dragDetents + await dragDetents .map { switch $0 { case .height(let targetHeight): min(targetHeight, calculateLargeScreenHeight()) case .fraction(let fraction): min(fraction * activePopupHeight, calculateLargeScreenHeight()) case .large: calculateLargeScreenHeight() case .fullscreen: screen.height }} - .appending(activePopupHeight) + .modified { $0.append(activePopupHeight) } .sorted(by: <) } func calculateTargetPopupHeight(_ currentPopupHeight: CGFloat, _ popupTargetHeights: [CGFloat]) async -> CGFloat { From 6d1f06b9978d22bdc067ea88cfb30246cbc7316e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Mon, 11 Nov 2024 15:53:25 +0100 Subject: [PATCH 189/407] 1 --- Sources/Internal/Managers/PopupManager.swift | 71 +++++++++++--------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/Sources/Internal/Managers/PopupManager.swift b/Sources/Internal/Managers/PopupManager.swift index fd2ee6dc33..fa9ad9fd07 100644 --- a/Sources/Internal/Managers/PopupManager.swift +++ b/Sources/Internal/Managers/PopupManager.swift @@ -40,49 +40,60 @@ extension PopupManager { enum StackOperation { // MARK: Perform Operation extension PopupManager { - func stack(_ operation: StackOperation) async { let oldStackCount = stack.count + func stack(_ operation: StackOperation) async { await hideKeyboard() - await perform(operation) - await reshuffleStackPriority(oldStackCount) + + let oldStack = stack, + newStack = await getNewStack(operation), + newStackPriority = await getNewStackPriority(newStack) + + await updateStack(newStack) + await updateStackPriority(newStackPriority, oldStack.count) } } private extension PopupManager { - func hideKeyboard() async { + nonisolated func hideKeyboard() async { await AnyView.hideKeyboard() } - func perform(_ operation: StackOperation) async { switch operation { - case .insertPopup(let popup): insertPopup(popup) - case .removeLastPopup: removeLastPopup() - case .removePopupInstance(let popup): removePopupInstance(popup) - case .removeAllPopupsOfType(let popupType): removeAllPopupsOfType(popupType) - case .removeAllPopupsWithID(let id): removeAllPopupsWithID(id) - case .removeAllPopups: removeAllPopups() + nonisolated func getNewStack(_ operation: StackOperation) async -> [AnyPopup] { switch operation { + case .insertPopup(let popup): await insertedPopup(popup) + case .removeLastPopup: await removedLastPopup() + case .removePopupInstance(let popup): await removedPopupInstance(popup) + case .removeAllPopupsOfType(let popupType): await removedAllPopupsOfType(popupType) + case .removeAllPopupsWithID(let id): await removedAllPopupsWithID(id) + case .removeAllPopups: await removedAllPopups() }} - func reshuffleStackPriority(_ oldStackCount: Int) async { - let delayDuration = oldStackCount > stack.count ? Animation.duration : 0 + nonisolated func getNewStackPriority(_ newStack: [AnyPopup]) async -> StackPriority { + await stackPriority.reshuffled(newStack) + } + nonisolated func updateStack(_ newStack: [AnyPopup]) async { + Task { @MainActor in stack = newStack } + } + nonisolated func updateStackPriority(_ newStackPriority: StackPriority, _ oldStackCount: Int) async { + let delayDuration = await oldStackCount > stack.count ? Animation.duration : 0 await Task.sleep(seconds: delayDuration) - - stackPriority.reshuffle(newPopups: stack) + + Task { @MainActor in stackPriority = newStackPriority } } } private extension PopupManager { - func insertPopup(_ erasedPopup: AnyPopup) { if !stack.contains(where: { $0.id.isSameType(as: erasedPopup.id) }) { - stack.append(erasedPopup.startDismissTimerIfNeeded(self)) + nonisolated func insertedPopup(_ erasedPopup: AnyPopup) async -> [AnyPopup] { await stack.modified(if: await !stack.contains { $0.id.isSameType(as: erasedPopup.id) }) { + $0.append(await erasedPopup.startDismissTimerIfNeeded(self)) }} - func removeLastPopup() { if !stack.isEmpty { - stack.removeLast() + nonisolated func removedLastPopup() async -> [AnyPopup] { await stack.modified(if: !stack.isEmpty) { + $0.removeLast() }} - func removePopupInstance(_ popup: AnyPopup) { - stack.removeAll(where: { $0.id.isSameInstance(as: popup) }) - } - func removeAllPopupsOfType(_ popupType: any Popup.Type) { - stack.removeAll(where: { $0.id.isSameType(as: popupType) }) - } - func removeAllPopupsWithID(_ id: String) { - stack.removeAll(where: { $0.id.isSameType(as: id) }) - } - func removeAllPopups() { - stack.removeAll() + nonisolated func removedPopupInstance(_ popup: AnyPopup) async -> [AnyPopup] { await stack.modified { + $0.removeAll { $0.id.isSameInstance(as: popup) } + }} + nonisolated func removedAllPopupsOfType(_ popupType: any Popup.Type) async -> [AnyPopup] { await stack.modified { + $0.removeAll { $0.id.isSameType(as: popupType) } + }} + nonisolated func removedAllPopupsWithID(_ id: String) async -> [AnyPopup] { await stack.modified { + $0.removeAll { $0.id.isSameType(as: id) } + }} + nonisolated func removedAllPopups() async -> [AnyPopup] { + [] } } From 99b3b4d1bf637a491b9465b09603030c8d08f84b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Mon, 11 Nov 2024 16:00:05 +0100 Subject: [PATCH 190/407] 1 --- Sources/Internal/Managers/PopupManager.swift | 6 +++--- Sources/Internal/Models/AnyPopup.swift | 2 +- Sources/Internal/UI/PopupView.swift | 6 +++--- Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift | 8 ++++---- Sources/Public/Present/Public+Present+Popup.swift | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/Internal/Managers/PopupManager.swift b/Sources/Internal/Managers/PopupManager.swift index fa9ad9fd07..7959fb4040 100644 --- a/Sources/Internal/Managers/PopupManager.swift +++ b/Sources/Internal/Managers/PopupManager.swift @@ -40,16 +40,16 @@ extension PopupManager { enum StackOperation { // MARK: Perform Operation extension PopupManager { - func stack(_ operation: StackOperation) async { + nonisolated func stack(_ operation: StackOperation) { Task { await hideKeyboard() - let oldStack = stack, + let oldStack = await stack, newStack = await getNewStack(operation), newStackPriority = await getNewStackPriority(newStack) await updateStack(newStack) await updateStackPriority(newStackPriority, oldStack.count) - } + }} } private extension PopupManager { nonisolated func hideKeyboard() async { diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 919e566d28..5f529e3a85 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -50,7 +50,7 @@ extension AnyPopup { func updatedID(_ customID: String) -> AnyPopup { updated { $0.id = .init(customID) }} func updatedDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} func updatedEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} - func startDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updated { $0._dismissTimer?.schedule { Task { await popupManager.stack(.removePopupInstance(self)) }}}} + func startDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} } private extension AnyPopup { func updated(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index a9a6a791c8..b9480332ce 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -103,9 +103,9 @@ private extension PopupView { func onKeyboardStateChange(_ isKeyboardActive: Bool) { Task { @MainActor in await updateViewModels { await $0.updateScreenValue(isKeyboardActive: isKeyboardActive) } }} - func onTap() { if tapOutsideClosesPopup { Task { - await popupManager.stack(.removeLastPopup) - }}} + func onTap() { if tapOutsideClosesPopup { + popupManager.stack(.removeLastPopup) + }} } private extension PopupView { nonisolated func updatePopup(_ popup: AnyPopup) async { diff --git a/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift b/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift index b3d2bbe844..ba9b81a243 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift @@ -21,7 +21,7 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - static func dismissLastPopup(popupManagerID: PopupManagerID = .shared) { Task { await fetchInstance(id: popupManagerID)?.stack(.removeLastPopup) }} + static func dismissLastPopup(popupManagerID: PopupManagerID = .shared) { fetchInstance(id: popupManagerID)?.stack(.removeLastPopup) } /** Removes all popups with the specified identifier from the stack. @@ -32,7 +32,7 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - static func dismissPopup(_ id: String, popupManagerID: PopupManagerID = .shared) { Task { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsWithID(id)) }} + static func dismissPopup(_ id: String, popupManagerID: PopupManagerID = .shared) { fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsWithID(id)) } /** Removes all popups of the provided type from the stack. @@ -44,7 +44,7 @@ public extension PopupManager { - Important: If a custom ID (``Popup/setCustomID(_:)``) is set for the popup, use the ``dismissPopup(_:popupManagerID:)-1atvy`` method instead. - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - static func dismissPopup(_ type: P.Type, popupManagerID: PopupManagerID = .shared) { Task { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsOfType(type)) }} + static func dismissPopup(_ type: P.Type, popupManagerID: PopupManagerID = .shared) { fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsOfType(type)) } /** Removes all popups from the stack. @@ -54,5 +54,5 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popups. */ - static func dismissAllPopups(popupManagerID: PopupManagerID = .shared) { Task { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopups) }} + static func dismissAllPopups(popupManagerID: PopupManagerID = .shared) { fetchInstance(id: popupManagerID)?.stack(.removeAllPopups) } } diff --git a/Sources/Public/Present/Public+Present+Popup.swift b/Sources/Public/Present/Public+Present+Popup.swift index 889fe55176..4594754d26 100644 --- a/Sources/Public/Present/Public+Present+Popup.swift +++ b/Sources/Public/Present/Public+Present+Popup.swift @@ -32,7 +32,7 @@ public extension Popup { - Warning: To present multiple popups of the same type, set a unique identifier using the method ``Popup/setCustomID(_:)``. */ - func present(popupManagerID: PopupManagerID = .shared) { Task { await PopupManager.fetchInstance(id: popupManagerID)?.stack(.insertPopup(.init(self))) }} + func present(popupManagerID: PopupManagerID = .shared) { PopupManager.fetchInstance(id: popupManagerID)?.stack(.insertPopup(.init(self))) } } // MARK: Configure Popup From 68d389fcc20a758cb11999f8c0b317bb202ba751 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Mon, 11 Nov 2024 16:02:56 +0100 Subject: [PATCH 191/407] 1 --- Sources/Internal/Extensions/View+ReadHeight.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/Internal/Extensions/View+ReadHeight.swift b/Sources/Internal/Extensions/View+ReadHeight.swift index 28d10e980a..a68ff26a49 100644 --- a/Sources/Internal/Extensions/View+ReadHeight.swift +++ b/Sources/Internal/Extensions/View+ReadHeight.swift @@ -15,7 +15,6 @@ extension View { func onHeightChange(perform action: @escaping (CGFloat) async -> ()) -> some View { background( GeometryReader { proxy in Task { @MainActor in - try await Task.sleep(nanoseconds: 10_000_000) await action(proxy.size.height) } return Color.clear From 56efc45a013135c1f5d01075d4cd519acd05d946 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Mon, 11 Nov 2024 16:05:58 +0100 Subject: [PATCH 192/407] 1 --- Sources/Internal/Containers/PopupManagerContainer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/Containers/PopupManagerContainer.swift b/Sources/Internal/Containers/PopupManagerContainer.swift index 7df41fb6ec..c9c753687d 100644 --- a/Sources/Internal/Containers/PopupManagerContainer.swift +++ b/Sources/Internal/Containers/PopupManagerContainer.swift @@ -12,7 +12,7 @@ import Foundation actor PopupManagerContainer { - nonisolated(unsafe) static private(set) var instances: [PopupManager] = [] + static private(set) var instances: [PopupManager] = [] } // MARK: Register From fd72c76f8fb1379c4446c5857a430660bf22ec77 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Mon, 11 Nov 2024 20:26:31 +0100 Subject: [PATCH 193/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 59f18b75ea..f27640d851 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -89,7 +89,7 @@ private extension VM.VerticalStack { } } private extension VM.VerticalStack { - nonisolated func calculatePriorityPopupPaddingValue(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { switch edge == alignment { + func calculatePriorityPopupPaddingValue(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { switch edge == alignment { case true: 0 case false: activePopupConfig.popupPadding[!edge] }} From 33f56c950b78e645c51bbd6aa06564bda548b3e8 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 11:51:13 +0100 Subject: [PATCH 194/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 926c0e64f8..110bf36c81 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -34,6 +34,11 @@ protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == Obs func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat } +// MARK: Initializer +extension ViewModel { + init(_ config: Config.Type) { self.init(); self.alignment = .init(Config.self) } +} + // MARK: Setup extension ViewModel { func setup(updatePopupAction: @escaping (AnyPopup) async -> (), closePopupAction: @escaping (AnyPopup) async -> ()) { @@ -87,9 +92,7 @@ private extension ViewModel { -extension ViewModel { - init(_ config: Config.Type) { self.init(); self.alignment = .init(Config.self) } -} + @@ -101,7 +104,6 @@ extension ViewModel { var outerPadding: EdgeInsets = .init() var corners: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] var verticalFixedSize: Bool = true - var gestureTranslation: CGFloat = 0 var translationProgress: CGFloat = 0 } From 636c282a296ee84948ed7cddaf692926132c67b6 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:01:56 +0100 Subject: [PATCH 195/407] 1 --- .../View Models/ViewModel+CentreStack.swift | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index c6a425f7fe..0ea20f81ea 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -22,7 +22,35 @@ extension VM { class CentreStack: ViewModel { required init() {} -// MARK: - VIEW METHODS +// MARK: - VIEW METHODS (ACTIVE POPUP) + + + +// MARK: Height + + + +// MARK: Inner Padding + + +// MARK: Outer Padding + + +// MARK: Corners + + + +// MARK: Vertical Fixed Size + + + +// MARK: Translation Progress + + + + + + From 1560be494a863c7a5a315ef5d0032f3859e87a60 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:04:22 +0100 Subject: [PATCH 196/407] 1 --- .../View Models/ViewModel+CentreStack.swift | 86 +++++++------------ 1 file changed, 33 insertions(+), 53 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 0ea20f81ea..09291ade47 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -27,45 +27,15 @@ extension VM { class CentreStack: ViewModel { required init() {} // MARK: Height - - - -// MARK: Inner Padding - - -// MARK: Outer Padding - - -// MARK: Corners - - - -// MARK: Vertical Fixed Size - - - -// MARK: Translation Progress - - - - - - - - - -// MARK: Popup Height extension VM.CentreStack { - func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { - min(heightCandidate, calculateLargeScreenHeight()) + func calculateActivePopupHeight() async -> CGFloat? { + popups.last?.height } } -private extension VM.CentreStack { - func calculateLargeScreenHeight() -> CGFloat { - let fullscreenHeight = screen.height, - safeAreaHeight = screen.safeArea.top + screen.safeArea.bottom - return fullscreenHeight - safeAreaHeight - } + +// MARK: Inner Padding +extension VM.CentreStack { + func calculateActivePopupInnerPadding() async -> EdgeInsets { .init() } } // MARK: Outer Padding @@ -95,12 +65,7 @@ private extension VM.CentreStack { } } -// MARK: Inner Padding -extension VM.CentreStack { - func calculateActivePopupInnerPadding() async -> EdgeInsets { .init() } -} - -// MARK: Corner Radius +// MARK: Corners extension VM.CentreStack { func calculateActivePopupCorners() async -> [PopupAlignment : CGFloat] { [ .top: popups.last?.config.cornerRadius ?? 0, @@ -108,14 +73,7 @@ extension VM.CentreStack { ]} } -// MARK: Opacity -extension VM.CentreStack { - func calculateOpacity(for popup: AnyPopup) -> CGFloat { - popups.last == popup ? 1 : 0 - } -} - -// MARK: Fixed Size +// MARK: Vertical Fixed Size extension VM.CentreStack { func calculateActivePopupVerticalFixedSize() async -> Bool { await activePopup.height != calculateLargeScreenHeight() @@ -127,9 +85,31 @@ extension VM.CentreStack { func calculateActivePopupTranslationProgress() async -> CGFloat { 0 } } -// MARK: Active Popup Height + + + + + + + +// MARK: Popup Height extension VM.CentreStack { - func calculateActivePopupHeight() async -> CGFloat? { - popups.last?.height + func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { + min(heightCandidate, calculateLargeScreenHeight()) + } +} +private extension VM.CentreStack { + func calculateLargeScreenHeight() -> CGFloat { + let fullscreenHeight = screen.height, + safeAreaHeight = screen.safeArea.top + screen.safeArea.bottom + return fullscreenHeight - safeAreaHeight + } +} + + +// MARK: Opacity +extension VM.CentreStack { + func calculateOpacity(for popup: AnyPopup) -> CGFloat { + popups.last == popup ? 1 : 0 } } From 44691a0aa518d90d18ff5c55e2b0c22c27125848 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:05:48 +0100 Subject: [PATCH 197/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 09291ade47..359f47ec6a 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -22,7 +22,7 @@ extension VM { class CentreStack: ViewModel { required init() {} -// MARK: - VIEW METHODS (ACTIVE POPUP) +// MARK: - METHODS (ACTIVE POPUP) @@ -87,12 +87,11 @@ extension VM.CentreStack { +// MARK: - METHODS (SELECTED POPUP) - - -// MARK: Popup Height +// MARK: Height extension VM.CentreStack { func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { min(heightCandidate, calculateLargeScreenHeight()) @@ -106,7 +105,6 @@ private extension VM.CentreStack { } } - // MARK: Opacity extension VM.CentreStack { func calculateOpacity(for popup: AnyPopup) -> CGFloat { From 435ce9cceaa356c7105e09873b187b0b26cd69a2 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:08:32 +0100 Subject: [PATCH 198/407] 1 --- .../Internal/View Models/ViewModel+CentreStack.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 359f47ec6a..09f19f692d 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -22,7 +22,7 @@ extension VM { class CentreStack: ViewModel { required init() {} -// MARK: - METHODS (ACTIVE POPUP) +// MARK: - METHODS / VIEW MODEL / ACTIVE POPUP @@ -87,7 +87,7 @@ extension VM.CentreStack { -// MARK: - METHODS (SELECTED POPUP) +// MARK: - METHODS / VIEW MODEL / SELECTED POPUP @@ -105,6 +105,12 @@ private extension VM.CentreStack { } } + + +// MARK: - METHODS / VIEW + + + // MARK: Opacity extension VM.CentreStack { func calculateOpacity(for popup: AnyPopup) -> CGFloat { From b817b0ee50328e01c7ef7d314de4cbf4046b1ee8 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:11:35 +0100 Subject: [PATCH 199/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index f27640d851..3df45fc4ed 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -22,7 +22,46 @@ extension VM { class VerticalStack: ViewModel { required init() {} -// MARK: - VIEW METHODS +// MARK: - METHODS / VIEW MODEL / ACTIVE POPUP + + + +// MARK: Height + + + +// MARK: Inner Padding + + + +// MARK: Outer Padding + + +// MARK: Corners + + +// MARK: Vertical Fixed Size + + +// MARK: Translation Progress + + + + + +// MARK: - METHODS / VIEW MODEL / SELECTED POPUP + + + +// MARK: Height + + + + + +// MARK: - METHODS / VIEW + + From 007263459b322d610c73fc9c00130577d9716a25 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:12:10 +0100 Subject: [PATCH 200/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 3df45fc4ed..0faef3386e 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -54,18 +54,6 @@ extension VM { class VerticalStack: ViewModel { required init() {} // MARK: Height - - - - - -// MARK: - METHODS / VIEW - - - - - -// MARK: Popup Height extension VM.VerticalStack { func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { guard await activePopup.gestureTranslation.isZero else { return popup.height ?? 0 } @@ -101,6 +89,18 @@ private extension VM.VerticalStack { } } + + + +// MARK: - METHODS / VIEW + + + + + + + + // MARK: Outer Padding extension VM.VerticalStack { func calculateActivePopupOuterPadding() async -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return await .init( From c1c1bf3196f5403a55d8bfe03e72be48e99f008a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:12:58 +0100 Subject: [PATCH 201/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 150 +++++++++--------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 0faef3386e..9a98b1d193 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -31,10 +31,85 @@ extension VM { class VerticalStack: ViewModel { required init() {} // MARK: Inner Padding +extension VM.VerticalStack { + func calculateActivePopupInnerPadding() async -> EdgeInsets { guard let popup = popups.last else { return .init() }; return await .init( + top: calculateTopBodyPadding(popup: popup), + leading: calculateLeadingBodyPadding(popup: popup), + bottom: calculateBottomBodyPadding(popup: popup), + trailing: calculateTrailingBodyPadding(popup: popup) + )} +} +private extension VM.VerticalStack { + func calculateTopBodyPadding(popup: AnyPopup) async -> CGFloat { + if popup.config.ignoredSafeAreaEdges.contains(.top) { return 0 } + return switch alignment { + case .top: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupPadding: activePopup.outerPadding.top) + case .bottom: await calculateVerticalPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.top) + case .centre: fatalError() + } + } + func calculateBottomBodyPadding(popup: AnyPopup) async -> CGFloat { + if popup.config.ignoredSafeAreaEdges.contains(.bottom) && !screen.isKeyboardActive { return 0 } + return switch alignment { + case .top: await calculateVerticalPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.bottom) + case .bottom: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupPadding: activePopup.outerPadding.bottom) + case .centre: fatalError() + } + } + func calculateLeadingBodyPadding(popup: AnyPopup) -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.leading) { + case true: 0 + case false: screen.safeArea.leading + }} + func calculateTrailingBodyPadding(popup: AnyPopup) async -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.trailing) { + case true: 0 + case false: screen.safeArea.trailing + }} +} +private extension VM.VerticalStack { + func calculateVerticalPaddingCounterEdge(popupHeight: CGFloat, safeArea: CGFloat) -> CGFloat { + let paddingValueCandidate = safeArea + popupHeight - screen.height + return max(paddingValueCandidate, 0) + } + func calculateVerticalPaddingAdhereEdge(safeAreaHeight: CGFloat, popupPadding: CGFloat) -> CGFloat { + let paddingValueCandidate = safeAreaHeight - popupPadding + return max(paddingValueCandidate, 0) + } +} // MARK: Outer Padding +extension VM.VerticalStack { + func calculateActivePopupOuterPadding() async -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return await .init( + top: calculateVerticalPopupPadding(for: .top, activePopupConfig: activePopupConfig), + leading: calculateLeadingPopupPadding(activePopupConfig: activePopupConfig), + bottom: calculateVerticalPopupPadding(for: .bottom, activePopupConfig: activePopupConfig), + trailing: calculateTrailingPopupPadding(activePopupConfig: activePopupConfig) + )} +} +private extension VM.VerticalStack { + func calculateVerticalPopupPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { + let largeScreenHeight = calculateLargeScreenHeight(), + activePopupHeight = await activePopup.height ?? 0, + priorityPopupPaddingValue = await calculatePriorityPopupPaddingValue(for: edge, activePopupConfig: activePopupConfig), + remainingHeight = largeScreenHeight - activePopupHeight - priorityPopupPaddingValue + + let popupPaddingCandidate = min(remainingHeight, activePopupConfig.popupPadding[edge]) + return max(popupPaddingCandidate, 0) + } + func calculateLeadingPopupPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { + activePopupConfig.popupPadding.leading + } + func calculateTrailingPopupPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { + activePopupConfig.popupPadding.trailing + } +} +private extension VM.VerticalStack { + func calculatePriorityPopupPaddingValue(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { switch edge == alignment { + case true: 0 + case false: activePopupConfig.popupPadding[!edge] + }} +} // MARK: Corners @@ -102,85 +177,10 @@ private extension VM.VerticalStack { // MARK: Outer Padding -extension VM.VerticalStack { - func calculateActivePopupOuterPadding() async -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return await .init( - top: calculateVerticalPopupPadding(for: .top, activePopupConfig: activePopupConfig), - leading: calculateLeadingPopupPadding(activePopupConfig: activePopupConfig), - bottom: calculateVerticalPopupPadding(for: .bottom, activePopupConfig: activePopupConfig), - trailing: calculateTrailingPopupPadding(activePopupConfig: activePopupConfig) - )} -} -private extension VM.VerticalStack { - func calculateVerticalPopupPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { - let largeScreenHeight = calculateLargeScreenHeight(), - activePopupHeight = await activePopup.height ?? 0, - priorityPopupPaddingValue = await calculatePriorityPopupPaddingValue(for: edge, activePopupConfig: activePopupConfig), - remainingHeight = largeScreenHeight - activePopupHeight - priorityPopupPaddingValue - let popupPaddingCandidate = min(remainingHeight, activePopupConfig.popupPadding[edge]) - return max(popupPaddingCandidate, 0) - } - func calculateLeadingPopupPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { - activePopupConfig.popupPadding.leading - } - func calculateTrailingPopupPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { - activePopupConfig.popupPadding.trailing - } -} -private extension VM.VerticalStack { - func calculatePriorityPopupPaddingValue(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { switch edge == alignment { - case true: 0 - case false: activePopupConfig.popupPadding[!edge] - }} -} // MARK: Inner Padding -extension VM.VerticalStack { - func calculateActivePopupInnerPadding() async -> EdgeInsets { guard let popup = popups.last else { return .init() }; return await .init( - top: calculateTopBodyPadding(popup: popup), - leading: calculateLeadingBodyPadding(popup: popup), - bottom: calculateBottomBodyPadding(popup: popup), - trailing: calculateTrailingBodyPadding(popup: popup) - )} -} -private extension VM.VerticalStack { - func calculateTopBodyPadding(popup: AnyPopup) async -> CGFloat { - if popup.config.ignoredSafeAreaEdges.contains(.top) { return 0 } - return switch alignment { - case .top: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupPadding: activePopup.outerPadding.top) - case .bottom: await calculateVerticalPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.top) - case .centre: fatalError() - } - } - func calculateBottomBodyPadding(popup: AnyPopup) async -> CGFloat { - if popup.config.ignoredSafeAreaEdges.contains(.bottom) && !screen.isKeyboardActive { return 0 } - - return switch alignment { - case .top: await calculateVerticalPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.bottom) - case .bottom: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupPadding: activePopup.outerPadding.bottom) - case .centre: fatalError() - } - } - func calculateLeadingBodyPadding(popup: AnyPopup) -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.leading) { - case true: 0 - case false: screen.safeArea.leading - }} - func calculateTrailingBodyPadding(popup: AnyPopup) async -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.trailing) { - case true: 0 - case false: screen.safeArea.trailing - }} -} -private extension VM.VerticalStack { - func calculateVerticalPaddingCounterEdge(popupHeight: CGFloat, safeArea: CGFloat) -> CGFloat { - let paddingValueCandidate = safeArea + popupHeight - screen.height - return max(paddingValueCandidate, 0) - } - func calculateVerticalPaddingAdhereEdge(safeAreaHeight: CGFloat, popupPadding: CGFloat) -> CGFloat { - let paddingValueCandidate = safeAreaHeight - popupPadding - return max(paddingValueCandidate, 0) - } -} // MARK: Offset Y extension VM.VerticalStack { From 16ab67c33a6582f4bf37561b6389fc47098a3eb2 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:15:36 +0100 Subject: [PATCH 202/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 9a98b1d193..33c9211aac 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -33,36 +33,36 @@ extension VM { class VerticalStack: ViewModel { required init() {} // MARK: Inner Padding extension VM.VerticalStack { func calculateActivePopupInnerPadding() async -> EdgeInsets { guard let popup = popups.last else { return .init() }; return await .init( - top: calculateTopBodyPadding(popup: popup), - leading: calculateLeadingBodyPadding(popup: popup), - bottom: calculateBottomBodyPadding(popup: popup), - trailing: calculateTrailingBodyPadding(popup: popup) + top: calculateTopInnerPadding(popup: popup), + leading: calculateLeadingInnerPadding(popup: popup), + bottom: calculateBottomInnerPadding(popup: popup), + trailing: calculateTrailingInnerPadding(popup: popup) )} } private extension VM.VerticalStack { - func calculateTopBodyPadding(popup: AnyPopup) async -> CGFloat { + func calculateTopInnerPadding(popup: AnyPopup) async -> CGFloat { if popup.config.ignoredSafeAreaEdges.contains(.top) { return 0 } return switch alignment { - case .top: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupPadding: activePopup.outerPadding.top) + case .top: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupOuterPadding: activePopup.outerPadding.top) case .bottom: await calculateVerticalPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.top) case .centre: fatalError() } } - func calculateBottomBodyPadding(popup: AnyPopup) async -> CGFloat { + func calculateBottomInnerPadding(popup: AnyPopup) async -> CGFloat { if popup.config.ignoredSafeAreaEdges.contains(.bottom) && !screen.isKeyboardActive { return 0 } return switch alignment { case .top: await calculateVerticalPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.bottom) - case .bottom: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupPadding: activePopup.outerPadding.bottom) + case .bottom: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupOuterPadding: activePopup.outerPadding.bottom) case .centre: fatalError() } } - func calculateLeadingBodyPadding(popup: AnyPopup) -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.leading) { + func calculateLeadingInnerPadding(popup: AnyPopup) -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.leading) { case true: 0 case false: screen.safeArea.leading }} - func calculateTrailingBodyPadding(popup: AnyPopup) async -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.trailing) { + func calculateTrailingInnerPadding(popup: AnyPopup) async -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.trailing) { case true: 0 case false: screen.safeArea.trailing }} @@ -72,8 +72,8 @@ private extension VM.VerticalStack { let paddingValueCandidate = safeArea + popupHeight - screen.height return max(paddingValueCandidate, 0) } - func calculateVerticalPaddingAdhereEdge(safeAreaHeight: CGFloat, popupPadding: CGFloat) -> CGFloat { - let paddingValueCandidate = safeAreaHeight - popupPadding + func calculateVerticalPaddingAdhereEdge(safeAreaHeight: CGFloat, popupOuterPadding: CGFloat) -> CGFloat { + let paddingValueCandidate = safeAreaHeight - popupOuterPadding return max(paddingValueCandidate, 0) } } From baf2da1f7a6d8d1feaca1a48aaeb73c5c30bb270 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:16:50 +0100 Subject: [PATCH 203/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 33c9211aac..f484747755 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -44,8 +44,8 @@ private extension VM.VerticalStack { if popup.config.ignoredSafeAreaEdges.contains(.top) { return 0 } return switch alignment { - case .top: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupOuterPadding: activePopup.outerPadding.top) - case .bottom: await calculateVerticalPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.top) + case .top: await calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupOuterPadding: activePopup.outerPadding.top) + case .bottom: await calculateVerticalInnerPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.top) case .centre: fatalError() } } @@ -53,8 +53,8 @@ private extension VM.VerticalStack { if popup.config.ignoredSafeAreaEdges.contains(.bottom) && !screen.isKeyboardActive { return 0 } return switch alignment { - case .top: await calculateVerticalPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.bottom) - case .bottom: await calculateVerticalPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupOuterPadding: activePopup.outerPadding.bottom) + case .top: await calculateVerticalInnerPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.bottom) + case .bottom: await calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupOuterPadding: activePopup.outerPadding.bottom) case .centre: fatalError() } } @@ -68,11 +68,11 @@ private extension VM.VerticalStack { }} } private extension VM.VerticalStack { - func calculateVerticalPaddingCounterEdge(popupHeight: CGFloat, safeArea: CGFloat) -> CGFloat { + func calculateVerticalInnerPaddingCounterEdge(popupHeight: CGFloat, safeArea: CGFloat) -> CGFloat { let paddingValueCandidate = safeArea + popupHeight - screen.height return max(paddingValueCandidate, 0) } - func calculateVerticalPaddingAdhereEdge(safeAreaHeight: CGFloat, popupOuterPadding: CGFloat) -> CGFloat { + func calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: CGFloat, popupOuterPadding: CGFloat) -> CGFloat { let paddingValueCandidate = safeAreaHeight - popupOuterPadding return max(paddingValueCandidate, 0) } From 2ef41903f8efb161a57126bb5d917a528d346fd9 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:18:22 +0100 Subject: [PATCH 204/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index f484747755..73e570306e 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -81,31 +81,31 @@ private extension VM.VerticalStack { // MARK: Outer Padding extension VM.VerticalStack { func calculateActivePopupOuterPadding() async -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return await .init( - top: calculateVerticalPopupPadding(for: .top, activePopupConfig: activePopupConfig), - leading: calculateLeadingPopupPadding(activePopupConfig: activePopupConfig), - bottom: calculateVerticalPopupPadding(for: .bottom, activePopupConfig: activePopupConfig), - trailing: calculateTrailingPopupPadding(activePopupConfig: activePopupConfig) + top: calculateVerticalOuterPadding(for: .top, activePopupConfig: activePopupConfig), + leading: calculateLeadingOuterPadding(activePopupConfig: activePopupConfig), + bottom: calculateVerticalOuterPadding(for: .bottom, activePopupConfig: activePopupConfig), + trailing: calculateTrailingOuterPadding(activePopupConfig: activePopupConfig) )} } private extension VM.VerticalStack { - func calculateVerticalPopupPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { + func calculateVerticalOuterPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { let largeScreenHeight = calculateLargeScreenHeight(), activePopupHeight = await activePopup.height ?? 0, - priorityPopupPaddingValue = await calculatePriorityPopupPaddingValue(for: edge, activePopupConfig: activePopupConfig), + priorityPopupPaddingValue = await calculatePriorityOuterPaddingValue(for: edge, activePopupConfig: activePopupConfig), remainingHeight = largeScreenHeight - activePopupHeight - priorityPopupPaddingValue let popupPaddingCandidate = min(remainingHeight, activePopupConfig.popupPadding[edge]) return max(popupPaddingCandidate, 0) } - func calculateLeadingPopupPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { + func calculateLeadingOuterPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { activePopupConfig.popupPadding.leading } - func calculateTrailingPopupPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { + func calculateTrailingOuterPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { activePopupConfig.popupPadding.trailing } } private extension VM.VerticalStack { - func calculatePriorityPopupPaddingValue(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { switch edge == alignment { + func calculatePriorityOuterPaddingValue(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { switch edge == alignment { case true: 0 case false: activePopupConfig.popupPadding[!edge] }} From f21bc1bc39c54ecde0e6cd4a7b7bb199a25a884a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:54:02 +0100 Subject: [PATCH 205/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 73e570306e..df269271c6 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -171,17 +171,6 @@ private extension VM.VerticalStack { - - - - - -// MARK: Outer Padding - - -// MARK: Inner Padding - - // MARK: Offset Y extension VM.VerticalStack { @MainActor func calculateOffsetY(for popup: AnyPopup) -> CGFloat { switch popup == popups.last { @@ -226,6 +215,14 @@ extension VM.VerticalStack { } } + + + + + + + + // MARK: Corner Radius extension VM.VerticalStack { func calculateActivePopupCorners() async -> [PopupAlignment: CGFloat] { From d30391771502682a520bf78dde360ee665831c49 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:55:08 +0100 Subject: [PATCH 206/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 88 +++++++++---------- 1 file changed, 43 insertions(+), 45 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index df269271c6..eb82155d6e 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -27,8 +27,25 @@ extension VM { class VerticalStack: ViewModel { required init() {} // MARK: Height +extension VM.VerticalStack { + func calculateActivePopupHeight() async -> CGFloat? { + guard let activePopupHeight = popups.last?.height else { return nil } + let activePopupDragHeight = popups.last?.dragHeight ?? 0 + let popupHeightFromGestureTranslation = await activePopupHeight + activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() + let newHeightCandidate1 = max(activePopupHeight, popupHeightFromGestureTranslation), + newHeightCanditate2 = screen.height + return min(newHeightCandidate1, newHeightCanditate2) + } +} +private extension VM.VerticalStack { + func getDragTranslationMultiplier() -> CGFloat { switch alignment { + case .top: 1 + case .bottom: -1 + case .centre: fatalError() + }} +} // MARK: Inner Padding extension VM.VerticalStack { @@ -111,9 +128,34 @@ private extension VM.VerticalStack { }} } - // MARK: Corners +extension VM.VerticalStack { + func calculateActivePopupCorners() async -> [PopupAlignment: CGFloat] { + guard let activePopup = popups.last else { return [:] } + let cornerRadiusValue = await calculateCornerRadiusValue(activePopup) + return await [ + .top: calculateTopCornerRadius(cornerRadiusValue), + .bottom: calculateBottomCornerRadius(cornerRadiusValue) + ] + } +} +private extension VM.VerticalStack { + func calculateCornerRadiusValue(_ activePopup: AnyPopup) async -> CGFloat { switch activePopup.config.heightMode { + case .auto, .large: activePopup.config.cornerRadius + case .fullscreen: 0 + }} + func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat) async -> CGFloat { switch alignment { + case .top: await activePopup.outerPadding.top != 0 ? cornerRadiusValue : 0 + case .bottom: cornerRadiusValue + case .centre: fatalError() + }} + func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat) async -> CGFloat { switch alignment { + case .top: cornerRadiusValue + case .bottom: await activePopup.outerPadding.bottom != 0 ? cornerRadiusValue : 0 + case .centre: fatalError() + }} +} // MARK: Vertical Fixed Size @@ -224,33 +266,7 @@ extension VM.VerticalStack { // MARK: Corner Radius -extension VM.VerticalStack { - func calculateActivePopupCorners() async -> [PopupAlignment: CGFloat] { - guard let activePopup = popups.last else { return [:] } - let cornerRadiusValue = await calculateCornerRadiusValue(activePopup) - return await [ - .top: calculateTopCornerRadius(cornerRadiusValue), - .bottom: calculateBottomCornerRadius(cornerRadiusValue) - ] - } -} -private extension VM.VerticalStack { - func calculateCornerRadiusValue(_ activePopup: AnyPopup) async -> CGFloat { switch activePopup.config.heightMode { - case .auto, .large: activePopup.config.cornerRadius - case .fullscreen: 0 - }} - func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat) async -> CGFloat { switch alignment { - case .top: await activePopup.outerPadding.top != 0 ? cornerRadiusValue : 0 - case .bottom: cornerRadiusValue - case .centre: fatalError() - }} - func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat) async -> CGFloat { switch alignment { - case .top: cornerRadiusValue - case .bottom: await activePopup.outerPadding.bottom != 0 ? cornerRadiusValue : 0 - case .centre: fatalError() - }} -} // MARK: Fixed Size extension VM.VerticalStack { @@ -293,25 +309,7 @@ private extension VM.VerticalStack { // MARK: Active Popup Height -extension VM.VerticalStack { - func calculateActivePopupHeight() async -> CGFloat? { - guard let activePopupHeight = popups.last?.height else { return nil } - let activePopupDragHeight = popups.last?.dragHeight ?? 0 - let popupHeightFromGestureTranslation = await activePopupHeight + activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() - - let newHeightCandidate1 = max(activePopupHeight, popupHeightFromGestureTranslation), - newHeightCanditate2 = screen.height - return min(newHeightCandidate1, newHeightCanditate2) - } -} -private extension VM.VerticalStack { - func getDragTranslationMultiplier() -> CGFloat { switch alignment { - case .top: 1 - case .bottom: -1 - case .centre: fatalError() - }} -} // MARK: Translation Progress extension VM.VerticalStack { From 95e71af7149ffcf86bf0322bf796f245f8f95606 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:56:38 +0100 Subject: [PATCH 207/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 48 ++++++------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index eb82155d6e..a04d720107 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -158,10 +158,21 @@ private extension VM.VerticalStack { } // MARK: Vertical Fixed Size - +extension VM.VerticalStack { + func calculateActivePopupVerticalFixedSize() async -> Bool { guard let popup = popups.last else { return true }; return switch popup.config.heightMode { + case .fullscreen, .large: false + case .auto: await activePopup.height != calculateLargeScreenHeight() + }} +} // MARK: Translation Progress - +extension VM.VerticalStack { + func calculateActivePopupTranslationProgress() async -> CGFloat { guard let activePopupHeight = popups.last?.height else { return 0 }; return switch alignment { + case .top: await abs(min(activePopup.gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight + case .bottom: await max(activePopup.gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight + case .centre: fatalError() + }} +} @@ -257,25 +268,6 @@ extension VM.VerticalStack { } } - - - - - - - - -// MARK: Corner Radius - - -// MARK: Fixed Size -extension VM.VerticalStack { - func calculateActivePopupVerticalFixedSize() async -> Bool { guard let popup = popups.last else { return true }; return switch popup.config.heightMode { - case .fullscreen, .large: false - case .auto: await activePopup.height != calculateLargeScreenHeight() - }} -} - // MARK: Z Index extension VM.VerticalStack { @MainActor func calculateZIndex() -> CGFloat { @@ -298,9 +290,6 @@ extension VM.VerticalStack { return max(opacity, 0) } } -private extension VM.VerticalStack { - var minStackOverlayProgressMultiplier: CGFloat { 0.6 } -} @@ -308,17 +297,9 @@ private extension VM.VerticalStack { -// MARK: Active Popup Height - // MARK: Translation Progress -extension VM.VerticalStack { - func calculateActivePopupTranslationProgress() async -> CGFloat { guard let activePopupHeight = popups.last?.height else { return 0 }; return switch alignment { - case .top: await abs(min(activePopup.gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight - case .bottom: await max(activePopup.gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight - case .centre: fatalError() - }} -} + // MARK: Others extension VM.VerticalStack { @@ -339,6 +320,7 @@ extension VM.VerticalStack { var dragGestureEnabled: Bool { popups.last?.config.isDragGestureEnabled ?? false } var dragTranslationThreshold: CGFloat { 8 } var minScaleProgressMultiplier: CGFloat { 0.7 } + var minStackOverlayProgressMultiplier: CGFloat { 0.6 } } From ca4319e80d2ac855c4019fdb171d1c9039d9a12a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 12:58:14 +0100 Subject: [PATCH 208/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index a04d720107..1c8e8e5ee0 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -176,7 +176,6 @@ extension VM.VerticalStack { - // MARK: - METHODS / VIEW MODEL / SELECTED POPUP @@ -219,7 +218,6 @@ private extension VM.VerticalStack { - // MARK: - METHODS / VIEW @@ -297,11 +295,7 @@ extension VM.VerticalStack { - -// MARK: Translation Progress - - -// MARK: Others +// MARK: Inverted Index extension VM.VerticalStack { func getInvertedIndex(of popup: AnyPopup) -> Int { let index = popups.firstIndex(of: popup) ?? 0 From 756a5d27a29eff076dd33a1ff8630eb75cba996b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 13:02:07 +0100 Subject: [PATCH 209/407] 1 --- Sources/Internal/Extensions/Array++.swift | 10 ++++ .../View Models/ViewModel+VerticalStack.swift | 49 +++++++------------ 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/Sources/Internal/Extensions/Array++.swift b/Sources/Internal/Extensions/Array++.swift index 655dee66bb..60ee57a3b2 100644 --- a/Sources/Internal/Extensions/Array++.swift +++ b/Sources/Internal/Extensions/Array++.swift @@ -9,6 +9,7 @@ // Copyright ©2024 Mijick. All rights reserved. +// MARK: Modified extension Array { func modified(if value: Bool = true, _ builder: (inout [Element]) async -> ()) async -> [Element] { guard value else { return self } var array = self @@ -16,3 +17,12 @@ extension Array { return array } } + +// MARK: Inverted Index +extension Array where Element: Equatable { + func getInvertedIndex(of element: Element) -> Int { + let index = firstIndex(of: element) ?? 0 + let invertedIndex = count - 1 - index + return invertedIndex + } +} diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 1c8e8e5ee0..84c6d49538 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -240,7 +240,7 @@ private extension VM.VerticalStack { } } func calculateOffsetForStackedPopup(_ popup: AnyPopup) -> CGFloat { - let invertedIndex = getInvertedIndex(of: popup) + let invertedIndex = popups.getInvertedIndex(of: popup) let offsetValue = stackOffset * .init(invertedIndex) let alignmentMultiplier = switch alignment { case .top: 1.0 @@ -257,7 +257,7 @@ extension VM.VerticalStack { @MainActor func calculateScaleX(for popup: AnyPopup) -> CGFloat { guard popup != popups.last else { return 1 } - let invertedIndex = getInvertedIndex(of: popup), + let invertedIndex = popups.getInvertedIndex(of: popup), remainingTranslationProgress = 1 - activePopup.translationProgress let progressMultiplier = invertedIndex == 1 ? remainingTranslationProgress : max(minScaleProgressMultiplier, remainingTranslationProgress) @@ -278,7 +278,7 @@ extension VM.VerticalStack { @MainActor func calculateStackOverlayOpacity(for popup: AnyPopup) -> CGFloat { guard popup != popups.last else { return 0 } - let invertedIndex = getInvertedIndex(of: popup), + let invertedIndex = popups.getInvertedIndex(of: popup), remainingTranslationProgress = 1 - activePopup.translationProgress let progressMultiplier = invertedIndex == 1 ? remainingTranslationProgress : max(minStackOverlayProgressMultiplier, remainingTranslationProgress) @@ -291,34 +291,6 @@ extension VM.VerticalStack { -// MARK: - HELPERS - - - -// MARK: Inverted Index -extension VM.VerticalStack { - func getInvertedIndex(of popup: AnyPopup) -> Int { - let index = popups.firstIndex(of: popup) ?? 0 - let invertedIndex = popups.count - 1 - index - return invertedIndex - } -} - -// MARK: Attributes -extension VM.VerticalStack { - var stackScaleFactor: CGFloat { 0.025 } - var stackOverlayFactor: CGFloat { 0.1 } - var maxStackOverlayFactor: CGFloat { 0.48 } - var stackOffset: CGFloat { GlobalConfigContainer.vertical.isStackingEnabled ? 8 : 0 } - var dragThreshold: CGFloat { GlobalConfigContainer.vertical.dragThreshold } - var dragGestureEnabled: Bool { popups.last?.config.isDragGestureEnabled ?? false } - var dragTranslationThreshold: CGFloat { 8 } - var minScaleProgressMultiplier: CGFloat { 0.7 } - var minStackOverlayProgressMultiplier: CGFloat { 0.6 } -} - - - // MARK: - GESTURES @@ -437,3 +409,18 @@ private extension VM.VerticalStack { await activePopup.translationProgress >= dragThreshold } } + + + +// MARK: - ATTRIBUTES +extension VM.VerticalStack { + var stackScaleFactor: CGFloat { 0.025 } + var stackOverlayFactor: CGFloat { 0.1 } + var maxStackOverlayFactor: CGFloat { 0.48 } + var stackOffset: CGFloat { GlobalConfigContainer.vertical.isStackingEnabled ? 8 : 0 } + var dragThreshold: CGFloat { GlobalConfigContainer.vertical.dragThreshold } + var dragGestureEnabled: Bool { popups.last?.config.isDragGestureEnabled ?? false } + var dragTranslationThreshold: CGFloat { 8 } + var minScaleProgressMultiplier: CGFloat { 0.7 } + var minStackOverlayProgressMultiplier: CGFloat { 0.6 } +} From e61743484538d3d0281cbac730b0d4102a53d448 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 13:14:42 +0100 Subject: [PATCH 210/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 5f529e3a85..cd2d80097b 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -15,7 +15,7 @@ struct AnyPopup: Popup { private(set) var id: PopupID private(set) var config: AnyPopupConfig private(set) var height: CGFloat? = nil - private(set) var dragHeight: CGFloat? = nil + private(set) var dragHeight: CGFloat = 0 private var _dismissTimer: PopupActionScheduler? = nil private var _body: AnyView @@ -46,7 +46,7 @@ extension AnyPopup { // MARK: Update extension AnyPopup { nonisolated func updatedHeight(_ newHeight: CGFloat?) async -> AnyPopup { await updatedAsync { $0.height = newHeight }} - nonisolated func updatedDragHeight(_ newDragHeight: CGFloat?) async -> AnyPopup { await updatedAsync { $0.dragHeight = newDragHeight }} + nonisolated func updatedDragHeight(_ newDragHeight: CGFloat) async -> AnyPopup { await updatedAsync { $0.dragHeight = newDragHeight }} func updatedID(_ customID: String) -> AnyPopup { updated { $0.id = .init(customID) }} func updatedDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} func updatedEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} @@ -98,7 +98,7 @@ extension AnyPopup { id: .init(id), config: .init(config), height: nil, - dragHeight: nil, + dragHeight: 0, _dismissTimer: nil, _body: .init(EmptyView()), _onFocus: {}, From f7acf7f070c0d707c698f0db891912d41d4bf1e7 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 15:32:13 +0100 Subject: [PATCH 211/407] DANGER --- Sources/Internal/View Models/ViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 110bf36c81..d9fe924d70 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -98,7 +98,7 @@ private extension ViewModel { -@MainActor class ActivePopup { +struct ActivePopup: Sendable { var height: CGFloat? = nil var innerPadding: EdgeInsets = .init() var outerPadding: EdgeInsets = .init() From 1bf661b139a3c46e990ee2de104de4e04f8d3241 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 15:59:02 +0100 Subject: [PATCH 212/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 84c6d49538..fafd60ab0b 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -32,7 +32,7 @@ extension VM.VerticalStack { guard let activePopupHeight = popups.last?.height else { return nil } let activePopupDragHeight = popups.last?.dragHeight ?? 0 - let popupHeightFromGestureTranslation = await activePopupHeight + activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() + let popupHeightFromGestureTranslation = activePopupHeight + activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() let newHeightCandidate1 = max(activePopupHeight, popupHeightFromGestureTranslation), newHeightCanditate2 = screen.height @@ -49,7 +49,7 @@ private extension VM.VerticalStack { // MARK: Inner Padding extension VM.VerticalStack { - func calculateActivePopupInnerPadding() async -> EdgeInsets { guard let popup = popups.last else { return .init() }; return await .init( + func calculateActivePopupInnerPadding() async -> EdgeInsets { guard let popup = popups.last else { return .init() }; return .init( top: calculateTopInnerPadding(popup: popup), leading: calculateLeadingInnerPadding(popup: popup), bottom: calculateBottomInnerPadding(popup: popup), @@ -57,21 +57,21 @@ extension VM.VerticalStack { )} } private extension VM.VerticalStack { - func calculateTopInnerPadding(popup: AnyPopup) async -> CGFloat { + func calculateTopInnerPadding(popup: AnyPopup) -> CGFloat { if popup.config.ignoredSafeAreaEdges.contains(.top) { return 0 } return switch alignment { - case .top: await calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupOuterPadding: activePopup.outerPadding.top) - case .bottom: await calculateVerticalInnerPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.top) + case .top: calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupOuterPadding: activePopup.outerPadding.top) + case .bottom: calculateVerticalInnerPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.top) case .centre: fatalError() } } - func calculateBottomInnerPadding(popup: AnyPopup) async -> CGFloat { + func calculateBottomInnerPadding(popup: AnyPopup) -> CGFloat { if popup.config.ignoredSafeAreaEdges.contains(.bottom) && !screen.isKeyboardActive { return 0 } return switch alignment { - case .top: await calculateVerticalInnerPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.bottom) - case .bottom: await calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupOuterPadding: activePopup.outerPadding.bottom) + case .top: calculateVerticalInnerPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.bottom) + case .bottom: calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupOuterPadding: activePopup.outerPadding.bottom) case .centre: fatalError() } } @@ -79,7 +79,7 @@ private extension VM.VerticalStack { case true: 0 case false: screen.safeArea.leading }} - func calculateTrailingInnerPadding(popup: AnyPopup) async -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.trailing) { + func calculateTrailingInnerPadding(popup: AnyPopup) -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.trailing) { case true: 0 case false: screen.safeArea.trailing }} @@ -97,7 +97,7 @@ private extension VM.VerticalStack { // MARK: Outer Padding extension VM.VerticalStack { - func calculateActivePopupOuterPadding() async -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return await .init( + func calculateActivePopupOuterPadding() async -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return .init( top: calculateVerticalOuterPadding(for: .top, activePopupConfig: activePopupConfig), leading: calculateLeadingOuterPadding(activePopupConfig: activePopupConfig), bottom: calculateVerticalOuterPadding(for: .bottom, activePopupConfig: activePopupConfig), @@ -105,10 +105,10 @@ extension VM.VerticalStack { )} } private extension VM.VerticalStack { - func calculateVerticalOuterPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { + func calculateVerticalOuterPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) -> CGFloat { let largeScreenHeight = calculateLargeScreenHeight(), - activePopupHeight = await activePopup.height ?? 0, - priorityPopupPaddingValue = await calculatePriorityOuterPaddingValue(for: edge, activePopupConfig: activePopupConfig), + activePopupHeight = activePopup.height ?? 0, + priorityPopupPaddingValue = calculatePriorityOuterPaddingValue(for: edge, activePopupConfig: activePopupConfig), remainingHeight = largeScreenHeight - activePopupHeight - priorityPopupPaddingValue let popupPaddingCandidate = min(remainingHeight, activePopupConfig.popupPadding[edge]) @@ -122,7 +122,7 @@ private extension VM.VerticalStack { } } private extension VM.VerticalStack { - func calculatePriorityOuterPaddingValue(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) async -> CGFloat { switch edge == alignment { + func calculatePriorityOuterPaddingValue(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) -> CGFloat { switch edge == alignment { case true: 0 case false: activePopupConfig.popupPadding[!edge] }} @@ -133,26 +133,26 @@ extension VM.VerticalStack { func calculateActivePopupCorners() async -> [PopupAlignment: CGFloat] { guard let activePopup = popups.last else { return [:] } - let cornerRadiusValue = await calculateCornerRadiusValue(activePopup) - return await [ + let cornerRadiusValue = calculateCornerRadiusValue(activePopup) + return [ .top: calculateTopCornerRadius(cornerRadiusValue), .bottom: calculateBottomCornerRadius(cornerRadiusValue) ] } } private extension VM.VerticalStack { - func calculateCornerRadiusValue(_ activePopup: AnyPopup) async -> CGFloat { switch activePopup.config.heightMode { + func calculateCornerRadiusValue(_ activePopup: AnyPopup) -> CGFloat { switch activePopup.config.heightMode { case .auto, .large: activePopup.config.cornerRadius case .fullscreen: 0 }} - func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat) async -> CGFloat { switch alignment { - case .top: await activePopup.outerPadding.top != 0 ? cornerRadiusValue : 0 + func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat) -> CGFloat { switch alignment { + case .top: activePopup.outerPadding.top != 0 ? cornerRadiusValue : 0 case .bottom: cornerRadiusValue case .centre: fatalError() }} - func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat) async -> CGFloat { switch alignment { + func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat) -> CGFloat { switch alignment { case .top: cornerRadiusValue - case .bottom: await activePopup.outerPadding.bottom != 0 ? cornerRadiusValue : 0 + case .bottom: activePopup.outerPadding.bottom != 0 ? cornerRadiusValue : 0 case .centre: fatalError() }} } @@ -161,15 +161,15 @@ private extension VM.VerticalStack { extension VM.VerticalStack { func calculateActivePopupVerticalFixedSize() async -> Bool { guard let popup = popups.last else { return true }; return switch popup.config.heightMode { case .fullscreen, .large: false - case .auto: await activePopup.height != calculateLargeScreenHeight() + case .auto: activePopup.height != calculateLargeScreenHeight() }} } // MARK: Translation Progress extension VM.VerticalStack { func calculateActivePopupTranslationProgress() async -> CGFloat { guard let activePopupHeight = popups.last?.height else { return 0 }; return switch alignment { - case .top: await abs(min(activePopup.gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight - case .bottom: await max(activePopup.gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight + case .top: abs(min(activePopup.gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight + case .bottom: max(activePopup.gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight case .centre: fatalError() }} } @@ -183,7 +183,7 @@ extension VM.VerticalStack { // MARK: Height extension VM.VerticalStack { func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { - guard await activePopup.gestureTranslation.isZero else { return popup.height ?? 0 } + guard activePopup.gestureTranslation.isZero else { return popup.height ?? 0 } let popupHeight = calculateNewPopupHeight(heightCandidate, popup.config) return popupHeight From 47817cd5d4fa16ff70dff286fb8b5890ef67da2f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 17:50:43 +0100 Subject: [PATCH 213/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index d9fe924d70..a583acdbe9 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -52,8 +52,8 @@ extension ViewModel { @MainActor func updatePopupsValue(_ newPopups: [AnyPopup]) async { Task { @MainActor in popups = await filterPopups(newPopups) - activePopup.outerPadding = await calculateActivePopupOuterPadding() activePopup.height = await calculateActivePopupHeight() + activePopup.outerPadding = await calculateActivePopupOuterPadding() activePopup.innerPadding = await calculateActivePopupInnerPadding() activePopup.corners = await calculateActivePopupCorners() activePopup.verticalFixedSize = await calculateActivePopupVerticalFixedSize() From cd8ca473cccaeb860d5df2770140b9423ae6b9a9 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 18:54:24 +0100 Subject: [PATCH 214/407] 1 --- .../View Models/ViewModel+CentreStack.swift | 18 +++++++++--------- Sources/Internal/View Models/ViewModel.swift | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 09f19f692d..1063487158 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -33,14 +33,9 @@ extension VM.CentreStack { } } -// MARK: Inner Padding -extension VM.CentreStack { - func calculateActivePopupInnerPadding() async -> EdgeInsets { .init() } -} - // MARK: Outer Padding extension VM.CentreStack { - func calculateActivePopupOuterPadding() async -> EdgeInsets { await .init( + func calculateActivePopupOuterPadding() async -> EdgeInsets { .init( top: calculateVerticalPopupPadding(for: .top), leading: calculateLeadingPopupPadding(), bottom: calculateVerticalPopupPadding(for: .bottom), @@ -48,8 +43,8 @@ extension VM.CentreStack { )} } private extension VM.CentreStack { - func calculateVerticalPopupPadding(for edge: PopupAlignment) async -> CGFloat { - guard let activePopupHeight = await activePopup.height, + func calculateVerticalPopupPadding(for edge: PopupAlignment) -> CGFloat { + guard let activePopupHeight = activePopup.height, screen.isKeyboardActive && edge == .bottom else { return 0 } @@ -65,6 +60,11 @@ private extension VM.CentreStack { } } +// MARK: Inner Padding +extension VM.CentreStack { + func calculateActivePopupInnerPadding() async -> EdgeInsets { .init() } +} + // MARK: Corners extension VM.CentreStack { func calculateActivePopupCorners() async -> [PopupAlignment : CGFloat] { [ @@ -76,7 +76,7 @@ extension VM.CentreStack { // MARK: Vertical Fixed Size extension VM.CentreStack { func calculateActivePopupVerticalFixedSize() async -> Bool { - await activePopup.height != calculateLargeScreenHeight() + activePopup.height != calculateLargeScreenHeight() } } diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index a583acdbe9..89eb457bac 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -26,8 +26,8 @@ protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == Obs // MARK: Methods func calculateActivePopupHeight() async -> CGFloat? - func calculateActivePopupInnerPadding() async -> EdgeInsets func calculateActivePopupOuterPadding() async -> EdgeInsets + func calculateActivePopupInnerPadding() async -> EdgeInsets func calculateActivePopupCorners() async -> [PopupAlignment: CGFloat] func calculateActivePopupVerticalFixedSize() async -> Bool func calculateActivePopupTranslationProgress() async -> CGFloat From 5b14e73df3077ab7aedb14fece6722a02fbdd2e2 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 18:54:56 +0100 Subject: [PATCH 215/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index fafd60ab0b..f8dc922789 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -47,6 +47,39 @@ private extension VM.VerticalStack { }} } +// MARK: Outer Padding +extension VM.VerticalStack { + func calculateActivePopupOuterPadding() async -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return .init( + top: calculateVerticalOuterPadding(for: .top, activePopupConfig: activePopupConfig), + leading: calculateLeadingOuterPadding(activePopupConfig: activePopupConfig), + bottom: calculateVerticalOuterPadding(for: .bottom, activePopupConfig: activePopupConfig), + trailing: calculateTrailingOuterPadding(activePopupConfig: activePopupConfig) + )} +} +private extension VM.VerticalStack { + func calculateVerticalOuterPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) -> CGFloat { + let largeScreenHeight = calculateLargeScreenHeight(), + activePopupHeight = activePopup.height ?? 0, + priorityPopupPaddingValue = calculatePriorityOuterPaddingValue(for: edge, activePopupConfig: activePopupConfig), + remainingHeight = largeScreenHeight - activePopupHeight - priorityPopupPaddingValue + + let popupPaddingCandidate = min(remainingHeight, activePopupConfig.popupPadding[edge]) + return max(popupPaddingCandidate, 0) + } + func calculateLeadingOuterPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { + activePopupConfig.popupPadding.leading + } + func calculateTrailingOuterPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { + activePopupConfig.popupPadding.trailing + } +} +private extension VM.VerticalStack { + func calculatePriorityOuterPaddingValue(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) -> CGFloat { switch edge == alignment { + case true: 0 + case false: activePopupConfig.popupPadding[!edge] + }} +} + // MARK: Inner Padding extension VM.VerticalStack { func calculateActivePopupInnerPadding() async -> EdgeInsets { guard let popup = popups.last else { return .init() }; return .init( @@ -95,39 +128,6 @@ private extension VM.VerticalStack { } } -// MARK: Outer Padding -extension VM.VerticalStack { - func calculateActivePopupOuterPadding() async -> EdgeInsets { guard let activePopupConfig = popups.last?.config else { return .init() }; return .init( - top: calculateVerticalOuterPadding(for: .top, activePopupConfig: activePopupConfig), - leading: calculateLeadingOuterPadding(activePopupConfig: activePopupConfig), - bottom: calculateVerticalOuterPadding(for: .bottom, activePopupConfig: activePopupConfig), - trailing: calculateTrailingOuterPadding(activePopupConfig: activePopupConfig) - )} -} -private extension VM.VerticalStack { - func calculateVerticalOuterPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) -> CGFloat { - let largeScreenHeight = calculateLargeScreenHeight(), - activePopupHeight = activePopup.height ?? 0, - priorityPopupPaddingValue = calculatePriorityOuterPaddingValue(for: edge, activePopupConfig: activePopupConfig), - remainingHeight = largeScreenHeight - activePopupHeight - priorityPopupPaddingValue - - let popupPaddingCandidate = min(remainingHeight, activePopupConfig.popupPadding[edge]) - return max(popupPaddingCandidate, 0) - } - func calculateLeadingOuterPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { - activePopupConfig.popupPadding.leading - } - func calculateTrailingOuterPadding(activePopupConfig: AnyPopupConfig) -> CGFloat { - activePopupConfig.popupPadding.trailing - } -} -private extension VM.VerticalStack { - func calculatePriorityOuterPaddingValue(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) -> CGFloat { switch edge == alignment { - case true: 0 - case false: activePopupConfig.popupPadding[!edge] - }} -} - // MARK: Corners extension VM.VerticalStack { func calculateActivePopupCorners() async -> [PopupAlignment: CGFloat] { From a02dbe6f1f73dfb3e60e7ffc7b4ddbb8122ff28b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 19:24:21 +0100 Subject: [PATCH 216/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index f8dc922789..46a938fdc0 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -31,12 +31,11 @@ extension VM.VerticalStack { func calculateActivePopupHeight() async -> CGFloat? { guard let activePopupHeight = popups.last?.height else { return nil } - let activePopupDragHeight = popups.last?.dragHeight ?? 0 - let popupHeightFromGestureTranslation = activePopupHeight + activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() + let activePopupDragHeight = popups.last?.dragHeight ?? 0, + popupHeightFromGestureTranslation = activePopupHeight + activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() - let newHeightCandidate1 = max(activePopupHeight, popupHeightFromGestureTranslation), - newHeightCanditate2 = screen.height - return min(newHeightCandidate1, newHeightCanditate2) + let newHeightCandidate = max(activePopupHeight, popupHeightFromGestureTranslation) + return min(newHeightCandidate, screen.height) } } private extension VM.VerticalStack { From f47a09bebac0660121c3a1d76704597ecbbc5fa7 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 19:29:00 +0100 Subject: [PATCH 217/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 46a938fdc0..f0554c3f52 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -29,10 +29,9 @@ extension VM { class VerticalStack: ViewModel { required init() {} // MARK: Height extension VM.VerticalStack { func calculateActivePopupHeight() async -> CGFloat? { - guard let activePopupHeight = popups.last?.height else { return nil } + guard let activePopupHeight = popups.last?.height, let activePopupDragHeight = popups.last?.dragHeight else { return nil } - let activePopupDragHeight = popups.last?.dragHeight ?? 0, - popupHeightFromGestureTranslation = activePopupHeight + activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() + let popupHeightFromGestureTranslation = activePopupHeight + activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() let newHeightCandidate = max(activePopupHeight, popupHeightFromGestureTranslation) return min(newHeightCandidate, screen.height) From 0bffd670f74ba5d21e95ea6847f72b777a61b074 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 20:11:24 +0100 Subject: [PATCH 218/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index f0554c3f52..1c364760c0 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -228,7 +228,7 @@ extension VM.VerticalStack { }} } private extension VM.VerticalStack { - @MainActor func calculateOffsetForActivePopup() -> CGFloat { + func calculateOffsetForActivePopup() -> CGFloat { let lastPopupDragHeight = popups.last?.dragHeight ?? 0 return switch alignment { From cbb1047b9944d0df3d4aa0dee3e4d542cc96ed91 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 20:29:05 +0100 Subject: [PATCH 219/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 1c364760c0..5b4d0aafbd 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -295,10 +295,12 @@ extension VM.VerticalStack { // MARK: On Changed extension VM.VerticalStack { - @MainActor func onPopupDragGestureChanged(_ value: CGFloat) async { Task { @MainActor in if dragGestureEnabled { + @MainActor func onPopupDragGestureChanged(_ value: CGFloat) async { Task { + guard dragGestureEnabled else { return } + let newGestureTranslation = await calculateGestureTranslation(value) await updateGestureTranslation(newGestureTranslation) - }}} + }} } private extension VM.VerticalStack { func calculateGestureTranslation(_ value: CGFloat) async -> CGFloat { switch popups.last?.config.dragDetents.isEmpty ?? true { @@ -310,7 +312,9 @@ private extension VM.VerticalStack { func calculateGestureTranslationWhenNoDragDetents(_ value: CGFloat) -> CGFloat { calculateDragExtremeValue(value, 0) } - func calculateGestureTranslationWhenDragDetents(_ value: CGFloat) async -> CGFloat { guard value * getDragTranslationMultiplier() > 0, let activePopupHeight = popups.last?.height else { return value } + func calculateGestureTranslationWhenDragDetents(_ value: CGFloat) async -> CGFloat { + guard value * getDragTranslationMultiplier() > 0, let activePopupHeight = popups.last?.height else { return value } + let maxHeight = await calculateMaxHeightForDragGesture(activePopupHeight) let dragTranslation = calculateDragTranslation(maxHeight, activePopupHeight) return calculateDragExtremeValue(dragTranslation, value) From 6d2507b9fc483b584e4f1d19ea2c0a661ead16a7 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 20:31:27 +0100 Subject: [PATCH 220/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 5b4d0aafbd..da2e5706da 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -345,7 +345,7 @@ extension VM.VerticalStack { }}} } private extension VM.VerticalStack { - func dismissLastItemIfNeeded() async { if await shouldDismissPopup() { if let popup = popups.last { + func dismissLastItemIfNeeded() async { if shouldDismissPopup() { if let popup = popups.last { await closePopupAction(popup) }}} @MainActor func updateTranslationValues() async { if let activePopupHeight = popups.last?.height { @@ -355,7 +355,7 @@ private extension VM.VerticalStack { let targetHeight = await calculateTargetPopupHeight(currentPopupHeight, popupTargetHeights) let targetDragHeight = await calculateTargetDragHeight(targetHeight, activePopupHeight) - await resetGestureTranslation() + await updateGestureTranslation(0) await updateDragHeight(targetDragHeight) } @@ -364,7 +364,7 @@ private extension VM.VerticalStack { private extension VM.VerticalStack { func calculateCurrentPopupHeight(_ activePopupHeight: CGFloat) async -> CGFloat { let activePopupDragHeight = popups.last?.dragHeight ?? 0 - let currentDragHeight = await activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() + let currentDragHeight = activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() let currentPopupHeight = activePopupHeight + currentDragHeight return currentPopupHeight @@ -386,14 +386,14 @@ private extension VM.VerticalStack { else { return popupTargetHeights.last ?? 0 } let initialIndex = popupTargetHeights.firstIndex(where: { $0 >= currentPopupHeight }) ?? popupTargetHeights.count - 1, - targetIndex = await activePopup.gestureTranslation * getDragTranslationMultiplier() > 0 ? initialIndex : max(0, initialIndex - 1) + targetIndex = activePopup.gestureTranslation * getDragTranslationMultiplier() > 0 ? initialIndex : max(0, initialIndex - 1) let previousPopupHeight = (popups.last?.dragHeight ?? 0) + activePopupHeight, popupTargetHeight = popupTargetHeights[targetIndex], deltaHeight = abs(previousPopupHeight - popupTargetHeight) let progress = abs(currentPopupHeight - previousPopupHeight) / deltaHeight if progress < dragThreshold { - let index = await activePopup.gestureTranslation * getDragTranslationMultiplier() > 0 ? max(0, initialIndex - 1) : initialIndex + let index = activePopup.gestureTranslation * getDragTranslationMultiplier() > 0 ? max(0, initialIndex - 1) : initialIndex return popupTargetHeights[index] } return popupTargetHeights[targetIndex] @@ -404,11 +404,8 @@ private extension VM.VerticalStack { @MainActor func updateDragHeight(_ targetDragHeight: CGFloat) async { if let activePopup = popups.last { await updatePopupAction(activePopup.updatedDragHeight(targetDragHeight)) }} - @MainActor func resetGestureTranslation() async { - await updateGestureTranslation(0) - } - func shouldDismissPopup() async -> Bool { - await activePopup.translationProgress >= dragThreshold + func shouldDismissPopup() -> Bool { + activePopup.translationProgress >= dragThreshold } } From d2c02b941ac0be8d26fc90fe13cca2cd12332d48 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 20:35:38 +0100 Subject: [PATCH 221/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index da2e5706da..67f1d10aaa 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -345,9 +345,13 @@ extension VM.VerticalStack { }}} } private extension VM.VerticalStack { - func dismissLastItemIfNeeded() async { if shouldDismissPopup() { if let popup = popups.last { + func dismissLastItemIfNeeded() async { + guard let popup = popups.last, + activePopup.translationProgress >= dragThreshold + else { return } + await closePopupAction(popup) - }}} + } @MainActor func updateTranslationValues() async { if let activePopupHeight = popups.last?.height { Task { let currentPopupHeight = await calculateCurrentPopupHeight(activePopupHeight) @@ -404,9 +408,6 @@ private extension VM.VerticalStack { @MainActor func updateDragHeight(_ targetDragHeight: CGFloat) async { if let activePopup = popups.last { await updatePopupAction(activePopup.updatedDragHeight(targetDragHeight)) }} - func shouldDismissPopup() -> Bool { - activePopup.translationProgress >= dragThreshold - } } From 1522e9b94ff6597c01ffa2cfca252859be72f7dd Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 20:36:16 +0100 Subject: [PATCH 222/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 67f1d10aaa..ee3d8efb08 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -128,9 +128,7 @@ private extension VM.VerticalStack { // MARK: Corners extension VM.VerticalStack { - func calculateActivePopupCorners() async -> [PopupAlignment: CGFloat] { - guard let activePopup = popups.last else { return [:] } - + func calculateActivePopupCorners() async -> [PopupAlignment: CGFloat] { guard let activePopup = popups.last else { return [.top: 0, .bottom: 0] } let cornerRadiusValue = calculateCornerRadiusValue(activePopup) return [ .top: calculateTopCornerRadius(cornerRadiusValue), From c2570e6572d2c263a10f77eb710999b1a751ea5e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Tue, 12 Nov 2024 20:37:09 +0100 Subject: [PATCH 223/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index ee3d8efb08..67a7b6c0cd 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -344,9 +344,7 @@ extension VM.VerticalStack { } private extension VM.VerticalStack { func dismissLastItemIfNeeded() async { - guard let popup = popups.last, - activePopup.translationProgress >= dragThreshold - else { return } + guard activePopup.translationProgress >= dragThreshold, let popup = popups.last else { return } await closePopupAction(popup) } From d14caf10626b165d1848617534fc09b8499a2a47 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 00:06:03 +0100 Subject: [PATCH 224/407] 1 --- Sources/Internal/Extensions/Array++.swift | 7 ++++++- Sources/Internal/Managers/PopupManager.swift | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/Extensions/Array++.swift b/Sources/Internal/Extensions/Array++.swift index 60ee57a3b2..989efa87f2 100644 --- a/Sources/Internal/Extensions/Array++.swift +++ b/Sources/Internal/Extensions/Array++.swift @@ -11,11 +11,16 @@ // MARK: Modified extension Array { - func modified(if value: Bool = true, _ builder: (inout [Element]) async -> ()) async -> [Element] { guard value else { return self } + func modifiedAsync(if value: Bool = true, _ builder: (inout [Element]) async -> ()) async -> [Element] { guard value else { return self } var array = self await builder(&array) return array } + func modified(if value: Bool = true, _ builder: (inout [Element]) -> ()) -> [Element] { guard value else { return self } + var array = self + builder(&array) + return array + } } // MARK: Inverted Index diff --git a/Sources/Internal/Managers/PopupManager.swift b/Sources/Internal/Managers/PopupManager.swift index 7959fb4040..a67a28ce72 100644 --- a/Sources/Internal/Managers/PopupManager.swift +++ b/Sources/Internal/Managers/PopupManager.swift @@ -77,19 +77,19 @@ private extension PopupManager { } } private extension PopupManager { - nonisolated func insertedPopup(_ erasedPopup: AnyPopup) async -> [AnyPopup] { await stack.modified(if: await !stack.contains { $0.id.isSameType(as: erasedPopup.id) }) { + nonisolated func insertedPopup(_ erasedPopup: AnyPopup) async -> [AnyPopup] { await stack.modifiedAsync(if: await !stack.contains { $0.id.isSameType(as: erasedPopup.id) }) { $0.append(await erasedPopup.startDismissTimerIfNeeded(self)) }} - nonisolated func removedLastPopup() async -> [AnyPopup] { await stack.modified(if: !stack.isEmpty) { + nonisolated func removedLastPopup() async -> [AnyPopup] { await stack.modifiedAsync(if: !stack.isEmpty) { $0.removeLast() }} - nonisolated func removedPopupInstance(_ popup: AnyPopup) async -> [AnyPopup] { await stack.modified { + nonisolated func removedPopupInstance(_ popup: AnyPopup) async -> [AnyPopup] { await stack.modifiedAsync { $0.removeAll { $0.id.isSameInstance(as: popup) } }} - nonisolated func removedAllPopupsOfType(_ popupType: any Popup.Type) async -> [AnyPopup] { await stack.modified { + nonisolated func removedAllPopupsOfType(_ popupType: any Popup.Type) async -> [AnyPopup] { await stack.modifiedAsync { $0.removeAll { $0.id.isSameType(as: popupType) } }} - nonisolated func removedAllPopupsWithID(_ id: String) async -> [AnyPopup] { await stack.modified { + nonisolated func removedAllPopupsWithID(_ id: String) async -> [AnyPopup] { await stack.modifiedAsync { $0.removeAll { $0.id.isSameType(as: id) } }} nonisolated func removedAllPopups() async -> [AnyPopup] { From d9a439d865f14bb1d92043b12d909a3fdd8634ce Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 00:09:07 +0100 Subject: [PATCH 225/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 67a7b6c0cd..6b6974db60 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -370,7 +370,7 @@ private extension VM.VerticalStack { return currentPopupHeight } func calculatePopupTargetHeightsFromDragDetents(_ activePopupHeight: CGFloat) async -> [CGFloat] { guard let dragDetents = popups.last?.config.dragDetents else { return [activePopupHeight] }; return - await dragDetents + dragDetents .map { switch $0 { case .height(let targetHeight): min(targetHeight, calculateLargeScreenHeight()) case .fraction(let fraction): min(fraction * activePopupHeight, calculateLargeScreenHeight()) From 87c6625afc3123dc670a8cd4a94a835712a37db2 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:05:35 +0100 Subject: [PATCH 226/407] DANGER --- .../View Models/ViewModel+VerticalStack.swift | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 6b6974db60..518441d541 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -337,17 +337,16 @@ private extension VM.VerticalStack { // MARK: On Ended extension VM.VerticalStack { - @MainActor func onPopupDragGestureEnded(_ value: CGFloat) async { Task { @MainActor in if value != 0 { - await dismissLastItemIfNeeded() + @MainActor func onPopupDragGestureEnded(_ value: CGFloat) async { Task { @MainActor in + if value == 0 { return } + if let popup = popups.last, activePopup.translationProgress >= dragThreshold { return await closePopupAction(popup) } + + + await updateTranslationValues() - }}} + }} } private extension VM.VerticalStack { - func dismissLastItemIfNeeded() async { - guard activePopup.translationProgress >= dragThreshold, let popup = popups.last else { return } - - await closePopupAction(popup) - } @MainActor func updateTranslationValues() async { if let activePopupHeight = popups.last?.height { Task { let currentPopupHeight = await calculateCurrentPopupHeight(activePopupHeight) From 1679d34655d75280b15b82f078fad6485d8d02c9 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:12:36 +0100 Subject: [PATCH 227/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 518441d541..c86fae2117 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -337,9 +337,10 @@ private extension VM.VerticalStack { // MARK: On Ended extension VM.VerticalStack { - @MainActor func onPopupDragGestureEnded(_ value: CGFloat) async { Task { @MainActor in - if value == 0 { return } - if let popup = popups.last, activePopup.translationProgress >= dragThreshold { return await closePopupAction(popup) } + @MainActor func onPopupDragGestureEnded(_ value: CGFloat) async { Task { + guard value != 0, await !closePopupIfNeeded() else { return } + + @@ -347,6 +348,14 @@ extension VM.VerticalStack { }} } private extension VM.VerticalStack { + func closePopupIfNeeded() async -> Bool { + guard activePopup.translationProgress >= dragThreshold else { return false } + + if let popup = popups.last { await closePopupAction(popup) } + return true + } + + @MainActor func updateTranslationValues() async { if let activePopupHeight = popups.last?.height { Task { let currentPopupHeight = await calculateCurrentPopupHeight(activePopupHeight) From f1f66d7eb7e3aabde904f46bb57ebaf3e9da03ff Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:22:34 +0100 Subject: [PATCH 228/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index c86fae2117..41ae4f7ce5 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -338,8 +338,9 @@ private extension VM.VerticalStack { // MARK: On Ended extension VM.VerticalStack { @MainActor func onPopupDragGestureEnded(_ value: CGFloat) async { Task { - guard value != 0, await !closePopupIfNeeded() else { return } + guard value != 0, let activePopup = popups.last, let activePopupHeight = activePopup.height else { return } + await dismissLastPopupIfNeeded(activePopup) @@ -348,12 +349,10 @@ extension VM.VerticalStack { }} } private extension VM.VerticalStack { - func closePopupIfNeeded() async -> Bool { - guard activePopup.translationProgress >= dragThreshold else { return false } - - if let popup = popups.last { await closePopupAction(popup) } - return true - } + func dismissLastPopupIfNeeded(_ popup: AnyPopup) async { switch activePopup.translationProgress >= dragThreshold { + case true: await closePopupAction(popup) + case false: return + }} @MainActor func updateTranslationValues() async { if let activePopupHeight = popups.last?.height { From ce2317fc97fe5eed68863f83c8653c199d3a9fd3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:25:02 +0100 Subject: [PATCH 229/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 41ae4f7ce5..96e398f4a3 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -342,10 +342,9 @@ extension VM.VerticalStack { await dismissLastPopupIfNeeded(activePopup) - - - - await updateTranslationValues() + let targetDragHeight = await calculateTargetDragHeight(activePopupHeight) + await updateGestureTranslation(0) + await updateDragHeight(targetDragHeight) }} } private extension VM.VerticalStack { @@ -353,6 +352,13 @@ private extension VM.VerticalStack { case true: await closePopupAction(popup) case false: return }} + func calculateTargetDragHeight(_ activePopupHeight: CGFloat) async -> CGFloat { + let currentPopupHeight = await calculateCurrentPopupHeight(activePopupHeight) + let popupTargetHeights = await calculatePopupTargetHeightsFromDragDetents(activePopupHeight) + let targetHeight = await calculateTargetPopupHeight(currentPopupHeight, popupTargetHeights) + let targetDragHeight = await calculateTargetDragHeight(targetHeight, activePopupHeight) + return targetDragHeight + } @MainActor func updateTranslationValues() async { if let activePopupHeight = popups.last?.height { From ae47f8f22566028a33ff953d3cb51e9063aec184 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:26:28 +0100 Subject: [PATCH 230/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 96e398f4a3..3f47b00ee3 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -353,36 +353,22 @@ private extension VM.VerticalStack { case false: return }} func calculateTargetDragHeight(_ activePopupHeight: CGFloat) async -> CGFloat { - let currentPopupHeight = await calculateCurrentPopupHeight(activePopupHeight) - let popupTargetHeights = await calculatePopupTargetHeightsFromDragDetents(activePopupHeight) - let targetHeight = await calculateTargetPopupHeight(currentPopupHeight, popupTargetHeights) - let targetDragHeight = await calculateTargetDragHeight(targetHeight, activePopupHeight) + let currentPopupHeight = calculateCurrentPopupHeight(activePopupHeight) + let popupTargetHeights = calculatePopupTargetHeightsFromDragDetents(activePopupHeight) + let targetHeight = calculateTargetPopupHeight(currentPopupHeight, popupTargetHeights) + let targetDragHeight = calculateTargetDragHeight(targetHeight, activePopupHeight) return targetDragHeight } - - - @MainActor func updateTranslationValues() async { if let activePopupHeight = popups.last?.height { - Task { - let currentPopupHeight = await calculateCurrentPopupHeight(activePopupHeight) - let popupTargetHeights = await calculatePopupTargetHeightsFromDragDetents(activePopupHeight) - let targetHeight = await calculateTargetPopupHeight(currentPopupHeight, popupTargetHeights) - let targetDragHeight = await calculateTargetDragHeight(targetHeight, activePopupHeight) - - await updateGestureTranslation(0) - await updateDragHeight(targetDragHeight) - } - - }} } private extension VM.VerticalStack { - func calculateCurrentPopupHeight(_ activePopupHeight: CGFloat) async -> CGFloat { + func calculateCurrentPopupHeight(_ activePopupHeight: CGFloat) -> CGFloat { let activePopupDragHeight = popups.last?.dragHeight ?? 0 let currentDragHeight = activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() let currentPopupHeight = activePopupHeight + currentDragHeight return currentPopupHeight } - func calculatePopupTargetHeightsFromDragDetents(_ activePopupHeight: CGFloat) async -> [CGFloat] { guard let dragDetents = popups.last?.config.dragDetents else { return [activePopupHeight] }; return + func calculatePopupTargetHeightsFromDragDetents(_ activePopupHeight: CGFloat) -> [CGFloat] { guard let dragDetents = popups.last?.config.dragDetents else { return [activePopupHeight] }; return dragDetents .map { switch $0 { case .height(let targetHeight): min(targetHeight, calculateLargeScreenHeight()) @@ -393,7 +379,7 @@ private extension VM.VerticalStack { .modified { $0.append(activePopupHeight) } .sorted(by: <) } - func calculateTargetPopupHeight(_ currentPopupHeight: CGFloat, _ popupTargetHeights: [CGFloat]) async -> CGFloat { + func calculateTargetPopupHeight(_ currentPopupHeight: CGFloat, _ popupTargetHeights: [CGFloat]) -> CGFloat { guard let activePopupHeight = popups.last?.height, currentPopupHeight < screen.height else { return popupTargetHeights.last ?? 0 } @@ -411,7 +397,7 @@ private extension VM.VerticalStack { } return popupTargetHeights[targetIndex] } - func calculateTargetDragHeight(_ targetHeight: CGFloat, _ activePopupHeight: CGFloat) async -> CGFloat { + func calculateTargetDragHeight(_ targetHeight: CGFloat, _ activePopupHeight: CGFloat) -> CGFloat { targetHeight - activePopupHeight } @MainActor func updateDragHeight(_ targetDragHeight: CGFloat) async { if let activePopup = popups.last { From 9f1bdfe26c09538aace57936245f68359c1ff369 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:26:53 +0100 Subject: [PATCH 231/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 3f47b00ee3..5716a6807a 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -359,6 +359,9 @@ private extension VM.VerticalStack { let targetDragHeight = calculateTargetDragHeight(targetHeight, activePopupHeight) return targetDragHeight } + @MainActor func updateDragHeight(_ targetDragHeight: CGFloat) async { if let activePopup = popups.last { + await updatePopupAction(activePopup.updatedDragHeight(targetDragHeight)) + }} } private extension VM.VerticalStack { func calculateCurrentPopupHeight(_ activePopupHeight: CGFloat) -> CGFloat { @@ -400,9 +403,6 @@ private extension VM.VerticalStack { func calculateTargetDragHeight(_ targetHeight: CGFloat, _ activePopupHeight: CGFloat) -> CGFloat { targetHeight - activePopupHeight } - @MainActor func updateDragHeight(_ targetDragHeight: CGFloat) async { if let activePopup = popups.last { - await updatePopupAction(activePopup.updatedDragHeight(targetDragHeight)) - }} } From 920cfbf8bb6ccfa0f19de50f85a58430d09f9c08 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:31:25 +0100 Subject: [PATCH 232/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 5 +---- Sources/Internal/View Models/ViewModel.swift | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 5716a6807a..e60fdd3007 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -344,7 +344,7 @@ extension VM.VerticalStack { let targetDragHeight = await calculateTargetDragHeight(activePopupHeight) await updateGestureTranslation(0) - await updateDragHeight(targetDragHeight) + await updateDragHeight(targetDragHeight, activePopup) }} } private extension VM.VerticalStack { @@ -359,9 +359,6 @@ private extension VM.VerticalStack { let targetDragHeight = calculateTargetDragHeight(targetHeight, activePopupHeight) return targetDragHeight } - @MainActor func updateDragHeight(_ targetDragHeight: CGFloat) async { if let activePopup = popups.last { - await updatePopupAction(activePopup.updatedDragHeight(targetDragHeight)) - }} } private extension VM.VerticalStack { func calculateCurrentPopupHeight(_ activePopupHeight: CGFloat) -> CGFloat { diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 89eb457bac..00c2c0be40 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -82,6 +82,9 @@ extension ViewModel { withAnimation(activePopup.gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } }} + @MainActor func updateDragHeight(_ targetDragHeight: CGFloat, _ popup: AnyPopup) async { + await updatePopupAction(popup.updatedDragHeight(targetDragHeight)) + } } private extension ViewModel { func filterPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { From 01a81c031d39142a68b613e21d3e904bd8e967e8 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:32:25 +0100 Subject: [PATCH 233/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index e60fdd3007..ce56bf5c37 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -303,24 +303,24 @@ extension VM.VerticalStack { private extension VM.VerticalStack { func calculateGestureTranslation(_ value: CGFloat) async -> CGFloat { switch popups.last?.config.dragDetents.isEmpty ?? true { case true: calculateGestureTranslationWhenNoDragDetents(value) - case false: await calculateGestureTranslationWhenDragDetents(value) + case false: calculateGestureTranslationWhenDragDetents(value) }} } private extension VM.VerticalStack { func calculateGestureTranslationWhenNoDragDetents(_ value: CGFloat) -> CGFloat { calculateDragExtremeValue(value, 0) } - func calculateGestureTranslationWhenDragDetents(_ value: CGFloat) async -> CGFloat { + func calculateGestureTranslationWhenDragDetents(_ value: CGFloat) -> CGFloat { guard value * getDragTranslationMultiplier() > 0, let activePopupHeight = popups.last?.height else { return value } - let maxHeight = await calculateMaxHeightForDragGesture(activePopupHeight) + let maxHeight = calculateMaxHeightForDragGesture(activePopupHeight) let dragTranslation = calculateDragTranslation(maxHeight, activePopupHeight) return calculateDragExtremeValue(dragTranslation, value) } } private extension VM.VerticalStack { - func calculateMaxHeightForDragGesture(_ activePopupHeight: CGFloat) async -> CGFloat { - let maxHeight1 = await (calculatePopupTargetHeightsFromDragDetents(activePopupHeight).max() ?? 0) + dragTranslationThreshold + func calculateMaxHeightForDragGesture(_ activePopupHeight: CGFloat) -> CGFloat { + let maxHeight1 = (calculatePopupTargetHeightsFromDragDetents(activePopupHeight).max() ?? 0) + dragTranslationThreshold let maxHeight2 = screen.height return min(maxHeight1, maxHeight2) } From db57ba2afd38fa112fcea8731f72c87068d9c625 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:35:40 +0100 Subject: [PATCH 234/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index ce56bf5c37..b871db9fd5 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -320,9 +320,9 @@ private extension VM.VerticalStack { } private extension VM.VerticalStack { func calculateMaxHeightForDragGesture(_ activePopupHeight: CGFloat) -> CGFloat { - let maxHeight1 = (calculatePopupTargetHeightsFromDragDetents(activePopupHeight).max() ?? 0) + dragTranslationThreshold - let maxHeight2 = screen.height - return min(maxHeight1, maxHeight2) + let maxDragDetent = calculatePopupTargetHeightsFromDragDetents(activePopupHeight).max() ?? 0 + let maxHeightCandidate = maxDragDetent + dragTranslationThreshold + return min(maxHeightCandidate, screen.height) } func calculateDragTranslation(_ maxHeight: CGFloat, _ activePopupHeight: CGFloat) -> CGFloat { let translation = maxHeight - activePopupHeight - (popups.last?.dragHeight ?? 0) From af899954515a383a1a2389839d26f2901d37f2f5 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:36:13 +0100 Subject: [PATCH 235/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index b871db9fd5..8339cecd21 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -325,7 +325,8 @@ private extension VM.VerticalStack { return min(maxHeightCandidate, screen.height) } func calculateDragTranslation(_ maxHeight: CGFloat, _ activePopupHeight: CGFloat) -> CGFloat { - let translation = maxHeight - activePopupHeight - (popups.last?.dragHeight ?? 0) + let activePopupDragHeight = popups.last?.dragHeight ?? 0 + let translation = maxHeight - activePopupHeight - activePopupDragHeight return translation * getDragTranslationMultiplier() } func calculateDragExtremeValue(_ value1: CGFloat, _ value2: CGFloat) -> CGFloat { switch alignment { From bb7c8c56329a41de9ef37c8f5550d613522cf29a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:39:48 +0100 Subject: [PATCH 236/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 8339cecd21..52a30fcf1f 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -381,11 +381,9 @@ private extension VM.VerticalStack { .sorted(by: <) } func calculateTargetPopupHeight(_ currentPopupHeight: CGFloat, _ popupTargetHeights: [CGFloat]) -> CGFloat { - guard let activePopupHeight = popups.last?.height, - currentPopupHeight < screen.height - else { return popupTargetHeights.last ?? 0 } + guard let activePopupHeight = popups.last?.height, currentPopupHeight < screen.height else { return popupTargetHeights.last ?? 0 } - let initialIndex = popupTargetHeights.firstIndex(where: { $0 >= currentPopupHeight }) ?? popupTargetHeights.count - 1, + let initialIndex = popupTargetHeights.firstIndex { $0 >= currentPopupHeight } ?? popupTargetHeights.count - 1, targetIndex = activePopup.gestureTranslation * getDragTranslationMultiplier() > 0 ? initialIndex : max(0, initialIndex - 1) let previousPopupHeight = (popups.last?.dragHeight ?? 0) + activePopupHeight, popupTargetHeight = popupTargetHeights[targetIndex], From b64f20ee4c9ca035ed75a0b3b3fa529326c8e56f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:40:36 +0100 Subject: [PATCH 237/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 52a30fcf1f..e5c777b1b9 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -285,6 +285,19 @@ extension VM.VerticalStack { } } +// MARK: Attributes +extension VM.VerticalStack { + var stackScaleFactor: CGFloat { 0.025 } + var stackOverlayFactor: CGFloat { 0.1 } + var maxStackOverlayFactor: CGFloat { 0.48 } + var stackOffset: CGFloat { GlobalConfigContainer.vertical.isStackingEnabled ? 8 : 0 } + var dragThreshold: CGFloat { GlobalConfigContainer.vertical.dragThreshold } + var dragGestureEnabled: Bool { popups.last?.config.isDragGestureEnabled ?? false } + var dragTranslationThreshold: CGFloat { 8 } + var minScaleProgressMultiplier: CGFloat { 0.7 } + var minStackOverlayProgressMultiplier: CGFloat { 0.6 } +} + // MARK: - GESTURES From 4a9e69d390fff485f50aa0b7a88fd98b634e9c10 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:48:20 +0100 Subject: [PATCH 238/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index e5c777b1b9..26a970dfe7 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -352,11 +352,11 @@ private extension VM.VerticalStack { // MARK: On Ended extension VM.VerticalStack { @MainActor func onPopupDragGestureEnded(_ value: CGFloat) async { Task { - guard value != 0, let activePopup = popups.last, let activePopupHeight = activePopup.height else { return } + guard value != 0, let activePopup = popups.last else { return } await dismissLastPopupIfNeeded(activePopup) - let targetDragHeight = await calculateTargetDragHeight(activePopupHeight) + let targetDragHeight = await calculateTargetDragHeight(activePopup) await updateGestureTranslation(0) await updateDragHeight(targetDragHeight, activePopup) }} @@ -366,24 +366,24 @@ private extension VM.VerticalStack { case true: await closePopupAction(popup) case false: return }} - func calculateTargetDragHeight(_ activePopupHeight: CGFloat) async -> CGFloat { - let currentPopupHeight = calculateCurrentPopupHeight(activePopupHeight) - let popupTargetHeights = calculatePopupTargetHeightsFromDragDetents(activePopupHeight) + func calculateTargetDragHeight(_ activePopup: AnyPopup) async -> CGFloat { + guard let activePopupHeight = activePopup.height else { return 0 } + + let currentPopupHeight = calculateCurrentPopupHeight(activePopupHeight: activePopupHeight, activePopupDragHeight: activePopup.dragHeight) + let popupTargetHeights = calculatePopupTargetHeightsFromDragDetents(activePopupHeight: activePopupHeight, activePopupConfig: activePopup.config) let targetHeight = calculateTargetPopupHeight(currentPopupHeight, popupTargetHeights) let targetDragHeight = calculateTargetDragHeight(targetHeight, activePopupHeight) return targetDragHeight } } private extension VM.VerticalStack { - func calculateCurrentPopupHeight(_ activePopupHeight: CGFloat) -> CGFloat { - let activePopupDragHeight = popups.last?.dragHeight ?? 0 + func calculateCurrentPopupHeight(activePopupHeight: CGFloat, activePopupDragHeight: CGFloat) -> CGFloat { let currentDragHeight = activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() - let currentPopupHeight = activePopupHeight + currentDragHeight return currentPopupHeight } - func calculatePopupTargetHeightsFromDragDetents(_ activePopupHeight: CGFloat) -> [CGFloat] { guard let dragDetents = popups.last?.config.dragDetents else { return [activePopupHeight] }; return - dragDetents + func calculatePopupTargetHeightsFromDragDetents(activePopupHeight: CGFloat, activePopupConfig: AnyPopupConfig) -> [CGFloat] { + activePopupConfig.dragDetents .map { switch $0 { case .height(let targetHeight): min(targetHeight, calculateLargeScreenHeight()) case .fraction(let fraction): min(fraction * activePopupHeight, calculateLargeScreenHeight()) From 86f757daac78e6977293e0b3f2d09afd54d7a73f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:55:46 +0100 Subject: [PATCH 239/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 26a970dfe7..965e7b4db8 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -324,16 +324,16 @@ private extension VM.VerticalStack { calculateDragExtremeValue(value, 0) } func calculateGestureTranslationWhenDragDetents(_ value: CGFloat) -> CGFloat { - guard value * getDragTranslationMultiplier() > 0, let activePopupHeight = popups.last?.height else { return value } + guard value * getDragTranslationMultiplier() > 0, let activePopup = popups.last, let activePopupHeight = activePopup.height else { return value } - let maxHeight = calculateMaxHeightForDragGesture(activePopupHeight) + let maxHeight = calculateMaxHeightForDragGesture(activePopupHeight, activePopup.config) let dragTranslation = calculateDragTranslation(maxHeight, activePopupHeight) return calculateDragExtremeValue(dragTranslation, value) } } private extension VM.VerticalStack { - func calculateMaxHeightForDragGesture(_ activePopupHeight: CGFloat) -> CGFloat { - let maxDragDetent = calculatePopupTargetHeightsFromDragDetents(activePopupHeight).max() ?? 0 + func calculateMaxHeightForDragGesture(_ activePopupHeight: CGFloat, _ activePopupConfig: AnyPopupConfig) -> CGFloat { + let maxDragDetent = calculatePopupTargetHeightsFromDragDetents(activePopupHeight, activePopupConfig).max() ?? 0 let maxHeightCandidate = maxDragDetent + dragTranslationThreshold return min(maxHeightCandidate, screen.height) } @@ -382,7 +382,7 @@ private extension VM.VerticalStack { let currentPopupHeight = activePopupHeight + currentDragHeight return currentPopupHeight } - func calculatePopupTargetHeightsFromDragDetents(activePopupHeight: CGFloat, activePopupConfig: AnyPopupConfig) -> [CGFloat] { + func calculatePopupTargetHeightsFromDragDetents(_ activePopupHeight: CGFloat, _ activePopupConfig: AnyPopupConfig) -> [CGFloat] { activePopupConfig.dragDetents .map { switch $0 { case .height(let targetHeight): min(targetHeight, calculateLargeScreenHeight()) From 502b8a8e768b8072a8d48f966194695878a7714f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:56:20 +0100 Subject: [PATCH 240/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 965e7b4db8..db32c22bc2 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -370,8 +370,8 @@ private extension VM.VerticalStack { guard let activePopupHeight = activePopup.height else { return 0 } let currentPopupHeight = calculateCurrentPopupHeight(activePopupHeight: activePopupHeight, activePopupDragHeight: activePopup.dragHeight) - let popupTargetHeights = calculatePopupTargetHeightsFromDragDetents(activePopupHeight: activePopupHeight, activePopupConfig: activePopup.config) - let targetHeight = calculateTargetPopupHeight(currentPopupHeight, popupTargetHeights) + let popupTargetHeights = calculatePopupTargetHeightsFromDragDetents(activePopupHeight, activePopup.config) + let targetHeight = calculateTargetPopupHeight(activePopupHeight: activePopupHeight, activePopupDragHeight: activePopup.dragHeight, currentPopupHeight: currentPopupHeight, popupTargetHeights: popupTargetHeights) let targetDragHeight = calculateTargetDragHeight(targetHeight, activePopupHeight) return targetDragHeight } @@ -393,12 +393,12 @@ private extension VM.VerticalStack { .modified { $0.append(activePopupHeight) } .sorted(by: <) } - func calculateTargetPopupHeight(_ currentPopupHeight: CGFloat, _ popupTargetHeights: [CGFloat]) -> CGFloat { - guard let activePopupHeight = popups.last?.height, currentPopupHeight < screen.height else { return popupTargetHeights.last ?? 0 } + func calculateTargetPopupHeight(activePopupHeight: CGFloat, activePopupDragHeight: CGFloat, currentPopupHeight: CGFloat, popupTargetHeights: [CGFloat]) -> CGFloat { + guard currentPopupHeight < screen.height else { return popupTargetHeights.last ?? 0 } let initialIndex = popupTargetHeights.firstIndex { $0 >= currentPopupHeight } ?? popupTargetHeights.count - 1, targetIndex = activePopup.gestureTranslation * getDragTranslationMultiplier() > 0 ? initialIndex : max(0, initialIndex - 1) - let previousPopupHeight = (popups.last?.dragHeight ?? 0) + activePopupHeight, + let previousPopupHeight = activePopupDragHeight + activePopupHeight, popupTargetHeight = popupTargetHeights[targetIndex], deltaHeight = abs(previousPopupHeight - popupTargetHeight) let progress = abs(currentPopupHeight - previousPopupHeight) / deltaHeight From 156886e2a003d607c9e9093257b72c3303622822 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 01:56:31 +0100 Subject: [PATCH 241/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index db32c22bc2..2fd48755c3 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -413,18 +413,3 @@ private extension VM.VerticalStack { targetHeight - activePopupHeight } } - - - -// MARK: - ATTRIBUTES -extension VM.VerticalStack { - var stackScaleFactor: CGFloat { 0.025 } - var stackOverlayFactor: CGFloat { 0.1 } - var maxStackOverlayFactor: CGFloat { 0.48 } - var stackOffset: CGFloat { GlobalConfigContainer.vertical.isStackingEnabled ? 8 : 0 } - var dragThreshold: CGFloat { GlobalConfigContainer.vertical.dragThreshold } - var dragGestureEnabled: Bool { popups.last?.config.isDragGestureEnabled ?? false } - var dragTranslationThreshold: CGFloat { 8 } - var minScaleProgressMultiplier: CGFloat { 0.7 } - var minStackOverlayProgressMultiplier: CGFloat { 0.6 } -} From 29cc64a5ba72e9e6cda611c75c58e57a95655341 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 02:02:52 +0100 Subject: [PATCH 242/407] 1 --- Sources/Internal/View Models/ViewModel+CentreStack.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 1063487158..459e5a22f4 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -44,9 +44,7 @@ extension VM.CentreStack { } private extension VM.CentreStack { func calculateVerticalPopupPadding(for edge: PopupAlignment) -> CGFloat { - guard let activePopupHeight = activePopup.height, - screen.isKeyboardActive && edge == .bottom - else { return 0 } + guard let activePopupHeight = activePopup.height, screen.isKeyboardActive && edge == .bottom else { return 0 } let remainingHeight = screen.height - activePopupHeight let paddingCandidate = (remainingHeight / 2 - screen.safeArea.bottom) * 2 From 611228fa2d0aa4f1c37e91023980350c702e908f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 02:03:59 +0100 Subject: [PATCH 243/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 00c2c0be40..440b3c2c67 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -41,7 +41,7 @@ extension ViewModel { // MARK: Setup extension ViewModel { - func setup(updatePopupAction: @escaping (AnyPopup) async -> (), closePopupAction: @escaping (AnyPopup) async -> ()) { + @MainActor func setup(updatePopupAction: @escaping (AnyPopup) async -> (), closePopupAction: @escaping (AnyPopup) async -> ()) { self.updatePopupAction = updatePopupAction self.closePopupAction = closePopupAction } From e30a3d9fb9ad6ca71c28822bf3fead2befbd49b9 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 12:26:59 +0100 Subject: [PATCH 244/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 440b3c2c67..3d68e167b3 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -51,19 +51,13 @@ extension ViewModel { extension ViewModel { @MainActor func updatePopupsValue(_ newPopups: [AnyPopup]) async { Task { @MainActor in popups = await filterPopups(newPopups) - - activePopup.height = await calculateActivePopupHeight() - activePopup.outerPadding = await calculateActivePopupOuterPadding() - activePopup.innerPadding = await calculateActivePopupInnerPadding() - activePopup.corners = await calculateActivePopupCorners() - activePopup.verticalFixedSize = await calculateActivePopupVerticalFixedSize() + await aa() withAnimation(.transition) { objectWillChange.send() } }} @MainActor func updateScreenValue(screenReader: GeometryProxy? = nil, isKeyboardActive: Bool? = nil) async { Task { @MainActor in screen.update(screenReader: screenReader, isKeyboardActive: isKeyboardActive) - activePopup.outerPadding = await calculateActivePopupOuterPadding() - activePopup.innerPadding = await calculateActivePopupInnerPadding() + await aa() withAnimation(.transition) { objectWillChange.send() } }} @@ -90,6 +84,13 @@ private extension ViewModel { func filterPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { popups.filter { $0.config.alignment == alignment } } + func aa() async { + activePopup.height = await calculateActivePopupHeight() + activePopup.outerPadding = await calculateActivePopupOuterPadding() + activePopup.innerPadding = await calculateActivePopupInnerPadding() + activePopup.corners = await calculateActivePopupCorners() + activePopup.verticalFixedSize = await calculateActivePopupVerticalFixedSize() + } } From 6fdf0bc7762b7dce6e2a0210f333240d10ed1182 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 12:41:20 +0100 Subject: [PATCH 245/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 45 +++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 3d68e167b3..62b5f9713c 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -34,7 +34,13 @@ protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == Obs func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat } -// MARK: Initializer + + +// MARK: - INIT & SETUP + + + +// MARK: Initialize extension ViewModel { init(_ config: Config.Type) { self.init(); self.alignment = .init(Config.self) } } @@ -47,6 +53,43 @@ extension ViewModel { } } + + +// MARK: MARK: UPDATE + + + +// MARK: Popups +extension ViewModel { + +} + +// MARK: Screen +extension ViewModel { +} + +// MARK: Gesture +extension ViewModel { + +} + +// MARK: Popup Height +extension ViewModel { + +} + +// MARK: Popup Drag Height +extension ViewModel { + +} + +// MARK: Helpers +private extension ViewModel { + +} + + + // MARK: Update extension ViewModel { @MainActor func updatePopupsValue(_ newPopups: [AnyPopup]) async { Task { @MainActor in From b189db3f180572e3679618e7bc69684d59d7e626 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 12:42:22 +0100 Subject: [PATCH 246/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 62b5f9713c..512ba93cc8 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -85,7 +85,7 @@ extension ViewModel { // MARK: Helpers private extension ViewModel { - + } @@ -93,14 +93,14 @@ private extension ViewModel { // MARK: Update extension ViewModel { @MainActor func updatePopupsValue(_ newPopups: [AnyPopup]) async { Task { @MainActor in - popups = await filterPopups(newPopups) - await aa() + popups = await filteredPopups(newPopups) + await updateActivePopupProperties() withAnimation(.transition) { objectWillChange.send() } }} @MainActor func updateScreenValue(screenReader: GeometryProxy? = nil, isKeyboardActive: Bool? = nil) async { Task { @MainActor in screen.update(screenReader: screenReader, isKeyboardActive: isKeyboardActive) - await aa() + await updateActivePopupProperties() withAnimation(.transition) { objectWillChange.send() } }} @@ -124,10 +124,10 @@ extension ViewModel { } } private extension ViewModel { - func filterPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { + func filteredPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { popups.filter { $0.config.alignment == alignment } } - func aa() async { + func updateActivePopupProperties() async { activePopup.height = await calculateActivePopupHeight() activePopup.outerPadding = await calculateActivePopupOuterPadding() activePopup.innerPadding = await calculateActivePopupInnerPadding() From 202e05c6dce67bfcf6a347af809fc9284972ade9 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:00:12 +0100 Subject: [PATCH 247/407] 1 --- Sources/Internal/Models/Screen.swift | 21 ++++---------------- Sources/Internal/View Models/ViewModel.swift | 15 +++++++++++--- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Sources/Internal/Models/Screen.swift b/Sources/Internal/Models/Screen.swift index e45499bdcb..453d1d535a 100644 --- a/Sources/Internal/Models/Screen.swift +++ b/Sources/Internal/Models/Screen.swift @@ -11,10 +11,10 @@ import SwiftUI -struct Screen { - private(set) var height: CGFloat - private(set) var safeArea: EdgeInsets - private(set) var isKeyboardActive: Bool +struct Screen: Sendable { + let height: CGFloat + let safeArea: EdgeInsets + let isKeyboardActive: Bool init(height: CGFloat = .zero, safeArea: EdgeInsets = .init(), isKeyboardActive: Bool = false) { @@ -23,16 +23,3 @@ struct Screen { self.isKeyboardActive = isKeyboardActive } } - -// MARK: Update -extension Screen { - mutating func update(screenReader: GeometryProxy?, isKeyboardActive: Bool?) { - if let screenReader { - self.height = screenReader.size.height + screenReader.safeAreaInsets.top + screenReader.safeAreaInsets.bottom - self.safeArea = screenReader.safeAreaInsets - } - if let isKeyboardActive { - self.isKeyboardActive = isKeyboardActive - } - } -} diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 512ba93cc8..42fc394ed7 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -99,7 +99,7 @@ extension ViewModel { withAnimation(.transition) { objectWillChange.send() } }} @MainActor func updateScreenValue(screenReader: GeometryProxy? = nil, isKeyboardActive: Bool? = nil) async { Task { @MainActor in - screen.update(screenReader: screenReader, isKeyboardActive: isKeyboardActive) + screen = await updatedScreenProperties(screenReader, isKeyboardActive) await updateActivePopupProperties() withAnimation(.transition) { objectWillChange.send() } @@ -127,6 +127,17 @@ private extension ViewModel { func filteredPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { popups.filter { $0.config.alignment == alignment } } + func updatedScreenProperties(_ screenReader: GeometryProxy?, _ isKeyboardActive: Bool?) async -> Screen { + let height = if let screenReader { screenReader.size.height + screenReader.safeAreaInsets.top + screenReader.safeAreaInsets.bottom } else { screen.height }, + safeArea = screenReader?.safeAreaInsets ?? screen.safeArea, + isKeyboardActive = isKeyboardActive ?? screen.isKeyboardActive + return .init(height: height, safeArea: safeArea, isKeyboardActive: isKeyboardActive) + } + + + + + func updateActivePopupProperties() async { activePopup.height = await calculateActivePopupHeight() activePopup.outerPadding = await calculateActivePopupOuterPadding() @@ -143,8 +154,6 @@ private extension ViewModel { - - struct ActivePopup: Sendable { var height: CGFloat? = nil var innerPadding: EdgeInsets = .init() From 3f6859d8744534f760ee6052f5735eb75268eb32 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:03:23 +0100 Subject: [PATCH 248/407] 1 --- Sources/Internal/UI/PopupView.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 10 +++--- .../Tests+ViewModel+PopupVerticalStack.swift | 32 +++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index b9480332ce..3a799a2d85 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -89,7 +89,7 @@ private extension PopupView { await updateViewModels { await $0.updateScreenValue(screenReader: screenReader) } }} func onPopupsHeightChange(_ p: Any) { Task { @MainActor in - await updateViewModels { await $0.updatePopupsValue(popupManager.stack) } + await updateViewModels { await $0.updatePopups(popupManager.stack) } }} func onStackChange(_ oldStack: [AnyPopup], _ newStack: [AnyPopup]) { newStack diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 42fc394ed7..dd323d8e2a 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -61,7 +61,12 @@ extension ViewModel { // MARK: Popups extension ViewModel { + @MainActor func updatePopups(_ newPopups: [AnyPopup]) async { Task { + popups = await filteredPopups(newPopups) + await updateActivePopupProperties() + withAnimation(.transition) { objectWillChange.send() } + }} } // MARK: Screen @@ -92,12 +97,7 @@ private extension ViewModel { // MARK: Update extension ViewModel { - @MainActor func updatePopupsValue(_ newPopups: [AnyPopup]) async { Task { @MainActor in - popups = await filteredPopups(newPopups) - await updateActivePopupProperties() - withAnimation(.transition) { objectWillChange.send() } - }} @MainActor func updateScreenValue(screenReader: GeometryProxy? = nil, isKeyboardActive: Bool? = nil) async { Task { @MainActor in screen = await updatedScreenProperties(screenReader, isKeyboardActive) await updateActivePopupProperties() diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 3bfec3cdbb..d0046c4140 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -33,13 +33,13 @@ private extension PopupVerticalStackViewModelTests { var popups = viewModel.popups popups[index] = popup - await viewModel.updatePopupsValue(popups) + await viewModel.updatePopups(popups) }} func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.popups.firstIndex(of: popup) { var popups = viewModel.popups popups.remove(at: index) - await viewModel.updatePopupsValue(popups) + await viewModel.updatePopups(popups) }} } @@ -52,7 +52,7 @@ private extension PopupVerticalStackViewModelTests { // MARK: Inverted Index extension PopupVerticalStackViewModelTests { func test_getInvertedIndex_1() async { - await bottomViewModel.updatePopupsValue([ + await bottomViewModel.updatePopups([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150) ]) @@ -62,7 +62,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_getInvertedIndex_2() async { - await bottomViewModel.updatePopupsValue([ + await bottomViewModel.updatePopups([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), @@ -132,7 +132,7 @@ extension PopupVerticalStackViewModelTests { } private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckPopups(viewModel: ViewModel, popups: [AnyPopup], updatedPopup: AnyPopup, expectedValue: (height: CGFloat?, dragHeight: CGFloat?)) async { - await viewModel.updatePopupsValue(popups) + await viewModel.updatePopups(popups) await viewModel.updatePopupAction(updatedPopup) if let index = viewModel.popups.firstIndex(of: updatedPopup) { @@ -463,7 +463,7 @@ private extension PopupVerticalStackViewModelTests { // MARK: Offset extension PopupVerticalStackViewModelTests { func test_calculateOffsetY_withZeroGestureTranslation_fivePopupsStacked_thirdElement() async { - await bottomViewModel.updatePopupsValue([ + await bottomViewModel.updatePopups([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 240), @@ -477,7 +477,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withZeroGestureTranslation_fivePopupsStacked_lastElement() async { - await bottomViewModel.updatePopupsValue([ + await bottomViewModel.updatePopups([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 240), @@ -491,7 +491,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withNegativeGestureTranslation_dragHeight_onePopupStacked() async { - await bottomViewModel.updatePopupsValue([ + await bottomViewModel.updatePopups([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 100) ]) await bottomViewModel.updateGestureTranslation(-100) @@ -502,7 +502,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withPositiveGestureTranslation_dragHeight_twoPopupsStacked_firstElement() async { - await bottomViewModel.updatePopupsValue([ + await bottomViewModel.updatePopups([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) @@ -514,7 +514,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withPositiveGestureTranslation_dragHeight_twoPopupsStacked_lastElement() async { - await bottomViewModel.updatePopupsValue([ + await bottomViewModel.updatePopups([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) @@ -526,7 +526,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withStackingDisabled() async { - await bottomViewModel.updatePopupsValue([ + await bottomViewModel.updatePopups([ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) @@ -538,7 +538,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withPopupsHaveTopAlignment_1() async { - await topViewModel.updatePopupsValue([ + await topViewModel.updatePopups([ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) @@ -549,7 +549,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOffsetY_withPopupsHaveTopAlignment_2() async { - await topViewModel.updatePopupsValue([ + await topViewModel.updatePopups([ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) @@ -1296,7 +1296,7 @@ extension PopupVerticalStackViewModelTests { } private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnChange(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat, gestureTranslation: CGFloat)) async { - await viewModel.updatePopupsValue(popups) + await viewModel.updatePopups(popups) await updatePopups(viewModel) await viewModel.onPopupDragGestureChanged(gestureValue) @@ -1466,7 +1466,7 @@ extension PopupVerticalStackViewModelTests { } private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnEnd(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat?, shouldPopupBeDismissed: Bool)) async { - await viewModel.updatePopupsValue(popups) + await viewModel.updatePopups(popups) await updatePopups(viewModel) await viewModel.updateGestureTranslation(gestureValue) await viewModel.onPopupDragGestureEnded(gestureValue) @@ -1492,7 +1492,7 @@ private extension PopupVerticalStackViewModelTests { .settingDragHeight(popupDragHeight) } func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { - await viewModel.updatePopupsValue(popups) + await viewModel.updatePopups(popups) await updatePopups(viewModel) await viewModel.updateGestureTranslation(gestureTranslation) From fe1cc4da8a0bd6eb9637b5892e01326123a4868b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:03:54 +0100 Subject: [PATCH 249/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index dd323d8e2a..b7c24b741f 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -71,6 +71,12 @@ extension ViewModel { // MARK: Screen extension ViewModel { + @MainActor func updateScreenValue(screenReader: GeometryProxy? = nil, isKeyboardActive: Bool? = nil) async { Task { + screen = await updatedScreenProperties(screenReader, isKeyboardActive) + await updateActivePopupProperties() + + withAnimation(.transition) { objectWillChange.send() } + }} } // MARK: Gesture @@ -98,12 +104,7 @@ private extension ViewModel { // MARK: Update extension ViewModel { - @MainActor func updateScreenValue(screenReader: GeometryProxy? = nil, isKeyboardActive: Bool? = nil) async { Task { @MainActor in - screen = await updatedScreenProperties(screenReader, isKeyboardActive) - await updateActivePopupProperties() - withAnimation(.transition) { objectWillChange.send() } - }} @MainActor func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { Task { @MainActor in guard activePopup.gestureTranslation == 0 else { return } From d60010ff5c6ba035ba1c6dfd0cbc6cee465a4725 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:33:26 +0100 Subject: [PATCH 250/407] 1 --- Sources/Internal/UI/PopupCentreStackView.swift | 2 +- Sources/Internal/UI/PopupVerticalStackView.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 2 +- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/UI/PopupCentreStackView.swift b/Sources/Internal/UI/PopupCentreStackView.swift index e2fa98496b..1dab7d9b81 100644 --- a/Sources/Internal/UI/PopupCentreStackView.swift +++ b/Sources/Internal/UI/PopupCentreStackView.swift @@ -31,7 +31,7 @@ private extension PopupCentreStackView { func createPopup(_ popup: AnyPopup) -> some View { popup.body .fixedSize(horizontal: false, vertical: viewModel.activePopup.verticalFixedSize) - .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } + .onHeightChange { await viewModel.updatePopupHeight($0, popup) } .frame(height: viewModel.activePopup.height) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopup.height) .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.activePopup.corners) diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index f7aa8f6a5e..fbb477d073 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -31,7 +31,7 @@ private extension PopupVerticalStackView { popup.body .padding(viewModel.activePopup.innerPadding) .fixedSize(horizontal: false, vertical: viewModel.activePopup.verticalFixedSize) - .onHeightChange { await viewModel.recalculateAndUpdatePopupHeight($0, popup) } + .onHeightChange { await viewModel.updatePopupHeight($0, popup) } .frame(height: viewModel.activePopup.height, alignment: (!viewModel.alignment).toAlignment()) .frame(maxWidth: .infinity, maxHeight: viewModel.activePopup.height, alignment: (!viewModel.alignment).toAlignment()) .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: viewModel.activePopup.corners) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index b7c24b741f..50fbb83aca 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -105,7 +105,7 @@ private extension ViewModel { extension ViewModel { - @MainActor func recalculateAndUpdatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { Task { @MainActor in + @MainActor func updatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { Task { guard activePopup.gestureTranslation == 0 else { return } let newHeight = await calculatePopupHeight(heightCandidate, popup) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index d0046c4140..5bd99300f6 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1511,7 +1511,7 @@ private extension PopupVerticalStackViewModelTests { isDragGestureEnabled: dragGestureEnabled )} func updatePopups(_ viewModel: ViewModel) async { - for popup in viewModel.popups { await viewModel.recalculateAndUpdatePopupHeight(popup.height!, popup) } + for popup in viewModel.popups { await viewModel.updatePopupHeight(popup.height!, popup) } } } From bdf2fae73737b26621cc0dc02643bc02ea5bcaff Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:34:57 +0100 Subject: [PATCH 251/407] 1 --- .../Internal/View Models/ViewModel+VerticalStack.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 2fd48755c3..a424b47926 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -358,7 +358,7 @@ extension VM.VerticalStack { let targetDragHeight = await calculateTargetDragHeight(activePopup) await updateGestureTranslation(0) - await updateDragHeight(targetDragHeight, activePopup) + await updatePopupDragHeight(targetDragHeight, activePopup) }} } private extension VM.VerticalStack { diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 50fbb83aca..fb9d3f8863 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -79,7 +79,7 @@ extension ViewModel { }} } -// MARK: Gesture +// MARK: Gesture Translation extension ViewModel { } @@ -91,7 +91,9 @@ extension ViewModel { // MARK: Popup Drag Height extension ViewModel { - + @MainActor func updatePopupDragHeight(_ targetDragHeight: CGFloat, _ popup: AnyPopup) async { Task { + await updatePopupAction(popup.updatedDragHeight(targetDragHeight)) + }} } // MARK: Helpers @@ -120,9 +122,6 @@ extension ViewModel { withAnimation(activePopup.gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } }} - @MainActor func updateDragHeight(_ targetDragHeight: CGFloat, _ popup: AnyPopup) async { - await updatePopupAction(popup.updatedDragHeight(targetDragHeight)) - } } private extension ViewModel { func filteredPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { From 743cb13dbb2f89ed34e8a1b2b17bc6d551f70c77 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:35:48 +0100 Subject: [PATCH 252/407] 1 --- Sources/Internal/UI/PopupView.swift | 4 ++-- Sources/Internal/View Models/ViewModel.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 3a799a2d85..a21064746c 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -86,7 +86,7 @@ private extension PopupView { await updateViewModels { $0.setup(updatePopupAction: updatePopup, closePopupAction: closePopup) } }} func onScreenChange(_ screenReader: GeometryProxy) { Task { @MainActor in - await updateViewModels { await $0.updateScreenValue(screenReader: screenReader) } + await updateViewModels { await $0.updateScreen(screenReader: screenReader) } }} func onPopupsHeightChange(_ p: Any) { Task { @MainActor in await updateViewModels { await $0.updatePopups(popupManager.stack) } @@ -101,7 +101,7 @@ private extension PopupView { newStack.last?.onFocus() } func onKeyboardStateChange(_ isKeyboardActive: Bool) { Task { @MainActor in - await updateViewModels { await $0.updateScreenValue(isKeyboardActive: isKeyboardActive) } + await updateViewModels { await $0.updateScreen(isKeyboardActive: isKeyboardActive) } }} func onTap() { if tapOutsideClosesPopup { popupManager.stack(.removeLastPopup) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index fb9d3f8863..c7bf33ef9d 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -71,7 +71,7 @@ extension ViewModel { // MARK: Screen extension ViewModel { - @MainActor func updateScreenValue(screenReader: GeometryProxy? = nil, isKeyboardActive: Bool? = nil) async { Task { + @MainActor func updateScreen(screenReader: GeometryProxy? = nil, isKeyboardActive: Bool? = nil) async { Task { screen = await updatedScreenProperties(screenReader, isKeyboardActive) await updateActivePopupProperties() From 62374f9f55166ff32378c41679075d7e9789b15a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:37:00 +0100 Subject: [PATCH 253/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 42 +++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index c7bf33ef9d..9bb01b0caa 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -98,7 +98,24 @@ extension ViewModel { // MARK: Helpers private extension ViewModel { - + func filteredPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { + popups.filter { $0.config.alignment == alignment } + } + func updatedScreenProperties(_ screenReader: GeometryProxy?, _ isKeyboardActive: Bool?) async -> Screen { + let height = if let screenReader { screenReader.size.height + screenReader.safeAreaInsets.top + screenReader.safeAreaInsets.bottom } else { screen.height }, + safeArea = screenReader?.safeAreaInsets ?? screen.safeArea, + isKeyboardActive = isKeyboardActive ?? screen.isKeyboardActive + return .init(height: height, safeArea: safeArea, isKeyboardActive: isKeyboardActive) + } +} +private extension ViewModel { + func updateActivePopupProperties() async { + activePopup.height = await calculateActivePopupHeight() + activePopup.outerPadding = await calculateActivePopupOuterPadding() + activePopup.innerPadding = await calculateActivePopupInnerPadding() + activePopup.corners = await calculateActivePopupCorners() + activePopup.verticalFixedSize = await calculateActivePopupVerticalFixedSize() + } } @@ -123,29 +140,6 @@ extension ViewModel { withAnimation(activePopup.gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } }} } -private extension ViewModel { - func filteredPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { - popups.filter { $0.config.alignment == alignment } - } - func updatedScreenProperties(_ screenReader: GeometryProxy?, _ isKeyboardActive: Bool?) async -> Screen { - let height = if let screenReader { screenReader.size.height + screenReader.safeAreaInsets.top + screenReader.safeAreaInsets.bottom } else { screen.height }, - safeArea = screenReader?.safeAreaInsets ?? screen.safeArea, - isKeyboardActive = isKeyboardActive ?? screen.isKeyboardActive - return .init(height: height, safeArea: safeArea, isKeyboardActive: isKeyboardActive) - } - - - - - - func updateActivePopupProperties() async { - activePopup.height = await calculateActivePopupHeight() - activePopup.outerPadding = await calculateActivePopupOuterPadding() - activePopup.innerPadding = await calculateActivePopupInnerPadding() - activePopup.corners = await calculateActivePopupCorners() - activePopup.verticalFixedSize = await calculateActivePopupVerticalFixedSize() - } -} From 6ac432b001069a8d3737f215eb3eef046fa1642b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:37:59 +0100 Subject: [PATCH 254/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 9bb01b0caa..c068ea007d 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -128,9 +128,9 @@ extension ViewModel { guard activePopup.gestureTranslation == 0 else { return } let newHeight = await calculatePopupHeight(heightCandidate, popup) - guard newHeight != popup.height else { return } - - await updatePopupAction(popup.updatedHeight(newHeight)) + if newHeight != popup.height { + await updatePopupAction(popup.updatedHeight(newHeight)) + } }} @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { Task { @MainActor in activePopup.gestureTranslation = newGestureTranslation From c4fbb107b757c792af9ca3c9a0aad9aac10c933f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:38:51 +0100 Subject: [PATCH 255/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index c068ea007d..6b613d8c06 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -86,7 +86,14 @@ extension ViewModel { // MARK: Popup Height extension ViewModel { + @MainActor func updatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { Task { + guard activePopup.gestureTranslation == 0 else { return } + let newHeight = await calculatePopupHeight(heightCandidate, popup) + if newHeight != popup.height { + await updatePopupAction(popup.updatedHeight(newHeight)) + } + }} } // MARK: Popup Drag Height @@ -124,14 +131,7 @@ private extension ViewModel { extension ViewModel { - @MainActor func updatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { Task { - guard activePopup.gestureTranslation == 0 else { return } - let newHeight = await calculatePopupHeight(heightCandidate, popup) - if newHeight != popup.height { - await updatePopupAction(popup.updatedHeight(newHeight)) - } - }} @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { Task { @MainActor in activePopup.gestureTranslation = newGestureTranslation activePopup.translationProgress = await calculateActivePopupTranslationProgress() From e623943cc9d525189becd81d9d459a5c75d474a2 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:39:32 +0100 Subject: [PATCH 256/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 25 +++++--------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 6b613d8c06..684bba1032 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -81,7 +81,13 @@ extension ViewModel { // MARK: Gesture Translation extension ViewModel { + @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { Task { + activePopup.gestureTranslation = newGestureTranslation + activePopup.translationProgress = await calculateActivePopupTranslationProgress() + activePopup.height = await calculateActivePopupHeight() + withAnimation(activePopup.gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } + }} } // MARK: Popup Height @@ -127,25 +133,6 @@ private extension ViewModel { -// MARK: Update -extension ViewModel { - - - - @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { Task { @MainActor in - activePopup.gestureTranslation = newGestureTranslation - activePopup.translationProgress = await calculateActivePopupTranslationProgress() - activePopup.height = await calculateActivePopupHeight() - - withAnimation(activePopup.gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } - }} -} - - - - - - struct ActivePopup: Sendable { From 37a71d4ecee2902e36f61a9dafef0511cabb0bcf Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:42:55 +0100 Subject: [PATCH 257/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 684bba1032..d7307eab6a 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -82,9 +82,7 @@ extension ViewModel { // MARK: Gesture Translation extension ViewModel { @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { Task { - activePopup.gestureTranslation = newGestureTranslation - activePopup.translationProgress = await calculateActivePopupTranslationProgress() - activePopup.height = await calculateActivePopupHeight() + await updateActivePopupPropertiesOnGestureTranslationChange(newGestureTranslation) withAnimation(activePopup.gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } }} @@ -129,6 +127,11 @@ private extension ViewModel { activePopup.corners = await calculateActivePopupCorners() activePopup.verticalFixedSize = await calculateActivePopupVerticalFixedSize() } + func updateActivePopupPropertiesOnGestureTranslationChange(_ newGestureTranslation: CGFloat) async { + activePopup.gestureTranslation = newGestureTranslation + activePopup.translationProgress = await calculateActivePopupTranslationProgress() + activePopup.height = await calculateActivePopupHeight() + } } From faa91d2a329b6ee38034b55983b88f79dd758012 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:44:13 +0100 Subject: [PATCH 258/407] 1 --- Sources/Internal/Models/ActivePopup.swift | 22 ++++++++++++++++++++ Sources/Internal/View Models/ViewModel.swift | 14 ------------- 2 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 Sources/Internal/Models/ActivePopup.swift diff --git a/Sources/Internal/Models/ActivePopup.swift b/Sources/Internal/Models/ActivePopup.swift new file mode 100644 index 0000000000..9ee05816dc --- /dev/null +++ b/Sources/Internal/Models/ActivePopup.swift @@ -0,0 +1,22 @@ +// +// ActivePopup.swift of MijickPopups +// +// Created by Tomasz Kurylik. Sending ❤️ from Kraków! +// - Mail: tomasz.kurylik@mijick.com +// - GitHub: https://github.com/FulcrumOne +// - Medium: https://medium.com/@mijick +// +// Copyright ©2024 Mijick. All rights reserved. + + +import SwiftUI + +struct ActivePopup: Sendable { + var height: CGFloat? = nil + var innerPadding: EdgeInsets = .init() + var outerPadding: EdgeInsets = .init() + var corners: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] + var verticalFixedSize: Bool = true + var gestureTranslation: CGFloat = 0 + var translationProgress: CGFloat = 0 +} diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index d7307eab6a..f5a3e33544 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -133,17 +133,3 @@ private extension ViewModel { activePopup.height = await calculateActivePopupHeight() } } - - - - - -struct ActivePopup: Sendable { - var height: CGFloat? = nil - var innerPadding: EdgeInsets = .init() - var outerPadding: EdgeInsets = .init() - var corners: [PopupAlignment: CGFloat] = [.top: 0, .bottom: 0] - var verticalFixedSize: Bool = true - var gestureTranslation: CGFloat = 0 - var translationProgress: CGFloat = 0 -} From 47c23ba13b70f567170de0be3e8d5fee4af2b640 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Wed, 13 Nov 2024 13:47:41 +0100 Subject: [PATCH 259/407] 1 --- ...opup.swift => ActivePopupProperties.swift} | 4 +- .../Internal/UI/PopupCentreStackView.swift | 10 ++--- .../Internal/UI/PopupVerticalStackView.swift | 12 +++--- .../View Models/ViewModel+CentreStack.swift | 6 +-- .../View Models/ViewModel+VerticalStack.swift | 42 +++++++++---------- Sources/Internal/View Models/ViewModel.swift | 22 +++++----- 6 files changed, 48 insertions(+), 48 deletions(-) rename Sources/Internal/Models/{ActivePopup.swift => ActivePopupProperties.swift} (86%) diff --git a/Sources/Internal/Models/ActivePopup.swift b/Sources/Internal/Models/ActivePopupProperties.swift similarity index 86% rename from Sources/Internal/Models/ActivePopup.swift rename to Sources/Internal/Models/ActivePopupProperties.swift index 9ee05816dc..3f894bb8c6 100644 --- a/Sources/Internal/Models/ActivePopup.swift +++ b/Sources/Internal/Models/ActivePopupProperties.swift @@ -1,5 +1,5 @@ // -// ActivePopup.swift of MijickPopups +// ActivePopupProperties.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com @@ -11,7 +11,7 @@ import SwiftUI -struct ActivePopup: Sendable { +struct ActivePopupProperties: Sendable { var height: CGFloat? = nil var innerPadding: EdgeInsets = .init() var outerPadding: EdgeInsets = .init() diff --git a/Sources/Internal/UI/PopupCentreStackView.swift b/Sources/Internal/UI/PopupCentreStackView.swift index 1dab7d9b81..4a3b9a3fc7 100644 --- a/Sources/Internal/UI/PopupCentreStackView.swift +++ b/Sources/Internal/UI/PopupCentreStackView.swift @@ -30,14 +30,14 @@ private extension PopupCentreStackView { private extension PopupCentreStackView { func createPopup(_ popup: AnyPopup) -> some View { popup.body - .fixedSize(horizontal: false, vertical: viewModel.activePopup.verticalFixedSize) + .fixedSize(horizontal: false, vertical: viewModel.activePopupProperties.verticalFixedSize) .onHeightChange { await viewModel.updatePopupHeight($0, popup) } - .frame(height: viewModel.activePopup.height) - .frame(maxWidth: .infinity, maxHeight: viewModel.activePopup.height) - .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.activePopup.corners) + .frame(height: viewModel.activePopupProperties.height) + .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupProperties.height) + .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: .clear, corners: viewModel.activePopupProperties.corners) .opacity(viewModel.calculateOpacity(for: popup)) .focusSection_tvOS() - .padding(viewModel.activePopup.outerPadding) + .padding(viewModel.activePopupProperties.outerPadding) .compositingGroup() } } diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index fbb477d073..03b0349e3a 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -29,16 +29,16 @@ private extension PopupVerticalStackView { private extension PopupVerticalStackView { func createPopup(_ popup: AnyPopup) -> some View { popup.body - .padding(viewModel.activePopup.innerPadding) - .fixedSize(horizontal: false, vertical: viewModel.activePopup.verticalFixedSize) + .padding(viewModel.activePopupProperties.innerPadding) + .fixedSize(horizontal: false, vertical: viewModel.activePopupProperties.verticalFixedSize) .onHeightChange { await viewModel.updatePopupHeight($0, popup) } - .frame(height: viewModel.activePopup.height, alignment: (!viewModel.alignment).toAlignment()) - .frame(maxWidth: .infinity, maxHeight: viewModel.activePopup.height, alignment: (!viewModel.alignment).toAlignment()) - .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: viewModel.activePopup.corners) + .frame(height: viewModel.activePopupProperties.height, alignment: (!viewModel.alignment).toAlignment()) + .frame(maxWidth: .infinity, maxHeight: viewModel.activePopupProperties.height, alignment: (!viewModel.alignment).toAlignment()) + .background(backgroundColor: getBackgroundColor(for: popup), overlayColor: getStackOverlayColor(for: popup), corners: viewModel.activePopupProperties.corners) .offset(y: viewModel.calculateOffsetY(for: popup)) .scaleEffect(x: viewModel.calculateScaleX(for: popup)) .focusSection_tvOS() - .padding(viewModel.activePopup.outerPadding) + .padding(viewModel.activePopupProperties.outerPadding) .transition(transition) .zIndex(viewModel.calculateZIndex()) .compositingGroup() diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 459e5a22f4..3a36190a2b 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -14,7 +14,7 @@ import SwiftUI extension VM { class CentreStack: ViewModel { required init() {} var alignment: PopupAlignment = .centre var popups: [AnyPopup] = [] - var activePopup: ActivePopup = .init() + var activePopupProperties: ActivePopupProperties = .init() var screen: Screen = .init() var updatePopupAction: ((AnyPopup) async -> ())! var closePopupAction: ((AnyPopup) async -> ())! @@ -44,7 +44,7 @@ extension VM.CentreStack { } private extension VM.CentreStack { func calculateVerticalPopupPadding(for edge: PopupAlignment) -> CGFloat { - guard let activePopupHeight = activePopup.height, screen.isKeyboardActive && edge == .bottom else { return 0 } + guard let activePopupHeight = activePopupProperties.height, screen.isKeyboardActive && edge == .bottom else { return 0 } let remainingHeight = screen.height - activePopupHeight let paddingCandidate = (remainingHeight / 2 - screen.safeArea.bottom) * 2 @@ -74,7 +74,7 @@ extension VM.CentreStack { // MARK: Vertical Fixed Size extension VM.CentreStack { func calculateActivePopupVerticalFixedSize() async -> Bool { - activePopup.height != calculateLargeScreenHeight() + activePopupProperties.height != calculateLargeScreenHeight() } } diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index a424b47926..7568c52318 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -14,7 +14,7 @@ import SwiftUI extension VM { class VerticalStack: ViewModel { required init() {} var alignment: PopupAlignment = .centre var popups: [AnyPopup] = [] - var activePopup: ActivePopup = .init() + var activePopupProperties: ActivePopupProperties = .init() var screen: Screen = .init() var updatePopupAction: ((AnyPopup) async -> ())! var closePopupAction: ((AnyPopup) async -> ())! @@ -31,7 +31,7 @@ extension VM.VerticalStack { func calculateActivePopupHeight() async -> CGFloat? { guard let activePopupHeight = popups.last?.height, let activePopupDragHeight = popups.last?.dragHeight else { return nil } - let popupHeightFromGestureTranslation = activePopupHeight + activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() + let popupHeightFromGestureTranslation = activePopupHeight + activePopupDragHeight + activePopupProperties.gestureTranslation * getDragTranslationMultiplier() let newHeightCandidate = max(activePopupHeight, popupHeightFromGestureTranslation) return min(newHeightCandidate, screen.height) @@ -57,7 +57,7 @@ extension VM.VerticalStack { private extension VM.VerticalStack { func calculateVerticalOuterPadding(for edge: PopupAlignment, activePopupConfig: AnyPopupConfig) -> CGFloat { let largeScreenHeight = calculateLargeScreenHeight(), - activePopupHeight = activePopup.height ?? 0, + activePopupHeight = activePopupProperties.height ?? 0, priorityPopupPaddingValue = calculatePriorityOuterPaddingValue(for: edge, activePopupConfig: activePopupConfig), remainingHeight = largeScreenHeight - activePopupHeight - priorityPopupPaddingValue @@ -92,8 +92,8 @@ private extension VM.VerticalStack { if popup.config.ignoredSafeAreaEdges.contains(.top) { return 0 } return switch alignment { - case .top: calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupOuterPadding: activePopup.outerPadding.top) - case .bottom: calculateVerticalInnerPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.top) + case .top: calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupOuterPadding: activePopupProperties.outerPadding.top) + case .bottom: calculateVerticalInnerPaddingCounterEdge(popupHeight: activePopupProperties.height ?? 0, safeArea: screen.safeArea.top) case .centre: fatalError() } } @@ -101,8 +101,8 @@ private extension VM.VerticalStack { if popup.config.ignoredSafeAreaEdges.contains(.bottom) && !screen.isKeyboardActive { return 0 } return switch alignment { - case .top: calculateVerticalInnerPaddingCounterEdge(popupHeight: activePopup.height ?? 0, safeArea: screen.safeArea.bottom) - case .bottom: calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupOuterPadding: activePopup.outerPadding.bottom) + case .top: calculateVerticalInnerPaddingCounterEdge(popupHeight: activePopupProperties.height ?? 0, safeArea: screen.safeArea.bottom) + case .bottom: calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupOuterPadding: activePopupProperties.outerPadding.bottom) case .centre: fatalError() } } @@ -142,13 +142,13 @@ private extension VM.VerticalStack { case .fullscreen: 0 }} func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat) -> CGFloat { switch alignment { - case .top: activePopup.outerPadding.top != 0 ? cornerRadiusValue : 0 + case .top: activePopupProperties.outerPadding.top != 0 ? cornerRadiusValue : 0 case .bottom: cornerRadiusValue case .centre: fatalError() }} func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat) -> CGFloat { switch alignment { case .top: cornerRadiusValue - case .bottom: activePopup.outerPadding.bottom != 0 ? cornerRadiusValue : 0 + case .bottom: activePopupProperties.outerPadding.bottom != 0 ? cornerRadiusValue : 0 case .centre: fatalError() }} } @@ -157,15 +157,15 @@ private extension VM.VerticalStack { extension VM.VerticalStack { func calculateActivePopupVerticalFixedSize() async -> Bool { guard let popup = popups.last else { return true }; return switch popup.config.heightMode { case .fullscreen, .large: false - case .auto: activePopup.height != calculateLargeScreenHeight() + case .auto: activePopupProperties.height != calculateLargeScreenHeight() }} } // MARK: Translation Progress extension VM.VerticalStack { func calculateActivePopupTranslationProgress() async -> CGFloat { guard let activePopupHeight = popups.last?.height else { return 0 }; return switch alignment { - case .top: abs(min(activePopup.gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight - case .bottom: max(activePopup.gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight + case .top: abs(min(activePopupProperties.gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight + case .bottom: max(activePopupProperties.gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight case .centre: fatalError() }} } @@ -179,7 +179,7 @@ extension VM.VerticalStack { // MARK: Height extension VM.VerticalStack { func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { - guard activePopup.gestureTranslation.isZero else { return popup.height ?? 0 } + guard activePopupProperties.gestureTranslation.isZero else { return popup.height ?? 0 } let popupHeight = calculateNewPopupHeight(heightCandidate, popup.config) return popupHeight @@ -230,8 +230,8 @@ private extension VM.VerticalStack { let lastPopupDragHeight = popups.last?.dragHeight ?? 0 return switch alignment { - case .top: min(activePopup.gestureTranslation + lastPopupDragHeight, 0) - case .bottom: max(activePopup.gestureTranslation - lastPopupDragHeight, 0) + case .top: min(activePopupProperties.gestureTranslation + lastPopupDragHeight, 0) + case .bottom: max(activePopupProperties.gestureTranslation - lastPopupDragHeight, 0) case .centre: fatalError() } } @@ -254,7 +254,7 @@ extension VM.VerticalStack { guard popup != popups.last else { return 1 } let invertedIndex = popups.getInvertedIndex(of: popup), - remainingTranslationProgress = 1 - activePopup.translationProgress + remainingTranslationProgress = 1 - activePopupProperties.translationProgress let progressMultiplier = invertedIndex == 1 ? remainingTranslationProgress : max(minScaleProgressMultiplier, remainingTranslationProgress) let scaleValue = .init(invertedIndex) * stackScaleFactor * progressMultiplier @@ -275,7 +275,7 @@ extension VM.VerticalStack { guard popup != popups.last else { return 0 } let invertedIndex = popups.getInvertedIndex(of: popup), - remainingTranslationProgress = 1 - activePopup.translationProgress + remainingTranslationProgress = 1 - activePopupProperties.translationProgress let progressMultiplier = invertedIndex == 1 ? remainingTranslationProgress : max(minStackOverlayProgressMultiplier, remainingTranslationProgress) let overlayValue = min(stackOverlayFactor * .init(invertedIndex), maxStackOverlayFactor) @@ -362,7 +362,7 @@ extension VM.VerticalStack { }} } private extension VM.VerticalStack { - func dismissLastPopupIfNeeded(_ popup: AnyPopup) async { switch activePopup.translationProgress >= dragThreshold { + func dismissLastPopupIfNeeded(_ popup: AnyPopup) async { switch activePopupProperties.translationProgress >= dragThreshold { case true: await closePopupAction(popup) case false: return }} @@ -378,7 +378,7 @@ private extension VM.VerticalStack { } private extension VM.VerticalStack { func calculateCurrentPopupHeight(activePopupHeight: CGFloat, activePopupDragHeight: CGFloat) -> CGFloat { - let currentDragHeight = activePopupDragHeight + activePopup.gestureTranslation * getDragTranslationMultiplier() + let currentDragHeight = activePopupDragHeight + activePopupProperties.gestureTranslation * getDragTranslationMultiplier() let currentPopupHeight = activePopupHeight + currentDragHeight return currentPopupHeight } @@ -397,14 +397,14 @@ private extension VM.VerticalStack { guard currentPopupHeight < screen.height else { return popupTargetHeights.last ?? 0 } let initialIndex = popupTargetHeights.firstIndex { $0 >= currentPopupHeight } ?? popupTargetHeights.count - 1, - targetIndex = activePopup.gestureTranslation * getDragTranslationMultiplier() > 0 ? initialIndex : max(0, initialIndex - 1) + targetIndex = activePopupProperties.gestureTranslation * getDragTranslationMultiplier() > 0 ? initialIndex : max(0, initialIndex - 1) let previousPopupHeight = activePopupDragHeight + activePopupHeight, popupTargetHeight = popupTargetHeights[targetIndex], deltaHeight = abs(previousPopupHeight - popupTargetHeight) let progress = abs(currentPopupHeight - previousPopupHeight) / deltaHeight if progress < dragThreshold { - let index = activePopup.gestureTranslation * getDragTranslationMultiplier() > 0 ? max(0, initialIndex - 1) : initialIndex + let index = activePopupProperties.gestureTranslation * getDragTranslationMultiplier() > 0 ? max(0, initialIndex - 1) : initialIndex return popupTargetHeights[index] } return popupTargetHeights[targetIndex] diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index f5a3e33544..62b39ad1af 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -17,7 +17,7 @@ protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == Obs // MARK: Attributes var alignment: PopupAlignment { get set } var popups: [AnyPopup] { get set } - var activePopup: ActivePopup { get set } + var activePopupProperties: ActivePopupProperties { get set } var screen: Screen { get set } // MARK: Actions @@ -84,14 +84,14 @@ extension ViewModel { @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { Task { await updateActivePopupPropertiesOnGestureTranslationChange(newGestureTranslation) - withAnimation(activePopup.gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } + withAnimation(activePopupProperties.gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } }} } // MARK: Popup Height extension ViewModel { @MainActor func updatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { Task { - guard activePopup.gestureTranslation == 0 else { return } + guard activePopupProperties.gestureTranslation == 0 else { return } let newHeight = await calculatePopupHeight(heightCandidate, popup) if newHeight != popup.height { @@ -121,15 +121,15 @@ private extension ViewModel { } private extension ViewModel { func updateActivePopupProperties() async { - activePopup.height = await calculateActivePopupHeight() - activePopup.outerPadding = await calculateActivePopupOuterPadding() - activePopup.innerPadding = await calculateActivePopupInnerPadding() - activePopup.corners = await calculateActivePopupCorners() - activePopup.verticalFixedSize = await calculateActivePopupVerticalFixedSize() + activePopupProperties.height = await calculateActivePopupHeight() + activePopupProperties.outerPadding = await calculateActivePopupOuterPadding() + activePopupProperties.innerPadding = await calculateActivePopupInnerPadding() + activePopupProperties.corners = await calculateActivePopupCorners() + activePopupProperties.verticalFixedSize = await calculateActivePopupVerticalFixedSize() } func updateActivePopupPropertiesOnGestureTranslationChange(_ newGestureTranslation: CGFloat) async { - activePopup.gestureTranslation = newGestureTranslation - activePopup.translationProgress = await calculateActivePopupTranslationProgress() - activePopup.height = await calculateActivePopupHeight() + activePopupProperties.gestureTranslation = newGestureTranslation + activePopupProperties.translationProgress = await calculateActivePopupTranslationProgress() + activePopupProperties.height = await calculateActivePopupHeight() } } From cb0ffd3540aa82b12c7f49ea2965e78645bced47 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 00:15:19 +0100 Subject: [PATCH 260/407] DANGER --- Sources/Public/Present/Public+Present+Popup.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Public/Present/Public+Present+Popup.swift b/Sources/Public/Present/Public+Present+Popup.swift index 4594754d26..bf1b854bb2 100644 --- a/Sources/Public/Present/Public+Present+Popup.swift +++ b/Sources/Public/Present/Public+Present+Popup.swift @@ -32,7 +32,7 @@ public extension Popup { - 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(.init(self))) } + @MainActor func present(popupManagerID: PopupManagerID = .shared) async { PopupManager.fetchInstance(id: popupManagerID)?.stack(.insertPopup(.init(self))) } } // MARK: Configure Popup @@ -43,12 +43,12 @@ public extension Popup { - important: To dismiss a popup with a custom ID set, use methods ``PopupManager/dismissPopup(_:popupManagerID:)-1atvy`` or ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-55ubm`` - tip: Useful if you want to display several different popups of the same type. */ - func setCustomID(_ id: String) -> some Popup { AnyPopup(self).updatedID(id) } + @MainActor func setCustomID(_ id: String) async -> some Popup { AnyPopup(self).updatedID(id) } /** Supplies an observable object to a popup's hierarchy. */ - func setEnvironmentObject(_ object: T) -> some Popup { AnyPopup(self).updatedEnvironmentObject(object) } + @MainActor func setEnvironmentObject(_ object: T) async -> some Popup { AnyPopup(self).updatedEnvironmentObject(object) } /** Dismisses the popup after a specified period of time. @@ -56,5 +56,5 @@ public extension Popup { - Parameters: - seconds: Time in seconds after which the popup will be closed. */ - func dismissAfter(_ seconds: Double) -> some Popup { AnyPopup(self).updatedDismissTimer(seconds) } + @MainActor func dismissAfter(_ seconds: Double) async -> some Popup { AnyPopup(self).updatedDismissTimer(seconds) } } From ee5ad5e0e6c99ee89bb9ff057b0206699ee768d2 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 00:22:54 +0100 Subject: [PATCH 261/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 8 ++++---- Sources/Internal/Models/ID+Popup.swift | 6 +++--- Sources/Public/Present/Public+Present+Popup.swift | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index cd2d80097b..60ce5a01cf 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -31,10 +31,10 @@ struct AnyPopup: Popup { // MARK: Initialize extension AnyPopup { - init(_ popup: P) { + init(_ popup: P) async { if let popup = popup as? AnyPopup { self = popup } else { - self.id = .init(P.self) + self.id = await .init(P.self) self.config = .init(popup.configurePopup(config: .init())) self._body = .init(popup) self._onFocus = popup.onFocus @@ -47,7 +47,7 @@ extension AnyPopup { extension AnyPopup { nonisolated func updatedHeight(_ newHeight: CGFloat?) async -> AnyPopup { await updatedAsync { $0.height = newHeight }} nonisolated func updatedDragHeight(_ newDragHeight: CGFloat) async -> AnyPopup { await updatedAsync { $0.dragHeight = newDragHeight }} - func updatedID(_ customID: String) -> AnyPopup { updated { $0.id = .init(customID) }} + nonisolated func updatedID(_ customID: String) async -> AnyPopup { await updatedAsync { $0.id = await .init(customID) }} func updatedDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} func updatedEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} func startDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} @@ -94,7 +94,7 @@ extension AnyPopup: Hashable { // MARK: New Object extension AnyPopup { - static func t_createNew(id: String = UUID().uuidString, config: LocalConfig) -> AnyPopup { .init( + static func t_createNew(id: String = UUID().uuidString, config: LocalConfig) async -> AnyPopup { await .init( id: .init(id), config: .init(config), height: nil, diff --git a/Sources/Internal/Models/ID+Popup.swift b/Sources/Internal/Models/ID+Popup.swift index bb1fcfa551..f12b315609 100644 --- a/Sources/Internal/Models/ID+Popup.swift +++ b/Sources/Internal/Models/ID+Popup.swift @@ -17,14 +17,14 @@ struct PopupID { // MARK: Create extension PopupID { - init(_ id: String) { + init(_ id: String) async { let firstComponent = id, secondComponent = Self.separator, thirdComponent = String(describing: Date()) self.init(rawValue: firstComponent + secondComponent + thirdComponent) } - init(_ popupType: any Popup.Type) { - self.init(.init(describing: popupType)) + init(_ popupType: any Popup.Type) async { + await self.init(.init(describing: popupType)) } } diff --git a/Sources/Public/Present/Public+Present+Popup.swift b/Sources/Public/Present/Public+Present+Popup.swift index bf1b854bb2..605743459a 100644 --- a/Sources/Public/Present/Public+Present+Popup.swift +++ b/Sources/Public/Present/Public+Present+Popup.swift @@ -32,7 +32,7 @@ public extension Popup { - Warning: To present multiple popups of the same type, set a unique identifier using the method ``Popup/setCustomID(_:)``. */ - @MainActor func present(popupManagerID: PopupManagerID = .shared) async { PopupManager.fetchInstance(id: popupManagerID)?.stack(.insertPopup(.init(self))) } + @MainActor func present(popupManagerID: PopupManagerID = .shared) async { await PopupManager.fetchInstance(id: popupManagerID)?.stack(.insertPopup(.init(self))) } } // MARK: Configure Popup @@ -43,12 +43,12 @@ public extension Popup { - important: To dismiss a popup with a custom ID set, use methods ``PopupManager/dismissPopup(_:popupManagerID:)-1atvy`` or ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-55ubm`` - tip: Useful if you want to display several different popups of the same type. */ - @MainActor func setCustomID(_ id: String) async -> some Popup { AnyPopup(self).updatedID(id) } + @MainActor func setCustomID(_ id: String) async -> some Popup { await AnyPopup(self).updatedID(id) } /** Supplies an observable object to a popup's hierarchy. */ - @MainActor func setEnvironmentObject(_ object: T) async -> some Popup { AnyPopup(self).updatedEnvironmentObject(object) } + @MainActor func setEnvironmentObject(_ object: T) async -> some Popup { await AnyPopup(self).updatedEnvironmentObject(object) } /** Dismisses the popup after a specified period of time. @@ -56,5 +56,5 @@ public extension Popup { - Parameters: - seconds: Time in seconds after which the popup will be closed. */ - @MainActor func dismissAfter(_ seconds: Double) async -> some Popup { AnyPopup(self).updatedDismissTimer(seconds) } + @MainActor func dismissAfter(_ seconds: Double) async -> some Popup { await AnyPopup(self).updatedDismissTimer(seconds) } } From 3c73959e060a04b5d51c21cada345180a16b3fbb Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 00:28:46 +0100 Subject: [PATCH 262/407] 1 --- Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift | 8 ++++---- Sources/Public/Dismiss/Public+Dismiss+View.swift | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift b/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift index ba9b81a243..1e37e7d0ae 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift @@ -21,7 +21,7 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - static func dismissLastPopup(popupManagerID: PopupManagerID = .shared) { fetchInstance(id: popupManagerID)?.stack(.removeLastPopup) } + @MainActor static func dismissLastPopup(popupManagerID: PopupManagerID = .shared) async { fetchInstance(id: popupManagerID)?.stack(.removeLastPopup) } /** Removes all popups with the specified identifier from the stack. @@ -32,7 +32,7 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - static func dismissPopup(_ id: String, popupManagerID: PopupManagerID = .shared) { fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsWithID(id)) } + @MainActor static func dismissPopup(_ id: String, popupManagerID: PopupManagerID = .shared) async { fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsWithID(id)) } /** Removes all popups of the provided type from the stack. @@ -44,7 +44,7 @@ public extension PopupManager { - Important: If a custom ID (``Popup/setCustomID(_:)``) is set for the popup, use the ``dismissPopup(_:popupManagerID:)-1atvy`` method instead. - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - static func dismissPopup(_ type: P.Type, popupManagerID: PopupManagerID = .shared) { fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsOfType(type)) } + @MainActor static func dismissPopup(_ type: P.Type, popupManagerID: PopupManagerID = .shared) async { fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsOfType(type)) } /** Removes all popups from the stack. @@ -54,5 +54,5 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popups. */ - static func dismissAllPopups(popupManagerID: PopupManagerID = .shared) { fetchInstance(id: popupManagerID)?.stack(.removeAllPopups) } + @MainActor static func dismissAllPopups(popupManagerID: PopupManagerID = .shared) async { fetchInstance(id: popupManagerID)?.stack(.removeAllPopups) } } diff --git a/Sources/Public/Dismiss/Public+Dismiss+View.swift b/Sources/Public/Dismiss/Public+Dismiss+View.swift index c3b99e4687..f2299f1acd 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+View.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+View.swift @@ -21,7 +21,7 @@ public extension View { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - func dismissLastPopup(popupManagerID: PopupManagerID = .shared) { PopupManager.dismissLastPopup(popupManagerID: popupManagerID) } + @MainActor func dismissLastPopup(popupManagerID: PopupManagerID = .shared) async { await PopupManager.dismissLastPopup(popupManagerID: popupManagerID) } /** Removes all popups with the specified identifier from the stack. @@ -32,7 +32,7 @@ public extension View { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - func dismissPopup(_ id: String, popupManagerID: PopupManagerID = .shared) { PopupManager.dismissPopup(id, popupManagerID: popupManagerID) } + @MainActor func dismissPopup(_ id: String, popupManagerID: PopupManagerID = .shared) async { await PopupManager.dismissPopup(id, popupManagerID: popupManagerID) } /** Removes all popups of the provided type from the stack. @@ -44,7 +44,7 @@ public extension View { - Important: If a custom ID (see ``Popup/setCustomID(_:)`` method for reference) is set for the popup, use the ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-55ubm`` method instead. - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - func dismissPopup(_ type: P.Type, popupManagerID: PopupManagerID = .shared) { PopupManager.dismissPopup(type, popupManagerID: popupManagerID) } + @MainActor func dismissPopup(_ type: P.Type, popupManagerID: PopupManagerID = .shared) async { await PopupManager.dismissPopup(type, popupManagerID: popupManagerID) } /** Removes all popups from the stack. @@ -54,5 +54,5 @@ public extension View { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popups. */ - func dismissAllPopups(popupManagerID: PopupManagerID = .shared) { PopupManager.dismissAllPopups(popupManagerID: popupManagerID) } + @MainActor func dismissAllPopups(popupManagerID: PopupManagerID = .shared) async { await PopupManager.dismissAllPopups(popupManagerID: popupManagerID) } } From fe71bd48f5431152888fdbbc19b4d92a23c1dd3c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 00:46:17 +0100 Subject: [PATCH 263/407] 1 --- Sources/Internal/Managers/PopupManager.swift | 4 ++-- Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/Managers/PopupManager.swift b/Sources/Internal/Managers/PopupManager.swift index a67a28ce72..5f6c59d70e 100644 --- a/Sources/Internal/Managers/PopupManager.swift +++ b/Sources/Internal/Managers/PopupManager.swift @@ -40,10 +40,10 @@ extension PopupManager { enum StackOperation { // MARK: Perform Operation extension PopupManager { - nonisolated func stack(_ operation: StackOperation) { Task { + func stack(_ operation: StackOperation) { Task { await hideKeyboard() - let oldStack = await stack, + let oldStack = stack, newStack = await getNewStack(operation), newStackPriority = await getNewStackPriority(newStack) diff --git a/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift b/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift index 1e37e7d0ae..5ae4bf9ffc 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift @@ -21,7 +21,7 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor static func dismissLastPopup(popupManagerID: PopupManagerID = .shared) async { fetchInstance(id: popupManagerID)?.stack(.removeLastPopup) } + @MainActor static func dismissLastPopup(popupManagerID: PopupManagerID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeLastPopup) } /** Removes all popups with the specified identifier from the stack. @@ -32,7 +32,7 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor static func dismissPopup(_ id: String, popupManagerID: PopupManagerID = .shared) async { fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsWithID(id)) } + @MainActor static func dismissPopup(_ id: String, popupManagerID: PopupManagerID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsWithID(id)) } /** Removes all popups of the provided type from the stack. @@ -44,7 +44,7 @@ public extension PopupManager { - Important: If a custom ID (``Popup/setCustomID(_:)``) is set for the popup, use the ``dismissPopup(_:popupManagerID:)-1atvy`` method instead. - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor static func dismissPopup(_ type: P.Type, popupManagerID: PopupManagerID = .shared) async { fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsOfType(type)) } + @MainActor static func dismissPopup(_ type: P.Type, popupManagerID: PopupManagerID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsOfType(type)) } /** Removes all popups from the stack. @@ -54,5 +54,5 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popups. */ - @MainActor static func dismissAllPopups(popupManagerID: PopupManagerID = .shared) async { fetchInstance(id: popupManagerID)?.stack(.removeAllPopups) } + @MainActor static func dismissAllPopups(popupManagerID: PopupManagerID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopups) } } From 3e7a203274234efb71c6a0d7ed5465756264af27 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 13:18:58 +0100 Subject: [PATCH 264/407] 1 --- Sources/Internal/Managers/PopupManager.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/Managers/PopupManager.swift b/Sources/Internal/Managers/PopupManager.swift index 5f6c59d70e..d63d9edb0d 100644 --- a/Sources/Internal/Managers/PopupManager.swift +++ b/Sources/Internal/Managers/PopupManager.swift @@ -105,14 +105,14 @@ private extension PopupManager { // MARK: Fetch extension PopupManager { - static func fetchInstance(id: PopupManagerID) -> PopupManager? { + nonisolated static func fetchInstance(id: PopupManagerID) async -> PopupManager? { let managerObject = PopupManagerContainer.instances.first(where: { $0.id == id }) - logNoInstanceErrorIfNeeded(managerObject: managerObject, popupManagerID: id) + await logNoInstanceErrorIfNeeded(managerObject: managerObject, popupManagerID: id) return managerObject } } private extension PopupManager { - static func logNoInstanceErrorIfNeeded(managerObject: PopupManager?, popupManagerID: PopupManagerID) { if managerObject == nil { + nonisolated static func logNoInstanceErrorIfNeeded(managerObject: PopupManager?, popupManagerID: PopupManagerID) async { if managerObject == nil { Logger.log( level: .fault, message: "PopupManager instance (\(popupManagerID.rawValue)) must be registered before use. More details can be found in the documentation." From 9cbad156f80f6c698fe6c0c016b51adecfeb6966 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 13:29:42 +0100 Subject: [PATCH 265/407] 1 --- Sources/Internal/Extensions/View+ReadHeight.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Internal/Extensions/View+ReadHeight.swift b/Sources/Internal/Extensions/View+ReadHeight.swift index a68ff26a49..1e99ee892a 100644 --- a/Sources/Internal/Extensions/View+ReadHeight.swift +++ b/Sources/Internal/Extensions/View+ReadHeight.swift @@ -15,6 +15,7 @@ extension View { func onHeightChange(perform action: @escaping (CGFloat) async -> ()) -> some View { background( GeometryReader { proxy in Task { @MainActor in + await Task.sleep(seconds: 0.03) await action(proxy.size.height) } return Color.clear From 4d4c48f4fda3570fdd19d41854dab649fa52da3c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 13:32:35 +0100 Subject: [PATCH 266/407] 1 --- Sources/Internal/Containers/PopupManagerContainer.swift | 2 +- Sources/Internal/Managers/PopupManager.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/Containers/PopupManagerContainer.swift b/Sources/Internal/Containers/PopupManagerContainer.swift index c9c753687d..603c8142c5 100644 --- a/Sources/Internal/Containers/PopupManagerContainer.swift +++ b/Sources/Internal/Containers/PopupManagerContainer.swift @@ -11,7 +11,7 @@ import Foundation -actor PopupManagerContainer { +@MainActor class PopupManagerContainer { static private(set) var instances: [PopupManager] = [] } diff --git a/Sources/Internal/Managers/PopupManager.swift b/Sources/Internal/Managers/PopupManager.swift index d63d9edb0d..2468fe7d0e 100644 --- a/Sources/Internal/Managers/PopupManager.swift +++ b/Sources/Internal/Managers/PopupManager.swift @@ -106,7 +106,7 @@ private extension PopupManager { // MARK: Fetch extension PopupManager { nonisolated static func fetchInstance(id: PopupManagerID) async -> PopupManager? { - let managerObject = PopupManagerContainer.instances.first(where: { $0.id == id }) + let managerObject = await PopupManagerContainer.instances.first(where: { $0.id == id }) await logNoInstanceErrorIfNeeded(managerObject: managerObject, popupManagerID: id) return managerObject } From b62f6f969eaa79e7a50b38224e5fc876df9cc11a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 14:07:56 +0100 Subject: [PATCH 267/407] 1 --- Sources/Public/Popup/Public+Popup+Main.swift | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Sources/Public/Popup/Public+Popup+Main.swift b/Sources/Public/Popup/Public+Popup+Main.swift index d69ccb5215..ca37393d60 100644 --- a/Sources/Public/Popup/Public+Popup+Main.swift +++ b/Sources/Public/Popup/Public+Popup+Main.swift @@ -108,9 +108,7 @@ public extension Popup { - ``Popup/onFocus()-6krqs`` - ``Popup/onDismiss()-3bufs`` - # Usage Examples - - ## TopPopup + # Usage Example ```swift struct TopPopupExample: TopPopup { func onFocus() { print("Popup is now active") } @@ -137,9 +135,7 @@ public protocol TopPopup: Popup { associatedtype Config = TopPopupConfig } - ``Popup/onFocus()-loq5`` - ``Popup/onDismiss()-3bufs`` - # Usage Examples - - ## CentrePopup + # Usage Example ```swift struct CentrePopupExample: CentrePopup { func onFocus() { print("Popup is now active") } @@ -165,9 +161,7 @@ public protocol CentrePopup: Popup { associatedtype Config = CentrePopupConfig } - ``Popup/onFocus()-loq5`` - ``Popup/onDismiss()-254h8`` - # Usage Examples - - ## BottomPopup + # Usage Example ```swift struct BottomPopupExample: BottomPopup { func onFocus() { print("Popup is now active") } From ea5328505a801989de1d4bf1f419f1ec5df0f889 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 14:09:16 +0100 Subject: [PATCH 268/407] 1 --- Sources/Public/Popup/Public+Popup+Main.swift | 52 -------------------- 1 file changed, 52 deletions(-) diff --git a/Sources/Public/Popup/Public+Popup+Main.swift b/Sources/Public/Popup/Public+Popup+Main.swift index ca37393d60..09ad5241b5 100644 --- a/Sources/Public/Popup/Public+Popup+Main.swift +++ b/Sources/Public/Popup/Public+Popup+Main.swift @@ -17,58 +17,6 @@ import SwiftUI - ``configurePopup(config:)-3ze4`` - ``onFocus()-6krqs`` - ``onDismiss()-254h8`` - - # 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) - - ## 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) - - ## 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 Popup: View { associatedtype Config: LocalConfig From 1e4b2f94ce141cc8bc2c1c97a4d69b0dd105ed45 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 14:28:46 +0100 Subject: [PATCH 269/407] 1 --- Sources/Internal/Models/ID+Popup.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Internal/Models/ID+Popup.swift b/Sources/Internal/Models/ID+Popup.swift index f12b315609..b164ee3f63 100644 --- a/Sources/Internal/Models/ID+Popup.swift +++ b/Sources/Internal/Models/ID+Popup.swift @@ -11,7 +11,7 @@ import Foundation -struct PopupID { +struct PopupID: Sendable { let rawValue: String } From 852cbc97c84da1114b41f11140866be7444d0b63 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 14:30:09 +0100 Subject: [PATCH 270/407] 1 --- Sources/Internal/Models/Screen.swift | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Sources/Internal/Models/Screen.swift b/Sources/Internal/Models/Screen.swift index 453d1d535a..4ecf8b55f4 100644 --- a/Sources/Internal/Models/Screen.swift +++ b/Sources/Internal/Models/Screen.swift @@ -12,14 +12,7 @@ import SwiftUI struct Screen: Sendable { - let height: CGFloat - let safeArea: EdgeInsets - let isKeyboardActive: Bool - - - init(height: CGFloat = .zero, safeArea: EdgeInsets = .init(), isKeyboardActive: Bool = false) { - self.height = height - self.safeArea = safeArea - self.isKeyboardActive = isKeyboardActive - } + var height: CGFloat = .zero + var safeArea: EdgeInsets = .init() + var isKeyboardActive: Bool = false } From 27f5d31c83fae3f4c318edb4ae6466c4eb81cc1d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 14:36:39 +0100 Subject: [PATCH 271/407] 1 --- .../Internal/Extensions/EdgeInsets++.swift | 2 +- Sources/Internal/Models/AnyPopupConfig.swift | 2 +- Sources/Internal/Models/StackPriority.swift | 4 ++-- Sources/Internal/UI/PopupView.swift | 2 +- .../Internal/Utilities/PopupAlignment.swift | 10 +++++----- .../View Models/ViewModel+CentreStack.swift | 2 +- .../View Models/ViewModel+VerticalStack.swift | 20 +++++++++---------- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Sources/Internal/Extensions/EdgeInsets++.swift b/Sources/Internal/Extensions/EdgeInsets++.swift index 436d763bed..521eaa6649 100644 --- a/Sources/Internal/Extensions/EdgeInsets++.swift +++ b/Sources/Internal/Extensions/EdgeInsets++.swift @@ -14,7 +14,7 @@ import SwiftUI extension EdgeInsets { subscript(_ edge: PopupAlignment) -> CGFloat { switch edge { case .top: top - case .centre: 0 + case .center: 0 case .bottom: bottom }} } diff --git a/Sources/Internal/Models/AnyPopupConfig.swift b/Sources/Internal/Models/AnyPopupConfig.swift index a3a320d54c..01f335c9f0 100644 --- a/Sources/Internal/Models/AnyPopupConfig.swift +++ b/Sources/Internal/Models/AnyPopupConfig.swift @@ -13,7 +13,7 @@ import SwiftUI struct AnyPopupConfig: LocalConfig, Sendable { init() {} // MARK: Content - var alignment: PopupAlignment = .centre + var alignment: PopupAlignment = .center var popupPadding: EdgeInsets = .init() var cornerRadius: CGFloat = 0 var ignoredSafeAreaEdges: Edge.Set = [] diff --git a/Sources/Internal/Models/StackPriority.swift b/Sources/Internal/Models/StackPriority.swift index 6296030d98..68e67ac80f 100644 --- a/Sources/Internal/Models/StackPriority.swift +++ b/Sources/Internal/Models/StackPriority.swift @@ -13,7 +13,7 @@ import Foundation struct StackPriority: Equatable, Sendable { var top: CGFloat { values[0] } - var centre: CGFloat { values[1] } + var center: CGFloat { values[1] } var bottom: CGFloat { values[2] } var overlay: CGFloat { 1 } @@ -24,7 +24,7 @@ struct StackPriority: Equatable, Sendable { extension StackPriority { func reshuffled(_ newPopups: [AnyPopup]) -> StackPriority { switch newPopups.last?.config.alignment { case .top: reshuffled(0) - case .centre: reshuffled(1) + case .center: reshuffled(1) case .bottom: reshuffled(2) default: self }} diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index a21064746c..99c1e6fd65 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -67,7 +67,7 @@ private extension PopupView { PopupVerticalStackView(viewModel: topStackViewModel).zIndex(popupManager.stackPriority.top) } func createCentrePopupStackView() -> some View { - PopupCentreStackView(viewModel: centreStackViewModel).zIndex(popupManager.stackPriority.centre) + PopupCentreStackView(viewModel: centreStackViewModel).zIndex(popupManager.stackPriority.center) } func createBottomPopupStackView() -> some View { PopupVerticalStackView(viewModel: bottomStackViewModel).zIndex(popupManager.stackPriority.bottom) diff --git a/Sources/Internal/Utilities/PopupAlignment.swift b/Sources/Internal/Utilities/PopupAlignment.swift index cb389a8714..561dcf6142 100644 --- a/Sources/Internal/Utilities/PopupAlignment.swift +++ b/Sources/Internal/Utilities/PopupAlignment.swift @@ -13,12 +13,12 @@ import SwiftUI enum PopupAlignment { case top - case centre + case center case bottom init(_ config: LocalConfig.Type) { switch config.self { case is TopPopupConfig.Type: self = .top - case is CentrePopupConfig.Type: self = .centre + case is CentrePopupConfig.Type: self = .center case is BottomPopupConfig.Type: self = .bottom default: fatalError() }} @@ -28,7 +28,7 @@ enum PopupAlignment { extension PopupAlignment { static prefix func !(lhs: Self) -> Self { switch lhs { case .top: .bottom - case .centre: .centre + case .center: .center case .bottom: .top }} } @@ -37,12 +37,12 @@ extension PopupAlignment { extension PopupAlignment { func toEdge() -> Edge { switch self { case .top: .top - case .centre: .bottom + case .center: .bottom case .bottom: .bottom }} func toAlignment() -> Alignment { switch self { case .top: .top - case .centre: .center + case .center: .center case .bottom: .bottom }} } diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 3a36190a2b..327c86cb56 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -12,7 +12,7 @@ import SwiftUI extension VM { class CentreStack: ViewModel { required init() {} - var alignment: PopupAlignment = .centre + var alignment: PopupAlignment = .center var popups: [AnyPopup] = [] var activePopupProperties: ActivePopupProperties = .init() var screen: Screen = .init() diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 7568c52318..9826fb4ec2 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -12,7 +12,7 @@ import SwiftUI extension VM { class VerticalStack: ViewModel { required init() {} - var alignment: PopupAlignment = .centre + var alignment: PopupAlignment = .center var popups: [AnyPopup] = [] var activePopupProperties: ActivePopupProperties = .init() var screen: Screen = .init() @@ -41,7 +41,7 @@ private extension VM.VerticalStack { func getDragTranslationMultiplier() -> CGFloat { switch alignment { case .top: 1 case .bottom: -1 - case .centre: fatalError() + case .center: fatalError() }} } @@ -94,7 +94,7 @@ private extension VM.VerticalStack { return switch alignment { case .top: calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: screen.safeArea.top, popupOuterPadding: activePopupProperties.outerPadding.top) case .bottom: calculateVerticalInnerPaddingCounterEdge(popupHeight: activePopupProperties.height ?? 0, safeArea: screen.safeArea.top) - case .centre: fatalError() + case .center: fatalError() } } func calculateBottomInnerPadding(popup: AnyPopup) -> CGFloat { @@ -103,7 +103,7 @@ private extension VM.VerticalStack { return switch alignment { case .top: calculateVerticalInnerPaddingCounterEdge(popupHeight: activePopupProperties.height ?? 0, safeArea: screen.safeArea.bottom) case .bottom: calculateVerticalInnerPaddingAdhereEdge(safeAreaHeight: screen.safeArea.bottom, popupOuterPadding: activePopupProperties.outerPadding.bottom) - case .centre: fatalError() + case .center: fatalError() } } func calculateLeadingInnerPadding(popup: AnyPopup) -> CGFloat { switch popup.config.ignoredSafeAreaEdges.contains(.leading) { @@ -144,12 +144,12 @@ private extension VM.VerticalStack { func calculateTopCornerRadius(_ cornerRadiusValue: CGFloat) -> CGFloat { switch alignment { case .top: activePopupProperties.outerPadding.top != 0 ? cornerRadiusValue : 0 case .bottom: cornerRadiusValue - case .centre: fatalError() + case .center: fatalError() }} func calculateBottomCornerRadius(_ cornerRadiusValue: CGFloat) -> CGFloat { switch alignment { case .top: cornerRadiusValue case .bottom: activePopupProperties.outerPadding.bottom != 0 ? cornerRadiusValue : 0 - case .centre: fatalError() + case .center: fatalError() }} } @@ -166,7 +166,7 @@ extension VM.VerticalStack { func calculateActivePopupTranslationProgress() async -> CGFloat { guard let activePopupHeight = popups.last?.height else { return 0 }; return switch alignment { case .top: abs(min(activePopupProperties.gestureTranslation + (popups.last?.dragHeight ?? 0), 0)) / activePopupHeight case .bottom: max(activePopupProperties.gestureTranslation - (popups.last?.dragHeight ?? 0), 0) / activePopupHeight - case .centre: fatalError() + case .center: fatalError() }} } @@ -232,7 +232,7 @@ private extension VM.VerticalStack { return switch alignment { case .top: min(activePopupProperties.gestureTranslation + lastPopupDragHeight, 0) case .bottom: max(activePopupProperties.gestureTranslation - lastPopupDragHeight, 0) - case .centre: fatalError() + case .center: fatalError() } } func calculateOffsetForStackedPopup(_ popup: AnyPopup) -> CGFloat { @@ -241,7 +241,7 @@ private extension VM.VerticalStack { let alignmentMultiplier = switch alignment { case .top: 1.0 case .bottom: -1.0 - case .centre: fatalError() + case .center: fatalError() } return offsetValue * alignmentMultiplier @@ -345,7 +345,7 @@ private extension VM.VerticalStack { func calculateDragExtremeValue(_ value1: CGFloat, _ value2: CGFloat) -> CGFloat { switch alignment { case .top: min(value1, value2) case .bottom: max(value1, value2) - case .centre: fatalError() + case .center: fatalError() }} } From dcfefe92e7d14043d1c7f9fcb126face9bd49ea4 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 14:38:57 +0100 Subject: [PATCH 272/407] 1 --- Sources/Internal/Models/AnyPopupConfig.swift | 2 +- Sources/Internal/Utilities/PopupAlignment.swift | 3 +++ Sources/Public/Setup/Public+Setup+SceneDelegate.swift | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/Models/AnyPopupConfig.swift b/Sources/Internal/Models/AnyPopupConfig.swift index 01f335c9f0..04265deda7 100644 --- a/Sources/Internal/Models/AnyPopupConfig.swift +++ b/Sources/Internal/Models/AnyPopupConfig.swift @@ -27,7 +27,7 @@ struct AnyPopupConfig: LocalConfig, Sendable { init() {} var isDragGestureEnabled: Bool = false } -// MARK: Initialization +// MARK: Initialize extension AnyPopupConfig { init(_ config: Config) { self.alignment = .init(Config.self) diff --git a/Sources/Internal/Utilities/PopupAlignment.swift b/Sources/Internal/Utilities/PopupAlignment.swift index 561dcf6142..e00e65e89a 100644 --- a/Sources/Internal/Utilities/PopupAlignment.swift +++ b/Sources/Internal/Utilities/PopupAlignment.swift @@ -15,7 +15,10 @@ enum PopupAlignment { case top case center case bottom +} +// MARK: Initialize +extension PopupAlignment { init(_ config: LocalConfig.Type) { switch config.self { case is TopPopupConfig.Type: self = .top case is CentrePopupConfig.Type: self = .center diff --git a/Sources/Public/Setup/Public+Setup+SceneDelegate.swift b/Sources/Public/Setup/Public+Setup+SceneDelegate.swift index 8ab5a7db80..5879aaa764 100644 --- a/Sources/Public/Setup/Public+Setup+SceneDelegate.swift +++ b/Sources/Public/Setup/Public+Setup+SceneDelegate.swift @@ -15,7 +15,7 @@ import SwiftUI /** Registers the framework to work in your application. Works on iOS only. - - tip: Recommended initialisation way when using the framework with standard Apple sheets. + - tip: Recommended initialization way when using the framework with standard Apple sheets. ## Usage Example ```swift From 45db5beaa1b47c21bb2bad30bb66290065107824 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 15:14:06 +0100 Subject: [PATCH 273/407] 1 --- .../Local/LocalConfig+Centre.swift | 18 +++++++++--------- .../Containers/GlobalConfigContainer.swift | 2 +- .../Setup/Public+Setup+ConfigContainer.swift | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift index e30b85e00d..cfbe34a0a7 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift @@ -13,17 +13,17 @@ import SwiftUI public class LocalConfigCentre: LocalConfig { required public init() {} // MARK: Active Variables - public var popupPadding: EdgeInsets = GlobalConfigContainer.centre.popupPadding - public var cornerRadius: CGFloat = GlobalConfigContainer.centre.cornerRadius - public var backgroundColor: Color = GlobalConfigContainer.centre.backgroundColor - public var overlayColor: Color = GlobalConfigContainer.centre.overlayColor - public var isTapOutsideToDismissEnabled: Bool = GlobalConfigContainer.centre.isTapOutsideToDismissEnabled + public var popupPadding: EdgeInsets = GlobalConfigContainer.center.popupPadding + public var cornerRadius: CGFloat = GlobalConfigContainer.center.cornerRadius + public var backgroundColor: Color = GlobalConfigContainer.center.backgroundColor + public var overlayColor: Color = GlobalConfigContainer.center.overlayColor + public var isTapOutsideToDismissEnabled: Bool = GlobalConfigContainer.center.isTapOutsideToDismissEnabled // MARK: Inactive Variables - public var ignoredSafeAreaEdges: Edge.Set = GlobalConfigContainer.centre.ignoredSafeAreaEdges - public var heightMode: HeightMode = GlobalConfigContainer.centre.heightMode - public var dragDetents: [DragDetent] = GlobalConfigContainer.centre.dragDetents - public var isDragGestureEnabled: Bool = GlobalConfigContainer.centre.isDragGestureEnabled + public var ignoredSafeAreaEdges: Edge.Set = GlobalConfigContainer.center.ignoredSafeAreaEdges + public var heightMode: HeightMode = GlobalConfigContainer.center.heightMode + public var dragDetents: [DragDetent] = GlobalConfigContainer.center.dragDetents + public var isDragGestureEnabled: Bool = GlobalConfigContainer.center.isDragGestureEnabled } // MARK: Typealias diff --git a/Sources/Internal/Containers/GlobalConfigContainer.swift b/Sources/Internal/Containers/GlobalConfigContainer.swift index eaddfcf374..859fcc87b6 100644 --- a/Sources/Internal/Containers/GlobalConfigContainer.swift +++ b/Sources/Internal/Containers/GlobalConfigContainer.swift @@ -10,6 +10,6 @@ public actor GlobalConfigContainer { - nonisolated(unsafe) static var centre: GlobalConfigCentre = .init() + nonisolated(unsafe) static var center: GlobalConfigCentre = .init() nonisolated(unsafe) static var vertical: GlobalConfigVertical = .init() } diff --git a/Sources/Public/Setup/Public+Setup+ConfigContainer.swift b/Sources/Public/Setup/Public+Setup+ConfigContainer.swift index 0c2ebab30d..a3eb14a5cb 100644 --- a/Sources/Public/Setup/Public+Setup+ConfigContainer.swift +++ b/Sources/Public/Setup/Public+Setup+ConfigContainer.swift @@ -15,7 +15,7 @@ public extension GlobalConfigContainer { Use the ``Popup/configurePopup(config:)-98ha0`` method to change the configuration for a specific popup. See the list of available methods in ``GlobalConfig``. */ - nonisolated func centre(_ builder: (GlobalConfigCentre) -> GlobalConfigCentre) -> Self { Self.centre = builder(.init()); return self } + nonisolated func centre(_ builder: (GlobalConfigCentre) -> GlobalConfigCentre) -> Self { Self.center = builder(.init()); return self } /** Default configuration for all top and bottom popups. From 29457cccca93fc973c7d03b3ffef3bbcb37da00a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 15:19:19 +0100 Subject: [PATCH 274/407] 1 --- Sources/Internal/Containers/GlobalConfigContainer.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/Containers/GlobalConfigContainer.swift b/Sources/Internal/Containers/GlobalConfigContainer.swift index 859fcc87b6..66674c065e 100644 --- a/Sources/Internal/Containers/GlobalConfigContainer.swift +++ b/Sources/Internal/Containers/GlobalConfigContainer.swift @@ -10,6 +10,6 @@ public actor GlobalConfigContainer { - nonisolated(unsafe) static var center: GlobalConfigCentre = .init() - nonisolated(unsafe) static var vertical: GlobalConfigVertical = .init() + static var center: GlobalConfigCentre = .init() + static var vertical: GlobalConfigVertical = .init() } From f6e9587a6f20d5c757cb08b047eb63843216a5fa Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 16:16:33 +0100 Subject: [PATCH 275/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 60ce5a01cf..13038c76a1 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -48,6 +48,16 @@ extension AnyPopup { nonisolated func updatedHeight(_ newHeight: CGFloat?) async -> AnyPopup { await updatedAsync { $0.height = newHeight }} nonisolated func updatedDragHeight(_ newDragHeight: CGFloat) async -> AnyPopup { await updatedAsync { $0.dragHeight = newDragHeight }} nonisolated func updatedID(_ customID: String) async -> AnyPopup { await updatedAsync { $0.id = await .init(customID) }} +} +private extension AnyPopup { + nonisolated func updatedAsync(_ customBuilder: (inout AnyPopup) async -> ()) async -> AnyPopup { + var popup = self + await customBuilder(&popup) + return popup + } +} + +extension AnyPopup { func updatedDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} func updatedEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} func startDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} @@ -58,11 +68,6 @@ private extension AnyPopup { customBuilder(&popup) return popup } - nonisolated func updatedAsync(_ customBuilder: (inout AnyPopup) async -> ()) async -> AnyPopup { - var popup = self - await customBuilder(&popup) - return popup - } } From 471659c0f65784d8b897b706f1033649c30a6995 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 16:26:52 +0100 Subject: [PATCH 276/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 13038c76a1..842225d739 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -56,7 +56,6 @@ private extension AnyPopup { return popup } } - extension AnyPopup { func updatedDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} func updatedEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} @@ -100,14 +99,7 @@ extension AnyPopup: Hashable { // MARK: New Object extension AnyPopup { static func t_createNew(id: String = UUID().uuidString, config: LocalConfig) async -> AnyPopup { await .init( - id: .init(id), - config: .init(config), - height: nil, - dragHeight: 0, - _dismissTimer: nil, - _body: .init(EmptyView()), - _onFocus: {}, - _onDismiss: {} + id: .init(id), config: .init(config), height: nil, dragHeight: 0, _dismissTimer: nil, _body: .init(EmptyView()), _onFocus: {}, _onDismiss: {} )} } #endif From 7f17dd74f65b95408da5078a27bf58dd58c00d2a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 17:07:42 +0100 Subject: [PATCH 277/407] 1 --- Sources/Internal/{Managers => Containers}/PopupManager.swift | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Sources/Internal/{Managers => Containers}/PopupManager.swift (100%) diff --git a/Sources/Internal/Managers/PopupManager.swift b/Sources/Internal/Containers/PopupManager.swift similarity index 100% rename from Sources/Internal/Managers/PopupManager.swift rename to Sources/Internal/Containers/PopupManager.swift From cb6322d8d59ebc740c1e421a8c21e2d7d29fa0a0 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 17:21:40 +0100 Subject: [PATCH 278/407] 1 --- .../{PopupManager.swift => PopupStack.swift} | 48 +++++++-------- ...tainer.swift => PopupStackContainer.swift} | 12 ++-- Sources/Internal/Models/AnyPopup.swift | 2 +- Sources/Internal/UI/PopupView.swift | 10 ++-- ....swift => Public+Dismiss+PopupStack.swift} | 12 ++-- .../Public/Dismiss/Public+Dismiss+View.swift | 8 +-- .../Public/Present/Public+Present+Popup.swift | 12 ++-- ...D.swift => Popup+Setup+PopupStackID.swift} | 12 ++-- Sources/Public/Setup/Public+Setup+View.swift | 4 +- Tests/Tests+PopupManager.swift | 60 +++++++++---------- 10 files changed, 90 insertions(+), 90 deletions(-) rename Sources/Internal/Containers/{PopupManager.swift => PopupStack.swift} (72%) rename Sources/Internal/Containers/{PopupManagerContainer.swift => PopupStackContainer.swift} (66%) rename Sources/Public/Dismiss/{Public+Dismiss+PopupManager.swift => Public+Dismiss+PopupStack.swift} (80%) rename Sources/Public/Setup/{Popup+Setup+PopupManagerID.swift => Popup+Setup+PopupStackID.swift} (77%) diff --git a/Sources/Internal/Containers/PopupManager.swift b/Sources/Internal/Containers/PopupStack.swift similarity index 72% rename from Sources/Internal/Containers/PopupManager.swift rename to Sources/Internal/Containers/PopupStack.swift index 2468fe7d0e..af64e18030 100644 --- a/Sources/Internal/Containers/PopupManager.swift +++ b/Sources/Internal/Containers/PopupStack.swift @@ -1,5 +1,5 @@ // -// PopupManager.swift of MijickPopups +// PopupStack.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com @@ -11,16 +11,16 @@ import SwiftUI -@MainActor public class PopupManager: ObservableObject { - let id: PopupManagerID +@MainActor public class PopupStack: ObservableObject { + let id: PopupStackID @Published private(set) var stack: [AnyPopup] = [] - @Published private(set) var stackPriority: StackPriority = .init() + @Published private(set) var priority: StackPriority = .init() - private init(id: PopupManagerID) { self.id = id } + private init(id: PopupStackID) { self.id = id } } // MARK: Update -extension PopupManager { +extension PopupStack { func updateStack(_ popup: AnyPopup) { if let index = stack.firstIndex(of: popup) { stack[index] = popup }} @@ -33,25 +33,25 @@ extension PopupManager { // MARK: Available Operations -extension PopupManager { enum StackOperation { +extension PopupStack { enum StackOperation { case insertPopup(AnyPopup) case removeLastPopup, removePopupInstance(AnyPopup), removeAllPopupsOfType(any Popup.Type), removeAllPopupsWithID(String), removeAllPopups }} // MARK: Perform Operation -extension PopupManager { +extension PopupStack { func stack(_ operation: StackOperation) { Task { await hideKeyboard() let oldStack = stack, newStack = await getNewStack(operation), - newStackPriority = await getNewStackPriority(newStack) + newPriority = await getNewStackPriority(newStack) await updateStack(newStack) - await updateStackPriority(newStackPriority, oldStack.count) + await updatePriority(newPriority, oldStack.count) }} } -private extension PopupManager { +private extension PopupStack { nonisolated func hideKeyboard() async { await AnyView.hideKeyboard() } @@ -64,19 +64,19 @@ private extension PopupManager { case .removeAllPopups: await removedAllPopups() }} nonisolated func getNewStackPriority(_ newStack: [AnyPopup]) async -> StackPriority { - await stackPriority.reshuffled(newStack) + await priority.reshuffled(newStack) } nonisolated func updateStack(_ newStack: [AnyPopup]) async { Task { @MainActor in stack = newStack } } - nonisolated func updateStackPriority(_ newStackPriority: StackPriority, _ oldStackCount: Int) async { + nonisolated func updatePriority(_ newPriority: StackPriority, _ oldStackCount: Int) async { let delayDuration = await oldStackCount > stack.count ? Animation.duration : 0 await Task.sleep(seconds: delayDuration) - Task { @MainActor in stackPriority = newStackPriority } + Task { @MainActor in priority = newPriority } } } -private extension PopupManager { +private extension PopupStack { nonisolated func insertedPopup(_ erasedPopup: AnyPopup) async -> [AnyPopup] { await stack.modifiedAsync(if: await !stack.contains { $0.id.isSameType(as: erasedPopup.id) }) { $0.append(await erasedPopup.startDismissTimerIfNeeded(self)) }} @@ -104,15 +104,15 @@ private extension PopupManager { // MARK: Fetch -extension PopupManager { - nonisolated static func fetchInstance(id: PopupManagerID) async -> PopupManager? { - let managerObject = await PopupManagerContainer.instances.first(where: { $0.id == id }) +extension PopupStack { + nonisolated static func fetchInstance(id: PopupStackID) async -> PopupStack? { + let managerObject = await PopupStackContainer.instances.first(where: { $0.id == id }) await logNoInstanceErrorIfNeeded(managerObject: managerObject, popupManagerID: id) return managerObject } } -private extension PopupManager { - nonisolated static func logNoInstanceErrorIfNeeded(managerObject: PopupManager?, popupManagerID: PopupManagerID) async { if managerObject == nil { +private extension PopupStack { + nonisolated static func logNoInstanceErrorIfNeeded(managerObject: PopupStack?, popupManagerID: PopupStackID) async { if managerObject == nil { Logger.log( level: .fault, message: "PopupManager instance (\(popupManagerID.rawValue)) must be registered before use. More details can be found in the documentation." @@ -121,10 +121,10 @@ private extension PopupManager { } // MARK: Register -extension PopupManager { - static func registerInstance(id: PopupManagerID) -> PopupManager { - let instanceToRegister = PopupManager(id: id) - let registeredInstance = PopupManagerContainer.register(popupManager: instanceToRegister) +extension PopupStack { + static func registerInstance(id: PopupStackID) -> PopupStack { + let instanceToRegister = PopupStack(id: id) + let registeredInstance = PopupStackContainer.register(popupManager: instanceToRegister) return registeredInstance } } diff --git a/Sources/Internal/Containers/PopupManagerContainer.swift b/Sources/Internal/Containers/PopupStackContainer.swift similarity index 66% rename from Sources/Internal/Containers/PopupManagerContainer.swift rename to Sources/Internal/Containers/PopupStackContainer.swift index 603c8142c5..b94c3f5ae3 100644 --- a/Sources/Internal/Containers/PopupManagerContainer.swift +++ b/Sources/Internal/Containers/PopupStackContainer.swift @@ -1,5 +1,5 @@ // -// PopupManagerContainer.swift of MijickPopups +// PopupStackContainer.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com @@ -11,13 +11,13 @@ import Foundation -@MainActor class PopupManagerContainer { - static private(set) var instances: [PopupManager] = [] +@MainActor class PopupStackContainer { + static private(set) var instances: [PopupStack] = [] } // MARK: Register -extension PopupManagerContainer { - static func register(popupManager: PopupManager) -> PopupManager { +extension PopupStackContainer { + static func register(popupManager: PopupStack) -> PopupStack { if let alreadyRegisteredInstance = instances.first(where: { $0.id == popupManager.id }) { return alreadyRegisteredInstance } instances.append(popupManager) @@ -26,6 +26,6 @@ extension PopupManagerContainer { } // MARK: Clean -extension PopupManagerContainer { +extension PopupStackContainer { static func clean() { instances = [] } } diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 842225d739..1afa1d20af 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -59,7 +59,7 @@ private extension AnyPopup { extension AnyPopup { func updatedDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} func updatedEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} - func startDismissTimerIfNeeded(_ popupManager: PopupManager) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} + func startDismissTimerIfNeeded(_ popupManager: PopupStack) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} } private extension AnyPopup { func updated(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 99c1e6fd65..4b79d57e41 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -16,7 +16,7 @@ struct PopupView: View { let rootView: any View #endif - @ObservedObject var popupManager: PopupManager + @ObservedObject var popupManager: PopupStack private let topStackViewModel: VM.VerticalStack = .init(TopPopupConfig.self) private let centreStackViewModel: VM.CentreStack = .init(CentrePopupConfig.self) private let bottomStackViewModel: VM.VerticalStack = .init(BottomPopupConfig.self) @@ -59,18 +59,18 @@ private extension PopupView { private extension PopupView { func createOverlayView() -> some View { getOverlayColor() - .zIndex(popupManager.stackPriority.overlay) + .zIndex(popupManager.priority.overlay) .animation(.linear, value: popupManager.stack) .onTapGesture(perform: onTap) } func createTopPopupStackView() -> some View { - PopupVerticalStackView(viewModel: topStackViewModel).zIndex(popupManager.stackPriority.top) + PopupVerticalStackView(viewModel: topStackViewModel).zIndex(popupManager.priority.top) } func createCentrePopupStackView() -> some View { - PopupCentreStackView(viewModel: centreStackViewModel).zIndex(popupManager.stackPriority.center) + PopupCentreStackView(viewModel: centreStackViewModel).zIndex(popupManager.priority.center) } func createBottomPopupStackView() -> some View { - PopupVerticalStackView(viewModel: bottomStackViewModel).zIndex(popupManager.stackPriority.bottom) + PopupVerticalStackView(viewModel: bottomStackViewModel).zIndex(popupManager.priority.bottom) } } private extension PopupView { diff --git a/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift b/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift similarity index 80% rename from Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift rename to Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift index 5ae4bf9ffc..6328beee21 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+PopupManager.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift @@ -1,5 +1,5 @@ // -// Public+Dismiss+PopupManager.swift of MijickPopups +// Public+Dismiss+PopupStack.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com @@ -11,7 +11,7 @@ import Foundation -public extension PopupManager { +public extension PopupStack { /** Removes the currently active popup from the stack. Makes the next popup in the stack the new active popup. @@ -21,7 +21,7 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor static func dismissLastPopup(popupManagerID: PopupManagerID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeLastPopup) } + @MainActor static func dismissLastPopup(popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeLastPopup) } /** Removes all popups with the specified identifier from the stack. @@ -32,7 +32,7 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor static func dismissPopup(_ id: String, popupManagerID: PopupManagerID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsWithID(id)) } + @MainActor static func dismissPopup(_ id: String, popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsWithID(id)) } /** Removes all popups of the provided type from the stack. @@ -44,7 +44,7 @@ public extension PopupManager { - Important: If a custom ID (``Popup/setCustomID(_:)``) is set for the popup, use the ``dismissPopup(_:popupManagerID:)-1atvy`` method instead. - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor static func dismissPopup(_ type: P.Type, popupManagerID: PopupManagerID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsOfType(type)) } + @MainActor static func dismissPopup(_ type: P.Type, popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsOfType(type)) } /** Removes all popups from the stack. @@ -54,5 +54,5 @@ public extension PopupManager { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popups. */ - @MainActor static func dismissAllPopups(popupManagerID: PopupManagerID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopups) } + @MainActor static func dismissAllPopups(popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopups) } } diff --git a/Sources/Public/Dismiss/Public+Dismiss+View.swift b/Sources/Public/Dismiss/Public+Dismiss+View.swift index f2299f1acd..34b702d1f9 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+View.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+View.swift @@ -21,7 +21,7 @@ public extension View { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor func dismissLastPopup(popupManagerID: PopupManagerID = .shared) async { await PopupManager.dismissLastPopup(popupManagerID: popupManagerID) } + @MainActor func dismissLastPopup(popupManagerID: PopupStackID = .shared) async { await PopupStack.dismissLastPopup(popupManagerID: popupManagerID) } /** Removes all popups with the specified identifier from the stack. @@ -32,7 +32,7 @@ public extension View { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor func dismissPopup(_ id: String, popupManagerID: PopupManagerID = .shared) async { await PopupManager.dismissPopup(id, popupManagerID: popupManagerID) } + @MainActor func dismissPopup(_ id: String, popupManagerID: PopupStackID = .shared) async { await PopupStack.dismissPopup(id, popupManagerID: popupManagerID) } /** Removes all popups of the provided type from the stack. @@ -44,7 +44,7 @@ public extension View { - Important: If a custom ID (see ``Popup/setCustomID(_:)`` method for reference) is set for the popup, use the ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-55ubm`` method instead. - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor func dismissPopup(_ type: P.Type, popupManagerID: PopupManagerID = .shared) async { await PopupManager.dismissPopup(type, popupManagerID: popupManagerID) } + @MainActor func dismissPopup(_ type: P.Type, popupManagerID: PopupStackID = .shared) async { await PopupStack.dismissPopup(type, popupManagerID: popupManagerID) } /** Removes all popups from the stack. @@ -54,5 +54,5 @@ public extension View { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popups. */ - @MainActor func dismissAllPopups(popupManagerID: PopupManagerID = .shared) async { await PopupManager.dismissAllPopups(popupManagerID: popupManagerID) } + @MainActor func dismissAllPopups(popupManagerID: PopupStackID = .shared) async { await PopupStack.dismissAllPopups(popupManagerID: popupManagerID) } } diff --git a/Sources/Public/Present/Public+Present+Popup.swift b/Sources/Public/Present/Public+Present+Popup.swift index 605743459a..cc57963306 100644 --- a/Sources/Public/Present/Public+Present+Popup.swift +++ b/Sources/Public/Present/Public+Present+Popup.swift @@ -20,10 +20,10 @@ public extension Popup { - Important: The **popupManagerID** must be registered prior to use. For more information see ``SwiftUICore/View/registerPopups(id:configBuilder:)``. - Important: The methods - ``PopupManager/dismissLastPopup(popupManagerID:)``, - ``PopupManager/dismissPopup(_:popupManagerID:)-1atvy``, - ``PopupManager/dismissPopup(_:popupManagerID:)-6l2c2``, - ``PopupManager/dismissAllPopups(popupManagerID:)``, + ``PopupStack/dismissLastPopup(popupManagerID:)``, + ``PopupStack/dismissPopup(_:popupManagerID:)-1atvy``, + ``PopupStack/dismissPopup(_:popupManagerID:)-6l2c2``, + ``PopupStack/dismissAllPopups(popupManagerID:)``, ``SwiftUICore/View/dismissLastPopup(popupManagerID:)``, ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-55ubm``, ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-9mkd5``, @@ -32,7 +32,7 @@ public extension Popup { - Warning: To present multiple popups of the same type, set a unique identifier using the method ``Popup/setCustomID(_:)``. */ - @MainActor func present(popupManagerID: PopupManagerID = .shared) async { await PopupManager.fetchInstance(id: popupManagerID)?.stack(.insertPopup(.init(self))) } + @MainActor func present(popupManagerID: PopupStackID = .shared) async { await PopupStack.fetchInstance(id: popupManagerID)?.stack(.insertPopup(.init(self))) } } // MARK: Configure Popup @@ -40,7 +40,7 @@ public extension Popup { /** Sets the custom ID for the selected popup. - - important: To dismiss a popup with a custom ID set, use methods ``PopupManager/dismissPopup(_:popupManagerID:)-1atvy`` or ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-55ubm`` + - important: To dismiss a popup with a custom ID set, use methods ``PopupStack/dismissPopup(_:popupManagerID:)-1atvy`` or ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-55ubm`` - tip: Useful if you want to display several different popups of the same type. */ @MainActor func setCustomID(_ id: String) async -> some Popup { await AnyPopup(self).updatedID(id) } diff --git a/Sources/Public/Setup/Popup+Setup+PopupManagerID.swift b/Sources/Public/Setup/Popup+Setup+PopupStackID.swift similarity index 77% rename from Sources/Public/Setup/Popup+Setup+PopupManagerID.swift rename to Sources/Public/Setup/Popup+Setup+PopupStackID.swift index e6ec71f860..4b89b828f8 100644 --- a/Sources/Public/Setup/Popup+Setup+PopupManagerID.swift +++ b/Sources/Public/Setup/Popup+Setup+PopupStackID.swift @@ -1,5 +1,5 @@ // -// Popup+Setup+PopupManagerID.swift of MijickPopups +// Popup+Setup+PopupStackID.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com @@ -25,22 +25,22 @@ } } - extension PopupManagerID { + extension PopupStackID { static let custom1: Self = .init(rawValue: "custom1") static let custom2: Self = .init(rawValue: "custom2") } ``` - - important: Use methods like ``SwiftUICore/View/dismissLastPopup(popupManagerID:)`` or ``Popup/present(popupManagerID:)`` only with a registered PopupManagerID. - - tip: The main use case where you might need to register a different PopupManagerID is when your application has multiple windows - for example, on macOS, iPad or visionOS. + - important: Use methods like ``SwiftUICore/View/dismissLastPopup(popupManagerID:)`` or ``Popup/present(popupManagerID:)`` only with a registered PopupStackID. + - tip: The main use case where you might need to register a different PopupStackID is when your application has multiple windows - for example, on macOS, iPad or visionOS. */ -public struct PopupManagerID: Equatable, Sendable { +public struct PopupStackID: Equatable, Sendable { let rawValue: String public init(rawValue: String) { self.rawValue = rawValue } } // MARK: Default Instance -public extension PopupManagerID { +public extension PopupStackID { static let shared: Self = .init(rawValue: "shared") } diff --git a/Sources/Public/Setup/Public+Setup+View.swift b/Sources/Public/Setup/Public+Setup+View.swift index b4e01dfe8a..2c37736aa7 100644 --- a/Sources/Public/Setup/Public+Setup+View.swift +++ b/Sources/Public/Setup/Public+Setup+View.swift @@ -16,7 +16,7 @@ public extension View { Registers the framework to work in your application. - Parameters: - - id: It is possible to register multiple managers (for different windows); especially useful in a macOS or iPad implementation. Read more in ``PopupManagerID``. + - id: It is possible to register multiple managers (for different windows); especially useful in a macOS or iPad implementation. Read more in ``PopupStackID``. - configBuilder: Default configuration for all popups. Use the ``Popup/configurePopup(config:)-98ha0`` method to change the configuration for a specific popup. See the list of available methods in ``GlobalConfig``. @@ -42,7 +42,7 @@ public extension View { - seealso: It's also possible to register the framework with ``PopupSceneDelegate``; useful if you want to use the library with Apple's default sheets. */ - func registerPopups(id: PopupManagerID = .shared, configBuilder: @escaping (GlobalConfigContainer) -> GlobalConfigContainer = { $0 }) -> some View { + func registerPopups(id: PopupStackID = .shared, configBuilder: @escaping (GlobalConfigContainer) -> GlobalConfigContainer = { $0 }) -> some View { #if os(tvOS) PopupView(rootView: self, popupManager: .registerInstance(id: id)).onAppear { _ = configBuilder(.init()) } #else diff --git a/Tests/Tests+PopupManager.swift b/Tests/Tests+PopupManager.swift index bd21aa2804..808fd5ec27 100644 --- a/Tests/Tests+PopupManager.swift +++ b/Tests/Tests+PopupManager.swift @@ -1,5 +1,5 @@ // -// Tests+PopupManager.swift of MijickPopups +// Tests+PopupStack.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com @@ -13,9 +13,9 @@ import XCTest import SwiftUI @testable import MijickPopups -@MainActor final class PopupManagerTests: XCTestCase { +@MainActor final class PopupStackTests: XCTestCase { override func setUp() async throws { - PopupManagerContainer.clean() + PopupStackContainer.clean() } } @@ -26,15 +26,15 @@ import SwiftUI // MARK: Register New Instance -extension PopupManagerTests { +extension PopupStackTests { func test_registerNewInstance_withNoInstancesToRegister() { - let popupManagerIds: [PopupManagerID] = [] + let popupManagerIds: [PopupStackID] = [] registerNewInstances(popupManagerIds: popupManagerIds) XCTAssertEqual(popupManagerIds, getRegisteredInstances()) } func test_registerNewInstance_withUniqueInstancesToRegister() { - let popupManagerIds: [PopupManagerID] = [ + let popupManagerIds: [PopupStackID] = [ .staremiasto, .grzegorzki, .krowodrza, @@ -45,7 +45,7 @@ extension PopupManagerTests { XCTAssertEqual(popupManagerIds, getRegisteredInstances()) } func test_registerNewInstance_withRepeatingInstancesToRegister() { - let popupManagerIds: [PopupManagerID] = [ + let popupManagerIds: [PopupStackID] = [ .staremiasto, .grzegorzki, .krowodrza, @@ -61,19 +61,19 @@ extension PopupManagerTests { XCTAssertEqual(getRegisteredInstances().count, 6) } } -private extension PopupManagerTests { - func registerNewInstances(popupManagerIds: [PopupManagerID]) { - popupManagerIds.forEach { _ = PopupManager.registerInstance(id: $0) } +private extension PopupStackTests { + func registerNewInstances(popupManagerIds: [PopupStackID]) { + popupManagerIds.forEach { _ = PopupStack.registerInstance(id: $0) } } - func getRegisteredInstances() -> [PopupManagerID] { - PopupManagerContainer.instances.map(\.id) + func getRegisteredInstances() -> [PopupStackID] { + PopupStackContainer.instances.map(\.id) } } // MARK: Get Instance -extension PopupManagerTests { +extension PopupStackTests { func test_getInstance_whenNoInstancesAreRegistered() { - let managerInstance = PopupManager.fetchInstance(id: .bronowice) + let managerInstance = PopupStack.fetchInstance(id: .bronowice) XCTAssertNil(managerInstance) } func test_getInstance_whenInstanceIsNotRegistered() { @@ -85,7 +85,7 @@ extension PopupManagerTests { .grzegorzki ]) - let managerInstance = PopupManager.fetchInstance(id: .bronowice) + let managerInstance = PopupStack.fetchInstance(id: .bronowice) XCTAssertNil(managerInstance) } func test_getInstance_whenInstanceIsRegistered() { @@ -95,13 +95,13 @@ extension PopupManagerTests { .grzegorzki ]) - let managerInstance = PopupManager.fetchInstance(id: .grzegorzki) + let managerInstance = PopupStack.fetchInstance(id: .grzegorzki) XCTAssertNotNil(managerInstance) } } // MARK: Present Popup -extension PopupManagerTests { +extension PopupStackTests { func test_presentPopup_withThreePopupsToBePresented() { registerNewInstanceAndPresentPopups(popups: [ AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), @@ -155,10 +155,10 @@ extension PopupManagerTests { } // MARK: Dismiss Popup -extension PopupManagerTests { +extension PopupStackTests { func test_dismissLastPopup_withNoPopupsOnStack() { registerNewInstanceAndPresentPopups(popups: []) - PopupManager.dismissLastPopup(popupManagerID: defaultPopupManagerID) + PopupStack.dismissLastPopup(popupManagerID: defaultPopupManagerID) let popupsOnStack = getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack.count, 0) @@ -169,7 +169,7 @@ extension PopupManagerTests { AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()) ]) - PopupManager.dismissLastPopup(popupManagerID: defaultPopupManagerID) + PopupStack.dismissLastPopup(popupManagerID: defaultPopupManagerID) let popupsOnStack = getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack.count, 2) @@ -185,7 +185,7 @@ extension PopupManagerTests { let popupsOnStackBefore = getPopupsForActiveInstance() XCTAssertEqual(popups, popupsOnStackBefore) - PopupManager.dismissPopup(TestBottomPopup.self, popupManagerID: defaultPopupManagerID) + PopupStack.dismissPopup(TestBottomPopup.self, popupManagerID: defaultPopupManagerID) let popupsOnStackAfter = getPopupsForActiveInstance() XCTAssertEqual([popups[0], popups[1]], popupsOnStackAfter) @@ -200,7 +200,7 @@ extension PopupManagerTests { let popupsOnStackBefore = getPopupsForActiveInstance() XCTAssertEqual(popups, popupsOnStackBefore) - PopupManager.dismissPopup(TestCentrePopup.self, popupManagerID: defaultPopupManagerID) + PopupStack.dismissPopup(TestCentrePopup.self, popupManagerID: defaultPopupManagerID) let popupsOnStackAfter = getPopupsForActiveInstance() XCTAssertEqual(popups, popupsOnStackAfter) @@ -215,7 +215,7 @@ extension PopupManagerTests { let popupsOnStackBefore = getPopupsForActiveInstance() XCTAssertEqual(popups, popupsOnStackBefore) - PopupManager.dismissPopup(TestTopPopup.self, popupManagerID: defaultPopupManagerID) + PopupStack.dismissPopup(TestTopPopup.self, popupManagerID: defaultPopupManagerID) let popupsOnStackAfter = getPopupsForActiveInstance() XCTAssertEqual(popups, popupsOnStackAfter) @@ -230,7 +230,7 @@ extension PopupManagerTests { let popupsOnStackBefore = getPopupsForActiveInstance() XCTAssertEqual(popups, popupsOnStackBefore) - PopupManager.dismissPopup("2137", popupManagerID: defaultPopupManagerID) + PopupStack.dismissPopup("2137", popupManagerID: defaultPopupManagerID) let popupsOnStackAfter = getPopupsForActiveInstance() XCTAssertEqual([popups[1]], popupsOnStackAfter) @@ -241,7 +241,7 @@ extension PopupManagerTests { AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()) ]) - PopupManager.dismissAllPopups(popupManagerID: defaultPopupManagerID) + PopupStack.dismissAllPopups(popupManagerID: defaultPopupManagerID) let popupsOnStack = getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack.count, 0) @@ -255,25 +255,25 @@ extension PopupManagerTests { // MARK: Methods -private extension PopupManagerTests { +private extension PopupStackTests { func registerNewInstanceAndPresentPopups(popups: [any Popup]) { registerNewInstances(popupManagerIds: [defaultPopupManagerID]) popups.forEach { $0.present(popupManagerID: defaultPopupManagerID) } } func getPopupsForActiveInstance() -> [AnyPopup] { - PopupManager + PopupStack .fetchInstance(id: defaultPopupManagerID)? .stack ?? [] } } // MARK: Variables -private extension PopupManagerTests { - var defaultPopupManagerID: PopupManagerID { .staremiasto } +private extension PopupStackTests { + var defaultPopupManagerID: PopupStackID { .staremiasto } } // MARK: Popup Manager Identifiers -private extension PopupManagerID { +private extension PopupStackID { static let staremiasto: Self = .init(rawValue: "staremiasto") static let grzegorzki: Self = .init(rawValue: "grzegorzki") static let pradnikczerwony: Self = .init(rawValue: "pradnikczerwony") From 9f9bcf6353f0e425ba4ae11cb8cc7e4c9b40a1f6 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 17:38:03 +0100 Subject: [PATCH 279/407] 1 --- Sources/Internal/Containers/PopupStack.swift | 18 ++++++------ Sources/Internal/Models/AnyPopup.swift | 2 +- Sources/Internal/UI/PopupView.swift | 28 +++++++++---------- .../Dismiss/Public+Dismiss+PopupStack.swift | 8 +++--- .../Public/Present/Public+Present+Popup.swift | 2 +- Sources/Public/Setup/Public+Setup+View.swift | 2 +- Tests/Tests+PopupManager.swift | 4 +-- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Sources/Internal/Containers/PopupStack.swift b/Sources/Internal/Containers/PopupStack.swift index af64e18030..154a9113e5 100644 --- a/Sources/Internal/Containers/PopupStack.swift +++ b/Sources/Internal/Containers/PopupStack.swift @@ -13,7 +13,7 @@ import SwiftUI @MainActor public class PopupStack: ObservableObject { let id: PopupStackID - @Published private(set) var stack: [AnyPopup] = [] + @Published private(set) var popups: [AnyPopup] = [] @Published private(set) var priority: StackPriority = .init() private init(id: PopupStackID) { self.id = id } @@ -21,8 +21,8 @@ import SwiftUI // MARK: Update extension PopupStack { - func updateStack(_ popup: AnyPopup) { if let index = stack.firstIndex(of: popup) { - stack[index] = popup + func update(popup: AnyPopup) { if let index = popups.firstIndex(of: popup) { + popups[index] = popup }} } @@ -77,19 +77,19 @@ private extension PopupStack { } } private extension PopupStack { - nonisolated func insertedPopup(_ erasedPopup: AnyPopup) async -> [AnyPopup] { await stack.modifiedAsync(if: await !stack.contains { $0.id.isSameType(as: erasedPopup.id) }) { + nonisolated func insertedPopup(_ erasedPopup: AnyPopup) async -> [AnyPopup] { await popups.modifiedAsync(if: await !popups.contains { $0.id.isSameType(as: erasedPopup.id) }) { $0.append(await erasedPopup.startDismissTimerIfNeeded(self)) }} - nonisolated func removedLastPopup() async -> [AnyPopup] { await stack.modifiedAsync(if: !stack.isEmpty) { + nonisolated func removedLastPopup() async -> [AnyPopup] { await popups.modifiedAsync(if: !popups.isEmpty) { $0.removeLast() }} - nonisolated func removedPopupInstance(_ popup: AnyPopup) async -> [AnyPopup] { await stack.modifiedAsync { + nonisolated func removedPopupInstance(_ popup: AnyPopup) async -> [AnyPopup] { await popups.modifiedAsync { $0.removeAll { $0.id.isSameInstance(as: popup) } }} - nonisolated func removedAllPopupsOfType(_ popupType: any Popup.Type) async -> [AnyPopup] { await stack.modifiedAsync { + nonisolated func removedAllPopupsOfType(_ popupType: any Popup.Type) async -> [AnyPopup] { await popups.modifiedAsync { $0.removeAll { $0.id.isSameType(as: popupType) } }} - nonisolated func removedAllPopupsWithID(_ id: String) async -> [AnyPopup] { await stack.modifiedAsync { + nonisolated func removedAllPopupsWithID(_ id: String) async -> [AnyPopup] { await popups.modifiedAsync { $0.removeAll { $0.id.isSameType(as: id) } }} nonisolated func removedAllPopups() async -> [AnyPopup] { @@ -122,7 +122,7 @@ private extension PopupStack { // MARK: Register extension PopupStack { - static func registerInstance(id: PopupStackID) -> PopupStack { + static func registerStack(id: PopupStackID) -> PopupStack { let instanceToRegister = PopupStack(id: id) let registeredInstance = PopupStackContainer.register(popupManager: instanceToRegister) return registeredInstance diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 1afa1d20af..6455912e7c 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -59,7 +59,7 @@ private extension AnyPopup { extension AnyPopup { func updatedDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} func updatedEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} - func startDismissTimerIfNeeded(_ popupManager: PopupStack) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.stack(.removePopupInstance(self)) }}} + func startDismissTimerIfNeeded(_ popupManager: PopupStack) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.modify(.removePopupInstance(self)) }}} } private extension AnyPopup { func updated(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 4b79d57e41..6ba36a3b7d 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -16,7 +16,7 @@ struct PopupView: View { let rootView: any View #endif - @ObservedObject var popupManager: PopupStack + @ObservedObject var stack: PopupStack private let topStackViewModel: VM.VerticalStack = .init(TopPopupConfig.self) private let centreStackViewModel: VM.CentreStack = .init(CentrePopupConfig.self) private let bottomStackViewModel: VM.VerticalStack = .init(BottomPopupConfig.self) @@ -41,8 +41,8 @@ private extension PopupView { .onChange(of: reader.size) { _ in onScreenChange(reader) } } .onAppear(perform: onAppear) - .onChange(of: popupManager.stack.map { [$0.height, $0.dragHeight] }, perform: onPopupsHeightChange) - .onChange(of: popupManager.stack) { [oldValue = popupManager.stack] newValue in onStackChange(oldValue, newValue) } + .onChange(of: stack.popups.map { [$0.height, $0.dragHeight] }, perform: onPopupsHeightChange) + .onChange(of: stack.popups) { [oldValue = stack.popups] newValue in onStackChange(oldValue, newValue) } .onKeyboardStateChange(perform: onKeyboardStateChange) } } @@ -59,22 +59,22 @@ private extension PopupView { private extension PopupView { func createOverlayView() -> some View { getOverlayColor() - .zIndex(popupManager.priority.overlay) - .animation(.linear, value: popupManager.stack) + .zIndex(stack.priority.overlay) + .animation(.linear, value: stack.popups) .onTapGesture(perform: onTap) } func createTopPopupStackView() -> some View { - PopupVerticalStackView(viewModel: topStackViewModel).zIndex(popupManager.priority.top) + PopupVerticalStackView(viewModel: topStackViewModel).zIndex(stack.priority.top) } func createCentrePopupStackView() -> some View { - PopupCentreStackView(viewModel: centreStackViewModel).zIndex(popupManager.priority.center) + PopupCentreStackView(viewModel: centreStackViewModel).zIndex(stack.priority.center) } func createBottomPopupStackView() -> some View { - PopupVerticalStackView(viewModel: bottomStackViewModel).zIndex(popupManager.priority.bottom) + PopupVerticalStackView(viewModel: bottomStackViewModel).zIndex(stack.priority.bottom) } } private extension PopupView { - func getOverlayColor() -> Color { switch popupManager.stack.last?.config.overlayColor { + func getOverlayColor() -> Color { switch stack.popups.last?.config.overlayColor { case .some(let color) where color == .clear: .black.opacity(0.0000000000001) case .some(let color): color case nil: .clear @@ -89,7 +89,7 @@ private extension PopupView { await updateViewModels { await $0.updateScreen(screenReader: screenReader) } }} func onPopupsHeightChange(_ p: Any) { Task { @MainActor in - await updateViewModels { await $0.updatePopups(popupManager.stack) } + await updateViewModels { await $0.updatePopups(stack.popups) } }} func onStackChange(_ oldStack: [AnyPopup], _ newStack: [AnyPopup]) { newStack @@ -104,20 +104,20 @@ private extension PopupView { await updateViewModels { await $0.updateScreen(isKeyboardActive: isKeyboardActive) } }} func onTap() { if tapOutsideClosesPopup { - popupManager.stack(.removeLastPopup) + stack.modify(.removeLastPopup) }} } private extension PopupView { nonisolated func updatePopup(_ popup: AnyPopup) async { - await popupManager.updateStack(popup) + await stack.update(popup: popup) } nonisolated func closePopup(_ popup: AnyPopup) async { - await popupManager.stack(.removePopupInstance(popup)) + await stack.modify(.removePopupInstance(popup)) } func updateViewModels(_ updateBuilder: @escaping (any ViewModel) async -> ()) async { for viewModel in [topStackViewModel, centreStackViewModel, bottomStackViewModel] { Task { @MainActor in await updateBuilder(viewModel as! any ViewModel) }} } } private extension PopupView { - var tapOutsideClosesPopup: Bool { popupManager.stack.last?.config.isTapOutsideToDismissEnabled ?? false } + var tapOutsideClosesPopup: Bool { stack.popups.last?.config.isTapOutsideToDismissEnabled ?? false } } diff --git a/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift b/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift index 6328beee21..d0fcd30280 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift @@ -21,7 +21,7 @@ public extension PopupStack { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor static func dismissLastPopup(popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeLastPopup) } + @MainActor static func dismissLastPopup(popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.modify(.removeLastPopup) } /** Removes all popups with the specified identifier from the stack. @@ -32,7 +32,7 @@ public extension PopupStack { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor static func dismissPopup(_ id: String, popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsWithID(id)) } + @MainActor static func dismissPopup(_ id: String, popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.modify(.removeAllPopupsWithID(id)) } /** Removes all popups of the provided type from the stack. @@ -44,7 +44,7 @@ public extension PopupStack { - Important: If a custom ID (``Popup/setCustomID(_:)``) is set for the popup, use the ``dismissPopup(_:popupManagerID:)-1atvy`` method instead. - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor static func dismissPopup(_ type: P.Type, popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopupsOfType(type)) } + @MainActor static func dismissPopup(_ type: P.Type, popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.modify(.removeAllPopupsOfType(type)) } /** Removes all popups from the stack. @@ -54,5 +54,5 @@ public extension PopupStack { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popups. */ - @MainActor static func dismissAllPopups(popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.stack(.removeAllPopups) } + @MainActor static func dismissAllPopups(popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.modify(.removeAllPopups) } } diff --git a/Sources/Public/Present/Public+Present+Popup.swift b/Sources/Public/Present/Public+Present+Popup.swift index cc57963306..1de134c2f8 100644 --- a/Sources/Public/Present/Public+Present+Popup.swift +++ b/Sources/Public/Present/Public+Present+Popup.swift @@ -32,7 +32,7 @@ public extension Popup { - Warning: To present multiple popups of the same type, set a unique identifier using the method ``Popup/setCustomID(_:)``. */ - @MainActor func present(popupManagerID: PopupStackID = .shared) async { await PopupStack.fetchInstance(id: popupManagerID)?.stack(.insertPopup(.init(self))) } + @MainActor func present(popupManagerID: PopupStackID = .shared) async { await PopupStack.fetchInstance(id: popupManagerID)?.modify(.insertPopup(.init(self))) } } // MARK: Configure Popup diff --git a/Sources/Public/Setup/Public+Setup+View.swift b/Sources/Public/Setup/Public+Setup+View.swift index 2c37736aa7..1356033a92 100644 --- a/Sources/Public/Setup/Public+Setup+View.swift +++ b/Sources/Public/Setup/Public+Setup+View.swift @@ -48,7 +48,7 @@ public extension View { #else self .frame(maxWidth: .infinity, maxHeight: .infinity) - .overlay(PopupView(popupManager: .registerInstance(id: id)), alignment: .top) + .overlay(PopupView(stack: .registerStack(id: id)), alignment: .top) .onAppear { _ = configBuilder(.init()) } #endif } diff --git a/Tests/Tests+PopupManager.swift b/Tests/Tests+PopupManager.swift index 808fd5ec27..2a0af5cf04 100644 --- a/Tests/Tests+PopupManager.swift +++ b/Tests/Tests+PopupManager.swift @@ -63,7 +63,7 @@ extension PopupStackTests { } private extension PopupStackTests { func registerNewInstances(popupManagerIds: [PopupStackID]) { - popupManagerIds.forEach { _ = PopupStack.registerInstance(id: $0) } + popupManagerIds.forEach { _ = PopupStack.registerStack(id: $0) } } func getRegisteredInstances() -> [PopupStackID] { PopupStackContainer.instances.map(\.id) @@ -263,7 +263,7 @@ private extension PopupStackTests { func getPopupsForActiveInstance() -> [AnyPopup] { PopupStack .fetchInstance(id: defaultPopupManagerID)? - .stack ?? [] + .popups ?? [] } } From 51f8e77b7d5cf595cbee2819a60befe7ebede352 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 17:40:11 +0100 Subject: [PATCH 280/407] 1 --- Sources/Internal/Containers/PopupStack.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/Containers/PopupStack.swift b/Sources/Internal/Containers/PopupStack.swift index 154a9113e5..13424208af 100644 --- a/Sources/Internal/Containers/PopupStack.swift +++ b/Sources/Internal/Containers/PopupStack.swift @@ -40,10 +40,10 @@ extension PopupStack { enum StackOperation { // MARK: Perform Operation extension PopupStack { - func stack(_ operation: StackOperation) { Task { + func modify(_ operation: StackOperation) { Task { await hideKeyboard() - let oldStack = stack, + let oldStack = popups, newStack = await getNewStack(operation), newPriority = await getNewStackPriority(newStack) @@ -67,10 +67,10 @@ private extension PopupStack { await priority.reshuffled(newStack) } nonisolated func updateStack(_ newStack: [AnyPopup]) async { - Task { @MainActor in stack = newStack } + Task { @MainActor in popups = newStack } } nonisolated func updatePriority(_ newPriority: StackPriority, _ oldStackCount: Int) async { - let delayDuration = await oldStackCount > stack.count ? Animation.duration : 0 + let delayDuration = await oldStackCount > popups.count ? Animation.duration : 0 await Task.sleep(seconds: delayDuration) Task { @MainActor in priority = newPriority } From a608e1dbb78fed3bde63956fc7b52ee0b9cf12f1 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 17:46:17 +0100 Subject: [PATCH 281/407] 1 --- Sources/Internal/Containers/PopupStack.swift | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/Internal/Containers/PopupStack.swift b/Sources/Internal/Containers/PopupStack.swift index 13424208af..7f93b82d21 100644 --- a/Sources/Internal/Containers/PopupStack.swift +++ b/Sources/Internal/Containers/PopupStack.swift @@ -43,19 +43,19 @@ extension PopupStack { func modify(_ operation: StackOperation) { Task { await hideKeyboard() - let oldStack = popups, - newStack = await getNewStack(operation), - newPriority = await getNewStackPriority(newStack) + let oldPopups = popups, + newPopups = await getNewPopups(operation), + newPriority = await getNewPriority(newPopups) - await updateStack(newStack) - await updatePriority(newPriority, oldStack.count) + await updatePopups(newPopups) + await updatePriority(newPriority, oldPopups.count) }} } private extension PopupStack { nonisolated func hideKeyboard() async { await AnyView.hideKeyboard() } - nonisolated func getNewStack(_ operation: StackOperation) async -> [AnyPopup] { switch operation { + nonisolated func getNewPopups(_ operation: StackOperation) async -> [AnyPopup] { switch operation { case .insertPopup(let popup): await insertedPopup(popup) case .removeLastPopup: await removedLastPopup() case .removePopupInstance(let popup): await removedPopupInstance(popup) @@ -63,14 +63,14 @@ private extension PopupStack { case .removeAllPopupsWithID(let id): await removedAllPopupsWithID(id) case .removeAllPopups: await removedAllPopups() }} - nonisolated func getNewStackPriority(_ newStack: [AnyPopup]) async -> StackPriority { - await priority.reshuffled(newStack) + nonisolated func getNewPriority(_ newPopups: [AnyPopup]) async -> StackPriority { + await priority.reshuffled(newPopups) } - nonisolated func updateStack(_ newStack: [AnyPopup]) async { - Task { @MainActor in popups = newStack } + nonisolated func updatePopups(_ newPopups: [AnyPopup]) async { + Task { @MainActor in popups = newPopups } } - nonisolated func updatePriority(_ newPriority: StackPriority, _ oldStackCount: Int) async { - let delayDuration = await oldStackCount > popups.count ? Animation.duration : 0 + nonisolated func updatePriority(_ newPriority: StackPriority, _ oldPopupsCount: Int) async { + let delayDuration = await oldPopupsCount > popups.count ? Animation.duration : 0 await Task.sleep(seconds: delayDuration) Task { @MainActor in priority = newPriority } From a2b0498c60426905798f424ab83368a1f9c028b6 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 17:59:25 +0100 Subject: [PATCH 282/407] 1 --- Sources/Internal/Containers/PopupStack.swift | 10 ++++------ .../Internal/Containers/PopupStackContainer.swift | 12 ++++++------ Tests/Tests+PopupManager.swift | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Sources/Internal/Containers/PopupStack.swift b/Sources/Internal/Containers/PopupStack.swift index 7f93b82d21..d3591ab7fe 100644 --- a/Sources/Internal/Containers/PopupStack.swift +++ b/Sources/Internal/Containers/PopupStack.swift @@ -32,13 +32,11 @@ extension PopupStack { -// MARK: Available Operations +// MARK: Stack Operations extension PopupStack { enum StackOperation { case insertPopup(AnyPopup) case removeLastPopup, removePopupInstance(AnyPopup), removeAllPopupsOfType(any Popup.Type), removeAllPopupsWithID(String), removeAllPopups }} - -// MARK: Perform Operation extension PopupStack { func modify(_ operation: StackOperation) { Task { await hideKeyboard() @@ -123,8 +121,8 @@ private extension PopupStack { // MARK: Register extension PopupStack { static func registerStack(id: PopupStackID) -> PopupStack { - let instanceToRegister = PopupStack(id: id) - let registeredInstance = PopupStackContainer.register(popupManager: instanceToRegister) - return registeredInstance + let stackToRegister = PopupStack(id: id) + let registeredStack = PopupStackContainer.register(stack: stackToRegister) + return registeredStack } } diff --git a/Sources/Internal/Containers/PopupStackContainer.swift b/Sources/Internal/Containers/PopupStackContainer.swift index b94c3f5ae3..514b186c61 100644 --- a/Sources/Internal/Containers/PopupStackContainer.swift +++ b/Sources/Internal/Containers/PopupStackContainer.swift @@ -12,20 +12,20 @@ import Foundation @MainActor class PopupStackContainer { - static private(set) var instances: [PopupStack] = [] + static private(set) var stacks: [PopupStack] = [] } // MARK: Register extension PopupStackContainer { - static func register(popupManager: PopupStack) -> PopupStack { - if let alreadyRegisteredInstance = instances.first(where: { $0.id == popupManager.id }) { return alreadyRegisteredInstance } + static func register(stack: PopupStack) -> PopupStack { + if let alreadyRegisteredStack = stacks.first(where: { $0.id == stack.id }) { return alreadyRegisteredStack } - instances.append(popupManager) - return popupManager + stacks.append(stack) + return stack } } // MARK: Clean extension PopupStackContainer { - static func clean() { instances = [] } + static func clean() { stacks = [] } } diff --git a/Tests/Tests+PopupManager.swift b/Tests/Tests+PopupManager.swift index 2a0af5cf04..c3ba12d0f4 100644 --- a/Tests/Tests+PopupManager.swift +++ b/Tests/Tests+PopupManager.swift @@ -66,7 +66,7 @@ private extension PopupStackTests { popupManagerIds.forEach { _ = PopupStack.registerStack(id: $0) } } func getRegisteredInstances() -> [PopupStackID] { - PopupStackContainer.instances.map(\.id) + PopupStackContainer.stacks.map(\.id) } } From eec2a9e4c0f2efa0551b0fb31b16a983e0d6897d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 17:59:54 +0100 Subject: [PATCH 283/407] 1 --- Sources/Internal/Containers/PopupStack.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/Containers/PopupStack.swift b/Sources/Internal/Containers/PopupStack.swift index d3591ab7fe..35899d57c2 100644 --- a/Sources/Internal/Containers/PopupStack.swift +++ b/Sources/Internal/Containers/PopupStack.swift @@ -104,16 +104,16 @@ private extension PopupStack { // MARK: Fetch extension PopupStack { nonisolated static func fetchInstance(id: PopupStackID) async -> PopupStack? { - let managerObject = await PopupStackContainer.instances.first(where: { $0.id == id }) - await logNoInstanceErrorIfNeeded(managerObject: managerObject, popupManagerID: id) - return managerObject + let stackInstance = await PopupStackContainer.stacks.first(where: { $0.id == id }) + await logNoInstanceErrorIfNeeded(stack: stackInstance, popupStackID: id) + return stackInstance } } private extension PopupStack { - nonisolated static func logNoInstanceErrorIfNeeded(managerObject: PopupStack?, popupManagerID: PopupStackID) async { if managerObject == nil { + nonisolated static func logNoInstanceErrorIfNeeded(stack: PopupStack?, popupStackID: PopupStackID) async { if stack == nil { Logger.log( level: .fault, - message: "PopupManager instance (\(popupManagerID.rawValue)) must be registered before use. More details can be found in the documentation." + message: "PopupStack (\(popupStackID.rawValue)) must be registered before use. More details can be found in the documentation." ) }} } From 07634765dd74908793547a791a2cf7e0e6282286 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 18:03:20 +0100 Subject: [PATCH 284/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 2 +- Sources/Internal/UI/PopupView.swift | 2 +- Sources/Public/Setup/Public+Setup+View.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 6455912e7c..7c93ed59e2 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -59,7 +59,7 @@ private extension AnyPopup { extension AnyPopup { func updatedDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} func updatedEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} - func startDismissTimerIfNeeded(_ popupManager: PopupStack) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupManager.modify(.removePopupInstance(self)) }}} + func startDismissTimerIfNeeded(_ popupStack: PopupStack) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupStack.modify(.removePopupInstance(self)) }}} } private extension AnyPopup { func updated(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 6ba36a3b7d..f3a5500731 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -25,7 +25,7 @@ struct PopupView: View { var body: some View { #if os(tvOS) AnyView(rootView) - .disabled(!popupManager.stack.isEmpty) + .disabled(!stack.popups.isEmpty) .overlay(createBody()) #else createBody() diff --git a/Sources/Public/Setup/Public+Setup+View.swift b/Sources/Public/Setup/Public+Setup+View.swift index 1356033a92..eb0baff243 100644 --- a/Sources/Public/Setup/Public+Setup+View.swift +++ b/Sources/Public/Setup/Public+Setup+View.swift @@ -44,7 +44,7 @@ public extension View { */ func registerPopups(id: PopupStackID = .shared, configBuilder: @escaping (GlobalConfigContainer) -> GlobalConfigContainer = { $0 }) -> some View { #if os(tvOS) - PopupView(rootView: self, popupManager: .registerInstance(id: id)).onAppear { _ = configBuilder(.init()) } + PopupView(rootView: self, stack: .registerStack(id: id)).onAppear { _ = configBuilder(.init()) } #else self .frame(maxWidth: .infinity, maxHeight: .infinity) From ef4dc40c7a7a1cd051e6c0bd2ba9ca2ebf176607 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 18:04:45 +0100 Subject: [PATCH 285/407] 1 --- Sources/Internal/Containers/PopupStack.swift | 4 ++-- Sources/Internal/Models/AnyPopup.swift | 2 +- Sources/Internal/UI/PopupView.swift | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/Containers/PopupStack.swift b/Sources/Internal/Containers/PopupStack.swift index 35899d57c2..1e1a4fa25a 100644 --- a/Sources/Internal/Containers/PopupStack.swift +++ b/Sources/Internal/Containers/PopupStack.swift @@ -35,7 +35,7 @@ extension PopupStack { // MARK: Stack Operations extension PopupStack { enum StackOperation { case insertPopup(AnyPopup) - case removeLastPopup, removePopupInstance(AnyPopup), removeAllPopupsOfType(any Popup.Type), removeAllPopupsWithID(String), removeAllPopups + case removeLastPopup, removePopup(AnyPopup), removeAllPopupsOfType(any Popup.Type), removeAllPopupsWithID(String), removeAllPopups }} extension PopupStack { func modify(_ operation: StackOperation) { Task { @@ -56,7 +56,7 @@ private extension PopupStack { nonisolated func getNewPopups(_ operation: StackOperation) async -> [AnyPopup] { switch operation { case .insertPopup(let popup): await insertedPopup(popup) case .removeLastPopup: await removedLastPopup() - case .removePopupInstance(let popup): await removedPopupInstance(popup) + case .removePopup(let popup): await removedPopupInstance(popup) case .removeAllPopupsOfType(let popupType): await removedAllPopupsOfType(popupType) case .removeAllPopupsWithID(let id): await removedAllPopupsWithID(id) case .removeAllPopups: await removedAllPopups() diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 7c93ed59e2..badf0959c0 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -59,7 +59,7 @@ private extension AnyPopup { extension AnyPopup { func updatedDismissTimer(_ secondsToDismiss: Double) -> AnyPopup { updated { $0._dismissTimer = .prepare(time: secondsToDismiss) }} func updatedEnvironmentObject(_ environmentObject: some ObservableObject) -> AnyPopup { updated { $0._body = .init(_body.environmentObject(environmentObject)) }} - func startDismissTimerIfNeeded(_ popupStack: PopupStack) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupStack.modify(.removePopupInstance(self)) }}} + func startDismissTimerIfNeeded(_ popupStack: PopupStack) -> AnyPopup { updated { $0._dismissTimer?.schedule { popupStack.modify(.removePopup(self)) }}} } private extension AnyPopup { func updated(_ customBuilder: (inout AnyPopup) -> ()) -> AnyPopup { diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index f3a5500731..1ab5ca544b 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -112,7 +112,7 @@ private extension PopupView { await stack.update(popup: popup) } nonisolated func closePopup(_ popup: AnyPopup) async { - await stack.modify(.removePopupInstance(popup)) + await stack.modify(.removePopup(popup)) } func updateViewModels(_ updateBuilder: @escaping (any ViewModel) async -> ()) async { for viewModel in [topStackViewModel, centreStackViewModel, bottomStackViewModel] { Task { @MainActor in await updateBuilder(viewModel as! any ViewModel) }} From 62e83623a3f4c6bd99cdc94badd4858f0c890874 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 18:05:09 +0100 Subject: [PATCH 286/407] 1 --- Sources/Internal/Containers/PopupStack.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/Containers/PopupStack.swift b/Sources/Internal/Containers/PopupStack.swift index 1e1a4fa25a..e42b717558 100644 --- a/Sources/Internal/Containers/PopupStack.swift +++ b/Sources/Internal/Containers/PopupStack.swift @@ -56,7 +56,7 @@ private extension PopupStack { nonisolated func getNewPopups(_ operation: StackOperation) async -> [AnyPopup] { switch operation { case .insertPopup(let popup): await insertedPopup(popup) case .removeLastPopup: await removedLastPopup() - case .removePopup(let popup): await removedPopupInstance(popup) + case .removePopup(let popup): await removedPopup(popup) case .removeAllPopupsOfType(let popupType): await removedAllPopupsOfType(popupType) case .removeAllPopupsWithID(let id): await removedAllPopupsWithID(id) case .removeAllPopups: await removedAllPopups() @@ -81,7 +81,7 @@ private extension PopupStack { nonisolated func removedLastPopup() async -> [AnyPopup] { await popups.modifiedAsync(if: !popups.isEmpty) { $0.removeLast() }} - nonisolated func removedPopupInstance(_ popup: AnyPopup) async -> [AnyPopup] { await popups.modifiedAsync { + nonisolated func removedPopup(_ popup: AnyPopup) async -> [AnyPopup] { await popups.modifiedAsync { $0.removeAll { $0.id.isSameInstance(as: popup) } }} nonisolated func removedAllPopupsOfType(_ popupType: any Popup.Type) async -> [AnyPopup] { await popups.modifiedAsync { From 5377dcebd5a7728a98cad4df9e25964c99f72ac6 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 18:11:10 +0100 Subject: [PATCH 287/407] 1 --- Sources/Internal/Containers/PopupStack.swift | 2 +- Sources/Internal/Models/AnyPopup.swift | 2 +- Sources/Internal/Models/ID+Popup.swift | 2 +- Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift | 8 ++++---- Sources/Public/Present/Public+Present+Popup.swift | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/Internal/Containers/PopupStack.swift b/Sources/Internal/Containers/PopupStack.swift index e42b717558..8d7cb6b18b 100644 --- a/Sources/Internal/Containers/PopupStack.swift +++ b/Sources/Internal/Containers/PopupStack.swift @@ -82,7 +82,7 @@ private extension PopupStack { $0.removeLast() }} nonisolated func removedPopup(_ popup: AnyPopup) async -> [AnyPopup] { await popups.modifiedAsync { - $0.removeAll { $0.id.isSameInstance(as: popup) } + $0.removeAll { $0.id.isSame(as: popup) } }} nonisolated func removedAllPopupsOfType(_ popupType: any Popup.Type) async -> [AnyPopup] { await popups.modifiedAsync { $0.removeAll { $0.id.isSameType(as: popupType) } diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index badf0959c0..747fa5f2bf 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -85,7 +85,7 @@ extension AnyPopup { typealias Config = AnyPopupConfig // MARK: Hashable extension AnyPopup: Hashable { - nonisolated static func ==(lhs: AnyPopup, rhs: AnyPopup) -> Bool { lhs.id.isSameInstance(as: rhs) } + nonisolated static func ==(lhs: AnyPopup, rhs: AnyPopup) -> Bool { lhs.id.isSame(as: rhs) } nonisolated func hash(into hasher: inout Hasher) { hasher.combine(id.rawValue) } } diff --git a/Sources/Internal/Models/ID+Popup.swift b/Sources/Internal/Models/ID+Popup.swift index b164ee3f63..866463dbf2 100644 --- a/Sources/Internal/Models/ID+Popup.swift +++ b/Sources/Internal/Models/ID+Popup.swift @@ -30,10 +30,10 @@ extension PopupID { // MARK: Comparison extension PopupID { + func isSame(as popup: AnyPopup) -> Bool { rawValue == popup.id.rawValue } func isSameType(as id: String) -> Bool { getFirstComponent(of: self) == id } func isSameType(as popupType: any Popup.Type) -> Bool { getFirstComponent(of: self) == String(describing: popupType) } func isSameType(as popupID: PopupID) -> Bool { getFirstComponent(of: self) == getFirstComponent(of: popupID) } - func isSameInstance(as popup: AnyPopup) -> Bool { rawValue == popup.id.rawValue } } diff --git a/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift b/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift index d0fcd30280..c6eff1167d 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift @@ -21,7 +21,7 @@ public extension PopupStack { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor static func dismissLastPopup(popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.modify(.removeLastPopup) } + @MainActor static func dismissLastPopup(popupManagerID: PopupStackID = .shared) async { await fetch(id: popupManagerID)?.modify(.removeLastPopup) } /** Removes all popups with the specified identifier from the stack. @@ -32,7 +32,7 @@ public extension PopupStack { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor static func dismissPopup(_ id: String, popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.modify(.removeAllPopupsWithID(id)) } + @MainActor static func dismissPopup(_ id: String, popupManagerID: PopupStackID = .shared) async { await fetch(id: popupManagerID)?.modify(.removeAllPopupsWithID(id)) } /** Removes all popups of the provided type from the stack. @@ -44,7 +44,7 @@ public extension PopupStack { - Important: If a custom ID (``Popup/setCustomID(_:)``) is set for the popup, use the ``dismissPopup(_:popupManagerID:)-1atvy`` method instead. - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. */ - @MainActor static func dismissPopup(_ type: P.Type, popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.modify(.removeAllPopupsOfType(type)) } + @MainActor static func dismissPopup(_ type: P.Type, popupManagerID: PopupStackID = .shared) async { await fetch(id: popupManagerID)?.modify(.removeAllPopupsOfType(type)) } /** Removes all popups from the stack. @@ -54,5 +54,5 @@ public extension PopupStack { - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popups. */ - @MainActor static func dismissAllPopups(popupManagerID: PopupStackID = .shared) async { await fetchInstance(id: popupManagerID)?.modify(.removeAllPopups) } + @MainActor static func dismissAllPopups(popupManagerID: PopupStackID = .shared) async { await fetch(id: popupManagerID)?.modify(.removeAllPopups) } } diff --git a/Sources/Public/Present/Public+Present+Popup.swift b/Sources/Public/Present/Public+Present+Popup.swift index 1de134c2f8..df9cebed55 100644 --- a/Sources/Public/Present/Public+Present+Popup.swift +++ b/Sources/Public/Present/Public+Present+Popup.swift @@ -32,7 +32,7 @@ public extension Popup { - Warning: To present multiple popups of the same type, set a unique identifier using the method ``Popup/setCustomID(_:)``. */ - @MainActor func present(popupManagerID: PopupStackID = .shared) async { await PopupStack.fetchInstance(id: popupManagerID)?.modify(.insertPopup(.init(self))) } + @MainActor func present(popupManagerID: PopupStackID = .shared) async { await PopupStack.fetch(id: popupManagerID)?.modify(.insertPopup(.init(self))) } } // MARK: Configure Popup From ac20a47a42261da8b081071b555a69e9240f7f27 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 18:11:20 +0100 Subject: [PATCH 288/407] 1 --- Tests/Tests+PopupID.swift | 6 +++--- Tests/Tests+PopupManager.swift | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/Tests+PopupID.swift b/Tests/Tests+PopupID.swift index 585ec52b99..46574b3970 100644 --- a/Tests/Tests+PopupID.swift +++ b/Tests/Tests+PopupID.swift @@ -91,14 +91,14 @@ extension PopupIDTests { let popupID = PopupID.create(from: TestTopPopup.self), popup = AnyPopup(TestCentrePopup()) - let result = popupID.isSameInstance(as: popup) + let result = popupID.isSame(as: popup) XCTAssertEqual(result, false) } func test_isSameInstance_2() { let popupID = PopupID.create(from: TestTopPopup.self), popup = AnyPopup(TestTopPopup()) - let result = popupID.isSameInstance(as: popup) + let result = popupID.isSame(as: popup) XCTAssertEqual(result, true) } func test_isSameInstance_3() async { @@ -106,7 +106,7 @@ extension PopupIDTests { await Task.sleep(seconds: 1) let popup = AnyPopup(TestTopPopup()) - let result = popupID.isSameInstance(as: popup) + let result = popupID.isSame(as: popup) XCTAssertEqual(result, false) } } diff --git a/Tests/Tests+PopupManager.swift b/Tests/Tests+PopupManager.swift index c3ba12d0f4..dd47ca70bd 100644 --- a/Tests/Tests+PopupManager.swift +++ b/Tests/Tests+PopupManager.swift @@ -73,7 +73,7 @@ private extension PopupStackTests { // MARK: Get Instance extension PopupStackTests { func test_getInstance_whenNoInstancesAreRegistered() { - let managerInstance = PopupStack.fetchInstance(id: .bronowice) + let managerInstance = PopupStack.fetch(id: .bronowice) XCTAssertNil(managerInstance) } func test_getInstance_whenInstanceIsNotRegistered() { @@ -85,7 +85,7 @@ extension PopupStackTests { .grzegorzki ]) - let managerInstance = PopupStack.fetchInstance(id: .bronowice) + let managerInstance = PopupStack.fetch(id: .bronowice) XCTAssertNil(managerInstance) } func test_getInstance_whenInstanceIsRegistered() { @@ -95,7 +95,7 @@ extension PopupStackTests { .grzegorzki ]) - let managerInstance = PopupStack.fetchInstance(id: .grzegorzki) + let managerInstance = PopupStack.fetch(id: .grzegorzki) XCTAssertNotNil(managerInstance) } } @@ -262,7 +262,7 @@ private extension PopupStackTests { } func getPopupsForActiveInstance() -> [AnyPopup] { PopupStack - .fetchInstance(id: defaultPopupManagerID)? + .fetch(id: defaultPopupManagerID)? .popups ?? [] } } From 5221c74338f7e2e44a92849f683454763246619a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 18:18:11 +0100 Subject: [PATCH 289/407] 1 --- Sources/Internal/Containers/PopupStack.swift | 12 ++++++------ Sources/Public/Setup/Popup+Setup+PopupStackID.swift | 2 +- Tests/Tests+PopupID.swift | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/Internal/Containers/PopupStack.swift b/Sources/Internal/Containers/PopupStack.swift index 8d7cb6b18b..d35e626c26 100644 --- a/Sources/Internal/Containers/PopupStack.swift +++ b/Sources/Internal/Containers/PopupStack.swift @@ -103,17 +103,17 @@ private extension PopupStack { // MARK: Fetch extension PopupStack { - nonisolated static func fetchInstance(id: PopupStackID) async -> PopupStack? { - let stackInstance = await PopupStackContainer.stacks.first(where: { $0.id == id }) - await logNoInstanceErrorIfNeeded(stack: stackInstance, popupStackID: id) - return stackInstance + nonisolated static func fetch(id: PopupStackID) async -> PopupStack? { + let stack = await PopupStackContainer.stacks.first(where: { $0.id == id }) + await logNoStackRegisteredErrorIfNeeded(stack: stack, id: id) + return stack } } private extension PopupStack { - nonisolated static func logNoInstanceErrorIfNeeded(stack: PopupStack?, popupStackID: PopupStackID) async { if stack == nil { + nonisolated static func logNoStackRegisteredErrorIfNeeded(stack: PopupStack?, id: PopupStackID) async { if stack == nil { Logger.log( level: .fault, - message: "PopupStack (\(popupStackID.rawValue)) must be registered before use. More details can be found in the documentation." + message: "PopupStack (\(id.rawValue)) must be registered before use. More details can be found in the documentation." ) }} } diff --git a/Sources/Public/Setup/Popup+Setup+PopupStackID.swift b/Sources/Public/Setup/Popup+Setup+PopupStackID.swift index 4b89b828f8..ff83003774 100644 --- a/Sources/Public/Setup/Popup+Setup+PopupStackID.swift +++ b/Sources/Public/Setup/Popup+Setup+PopupStackID.swift @@ -40,7 +40,7 @@ public struct PopupStackID: Equatable, Sendable { public init(rawValue: String) { self.rawValue = rawValue } } -// MARK: Default Instance +// MARK: Default ID public extension PopupStackID { static let shared: Self = .init(rawValue: "shared") } diff --git a/Tests/Tests+PopupID.swift b/Tests/Tests+PopupID.swift index 46574b3970..aa7eb12afc 100644 --- a/Tests/Tests+PopupID.swift +++ b/Tests/Tests+PopupID.swift @@ -85,23 +85,23 @@ extension PopupIDTests { } } -// MARK: Is Same Instance +// MARK: Is Same extension PopupIDTests { - func test_isSameInstance_1() { + func test_isSame_1() { let popupID = PopupID.create(from: TestTopPopup.self), popup = AnyPopup(TestCentrePopup()) let result = popupID.isSame(as: popup) XCTAssertEqual(result, false) } - func test_isSameInstance_2() { + func test_isSame_2() { let popupID = PopupID.create(from: TestTopPopup.self), popup = AnyPopup(TestTopPopup()) let result = popupID.isSame(as: popup) XCTAssertEqual(result, true) } - func test_isSameInstance_3() async { + func test_isSame_3() async { let popupID = PopupID.create(from: TestTopPopup.self) await Task.sleep(seconds: 1) let popup = AnyPopup(TestTopPopup()) From d063e26e25e9c69e84cb9d4037973567f0031f7e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 18:23:10 +0100 Subject: [PATCH 290/407] 1 --- .../Dismiss/Public+Dismiss+PopupStack.swift | 26 +++++++++---------- .../Public/Dismiss/Public+Dismiss+View.swift | 26 +++++++++---------- .../Public/Present/Public+Present+Popup.swift | 26 +++++++++---------- .../Setup/Popup+Setup+PopupStackID.swift | 2 +- Sources/Public/Setup/Public+Setup+View.swift | 2 +- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift b/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift index c6eff1167d..c66cc691fb 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift @@ -17,42 +17,42 @@ public extension PopupStack { Makes the next popup in the stack the new active popup. - Parameters: - - popupManagerID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupManagerID:)``. + - popupStackID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupStackID:)``. - - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. + - Important: Make sure you use the correct **popupStackID** from which you want to remove the popup. */ - @MainActor static func dismissLastPopup(popupManagerID: PopupStackID = .shared) async { await fetch(id: popupManagerID)?.modify(.removeLastPopup) } + @MainActor static func dismissLastPopup(popupStackID: PopupStackID = .shared) async { await fetch(id: popupStackID)?.modify(.removeLastPopup) } /** Removes all popups with the specified identifier from the stack. - Parameters: - id: Identifier of the popup located on the stack. - - popupManagerID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupManagerID:)``. + - popupStackID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupStackID:)``. - - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. + - Important: Make sure you use the correct **popupStackID** from which you want to remove the popup. */ - @MainActor static func dismissPopup(_ id: String, popupManagerID: PopupStackID = .shared) async { await fetch(id: popupManagerID)?.modify(.removeAllPopupsWithID(id)) } + @MainActor static func dismissPopup(_ id: String, popupStackID: PopupStackID = .shared) async { await fetch(id: popupStackID)?.modify(.removeAllPopupsWithID(id)) } /** Removes all popups of the provided type from the stack. - Parameters: - type: Type of the popup located on the stack. - - popupManagerID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupManagerID:)``. + - popupStackID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupStackID:)``. - - Important: If a custom ID (``Popup/setCustomID(_:)``) is set for the popup, use the ``dismissPopup(_:popupManagerID:)-1atvy`` method instead. - - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. + - Important: If a custom ID (``Popup/setCustomID(_:)``) is set for the popup, use the ``dismissPopup(_:popupStackID:)-1atvy`` method instead. + - Important: Make sure you use the correct **popupStackID** from which you want to remove the popup. */ - @MainActor static func dismissPopup(_ type: P.Type, popupManagerID: PopupStackID = .shared) async { await fetch(id: popupManagerID)?.modify(.removeAllPopupsOfType(type)) } + @MainActor static func dismissPopup(_ type: P.Type, popupStackID: PopupStackID = .shared) async { await fetch(id: popupStackID)?.modify(.removeAllPopupsOfType(type)) } /** Removes all popups from the stack. - Parameters: - - popupManagerID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupManagerID:)``. + - popupStackID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupStackID:)``. - - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popups. + - Important: Make sure you use the correct **popupStackID** from which you want to remove the popups. */ - @MainActor static func dismissAllPopups(popupManagerID: PopupStackID = .shared) async { await fetch(id: popupManagerID)?.modify(.removeAllPopups) } + @MainActor static func dismissAllPopups(popupStackID: PopupStackID = .shared) async { await fetch(id: popupStackID)?.modify(.removeAllPopups) } } diff --git a/Sources/Public/Dismiss/Public+Dismiss+View.swift b/Sources/Public/Dismiss/Public+Dismiss+View.swift index 34b702d1f9..0922b6561e 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+View.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+View.swift @@ -17,42 +17,42 @@ public extension View { Makes the next popup in the stack the new active popup. - Parameters: - - popupManagerID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupManagerID:)``. + - popupStackID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupStackID:)``. - - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. + - Important: Make sure you use the correct **popupStackID** from which you want to remove the popup. */ - @MainActor func dismissLastPopup(popupManagerID: PopupStackID = .shared) async { await PopupStack.dismissLastPopup(popupManagerID: popupManagerID) } + @MainActor func dismissLastPopup(popupStackID: PopupStackID = .shared) async { await PopupStack.dismissLastPopup(popupStackID: popupStackID) } /** Removes all popups with the specified identifier from the stack. - Parameters: - id: Identifier of the popup located on the stack. - - popupManagerID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupManagerID:)``. + - popupStackID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupStackID:)``. - - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. + - Important: Make sure you use the correct **popupStackID** from which you want to remove the popup. */ - @MainActor func dismissPopup(_ id: String, popupManagerID: PopupStackID = .shared) async { await PopupStack.dismissPopup(id, popupManagerID: popupManagerID) } + @MainActor func dismissPopup(_ id: String, popupStackID: PopupStackID = .shared) async { await PopupStack.dismissPopup(id, popupStackID: popupStackID) } /** Removes all popups of the provided type from the stack. - Parameters: - type: Type of the popup located on the stack. - - popupManagerID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupManagerID:)``. + - popupStackID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupStackID:)``. - - Important: If a custom ID (see ``Popup/setCustomID(_:)`` method for reference) is set for the popup, use the ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-55ubm`` method instead. - - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popup. + - Important: If a custom ID (see ``Popup/setCustomID(_:)`` method for reference) is set for the popup, use the ``SwiftUICore/View/dismissPopup(_:popupStackID:)-55ubm`` method instead. + - Important: Make sure you use the correct **popupStackID** from which you want to remove the popup. */ - @MainActor func dismissPopup(_ type: P.Type, popupManagerID: PopupStackID = .shared) async { await PopupStack.dismissPopup(type, popupManagerID: popupManagerID) } + @MainActor func dismissPopup(_ type: P.Type, popupStackID: PopupStackID = .shared) async { await PopupStack.dismissPopup(type, popupStackID: popupStackID) } /** Removes all popups from the stack. - Parameters: - - popupManagerID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupManagerID:)``. + - popupStackID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupStackID:)``. - - Important: Make sure you use the correct **popupManagerID** from which you want to remove the popups. + - Important: Make sure you use the correct **popupStackID** from which you want to remove the popups. */ - @MainActor func dismissAllPopups(popupManagerID: PopupStackID = .shared) async { await PopupStack.dismissAllPopups(popupManagerID: popupManagerID) } + @MainActor func dismissAllPopups(popupStackID: PopupStackID = .shared) async { await PopupStack.dismissAllPopups(popupStackID: popupStackID) } } diff --git a/Sources/Public/Present/Public+Present+Popup.swift b/Sources/Public/Present/Public+Present+Popup.swift index df9cebed55..5904e3b0e6 100644 --- a/Sources/Public/Present/Public+Present+Popup.swift +++ b/Sources/Public/Present/Public+Present+Popup.swift @@ -16,23 +16,23 @@ public extension Popup { Presents the popup. - Parameters: - - popupManagerID: The identifier registered in one of the application windows in which the popup is to be displayed. + - popupStackID: The identifier registered in one of the application windows in which the popup is to be displayed. - - Important: The **popupManagerID** must be registered prior to use. For more information see ``SwiftUICore/View/registerPopups(id:configBuilder:)``. + - Important: The **popupStackID** must be registered prior to use. For more information see ``SwiftUICore/View/registerPopups(id:configBuilder:)``. - Important: The methods - ``PopupStack/dismissLastPopup(popupManagerID:)``, - ``PopupStack/dismissPopup(_:popupManagerID:)-1atvy``, - ``PopupStack/dismissPopup(_:popupManagerID:)-6l2c2``, - ``PopupStack/dismissAllPopups(popupManagerID:)``, - ``SwiftUICore/View/dismissLastPopup(popupManagerID:)``, - ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-55ubm``, - ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-9mkd5``, - ``SwiftUICore/View/dismissAllPopups(popupManagerID:)`` - should be called with the same **popupManagerID** as the one used here. + ``PopupStack/dismissLastPopup(popupStackID:)``, + ``PopupStack/dismissPopup(_:popupStackID:)-1atvy``, + ``PopupStack/dismissPopup(_:popupStackID:)-6l2c2``, + ``PopupStack/dismissAllPopups(popupStackID:)``, + ``SwiftUICore/View/dismissLastPopup(popupStackID:)``, + ``SwiftUICore/View/dismissPopup(_:popupStackID:)-55ubm``, + ``SwiftUICore/View/dismissPopup(_:popupStackID:)-9mkd5``, + ``SwiftUICore/View/dismissAllPopups(popupStackID:)`` + should be called with the same **popupStackID** as the one used here. - Warning: To present multiple popups of the same type, set a unique identifier using the method ``Popup/setCustomID(_:)``. */ - @MainActor func present(popupManagerID: PopupStackID = .shared) async { await PopupStack.fetch(id: popupManagerID)?.modify(.insertPopup(.init(self))) } + @MainActor func present(popupStackID: PopupStackID = .shared) async { await PopupStack.fetch(id: popupStackID)?.modify(.insertPopup(.init(self))) } } // MARK: Configure Popup @@ -40,7 +40,7 @@ public extension Popup { /** Sets the custom ID for the selected popup. - - important: To dismiss a popup with a custom ID set, use methods ``PopupStack/dismissPopup(_:popupManagerID:)-1atvy`` or ``SwiftUICore/View/dismissPopup(_:popupManagerID:)-55ubm`` + - important: To dismiss a popup with a custom ID set, use methods ``PopupStack/dismissPopup(_:popupStackID:)-1atvy`` or ``SwiftUICore/View/dismissPopup(_:popupStackID:)-55ubm`` - tip: Useful if you want to display several different popups of the same type. */ @MainActor func setCustomID(_ id: String) async -> some Popup { await AnyPopup(self).updatedID(id) } diff --git a/Sources/Public/Setup/Popup+Setup+PopupStackID.swift b/Sources/Public/Setup/Popup+Setup+PopupStackID.swift index ff83003774..886f6dcc5f 100644 --- a/Sources/Public/Setup/Popup+Setup+PopupStackID.swift +++ b/Sources/Public/Setup/Popup+Setup+PopupStackID.swift @@ -31,7 +31,7 @@ } ``` - - important: Use methods like ``SwiftUICore/View/dismissLastPopup(popupManagerID:)`` or ``Popup/present(popupManagerID:)`` only with a registered PopupStackID. + - important: Use methods like ``SwiftUICore/View/dismissLastPopup(popupStackID:)`` or ``Popup/present(popupStackID:)`` only with a registered PopupStackID. - tip: The main use case where you might need to register a different PopupStackID is when your application has multiple windows - for example, on macOS, iPad or visionOS. */ public struct PopupStackID: Equatable, Sendable { diff --git a/Sources/Public/Setup/Public+Setup+View.swift b/Sources/Public/Setup/Public+Setup+View.swift index eb0baff243..2e2493d954 100644 --- a/Sources/Public/Setup/Public+Setup+View.swift +++ b/Sources/Public/Setup/Public+Setup+View.swift @@ -16,7 +16,7 @@ public extension View { Registers the framework to work in your application. - Parameters: - - id: It is possible to register multiple managers (for different windows); especially useful in a macOS or iPad implementation. Read more in ``PopupStackID``. + - id: It is possible to register multiple stacks (for different windows); especially useful in a macOS or iPad implementation. Read more in ``PopupStackID``. - configBuilder: Default configuration for all popups. Use the ``Popup/configurePopup(config:)-98ha0`` method to change the configuration for a specific popup. See the list of available methods in ``GlobalConfig``. From 736713904908489efe15a4d59393ac266f57108b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 19:14:24 +0100 Subject: [PATCH 291/407] 1 --- Sources/Internal/Containers/PopupStack.swift | 4 ++-- Sources/Internal/Extensions/Animation++.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/Containers/PopupStack.swift b/Sources/Internal/Containers/PopupStack.swift index d35e626c26..fbbdaff64a 100644 --- a/Sources/Internal/Containers/PopupStack.swift +++ b/Sources/Internal/Containers/PopupStack.swift @@ -32,7 +32,7 @@ extension PopupStack { -// MARK: Stack Operations +// MARK: Modify extension PopupStack { enum StackOperation { case insertPopup(AnyPopup) case removeLastPopup, removePopup(AnyPopup), removeAllPopupsOfType(any Popup.Type), removeAllPopupsWithID(String), removeAllPopups @@ -97,7 +97,7 @@ private extension PopupStack { -// MARK: - INSTACE OPERATIONS +// MARK: - STACK CONTAINER OPERATIONS diff --git a/Sources/Internal/Extensions/Animation++.swift b/Sources/Internal/Extensions/Animation++.swift index 1b524229c4..053d7796fd 100644 --- a/Sources/Internal/Extensions/Animation++.swift +++ b/Sources/Internal/Extensions/Animation++.swift @@ -15,5 +15,5 @@ extension Animation { static var transition: Animation { .spring(duration: Animation.duration, bounce: 0, blendDuration: 0) } } extension Animation { - static var duration: CGFloat { 0.27 } + static var duration: CGFloat { 0.28 } } From f6f178b251e94d83c9da6ed6b7e152b3cd6cc3ab Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 19:19:04 +0100 Subject: [PATCH 292/407] 1 --- .../{GlobalConfig+Centre.swift => GlobalConfig+Center.swift} | 4 ++-- Sources/Internal/Containers/GlobalConfigContainer.swift | 2 +- Sources/Public/Setup/Public+Setup+Config.swift | 2 +- Sources/Public/Setup/Public+Setup+ConfigContainer.swift | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename Sources/Internal/Configurables/Global/{GlobalConfig+Centre.swift => GlobalConfig+Center.swift} (89%) diff --git a/Sources/Internal/Configurables/Global/GlobalConfig+Centre.swift b/Sources/Internal/Configurables/Global/GlobalConfig+Center.swift similarity index 89% rename from Sources/Internal/Configurables/Global/GlobalConfig+Centre.swift rename to Sources/Internal/Configurables/Global/GlobalConfig+Center.swift index 24929fba87..2062dbc9f9 100644 --- a/Sources/Internal/Configurables/Global/GlobalConfig+Centre.swift +++ b/Sources/Internal/Configurables/Global/GlobalConfig+Center.swift @@ -1,5 +1,5 @@ // -// GlobalConfig+Centre.swift of MijickPopups +// GlobalConfig+Center.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com @@ -11,7 +11,7 @@ import SwiftUI -public final class GlobalConfigCentre: GlobalConfig { required public init() {} +public final class GlobalConfigCenter: GlobalConfig { required public init() {} // MARK: Active Variables public var popupPadding: EdgeInsets = .init(top: 0, leading: 16, bottom: 0, trailing: 16) public var cornerRadius: CGFloat = 24 diff --git a/Sources/Internal/Containers/GlobalConfigContainer.swift b/Sources/Internal/Containers/GlobalConfigContainer.swift index 66674c065e..b8a742cb10 100644 --- a/Sources/Internal/Containers/GlobalConfigContainer.swift +++ b/Sources/Internal/Containers/GlobalConfigContainer.swift @@ -10,6 +10,6 @@ public actor GlobalConfigContainer { - static var center: GlobalConfigCentre = .init() + static var center: GlobalConfigCenter = .init() static var vertical: GlobalConfigVertical = .init() } diff --git a/Sources/Public/Setup/Public+Setup+Config.swift b/Sources/Public/Setup/Public+Setup+Config.swift index e9ddcfc602..7b00e0547b 100644 --- a/Sources/Public/Setup/Public+Setup+Config.swift +++ b/Sources/Public/Setup/Public+Setup+Config.swift @@ -12,7 +12,7 @@ import SwiftUI // MARK: Centre -public extension GlobalConfigCentre { +public extension GlobalConfigCenter { /** Distance of the entire popup (including its background) from the horizontal edges of the screen. diff --git a/Sources/Public/Setup/Public+Setup+ConfigContainer.swift b/Sources/Public/Setup/Public+Setup+ConfigContainer.swift index a3eb14a5cb..36ccfdefe3 100644 --- a/Sources/Public/Setup/Public+Setup+ConfigContainer.swift +++ b/Sources/Public/Setup/Public+Setup+ConfigContainer.swift @@ -15,7 +15,7 @@ public extension GlobalConfigContainer { Use the ``Popup/configurePopup(config:)-98ha0`` method to change the configuration for a specific popup. See the list of available methods in ``GlobalConfig``. */ - nonisolated func centre(_ builder: (GlobalConfigCentre) -> GlobalConfigCentre) -> Self { Self.center = builder(.init()); return self } + nonisolated func centre(_ builder: (GlobalConfigCenter) -> GlobalConfigCenter) -> Self { Self.center = builder(.init()); return self } /** Default configuration for all top and bottom popups. From 2b97fc07ecd3523f8871825ad4b77a70e1ceb89f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 19:28:06 +0100 Subject: [PATCH 293/407] 1 --- .../Local/LocalConfig+Centre.swift | 17 ----------------- Tests/Tests+ViewModel+PopupCentreStack.swift | 10 ++++++---- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift index cfbe34a0a7..ee9fb2121a 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift @@ -34,20 +34,3 @@ public class LocalConfigCentre: LocalConfig { required public init() {} - important: If a certain method is not called here, the popup inherits the configuration from ``GlobalConfigContainer``. */ public typealias CentrePopupConfig = LocalConfigCentre - - - -// MARK: - TESTS -#if DEBUG - - - -extension LocalConfigCentre { - static func t_createNew(popupPadding: EdgeInsets, cornerRadius: CGFloat) -> LocalConfigCentre { - let config = LocalConfigCentre() - config.popupPadding = popupPadding - config.cornerRadius = cornerRadius - return config - } -} -#endif diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index a880c309b1..ca32901bdb 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -248,10 +248,12 @@ private extension PopupCentreStackViewModelTests { } } private extension PopupCentreStackViewModelTests { - func getConfigForPopupHeightTests(cornerRadius: CGFloat, popupPadding: EdgeInsets) -> CentrePopupConfig { .t_createNew( - popupPadding: popupPadding, - cornerRadius: cornerRadius - )} + func getConfigForPopupHeightTests(cornerRadius: CGFloat, popupPadding: EdgeInsets) -> CentrePopupConfig { + var config = CentrePopupConfig() + config.cornerRadius = cornerRadius + config.popupPadding = popupPadding + return config + } func updatePopups(_ viewModel: ViewModel) async { for popup in viewModel.popups { await viewModel.recalculateAndUpdatePopupHeight(popup.height!, popup) } } From 7381ce05fc19e40ee81f443787b7616e7355735a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 19:35:17 +0100 Subject: [PATCH 294/407] 1 --- Sources/Internal/Models/AnyPopup.swift | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/Sources/Internal/Models/AnyPopup.swift b/Sources/Internal/Models/AnyPopup.swift index 747fa5f2bf..e21246854b 100644 --- a/Sources/Internal/Models/AnyPopup.swift +++ b/Sources/Internal/Models/AnyPopup.swift @@ -88,18 +88,3 @@ extension AnyPopup: Hashable { nonisolated static func ==(lhs: AnyPopup, rhs: AnyPopup) -> Bool { lhs.id.isSame(as: rhs) } nonisolated func hash(into hasher: inout Hasher) { hasher.combine(id.rawValue) } } - - - -// MARK: - TESTS -#if DEBUG - - - -// MARK: New Object -extension AnyPopup { - static func t_createNew(id: String = UUID().uuidString, config: LocalConfig) async -> AnyPopup { await .init( - id: .init(id), config: .init(config), height: nil, dragHeight: 0, _dismissTimer: nil, _body: .init(EmptyView()), _onFocus: {}, _onDismiss: {} - )} -} -#endif From 1e18d9c9a61d1dd550bd98041ac993c1adbb5d36 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 19:39:37 +0100 Subject: [PATCH 295/407] 1 --- .../Local/LocalConfig+Centre.swift | 9 ---- .../Local/LocalConfig+Vertical.swift | 14 ------- .../Popup/Public+Popup+AvailableTypes.swift | 41 +++++++++++++++++++ 3 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 Sources/Public/Popup/Public+Popup+AvailableTypes.swift diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift index ee9fb2121a..788af70e25 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift @@ -25,12 +25,3 @@ public class LocalConfigCentre: LocalConfig { required public init() {} public var dragDetents: [DragDetent] = GlobalConfigContainer.center.dragDetents public var isDragGestureEnabled: Bool = GlobalConfigContainer.center.isDragGestureEnabled } - -// 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 = LocalConfigCentre diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift index 25110e95e7..ba023b4d96 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift @@ -32,21 +32,7 @@ public extension LocalConfigVertical { class Bottom: LocalConfigVertical {} } -/** - 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 = LocalConfigVertical.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 = LocalConfigVertical.Bottom diff --git a/Sources/Public/Popup/Public+Popup+AvailableTypes.swift b/Sources/Public/Popup/Public+Popup+AvailableTypes.swift new file mode 100644 index 0000000000..5c27a404e9 --- /dev/null +++ b/Sources/Public/Popup/Public+Popup+AvailableTypes.swift @@ -0,0 +1,41 @@ +// +// Public+Popup+AvailableTypes.swift of MijickPopups +// +// Created by Tomasz Kurylik. Sending ❤️ from Kraków! +// - Mail: tomasz.kurylik@mijick.com +// - GitHub: https://github.com/FulcrumOne +// - Medium: https://medium.com/@mijick +// +// Copyright ©2024 Mijick. All rights reserved. + + +// MARK: 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 TopPopupConfig = LocalConfigVertical.Top + + + +// MARK: Center +/** + 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 = LocalConfigCentre + + + +// MARK: Bottom +/** + 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 = LocalConfigVertical.Bottom From 581ca7f78d80c2d6c7b7e3447e0785568004bb9a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 19:42:19 +0100 Subject: [PATCH 296/407] 1 --- .../{LocalConfig+Centre.swift => LocalConfig+Center.swift} | 4 ++-- Sources/Internal/UI/PopupView.swift | 2 +- Sources/Internal/Utilities/PopupAlignment.swift | 2 +- Sources/Public/Popup/Public+Popup+AvailableTypes.swift | 2 +- Sources/Public/Popup/Public+Popup+Config.swift | 4 ++-- Sources/Public/Popup/Public+Popup+Main.swift | 4 ++-- Tests/Tests+ViewModel+PopupCentreStack.swift | 6 +++--- 7 files changed, 12 insertions(+), 12 deletions(-) rename Sources/Internal/Configurables/Local/{LocalConfig+Centre.swift => LocalConfig+Center.swift} (91%) diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift b/Sources/Internal/Configurables/Local/LocalConfig+Center.swift similarity index 91% rename from Sources/Internal/Configurables/Local/LocalConfig+Centre.swift rename to Sources/Internal/Configurables/Local/LocalConfig+Center.swift index 788af70e25..74875801b2 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Centre.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Center.swift @@ -1,5 +1,5 @@ // -// LocalConfig+Centre.swift of MijickPopups +// LocalConfig+Center.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com @@ -11,7 +11,7 @@ import SwiftUI -public class LocalConfigCentre: LocalConfig { required public init() {} +public class LocalConfigCenter: LocalConfig { required public init() {} // MARK: Active Variables public var popupPadding: EdgeInsets = GlobalConfigContainer.center.popupPadding public var cornerRadius: CGFloat = GlobalConfigContainer.center.cornerRadius diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 1ab5ca544b..c6536524ed 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -18,7 +18,7 @@ struct PopupView: View { @ObservedObject var stack: PopupStack private let topStackViewModel: VM.VerticalStack = .init(TopPopupConfig.self) - private let centreStackViewModel: VM.CentreStack = .init(CentrePopupConfig.self) + private let centreStackViewModel: VM.CentreStack = .init(CenterPopupConfig.self) private let bottomStackViewModel: VM.VerticalStack = .init(BottomPopupConfig.self) diff --git a/Sources/Internal/Utilities/PopupAlignment.swift b/Sources/Internal/Utilities/PopupAlignment.swift index e00e65e89a..4047536dbc 100644 --- a/Sources/Internal/Utilities/PopupAlignment.swift +++ b/Sources/Internal/Utilities/PopupAlignment.swift @@ -21,7 +21,7 @@ enum PopupAlignment { extension PopupAlignment { init(_ config: LocalConfig.Type) { switch config.self { case is TopPopupConfig.Type: self = .top - case is CentrePopupConfig.Type: self = .center + case is CenterPopupConfig.Type: self = .center case is BottomPopupConfig.Type: self = .bottom default: fatalError() }} diff --git a/Sources/Public/Popup/Public+Popup+AvailableTypes.swift b/Sources/Public/Popup/Public+Popup+AvailableTypes.swift index 5c27a404e9..be2c178b86 100644 --- a/Sources/Public/Popup/Public+Popup+AvailableTypes.swift +++ b/Sources/Public/Popup/Public+Popup+AvailableTypes.swift @@ -27,7 +27,7 @@ public typealias TopPopupConfig = LocalConfigVertical.Top - important: If a certain method is not called here, the popup inherits the configuration from ``GlobalConfigContainer``. */ -public typealias CentrePopupConfig = LocalConfigCentre +public typealias CenterPopupConfig = LocalConfigCenter diff --git a/Sources/Public/Popup/Public+Popup+Config.swift b/Sources/Public/Popup/Public+Popup+Config.swift index 9cf9df520a..203ed96733 100644 --- a/Sources/Public/Popup/Public+Popup+Config.swift +++ b/Sources/Public/Popup/Public+Popup+Config.swift @@ -11,8 +11,8 @@ import SwiftUI -// MARK: Centre -public extension LocalConfigCentre { +// MARK: Center +public extension LocalConfigCenter { /** Distance of the entire popup (including its background) from the horizontal edges of the screen. diff --git a/Sources/Public/Popup/Public+Popup+Main.swift b/Sources/Public/Popup/Public+Popup+Main.swift index 09ad5241b5..a171343d4a 100644 --- a/Sources/Public/Popup/Public+Popup+Main.swift +++ b/Sources/Public/Popup/Public+Popup+Main.swift @@ -88,7 +88,7 @@ public protocol TopPopup: Popup { associatedtype Config = TopPopupConfig } struct CentrePopupExample: CentrePopup { func onFocus() { print("Popup is now active") } func onDismiss() { print("Popup was dismissed") } - func configurePopup(config: CentrePopupConfig) -> CentrePopupConfig { config + func configurePopup(config: CenterPopupConfig) -> CenterPopupConfig { config .cornerRadius(44) .tapOutsideToDismissPopup(true) } @@ -99,7 +99,7 @@ public protocol TopPopup: Popup { associatedtype Config = TopPopupConfig } ``` ![CentrePopup](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/centre-popup.png?raw=true) */ -public protocol CentrePopup: Popup { associatedtype Config = CentrePopupConfig } +public protocol CentrePopup: Popup { associatedtype Config = CenterPopupConfig } /** The view to be displayed as a Bottom popup. diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index ca32901bdb..3f4524d894 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -14,7 +14,7 @@ import SwiftUI @testable import MijickPopups @MainActor final class PopupCentreStackViewModelTests: XCTestCase { - @ObservedObject private var viewModel: ViewModel = .init(CentrePopupConfig.self) + @ObservedObject private var viewModel: ViewModel = .init(CenterPopupConfig.self) override func setUp() async throws { viewModel.updateScreenValue(screen) @@ -248,8 +248,8 @@ private extension PopupCentreStackViewModelTests { } } private extension PopupCentreStackViewModelTests { - func getConfigForPopupHeightTests(cornerRadius: CGFloat, popupPadding: EdgeInsets) -> CentrePopupConfig { - var config = CentrePopupConfig() + func getConfigForPopupHeightTests(cornerRadius: CGFloat, popupPadding: EdgeInsets) -> CenterPopupConfig { + var config = CenterPopupConfig() config.cornerRadius = cornerRadius config.popupPadding = popupPadding return config From edff2ab62fcbfe8a2704d91d5bb05c6aa01cf3f9 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 19:45:03 +0100 Subject: [PATCH 297/407] 1 --- .../Local/LocalConfig+Vertical.swift | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift index ba023b4d96..d315a42cdf 100644 --- a/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift +++ b/Sources/Internal/Configurables/Local/LocalConfig+Vertical.swift @@ -26,31 +26,8 @@ public class LocalConfigVertical: LocalConfig { required public init() {} public var isDragGestureEnabled: Bool = GlobalConfigContainer.vertical.isDragGestureEnabled } -// MARK: Subclasses & Typealiases +// MARK: Subclasses public extension LocalConfigVertical { class Top: LocalConfigVertical {} class Bottom: LocalConfigVertical {} } - - - - - -// MARK: - TESTS -#if DEBUG - - - -extension LocalConfigVertical { - static func t_createNew(popupPadding: EdgeInsets, cornerRadius: CGFloat, ignoredSafeAreaEdges: Edge.Set, heightMode: HeightMode, dragDetents: [DragDetent], isDragGestureEnabled: Bool) -> C { - let config = C() - config.popupPadding = popupPadding - config.cornerRadius = cornerRadius - config.ignoredSafeAreaEdges = ignoredSafeAreaEdges - config.heightMode = heightMode - config.dragDetents = dragDetents - config.isDragGestureEnabled = isDragGestureEnabled - return config - } -} -#endif From 2ba3ee511c72a4ee45ec26e4c36e39ca98932070 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 19:46:22 +0100 Subject: [PATCH 298/407] 1 --- ...Setup+PopupStackID.swift => Public+Setup+PopupStackID.swift} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Sources/Public/Setup/{Popup+Setup+PopupStackID.swift => Public+Setup+PopupStackID.swift} (96%) diff --git a/Sources/Public/Setup/Popup+Setup+PopupStackID.swift b/Sources/Public/Setup/Public+Setup+PopupStackID.swift similarity index 96% rename from Sources/Public/Setup/Popup+Setup+PopupStackID.swift rename to Sources/Public/Setup/Public+Setup+PopupStackID.swift index 886f6dcc5f..91baf03f57 100644 --- a/Sources/Public/Setup/Popup+Setup+PopupStackID.swift +++ b/Sources/Public/Setup/Public+Setup+PopupStackID.swift @@ -1,5 +1,5 @@ // -// Popup+Setup+PopupStackID.swift of MijickPopups +// Public+Setup+PopupStackID.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com From 3aeebbdcc0e5b5fd8cb8ee63f39b61c7bf9b8d6c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 19:49:23 +0100 Subject: [PATCH 299/407] 1 --- ...treStackView.swift => PopupCenterStackView.swift} | 12 ++++++------ Sources/Internal/UI/PopupView.swift | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) rename Sources/Internal/UI/{PopupCentreStackView.swift => PopupCenterStackView.swift} (86%) diff --git a/Sources/Internal/UI/PopupCentreStackView.swift b/Sources/Internal/UI/PopupCenterStackView.swift similarity index 86% rename from Sources/Internal/UI/PopupCentreStackView.swift rename to Sources/Internal/UI/PopupCenterStackView.swift index 4a3b9a3fc7..2a10c14381 100644 --- a/Sources/Internal/UI/PopupCentreStackView.swift +++ b/Sources/Internal/UI/PopupCenterStackView.swift @@ -1,5 +1,5 @@ // -// PopupCentreStackView.swift of MijickPopups +// PopupCenterStackView.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com @@ -11,7 +11,7 @@ import SwiftUI -struct PopupCentreStackView: View { +struct PopupCenterStackView: View { @ObservedObject var viewModel: VM.CentreStack @@ -22,12 +22,12 @@ struct PopupCentreStackView: View { .frame(maxWidth: .infinity, maxHeight: viewModel.screen.height) } } -private extension PopupCentreStackView { +private extension PopupCenterStackView { func createPopupStack() -> some View { ForEach(viewModel.popups, id: \.self, content: createPopup) } } -private extension PopupCentreStackView { +private extension PopupCenterStackView { func createPopup(_ popup: AnyPopup) -> some View { popup.body .fixedSize(horizontal: false, vertical: viewModel.activePopupProperties.verticalFixedSize) @@ -42,9 +42,9 @@ private extension PopupCentreStackView { } } -private extension PopupCentreStackView { +private extension PopupCenterStackView { func getBackgroundColor(for popup: AnyPopup) -> Color { popup.config.backgroundColor } } -private extension PopupCentreStackView { +private extension PopupCenterStackView { var transition: AnyTransition { .scale(scale: 1.1).combined(with: .opacity) } } diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index c6536524ed..91d7d4589a 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -67,7 +67,7 @@ private extension PopupView { PopupVerticalStackView(viewModel: topStackViewModel).zIndex(stack.priority.top) } func createCentrePopupStackView() -> some View { - PopupCentreStackView(viewModel: centreStackViewModel).zIndex(stack.priority.center) + PopupCenterStackView(viewModel: centreStackViewModel).zIndex(stack.priority.center) } func createBottomPopupStackView() -> some View { PopupVerticalStackView(viewModel: bottomStackViewModel).zIndex(stack.priority.bottom) From 259e850fe67fdc56e3ce73326ff031d274237aad Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 19:53:12 +0100 Subject: [PATCH 300/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 62b39ad1af..4ec54997c6 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -36,7 +36,7 @@ protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == Obs -// MARK: - INIT & SETUP +// MARK: - INITIALIZE & SETUP @@ -55,7 +55,7 @@ extension ViewModel { -// MARK: MARK: UPDATE +// MARK: UPDATE From f149ca66a6bb8381580c530e3bdbaf5dc4a78986 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 19:54:39 +0100 Subject: [PATCH 301/407] 1 --- .../Internal/UI/PopupCenterStackView.swift | 2 +- Sources/Internal/UI/PopupView.swift | 2 +- .../View Models/ViewModel+CentreStack.swift | 24 +++++++++---------- Tests/Tests+ViewModel+PopupCentreStack.swift | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Sources/Internal/UI/PopupCenterStackView.swift b/Sources/Internal/UI/PopupCenterStackView.swift index 2a10c14381..711be27820 100644 --- a/Sources/Internal/UI/PopupCenterStackView.swift +++ b/Sources/Internal/UI/PopupCenterStackView.swift @@ -12,7 +12,7 @@ import SwiftUI struct PopupCenterStackView: View { - @ObservedObject var viewModel: VM.CentreStack + @ObservedObject var viewModel: VM.CenterStack var body: some View { diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 91d7d4589a..c5cb01de8e 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -18,7 +18,7 @@ struct PopupView: View { @ObservedObject var stack: PopupStack private let topStackViewModel: VM.VerticalStack = .init(TopPopupConfig.self) - private let centreStackViewModel: VM.CentreStack = .init(CenterPopupConfig.self) + private let centreStackViewModel: VM.CenterStack = .init(CenterPopupConfig.self) private let bottomStackViewModel: VM.VerticalStack = .init(BottomPopupConfig.self) diff --git a/Sources/Internal/View Models/ViewModel+CentreStack.swift b/Sources/Internal/View Models/ViewModel+CentreStack.swift index 327c86cb56..db6847549c 100644 --- a/Sources/Internal/View Models/ViewModel+CentreStack.swift +++ b/Sources/Internal/View Models/ViewModel+CentreStack.swift @@ -1,5 +1,5 @@ // -// ViewModel+CentreStack.swift of MijickPopups +// ViewModel+CenterStack.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com @@ -11,7 +11,7 @@ import SwiftUI -extension VM { class CentreStack: ViewModel { required init() {} +extension VM { class CenterStack: ViewModel { required init() {} var alignment: PopupAlignment = .center var popups: [AnyPopup] = [] var activePopupProperties: ActivePopupProperties = .init() @@ -27,14 +27,14 @@ extension VM { class CentreStack: ViewModel { required init() {} // MARK: Height -extension VM.CentreStack { +extension VM.CenterStack { func calculateActivePopupHeight() async -> CGFloat? { popups.last?.height } } // MARK: Outer Padding -extension VM.CentreStack { +extension VM.CenterStack { func calculateActivePopupOuterPadding() async -> EdgeInsets { .init( top: calculateVerticalPopupPadding(for: .top), leading: calculateLeadingPopupPadding(), @@ -42,7 +42,7 @@ extension VM.CentreStack { trailing: calculateTrailingPopupPadding() )} } -private extension VM.CentreStack { +private extension VM.CenterStack { func calculateVerticalPopupPadding(for edge: PopupAlignment) -> CGFloat { guard let activePopupHeight = activePopupProperties.height, screen.isKeyboardActive && edge == .bottom else { return 0 } @@ -59,12 +59,12 @@ private extension VM.CentreStack { } // MARK: Inner Padding -extension VM.CentreStack { +extension VM.CenterStack { func calculateActivePopupInnerPadding() async -> EdgeInsets { .init() } } // MARK: Corners -extension VM.CentreStack { +extension VM.CenterStack { func calculateActivePopupCorners() async -> [PopupAlignment : CGFloat] { [ .top: popups.last?.config.cornerRadius ?? 0, .bottom: popups.last?.config.cornerRadius ?? 0 @@ -72,14 +72,14 @@ extension VM.CentreStack { } // MARK: Vertical Fixed Size -extension VM.CentreStack { +extension VM.CenterStack { func calculateActivePopupVerticalFixedSize() async -> Bool { activePopupProperties.height != calculateLargeScreenHeight() } } // MARK: Translation Progress -extension VM.CentreStack { +extension VM.CenterStack { func calculateActivePopupTranslationProgress() async -> CGFloat { 0 } } @@ -90,12 +90,12 @@ extension VM.CentreStack { // MARK: Height -extension VM.CentreStack { +extension VM.CenterStack { func calculatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async -> CGFloat { min(heightCandidate, calculateLargeScreenHeight()) } } -private extension VM.CentreStack { +private extension VM.CenterStack { func calculateLargeScreenHeight() -> CGFloat { let fullscreenHeight = screen.height, safeAreaHeight = screen.safeArea.top + screen.safeArea.bottom @@ -110,7 +110,7 @@ private extension VM.CentreStack { // MARK: Opacity -extension VM.CentreStack { +extension VM.CenterStack { func calculateOpacity(for popup: AnyPopup) -> CGFloat { popups.last == popup ? 1 : 0 } diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCentreStack.swift index 3f4524d894..8d83282cbc 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCentreStack.swift @@ -273,5 +273,5 @@ private extension PopupCentreStackViewModelTests { // MARK: Typealiases private extension PopupCentreStackViewModelTests { - typealias ViewModel = VM.CentreStack + typealias ViewModel = VM.CenterStack } From bd23a36ce0d1c8e2970897f00036cf349966017d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 19:57:47 +0100 Subject: [PATCH 302/407] 1 --- Sources/Internal/UI/PopupView.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index c5cb01de8e..16363acf71 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -18,7 +18,7 @@ struct PopupView: View { @ObservedObject var stack: PopupStack private let topStackViewModel: VM.VerticalStack = .init(TopPopupConfig.self) - private let centreStackViewModel: VM.CenterStack = .init(CenterPopupConfig.self) + private let centerStackViewModel: VM.CenterStack = .init(CenterPopupConfig.self) private let bottomStackViewModel: VM.VerticalStack = .init(BottomPopupConfig.self) @@ -51,7 +51,7 @@ private extension PopupView { ZStack { createOverlayView() createTopPopupStackView() - createCentrePopupStackView() + createCenterPopupStackView() createBottomPopupStackView() } } @@ -66,8 +66,8 @@ private extension PopupView { func createTopPopupStackView() -> some View { PopupVerticalStackView(viewModel: topStackViewModel).zIndex(stack.priority.top) } - func createCentrePopupStackView() -> some View { - PopupCenterStackView(viewModel: centreStackViewModel).zIndex(stack.priority.center) + func createCenterPopupStackView() -> some View { + PopupCenterStackView(viewModel: centerStackViewModel).zIndex(stack.priority.center) } func createBottomPopupStackView() -> some View { PopupVerticalStackView(viewModel: bottomStackViewModel).zIndex(stack.priority.bottom) @@ -115,7 +115,7 @@ private extension PopupView { await stack.modify(.removePopup(popup)) } func updateViewModels(_ updateBuilder: @escaping (any ViewModel) async -> ()) async { - for viewModel in [topStackViewModel, centreStackViewModel, bottomStackViewModel] { Task { @MainActor in await updateBuilder(viewModel as! any ViewModel) }} + for viewModel in [topStackViewModel, centerStackViewModel, bottomStackViewModel] { Task { @MainActor in await updateBuilder(viewModel as! any ViewModel) }} } } private extension PopupView { From 7e793455bf13cc2d502f25eefe0887aab6016f51 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 20:04:17 +0100 Subject: [PATCH 303/407] 1 --- Sources/Public/Popup/Public+Popup+Main.swift | 6 +++--- Sources/Public/Setup/Public+Setup+Config.swift | 2 +- Sources/Public/Setup/Public+Setup+ConfigContainer.swift | 4 ++-- Sources/Public/Setup/Public+Setup+SceneDelegate.swift | 2 +- Sources/Public/Setup/Public+Setup+View.swift | 2 +- Tests/Tests+PopupID.swift | 8 ++++---- Tests/Tests+PopupManager.swift | 6 +++--- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Sources/Public/Popup/Public+Popup+Main.swift b/Sources/Public/Popup/Public+Popup+Main.swift index a171343d4a..b17cc96668 100644 --- a/Sources/Public/Popup/Public+Popup+Main.swift +++ b/Sources/Public/Popup/Public+Popup+Main.swift @@ -85,7 +85,7 @@ public protocol TopPopup: Popup { associatedtype Config = TopPopupConfig } # Usage Example ```swift - struct CentrePopupExample: CentrePopup { + struct CenterPopupExample: CenterPopup { func onFocus() { print("Popup is now active") } func onDismiss() { print("Popup was dismissed") } func configurePopup(config: CenterPopupConfig) -> CenterPopupConfig { config @@ -97,9 +97,9 @@ public protocol TopPopup: Popup { associatedtype Config = TopPopupConfig } } } ``` - ![CentrePopup](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/centre-popup.png?raw=true) + ![CenterPopup](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/centre-popup.png?raw=true) */ -public protocol CentrePopup: Popup { associatedtype Config = CenterPopupConfig } +public protocol CenterPopup: Popup { associatedtype Config = CenterPopupConfig } /** The view to be displayed as a Bottom popup. diff --git a/Sources/Public/Setup/Public+Setup+Config.swift b/Sources/Public/Setup/Public+Setup+Config.swift index 7b00e0547b..3bb73fc2ac 100644 --- a/Sources/Public/Setup/Public+Setup+Config.swift +++ b/Sources/Public/Setup/Public+Setup+Config.swift @@ -11,7 +11,7 @@ import SwiftUI -// MARK: Centre +// MARK: Center public extension GlobalConfigCenter { /** Distance of the entire popup (including its background) from the horizontal edges of the screen. diff --git a/Sources/Public/Setup/Public+Setup+ConfigContainer.swift b/Sources/Public/Setup/Public+Setup+ConfigContainer.swift index 36ccfdefe3..a11773c152 100644 --- a/Sources/Public/Setup/Public+Setup+ConfigContainer.swift +++ b/Sources/Public/Setup/Public+Setup+ConfigContainer.swift @@ -11,11 +11,11 @@ public extension GlobalConfigContainer { /** - Default configuration for all centre popups. + Default configuration for all center popups. Use the ``Popup/configurePopup(config:)-98ha0`` method to change the configuration for a specific popup. See the list of available methods in ``GlobalConfig``. */ - nonisolated func centre(_ builder: (GlobalConfigCenter) -> GlobalConfigCenter) -> Self { Self.center = builder(.init()); return self } + nonisolated func center(_ builder: (GlobalConfigCenter) -> GlobalConfigCenter) -> Self { Self.center = builder(.init()); return self } /** Default configuration for all top and bottom popups. diff --git a/Sources/Public/Setup/Public+Setup+SceneDelegate.swift b/Sources/Public/Setup/Public+Setup+SceneDelegate.swift index 5879aaa764..3e1f8d094d 100644 --- a/Sources/Public/Setup/Public+Setup+SceneDelegate.swift +++ b/Sources/Public/Setup/Public+Setup+SceneDelegate.swift @@ -41,7 +41,7 @@ import SwiftUI .tapOutsideToDismissPopup(true) .cornerRadius(32) } - .centre { $0 + .center { $0 .tapOutsideToDismissPopup(false) .backgroundColor(.white) } diff --git a/Sources/Public/Setup/Public+Setup+View.swift b/Sources/Public/Setup/Public+Setup+View.swift index 2e2493d954..cf4cb1de9a 100644 --- a/Sources/Public/Setup/Public+Setup+View.swift +++ b/Sources/Public/Setup/Public+Setup+View.swift @@ -31,7 +31,7 @@ public extension View { .tapOutsideToDismissPopup(true) .cornerRadius(32) } - .centre { $0 + .center { $0 .tapOutsideToDismissPopup(false) .backgroundColor(.white) } diff --git a/Tests/Tests+PopupID.swift b/Tests/Tests+PopupID.swift index aa7eb12afc..77eefdafd1 100644 --- a/Tests/Tests+PopupID.swift +++ b/Tests/Tests+PopupID.swift @@ -36,11 +36,11 @@ extension PopupIDTests { func test_createPopupID_2() { let dateString = String(describing: Date()) - let popupID = PopupID.create(from: TestCentrePopup.self) + let popupID = PopupID.create(from: TestCenterPopup.self) let idComponents = popupID.rawValue.components(separatedBy: "/{}/") XCTAssertEqual(idComponents.count, 2) - XCTAssertEqual(idComponents[0], "TestCentrePopup") + XCTAssertEqual(idComponents[0], "TestCenterPopup") XCTAssertEqual(idComponents[1], dateString) } } @@ -89,7 +89,7 @@ extension PopupIDTests { extension PopupIDTests { func test_isSame_1() { let popupID = PopupID.create(from: TestTopPopup.self), - popup = AnyPopup(TestCentrePopup()) + popup = AnyPopup(TestCenterPopup()) let result = popupID.isSame(as: popup) XCTAssertEqual(result, false) @@ -121,7 +121,7 @@ extension PopupIDTests { private struct TestTopPopup: TopPopup { var body: some View { EmptyView() } } -private struct TestCentrePopup: CentrePopup { +private struct TestCenterPopup: CenterPopup { var body: some View { EmptyView() } } private struct TestBottomPopup: BottomPopup { diff --git a/Tests/Tests+PopupManager.swift b/Tests/Tests+PopupManager.swift index dd47ca70bd..9ccd4b196a 100644 --- a/Tests/Tests+PopupManager.swift +++ b/Tests/Tests+PopupManager.swift @@ -177,7 +177,7 @@ extension PopupStackTests { func test_dismissPopupWithType_whenPopupOnStack() { let popups: [AnyPopup] = [ .init(TestTopPopup()), - .init(TestCentrePopup()), + .init(TestCenterPopup()), .init(TestBottomPopup()) ] registerNewInstanceAndPresentPopups(popups: popups) @@ -200,7 +200,7 @@ extension PopupStackTests { let popupsOnStackBefore = getPopupsForActiveInstance() XCTAssertEqual(popups, popupsOnStackBefore) - PopupStack.dismissPopup(TestCentrePopup.self, popupManagerID: defaultPopupManagerID) + PopupStack.dismissPopup(TestCenterPopup.self, popupManagerID: defaultPopupManagerID) let popupsOnStackAfter = getPopupsForActiveInstance() XCTAssertEqual(popups, popupsOnStackAfter) @@ -286,7 +286,7 @@ private extension PopupStackID { private struct TestTopPopup: TopPopup { var body: some View { EmptyView() } } -private struct TestCentrePopup: CentrePopup { +private struct TestCenterPopup: CenterPopup { var body: some View { EmptyView() } } private struct TestBottomPopup: BottomPopup { From a43b45b27b56704a51118c404e790c8e6f0bd544 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 20:04:28 +0100 Subject: [PATCH 304/407] 1 --- Sources/Public/Popup/Public+Popup+Main.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Public/Popup/Public+Popup+Main.swift b/Sources/Public/Popup/Public+Popup+Main.swift index b17cc96668..5dfe022636 100644 --- a/Sources/Public/Popup/Public+Popup+Main.swift +++ b/Sources/Public/Popup/Public+Popup+Main.swift @@ -76,7 +76,7 @@ public extension Popup { public protocol TopPopup: Popup { associatedtype Config = TopPopupConfig } /** - The view to be displayed as a Centre popup. + The view to be displayed as a Center popup. # Optional Methods - ``Popup/configurePopup(config:)-3ze4`` From ad7d8808888fcd596767a49d1d5c59f9d190678b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 20:18:54 +0100 Subject: [PATCH 305/407] 1 --- Sources/Internal/UI/PopupView.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 16363acf71..9620b6d46f 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -74,11 +74,7 @@ private extension PopupView { } } private extension PopupView { - func getOverlayColor() -> Color { switch stack.popups.last?.config.overlayColor { - case .some(let color) where color == .clear: .black.opacity(0.0000000000001) - case .some(let color): color - case nil: .clear - }} + func getOverlayColor() -> Color { stack.popups.last?.config.overlayColor ?? .clear } } private extension PopupView { From 851f045cc4c6599d4e90bcaceb8e27205203217d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 20:20:37 +0100 Subject: [PATCH 306/407] 1 --- Sources/Internal/UI/PopupView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index 9620b6d46f..b09577dabb 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -110,8 +110,8 @@ private extension PopupView { nonisolated func closePopup(_ popup: AnyPopup) async { await stack.modify(.removePopup(popup)) } - func updateViewModels(_ updateBuilder: @escaping (any ViewModel) async -> ()) async { - for viewModel in [topStackViewModel, centerStackViewModel, bottomStackViewModel] { Task { @MainActor in await updateBuilder(viewModel as! any ViewModel) }} + func updateViewModels(_ updateBuilder: @MainActor @escaping (any ViewModel) async -> ()) async { + for viewModel in [topStackViewModel, centerStackViewModel, bottomStackViewModel] { await updateBuilder(viewModel as! any ViewModel) } } } private extension PopupView { From 94a64ea46d569911bd3dd43b339e156566685a21 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 20:22:25 +0100 Subject: [PATCH 307/407] 1 --- Sources/Internal/UI/PopupView.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index b09577dabb..a9b6760247 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -78,13 +78,13 @@ private extension PopupView { } private extension PopupView { - func onAppear() { Task { @MainActor in + func onAppear() { Task { await updateViewModels { $0.setup(updatePopupAction: updatePopup, closePopupAction: closePopup) } }} - func onScreenChange(_ screenReader: GeometryProxy) { Task { @MainActor in + func onScreenChange(_ screenReader: GeometryProxy) { Task { await updateViewModels { await $0.updateScreen(screenReader: screenReader) } }} - func onPopupsHeightChange(_ p: Any) { Task { @MainActor in + func onPopupsHeightChange(_ p: Any) { Task { await updateViewModels { await $0.updatePopups(stack.popups) } }} func onStackChange(_ oldStack: [AnyPopup], _ newStack: [AnyPopup]) { @@ -96,7 +96,7 @@ private extension PopupView { }} newStack.last?.onFocus() } - func onKeyboardStateChange(_ isKeyboardActive: Bool) { Task { @MainActor in + func onKeyboardStateChange(_ isKeyboardActive: Bool) { Task { await updateViewModels { await $0.updateScreen(isKeyboardActive: isKeyboardActive) } }} func onTap() { if tapOutsideClosesPopup { From 8af6c8bb4c675fbf12a5113692e688bac8603a71 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 21:01:57 +0100 Subject: [PATCH 308/407] 1 --- Sources/Public/Setup/Public+Setup+PopupStackID.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Public/Setup/Public+Setup+PopupStackID.swift b/Sources/Public/Setup/Public+Setup+PopupStackID.swift index 91baf03f57..ce41ba8758 100644 --- a/Sources/Public/Setup/Public+Setup+PopupStackID.swift +++ b/Sources/Public/Setup/Public+Setup+PopupStackID.swift @@ -12,7 +12,7 @@ /** A set of identifiers to be registered. - # Usage Example + ## Usage ```swift @main struct App_Main: App { var body: some Scene { From f996829a6042b731ae60db876d645b82869ae66b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 21:03:46 +0100 Subject: [PATCH 309/407] 1 --- Sources/Public/Setup/Public+Setup+SceneDelegate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Public/Setup/Public+Setup+SceneDelegate.swift b/Sources/Public/Setup/Public+Setup+SceneDelegate.swift index 3e1f8d094d..3e391b15f7 100644 --- a/Sources/Public/Setup/Public+Setup+SceneDelegate.swift +++ b/Sources/Public/Setup/Public+Setup+SceneDelegate.swift @@ -17,7 +17,7 @@ import SwiftUI - tip: Recommended initialization way when using the framework with standard Apple sheets. - ## Usage Example + ## Usage ```swift @main struct App_Main: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate From 4b9028ee27ca81fca3e201b94879ec48c57c646b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 21:06:05 +0100 Subject: [PATCH 310/407] 1 --- Sources/Public/Setup/Public+Setup+View.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Public/Setup/Public+Setup+View.swift b/Sources/Public/Setup/Public+Setup+View.swift index cf4cb1de9a..676d277a4d 100644 --- a/Sources/Public/Setup/Public+Setup+View.swift +++ b/Sources/Public/Setup/Public+Setup+View.swift @@ -20,7 +20,7 @@ public extension View { - configBuilder: Default configuration for all popups. Use the ``Popup/configurePopup(config:)-98ha0`` method to change the configuration for a specific popup. See the list of available methods in ``GlobalConfig``. - ## Usage Example + ## Usage ```swift @main struct App_Main: App { var body: some Scene { WindowGroup { From 6b00bafb3e734cda827b6541361ce28469d33eee Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 21:11:04 +0100 Subject: [PATCH 311/407] 1 --- Sources/Public/Popup/Public+Popup+Main.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Public/Popup/Public+Popup+Main.swift b/Sources/Public/Popup/Public+Popup+Main.swift index 5dfe022636..2db8cfda4e 100644 --- a/Sources/Public/Popup/Public+Popup+Main.swift +++ b/Sources/Public/Popup/Public+Popup+Main.swift @@ -12,8 +12,8 @@ import SwiftUI /** - The view to be displayed as a popup. It may appear in one of three positions (see **Usage Examples** section). - # Optional Methods + The view to be displayed as a popup. It may appear in one of three positions (see **Usage** section). + ## Optional Methods - ``configurePopup(config:)-3ze4`` - ``onFocus()-6krqs`` - ``onDismiss()-254h8`` @@ -23,7 +23,7 @@ public protocol Popup: View { /** Configures the popup. - See the list of available methods in ``LocalConfig`` and ``LocalConfig/Vertical``. + See the list of available methods in ``LocalConfigCenter`` and ``LocalConfigVertical``. - important: If a certain method is not called here, the popup inherits the configuration from ``GlobalConfigContainer``. */ From 31bb69cef52e8c8124b8fa0a48559ba939e40b52 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 21:23:35 +0100 Subject: [PATCH 312/407] 1 --- Sources/Public/Popup/Public+Popup+Main.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/Public/Popup/Public+Popup+Main.swift b/Sources/Public/Popup/Public+Popup+Main.swift index 2db8cfda4e..ddde83f366 100644 --- a/Sources/Public/Popup/Public+Popup+Main.swift +++ b/Sources/Public/Popup/Public+Popup+Main.swift @@ -56,7 +56,7 @@ public extension Popup { - ``Popup/onFocus()-6krqs`` - ``Popup/onDismiss()-3bufs`` - # Usage Example + ## Usage ```swift struct TopPopupExample: TopPopup { func onFocus() { print("Popup is now active") } @@ -74,6 +74,7 @@ public extension Popup { ![TopPopup](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/top-popup.png?raw=true) */ public protocol TopPopup: Popup { associatedtype Config = TopPopupConfig } +public typealias TopPopupConfig = LocalConfigVertical.Top /** The view to be displayed as a Center popup. @@ -83,7 +84,7 @@ public protocol TopPopup: Popup { associatedtype Config = TopPopupConfig } - ``Popup/onFocus()-loq5`` - ``Popup/onDismiss()-3bufs`` - # Usage Example + ## Usage ```swift struct CenterPopupExample: CenterPopup { func onFocus() { print("Popup is now active") } @@ -100,6 +101,7 @@ public protocol TopPopup: Popup { associatedtype Config = TopPopupConfig } ![CenterPopup](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/centre-popup.png?raw=true) */ public protocol CenterPopup: Popup { associatedtype Config = CenterPopupConfig } +public typealias CenterPopupConfig = LocalConfigCenter /** The view to be displayed as a Bottom popup. @@ -109,7 +111,7 @@ public protocol CenterPopup: Popup { associatedtype Config = CenterPopupConfig } - ``Popup/onFocus()-loq5`` - ``Popup/onDismiss()-254h8`` - # Usage Example + ## Usage ```swift struct BottomPopupExample: BottomPopup { func onFocus() { print("Popup is now active") } @@ -127,3 +129,4 @@ public protocol CenterPopup: Popup { associatedtype Config = CenterPopupConfig } ![BottomPopup](https://github.com/Mijick/Assets/blob/main/Framework%20Docs/Popups/bottom-popup.png?raw=true) */ public protocol BottomPopup: Popup { associatedtype Config = BottomPopupConfig } +public typealias BottomPopupConfig = LocalConfigVertical.Bottom From 2ec50e9549d6fa06f4514aba1dcaa88cec748484 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 21:24:06 +0100 Subject: [PATCH 313/407] 1 --- .../Popup/Public+Popup+AvailableTypes.swift | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 Sources/Public/Popup/Public+Popup+AvailableTypes.swift diff --git a/Sources/Public/Popup/Public+Popup+AvailableTypes.swift b/Sources/Public/Popup/Public+Popup+AvailableTypes.swift deleted file mode 100644 index be2c178b86..0000000000 --- a/Sources/Public/Popup/Public+Popup+AvailableTypes.swift +++ /dev/null @@ -1,41 +0,0 @@ -// -// Public+Popup+AvailableTypes.swift of MijickPopups -// -// Created by Tomasz Kurylik. Sending ❤️ from Kraków! -// - Mail: tomasz.kurylik@mijick.com -// - GitHub: https://github.com/FulcrumOne -// - Medium: https://medium.com/@mijick -// -// Copyright ©2024 Mijick. All rights reserved. - - -// MARK: 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 TopPopupConfig = LocalConfigVertical.Top - - - -// MARK: Center -/** - 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 CenterPopupConfig = LocalConfigCenter - - - -// MARK: Bottom -/** - 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 = LocalConfigVertical.Bottom From a00c34f70479d9f7393b4b3fe1ccd93303cab892 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 21:27:48 +0100 Subject: [PATCH 314/407] 1 --- Sources/Public/Popup/Public+Popup+Main.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Public/Popup/Public+Popup+Main.swift b/Sources/Public/Popup/Public+Popup+Main.swift index ddde83f366..a0aff7a9db 100644 --- a/Sources/Public/Popup/Public+Popup+Main.swift +++ b/Sources/Public/Popup/Public+Popup+Main.swift @@ -51,7 +51,7 @@ public extension Popup { /** The view to be displayed as a Top popup. - # Optional Methods + ## Optional Methods - ``Popup/configurePopup(config:)-98ha0`` - ``Popup/onFocus()-6krqs`` - ``Popup/onDismiss()-3bufs`` @@ -79,7 +79,7 @@ public typealias TopPopupConfig = LocalConfigVertical.Top /** The view to be displayed as a Center popup. - # Optional Methods + ## Optional Methods - ``Popup/configurePopup(config:)-3ze4`` - ``Popup/onFocus()-loq5`` - ``Popup/onDismiss()-3bufs`` From 36ad749b6d5fce558fac55d499bbe425d9324bdc Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:00:18 +0100 Subject: [PATCH 315/407] 1 --- Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift b/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift index c66cc691fb..b89ed73c33 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+PopupStack.swift @@ -13,8 +13,7 @@ import Foundation public extension PopupStack { /** - Removes the currently active popup from the stack. - Makes the next popup in the stack the new active popup. + Dismisses the currently active popup. - Parameters: - popupStackID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupStackID:)``. @@ -24,7 +23,7 @@ public extension PopupStack { @MainActor static func dismissLastPopup(popupStackID: PopupStackID = .shared) async { await fetch(id: popupStackID)?.modify(.removeLastPopup) } /** - Removes all popups with the specified identifier from the stack. + Dismisses all popups with the specified identifier. - Parameters: - id: Identifier of the popup located on the stack. @@ -35,7 +34,7 @@ public extension PopupStack { @MainActor static func dismissPopup(_ id: String, popupStackID: PopupStackID = .shared) async { await fetch(id: popupStackID)?.modify(.removeAllPopupsWithID(id)) } /** - Removes all popups of the provided type from the stack. + Dismisses all popups of the provided type. - Parameters: - type: Type of the popup located on the stack. @@ -47,7 +46,7 @@ public extension PopupStack { @MainActor static func dismissPopup(_ type: P.Type, popupStackID: PopupStackID = .shared) async { await fetch(id: popupStackID)?.modify(.removeAllPopupsOfType(type)) } /** - Removes all popups from the stack. + Dismisses all the popups. - Parameters: - popupStackID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupStackID:)``. From 93c37dd87b434bfa52572d2c9c889c68b90c012e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:02:25 +0100 Subject: [PATCH 316/407] 1 --- Sources/Public/Dismiss/Public+Dismiss+View.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sources/Public/Dismiss/Public+Dismiss+View.swift b/Sources/Public/Dismiss/Public+Dismiss+View.swift index 0922b6561e..da812635bd 100644 --- a/Sources/Public/Dismiss/Public+Dismiss+View.swift +++ b/Sources/Public/Dismiss/Public+Dismiss+View.swift @@ -13,8 +13,7 @@ import SwiftUI public extension View { /** - Removes the currently active popup from the stack. - Makes the next popup in the stack the new active popup. + Dismisses the currently active popup. - Parameters: - popupStackID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupStackID:)``. @@ -24,7 +23,7 @@ public extension View { @MainActor func dismissLastPopup(popupStackID: PopupStackID = .shared) async { await PopupStack.dismissLastPopup(popupStackID: popupStackID) } /** - Removes all popups with the specified identifier from the stack. + Dismisses all popups with the specified identifier. - Parameters: - id: Identifier of the popup located on the stack. @@ -35,7 +34,7 @@ public extension View { @MainActor func dismissPopup(_ id: String, popupStackID: PopupStackID = .shared) async { await PopupStack.dismissPopup(id, popupStackID: popupStackID) } /** - Removes all popups of the provided type from the stack. + Dismisses all popups of the provided type. - Parameters: - type: Type of the popup located on the stack. @@ -47,7 +46,7 @@ public extension View { @MainActor func dismissPopup(_ type: P.Type, popupStackID: PopupStackID = .shared) async { await PopupStack.dismissPopup(type, popupStackID: popupStackID) } /** - Removes all popups from the stack. + Dismisses all the popups. - Parameters: - popupStackID: The identifier for which the popup was presented. For more information, see ``Popup/present(popupStackID:)``. From b2af4d508571198cabc8166d3fe0d802f2c2dd29 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:26:02 +0100 Subject: [PATCH 317/407] 1 --- Tests/Tests+PopupID.swift | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Tests/Tests+PopupID.swift b/Tests/Tests+PopupID.swift index 77eefdafd1..c7f0ff4c45 100644 --- a/Tests/Tests+PopupID.swift +++ b/Tests/Tests+PopupID.swift @@ -23,20 +23,20 @@ import SwiftUI // MARK: Create ID extension PopupIDTests { - func test_createPopupID_1() { + func test_createPopupID_1() async { let dateString = String(describing: Date()) - let popupID = PopupID.create(from: TestTopPopup.self) + let popupID = await PopupID(TestTopPopup.self) let idComponents = popupID.rawValue.components(separatedBy: "/{}/") XCTAssertEqual(idComponents.count, 2) XCTAssertEqual(idComponents[0], "TestTopPopup") XCTAssertEqual(idComponents[1], dateString) } - func test_createPopupID_2() { + func test_createPopupID_2() async { let dateString = String(describing: Date()) - let popupID = PopupID.create(from: TestCenterPopup.self) + let popupID = await PopupID(TestCenterPopup.self) let idComponents = popupID.rawValue.components(separatedBy: "/{}/") XCTAssertEqual(idComponents.count, 2) @@ -47,38 +47,38 @@ extension PopupIDTests { // MARK: Is Same Type extension PopupIDTests { - func test_isSameType_1() { - let popupID1 = PopupID.create(from: TestTopPopup.self), - popupID2 = PopupID.create(from: TestBottomPopup.self) + func test_isSameType_1() async { + let popupID1 = await PopupID(TestTopPopup.self), + popupID2 = await PopupID(TestBottomPopup.self) let result = popupID1.isSameType(as: popupID2) XCTAssertEqual(result, false) } - func test_isSameType_2() { - let popupID1 = PopupID.create(from: TestTopPopup.self), + func test_isSameType_2() async { + let popupID1 = await PopupID(TestTopPopup.self), popupID2 = "TestTopPopup" let result = popupID1.isSameType(as: popupID2) XCTAssertEqual(result, true) } - func test_isSameType_3() { - let popupID1 = PopupID.create(from: "2137"), + func test_isSameType_3() async { + let popupID1 = await PopupID("2137"), popupID2 = "2137" let result = popupID1.isSameType(as: popupID2) XCTAssertEqual(result, true) } - func test_isSameType_4() { - let popupID1 = AnyPopup(TestTopPopup().setCustomID("2137")).id, - popupID2 = AnyPopup(TestTopPopup()).id + func test_isSameType_4() async { + let popupID1 = await AnyPopup(TestTopPopup().setCustomID("2137")).id, + popupID2 = await AnyPopup(TestTopPopup()).id let result = popupID1.isSameType(as: popupID2) XCTAssertEqual(result, false) } func test_isSameType_5() async { - let popupID1 = PopupID.create(from: TestTopPopup.self) + let popupID1 = await PopupID(TestTopPopup.self) await Task.sleep(seconds: 1) - let popupID2 = PopupID.create(from: TestTopPopup.self) + let popupID2 = await PopupID(TestTopPopup.self) let result = popupID1.isSameType(as: popupID2) XCTAssertEqual(result, true) @@ -87,9 +87,9 @@ extension PopupIDTests { // MARK: Is Same extension PopupIDTests { - func test_isSame_1() { - let popupID = PopupID.create(from: TestTopPopup.self), - popup = AnyPopup(TestCenterPopup()) + func test_isSame_1() async { + let popupID = await PopupID(TestTopPopup.self), + popup = await AnyPopup(TestCenterPopup()) let result = popupID.isSame(as: popup) XCTAssertEqual(result, false) From f74633f6de38a349b14ee9b99c32ca2c984eb582 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:27:08 +0100 Subject: [PATCH 318/407] 1 --- Tests/Tests+PopupID.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Tests/Tests+PopupID.swift b/Tests/Tests+PopupID.swift index c7f0ff4c45..d64348becd 100644 --- a/Tests/Tests+PopupID.swift +++ b/Tests/Tests+PopupID.swift @@ -69,13 +69,20 @@ extension PopupIDTests { XCTAssertEqual(result, true) } func test_isSameType_4() async { + let popupID1 = await AnyPopup(TestTopPopup().setCustomID("2137")).id, + popupID2 = "2137" + + let result = popupID1.isSameType(as: popupID2) + XCTAssertEqual(result, true) + } + func test_isSameType_5() async { let popupID1 = await AnyPopup(TestTopPopup().setCustomID("2137")).id, popupID2 = await AnyPopup(TestTopPopup()).id let result = popupID1.isSameType(as: popupID2) XCTAssertEqual(result, false) } - func test_isSameType_5() async { + func test_isSameType_6() async { let popupID1 = await PopupID(TestTopPopup.self) await Task.sleep(seconds: 1) let popupID2 = await PopupID(TestTopPopup.self) From 40f309009d45aef5d2dc87d8d0817e7a2d8906a2 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:27:55 +0100 Subject: [PATCH 319/407] 1 --- Tests/Tests+PopupID.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Tests+PopupID.swift b/Tests/Tests+PopupID.swift index d64348becd..c30460e79f 100644 --- a/Tests/Tests+PopupID.swift +++ b/Tests/Tests+PopupID.swift @@ -101,17 +101,17 @@ extension PopupIDTests { let result = popupID.isSame(as: popup) XCTAssertEqual(result, false) } - func test_isSame_2() { - let popupID = PopupID.create(from: TestTopPopup.self), - popup = AnyPopup(TestTopPopup()) + func test_isSame_2() async { + let popupID = await PopupID(TestTopPopup.self), + popup = await AnyPopup(TestTopPopup()) let result = popupID.isSame(as: popup) XCTAssertEqual(result, true) } func test_isSame_3() async { - let popupID = PopupID.create(from: TestTopPopup.self) + let popupID = await PopupID(TestTopPopup.self) await Task.sleep(seconds: 1) - let popup = AnyPopup(TestTopPopup()) + let popup = await AnyPopup(TestTopPopup()) let result = popupID.isSame(as: popup) XCTAssertEqual(result, false) From 6ca6acb6c067be081baf7436c1e11d489ec771ad Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:34:39 +0100 Subject: [PATCH 320/407] 1 --- Tests/{Tests+PopupManager.swift => Tests+PopupStack.swift} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Tests/{Tests+PopupManager.swift => Tests+PopupStack.swift} (100%) diff --git a/Tests/Tests+PopupManager.swift b/Tests/Tests+PopupStack.swift similarity index 100% rename from Tests/Tests+PopupManager.swift rename to Tests/Tests+PopupStack.swift From 788c986a6c50128b998450f6a4deec3ddf6a0d90 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:35:59 +0100 Subject: [PATCH 321/407] 1 --- Tests/Tests+PopupStack.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 9ccd4b196a..63b420ee12 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -260,8 +260,8 @@ private extension PopupStackTests { registerNewInstances(popupManagerIds: [defaultPopupManagerID]) popups.forEach { $0.present(popupManagerID: defaultPopupManagerID) } } - func getPopupsForActiveInstance() -> [AnyPopup] { - PopupStack + func getPopupsForActiveInstance() async -> [AnyPopup] { + await PopupStack .fetch(id: defaultPopupManagerID)? .popups ?? [] } From a55872349c5dc94e27a7068f87920161dc999791 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:37:36 +0100 Subject: [PATCH 322/407] 1 --- Tests/Tests+PopupStack.swift | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 63b420ee12..4486bf769b 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -25,13 +25,13 @@ import SwiftUI -// MARK: Register New Instance +// MARK: Register extension PopupStackTests { - func test_registerNewInstance_withNoInstancesToRegister() { - let popupManagerIds: [PopupStackID] = [] + func test_register_withNoStacksToRegister() { + let popupStacksIDs: [PopupStackID] = [] - registerNewInstances(popupManagerIds: popupManagerIds) - XCTAssertEqual(popupManagerIds, getRegisteredInstances()) + register(stackIDs: popupStacksIDs) + XCTAssertEqual(popupStacksIDs, getRegisteredInstances()) } func test_registerNewInstance_withUniqueInstancesToRegister() { let popupManagerIds: [PopupStackID] = [ @@ -41,7 +41,7 @@ extension PopupStackTests { .bronowice ] - registerNewInstances(popupManagerIds: popupManagerIds) + register(stackIDs: popupManagerIds) XCTAssertEqual(popupManagerIds, getRegisteredInstances()) } func test_registerNewInstance_withRepeatingInstancesToRegister() { @@ -56,28 +56,28 @@ extension PopupStackTests { .krowodrza ] - registerNewInstances(popupManagerIds: popupManagerIds) + register(stackIDs: popupManagerIds) XCTAssertNotEqual(popupManagerIds, getRegisteredInstances()) XCTAssertEqual(getRegisteredInstances().count, 6) } } private extension PopupStackTests { - func registerNewInstances(popupManagerIds: [PopupStackID]) { - popupManagerIds.forEach { _ = PopupStack.registerStack(id: $0) } + func register(stackIDs: [PopupStackID]) { + stackIDs.forEach { _ = PopupStack.registerStack(id: $0) } } func getRegisteredInstances() -> [PopupStackID] { PopupStackContainer.stacks.map(\.id) } } -// MARK: Get Instance +// MARK: Fetch extension PopupStackTests { func test_getInstance_whenNoInstancesAreRegistered() { let managerInstance = PopupStack.fetch(id: .bronowice) XCTAssertNil(managerInstance) } func test_getInstance_whenInstanceIsNotRegistered() { - registerNewInstances(popupManagerIds: [ + register(stackIDs: [ .krowodrza, .staremiasto, .pradnikczerwony, @@ -89,7 +89,7 @@ extension PopupStackTests { XCTAssertNil(managerInstance) } func test_getInstance_whenInstanceIsRegistered() { - registerNewInstances(popupManagerIds: [ + register(stackIDs: [ .krowodrza, .staremiasto, .grzegorzki @@ -257,7 +257,7 @@ extension PopupStackTests { // MARK: Methods private extension PopupStackTests { func registerNewInstanceAndPresentPopups(popups: [any Popup]) { - registerNewInstances(popupManagerIds: [defaultPopupManagerID]) + register(stackIDs: [defaultPopupManagerID]) popups.forEach { $0.present(popupManagerID: defaultPopupManagerID) } } func getPopupsForActiveInstance() async -> [AnyPopup] { From e09444d0ffffa969ba235cac3fe16b3ea71ea5bb Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:38:58 +0100 Subject: [PATCH 323/407] 1 --- Tests/Tests+PopupStack.swift | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 4486bf769b..99d15a1e9e 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -31,21 +31,21 @@ extension PopupStackTests { let popupStacksIDs: [PopupStackID] = [] register(stackIDs: popupStacksIDs) - XCTAssertEqual(popupStacksIDs, getRegisteredInstances()) + XCTAssertEqual(popupStacksIDs, getRegisteredStacks()) } - func test_registerNewInstance_withUniqueInstancesToRegister() { - let popupManagerIds: [PopupStackID] = [ + func test_register_withUniqueStacksToRegister() { + let popupStacksIDs: [PopupStackID] = [ .staremiasto, .grzegorzki, .krowodrza, .bronowice ] - register(stackIDs: popupManagerIds) - XCTAssertEqual(popupManagerIds, getRegisteredInstances()) + register(stackIDs: popupStacksIDs) + XCTAssertEqual(popupStacksIDs, getRegisteredStacks()) } - func test_registerNewInstance_withRepeatingInstancesToRegister() { - let popupManagerIds: [PopupStackID] = [ + func test_register_withRepeatingStacksToRegister() { + let popupStacksIDs: [PopupStackID] = [ .staremiasto, .grzegorzki, .krowodrza, @@ -56,16 +56,16 @@ extension PopupStackTests { .krowodrza ] - register(stackIDs: popupManagerIds) - XCTAssertNotEqual(popupManagerIds, getRegisteredInstances()) - XCTAssertEqual(getRegisteredInstances().count, 6) + register(stackIDs: popupStacksIDs) + XCTAssertNotEqual(popupStacksIDs, getRegisteredStacks()) + XCTAssertEqual(getRegisteredStacks().count, 6) } } private extension PopupStackTests { func register(stackIDs: [PopupStackID]) { stackIDs.forEach { _ = PopupStack.registerStack(id: $0) } } - func getRegisteredInstances() -> [PopupStackID] { + func getRegisteredStacks() -> [PopupStackID] { PopupStackContainer.stacks.map(\.id) } } From 09319ae30cc0f44849aba91796ab7987ba28862c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:41:00 +0100 Subject: [PATCH 324/407] 1 --- Tests/Tests+PopupStack.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 99d15a1e9e..b8c0b80df7 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -27,13 +27,13 @@ import SwiftUI // MARK: Register extension PopupStackTests { - func test_register_withNoStacksToRegister() { + func test_registerStack_withNoStacksToRegister() { let popupStacksIDs: [PopupStackID] = [] register(stackIDs: popupStacksIDs) XCTAssertEqual(popupStacksIDs, getRegisteredStacks()) } - func test_register_withUniqueStacksToRegister() { + func test_registerStack_withUniqueStacksToRegister() { let popupStacksIDs: [PopupStackID] = [ .staremiasto, .grzegorzki, @@ -44,7 +44,7 @@ extension PopupStackTests { register(stackIDs: popupStacksIDs) XCTAssertEqual(popupStacksIDs, getRegisteredStacks()) } - func test_register_withRepeatingStacksToRegister() { + func test_registerStack_withRepeatingStacksToRegister() { let popupStacksIDs: [PopupStackID] = [ .staremiasto, .grzegorzki, @@ -72,11 +72,11 @@ private extension PopupStackTests { // MARK: Fetch extension PopupStackTests { - func test_getInstance_whenNoInstancesAreRegistered() { - let managerInstance = PopupStack.fetch(id: .bronowice) - XCTAssertNil(managerInstance) + func test_fetchStack_whenNoStacksAreRegistered() async { + let stack = await PopupStack.fetch(id: .bronowice) + XCTAssertNil(stack) } - func test_getInstance_whenInstanceIsNotRegistered() { + func test_fetchStack_whenStackIsNotRegistered() async { register(stackIDs: [ .krowodrza, .staremiasto, @@ -85,8 +85,8 @@ extension PopupStackTests { .grzegorzki ]) - let managerInstance = PopupStack.fetch(id: .bronowice) - XCTAssertNil(managerInstance) + let stack = await PopupStack.fetch(id: .bronowice) + XCTAssertNil(stack) } func test_getInstance_whenInstanceIsRegistered() { register(stackIDs: [ From 6a4ad63855f9a380ceb6c98cc0884fe70a7113ed Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:41:48 +0100 Subject: [PATCH 325/407] 1 --- Tests/Tests+PopupStack.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index b8c0b80df7..40585970e5 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -88,15 +88,15 @@ extension PopupStackTests { let stack = await PopupStack.fetch(id: .bronowice) XCTAssertNil(stack) } - func test_getInstance_whenInstanceIsRegistered() { + func test_fetchStack_whenStackIsRegistered() async { register(stackIDs: [ .krowodrza, .staremiasto, .grzegorzki ]) - let managerInstance = PopupStack.fetch(id: .grzegorzki) - XCTAssertNotNil(managerInstance) + let stack = await PopupStack.fetch(id: .grzegorzki) + XCTAssertNotNil(stack) } } From 73075e528382182886047cf34c4107bd02f74f89 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:44:39 +0100 Subject: [PATCH 326/407] 1 --- Tests/Tests+PopupStack.swift | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 40585970e5..cbd41a829d 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -102,24 +102,24 @@ extension PopupStackTests { // MARK: Present Popup extension PopupStackTests { - func test_presentPopup_withThreePopupsToBePresented() { + func test_presentPopup_withThreePopupsToBePresented() async { registerNewInstanceAndPresentPopups(popups: [ - AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), - AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), - AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()) + await AnyPopup(TestBottomPopup1()), + await AnyPopup(TestBottomPopup2()), + await AnyPopup(TestBottomPopup3()) ]) - let popupsOnStack = getPopupsForActiveInstance() + let popupsOnStack = await getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack.count, 3) } - func test_presentPopup_withPopupsWithSameID() { + func test_presentPopup_withPopupsWithSameID() async { registerNewInstanceAndPresentPopups(popups: [ - AnyPopup.t_createNew(id: "2137", config: LocalConfigVertical.Bottom()), - AnyPopup.t_createNew(id: "2137", config: LocalConfigVertical.Bottom()), - AnyPopup.t_createNew(id: "2331", config: LocalConfigVertical.Bottom()) + await AnyPopup(TestBottomPopup1()), + await AnyPopup(TestBottomPopup1()), + await AnyPopup(TestBottomPopup1()), ]) - let popupsOnStack = getPopupsForActiveInstance() + let popupsOnStack = await getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack.count, 2) } func test_presentPopup_withCustomID() { From f772271376c95666281aa23337d02c33d992e8cc Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:45:49 +0100 Subject: [PATCH 327/407] 1 --- Tests/Tests+PopupStack.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index cbd41a829d..eb398663d7 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -122,14 +122,14 @@ extension PopupStackTests { let popupsOnStack = await getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack.count, 2) } - func test_presentPopup_withCustomID() { + func test_presentPopup_withCustomID() async { registerNewInstanceAndPresentPopups(popups: [ - AnyPopup.t_createNew(id: "2137", config: LocalConfigVertical.Bottom()).setCustomID("1"), - AnyPopup.t_createNew(id: "2137", config: LocalConfigVertical.Bottom()), - AnyPopup.t_createNew(id: "2137", config: LocalConfigVertical.Bottom()).setCustomID("3") + await AnyPopup(TestBottomPopup1()), + await AnyPopup(TestBottomPopup1().setCustomID("2137")), + await AnyPopup(TestBottomPopup1().setCustomID("I Pan Paweł oczywiście")), ]) - let popupsOnStack = getPopupsForActiveInstance() + let popupsOnStack = await getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack.count, 3) } func test_presentPopup_withDismissAfter() async { From 3fe6393ed810715014f8de8c699c797d84af91e8 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:46:55 +0100 Subject: [PATCH 328/407] 1 --- Tests/Tests+PopupStack.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index eb398663d7..5ebb8971d3 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -134,22 +134,22 @@ extension PopupStackTests { } func test_presentPopup_withDismissAfter() async { registerNewInstanceAndPresentPopups(popups: [ - AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()).dismissAfter(0.7), - AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), - AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()).dismissAfter(1.5) + await AnyPopup(TestBottomPopup1()), + await AnyPopup(TestBottomPopup1()).dismissAfter(0.7), + await AnyPopup(TestBottomPopup1()).dismissAfter(1.5), ]) - let popupsOnStack1 = getPopupsForActiveInstance() + let popupsOnStack1 = await getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack1.count, 3) await Task.sleep(seconds: 1) - let popupsOnStack2 = getPopupsForActiveInstance() + let popupsOnStack2 = await getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack2.count, 2) await Task.sleep(seconds: 1) - let popupsOnStack3 = getPopupsForActiveInstance() + let popupsOnStack3 = await getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack3.count, 1) } } From 33e943cc115356583832fb9933fb15cac059485b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:47:46 +0100 Subject: [PATCH 329/407] 1 --- Tests/Tests+PopupStack.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 5ebb8971d3..73efb44b53 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -158,7 +158,7 @@ extension PopupStackTests { extension PopupStackTests { func test_dismissLastPopup_withNoPopupsOnStack() { registerNewInstanceAndPresentPopups(popups: []) - PopupStack.dismissLastPopup(popupManagerID: defaultPopupManagerID) + PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) let popupsOnStack = getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack.count, 0) @@ -257,19 +257,19 @@ extension PopupStackTests { // MARK: Methods private extension PopupStackTests { func registerNewInstanceAndPresentPopups(popups: [any Popup]) { - register(stackIDs: [defaultPopupManagerID]) + register(stackIDs: [defaultPopupStackID]) popups.forEach { $0.present(popupManagerID: defaultPopupManagerID) } } func getPopupsForActiveInstance() async -> [AnyPopup] { await PopupStack - .fetch(id: defaultPopupManagerID)? + .fetch(id: defaultPopupStackID)? .popups ?? [] } } // MARK: Variables private extension PopupStackTests { - var defaultPopupManagerID: PopupStackID { .staremiasto } + var defaultPopupStackID: PopupStackID { .staremiasto } } // MARK: Popup Manager Identifiers From bf97e7e9f058e51294cbc633e132a31b3fc4bf42 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:48:24 +0100 Subject: [PATCH 330/407] 1 --- Tests/Tests+PopupStack.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 73efb44b53..9db8052eac 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -156,14 +156,14 @@ extension PopupStackTests { // MARK: Dismiss Popup extension PopupStackTests { - func test_dismissLastPopup_withNoPopupsOnStack() { + func test_dismissLastPopup_withNoPopupsOnStack() async { registerNewInstanceAndPresentPopups(popups: []) - PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) + await PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) - let popupsOnStack = getPopupsForActiveInstance() + let popupsOnStack = await getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack.count, 0) } - func test_dismissLastPopup_withThreePopupsOnStack() { + func test_dismissLastPopup_withThreePopupsOnStack() async { registerNewInstanceAndPresentPopups(popups: [ AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), From 7f115c1cd7ba0677219afd390339a66c9673140d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:50:01 +0100 Subject: [PATCH 331/407] 1 --- Tests/Tests+PopupStack.swift | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 9db8052eac..b68e189bf7 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -164,14 +164,14 @@ extension PopupStackTests { XCTAssertEqual(popupsOnStack.count, 0) } func test_dismissLastPopup_withThreePopupsOnStack() async { - registerNewInstanceAndPresentPopups(popups: [ - AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), - AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), - AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()) + await registerNewInstanceAndPresentPopups(popups: [ + AnyPopup(TestBottomPopup1()), + AnyPopup(TestBottomPopup2()), + AnyPopup(TestBottomPopup3()) ]) - PopupStack.dismissLastPopup(popupManagerID: defaultPopupManagerID) + await PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) - let popupsOnStack = getPopupsForActiveInstance() + let popupsOnStack = await getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack.count, 2) } func test_dismissPopupWithType_whenPopupOnStack() { @@ -289,6 +289,12 @@ private struct TestTopPopup: TopPopup { private struct TestCenterPopup: CenterPopup { var body: some View { EmptyView() } } -private struct TestBottomPopup: BottomPopup { +private struct TestBottomPopup1: BottomPopup { + var body: some View { EmptyView() } +} +private struct TestBottomPopup2: BottomPopup { + var body: some View { EmptyView() } +} +private struct TestBottomPopup3: BottomPopup { var body: some View { EmptyView() } } From fcc06e53433c81f2dc97c03ecacd643405834399 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:50:54 +0100 Subject: [PATCH 332/407] 1 --- Tests/Tests+PopupStack.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index b68e189bf7..4a4fb154c3 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -174,20 +174,20 @@ extension PopupStackTests { let popupsOnStack = await getPopupsForActiveInstance() XCTAssertEqual(popupsOnStack.count, 2) } - func test_dismissPopupWithType_whenPopupOnStack() { - let popups: [AnyPopup] = [ + func test_dismissPopupWithType_whenPopupOnStack() async { + let popups: [AnyPopup] = await [ .init(TestTopPopup()), .init(TestCenterPopup()), - .init(TestBottomPopup()) + .init(TestBottomPopup1()) ] registerNewInstanceAndPresentPopups(popups: popups) - let popupsOnStackBefore = getPopupsForActiveInstance() + let popupsOnStackBefore = await getPopupsForActiveInstance() XCTAssertEqual(popups, popupsOnStackBefore) - PopupStack.dismissPopup(TestBottomPopup.self, popupManagerID: defaultPopupManagerID) + await PopupStack.dismissPopup(TestBottomPopup1.self, popupStackID: defaultPopupStackID) - let popupsOnStackAfter = getPopupsForActiveInstance() + let popupsOnStackAfter = await getPopupsForActiveInstance() XCTAssertEqual([popups[0], popups[1]], popupsOnStackAfter) } func test_dismissPopupWithType_whenPopupNotOnStack() { From c78132baa1a7a17cce12ea1699cf8cf8e23b77c1 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:53:52 +0100 Subject: [PATCH 333/407] 1 --- Tests/Tests+PopupStack.swift | 60 ++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 4a4fb154c3..3e4a02446e 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -103,53 +103,53 @@ extension PopupStackTests { // MARK: Present Popup extension PopupStackTests { func test_presentPopup_withThreePopupsToBePresented() async { - registerNewInstanceAndPresentPopups(popups: [ + await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup2()), await AnyPopup(TestBottomPopup3()) ]) - let popupsOnStack = await getPopupsForActiveInstance() + let popupsOnStack = await getPopupsForActiveStack() XCTAssertEqual(popupsOnStack.count, 3) } func test_presentPopup_withPopupsWithSameID() async { - registerNewInstanceAndPresentPopups(popups: [ + await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup1()), ]) - let popupsOnStack = await getPopupsForActiveInstance() + let popupsOnStack = await getPopupsForActiveStack() XCTAssertEqual(popupsOnStack.count, 2) } func test_presentPopup_withCustomID() async { - registerNewInstanceAndPresentPopups(popups: [ + await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup1().setCustomID("2137")), await AnyPopup(TestBottomPopup1().setCustomID("I Pan Paweł oczywiście")), ]) - let popupsOnStack = await getPopupsForActiveInstance() + let popupsOnStack = await getPopupsForActiveStack() XCTAssertEqual(popupsOnStack.count, 3) } func test_presentPopup_withDismissAfter() async { - registerNewInstanceAndPresentPopups(popups: [ + await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup1()).dismissAfter(0.7), await AnyPopup(TestBottomPopup1()).dismissAfter(1.5), ]) - let popupsOnStack1 = await getPopupsForActiveInstance() + let popupsOnStack1 = await getPopupsForActiveStack() XCTAssertEqual(popupsOnStack1.count, 3) await Task.sleep(seconds: 1) - let popupsOnStack2 = await getPopupsForActiveInstance() + let popupsOnStack2 = await getPopupsForActiveStack() XCTAssertEqual(popupsOnStack2.count, 2) await Task.sleep(seconds: 1) - let popupsOnStack3 = await getPopupsForActiveInstance() + let popupsOnStack3 = await getPopupsForActiveStack() XCTAssertEqual(popupsOnStack3.count, 1) } } @@ -157,21 +157,21 @@ extension PopupStackTests { // MARK: Dismiss Popup extension PopupStackTests { func test_dismissLastPopup_withNoPopupsOnStack() async { - registerNewInstanceAndPresentPopups(popups: []) + await registerNewStackAndPresent(popups: []) await PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) - let popupsOnStack = await getPopupsForActiveInstance() + let popupsOnStack = await getPopupsForActiveStack() XCTAssertEqual(popupsOnStack.count, 0) } func test_dismissLastPopup_withThreePopupsOnStack() async { - await registerNewInstanceAndPresentPopups(popups: [ + await registerNewStackAndPresent(popups: [ AnyPopup(TestBottomPopup1()), AnyPopup(TestBottomPopup2()), AnyPopup(TestBottomPopup3()) ]) await PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) - let popupsOnStack = await getPopupsForActiveInstance() + let popupsOnStack = await getPopupsForActiveStack() XCTAssertEqual(popupsOnStack.count, 2) } func test_dismissPopupWithType_whenPopupOnStack() async { @@ -180,14 +180,14 @@ extension PopupStackTests { .init(TestCenterPopup()), .init(TestBottomPopup1()) ] - registerNewInstanceAndPresentPopups(popups: popups) + await registerNewStackAndPresent(popups: popups) - let popupsOnStackBefore = await getPopupsForActiveInstance() + let popupsOnStackBefore = await getPopupsForActiveStack() XCTAssertEqual(popups, popupsOnStackBefore) await PopupStack.dismissPopup(TestBottomPopup1.self, popupStackID: defaultPopupStackID) - let popupsOnStackAfter = await getPopupsForActiveInstance() + let popupsOnStackAfter = await getPopupsForActiveStack() XCTAssertEqual([popups[0], popups[1]], popupsOnStackAfter) } func test_dismissPopupWithType_whenPopupNotOnStack() { @@ -195,14 +195,14 @@ extension PopupStackTests { .init(TestTopPopup()), .init(TestBottomPopup()) ] - registerNewInstanceAndPresentPopups(popups: popups) + await registerNewStackAndPresent(popups: popups) - let popupsOnStackBefore = getPopupsForActiveInstance() + let popupsOnStackBefore = getPopupsForActiveStack() XCTAssertEqual(popups, popupsOnStackBefore) PopupStack.dismissPopup(TestCenterPopup.self, popupManagerID: defaultPopupManagerID) - let popupsOnStackAfter = getPopupsForActiveInstance() + let popupsOnStackAfter = getPopupsForActiveStack() XCTAssertEqual(popups, popupsOnStackAfter) } func test_dismissPopupWithType_whenPopupHasCustomID() { @@ -210,14 +210,14 @@ extension PopupStackTests { .init(TestTopPopup().setCustomID("2137")), .init(TestBottomPopup()) ] - registerNewInstanceAndPresentPopups(popups: popups) + await registerNewStackAndPresent(popups: popups) - let popupsOnStackBefore = getPopupsForActiveInstance() + let popupsOnStackBefore = getPopupsForActiveStack() XCTAssertEqual(popups, popupsOnStackBefore) PopupStack.dismissPopup(TestTopPopup.self, popupManagerID: defaultPopupManagerID) - let popupsOnStackAfter = getPopupsForActiveInstance() + let popupsOnStackAfter = getPopupsForActiveStack() XCTAssertEqual(popups, popupsOnStackAfter) } func test_dismissPopupWithID_whenPopupHasCustomID() { @@ -225,14 +225,14 @@ extension PopupStackTests { .init(TestTopPopup().setCustomID("2137")), .init(TestBottomPopup()) ] - registerNewInstanceAndPresentPopups(popups: popups) + await registerNewStackAndPresent(popups: popups) - let popupsOnStackBefore = getPopupsForActiveInstance() + let popupsOnStackBefore = getPopupsForActiveStack() XCTAssertEqual(popups, popupsOnStackBefore) PopupStack.dismissPopup("2137", popupManagerID: defaultPopupManagerID) - let popupsOnStackAfter = getPopupsForActiveInstance() + let popupsOnStackAfter = getPopupsForActiveStack() XCTAssertEqual([popups[1]], popupsOnStackAfter) } func test_dismissAllPopups() { @@ -243,7 +243,7 @@ extension PopupStackTests { ]) PopupStack.dismissAllPopups(popupManagerID: defaultPopupManagerID) - let popupsOnStack = getPopupsForActiveInstance() + let popupsOnStack = getPopupsForActiveStack() XCTAssertEqual(popupsOnStack.count, 0) } } @@ -256,11 +256,11 @@ extension PopupStackTests { // MARK: Methods private extension PopupStackTests { - func registerNewInstanceAndPresentPopups(popups: [any Popup]) { + func registerNewStackAndPresent(popups: [any Popup]) async { register(stackIDs: [defaultPopupStackID]) - popups.forEach { $0.present(popupManagerID: defaultPopupManagerID) } + for popup in popups { await popup.present(popupStackID: defaultPopupStackID) } } - func getPopupsForActiveInstance() async -> [AnyPopup] { + func getPopupsForActiveStack() async -> [AnyPopup] { await PopupStack .fetch(id: defaultPopupStackID)? .popups ?? [] From 80bee3df00f0d460a9154d79e76a36862eadf5cb Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:55:26 +0100 Subject: [PATCH 334/407] 1 --- Tests/Tests+PopupStack.swift | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 3e4a02446e..74f9b32a33 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -190,34 +190,34 @@ extension PopupStackTests { let popupsOnStackAfter = await getPopupsForActiveStack() XCTAssertEqual([popups[0], popups[1]], popupsOnStackAfter) } - func test_dismissPopupWithType_whenPopupNotOnStack() { - let popups: [AnyPopup] = [ + func test_dismissPopupWithType_whenPopupNotOnStack() async { + let popups: [AnyPopup] = await [ .init(TestTopPopup()), - .init(TestBottomPopup()) + .init(TestBottomPopup1()) ] await registerNewStackAndPresent(popups: popups) - let popupsOnStackBefore = getPopupsForActiveStack() + let popupsOnStackBefore = await getPopupsForActiveStack() XCTAssertEqual(popups, popupsOnStackBefore) - PopupStack.dismissPopup(TestCenterPopup.self, popupManagerID: defaultPopupManagerID) + await PopupStack.dismissPopup(TestCenterPopup.self, popupStackID: defaultPopupStackID) - let popupsOnStackAfter = getPopupsForActiveStack() + let popupsOnStackAfter = await getPopupsForActiveStack() XCTAssertEqual(popups, popupsOnStackAfter) } - func test_dismissPopupWithType_whenPopupHasCustomID() { - let popups: [AnyPopup] = [ + func test_dismissPopupWithType_whenPopupHasCustomID() async { + let popups: [AnyPopup] = await [ .init(TestTopPopup().setCustomID("2137")), - .init(TestBottomPopup()) + .init(TestBottomPopup1()) ] await registerNewStackAndPresent(popups: popups) - let popupsOnStackBefore = getPopupsForActiveStack() + let popupsOnStackBefore = await getPopupsForActiveStack() XCTAssertEqual(popups, popupsOnStackBefore) - PopupStack.dismissPopup(TestTopPopup.self, popupManagerID: defaultPopupManagerID) + await PopupStack.dismissPopup(TestTopPopup.self, popupStackID: defaultPopupStackID) - let popupsOnStackAfter = getPopupsForActiveStack() + let popupsOnStackAfter = await getPopupsForActiveStack() XCTAssertEqual(popups, popupsOnStackAfter) } func test_dismissPopupWithID_whenPopupHasCustomID() { From 469ae9a8aa78ea2b2624a6ef69fbdae692742edf Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:56:34 +0100 Subject: [PATCH 335/407] 1 --- Tests/Tests+PopupStack.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 74f9b32a33..7fead5c9e0 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -220,22 +220,22 @@ extension PopupStackTests { let popupsOnStackAfter = await getPopupsForActiveStack() XCTAssertEqual(popups, popupsOnStackAfter) } - func test_dismissPopupWithID_whenPopupHasCustomID() { - let popups: [AnyPopup] = [ + func test_dismissPopupWithID_whenPopupHasCustomID() async { + let popups: [AnyPopup] = await [ .init(TestTopPopup().setCustomID("2137")), - .init(TestBottomPopup()) + .init(TestBottomPopup1()) ] await registerNewStackAndPresent(popups: popups) - let popupsOnStackBefore = getPopupsForActiveStack() + let popupsOnStackBefore = await getPopupsForActiveStack() XCTAssertEqual(popups, popupsOnStackBefore) - PopupStack.dismissPopup("2137", popupManagerID: defaultPopupManagerID) + await PopupStack.dismissPopup("2137", popupStackID: defaultPopupStackID) - let popupsOnStackAfter = getPopupsForActiveStack() + let popupsOnStackAfter = await getPopupsForActiveStack() XCTAssertEqual([popups[1]], popupsOnStackAfter) } - func test_dismissAllPopups() { + func test_dismissAllPopups() async { registerNewInstanceAndPresentPopups(popups: [ AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), From 2565cc70b13a7653f73ebc83978c5ea108adcc5c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 22:57:50 +0100 Subject: [PATCH 336/407] 1 --- Tests/Tests+PopupStack.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 7fead5c9e0..8ead039a2e 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -236,14 +236,14 @@ extension PopupStackTests { XCTAssertEqual([popups[1]], popupsOnStackAfter) } func test_dismissAllPopups() async { - registerNewInstanceAndPresentPopups(popups: [ - AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), - AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()), - AnyPopup.t_createNew(config: LocalConfigVertical.Bottom()) + await registerNewStackAndPresent(popups: [ + AnyPopup(TestBottomPopup1()), + AnyPopup(TestBottomPopup2()), + AnyPopup(TestBottomPopup3()) ]) - PopupStack.dismissAllPopups(popupManagerID: defaultPopupManagerID) + await PopupStack.dismissAllPopups(popupStackID: defaultPopupStackID) - let popupsOnStack = getPopupsForActiveStack() + let popupsOnStack = await getPopupsForActiveStack() XCTAssertEqual(popupsOnStack.count, 0) } } From aee456910b524de856a7c0031fda83646c33cc61 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 23:01:18 +0100 Subject: [PATCH 337/407] 1 --- Tests/Tests+PopupStack.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 8ead039a2e..a9e684f8e0 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -30,7 +30,7 @@ extension PopupStackTests { func test_registerStack_withNoStacksToRegister() { let popupStacksIDs: [PopupStackID] = [] - register(stackIDs: popupStacksIDs) + registerStacks(ids: popupStacksIDs) XCTAssertEqual(popupStacksIDs, getRegisteredStacks()) } func test_registerStack_withUniqueStacksToRegister() { @@ -41,7 +41,7 @@ extension PopupStackTests { .bronowice ] - register(stackIDs: popupStacksIDs) + registerStacks(ids: popupStacksIDs) XCTAssertEqual(popupStacksIDs, getRegisteredStacks()) } func test_registerStack_withRepeatingStacksToRegister() { @@ -56,14 +56,14 @@ extension PopupStackTests { .krowodrza ] - register(stackIDs: popupStacksIDs) + registerStacks(ids: popupStacksIDs) XCTAssertNotEqual(popupStacksIDs, getRegisteredStacks()) XCTAssertEqual(getRegisteredStacks().count, 6) } } private extension PopupStackTests { - func register(stackIDs: [PopupStackID]) { - stackIDs.forEach { _ = PopupStack.registerStack(id: $0) } + func registerStacks(ids: [PopupStackID]) { + ids.forEach { _ = PopupStack.registerStack(id: $0) } } func getRegisteredStacks() -> [PopupStackID] { PopupStackContainer.stacks.map(\.id) @@ -77,7 +77,7 @@ extension PopupStackTests { XCTAssertNil(stack) } func test_fetchStack_whenStackIsNotRegistered() async { - register(stackIDs: [ + registerStacks(ids: [ .krowodrza, .staremiasto, .pradnikczerwony, @@ -89,7 +89,7 @@ extension PopupStackTests { XCTAssertNil(stack) } func test_fetchStack_whenStackIsRegistered() async { - register(stackIDs: [ + registerStacks(ids: [ .krowodrza, .staremiasto, .grzegorzki @@ -257,7 +257,7 @@ extension PopupStackTests { // MARK: Methods private extension PopupStackTests { func registerNewStackAndPresent(popups: [any Popup]) async { - register(stackIDs: [defaultPopupStackID]) + registerStacks(ids: [defaultPopupStackID]) for popup in popups { await popup.present(popupStackID: defaultPopupStackID) } } func getPopupsForActiveStack() async -> [AnyPopup] { From 46620f41631193ac7a75f165189b2b5c3e9fd2e4 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 23:01:38 +0100 Subject: [PATCH 338/407] 1 --- Tests/Tests+PopupStack.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index a9e684f8e0..91459e8c21 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -61,14 +61,6 @@ extension PopupStackTests { XCTAssertEqual(getRegisteredStacks().count, 6) } } -private extension PopupStackTests { - func registerStacks(ids: [PopupStackID]) { - ids.forEach { _ = PopupStack.registerStack(id: $0) } - } - func getRegisteredStacks() -> [PopupStackID] { - PopupStackContainer.stacks.map(\.id) - } -} // MARK: Fetch extension PopupStackTests { @@ -266,6 +258,14 @@ private extension PopupStackTests { .popups ?? [] } } +private extension PopupStackTests { + func registerStacks(ids: [PopupStackID]) { + ids.forEach { _ = PopupStack.registerStack(id: $0) } + } + func getRegisteredStacks() -> [PopupStackID] { + PopupStackContainer.stacks.map(\.id) + } +} // MARK: Variables private extension PopupStackTests { From ac76dc0acc05f00a985aef31ddc22dfee4a7e5fb Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 23:06:38 +0100 Subject: [PATCH 339/407] 1 --- Tests/Tests+PopupStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 91459e8c21..a4d6206069 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -272,7 +272,7 @@ private extension PopupStackTests { var defaultPopupStackID: PopupStackID { .staremiasto } } -// MARK: Popup Manager Identifiers +// MARK: Popup Stack Identifiers private extension PopupStackID { static let staremiasto: Self = .init(rawValue: "staremiasto") static let grzegorzki: Self = .init(rawValue: "grzegorzki") From 21009eb4e75aa2878f1342c66d613e316c5f871f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 23:10:31 +0100 Subject: [PATCH 340/407] 1 --- ...=> Tests+ViewModel+PopupCenterStack.swift} | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) rename Tests/{Tests+ViewModel+PopupCentreStack.swift => Tests+ViewModel+PopupCenterStack.swift} (92%) diff --git a/Tests/Tests+ViewModel+PopupCentreStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift similarity index 92% rename from Tests/Tests+ViewModel+PopupCentreStack.swift rename to Tests/Tests+ViewModel+PopupCenterStack.swift index 8d83282cbc..b6ee337b47 100644 --- a/Tests/Tests+ViewModel+PopupCentreStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -1,5 +1,5 @@ // -// Tests+ViewModel+PopupCentreStack.swift of MijickPopups +// Tests+ViewModel+PopupCenterStack.swift of MijickPopups // // Created by Tomasz Kurylik. Sending ❤️ from Kraków! // - Mail: tomasz.kurylik@mijick.com @@ -13,7 +13,7 @@ import XCTest import SwiftUI @testable import MijickPopups -@MainActor final class PopupCentreStackViewModelTests: XCTestCase { +@MainActor final class PopupCenterStackViewModelTests: XCTestCase { @ObservedObject private var viewModel: ViewModel = .init(CenterPopupConfig.self) override func setUp() async throws { @@ -21,7 +21,7 @@ import SwiftUI viewModel.setup(updatePopupAction: { [self] in await updatePopupAction(viewModel, $0) }, closePopupAction: { [self] in await closePopupAction(viewModel, $0) }) } } -private extension PopupCentreStackViewModelTests { +private extension PopupCenterStackViewModelTests { func updatePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.popups.firstIndex(of: popup) { var popups = viewModel.popups popups[index] = popup @@ -43,7 +43,7 @@ private extension PopupCentreStackViewModelTests { // MARK: Popup Padding -extension PopupCentreStackViewModelTests { +extension PopupCenterStackViewModelTests { func test_calculatePopupPadding_withKeyboardHidden_whenCustomPaddingNotSet() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), @@ -97,7 +97,7 @@ extension PopupCentreStackViewModelTests { ) } } -private extension PopupCentreStackViewModelTests { +private extension PopupCenterStackViewModelTests { func appendPopupsAndCheckPopupPadding(popups: [AnyPopup], isKeyboardActive: Bool, expectedValue: EdgeInsets) async { await appendPopupsAndPerformChecks( popups: popups, @@ -109,7 +109,7 @@ private extension PopupCentreStackViewModelTests { } // MARK: Corner Radius -extension PopupCentreStackViewModelTests { +extension PopupCenterStackViewModelTests { func test_calculateCornerRadius_withCornerRadiusZero() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 20), @@ -133,7 +133,7 @@ extension PopupCentreStackViewModelTests { ) } } -private extension PopupCentreStackViewModelTests { +private extension PopupCenterStackViewModelTests { func appendPopupsAndCheckCornerRadius(popups: [AnyPopup], expectedValue: [MijickPopups.PopupAlignment: CGFloat]) async { await appendPopupsAndPerformChecks( popups: popups, @@ -145,7 +145,7 @@ private extension PopupCentreStackViewModelTests { } // MARK: Opacity -extension PopupCentreStackViewModelTests { +extension PopupCenterStackViewModelTests { func test_calculatePopupOpacity_1() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), @@ -173,7 +173,7 @@ extension PopupCentreStackViewModelTests { ) } } -private extension PopupCentreStackViewModelTests { +private extension PopupCenterStackViewModelTests { func appendPopupsAndCheckOpacity(popups: [AnyPopup], calculateForIndex index: Int, expectedValue: CGFloat) async { await appendPopupsAndPerformChecks( popups: popups, @@ -185,7 +185,7 @@ private extension PopupCentreStackViewModelTests { } // MARK: Vertical Fixed Size -extension PopupCentreStackViewModelTests { +extension PopupCenterStackViewModelTests { func test_calculateVerticalFixedSize_withHeightSmallerThanScreen() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), @@ -213,7 +213,7 @@ extension PopupCentreStackViewModelTests { ) } } -private extension PopupCentreStackViewModelTests { +private extension PopupCenterStackViewModelTests { func appendPopupsAndCheckVerticalFixedSize(popups: [AnyPopup], calculateForIndex index: Int, expectedValue: Bool) async { await appendPopupsAndPerformChecks( popups: popups, @@ -231,7 +231,7 @@ private extension PopupCentreStackViewModelTests { // MARK: Methods -private extension PopupCentreStackViewModelTests { +private extension PopupCenterStackViewModelTests { func createPopupInstanceForPopupHeightTests(popupHeight: CGFloat, popupPadding: EdgeInsets = .init(), cornerRadius: CGFloat = 0) -> AnyPopup { let config = getConfigForPopupHeightTests(cornerRadius: cornerRadius, popupPadding: popupPadding) return AnyPopup.t_createNew(config: config).settingHeight(popupHeight) @@ -247,7 +247,7 @@ private extension PopupCentreStackViewModelTests { XCTAssertEqual(calculatedValue, expectedValue) } } -private extension PopupCentreStackViewModelTests { +private extension PopupCenterStackViewModelTests { func getConfigForPopupHeightTests(cornerRadius: CGFloat, popupPadding: EdgeInsets) -> CenterPopupConfig { var config = CenterPopupConfig() config.cornerRadius = cornerRadius @@ -260,7 +260,7 @@ private extension PopupCentreStackViewModelTests { } // MARK: Screen -private extension PopupCentreStackViewModelTests { +private extension PopupCenterStackViewModelTests { var screen: Screen { .init( height: 1000, safeArea: .init(top: 100, leading: 20, bottom: 50, trailing: 30) @@ -272,6 +272,6 @@ private extension PopupCentreStackViewModelTests { } // MARK: Typealiases -private extension PopupCentreStackViewModelTests { +private extension PopupCenterStackViewModelTests { typealias ViewModel = VM.CenterStack } From 5bfb3af9e40e7ca5929647dc4735afdc21c5671f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 23:13:09 +0100 Subject: [PATCH 341/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 8 ++++---- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index b6ee337b47..bbceeb1216 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -26,13 +26,13 @@ private extension PopupCenterStackViewModelTests { var popups = viewModel.popups popups[index] = popup - await viewModel.updatePopupsValue(popups) + await viewModel.updatePopups(popups) }} func closePopupAction(_ viewModel: ViewModel, _ popup: AnyPopup) async { if let index = viewModel.popups.firstIndex(of: popup) { var popups = viewModel.popups popups.remove(at: index) - await viewModel.updatePopupsValue(popups) + await viewModel.updatePopups(popups) }} } @@ -237,7 +237,7 @@ private extension PopupCenterStackViewModelTests { return AnyPopup.t_createNew(config: config).settingHeight(popupHeight) } func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { - await viewModel.updatePopupsValue(popups) + await viewModel.updatePopups(popups) await updatePopups(viewModel) viewModel.updateKeyboardValue(isKeyboardActive) viewModel.updateScreenValue(isKeyboardActive ? screenWithKeyboard : screen) @@ -255,7 +255,7 @@ private extension PopupCenterStackViewModelTests { return config } func updatePopups(_ viewModel: ViewModel) async { - for popup in viewModel.popups { await viewModel.recalculateAndUpdatePopupHeight(popup.height!, popup) } + for popup in viewModel.popups { await viewModel.updatePopupHeight(popup.height!, popup) } } } diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 5bd99300f6..70231273ea 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1472,7 +1472,7 @@ private extension PopupVerticalStackViewModelTests { await viewModel.onPopupDragGestureEnded(gestureValue) XCTAssertEqual(viewModel.popups.count, expectedValues.shouldPopupBeDismissed ? 0 : 1) - XCTAssertEqual(viewModel.activePopupHeight, expectedValues.popupHeight) + XCTAssertEqual(viewModel.activePopupProperties.height, expectedValues.popupHeight) } } From 2a0f235a8f776cc645eb25931789b159f349db66 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 23:17:55 +0100 Subject: [PATCH 342/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index bbceeb1216..6cab04cb30 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -138,7 +138,7 @@ private extension PopupCenterStackViewModelTests { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, - calculatedValue: { await $0.calculateCornerRadius() }, + calculatedValue: { await $0.calculateActivePopupCorners() }, expectedValueBuilder: { _ in expectedValue } ) } @@ -195,7 +195,6 @@ extension PopupCenterStackViewModelTests { await appendPopupsAndCheckVerticalFixedSize( popups: popups, - calculateForIndex: 2, expectedValue: true ) } @@ -208,17 +207,16 @@ extension PopupCenterStackViewModelTests { await appendPopupsAndCheckVerticalFixedSize( popups: popups, - calculateForIndex: 2, expectedValue: false ) } } private extension PopupCenterStackViewModelTests { - func appendPopupsAndCheckVerticalFixedSize(popups: [AnyPopup], calculateForIndex index: Int, expectedValue: Bool) async { + func appendPopupsAndCheckVerticalFixedSize(popups: [AnyPopup], expectedValue: Bool) async { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, - calculatedValue: { $0.calculateVerticalFixedSize(for: $0.popups[index]) }, + calculatedValue: { await $0.calculateActivePopupVerticalFixedSize() }, expectedValueBuilder: { _ in expectedValue } ) } From f1fac04eee00bacbe59083d86950505359ce13db Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 23:19:13 +0100 Subject: [PATCH 343/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index 6cab04cb30..02e4f202a1 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -42,55 +42,55 @@ private extension PopupCenterStackViewModelTests { -// MARK: Popup Padding +// MARK: Outer Padding extension PopupCenterStackViewModelTests { - func test_calculatePopupPadding_withKeyboardHidden_whenCustomPaddingNotSet() async { + func test_calculateOuterPadding_withKeyboardHidden_whenCustomPaddingNotSet() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72), createPopupInstanceForPopupHeightTests(popupHeight: 400) ] - await appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckOuterPadding( popups: popups, isKeyboardActive: false, expectedValue: .init() ) } - func test_calculatePopupPadding_withKeyboardHidden_whenCustomPaddingSet() async { + func test_calculateOuterPadding_withKeyboardHidden_whenCustomPaddingSet() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72, popupPadding: .init(top: 0, leading: 11, bottom: 0, trailing: 11)), createPopupInstanceForPopupHeightTests(popupHeight: 400, popupPadding: .init(top: 0, leading: 16, bottom: 0, trailing: 16)) ] - await appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckOuterPadding( popups: popups, isKeyboardActive: false, expectedValue: .init(top: 0, leading: 16, bottom: 0, trailing: 16) ) } - func test_calculatePopupPadding_withKeyboardShown_whenKeyboardNotOverlapingPopup() async { + func test_calculateOuterPadding_withKeyboardShown_whenKeyboardNotOverlapingPopup() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72, popupPadding: .init(top: 0, leading: 11, bottom: 0, trailing: 11)), createPopupInstanceForPopupHeightTests(popupHeight: 400, popupPadding: .init(top: 0, leading: 16, bottom: 0, trailing: 16)) ] - await appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckOuterPadding( popups: popups, isKeyboardActive: true, expectedValue: .init(top: 0, leading: 16, bottom: 0, trailing: 16) ) } - func test_calculatePopupPadding_withKeyboardShown_whenKeyboardOverlapingPopup() async { + func test_calculateOuterPadding_withKeyboardShown_whenKeyboardOverlapingPopup() async { let popups = [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72, popupPadding: .init(top: 0, leading: 11, bottom: 0, trailing: 11)), createPopupInstanceForPopupHeightTests(popupHeight: 1000, popupPadding: .init(top: 0, leading: 16, bottom: 0, trailing: 16)) ] - await appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckOuterPadding( popups: popups, isKeyboardActive: true, expectedValue: .init(top: 0, leading: 16, bottom: 250, trailing: 16) @@ -98,11 +98,11 @@ extension PopupCenterStackViewModelTests { } } private extension PopupCenterStackViewModelTests { - func appendPopupsAndCheckPopupPadding(popups: [AnyPopup], isKeyboardActive: Bool, expectedValue: EdgeInsets) async { + func appendPopupsAndCheckOuterPadding(popups: [AnyPopup], isKeyboardActive: Bool, expectedValue: EdgeInsets) async { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: isKeyboardActive, - calculatedValue: { await $0.calculatePopupPadding() }, + calculatedValue: { await $0.calculateActivePopupOuterPadding() }, expectedValueBuilder: { _ in expectedValue } ) } From 7fa7be8efdedcb7063d412cd00c327a231928627 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Thu, 14 Nov 2024 23:23:26 +0100 Subject: [PATCH 344/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 70231273ea..3e085a5a77 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -454,7 +454,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.activePopupHeight }, + calculatedValue: { $0.activePopupProperties.height }, expectedValueBuilder: { _ in expectedValue } ) } From 660b40dcdf17d09bc7ad236af324cc7fd10176b8 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 00:04:32 +0100 Subject: [PATCH 345/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 3e085a5a77..91af1919fc 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -83,9 +83,9 @@ extension PopupVerticalStackViewModelTests { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 0) ] - let updatedPopup = popups[0] - .settingHeight(100) - .settingDragHeight(100) + let updatedPopup = await popups[0] + .updatedHeight(100) + .updatedDragHeight(100) await appendPopupsAndCheckPopups( viewModel: bottomViewModel, @@ -102,7 +102,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 15), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2137) ] - let updatedPopup = popups[2].settingHeight(1371) + let updatedPopup = await popups[2].updatedHeight(1371) await appendPopupsAndCheckPopups( viewModel: bottomViewModel, @@ -120,7 +120,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2137), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 77) ] - let updatedPopup = popups[4].settingHeight(nil) + let updatedPopup = await popups[4].updatedHeight(nil) await appendPopupsAndCheckPopups( viewModel: bottomViewModel, @@ -932,7 +932,7 @@ private extension PopupVerticalStackViewModelTests { viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { await $0.calculateCornerRadius() }, + calculatedValue: { await $0.calculateActivePopupCorners() }, expectedValueBuilder: { _ in expectedValue } ) } @@ -1300,8 +1300,8 @@ private extension PopupVerticalStackViewModelTests { await updatePopups(viewModel) await viewModel.onPopupDragGestureChanged(gestureValue) - XCTAssertEqual(viewModel.activePopupHeight, expectedValues.popupHeight) - XCTAssertEqual(viewModel.gestureTranslation, expectedValues.gestureTranslation) + XCTAssertEqual(viewModel.activePopupProperties.height, expectedValues.popupHeight) + XCTAssertEqual(viewModel.activePopupProperties.gestureTranslation, expectedValues.gestureTranslation) } } From 5cdf079df2d6320f94670462c87f3383ce7ca61f Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 00:06:02 +0100 Subject: [PATCH 346/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 91af1919fc..046a12f76c 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -57,7 +57,7 @@ extension PopupVerticalStackViewModelTests { ]) XCTAssertEqual( - bottomViewModel.getInvertedIndex(of: bottomViewModel.popups[0]), + bottomViewModel.popups.getInvertedIndex(of: bottomViewModel.popups[0]), 0 ) } @@ -71,7 +71,7 @@ extension PopupVerticalStackViewModelTests { ]) XCTAssertEqual( - bottomViewModel.getInvertedIndex(of: bottomViewModel.popups[3]), + bottomViewModel.popups.getInvertedIndex(of: bottomViewModel.popups[3]), 1 ) } From 09b88a18a4685a4df0a2f741bfbc89c9ac4045ab Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 00:07:23 +0100 Subject: [PATCH 347/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 046a12f76c..ce3feffac8 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1029,7 +1029,6 @@ extension PopupVerticalStackViewModelTests { viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, - calculateForIndex: 1, expectedValue: true ) } @@ -1043,7 +1042,6 @@ extension PopupVerticalStackViewModelTests { viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, - calculateForIndex: 1, expectedValue: false ) } @@ -1058,7 +1056,6 @@ extension PopupVerticalStackViewModelTests { viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, - calculateForIndex: 2, expectedValue: false ) } @@ -1075,18 +1072,17 @@ extension PopupVerticalStackViewModelTests { viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, - calculateForIndex: 4, expectedValue: false ) } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckVerticalFixedSize(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculateForIndex index: Int, expectedValue: Bool) async { + func appendPopupsAndCheckVerticalFixedSize(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: Bool) async { await appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.calculateVerticalFixedSize(for: $0.popups[index]) }, + calculatedValue: { await $0.calculateActivePopupVerticalFixedSize() }, expectedValueBuilder: { _ in expectedValue } ) } From f8a882dfc368ca6902d240b2b4223834ea8db586 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 00:09:44 +0100 Subject: [PATCH 348/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index ce3feffac8..c8f026352f 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -562,86 +562,86 @@ extension PopupVerticalStackViewModelTests { } } -// MARK: Popup Padding +// MARK: Outer Padding extension PopupVerticalStackViewModelTests { - func test_calculatePopupPadding_withAutoHeightMode_whenLessThanScreen() async { + func test_calculateOuterPadding_withAutoHeightMode_whenLessThanScreen() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - await appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckOuterPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 12, leading: 17, bottom: 33, trailing: 17) ) } - func test_calculatePopupPadding_withAutoHeightMode_almostLikeScreen_onlyOnePaddingShouldBeNonZero() async { + func test_calculateOuterPadding_withAutoHeightMode_almostLikeScreen_onlyOnePaddingShouldBeNonZero() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 877, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - await appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckOuterPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: 17, bottom: 23, trailing: 17) ) } - func test_calculatePopupPadding_withAutoHeightMode_almostLikeScreen_bothPaddingsShouldBeNonZero() async { + func test_calculateOuterPadding_withAutoHeightMode_almostLikeScreen_bothPaddingsShouldBeNonZero() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 861, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - await appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckOuterPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 6, leading: 17, bottom: 33, trailing: 17) ) } - func test_calculatePopupPadding_withAutoHeightMode_almostLikeScreen_topPopupsAlignment() async { + func test_calculateOuterPadding_withAutoHeightMode_almostLikeScreen_topPopupsAlignment() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 911, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - await appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckOuterPadding( viewModel: topViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 12, leading: 17, bottom: 27, trailing: 17) ) } - func test_calculatePopupPadding_withAutoHeightMode_whenBiggerThanScreen() async { + func test_calculateOuterPadding_withAutoHeightMode_whenBiggerThanScreen() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1100, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - await appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckOuterPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: 17, bottom: 0, trailing: 17) ) } - func test_calculatePopupPadding_withLargeHeightMode() async { + func test_calculateOuterPadding_withLargeHeightMode() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - await appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckOuterPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: 17, bottom: 0, trailing: 17) ) } - func test_calculatePopupPadding_withFullscreenHeightMode() async { + func test_calculateOuterPadding_withFullscreenHeightMode() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] - await appendPopupsAndCheckPopupPadding( + await appendPopupsAndCheckOuterPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, @@ -650,12 +650,12 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckPopupPadding(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: EdgeInsets) async { + func appendPopupsAndCheckOuterPadding(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: EdgeInsets) async { await appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { await $0.calculatePopupPadding() }, + calculatedValue: { await $0.calculateActivePopupOuterPadding() }, expectedValueBuilder: { _ in expectedValue } ) } From c1878606c6d9a77c41a2ffcbf65ffa9ec95e3ef5 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 00:11:38 +0100 Subject: [PATCH 349/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index c8f026352f..570e7328fe 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -661,98 +661,98 @@ private extension PopupVerticalStackViewModelTests { } } -// MARK: Body Padding +// MARK: Inner Padding extension PopupVerticalStackViewModelTests { - func test_calculateBodyPadding_withDefaultSettings() async { + func test_calculateInnerPadding_withDefaultSettings() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 350) ] - await appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckInnerPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: screen.safeArea.top, leading: screen.safeArea.leading, bottom: screen.safeArea.bottom, trailing: screen.safeArea.trailing) ) } - func test_calculateBodyPadding_withIgnoringSafeArea_bottom() async { + func test_calculateInnerPadding_withIgnoringSafeArea_bottom() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 200, ignoredSafeAreaEdges: .bottom) ] - await appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckInnerPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: screen.safeArea.leading, bottom: 0, trailing: screen.safeArea.trailing) ) } - func test_calculateBodyPadding_withIgnoringSafeArea_all() async { + func test_calculateInnerPadding_withIgnoringSafeArea_all() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1200, ignoredSafeAreaEdges: .all) ] - await appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckInnerPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: 0, bottom: 0, trailing: 0) ) } - func test_calculateBodyPadding_withPopupPadding() async { + func test_calculateInnerPadding_withPopupPadding() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1200, popupPadding: .init(top: 21, leading: 12, bottom: 37, trailing: 12)) ] - await appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckInnerPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: screen.safeArea.leading, bottom: screen.safeArea.bottom, trailing: screen.safeArea.trailing) ) } - func test_calculateBodyPadding_withFullscreenHeightMode_ignoringSafeArea_top() async { + func test_calculateInnerPadding_withFullscreenHeightMode_ignoringSafeArea_top() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100, ignoredSafeAreaEdges: .top) ] - await appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckInnerPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 0, expectedValue: .init(top: 0, leading: screen.safeArea.leading, bottom: screen.safeArea.bottom, trailing: screen.safeArea.trailing) ) } - func test_calculateBodyPadding_withGestureTranslation() async { + func test_calculateInnerPadding_withGestureTranslation() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 800) ] - await appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckInnerPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: -300, expectedValue: .init(top: screen.safeArea.top, leading: screen.safeArea.leading, bottom: screen.safeArea.bottom, trailing: screen.safeArea.trailing) ) } - func test_calculateBodyPadding_withGestureTranslation_dragHeight() async { + func test_calculateInnerPadding_withGestureTranslation_dragHeight() async { let popups = [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupDragHeight: 700) ] - await appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckInnerPadding( viewModel: bottomViewModel, popups: popups, gestureTranslation: 21, expectedValue: .init(top: screen.safeArea.top - 21, leading: screen.safeArea.leading, bottom: screen.safeArea.bottom, trailing: screen.safeArea.trailing) ) } - func test_calculateBodyPadding_withGestureTranslation_dragHeight_topPopupsAlignment() async { + func test_calculateInnerPadding_withGestureTranslation_dragHeight_topPopupsAlignment() async { let popups = [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 300, popupDragHeight: 700) ] - await appendPopupsAndCheckBodyPadding( + await appendPopupsAndCheckInnerPadding( viewModel: topViewModel, popups: popups, gestureTranslation: -21, @@ -761,12 +761,12 @@ extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckBodyPadding(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: EdgeInsets) async { + func appendPopupsAndCheckInnerPadding(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, expectedValue: EdgeInsets) async { await appendPopupsAndPerformChecks( viewModel: viewModel, popups: popups, gestureTranslation: gestureTranslation, - calculatedValue: { $0.calculateBodyPadding(for: popups.last!) }, + calculatedValue: { await $0.calculateActivePopupInnerPadding() }, expectedValueBuilder: { _ in expectedValue } ) } From 32913b821ecfd60092ad3e8d0fe324bff8471c4b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 00:13:12 +0100 Subject: [PATCH 350/407] 1 --- Sources/Internal/Containers/GlobalConfigContainer.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/Containers/GlobalConfigContainer.swift b/Sources/Internal/Containers/GlobalConfigContainer.swift index b8a742cb10..25aa8d7ff8 100644 --- a/Sources/Internal/Containers/GlobalConfigContainer.swift +++ b/Sources/Internal/Containers/GlobalConfigContainer.swift @@ -10,6 +10,6 @@ public actor GlobalConfigContainer { - static var center: GlobalConfigCenter = .init() - static var vertical: GlobalConfigVertical = .init() + nonisolated(unsafe) static var center: GlobalConfigCenter = .init() + nonisolated(unsafe) static var vertical: GlobalConfigVertical = .init() } From 50898d2caf9edb62937ae129b2b2fc42780e740a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 00:29:50 +0100 Subject: [PATCH 351/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 50 ++++++++++++-------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index 02e4f202a1..99bd4e0274 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -45,7 +45,7 @@ private extension PopupCenterStackViewModelTests { // MARK: Outer Padding extension PopupCenterStackViewModelTests { func test_calculateOuterPadding_withKeyboardHidden_whenCustomPaddingNotSet() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72), createPopupInstanceForPopupHeightTests(popupHeight: 400) @@ -58,10 +58,10 @@ extension PopupCenterStackViewModelTests { ) } func test_calculateOuterPadding_withKeyboardHidden_whenCustomPaddingSet() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(popupHeight: 350), - createPopupInstanceForPopupHeightTests(popupHeight: 72, popupPadding: .init(top: 0, leading: 11, bottom: 0, trailing: 11)), - createPopupInstanceForPopupHeightTests(popupHeight: 400, popupPadding: .init(top: 0, leading: 16, bottom: 0, trailing: 16)) + createPopupInstanceForPopupHeightTests(popupHeight: 72, horizontalPadding: 11), + createPopupInstanceForPopupHeightTests(popupHeight: 400, horizontalPadding: 16) ] await appendPopupsAndCheckOuterPadding( @@ -71,10 +71,10 @@ extension PopupCenterStackViewModelTests { ) } func test_calculateOuterPadding_withKeyboardShown_whenKeyboardNotOverlapingPopup() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(popupHeight: 350), - createPopupInstanceForPopupHeightTests(popupHeight: 72, popupPadding: .init(top: 0, leading: 11, bottom: 0, trailing: 11)), - createPopupInstanceForPopupHeightTests(popupHeight: 400, popupPadding: .init(top: 0, leading: 16, bottom: 0, trailing: 16)) + createPopupInstanceForPopupHeightTests(popupHeight: 72, horizontalPadding: 11), + createPopupInstanceForPopupHeightTests(popupHeight: 400, horizontalPadding: 16) ] await appendPopupsAndCheckOuterPadding( @@ -84,10 +84,10 @@ extension PopupCenterStackViewModelTests { ) } func test_calculateOuterPadding_withKeyboardShown_whenKeyboardOverlapingPopup() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(popupHeight: 350), - createPopupInstanceForPopupHeightTests(popupHeight: 72, popupPadding: .init(top: 0, leading: 11, bottom: 0, trailing: 11)), - createPopupInstanceForPopupHeightTests(popupHeight: 1000, popupPadding: .init(top: 0, leading: 16, bottom: 0, trailing: 16)) + createPopupInstanceForPopupHeightTests(popupHeight: 72, horizontalPadding: 11), + createPopupInstanceForPopupHeightTests(popupHeight: 1000, horizontalPadding: 16) ] await appendPopupsAndCheckOuterPadding( @@ -111,7 +111,7 @@ private extension PopupCenterStackViewModelTests { // MARK: Corner Radius extension PopupCenterStackViewModelTests { func test_calculateCornerRadius_withCornerRadiusZero() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 20), createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 0), ] @@ -122,7 +122,7 @@ extension PopupCenterStackViewModelTests { ) } func test_calculateCornerRadius_withCornerRadiusNonZero() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 20), createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 24), ] @@ -147,7 +147,7 @@ private extension PopupCenterStackViewModelTests { // MARK: Opacity extension PopupCenterStackViewModelTests { func test_calculatePopupOpacity_1() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72), createPopupInstanceForPopupHeightTests(popupHeight: 400) @@ -160,7 +160,7 @@ extension PopupCenterStackViewModelTests { ) } func test_calculatePopupOpacity_2() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72), createPopupInstanceForPopupHeightTests(popupHeight: 400) @@ -187,7 +187,7 @@ private extension PopupCenterStackViewModelTests { // MARK: Vertical Fixed Size extension PopupCenterStackViewModelTests { func test_calculateVerticalFixedSize_withHeightSmallerThanScreen() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 913), createPopupInstanceForPopupHeightTests(popupHeight: 400) @@ -199,7 +199,7 @@ extension PopupCenterStackViewModelTests { ) } func test_calculateVerticalFixedSize_withHeightLargerThanScreen() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(popupHeight: 350), createPopupInstanceForPopupHeightTests(popupHeight: 72), createPopupInstanceForPopupHeightTests(popupHeight: 913) @@ -230,9 +230,9 @@ private extension PopupCenterStackViewModelTests { // MARK: Methods private extension PopupCenterStackViewModelTests { - func createPopupInstanceForPopupHeightTests(popupHeight: CGFloat, popupPadding: EdgeInsets = .init(), cornerRadius: CGFloat = 0) -> AnyPopup { - let config = getConfigForPopupHeightTests(cornerRadius: cornerRadius, popupPadding: popupPadding) - return AnyPopup.t_createNew(config: config).settingHeight(popupHeight) + func createPopupInstanceForPopupHeightTests(popupHeight: CGFloat, horizontalPadding: CGFloat = 0, cornerRadius: CGFloat = 0) async -> AnyPopup { + let popup = TestPopup(horizontalPadding: horizontalPadding, cornerRadius: cornerRadius) + return await AnyPopup(popup).updatedHeight(popupHeight) } func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.updatePopups(popups) @@ -273,3 +273,15 @@ private extension PopupCenterStackViewModelTests { private extension PopupCenterStackViewModelTests { typealias ViewModel = VM.CenterStack } + +// MARK: Test Popup +private struct TestPopup: CenterPopup { + let horizontalPadding: CGFloat + let cornerRadius: CGFloat + + func configurePopup(config: LocalConfigCenter) -> LocalConfigCenter { config + .popupHorizontalPadding(horizontalPadding) + .cornerRadius(cornerRadius) + } + var body: some View { EmptyView() } +} From 8ebfa77d68283705dec45462f659d2e334634f4b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 00:39:38 +0100 Subject: [PATCH 352/407] 1 --- Sources/Internal/UI/PopupView.swift | 2 +- Sources/Internal/View Models/ViewModel.swift | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Sources/Internal/UI/PopupView.swift b/Sources/Internal/UI/PopupView.swift index a9b6760247..b59e99cff8 100644 --- a/Sources/Internal/UI/PopupView.swift +++ b/Sources/Internal/UI/PopupView.swift @@ -82,7 +82,7 @@ private extension PopupView { await updateViewModels { $0.setup(updatePopupAction: updatePopup, closePopupAction: closePopup) } }} func onScreenChange(_ screenReader: GeometryProxy) { Task { - await updateViewModels { await $0.updateScreen(screenReader: screenReader) } + await updateViewModels { await $0.updateScreen(screenHeight: screenReader.size.height + screenReader.safeAreaInsets.top + screenReader.safeAreaInsets.bottom, screenSafeArea: screenReader.safeAreaInsets) } }} func onPopupsHeightChange(_ p: Any) { Task { await updateViewModels { await $0.updatePopups(stack.popups) } diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 4ec54997c6..07e21e7926 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -71,8 +71,8 @@ extension ViewModel { // MARK: Screen extension ViewModel { - @MainActor func updateScreen(screenReader: GeometryProxy? = nil, isKeyboardActive: Bool? = nil) async { Task { - screen = await updatedScreenProperties(screenReader, isKeyboardActive) + @MainActor func updateScreen(screenHeight: CGFloat? = nil, screenSafeArea: EdgeInsets? = nil, isKeyboardActive: Bool? = nil) async { Task { + screen = await updatedScreenProperties(screenHeight, screenSafeArea, isKeyboardActive) await updateActivePopupProperties() withAnimation(.transition) { objectWillChange.send() } @@ -112,12 +112,11 @@ private extension ViewModel { func filteredPopups(_ popups: [AnyPopup]) async -> [AnyPopup] { popups.filter { $0.config.alignment == alignment } } - func updatedScreenProperties(_ screenReader: GeometryProxy?, _ isKeyboardActive: Bool?) async -> Screen { - let height = if let screenReader { screenReader.size.height + screenReader.safeAreaInsets.top + screenReader.safeAreaInsets.bottom } else { screen.height }, - safeArea = screenReader?.safeAreaInsets ?? screen.safeArea, - isKeyboardActive = isKeyboardActive ?? screen.isKeyboardActive - return .init(height: height, safeArea: safeArea, isKeyboardActive: isKeyboardActive) - } + func updatedScreenProperties(_ screenHeight: CGFloat?, _ screenSafeArea: EdgeInsets?, _ isKeyboardActive: Bool?) async -> Screen { .init( + height: screenHeight ?? screen.height, + safeArea: screenSafeArea ?? screen.safeArea, + isKeyboardActive: isKeyboardActive ?? screen.isKeyboardActive + )} } private extension ViewModel { func updateActivePopupProperties() async { From 55524e63ceda24fbea91d64ea0e3a30eba6e5c6b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 00:42:45 +0100 Subject: [PATCH 353/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index 99bd4e0274..cc1dd7d8a4 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -17,7 +17,7 @@ import SwiftUI @ObservedObject private var viewModel: ViewModel = .init(CenterPopupConfig.self) override func setUp() async throws { - viewModel.updateScreenValue(screen) + await viewModel.updateScreen(screenHeight: screen.height, screenSafeArea: screen.safeArea) viewModel.setup(updatePopupAction: { [self] in await updatePopupAction(viewModel, $0) }, closePopupAction: { [self] in await closePopupAction(viewModel, $0) }) } } @@ -237,8 +237,7 @@ private extension PopupCenterStackViewModelTests { func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.updatePopups(popups) await updatePopups(viewModel) - viewModel.updateKeyboardValue(isKeyboardActive) - viewModel.updateScreenValue(isKeyboardActive ? screenWithKeyboard : screen) + await viewModel.updateScreen(screenHeight: isKeyboardActive ? screenWithKeyboard.height : screen.height, screenSafeArea: isKeyboardActive ? screenWithKeyboard.safeArea : screen.safeArea, isKeyboardActive: isKeyboardActive) let calculatedValue = await calculatedValue(viewModel) let expectedValue = await expectedValueBuilder(viewModel) From 8aa25d9e94ccda6ec5f41eadec5c1c86802a90a0 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 00:51:23 +0100 Subject: [PATCH 354/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index cc1dd7d8a4..e80d00c6d3 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -234,7 +234,7 @@ private extension PopupCenterStackViewModelTests { let popup = TestPopup(horizontalPadding: horizontalPadding, cornerRadius: cornerRadius) return await AnyPopup(popup).updatedHeight(popupHeight) } - func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { + func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @MainActor @escaping (ViewModel) async -> Value, expectedValueBuilder: @MainActor @escaping (ViewModel) async -> Value) async { await viewModel.updatePopups(popups) await updatePopups(viewModel) await viewModel.updateScreen(screenHeight: isKeyboardActive ? screenWithKeyboard.height : screen.height, screenSafeArea: isKeyboardActive ? screenWithKeyboard.safeArea : screen.safeArea, isKeyboardActive: isKeyboardActive) From 736d2cbb5ef5b77f4088d8cbb8b00be924f4fc7c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 00:52:33 +0100 Subject: [PATCH 355/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index e80d00c6d3..bafd1a0be5 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -245,12 +245,6 @@ private extension PopupCenterStackViewModelTests { } } private extension PopupCenterStackViewModelTests { - func getConfigForPopupHeightTests(cornerRadius: CGFloat, popupPadding: EdgeInsets) -> CenterPopupConfig { - var config = CenterPopupConfig() - config.cornerRadius = cornerRadius - config.popupPadding = popupPadding - return config - } func updatePopups(_ viewModel: ViewModel) async { for popup in viewModel.popups { await viewModel.updatePopupHeight(popup.height!, popup) } } From ccbc326408049ad511fa0baad235ca839cef948a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 02:01:18 +0100 Subject: [PATCH 356/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index bafd1a0be5..0f26f15bef 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -234,7 +234,7 @@ private extension PopupCenterStackViewModelTests { let popup = TestPopup(horizontalPadding: horizontalPadding, cornerRadius: cornerRadius) return await AnyPopup(popup).updatedHeight(popupHeight) } - func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @MainActor @escaping (ViewModel) async -> Value, expectedValueBuilder: @MainActor @escaping (ViewModel) async -> Value) async { + func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) async -> Value, expectedValueBuilder: @escaping (ViewModel) async -> Value) async { Task { await viewModel.updatePopups(popups) await updatePopups(viewModel) await viewModel.updateScreen(screenHeight: isKeyboardActive ? screenWithKeyboard.height : screen.height, screenSafeArea: isKeyboardActive ? screenWithKeyboard.safeArea : screen.safeArea, isKeyboardActive: isKeyboardActive) @@ -242,7 +242,7 @@ private extension PopupCenterStackViewModelTests { let calculatedValue = await calculatedValue(viewModel) let expectedValue = await expectedValueBuilder(viewModel) XCTAssertEqual(calculatedValue, expectedValue) - } + }} } private extension PopupCenterStackViewModelTests { func updatePopups(_ viewModel: ViewModel) async { From e0a82b615fad12d41ebdd3b8aa3062dd8b41f6c9 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 02:32:42 +0100 Subject: [PATCH 357/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index 0f26f15bef..eef428cf4e 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -239,6 +239,8 @@ private extension PopupCenterStackViewModelTests { await updatePopups(viewModel) await viewModel.updateScreen(screenHeight: isKeyboardActive ? screenWithKeyboard.height : screen.height, screenSafeArea: isKeyboardActive ? screenWithKeyboard.safeArea : screen.safeArea, isKeyboardActive: isKeyboardActive) + await Task.sleep(seconds: 0.1) + let calculatedValue = await calculatedValue(viewModel) let expectedValue = await expectedValueBuilder(viewModel) XCTAssertEqual(calculatedValue, expectedValue) From 9b67859ba2b4d2b933859ed1f92750e48cb92836 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 02:33:00 +0100 Subject: [PATCH 358/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index eef428cf4e..822fd9f766 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -280,3 +280,6 @@ private struct TestPopup: CenterPopup { } var body: some View { EmptyView() } } + +// MARK: Others +extension VM.CenterStack: @unchecked Sendable {} From 16f5e7a2edf60157b3a06f0f603bb55505241fc1 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 02:44:11 +0100 Subject: [PATCH 359/407] 1 --- Tests/Tests+PopupStack.swift | 92 ++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index a4d6206069..ea3463f215 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -64,11 +64,11 @@ extension PopupStackTests { // MARK: Fetch extension PopupStackTests { - func test_fetchStack_whenNoStacksAreRegistered() async { + func test_fetchStack_whenNoStacksAreRegistered() async { Task { let stack = await PopupStack.fetch(id: .bronowice) XCTAssertNil(stack) - } - func test_fetchStack_whenStackIsNotRegistered() async { + }} + func test_fetchStack_whenStackIsNotRegistered() async { Task { registerStacks(ids: [ .krowodrza, .staremiasto, @@ -79,8 +79,8 @@ extension PopupStackTests { let stack = await PopupStack.fetch(id: .bronowice) XCTAssertNil(stack) - } - func test_fetchStack_whenStackIsRegistered() async { + }} + func test_fetchStack_whenStackIsRegistered() async { Task { registerStacks(ids: [ .krowodrza, .staremiasto, @@ -89,73 +89,73 @@ extension PopupStackTests { let stack = await PopupStack.fetch(id: .grzegorzki) XCTAssertNotNil(stack) - } + }} } // MARK: Present Popup extension PopupStackTests { - func test_presentPopup_withThreePopupsToBePresented() async { + func test_presentPopup_withThreePopupsToBePresented() async { Task { await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup2()), await AnyPopup(TestBottomPopup3()) ]) - let popupsOnStack = await getPopupsForActiveStack() + let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 3) - } - func test_presentPopup_withPopupsWithSameID() async { + }} + func test_presentPopup_withPopupsWithSameID() async { Task { await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup1()), ]) - let popupsOnStack = await getPopupsForActiveStack() + let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 2) - } - func test_presentPopup_withCustomID() async { + }} + func test_presentPopup_withCustomID() async { Task { await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup1().setCustomID("2137")), await AnyPopup(TestBottomPopup1().setCustomID("I Pan Paweł oczywiście")), ]) - let popupsOnStack = await getPopupsForActiveStack() + let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 3) - } - func test_presentPopup_withDismissAfter() async { + }} + func test_presentPopup_withDismissAfter() async { Task { await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup1()).dismissAfter(0.7), await AnyPopup(TestBottomPopup1()).dismissAfter(1.5), ]) - let popupsOnStack1 = await getPopupsForActiveStack() + let popupsOnStack1 = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack1.count, 3) await Task.sleep(seconds: 1) - let popupsOnStack2 = await getPopupsForActiveStack() + let popupsOnStack2 = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack2.count, 2) await Task.sleep(seconds: 1) - let popupsOnStack3 = await getPopupsForActiveStack() + let popupsOnStack3 = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack3.count, 1) - } + }} } // MARK: Dismiss Popup extension PopupStackTests { - func test_dismissLastPopup_withNoPopupsOnStack() async { + func test_dismissLastPopup_withNoPopupsOnStack() async { Task { await registerNewStackAndPresent(popups: []) await PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) - let popupsOnStack = await getPopupsForActiveStack() + let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 0) - } - func test_dismissLastPopup_withThreePopupsOnStack() async { + }} + func test_dismissLastPopup_withThreePopupsOnStack() async { Task { await registerNewStackAndPresent(popups: [ AnyPopup(TestBottomPopup1()), AnyPopup(TestBottomPopup2()), @@ -163,10 +163,10 @@ extension PopupStackTests { ]) await PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) - let popupsOnStack = await getPopupsForActiveStack() + let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 2) - } - func test_dismissPopupWithType_whenPopupOnStack() async { + }} + func test_dismissPopupWithType_whenPopupOnStack() async { Task { let popups: [AnyPopup] = await [ .init(TestTopPopup()), .init(TestCenterPopup()), @@ -174,60 +174,60 @@ extension PopupStackTests { ] await registerNewStackAndPresent(popups: popups) - let popupsOnStackBefore = await getPopupsForActiveStack() + let popupsOnStackBefore = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackBefore) await PopupStack.dismissPopup(TestBottomPopup1.self, popupStackID: defaultPopupStackID) - let popupsOnStackAfter = await getPopupsForActiveStack() + let popupsOnStackAfter = await getPopupsForDefaultStack() XCTAssertEqual([popups[0], popups[1]], popupsOnStackAfter) - } - func test_dismissPopupWithType_whenPopupNotOnStack() async { + }} + func test_dismissPopupWithType_whenPopupNotOnStack() async { Task { let popups: [AnyPopup] = await [ .init(TestTopPopup()), .init(TestBottomPopup1()) ] await registerNewStackAndPresent(popups: popups) - let popupsOnStackBefore = await getPopupsForActiveStack() + let popupsOnStackBefore = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackBefore) await PopupStack.dismissPopup(TestCenterPopup.self, popupStackID: defaultPopupStackID) - let popupsOnStackAfter = await getPopupsForActiveStack() + let popupsOnStackAfter = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackAfter) - } - func test_dismissPopupWithType_whenPopupHasCustomID() async { + }} + func test_dismissPopupWithType_whenPopupHasCustomID() async { Task { let popups: [AnyPopup] = await [ .init(TestTopPopup().setCustomID("2137")), .init(TestBottomPopup1()) ] await registerNewStackAndPresent(popups: popups) - let popupsOnStackBefore = await getPopupsForActiveStack() + let popupsOnStackBefore = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackBefore) await PopupStack.dismissPopup(TestTopPopup.self, popupStackID: defaultPopupStackID) - let popupsOnStackAfter = await getPopupsForActiveStack() + let popupsOnStackAfter = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackAfter) - } - func test_dismissPopupWithID_whenPopupHasCustomID() async { + }} + func test_dismissPopupWithID_whenPopupHasCustomID() async { Task { let popups: [AnyPopup] = await [ .init(TestTopPopup().setCustomID("2137")), .init(TestBottomPopup1()) ] await registerNewStackAndPresent(popups: popups) - let popupsOnStackBefore = await getPopupsForActiveStack() + let popupsOnStackBefore = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackBefore) await PopupStack.dismissPopup("2137", popupStackID: defaultPopupStackID) - let popupsOnStackAfter = await getPopupsForActiveStack() + let popupsOnStackAfter = await getPopupsForDefaultStack() XCTAssertEqual([popups[1]], popupsOnStackAfter) - } - func test_dismissAllPopups() async { + }} + func test_dismissAllPopups() async { Task { await registerNewStackAndPresent(popups: [ AnyPopup(TestBottomPopup1()), AnyPopup(TestBottomPopup2()), @@ -235,9 +235,9 @@ extension PopupStackTests { ]) await PopupStack.dismissAllPopups(popupStackID: defaultPopupStackID) - let popupsOnStack = await getPopupsForActiveStack() + let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 0) - } + }} } @@ -252,7 +252,7 @@ private extension PopupStackTests { registerStacks(ids: [defaultPopupStackID]) for popup in popups { await popup.present(popupStackID: defaultPopupStackID) } } - func getPopupsForActiveStack() async -> [AnyPopup] { + func getPopupsForDefaultStack() async -> [AnyPopup] { await PopupStack .fetch(id: defaultPopupStackID)? .popups ?? [] From 1593b47f70f14724715390a3f06f8d6322a1385e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 02:52:16 +0100 Subject: [PATCH 360/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index 822fd9f766..870ecf7a78 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -51,10 +51,10 @@ extension PopupCenterStackViewModelTests { createPopupInstanceForPopupHeightTests(popupHeight: 400) ] - await appendPopupsAndCheckOuterPadding( + await appendPopupsAndCheckOuterHorizontalPadding( popups: popups, isKeyboardActive: false, - expectedValue: .init() + expectedValue: 0 ) } func test_calculateOuterPadding_withKeyboardHidden_whenCustomPaddingSet() async { @@ -64,10 +64,10 @@ extension PopupCenterStackViewModelTests { createPopupInstanceForPopupHeightTests(popupHeight: 400, horizontalPadding: 16) ] - await appendPopupsAndCheckOuterPadding( + await appendPopupsAndCheckOuterHorizontalPadding( popups: popups, isKeyboardActive: false, - expectedValue: .init(top: 0, leading: 16, bottom: 0, trailing: 16) + expectedValue: 16 ) } func test_calculateOuterPadding_withKeyboardShown_whenKeyboardNotOverlapingPopup() async { @@ -77,10 +77,10 @@ extension PopupCenterStackViewModelTests { createPopupInstanceForPopupHeightTests(popupHeight: 400, horizontalPadding: 16) ] - await appendPopupsAndCheckOuterPadding( + await appendPopupsAndCheckOuterHorizontalPadding( popups: popups, isKeyboardActive: true, - expectedValue: .init(top: 0, leading: 16, bottom: 0, trailing: 16) + expectedValue: 16 ) } func test_calculateOuterPadding_withKeyboardShown_whenKeyboardOverlapingPopup() async { @@ -90,19 +90,19 @@ extension PopupCenterStackViewModelTests { createPopupInstanceForPopupHeightTests(popupHeight: 1000, horizontalPadding: 16) ] - await appendPopupsAndCheckOuterPadding( + await appendPopupsAndCheckOuterHorizontalPadding( popups: popups, isKeyboardActive: true, - expectedValue: .init(top: 0, leading: 16, bottom: 250, trailing: 16) + expectedValue: 16 ) } } private extension PopupCenterStackViewModelTests { - func appendPopupsAndCheckOuterPadding(popups: [AnyPopup], isKeyboardActive: Bool, expectedValue: EdgeInsets) async { + func appendPopupsAndCheckOuterHorizontalPadding(popups: [AnyPopup], isKeyboardActive: Bool, expectedValue: CGFloat) async { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: isKeyboardActive, - calculatedValue: { await $0.calculateActivePopupOuterPadding() }, + calculatedValue: { await $0.calculateActivePopupOuterPadding().leading }, expectedValueBuilder: { _ in expectedValue } ) } @@ -234,7 +234,7 @@ private extension PopupCenterStackViewModelTests { let popup = TestPopup(horizontalPadding: horizontalPadding, cornerRadius: cornerRadius) return await AnyPopup(popup).updatedHeight(popupHeight) } - func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) async -> Value, expectedValueBuilder: @escaping (ViewModel) async -> Value) async { Task { + func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) async -> Value, expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.updatePopups(popups) await updatePopups(viewModel) await viewModel.updateScreen(screenHeight: isKeyboardActive ? screenWithKeyboard.height : screen.height, screenSafeArea: isKeyboardActive ? screenWithKeyboard.safeArea : screen.safeArea, isKeyboardActive: isKeyboardActive) @@ -244,7 +244,7 @@ private extension PopupCenterStackViewModelTests { let calculatedValue = await calculatedValue(viewModel) let expectedValue = await expectedValueBuilder(viewModel) XCTAssertEqual(calculatedValue, expectedValue) - }} + } } private extension PopupCenterStackViewModelTests { func updatePopups(_ viewModel: ViewModel) async { From 702d6693a72d5ae07d57b5c898007675c74b423b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 02:58:59 +0100 Subject: [PATCH 361/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index 870ecf7a78..90a5d80ac6 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -231,7 +231,7 @@ private extension PopupCenterStackViewModelTests { // MARK: Methods private extension PopupCenterStackViewModelTests { func createPopupInstanceForPopupHeightTests(popupHeight: CGFloat, horizontalPadding: CGFloat = 0, cornerRadius: CGFloat = 0) async -> AnyPopup { - let popup = TestPopup(horizontalPadding: horizontalPadding, cornerRadius: cornerRadius) + let popup = await TestPopup(horizontalPadding: horizontalPadding, cornerRadius: cornerRadius).setCustomID(UUID().uuidString) return await AnyPopup(popup).updatedHeight(popupHeight) } func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) async -> Value, expectedValueBuilder: @escaping (ViewModel) async -> Value) async { From 550218a4dd7ddd7d8ce8256e04c030b2d17be95b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 03:04:24 +0100 Subject: [PATCH 362/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index 90a5d80ac6..28c5033e45 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -236,10 +236,13 @@ private extension PopupCenterStackViewModelTests { } func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) async -> Value, expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.updatePopups(popups) - await updatePopups(viewModel) + + await Task.sleep(seconds: 0.01) + + await updatePopups() await viewModel.updateScreen(screenHeight: isKeyboardActive ? screenWithKeyboard.height : screen.height, screenSafeArea: isKeyboardActive ? screenWithKeyboard.safeArea : screen.safeArea, isKeyboardActive: isKeyboardActive) - await Task.sleep(seconds: 0.1) + await Task.sleep(seconds: 0.01) let calculatedValue = await calculatedValue(viewModel) let expectedValue = await expectedValueBuilder(viewModel) @@ -247,7 +250,7 @@ private extension PopupCenterStackViewModelTests { } } private extension PopupCenterStackViewModelTests { - func updatePopups(_ viewModel: ViewModel) async { + func updatePopups() async { for popup in viewModel.popups { await viewModel.updatePopupHeight(popup.height!, popup) } } } From 8a21aead8cfb432b82408cf630456fbd005f0894 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 03:07:52 +0100 Subject: [PATCH 363/407] 1 --- Tests/Tests+PopupStack.swift | 56 ++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index ea3463f215..9c554ebeb6 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -64,11 +64,11 @@ extension PopupStackTests { // MARK: Fetch extension PopupStackTests { - func test_fetchStack_whenNoStacksAreRegistered() async { Task { + func test_fetchStack_whenNoStacksAreRegistered() async { let stack = await PopupStack.fetch(id: .bronowice) XCTAssertNil(stack) - }} - func test_fetchStack_whenStackIsNotRegistered() async { Task { + } + func test_fetchStack_whenStackIsNotRegistered() async { registerStacks(ids: [ .krowodrza, .staremiasto, @@ -79,8 +79,8 @@ extension PopupStackTests { let stack = await PopupStack.fetch(id: .bronowice) XCTAssertNil(stack) - }} - func test_fetchStack_whenStackIsRegistered() async { Task { + } + func test_fetchStack_whenStackIsRegistered() async { registerStacks(ids: [ .krowodrza, .staremiasto, @@ -89,12 +89,12 @@ extension PopupStackTests { let stack = await PopupStack.fetch(id: .grzegorzki) XCTAssertNotNil(stack) - }} + } } // MARK: Present Popup extension PopupStackTests { - func test_presentPopup_withThreePopupsToBePresented() async { Task { + func test_presentPopup_withThreePopupsToBePresented() async { await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup2()), @@ -103,8 +103,8 @@ extension PopupStackTests { let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 3) - }} - func test_presentPopup_withPopupsWithSameID() async { Task { + } + func test_presentPopup_withPopupsWithSameID() async { await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup1()), @@ -113,8 +113,8 @@ extension PopupStackTests { let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 2) - }} - func test_presentPopup_withCustomID() async { Task { + } + func test_presentPopup_withCustomID() async { await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup1().setCustomID("2137")), @@ -123,8 +123,8 @@ extension PopupStackTests { let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 3) - }} - func test_presentPopup_withDismissAfter() async { Task { + } + func test_presentPopup_withDismissAfter() async { await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), await AnyPopup(TestBottomPopup1()).dismissAfter(0.7), @@ -143,19 +143,19 @@ extension PopupStackTests { let popupsOnStack3 = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack3.count, 1) - }} + } } // MARK: Dismiss Popup extension PopupStackTests { - func test_dismissLastPopup_withNoPopupsOnStack() async { Task { + func test_dismissLastPopup_withNoPopupsOnStack() async { await registerNewStackAndPresent(popups: []) await PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 0) - }} - func test_dismissLastPopup_withThreePopupsOnStack() async { Task { + } + func test_dismissLastPopup_withThreePopupsOnStack() async { await registerNewStackAndPresent(popups: [ AnyPopup(TestBottomPopup1()), AnyPopup(TestBottomPopup2()), @@ -165,8 +165,8 @@ extension PopupStackTests { let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 2) - }} - func test_dismissPopupWithType_whenPopupOnStack() async { Task { + } + func test_dismissPopupWithType_whenPopupOnStack() async { let popups: [AnyPopup] = await [ .init(TestTopPopup()), .init(TestCenterPopup()), @@ -181,8 +181,8 @@ extension PopupStackTests { let popupsOnStackAfter = await getPopupsForDefaultStack() XCTAssertEqual([popups[0], popups[1]], popupsOnStackAfter) - }} - func test_dismissPopupWithType_whenPopupNotOnStack() async { Task { + } + func test_dismissPopupWithType_whenPopupNotOnStack() async { let popups: [AnyPopup] = await [ .init(TestTopPopup()), .init(TestBottomPopup1()) @@ -196,8 +196,8 @@ extension PopupStackTests { let popupsOnStackAfter = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackAfter) - }} - func test_dismissPopupWithType_whenPopupHasCustomID() async { Task { + } + func test_dismissPopupWithType_whenPopupHasCustomID() async { let popups: [AnyPopup] = await [ .init(TestTopPopup().setCustomID("2137")), .init(TestBottomPopup1()) @@ -211,8 +211,8 @@ extension PopupStackTests { let popupsOnStackAfter = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackAfter) - }} - func test_dismissPopupWithID_whenPopupHasCustomID() async { Task { + } + func test_dismissPopupWithID_whenPopupHasCustomID() async { let popups: [AnyPopup] = await [ .init(TestTopPopup().setCustomID("2137")), .init(TestBottomPopup1()) @@ -226,8 +226,8 @@ extension PopupStackTests { let popupsOnStackAfter = await getPopupsForDefaultStack() XCTAssertEqual([popups[1]], popupsOnStackAfter) - }} - func test_dismissAllPopups() async { Task { + } + func test_dismissAllPopups() async { await registerNewStackAndPresent(popups: [ AnyPopup(TestBottomPopup1()), AnyPopup(TestBottomPopup2()), @@ -237,7 +237,7 @@ extension PopupStackTests { let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 0) - }} + } } From 9bfc1496d92ec8166e34d2ada704ae3a75fe3afb Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 03:14:55 +0100 Subject: [PATCH 364/407] 1 --- Tests/Tests+PopupStack.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 9c554ebeb6..480cd91ff0 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -112,7 +112,7 @@ extension PopupStackTests { ]) let popupsOnStack = await getPopupsForDefaultStack() - XCTAssertEqual(popupsOnStack.count, 2) + XCTAssertEqual(popupsOnStack.count, 1) } func test_presentPopup_withCustomID() async { await registerNewStackAndPresent(popups: [ @@ -127,8 +127,8 @@ extension PopupStackTests { func test_presentPopup_withDismissAfter() async { await registerNewStackAndPresent(popups: [ await AnyPopup(TestBottomPopup1()), - await AnyPopup(TestBottomPopup1()).dismissAfter(0.7), - await AnyPopup(TestBottomPopup1()).dismissAfter(1.5), + await AnyPopup(TestBottomPopup2()).dismissAfter(0.7), + await AnyPopup(TestBottomPopup3()).dismissAfter(1.5), ]) let popupsOnStack1 = await getPopupsForDefaultStack() From c4c72dafd0548b1ec1bd9ed2a2b548eae9dcddf8 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 03:15:35 +0100 Subject: [PATCH 365/407] 1 --- Tests/Tests+PopupStack.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 480cd91ff0..ee3af5ef3e 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -250,7 +250,10 @@ extension PopupStackTests { private extension PopupStackTests { func registerNewStackAndPresent(popups: [any Popup]) async { registerStacks(ids: [defaultPopupStackID]) - for popup in popups { await popup.present(popupStackID: defaultPopupStackID) } + for popup in popups { + await popup.present(popupStackID: defaultPopupStackID) + await Task.sleep(seconds: 0.01) + } } func getPopupsForDefaultStack() async -> [AnyPopup] { await PopupStack From 75d62192cd161359abd6451bf84c631f932d0a0a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 03:19:47 +0100 Subject: [PATCH 366/407] 1 --- Tests/Tests+PopupStack.swift | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index ee3af5ef3e..182ac4e8e3 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -150,7 +150,7 @@ extension PopupStackTests { extension PopupStackTests { func test_dismissLastPopup_withNoPopupsOnStack() async { await registerNewStackAndPresent(popups: []) - await PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) + await performAction { await PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) } let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 0) @@ -161,7 +161,7 @@ extension PopupStackTests { AnyPopup(TestBottomPopup2()), AnyPopup(TestBottomPopup3()) ]) - await PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) + await performAction { await PopupStack.dismissLastPopup(popupStackID: defaultPopupStackID) } let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 2) @@ -177,7 +177,7 @@ extension PopupStackTests { let popupsOnStackBefore = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackBefore) - await PopupStack.dismissPopup(TestBottomPopup1.self, popupStackID: defaultPopupStackID) + await performAction { await PopupStack.dismissPopup(TestBottomPopup1.self, popupStackID: defaultPopupStackID) } let popupsOnStackAfter = await getPopupsForDefaultStack() XCTAssertEqual([popups[0], popups[1]], popupsOnStackAfter) @@ -192,7 +192,7 @@ extension PopupStackTests { let popupsOnStackBefore = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackBefore) - await PopupStack.dismissPopup(TestCenterPopup.self, popupStackID: defaultPopupStackID) + await performAction { await PopupStack.dismissPopup(TestCenterPopup.self, popupStackID: defaultPopupStackID) } let popupsOnStackAfter = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackAfter) @@ -207,7 +207,7 @@ extension PopupStackTests { let popupsOnStackBefore = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackBefore) - await PopupStack.dismissPopup(TestTopPopup.self, popupStackID: defaultPopupStackID) + await performAction { await PopupStack.dismissPopup(TestTopPopup.self, popupStackID: defaultPopupStackID) } let popupsOnStackAfter = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackAfter) @@ -222,7 +222,7 @@ extension PopupStackTests { let popupsOnStackBefore = await getPopupsForDefaultStack() XCTAssertEqual(popups, popupsOnStackBefore) - await PopupStack.dismissPopup("2137", popupStackID: defaultPopupStackID) + await performAction { await PopupStack.dismissPopup("2137", popupStackID: defaultPopupStackID) } let popupsOnStackAfter = await getPopupsForDefaultStack() XCTAssertEqual([popups[1]], popupsOnStackAfter) @@ -233,7 +233,7 @@ extension PopupStackTests { AnyPopup(TestBottomPopup2()), AnyPopup(TestBottomPopup3()) ]) - await PopupStack.dismissAllPopups(popupStackID: defaultPopupStackID) + await performAction { await PopupStack.dismissAllPopups(popupStackID: defaultPopupStackID) } let popupsOnStack = await getPopupsForDefaultStack() XCTAssertEqual(popupsOnStack.count, 0) @@ -255,6 +255,10 @@ private extension PopupStackTests { await Task.sleep(seconds: 0.01) } } + func performAction(_ action: () async -> ()) async { + await action() + await Task.sleep(seconds: 0.01) + } func getPopupsForDefaultStack() async -> [AnyPopup] { await PopupStack .fetch(id: defaultPopupStackID)? From 085e3d8662ff8b0fe22a772ca4bdaacabc5ede1d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 03:20:47 +0100 Subject: [PATCH 367/407] 1 --- Tests/Tests+PopupStack.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 182ac4e8e3..625315cb6c 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -250,10 +250,7 @@ extension PopupStackTests { private extension PopupStackTests { func registerNewStackAndPresent(popups: [any Popup]) async { registerStacks(ids: [defaultPopupStackID]) - for popup in popups { - await popup.present(popupStackID: defaultPopupStackID) - await Task.sleep(seconds: 0.01) - } + for popup in popups { await performAction { await popup.present(popupStackID: defaultPopupStackID) } } } func performAction(_ action: () async -> ()) async { await action() From 882563379c9f5a2893ec474223a5fb6747e12e9c Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 03:22:24 +0100 Subject: [PATCH 368/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index 28c5033e45..af34b9b931 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -108,33 +108,33 @@ private extension PopupCenterStackViewModelTests { } } -// MARK: Corner Radius +// MARK: Corners extension PopupCenterStackViewModelTests { - func test_calculateCornerRadius_withCornerRadiusZero() async { + func test_calculateCorners_withCornerRadiusZero() async { let popups = await [ createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 20), createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 0), ] - await appendPopupsAndCheckCornerRadius( + await appendPopupsAndCheckCorners( popups: popups, expectedValue: [.top: 0, .bottom: 0] ) } - func test_calculateCornerRadius_withCornerRadiusNonZero() async { + func test_calculateCorners_withCornerRadiusNonZero() async { let popups = await [ createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 20), createPopupInstanceForPopupHeightTests(popupHeight: 234, cornerRadius: 24), ] - await appendPopupsAndCheckCornerRadius( + await appendPopupsAndCheckCorners( popups: popups, expectedValue: [.top: 24, .bottom: 24] ) } } private extension PopupCenterStackViewModelTests { - func appendPopupsAndCheckCornerRadius(popups: [AnyPopup], expectedValue: [MijickPopups.PopupAlignment: CGFloat]) async { + func appendPopupsAndCheckCorners(popups: [AnyPopup], expectedValue: [MijickPopups.PopupAlignment: CGFloat]) async { await appendPopupsAndPerformChecks( popups: popups, isKeyboardActive: false, From 052d3dc720a702524b71c5c762f0ab35cb2ec566 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:04:14 +0100 Subject: [PATCH 369/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 570e7328fe..d4a8ab0e67 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -18,13 +18,13 @@ import SwiftUI @ObservedObject private var bottomViewModel: ViewModel = .init(BottomPopupConfig.self) override func setUp() async throws { - setup(topViewModel) - setup(bottomViewModel) + await setup(topViewModel) + await setup(bottomViewModel) } } private extension PopupVerticalStackViewModelTests { - func setup(_ viewModel: ViewModel) { - viewModel.updateScreenValue(screen) + func setup(_ viewModel: ViewModel) async { + await viewModel.updateScreen(screenHeight: screen.height, screenSafeArea: screen.safeArea) viewModel.setup(updatePopupAction: { await self.updatePopupAction(viewModel, $0) }, closePopupAction: { await self.closePopupAction(viewModel, $0) }) } } From fcde02a5287c6d6b55afec0591ac963ce0fbcb8b Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:20:13 +0100 Subject: [PATCH 370/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 120 ++++++++++++------ 1 file changed, 80 insertions(+), 40 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index d4a8ab0e67..c44fd40402 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1304,8 +1304,8 @@ private extension PopupVerticalStackViewModelTests { // MARK: On Drag Gesture Ended extension PopupVerticalStackViewModelTests { func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenNoDragDetents() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 344) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1316,8 +1316,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_1() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440)]) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440)]) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1328,8 +1328,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_2() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520)]) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520)]) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1340,8 +1340,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_3() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520)]) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520)]) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1352,8 +1352,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_4() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520), .large, .fullscreen]) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520), .large, .fullscreen]) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1364,8 +1364,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_bottomPopupsAlignment_5() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520), .large, .fullscreen]) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520), .large, .fullscreen]) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1376,8 +1376,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_topPopupsAlignment_1() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520), .large, .fullscreen]) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520), .large, .fullscreen]) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1388,8 +1388,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureEnded_withNegativeDragValue_whenDragDetentsSet_topPopupsAlignment_2() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520), .large, .fullscreen]) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 344, dragDetents: [.height(440), .height(520), .large, .fullscreen]) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1400,8 +1400,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_bottomPopupsAlignment_1() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 400) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 400) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1412,8 +1412,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_bottomPopupsAlignment_2() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 400) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 400) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1424,8 +1424,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_topPopupsAlignment_1() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 400) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 400) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1436,8 +1436,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_topPopupsAlignment_2() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 400, dragDetents: [.large]) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 400, dragDetents: [.large]) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1448,8 +1448,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureEnded_withPositiveDragValue_topPopupsAlignment_3() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 400, dragDetents: [.large]) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 400, dragDetents: [.large]) ] await appendPopupsAndCheckGestureTranslationOnEnd( @@ -1480,12 +1480,11 @@ private extension PopupVerticalStackViewModelTests { // MARK: Methods private extension PopupVerticalStackViewModelTests { - func createPopupInstanceForPopupHeightTests(type: C.Type, heightMode: HeightMode, popupHeight: CGFloat, popupDragHeight: CGFloat? = nil, ignoredSafeAreaEdges: Edge.Set = [], popupPadding: EdgeInsets = .init(), cornerRadius: CGFloat = 0, dragGestureEnabled: Bool = true, dragDetents: [DragDetent] = []) -> AnyPopup { - let config = getConfigForPopupHeightTests(type: type, heightMode: heightMode, ignoredSafeAreaEdges: ignoredSafeAreaEdges, popupPadding: popupPadding, cornerRadius: cornerRadius, dragGestureEnabled: dragGestureEnabled, dragDetents: dragDetents) - - return AnyPopup.t_createNew(config: config) - .settingHeight(popupHeight) - .settingDragHeight(popupDragHeight) + func createPopupInstanceForPopupHeightTests(alignment: PopupAlignment, heightMode: HeightMode, popupHeight: CGFloat, popupDragHeight: CGFloat = 0, ignoredSafeAreaEdges: Edge.Set = [], popupPadding: EdgeInsets = .init(), cornerRadius: CGFloat = 0, dragGestureEnabled: Bool = true, dragDetents: [DragDetent] = []) async -> AnyPopup { + let popup = getTestPopup(alignment, heightMode, popupHeight, popupDragHeight, ignoredSafeAreaEdges, popupPadding, cornerRadius, dragGestureEnabled, dragDetents) + return await AnyPopup(popup) + .updatedHeight(popupHeight) + .updatedDragHeight(popupDragHeight) } func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.updatePopups(popups) @@ -1498,14 +1497,11 @@ private extension PopupVerticalStackViewModelTests { } } private extension PopupVerticalStackViewModelTests { - func getConfigForPopupHeightTests(type: C.Type, heightMode: HeightMode, ignoredSafeAreaEdges: Edge.Set, popupPadding: EdgeInsets, cornerRadius: CGFloat, dragGestureEnabled: Bool, dragDetents: [DragDetent]) -> C { .t_createNew( - popupPadding: popupPadding, - cornerRadius: cornerRadius, - ignoredSafeAreaEdges: ignoredSafeAreaEdges, - heightMode: heightMode, - dragDetents: dragDetents, - isDragGestureEnabled: dragGestureEnabled - )} + func getTestPopup(_ alignment: PopupAlignment, _ heightMode: HeightMode, _ popupHeight: CGFloat, _ popupDragHeight: CGFloat, _ ignoredSafeAreaEdges: Edge.Set, _ popupPadding: EdgeInsets, _ cornerRadius: CGFloat, _ dragGestureEnabled: Bool, _ dragDetents: [DragDetent]) -> any Popup { switch alignment { + case .top: TestTopPopup(popupPadding: popupPadding, cornerRadius: cornerRadius, ignoredSafeAreaEdges: ignoredSafeAreaEdges, heightMode: heightMode, dragDetents: dragDetents, dragGestureEnabled: dragGestureEnabled) + case .bottom: TestBottomPopup(popupPadding: popupPadding, cornerRadius: cornerRadius, ignoredSafeAreaEdges: ignoredSafeAreaEdges, heightMode: heightMode, dragDetents: dragDetents, dragGestureEnabled: dragGestureEnabled) + case .center: fatalError() + }} func updatePopups(_ viewModel: ViewModel) async { for popup in viewModel.popups { await viewModel.updatePopupHeight(popup.height!, popup) } } @@ -1523,3 +1519,47 @@ private extension PopupVerticalStackViewModelTests { private extension PopupVerticalStackViewModelTests { typealias ViewModel = VM.VerticalStack } + +// MARK: Test Popups +private struct TestTopPopup: TopPopup { + let popupPadding: EdgeInsets + let cornerRadius: CGFloat + let ignoredSafeAreaEdges: Edge.Set + let heightMode: HeightMode + let dragDetents: [DragDetent] + let dragGestureEnabled: Bool + + + func configurePopup(config: LocalConfigVertical) -> LocalConfigVertical { config + .popupTopPadding(popupPadding.top) + .popupBottomPadding(popupPadding.bottom) + .popupHorizontalPadding(popupPadding.leading) + .cornerRadius(cornerRadius) + .ignoreSafeArea(edges: ignoredSafeAreaEdges) + .heightMode(heightMode) + .dragDetents(dragDetents) + .enableDragGesture(dragGestureEnabled) + } + var body: some View { EmptyView() } +} +private struct TestBottomPopup: BottomPopup { + let popupPadding: EdgeInsets + let cornerRadius: CGFloat + let ignoredSafeAreaEdges: Edge.Set + let heightMode: HeightMode + let dragDetents: [DragDetent] + let dragGestureEnabled: Bool + + + func configurePopup(config: LocalConfigVertical) -> LocalConfigVertical { config + .popupTopPadding(popupPadding.top) + .popupBottomPadding(popupPadding.bottom) + .popupHorizontalPadding(popupPadding.leading) + .cornerRadius(cornerRadius) + .ignoreSafeArea(edges: ignoredSafeAreaEdges) + .heightMode(heightMode) + .dragDetents(dragDetents) + .enableDragGesture(dragGestureEnabled) + } + var body: some View { EmptyView() } +} From ece7af09c4c405f29853ba030058da6b58980ec4 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:21:56 +0100 Subject: [PATCH 371/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index c44fd40402..4fc9fe5a08 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1206,8 +1206,8 @@ private extension PopupVerticalStackViewModelTests { // MARK: On Drag Gesture Changed extension PopupVerticalStackViewModelTests { func test_calculateValuesOnDragGestureChanged_withPositiveDragValue_whenDragGestureDisabled() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragGestureEnabled: false) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 344, dragGestureEnabled: false) ] await appendPopupsAndCheckGestureTranslationOnChange( @@ -1218,8 +1218,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureChanged_withPositiveDragValue_whenDragGestureEnabled_bottomPopupsAlignment() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 344) ] await appendPopupsAndCheckGestureTranslationOnChange( @@ -1230,8 +1230,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureChanged_withPositiveDragValue_whenDragGestureEnabled_topPopupsAlignment() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 344) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 344) ] await appendPopupsAndCheckGestureTranslationOnChange( @@ -1242,8 +1242,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenNoDragDetents() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: []) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 344, dragDetents: []) ] await appendPopupsAndCheckGestureTranslationOnChange( @@ -1254,8 +1254,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenDragDetents() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(450)]) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 344, dragDetents: [.height(450)]) ] await appendPopupsAndCheckGestureTranslationOnChange( @@ -1266,8 +1266,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenDragDetentsLessThanDragValue_bottomPopupsAlignment() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(370)]) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 344, dragDetents: [.height(370)]) ] await appendPopupsAndCheckGestureTranslationOnChange( @@ -1278,8 +1278,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateValuesOnDragGestureChanged_withNegativeDragValue_whenDragDetentsLessThanDragValue_topPopupsAlignment() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 344, dragDetents: [.height(370)]) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 344, dragDetents: [.height(370)]) ] await appendPopupsAndCheckGestureTranslationOnChange( From 6468bd70cf8b37dddaba2c767a9f7740af148b57 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:25:07 +0100 Subject: [PATCH 372/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 4fc9fe5a08..c69196d937 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1091,10 +1091,10 @@ private extension PopupVerticalStackViewModelTests { // MARK: Stack Overlay Opacity extension PopupVerticalStackViewModelTests { func test_calculateStackOverlayOpacity_withThreePopupsStacked_whenNoGestureTranslation_last() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 233), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 512) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 1360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 233), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 512) ] await appendPopupsAndCheckStackOverlayOpacity( @@ -1106,11 +1106,11 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateStackOverlayOpacity_withFourPopupsStacked_whenNoGestureTranslation_second() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 233), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 512), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 812) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 1360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 233), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 512), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 812) ] await appendPopupsAndCheckStackOverlayOpacity( @@ -1122,11 +1122,11 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateStackOverlayOpacity_withFourPopupsStacked_whenGestureTranslationIsNegative_last() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 233), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 512), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 812) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 1360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 233), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 512), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 812) ] await appendPopupsAndCheckStackOverlayOpacity( @@ -1138,17 +1138,17 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateStackOverlayOpacity_withTenPopupsStacked_whenGestureTranslationIsNegative_first() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 55), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 233), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 512), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 812), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 34), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 664), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 754), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 357), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1234), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 356) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 55), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 233), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 512), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 812), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 34), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 664), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 754), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 357), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1234), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 356) ] await appendPopupsAndCheckStackOverlayOpacity( @@ -1160,10 +1160,10 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateStackOverlayOpacity_withThreePopupsStacked_whenGestureTranslationIsPositive_last() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 233), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 512) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 1360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 233), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 512) ] await appendPopupsAndCheckStackOverlayOpacity( @@ -1175,11 +1175,11 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateStackOverlayOpacity_withFourPopupsStacked_whenGestureTranslationIsPositive_nextToLast() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 233), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 512), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 343) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 1360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 233), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 512), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 343) ] await appendPopupsAndCheckStackOverlayOpacity( From 82c64c0a88910f2f948b9ba18745ce70b31c318a Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:27:38 +0100 Subject: [PATCH 373/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index c69196d937..23891e5871 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1020,9 +1020,9 @@ private extension PopupVerticalStackViewModelTests { // MARK: Fixed Size extension PopupVerticalStackViewModelTests { func test_calculateFixedSize_withAutoHeightMode_whenLessThanScreen_twoPopupsStacked() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 123) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 123) ] await appendPopupsAndCheckVerticalFixedSize( @@ -1033,9 +1033,9 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateFixedSize_withAutoHeightMode_whenBiggerThanScreen_twoPopupsStacked() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1223) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1223) ] await appendPopupsAndCheckVerticalFixedSize( @@ -1046,10 +1046,10 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateFixedSize_withLargeHeightMode_threePopupsStacked() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1223), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 1223) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 1360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1223), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 1223) ] await appendPopupsAndCheckVerticalFixedSize( @@ -1060,12 +1060,12 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateFixedSize_withFullscreenHeightMode_fivePopupsStacked() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1223), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 1223), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1223), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1223) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 1360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1223), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 1223), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1223), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 1223) ] await appendPopupsAndCheckVerticalFixedSize( From 6ab848ddf54c8367800b6dff7e10c96f9ff4e2b9 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:30:14 +0100 Subject: [PATCH 374/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 92 +++++++++---------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 23891e5871..973f39907c 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -565,7 +565,7 @@ extension PopupVerticalStackViewModelTests { // MARK: Outer Padding extension PopupVerticalStackViewModelTests { func test_calculateOuterPadding_withAutoHeightMode_whenLessThanScreen() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] @@ -577,7 +577,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOuterPadding_withAutoHeightMode_almostLikeScreen_onlyOnePaddingShouldBeNonZero() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 877, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] @@ -589,7 +589,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOuterPadding_withAutoHeightMode_almostLikeScreen_bothPaddingsShouldBeNonZero() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 861, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] @@ -601,7 +601,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOuterPadding_withAutoHeightMode_almostLikeScreen_topPopupsAlignment() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 911, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] @@ -613,7 +613,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOuterPadding_withAutoHeightMode_whenBiggerThanScreen() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1100, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] @@ -625,7 +625,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOuterPadding_withLargeHeightMode() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] @@ -637,7 +637,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateOuterPadding_withFullscreenHeightMode() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] @@ -664,7 +664,7 @@ private extension PopupVerticalStackViewModelTests { // MARK: Inner Padding extension PopupVerticalStackViewModelTests { func test_calculateInnerPadding_withDefaultSettings() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 350) ] @@ -676,7 +676,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateInnerPadding_withIgnoringSafeArea_bottom() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 200, ignoredSafeAreaEdges: .bottom) ] @@ -688,7 +688,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateInnerPadding_withIgnoringSafeArea_all() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1200, ignoredSafeAreaEdges: .all) ] @@ -700,7 +700,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateInnerPadding_withPopupPadding() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1200, popupPadding: .init(top: 21, leading: 12, bottom: 37, trailing: 12)) ] @@ -712,7 +712,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateInnerPadding_withFullscreenHeightMode_ignoringSafeArea_top() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100, ignoredSafeAreaEdges: .top) ] @@ -724,7 +724,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateInnerPadding_withGestureTranslation() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 800) ] @@ -736,7 +736,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateInnerPadding_withGestureTranslation_dragHeight() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupDragHeight: 700) ] @@ -748,7 +748,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateInnerPadding_withGestureTranslation_dragHeight_topPopupsAlignment() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 300, popupDragHeight: 700) ] @@ -775,7 +775,7 @@ private extension PopupVerticalStackViewModelTests { // MARK: Translation Progress extension PopupVerticalStackViewModelTests { func test_calculateTranslationProgress_withNoGestureTranslation() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300) ] @@ -787,7 +787,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateTranslationProgress_withPositiveGestureTranslation() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300) ] @@ -799,7 +799,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateTranslationProgress_withPositiveGestureTranslation_dragHeight() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupDragHeight: 120) ] @@ -811,7 +811,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateTranslationProgress_withNegativeGestureTranslation() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300) ] @@ -823,7 +823,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateTranslationProgress_withNegativeGestureTranslation_whenTopPopupsAlignment() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 300) ] @@ -850,7 +850,7 @@ private extension PopupVerticalStackViewModelTests { // MARK: Corner Radius extension PopupVerticalStackViewModelTests { func test_calculateCornerRadius_withTwoPopupsStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 1), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 12) ] @@ -863,7 +863,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateCornerRadius_withPopupPadding_bottom_first() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupPadding: .init(top: 0, leading: 0, bottom: 12, trailing: 0), cornerRadius: 1), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 12) ] @@ -876,7 +876,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateCornerRadius_withPopupPadding_bottom_last() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 1), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupPadding: .init(top: 0, leading: 0, bottom: 12, trailing: 0), cornerRadius: 12) ] @@ -889,7 +889,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateCornerRadius_withPopupPadding_all() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 1), createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupPadding: .init(top: 12, leading: 24, bottom: 12, trailing: 24), cornerRadius: 12) ] @@ -902,7 +902,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateCornerRadius_fullscreen() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 300, cornerRadius: 13) ] @@ -914,7 +914,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateCornerRadius_whenPopupsHaveTopAlignment() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 12) ] @@ -941,10 +941,10 @@ private extension PopupVerticalStackViewModelTests { // MARK: Scale X extension PopupVerticalStackViewModelTests { func test_calculateScaleX_withNoGestureTranslation_threePopupsStacked_last() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 360) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 120), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 360) ] await appendPopupsAndCheckScaleX( @@ -956,11 +956,11 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateScaleX_withNoGestureTranslation_fourPopupsStacked_second() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1360) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 120), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1360) ] await appendPopupsAndCheckScaleX( @@ -972,11 +972,11 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateScaleX_withNegativeGestureTranslation_fourPopupsStacked_third() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1360) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 120), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1360) ] await appendPopupsAndCheckScaleX( @@ -988,12 +988,12 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateScaleX_withPositiveGestureTranslation_fivePopupsStacked_second() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1360), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 123) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 120), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1360), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 123) ] await appendPopupsAndCheckScaleX( From e4829637ef020a8f4c210d6f51d57663043356cd Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:32:49 +0100 Subject: [PATCH 375/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 973f39907c..6e60d51863 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -665,7 +665,7 @@ private extension PopupVerticalStackViewModelTests { extension PopupVerticalStackViewModelTests { func test_calculateInnerPadding_withDefaultSettings() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 350) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 350) ] await appendPopupsAndCheckInnerPadding( @@ -677,7 +677,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateInnerPadding_withIgnoringSafeArea_bottom() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 200, ignoredSafeAreaEdges: .bottom) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 200, ignoredSafeAreaEdges: .bottom) ] await appendPopupsAndCheckInnerPadding( @@ -689,7 +689,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateInnerPadding_withIgnoringSafeArea_all() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1200, ignoredSafeAreaEdges: .all) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1200, ignoredSafeAreaEdges: .all) ] await appendPopupsAndCheckInnerPadding( @@ -701,7 +701,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateInnerPadding_withPopupPadding() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1200, popupPadding: .init(top: 21, leading: 12, bottom: 37, trailing: 12)) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1200, popupPadding: .init(top: 21, leading: 12, bottom: 37, trailing: 12)) ] await appendPopupsAndCheckInnerPadding( @@ -713,7 +713,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateInnerPadding_withFullscreenHeightMode_ignoringSafeArea_top() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100, ignoredSafeAreaEdges: .top) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 100, ignoredSafeAreaEdges: .top) ] await appendPopupsAndCheckInnerPadding( @@ -725,7 +725,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateInnerPadding_withGestureTranslation() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 800) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 800) ] await appendPopupsAndCheckInnerPadding( @@ -737,7 +737,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateInnerPadding_withGestureTranslation_dragHeight() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupDragHeight: 700) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300, popupDragHeight: 700) ] await appendPopupsAndCheckInnerPadding( @@ -749,7 +749,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateInnerPadding_withGestureTranslation_dragHeight_topPopupsAlignment() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 300, popupDragHeight: 700) + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 300, popupDragHeight: 700) ] await appendPopupsAndCheckInnerPadding( @@ -776,7 +776,7 @@ private extension PopupVerticalStackViewModelTests { extension PopupVerticalStackViewModelTests { func test_calculateTranslationProgress_withNoGestureTranslation() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300) ] await appendPopupsAndCheckTranslationProgress( @@ -788,7 +788,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateTranslationProgress_withPositiveGestureTranslation() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300) ] await appendPopupsAndCheckTranslationProgress( @@ -800,7 +800,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateTranslationProgress_withPositiveGestureTranslation_dragHeight() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupDragHeight: 120) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300, popupDragHeight: 120) ] await appendPopupsAndCheckTranslationProgress( @@ -812,7 +812,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateTranslationProgress_withNegativeGestureTranslation() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300) ] await appendPopupsAndCheckTranslationProgress( @@ -824,7 +824,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateTranslationProgress_withNegativeGestureTranslation_whenTopPopupsAlignment() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 300) + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 300) ] await appendPopupsAndCheckTranslationProgress( @@ -851,8 +851,8 @@ private extension PopupVerticalStackViewModelTests { extension PopupVerticalStackViewModelTests { func test_calculateCornerRadius_withTwoPopupsStacked() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 1), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 12) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300, cornerRadius: 1), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300, cornerRadius: 12) ] await appendPopupsAndCheckCornerRadius( @@ -864,8 +864,8 @@ extension PopupVerticalStackViewModelTests { } func test_calculateCornerRadius_withPopupPadding_bottom_first() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupPadding: .init(top: 0, leading: 0, bottom: 12, trailing: 0), cornerRadius: 1), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 12) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300, popupPadding: .init(top: 0, leading: 0, bottom: 12, trailing: 0), cornerRadius: 1), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300, cornerRadius: 12) ] await appendPopupsAndCheckCornerRadius( @@ -877,8 +877,8 @@ extension PopupVerticalStackViewModelTests { } func test_calculateCornerRadius_withPopupPadding_bottom_last() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 1), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupPadding: .init(top: 0, leading: 0, bottom: 12, trailing: 0), cornerRadius: 12) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300, cornerRadius: 1), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300, popupPadding: .init(top: 0, leading: 0, bottom: 12, trailing: 0), cornerRadius: 12) ] await appendPopupsAndCheckCornerRadius( @@ -890,8 +890,8 @@ extension PopupVerticalStackViewModelTests { } func test_calculateCornerRadius_withPopupPadding_all() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 1), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300, popupPadding: .init(top: 12, leading: 24, bottom: 12, trailing: 24), cornerRadius: 12) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300, cornerRadius: 1), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300, popupPadding: .init(top: 12, leading: 24, bottom: 12, trailing: 24), cornerRadius: 12) ] await appendPopupsAndCheckCornerRadius( @@ -903,7 +903,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateCornerRadius_fullscreen() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 300, cornerRadius: 13) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 300, cornerRadius: 13) ] await appendPopupsAndCheckCornerRadius( @@ -915,7 +915,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateCornerRadius_whenPopupsHaveTopAlignment() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 300, cornerRadius: 12) + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 300, cornerRadius: 12) ] await appendPopupsAndCheckCornerRadius( From 2315558a56d1cc433e0cb25e01dfdf10a43cfff5 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:33:52 +0100 Subject: [PATCH 376/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 6e60d51863..2c56ceb3e4 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -566,7 +566,7 @@ extension PopupVerticalStackViewModelTests { extension PopupVerticalStackViewModelTests { func test_calculateOuterPadding_withAutoHeightMode_whenLessThanScreen() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] await appendPopupsAndCheckOuterPadding( @@ -578,7 +578,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOuterPadding_withAutoHeightMode_almostLikeScreen_onlyOnePaddingShouldBeNonZero() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 877, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 877, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] await appendPopupsAndCheckOuterPadding( @@ -590,7 +590,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOuterPadding_withAutoHeightMode_almostLikeScreen_bothPaddingsShouldBeNonZero() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 861, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 861, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] await appendPopupsAndCheckOuterPadding( @@ -602,7 +602,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOuterPadding_withAutoHeightMode_almostLikeScreen_topPopupsAlignment() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 911, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 911, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] await appendPopupsAndCheckOuterPadding( @@ -614,7 +614,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOuterPadding_withAutoHeightMode_whenBiggerThanScreen() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1100, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1100, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] await appendPopupsAndCheckOuterPadding( @@ -626,7 +626,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOuterPadding_withLargeHeightMode() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] await appendPopupsAndCheckOuterPadding( @@ -638,7 +638,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOuterPadding_withFullscreenHeightMode() async { let popups = await [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) + createPopupInstanceForPopupHeightTests(alignment: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] await appendPopupsAndCheckOuterPadding( From 2750f4aa02679f28faba5792e73a40c04ef6b533 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:34:02 +0100 Subject: [PATCH 377/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 2c56ceb3e4..28c1977b3d 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -638,7 +638,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOuterPadding_withFullscreenHeightMode() async { let popups = await [ - createPopupInstanceForPopupHeightTests(alignment: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 344, popupPadding: .init(top: 12, leading: 17, bottom: 33, trailing: 17)) ] await appendPopupsAndCheckOuterPadding( From 9c9908f78210272ea2485fd0f9dacf5c6fa8a599 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:35:52 +0100 Subject: [PATCH 378/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 158 +++++++++--------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 28c1977b3d..b3069747ae 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -53,7 +53,7 @@ private extension PopupVerticalStackViewModelTests { extension PopupVerticalStackViewModelTests { func test_getInvertedIndex_1() async { await bottomViewModel.updatePopups([ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150) ]) XCTAssertEqual( @@ -63,11 +63,11 @@ extension PopupVerticalStackViewModelTests { } func test_getInvertedIndex_2() async { await bottomViewModel.updatePopups([ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150) ]) XCTAssertEqual( @@ -81,7 +81,7 @@ extension PopupVerticalStackViewModelTests { extension PopupVerticalStackViewModelTests { func test_updatePopup_1() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 0) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 0) ] let updatedPopup = await popups[0] .updatedHeight(100) @@ -96,11 +96,11 @@ extension PopupVerticalStackViewModelTests { } func test_updatePopup_2() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 50), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 25), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 15), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2137) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 100), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 50), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 25), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 15), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 2137) ] let updatedPopup = await popups[2].updatedHeight(1371) @@ -113,12 +113,12 @@ extension PopupVerticalStackViewModelTests { } func test_updatePopup_3() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 50), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 25), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 15), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2137), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 77) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 100), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 50), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 25), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 15), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 2137), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 77) ] let updatedPopup = await popups[4].updatedHeight(nil) @@ -146,7 +146,7 @@ private extension PopupVerticalStackViewModelTests { extension PopupVerticalStackViewModelTests { func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_onePopupStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150) ] await appendPopupsAndCheckPopupHeight( @@ -158,10 +158,10 @@ extension PopupVerticalStackViewModelTests { } func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_fourPopupsStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 200), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 200), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 100) ] await appendPopupsAndCheckPopupHeight( @@ -173,7 +173,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_onePopupStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2000) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 2000) ] await appendPopupsAndCheckPopupHeight( @@ -185,11 +185,11 @@ extension PopupVerticalStackViewModelTests { } func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_fivePopupStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 150), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 200), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 300), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2000) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 200), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 100), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 2000) ] await appendPopupsAndCheckPopupHeight( @@ -201,7 +201,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculatePopupHeight_withLargeHeightMode_whenOnePopupStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 100) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 100) ] await appendPopupsAndCheckPopupHeight( @@ -213,9 +213,9 @@ extension PopupVerticalStackViewModelTests { } func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 100), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 700), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 1000) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 100), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 700), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 1000) ] await appendPopupsAndCheckPopupHeight( @@ -227,7 +227,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculatePopupHeight_withFullscreenHeightMode_whenOnePopupStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 100) ] await appendPopupsAndCheckPopupHeight( @@ -239,9 +239,9 @@ extension PopupVerticalStackViewModelTests { } func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 2000), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 3000) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 100), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 2000), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 3000) ] await appendPopupsAndCheckPopupHeight( @@ -253,9 +253,9 @@ extension PopupVerticalStackViewModelTests { } func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupsStacked_popupPadding() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 2000), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 3000, popupPadding: .init(top: 33, leading: 15, bottom: 21, trailing: 15)) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 100), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 2000), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 3000, popupPadding: .init(top: 33, leading: 15, bottom: 21, trailing: 15)) ] await appendPopupsAndCheckPopupHeight( @@ -267,9 +267,9 @@ extension PopupVerticalStackViewModelTests { } func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked_popupPadding() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 100), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 2000), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 3000, popupPadding: .init(top: 33, leading: 15, bottom: 21, trailing: 15)) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 100), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 2000), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 3000, popupPadding: .init(top: 33, leading: 15, bottom: 21, trailing: 15)) ] await appendPopupsAndCheckPopupHeight( @@ -308,7 +308,7 @@ private extension PopupVerticalStackViewModelTests { extension PopupVerticalStackViewModelTests { func test_calculateActivePopupHeight_withAutoHeightMode_whenLessThanScreen_onePopupStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 100) ] await appendPopupsAndCheckActivePopupHeight( @@ -320,9 +320,9 @@ extension PopupVerticalStackViewModelTests { } func test_calculateActivePopupHeight_withAutoHeightMode_whenBiggerThanScreen_threePopupsStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 3000), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1000), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2000) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 3000), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1000), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 2000) ] await appendPopupsAndCheckActivePopupHeight( @@ -334,9 +334,9 @@ extension PopupVerticalStackViewModelTests { } func test_calculateActivePopupHeight_withLargeHeightMode_whenThreePopupsStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1000), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 2000) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 350), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 1000), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 2000) ] await appendPopupsAndCheckActivePopupHeight( @@ -348,8 +348,8 @@ extension PopupVerticalStackViewModelTests { } func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsNegative_twoPopupsStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 2000) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 350), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 2000) ] await appendPopupsAndCheckActivePopupHeight( @@ -361,7 +361,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateActivePopupHeight_withLargeHeightMode_whenGestureIsNegative_onePopupStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 350) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 350) ] await appendPopupsAndCheckActivePopupHeight( @@ -373,8 +373,8 @@ extension PopupVerticalStackViewModelTests { } func test_calculateActivePopupHeight_withFullscreenHeightMode_whenGestureIsNegative_twoPopupsStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 100), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 250) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 100), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 250) ] await appendPopupsAndCheckActivePopupHeight( @@ -386,9 +386,9 @@ extension PopupVerticalStackViewModelTests { } func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsPositive_threePopupsStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .large, popupHeight: 350), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 1000), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 850) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 350), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 1000), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 850) ] await appendPopupsAndCheckActivePopupHeight( @@ -400,7 +400,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateActivePopupHeight_withFullscreenHeightMode_whenGestureIsPositive_onePopupStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 350) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 350) ] await appendPopupsAndCheckActivePopupHeight( @@ -412,8 +412,8 @@ extension PopupVerticalStackViewModelTests { } func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsNegative_hasDragHeightStored_twoPopupsStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .fullscreen, popupHeight: 350), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 500, popupDragHeight: 100) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 350), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 500, popupDragHeight: 100) ] await appendPopupsAndCheckActivePopupHeight( @@ -425,7 +425,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsPositive_hasDragHeightStored_onePopupStacked() async { let popups = [ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 1300, popupDragHeight: 100) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1300, popupDragHeight: 100) ] await appendPopupsAndCheckActivePopupHeight( @@ -464,11 +464,11 @@ private extension PopupVerticalStackViewModelTests { extension PopupVerticalStackViewModelTests { func test_calculateOffsetY_withZeroGestureTranslation_fivePopupsStacked_thirdElement() async { await bottomViewModel.updatePopups([ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 240), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 670), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 310) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 350), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 120), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 240), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 670), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 310) ]) XCTAssertEqual( @@ -478,11 +478,11 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOffsetY_withZeroGestureTranslation_fivePopupsStacked_lastElement() async { await bottomViewModel.updatePopups([ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 120), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 240), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 670), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 310) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 350), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 120), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 240), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 670), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 310) ]) XCTAssertEqual( @@ -492,7 +492,7 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOffsetY_withNegativeGestureTranslation_dragHeight_onePopupStacked() async { await bottomViewModel.updatePopups([ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 100) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 350, popupDragHeight: 100) ]) await bottomViewModel.updateGestureTranslation(-100) @@ -503,8 +503,8 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOffsetY_withPositiveGestureTranslation_dragHeight_twoPopupsStacked_firstElement() async { await bottomViewModel.updatePopups([ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) await bottomViewModel.updateGestureTranslation(100) @@ -515,8 +515,8 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOffsetY_withPositiveGestureTranslation_dragHeight_twoPopupsStacked_lastElement() async { await bottomViewModel.updatePopups([ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) await bottomViewModel.updateGestureTranslation(100) @@ -527,8 +527,8 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOffsetY_withStackingDisabled() async { await bottomViewModel.updatePopups([ - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), - createPopupInstanceForPopupHeightTests(type: BottomPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), + createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) GlobalConfigContainer.vertical.isStackingEnabled = false From 48b8269f15c5f2af15616ebda2adac668a94320d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:37:02 +0100 Subject: [PATCH 379/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index b3069747ae..06f343a151 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -280,8 +280,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withLargeHeightMode_whenPopupsHaveTopAlignment() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .large, popupHeight: 100) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .large, popupHeight: 100) ] await appendPopupsAndCheckPopupHeight( @@ -307,7 +307,7 @@ private extension PopupVerticalStackViewModelTests { // MARK: Active Popup Height extension PopupVerticalStackViewModelTests { func test_calculateActivePopupHeight_withAutoHeightMode_whenLessThanScreen_onePopupStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 100) ] @@ -319,7 +319,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateActivePopupHeight_withAutoHeightMode_whenBiggerThanScreen_threePopupsStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 3000), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1000), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 2000) @@ -333,7 +333,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateActivePopupHeight_withLargeHeightMode_whenThreePopupsStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 350), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 1000), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 2000) @@ -347,7 +347,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsNegative_twoPopupsStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 350), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 2000) ] @@ -360,7 +360,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateActivePopupHeight_withLargeHeightMode_whenGestureIsNegative_onePopupStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 350) ] @@ -372,7 +372,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateActivePopupHeight_withFullscreenHeightMode_whenGestureIsNegative_twoPopupsStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 100), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 250) ] @@ -385,7 +385,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsPositive_threePopupsStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 350), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 1000), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 850) @@ -399,7 +399,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateActivePopupHeight_withFullscreenHeightMode_whenGestureIsPositive_onePopupStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 350) ] @@ -411,7 +411,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsNegative_hasDragHeightStored_twoPopupsStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 350), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 500, popupDragHeight: 100) ] @@ -424,7 +424,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateActivePopupHeight_withAutoHeightMode_whenGestureIsPositive_hasDragHeightStored_onePopupStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 1300, popupDragHeight: 100) ] @@ -436,8 +436,8 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculateActivePopupHeight_withPopupsHaveTopAlignment() async { - let popups = [ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .large, popupHeight: 1300) + let popups = await [ + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .large, popupHeight: 1300) ] await appendPopupsAndCheckActivePopupHeight( @@ -539,8 +539,8 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOffsetY_withPopupsHaveTopAlignment_1() async { await topViewModel.updatePopups([ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) XCTAssertEqual( @@ -550,8 +550,8 @@ extension PopupVerticalStackViewModelTests { } func test_calculateOffsetY_withPopupsHaveTopAlignment_2() async { await topViewModel.updatePopups([ - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), - createPopupInstanceForPopupHeightTests(type: TopPopupConfig.self, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), + createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) await topViewModel.updateGestureTranslation(-100) From 439621c72cc861d34bde196ed92184177d7f2db6 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:37:40 +0100 Subject: [PATCH 380/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 06f343a151..3a9b8c64ff 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -80,7 +80,7 @@ extension PopupVerticalStackViewModelTests { // MARK: Update Popup extension PopupVerticalStackViewModelTests { func test_updatePopup_1() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 0) ] let updatedPopup = await popups[0] @@ -95,7 +95,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_updatePopup_2() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 100), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 50), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 25), @@ -112,7 +112,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_updatePopup_3() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 100), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 50), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 25), @@ -145,7 +145,7 @@ private extension PopupVerticalStackViewModelTests { // MARK: Popup Height extension PopupVerticalStackViewModelTests { func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_onePopupStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150) ] @@ -157,7 +157,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withAutoHeightMode_whenLessThanScreen_fourPopupsStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 200), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300), @@ -172,7 +172,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_onePopupStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 2000) ] @@ -184,7 +184,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withAutoHeightMode_whenBiggerThanScreen_fivePopupStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 200), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 300), @@ -200,7 +200,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withLargeHeightMode_whenOnePopupStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 100) ] @@ -212,7 +212,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 100), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 700), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 1000) @@ -226,7 +226,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withFullscreenHeightMode_whenOnePopupStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 100) ] @@ -238,7 +238,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 100), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 2000), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 3000) @@ -252,7 +252,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withLargeHeightMode_whenThreePopupsStacked_popupPadding() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 100), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 2000), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .large, popupHeight: 3000, popupPadding: .init(top: 33, leading: 15, bottom: 21, trailing: 15)) @@ -266,7 +266,7 @@ extension PopupVerticalStackViewModelTests { ) } func test_calculatePopupHeight_withFullscreenHeightMode_whenThreePopupsStacked_popupPadding() async { - let popups = [ + let popups = await [ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 100), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 2000), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .fullscreen, popupHeight: 3000, popupPadding: .init(top: 33, leading: 15, bottom: 21, trailing: 15)) From b5ea047e0aa6221f260009ece8f755a59f3847be Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 12:54:36 +0100 Subject: [PATCH 381/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 3a9b8c64ff..28cb15bd78 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1530,7 +1530,7 @@ private struct TestTopPopup: TopPopup { let dragGestureEnabled: Bool - func configurePopup(config: LocalConfigVertical) -> LocalConfigVertical { config + func configurePopup(config: TopPopupConfig) -> TopPopupConfig { config .popupTopPadding(popupPadding.top) .popupBottomPadding(popupPadding.bottom) .popupHorizontalPadding(popupPadding.leading) @@ -1551,7 +1551,7 @@ private struct TestBottomPopup: BottomPopup { let dragGestureEnabled: Bool - func configurePopup(config: LocalConfigVertical) -> LocalConfigVertical { config + func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config .popupTopPadding(popupPadding.top) .popupBottomPadding(popupPadding.bottom) .popupHorizontalPadding(popupPadding.leading) @@ -1563,3 +1563,6 @@ private struct TestBottomPopup: BottomPopup { } var body: some View { EmptyView() } } + +// MARK: Others +extension VM.VerticalStack: @unchecked Sendable {} From dc5a60586ee27394c2ff95e54048388b49e40f79 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 14:20:07 +0100 Subject: [PATCH 382/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 28cb15bd78..b6333dee6a 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1503,7 +1503,13 @@ private extension PopupVerticalStackViewModelTests { case .center: fatalError() }} func updatePopups(_ viewModel: ViewModel) async { - for popup in viewModel.popups { await viewModel.updatePopupHeight(popup.height!, popup) } + for popup in viewModel.popups { + await viewModel.updatePopupHeight(popup.height!, popup) + await waitForResults() + } + } + func waitForResults() async { + await Task.sleep(seconds: 0.01) } } From ecc8a71b58aaae79c6648891c6097482c997f9ea Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 14:22:29 +0100 Subject: [PATCH 383/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index b6333dee6a..1f48d4261a 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1483,13 +1483,17 @@ private extension PopupVerticalStackViewModelTests { func createPopupInstanceForPopupHeightTests(alignment: PopupAlignment, heightMode: HeightMode, popupHeight: CGFloat, popupDragHeight: CGFloat = 0, ignoredSafeAreaEdges: Edge.Set = [], popupPadding: EdgeInsets = .init(), cornerRadius: CGFloat = 0, dragGestureEnabled: Bool = true, dragDetents: [DragDetent] = []) async -> AnyPopup { let popup = getTestPopup(alignment, heightMode, popupHeight, popupDragHeight, ignoredSafeAreaEdges, popupPadding, cornerRadius, dragGestureEnabled, dragDetents) return await AnyPopup(popup) + .updatedID(UUID().uuidString) .updatedHeight(popupHeight) .updatedDragHeight(popupDragHeight) } - func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) async -> (Value), expectedValueBuilder: @escaping (ViewModel) async -> Value) async { + func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) async -> Value, expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.updatePopups(popups) + await waitForResults() await updatePopups(viewModel) + await waitForResults() await viewModel.updateGestureTranslation(gestureTranslation) + await waitForResults() let calculatedValue = await calculatedValue(viewModel) let expectedValue = await expectedValueBuilder(viewModel) From 170d1cc01bd0b51458f95e67dfd31f339f81a165 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 14:24:22 +0100 Subject: [PATCH 384/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 1f48d4261a..5a0e3f09db 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -55,6 +55,7 @@ extension PopupVerticalStackViewModelTests { await bottomViewModel.updatePopups([ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150) ]) + await waitForResults() XCTAssertEqual( bottomViewModel.popups.getInvertedIndex(of: bottomViewModel.popups[0]), @@ -69,6 +70,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150) ]) + await waitForResults() XCTAssertEqual( bottomViewModel.popups.getInvertedIndex(of: bottomViewModel.popups[3]), @@ -470,6 +472,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 670), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 310) ]) + await waitForResults() XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[2]), @@ -495,6 +498,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 350, popupDragHeight: 100) ]) await bottomViewModel.updateGestureTranslation(-100) + await waitForResults() XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[0]), @@ -507,6 +511,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) await bottomViewModel.updateGestureTranslation(100) + await waitForResults() XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[0]), @@ -519,6 +524,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) await bottomViewModel.updateGestureTranslation(100) + await waitForResults() XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[1]), @@ -531,6 +537,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) GlobalConfigContainer.vertical.isStackingEnabled = false + await waitForResults() XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[0]), @@ -554,6 +561,7 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) await topViewModel.updateGestureTranslation(-100) + await waitForResults() XCTAssertEqual( topViewModel.calculateOffsetY(for: topViewModel.popups[1]), From 552fddb1f20987106d139ae46d399e9ebb415bb8 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 14:24:28 +0100 Subject: [PATCH 385/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 5a0e3f09db..6c3201a4ba 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -487,6 +487,8 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 670), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 310) ]) + await bottomViewModel.updateGestureTranslation(0) + await waitForResults() XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[4]), @@ -549,6 +551,8 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 350, popupDragHeight: 249), createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) + await topViewModel.updateGestureTranslation(0) + await waitForResults() XCTAssertEqual( topViewModel.calculateOffsetY(for: topViewModel.popups[0]), From 2b96b4b69b6f8943dee064f86e6a28a59438c290 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 14:25:15 +0100 Subject: [PATCH 386/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 6c3201a4ba..9fb3c0e848 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1475,9 +1475,13 @@ extension PopupVerticalStackViewModelTests { private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnEnd(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat?, shouldPopupBeDismissed: Bool)) async { await viewModel.updatePopups(popups) + await waitForResults() await updatePopups(viewModel) + await waitForResults() await viewModel.updateGestureTranslation(gestureValue) + await waitForResults() await viewModel.onPopupDragGestureEnded(gestureValue) + await waitForResults() XCTAssertEqual(viewModel.popups.count, expectedValues.shouldPopupBeDismissed ? 0 : 1) XCTAssertEqual(viewModel.activePopupProperties.height, expectedValues.popupHeight) From 52498b38256db87016a1f1efcf3d9279b9ce29c5 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 14:25:34 +0100 Subject: [PATCH 387/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 9fb3c0e848..24685fd317 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1306,7 +1306,9 @@ private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnChange(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat, gestureTranslation: CGFloat)) async { await viewModel.updatePopups(popups) await updatePopups(viewModel) + await waitForResults() await viewModel.onPopupDragGestureChanged(gestureValue) + await waitForResults() XCTAssertEqual(viewModel.activePopupProperties.height, expectedValues.popupHeight) XCTAssertEqual(viewModel.activePopupProperties.gestureTranslation, expectedValues.gestureTranslation) From ef630e0529557754a6a66daf7275f8e7c3327df1 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 14:37:18 +0100 Subject: [PATCH 388/407] 1 --- Tests/Tests+PopupStack.swift | 2 +- Tests/Tests+ViewModel+PopupCenterStack.swift | 10 +++++----- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 625315cb6c..7fe7bb3e6a 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -254,7 +254,7 @@ private extension PopupStackTests { } func performAction(_ action: () async -> ()) async { await action() - await Task.sleep(seconds: 0.01) + await Task.sleep(seconds: 0.03) } func getPopupsForDefaultStack() async -> [AnyPopup] { await PopupStack diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index af34b9b931..bd8d462db5 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -236,13 +236,10 @@ private extension PopupCenterStackViewModelTests { } func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) async -> Value, expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.updatePopups(popups) - - await Task.sleep(seconds: 0.01) - + await waitForResults() await updatePopups() await viewModel.updateScreen(screenHeight: isKeyboardActive ? screenWithKeyboard.height : screen.height, screenSafeArea: isKeyboardActive ? screenWithKeyboard.safeArea : screen.safeArea, isKeyboardActive: isKeyboardActive) - - await Task.sleep(seconds: 0.01) + await waitForResults() let calculatedValue = await calculatedValue(viewModel) let expectedValue = await expectedValueBuilder(viewModel) @@ -253,6 +250,9 @@ private extension PopupCenterStackViewModelTests { func updatePopups() async { for popup in viewModel.popups { await viewModel.updatePopupHeight(popup.height!, popup) } } + func waitForResults() async { + await Task.sleep(seconds: 0.03) + } } // MARK: Screen diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 24685fd317..ae10355e8d 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1531,7 +1531,7 @@ private extension PopupVerticalStackViewModelTests { } } func waitForResults() async { - await Task.sleep(seconds: 0.01) + await Task.sleep(seconds: 0.03) } } From 3cf24d1db644f306ebc1c7fd18af0d1d09f596ed Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Fri, 15 Nov 2024 14:42:58 +0100 Subject: [PATCH 389/407] 1 --- Tests/Tests+PopupStack.swift | 2 +- Tests/Tests+ViewModel+PopupCenterStack.swift | 2 +- Tests/Tests+ViewModel+PopupVerticalStack.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Tests+PopupStack.swift b/Tests/Tests+PopupStack.swift index 7fe7bb3e6a..148bae864d 100644 --- a/Tests/Tests+PopupStack.swift +++ b/Tests/Tests+PopupStack.swift @@ -254,7 +254,7 @@ private extension PopupStackTests { } func performAction(_ action: () async -> ()) async { await action() - await Task.sleep(seconds: 0.03) + await Task.sleep(seconds: 0.06) } func getPopupsForDefaultStack() async -> [AnyPopup] { await PopupStack diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index bd8d462db5..493b4a5242 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -251,7 +251,7 @@ private extension PopupCenterStackViewModelTests { for popup in viewModel.popups { await viewModel.updatePopupHeight(popup.height!, popup) } } func waitForResults() async { - await Task.sleep(seconds: 0.03) + await Task.sleep(seconds: 0.06) } } diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index ae10355e8d..9431ef4b05 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -1531,7 +1531,7 @@ private extension PopupVerticalStackViewModelTests { } } func waitForResults() async { - await Task.sleep(seconds: 0.03) + await Task.sleep(seconds: 0.06) } } From 45b6dafb2a00b165864844fd3e1a900257b5e560 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 16 Nov 2024 13:08:43 +0100 Subject: [PATCH 390/407] 1 --- Sources/Internal/Extensions/View+Background.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/Extensions/View+Background.swift b/Sources/Internal/Extensions/View+Background.swift index d535924c0b..8302600067 100644 --- a/Sources/Internal/Extensions/View+Background.swift +++ b/Sources/Internal/Extensions/View+Background.swift @@ -12,11 +12,11 @@ import SwiftUI extension View { - func background(backgroundColor: Color, overlayColor: Color, corners: [PopupAlignment: CGFloat]) -> some View { background( - backgroundColor + func background(backgroundColor: Color, overlayColor: Color, corners: [PopupAlignment: CGFloat]) -> some View { + background(backgroundColor) .overlay(overlayColor) .mask(RoundedCorner(corners: corners)) - )} + } } // MARK: Background Shape From 6ef2aa94af4642bc497904c720562d79103a1bda Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 16 Nov 2024 13:18:28 +0100 Subject: [PATCH 391/407] 1 --- Sources/Internal/UI/PopupVerticalStackView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index 03b0349e3a..3d6937182c 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -27,7 +27,7 @@ private extension PopupVerticalStackView { } } private extension PopupVerticalStackView { - func createPopup(_ popup: AnyPopup) -> some View { + @ViewBuilder func createPopup(_ popup: AnyPopup) -> some View { if viewModel.isPopupActive(popup) { popup.body .padding(viewModel.activePopupProperties.innerPadding) .fixedSize(horizontal: false, vertical: viewModel.activePopupProperties.verticalFixedSize) @@ -42,7 +42,7 @@ private extension PopupVerticalStackView { .transition(transition) .zIndex(viewModel.calculateZIndex()) .compositingGroup() - } + }} } private extension PopupVerticalStackView { From d6e59e12abe5b53772cd70191b9e6d79753b1980 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 16 Nov 2024 13:19:12 +0100 Subject: [PATCH 392/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 9826fb4ec2..dc5ddd8f02 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -278,7 +278,7 @@ extension VM.VerticalStack { remainingTranslationProgress = 1 - activePopupProperties.translationProgress let progressMultiplier = invertedIndex == 1 ? remainingTranslationProgress : max(minStackOverlayProgressMultiplier, remainingTranslationProgress) - let overlayValue = min(stackOverlayFactor * .init(invertedIndex), maxStackOverlayFactor) + let overlayValue = stackOverlayFactor * .init(invertedIndex) let opacity = overlayValue * progressMultiplier return max(opacity, 0) @@ -296,6 +296,7 @@ extension VM.VerticalStack { var dragTranslationThreshold: CGFloat { 8 } var minScaleProgressMultiplier: CGFloat { 0.7 } var minStackOverlayProgressMultiplier: CGFloat { 0.6 } + var maxNumberOfVisiblePopups: Int { 3 } } From bcea74e3bc4d518bc225523bd4d062b39a260747 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 16 Nov 2024 13:24:45 +0100 Subject: [PATCH 393/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index dc5ddd8f02..b4ab361ab9 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -287,9 +287,8 @@ extension VM.VerticalStack { // MARK: Attributes extension VM.VerticalStack { - var stackScaleFactor: CGFloat { 0.025 } - var stackOverlayFactor: CGFloat { 0.1 } - var maxStackOverlayFactor: CGFloat { 0.48 } + var stackScaleFactor: CGFloat { 0.03 } + var stackOverlayFactor: CGFloat { 0.2 } var stackOffset: CGFloat { GlobalConfigContainer.vertical.isStackingEnabled ? 8 : 0 } var dragThreshold: CGFloat { GlobalConfigContainer.vertical.dragThreshold } var dragGestureEnabled: Bool { popups.last?.config.isDragGestureEnabled ?? false } From 12284ecab98f02489f9e1b660b625b348bc9b1df Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 16 Nov 2024 13:27:18 +0100 Subject: [PATCH 394/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index b4ab361ab9..90d5cea98c 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -218,6 +218,13 @@ private extension VM.VerticalStack { +// MARK: Is Popup Active +extension VM.VerticalStack { + @MainActor func isPopupActive(_ popup: AnyPopup) -> Bool { + popups.getInvertedIndex(of: popup) < maxNumberOfVisiblePopups + } +} + // MARK: Offset Y extension VM.VerticalStack { @MainActor func calculateOffsetY(for popup: AnyPopup) -> CGFloat { switch popup == popups.last { From 430fc712931994f3c115532e22241d1e2326906e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 16 Nov 2024 14:50:21 +0100 Subject: [PATCH 395/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 90d5cea98c..6386ec82d8 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -205,9 +205,10 @@ private extension VM.VerticalStack { } private extension VM.VerticalStack { func calculateStackHeight() -> CGFloat { - let numberOfStackedItems = max(popups.count - 1, 0) + let numberOfStackedItems = max(popups.count - 1, 0), + numberOfVisibleItems = min(numberOfStackedItems, maxNumberOfVisiblePopups) - let stackedItemsHeight = stackOffset * .init(numberOfStackedItems) + let stackedItemsHeight = stackOffset * .init(numberOfVisibleItems) return stackedItemsHeight } } @@ -294,7 +295,7 @@ extension VM.VerticalStack { // MARK: Attributes extension VM.VerticalStack { - var stackScaleFactor: CGFloat { 0.03 } + var stackScaleFactor: CGFloat { 0.025 } var stackOverlayFactor: CGFloat { 0.2 } var stackOffset: CGFloat { GlobalConfigContainer.vertical.isStackingEnabled ? 8 : 0 } var dragThreshold: CGFloat { GlobalConfigContainer.vertical.dragThreshold } From 06af961c44b892f151413e577b589f054a7b474d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sat, 16 Nov 2024 15:40:01 +0100 Subject: [PATCH 396/407] 1 --- Sources/Internal/UI/PopupCenterStackView.swift | 2 +- Sources/Internal/UI/PopupVerticalStackView.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/UI/PopupCenterStackView.swift b/Sources/Internal/UI/PopupCenterStackView.swift index 711be27820..0b6af71a2d 100644 --- a/Sources/Internal/UI/PopupCenterStackView.swift +++ b/Sources/Internal/UI/PopupCenterStackView.swift @@ -30,6 +30,7 @@ private extension PopupCenterStackView { private extension PopupCenterStackView { func createPopup(_ popup: AnyPopup) -> some View { popup.body + .compositingGroup() .fixedSize(horizontal: false, vertical: viewModel.activePopupProperties.verticalFixedSize) .onHeightChange { await viewModel.updatePopupHeight($0, popup) } .frame(height: viewModel.activePopupProperties.height) @@ -38,7 +39,6 @@ private extension PopupCenterStackView { .opacity(viewModel.calculateOpacity(for: popup)) .focusSection_tvOS() .padding(viewModel.activePopupProperties.outerPadding) - .compositingGroup() } } diff --git a/Sources/Internal/UI/PopupVerticalStackView.swift b/Sources/Internal/UI/PopupVerticalStackView.swift index 3d6937182c..cbeaa0685d 100644 --- a/Sources/Internal/UI/PopupVerticalStackView.swift +++ b/Sources/Internal/UI/PopupVerticalStackView.swift @@ -29,6 +29,7 @@ private extension PopupVerticalStackView { private extension PopupVerticalStackView { @ViewBuilder func createPopup(_ popup: AnyPopup) -> some View { if viewModel.isPopupActive(popup) { popup.body + .compositingGroup() .padding(viewModel.activePopupProperties.innerPadding) .fixedSize(horizontal: false, vertical: viewModel.activePopupProperties.verticalFixedSize) .onHeightChange { await viewModel.updatePopupHeight($0, popup) } @@ -41,7 +42,6 @@ private extension PopupVerticalStackView { .padding(viewModel.activePopupProperties.outerPadding) .transition(transition) .zIndex(viewModel.calculateZIndex()) - .compositingGroup() }} } From 9a7a9c9758f4174c8fecfd43f60ca4960c1c7761 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 17 Nov 2024 01:25:37 +0100 Subject: [PATCH 397/407] 1 --- Sources/Internal/Extensions/View+ReadHeight.swift | 1 - Sources/Internal/View Models/ViewModel+VerticalStack.swift | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Internal/Extensions/View+ReadHeight.swift b/Sources/Internal/Extensions/View+ReadHeight.swift index 1e99ee892a..a68ff26a49 100644 --- a/Sources/Internal/Extensions/View+ReadHeight.swift +++ b/Sources/Internal/Extensions/View+ReadHeight.swift @@ -15,7 +15,6 @@ extension View { func onHeightChange(perform action: @escaping (CGFloat) async -> ()) -> some View { background( GeometryReader { proxy in Task { @MainActor in - await Task.sleep(seconds: 0.03) await action(proxy.size.height) } return Color.clear diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 6386ec82d8..1490825b7b 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -300,7 +300,7 @@ extension VM.VerticalStack { var stackOffset: CGFloat { GlobalConfigContainer.vertical.isStackingEnabled ? 8 : 0 } var dragThreshold: CGFloat { GlobalConfigContainer.vertical.dragThreshold } var dragGestureEnabled: Bool { popups.last?.config.isDragGestureEnabled ?? false } - var dragTranslationThreshold: CGFloat { 8 } + var dragTranslationThreshold: CGFloat { 32 } var minScaleProgressMultiplier: CGFloat { 0.7 } var minStackOverlayProgressMultiplier: CGFloat { 0.6 } var maxNumberOfVisiblePopups: Int { 3 } From c3bea41112f5f2e7776abb4bde656447a93e8df3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 17 Nov 2024 01:28:27 +0100 Subject: [PATCH 398/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 4 ++-- Sources/Internal/View Models/ViewModel.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index 1490825b7b..dfbeffab5e 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -314,12 +314,12 @@ extension VM.VerticalStack { // MARK: On Changed extension VM.VerticalStack { - @MainActor func onPopupDragGestureChanged(_ value: CGFloat) async { Task { + @MainActor func onPopupDragGestureChanged(_ value: CGFloat) async { guard dragGestureEnabled else { return } let newGestureTranslation = await calculateGestureTranslation(value) await updateGestureTranslation(newGestureTranslation) - }} + } } private extension VM.VerticalStack { func calculateGestureTranslation(_ value: CGFloat) async -> CGFloat { switch popups.last?.config.dragDetents.isEmpty ?? true { diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 07e21e7926..6e6bbbe8d2 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -102,9 +102,9 @@ extension ViewModel { // MARK: Popup Drag Height extension ViewModel { - @MainActor func updatePopupDragHeight(_ targetDragHeight: CGFloat, _ popup: AnyPopup) async { Task { + @MainActor func updatePopupDragHeight(_ targetDragHeight: CGFloat, _ popup: AnyPopup) async { await updatePopupAction(popup.updatedDragHeight(targetDragHeight)) - }} + } } // MARK: Helpers From 12eae3a0c7ebe444be811f348298bc218d842396 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 17 Nov 2024 01:28:50 +0100 Subject: [PATCH 399/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 6e6bbbe8d2..2f48e90d6d 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -61,12 +61,12 @@ extension ViewModel { // MARK: Popups extension ViewModel { - @MainActor func updatePopups(_ newPopups: [AnyPopup]) async { Task { + @MainActor func updatePopups(_ newPopups: [AnyPopup]) async { popups = await filteredPopups(newPopups) await updateActivePopupProperties() withAnimation(.transition) { objectWillChange.send() } - }} + } } // MARK: Screen @@ -81,23 +81,23 @@ extension ViewModel { // MARK: Gesture Translation extension ViewModel { - @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { Task { + @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { await updateActivePopupPropertiesOnGestureTranslationChange(newGestureTranslation) withAnimation(activePopupProperties.gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } - }} + } } // MARK: Popup Height extension ViewModel { - @MainActor func updatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { Task { + @MainActor func updatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { guard activePopupProperties.gestureTranslation == 0 else { return } let newHeight = await calculatePopupHeight(heightCandidate, popup) if newHeight != popup.height { await updatePopupAction(popup.updatedHeight(newHeight)) } - }} + } } // MARK: Popup Drag Height From abf81a9c6a14d7c911677ccb933a7b5b62b21acd Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 17 Nov 2024 01:35:13 +0100 Subject: [PATCH 400/407] 1 --- Sources/Internal/Containers/PopupStack.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/Containers/PopupStack.swift b/Sources/Internal/Containers/PopupStack.swift index fbbdaff64a..3823856658 100644 --- a/Sources/Internal/Containers/PopupStack.swift +++ b/Sources/Internal/Containers/PopupStack.swift @@ -21,7 +21,7 @@ import SwiftUI // MARK: Update extension PopupStack { - func update(popup: AnyPopup) { if let index = popups.firstIndex(of: popup) { + func update(popup: AnyPopup) async { if let index = popups.firstIndex(of: popup) { popups[index] = popup }} } @@ -64,14 +64,14 @@ private extension PopupStack { nonisolated func getNewPriority(_ newPopups: [AnyPopup]) async -> StackPriority { await priority.reshuffled(newPopups) } - nonisolated func updatePopups(_ newPopups: [AnyPopup]) async { - Task { @MainActor in popups = newPopups } + func updatePopups(_ newPopups: [AnyPopup]) async { + popups = newPopups } - nonisolated func updatePriority(_ newPriority: StackPriority, _ oldPopupsCount: Int) async { - let delayDuration = await oldPopupsCount > popups.count ? Animation.duration : 0 + func updatePriority(_ newPriority: StackPriority, _ oldPopupsCount: Int) async { + let delayDuration = oldPopupsCount > popups.count ? Animation.duration : 0 await Task.sleep(seconds: delayDuration) - Task { @MainActor in priority = newPriority } + priority = newPriority } } private extension PopupStack { From 10b207366d1ac26160329e90145ecead902cf239 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 17 Nov 2024 01:41:15 +0100 Subject: [PATCH 401/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index 2f48e90d6d..dff71ee701 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -13,7 +13,7 @@ import SwiftUI import Combine enum VM {} -protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == ObservableObjectPublisher { init() +@MainActor protocol ViewModel: ObservableObject where Self.ObjectWillChangePublisher == ObservableObjectPublisher { init() // MARK: Attributes var alignment: PopupAlignment { get set } var popups: [AnyPopup] { get set } @@ -47,7 +47,7 @@ extension ViewModel { // MARK: Setup extension ViewModel { - @MainActor func setup(updatePopupAction: @escaping (AnyPopup) async -> (), closePopupAction: @escaping (AnyPopup) async -> ()) { + func setup(updatePopupAction: @escaping (AnyPopup) async -> (), closePopupAction: @escaping (AnyPopup) async -> ()) { self.updatePopupAction = updatePopupAction self.closePopupAction = closePopupAction } @@ -61,7 +61,7 @@ extension ViewModel { // MARK: Popups extension ViewModel { - @MainActor func updatePopups(_ newPopups: [AnyPopup]) async { + func updatePopups(_ newPopups: [AnyPopup]) async { popups = await filteredPopups(newPopups) await updateActivePopupProperties() @@ -81,7 +81,7 @@ extension ViewModel { // MARK: Gesture Translation extension ViewModel { - @MainActor func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { + func updateGestureTranslation(_ newGestureTranslation: CGFloat) async { await updateActivePopupPropertiesOnGestureTranslationChange(newGestureTranslation) withAnimation(activePopupProperties.gestureTranslation == 0 ? .transition : nil) { objectWillChange.send() } @@ -90,7 +90,7 @@ extension ViewModel { // MARK: Popup Height extension ViewModel { - @MainActor func updatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { + func updatePopupHeight(_ heightCandidate: CGFloat, _ popup: AnyPopup) async { guard activePopupProperties.gestureTranslation == 0 else { return } let newHeight = await calculatePopupHeight(heightCandidate, popup) @@ -102,7 +102,7 @@ extension ViewModel { // MARK: Popup Drag Height extension ViewModel { - @MainActor func updatePopupDragHeight(_ targetDragHeight: CGFloat, _ popup: AnyPopup) async { + func updatePopupDragHeight(_ targetDragHeight: CGFloat, _ popup: AnyPopup) async { await updatePopupAction(popup.updatedDragHeight(targetDragHeight)) } } From a4d64ed93c985db48a8a41a991b45493684d95c0 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 17 Nov 2024 01:44:43 +0100 Subject: [PATCH 402/407] 1 --- .../View Models/ViewModel+VerticalStack.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index dfbeffab5e..e7c8128852 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -221,14 +221,14 @@ private extension VM.VerticalStack { // MARK: Is Popup Active extension VM.VerticalStack { - @MainActor func isPopupActive(_ popup: AnyPopup) -> Bool { + func isPopupActive(_ popup: AnyPopup) -> Bool { popups.getInvertedIndex(of: popup) < maxNumberOfVisiblePopups } } // MARK: Offset Y extension VM.VerticalStack { - @MainActor func calculateOffsetY(for popup: AnyPopup) -> CGFloat { switch popup == popups.last { + func calculateOffsetY(for popup: AnyPopup) -> CGFloat { switch popup == popups.last { case true: calculateOffsetForActivePopup() case false: calculateOffsetForStackedPopup(popup) }} @@ -258,7 +258,7 @@ private extension VM.VerticalStack { // MARK: Scale X extension VM.VerticalStack { - @MainActor func calculateScaleX(for popup: AnyPopup) -> CGFloat { + func calculateScaleX(for popup: AnyPopup) -> CGFloat { guard popup != popups.last else { return 1 } let invertedIndex = popups.getInvertedIndex(of: popup), @@ -272,14 +272,14 @@ extension VM.VerticalStack { // MARK: Z Index extension VM.VerticalStack { - @MainActor func calculateZIndex() -> CGFloat { + func calculateZIndex() -> CGFloat { popups.last == nil ? 2137 : .init(popups.count) } } // MARK: - Stack Overlay Opacity extension VM.VerticalStack { - @MainActor func calculateStackOverlayOpacity(for popup: AnyPopup) -> CGFloat { + func calculateStackOverlayOpacity(for popup: AnyPopup) -> CGFloat { guard popup != popups.last else { return 0 } let invertedIndex = popups.getInvertedIndex(of: popup), @@ -314,7 +314,7 @@ extension VM.VerticalStack { // MARK: On Changed extension VM.VerticalStack { - @MainActor func onPopupDragGestureChanged(_ value: CGFloat) async { + func onPopupDragGestureChanged(_ value: CGFloat) async { guard dragGestureEnabled else { return } let newGestureTranslation = await calculateGestureTranslation(value) @@ -359,7 +359,7 @@ private extension VM.VerticalStack { // MARK: On Ended extension VM.VerticalStack { - @MainActor func onPopupDragGestureEnded(_ value: CGFloat) async { Task { + func onPopupDragGestureEnded(_ value: CGFloat) async { Task { guard value != 0, let activePopup = popups.last else { return } await dismissLastPopupIfNeeded(activePopup) From 59fedfa9bdf81fab38a71feee007060f70c617d3 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 17 Nov 2024 01:46:59 +0100 Subject: [PATCH 403/407] 1 --- Sources/Internal/View Models/ViewModel.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel.swift b/Sources/Internal/View Models/ViewModel.swift index dff71ee701..4f852add0d 100644 --- a/Sources/Internal/View Models/ViewModel.swift +++ b/Sources/Internal/View Models/ViewModel.swift @@ -71,12 +71,12 @@ extension ViewModel { // MARK: Screen extension ViewModel { - @MainActor func updateScreen(screenHeight: CGFloat? = nil, screenSafeArea: EdgeInsets? = nil, isKeyboardActive: Bool? = nil) async { Task { + func updateScreen(screenHeight: CGFloat? = nil, screenSafeArea: EdgeInsets? = nil, isKeyboardActive: Bool? = nil) async { screen = await updatedScreenProperties(screenHeight, screenSafeArea, isKeyboardActive) await updateActivePopupProperties() withAnimation(.transition) { objectWillChange.send() } - }} + } } // MARK: Gesture Translation From 7e92b50ac2e042b9678683c10478183a99d80156 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 17 Nov 2024 02:15:28 +0100 Subject: [PATCH 404/407] 1 --- Sources/Internal/View Models/ViewModel+VerticalStack.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Internal/View Models/ViewModel+VerticalStack.swift b/Sources/Internal/View Models/ViewModel+VerticalStack.swift index e7c8128852..a29ca2e87f 100644 --- a/Sources/Internal/View Models/ViewModel+VerticalStack.swift +++ b/Sources/Internal/View Models/ViewModel+VerticalStack.swift @@ -359,7 +359,7 @@ private extension VM.VerticalStack { // MARK: On Ended extension VM.VerticalStack { - func onPopupDragGestureEnded(_ value: CGFloat) async { Task { + func onPopupDragGestureEnded(_ value: CGFloat) async { guard value != 0, let activePopup = popups.last else { return } await dismissLastPopupIfNeeded(activePopup) @@ -367,7 +367,7 @@ extension VM.VerticalStack { let targetDragHeight = await calculateTargetDragHeight(activePopup) await updateGestureTranslation(0) await updatePopupDragHeight(targetDragHeight, activePopup) - }} + } } private extension VM.VerticalStack { func dismissLastPopupIfNeeded(_ popup: AnyPopup) async { switch activePopupProperties.translationProgress >= dragThreshold { From 3d793adb0d48b66b78e8aa5f894214b4ae05098e Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 17 Nov 2024 02:23:15 +0100 Subject: [PATCH 405/407] 1 --- Tests/Tests+ViewModel+PopupCenterStack.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupCenterStack.swift b/Tests/Tests+ViewModel+PopupCenterStack.swift index 493b4a5242..47887c6aaf 100644 --- a/Tests/Tests+ViewModel+PopupCenterStack.swift +++ b/Tests/Tests+ViewModel+PopupCenterStack.swift @@ -236,10 +236,8 @@ private extension PopupCenterStackViewModelTests { } func appendPopupsAndPerformChecks(popups: [AnyPopup], isKeyboardActive: Bool, calculatedValue: @escaping (ViewModel) async -> Value, expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.updatePopups(popups) - await waitForResults() await updatePopups() await viewModel.updateScreen(screenHeight: isKeyboardActive ? screenWithKeyboard.height : screen.height, screenSafeArea: isKeyboardActive ? screenWithKeyboard.safeArea : screen.safeArea, isKeyboardActive: isKeyboardActive) - await waitForResults() let calculatedValue = await calculatedValue(viewModel) let expectedValue = await expectedValueBuilder(viewModel) @@ -250,9 +248,6 @@ private extension PopupCenterStackViewModelTests { func updatePopups() async { for popup in viewModel.popups { await viewModel.updatePopupHeight(popup.height!, popup) } } - func waitForResults() async { - await Task.sleep(seconds: 0.06) - } } // MARK: Screen From ade11ebb74b6fae7b0a324edd202466c0675f25d Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 17 Nov 2024 02:27:04 +0100 Subject: [PATCH 406/407] 1 --- Tests/Tests+ViewModel+PopupVerticalStack.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 9431ef4b05..8251f7dc2b 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -110,7 +110,7 @@ extension PopupVerticalStackViewModelTests { viewModel: bottomViewModel, popups: popups, updatedPopup: updatedPopup, - expectedValue: (height: 1371, dragHeight: nil) + expectedValue: (height: 1371, dragHeight: 0) ) } func test_updatePopup_3() async { @@ -128,12 +128,12 @@ extension PopupVerticalStackViewModelTests { viewModel: bottomViewModel, popups: popups, updatedPopup: updatedPopup, - expectedValue: (height: nil, dragHeight: nil) + expectedValue: (height: nil, dragHeight: 0) ) } } private extension PopupVerticalStackViewModelTests { - func appendPopupsAndCheckPopups(viewModel: ViewModel, popups: [AnyPopup], updatedPopup: AnyPopup, expectedValue: (height: CGFloat?, dragHeight: CGFloat?)) async { + func appendPopupsAndCheckPopups(viewModel: ViewModel, popups: [AnyPopup], updatedPopup: AnyPopup, expectedValue: (height: CGFloat?, dragHeight: CGFloat)) async { await viewModel.updatePopups(popups) await viewModel.updatePopupAction(updatedPopup) @@ -1168,7 +1168,7 @@ extension PopupVerticalStackViewModelTests { popups: popups, gestureTranslation: -123, calculateForIndex: 0, - expectedValueBuilder: { min($0.stackOverlayFactor * 9, $0.maxStackOverlayFactor) } + expectedValueBuilder: { $0.stackOverlayFactor * 9 } ) } func test_calculateStackOverlayOpacity_withThreePopupsStacked_whenGestureTranslationIsPositive_last() async { From b64536d054a6607ea7e1aae832f563ebd94639c2 Mon Sep 17 00:00:00 2001 From: Tomasz Kurylik Date: Sun, 17 Nov 2024 02:29:54 +0100 Subject: [PATCH 407/407] 1 --- .../Tests+ViewModel+PopupVerticalStack.swift | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/Tests/Tests+ViewModel+PopupVerticalStack.swift b/Tests/Tests+ViewModel+PopupVerticalStack.swift index 8251f7dc2b..2ca6c82671 100644 --- a/Tests/Tests+ViewModel+PopupVerticalStack.swift +++ b/Tests/Tests+ViewModel+PopupVerticalStack.swift @@ -55,7 +55,6 @@ extension PopupVerticalStackViewModelTests { await bottomViewModel.updatePopups([ createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150) ]) - await waitForResults() XCTAssertEqual( bottomViewModel.popups.getInvertedIndex(of: bottomViewModel.popups[0]), @@ -70,7 +69,6 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 150) ]) - await waitForResults() XCTAssertEqual( bottomViewModel.popups.getInvertedIndex(of: bottomViewModel.popups[3]), @@ -472,7 +470,6 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 670), createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 310) ]) - await waitForResults() XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[2]), @@ -488,7 +485,6 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 310) ]) await bottomViewModel.updateGestureTranslation(0) - await waitForResults() XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[4]), @@ -500,7 +496,6 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 350, popupDragHeight: 100) ]) await bottomViewModel.updateGestureTranslation(-100) - await waitForResults() XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[0]), @@ -513,7 +508,6 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) await bottomViewModel.updateGestureTranslation(100) - await waitForResults() XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[0]), @@ -526,7 +520,6 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) await bottomViewModel.updateGestureTranslation(100) - await waitForResults() XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[1]), @@ -539,7 +532,6 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .bottom, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) GlobalConfigContainer.vertical.isStackingEnabled = false - await waitForResults() XCTAssertEqual( bottomViewModel.calculateOffsetY(for: bottomViewModel.popups[0]), @@ -552,7 +544,6 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) await topViewModel.updateGestureTranslation(0) - await waitForResults() XCTAssertEqual( topViewModel.calculateOffsetY(for: topViewModel.popups[0]), @@ -565,7 +556,6 @@ extension PopupVerticalStackViewModelTests { createPopupInstanceForPopupHeightTests(alignment: .top, heightMode: .auto, popupHeight: 133, popupDragHeight: 21) ]) await topViewModel.updateGestureTranslation(-100) - await waitForResults() XCTAssertEqual( topViewModel.calculateOffsetY(for: topViewModel.popups[1]), @@ -1306,9 +1296,7 @@ private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnChange(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat, gestureTranslation: CGFloat)) async { await viewModel.updatePopups(popups) await updatePopups(viewModel) - await waitForResults() await viewModel.onPopupDragGestureChanged(gestureValue) - await waitForResults() XCTAssertEqual(viewModel.activePopupProperties.height, expectedValues.popupHeight) XCTAssertEqual(viewModel.activePopupProperties.gestureTranslation, expectedValues.gestureTranslation) @@ -1477,13 +1465,9 @@ extension PopupVerticalStackViewModelTests { private extension PopupVerticalStackViewModelTests { func appendPopupsAndCheckGestureTranslationOnEnd(viewModel: ViewModel, popups: [AnyPopup], gestureValue: CGFloat, expectedValues: (popupHeight: CGFloat?, shouldPopupBeDismissed: Bool)) async { await viewModel.updatePopups(popups) - await waitForResults() await updatePopups(viewModel) - await waitForResults() await viewModel.updateGestureTranslation(gestureValue) - await waitForResults() await viewModel.onPopupDragGestureEnded(gestureValue) - await waitForResults() XCTAssertEqual(viewModel.popups.count, expectedValues.shouldPopupBeDismissed ? 0 : 1) XCTAssertEqual(viewModel.activePopupProperties.height, expectedValues.popupHeight) @@ -1507,11 +1491,8 @@ private extension PopupVerticalStackViewModelTests { } func appendPopupsAndPerformChecks(viewModel: ViewModel, popups: [AnyPopup], gestureTranslation: CGFloat, calculatedValue: @escaping (ViewModel) async -> Value, expectedValueBuilder: @escaping (ViewModel) async -> Value) async { await viewModel.updatePopups(popups) - await waitForResults() await updatePopups(viewModel) - await waitForResults() await viewModel.updateGestureTranslation(gestureTranslation) - await waitForResults() let calculatedValue = await calculatedValue(viewModel) let expectedValue = await expectedValueBuilder(viewModel) @@ -1525,13 +1506,7 @@ private extension PopupVerticalStackViewModelTests { case .center: fatalError() }} func updatePopups(_ viewModel: ViewModel) async { - for popup in viewModel.popups { - await viewModel.updatePopupHeight(popup.height!, popup) - await waitForResults() - } - } - func waitForResults() async { - await Task.sleep(seconds: 0.06) + for popup in viewModel.popups { await viewModel.updatePopupHeight(popup.height!, popup) } } }