Skip to content

Commit

Permalink
Patch 2.3.0
Browse files Browse the repository at this point in the history
feat:
- While presenting popups of different types together, the overlay will hide previous popups underneath (#62, #77)
  • Loading branch information
FulcrumOne authored Mar 25, 2024
1 parent 379dbe3 commit 890da6d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion MijickPopupView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pod::Spec.new do |s|
PopupView is a free and open-source library dedicated for SwiftUI that makes the process of presenting popups easier and much cleaner.
DESC

s.version = '2.2.4'
s.version = '2.3.0'
s.ios.deployment_target = '14.0'
s.osx.deployment_target = '12.0'
s.swift_version = '5.0'
Expand Down
5 changes: 0 additions & 5 deletions Sources/Internal/Protocols/PopupStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ extension PopupStack {
func getOffset(_ item: AnyPopup<Config>) -> CGFloat { isLast(item) ? gestureTranslation : invertedIndex(item).floatValue * stackOffsetValue }
}

// MARK: - Z Index
extension PopupStack {
func getZIndex(_ item: AnyPopup<Config>) -> Double { index(item).doubleValue + 1 }
}

// MARK: - Initial Height
extension PopupStack {
func getInitialHeight() -> CGFloat {
Expand Down
5 changes: 2 additions & 3 deletions Sources/Internal/Views/PopupBottomStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ private extension PopupBottomStackView {
.focusSectionIfAvailable()
.align(to: .bottom, lastPopupConfig.contentFillsEntireScreen ? 0 : popupBottomPadding)
.transition(transition)
.zIndex(getZIndex(item))
}
}

Expand Down Expand Up @@ -86,13 +85,13 @@ private extension PopupBottomStackView {
default: return .allCorners
}
}
func saveHeight(_ height: CGFloat, for item: AnyPopup<BottomPopupConfig>) {
func saveHeight(_ height: CGFloat, for item: AnyPopup<BottomPopupConfig>) { if !isGestureActive {
let config = item.configurePopup(popup: .init())

if config.contentFillsEntireScreen { return heights[item.id] = screenManager.size.height }
if config.contentFillsWholeHeight { return heights[item.id] = getMaxHeight() }
return heights[item.id] = min(height, maxHeight)
}
}}
func getMaxHeight() -> CGFloat {
let basicHeight = screenManager.size.height - screenManager.safeArea.top
let stackedViewsCount = min(max(0, globalConfig.bottom.stackLimit - 1), items.count - 1)
Expand Down
3 changes: 1 addition & 2 deletions Sources/Internal/Views/PopupTopStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ private extension PopupTopStackView {
.focusSectionIfAvailable()
.align(to: .top, popupTopPadding)
.transition(transition)
.zIndex(getZIndex(item))
}
}

Expand Down Expand Up @@ -84,7 +83,7 @@ private extension PopupTopStackView {
}
}
func getBackgroundColour(for item: AnyPopup<TopPopupConfig>) -> Color { getConfig(item).backgroundColour ?? globalConfig.top.backgroundColour }
func saveHeight(_ height: CGFloat, for item: AnyPopup<TopPopupConfig>) { heights[item.id] = height }
func saveHeight(_ height: CGFloat, for item: AnyPopup<TopPopupConfig>) { if !isGestureActive { heights[item.id] = height }}
}

// MARK: - Flags & Values
Expand Down
35 changes: 21 additions & 14 deletions Sources/Internal/Views/PopupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ private extension PopupView {
.ignoresSafeArea()
.frame(height: screenManager.size.height)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(createOverlay())
.animation(stackAnimation, value: popupManager.views.map(\.id))
.onChange(of: popupManager.views.count, perform: onViewsCountChange)
}
Expand All @@ -57,29 +56,28 @@ private extension PopupView {
private extension PopupView {
func createPopupStackView() -> some View {
ZStack {
createTopPopupStackView().zIndex(zIndex.top)
createCentrePopupStackView().zIndex(zIndex.centre)
createBottomPopupStackView().zIndex(zIndex.bottom)
createTopPopupStackView()
createCentrePopupStackView()
createBottomPopupStackView()
}
}
func createOverlay() -> some View {
overlayColour
.ignoresSafeArea()
.active(if: isOverlayActive)
.animation(overlayAnimation, value: isStackEmpty)
.animation(overlayAnimation, value: shouldOverlayBeHiddenForCurrentPopup)
}
}

private extension PopupView {
func createTopPopupStackView() -> some View {
PopupTopStackView(items: getViews(AnyPopup<TopPopupConfig>.self), globalConfig: globalConfig)
.addOverlay(overlayColour, isOverlayActive(AnyPopup<TopPopupConfig>.self))
.zIndex(zIndex.top)
}
func createCentrePopupStackView() -> some View {
PopupCentreStackView(items: getViews(AnyPopup<CentrePopupConfig>.self), globalConfig: globalConfig)
.addOverlay(overlayColour, isOverlayActive(AnyPopup<CentrePopupConfig>.self))
.zIndex(zIndex.centre)
}
func createBottomPopupStackView() -> some View {
PopupBottomStackView(items: getViews(AnyPopup<BottomPopupConfig>.self), globalConfig: globalConfig)
.addOverlay(overlayColour, isOverlayActive(AnyPopup<BottomPopupConfig>.self))
.zIndex(zIndex.bottom)
}
}
private extension PopupView {
Expand All @@ -91,15 +89,15 @@ private extension PopupView {
}

private extension PopupView {
var isOverlayActive: Bool { !isStackEmpty && !shouldOverlayBeHiddenForCurrentPopup }
var isStackEmpty: Bool { popupManager.views.isEmpty }
func isOverlayActive<P: Popup>(_ type: P.Type) -> Bool { popupManager.views.last is P && !shouldOverlayBeHiddenForCurrentPopup }
}
private extension PopupView {
var shouldOverlayBeHiddenForCurrentPopup: Bool { popupManager.popupsWithoutOverlay.contains(popupManager.views.last?.id ?? "") }
}

private extension PopupView {
var stackAnimation: Animation { popupManager.presenting ? globalConfig.common.animation.entry : globalConfig.common.animation.removal }
var overlayColour: Color { globalConfig.common.overlayColour }
var overlayAnimation: Animation { .easeInOut(duration: 0.44) }
}


Expand Down Expand Up @@ -128,3 +126,12 @@ private extension PopupView.ZIndex {
var centre: Double { values[1] }
var bottom: Double { values[2] }
}


// MARK: - Helpers
fileprivate extension View {
func addOverlay(_ colour: Color, _ active: Bool) -> some View { ZStack {
colour.active(if: active)
self
}}
}

0 comments on commit 890da6d

Please sign in to comment.