Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 2.4.1 #95

Merged
merged 10 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MijickPopupView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pod::Spec.new do |s|
PopupView is a free and open-source library dedicated for SwiftUI that makes the process of presenting popups easier and much cleaner.
DESC

s.version = '2.4.0'
s.version = '2.4.1'
s.ios.deployment_target = '14.0'
s.osx.deployment_target = '12.0'
s.swift_version = '5.0'
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ PopupView is released under the MIT license. See [LICENSE][License] for details.
<br>
[GridView] - Lay out your data with no effort
<br>
[CameraView] - The most powerful CameraController. Designed for SwiftUI
<br>
[Timer] - Modern API for Timer


Expand All @@ -233,5 +235,6 @@ PopupView is released under the MIT license. See [LICENSE][License] for details.

[Navigattie]: https://github.com/Mijick/Navigattie
[CalendarView]: https://github.com/Mijick/CalendarView
[CameraView]: https://github.com/Mijick/CameraView
[GridView]: https://github.com/Mijick/GridView
[Timer]: https://github.com/Mijick/Timer
16 changes: 16 additions & 0 deletions Sources/Internal/Extensions/Animation++.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Animation++.swift of PopupView
//
// Created by Tomasz Kurylik
// - Twitter: https://twitter.com/tkurylik
// - Mail: tomasz.kurylik@mijick.com
// - GitHub: https://github.com/FulcrumOne
//
// Copyright ©2024 Mijick. Licensed under MIT License.


import SwiftUI

extension Animation {
static var keyboard: Animation { .interpolatingSpring(mass: 3, stiffness: 1000, damping: 500, initialVelocity: 6.4) }
}
1 change: 0 additions & 1 deletion Sources/Internal/Managers/KeyboardManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extension KeyboardManager {
private extension KeyboardManager {
func subscribeToKeyboardEvents() {
Publishers.Merge(getKeyboardWillOpenPublisher(), createKeyboardWillHidePublisher())
.debounce(for: .milliseconds(40), scheduler: DispatchQueue.main)
.sink { self.height = $0 }
.store(in: &subscription)
}
Expand Down
9 changes: 5 additions & 4 deletions Sources/Internal/Views/PopupBottomStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct PopupBottomStackView: PopupStack {
.background(createTapArea())
.animation(getHeightAnimation(isAnimationDisabled: screenManager.animationsDisabled), value: heights)
.animation(isGestureActive ? dragGestureAnimation : transitionRemovalAnimation, value: gestureTranslation)
.animation(.keyboard, value: isKeyboardVisible)
.onDragGesture($isGestureActive, onChanged: onPopupDragGestureChanged, onEnded: onPopupDragGestureEnded)
}
}
Expand All @@ -44,11 +45,11 @@ private extension PopupBottomStackView {
.padding(.trailing, screenManager.safeArea.right)
.fixedSize(horizontal: false, vertical: getFixedSize(item))
.readHeight { saveHeight($0, for: item) }
.frame(height: height, alignment: .top).frame(maxWidth: .infinity, maxHeight: frameMaxHeight)
.frame(height: getHeight(item), alignment: .top).frame(maxWidth: .infinity, maxHeight: height)
.background(getBackgroundColour(for: item), overlayColour: getStackOverlayColour(item), radius: getCornerRadius(item), corners: getCorners(), shadow: popupShadow)
.padding(.horizontal, popupHorizontalPadding)
.offset(y: getOffset(item))
.scaleEffect(getScale(item), anchor: .top)
.scaleEffect(x: getScale(item))
.opacity(getOpacity(item))
.compositingGroup()
.focusSectionIfAvailable()
Expand Down Expand Up @@ -89,7 +90,7 @@ private extension PopupBottomStackView {
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.contentFillsEntireScreen { return heights[item.id] = screenManager.size.height + screenManager.safeArea.top }
if config.contentFillsWholeHeight { return heights[item.id] = getMaxHeight() }
return heights[item.id] = min(height, maxHeight)
}}
Expand All @@ -106,6 +107,7 @@ private extension PopupBottomStackView {
return max(screenManager.safeArea.bottom - popupBottomPadding, 0)
}
func getContentTopPadding() -> CGFloat { lastPopupConfig.contentFillsEntireScreen ? screenManager.safeArea.top : 0 }
func getHeight(_ item: AnyPopup<BottomPopupConfig>) -> CGFloat? { getConfig(item).contentFillsEntireScreen ? nil : height }
func getFixedSize(_ item: AnyPopup<BottomPopupConfig>) -> Bool { !(getConfig(item).contentFillsEntireScreen || getConfig(item).contentFillsWholeHeight || height == maxHeight) }
func getBackgroundColour(for item: AnyPopup<BottomPopupConfig>) -> Color { item.configurePopup(popup: .init()).backgroundColour ?? globalConfig.bottom.backgroundColour }
}
Expand All @@ -116,7 +118,6 @@ extension PopupBottomStackView {
var popupHorizontalPadding: CGFloat { lastPopupConfig.popupPadding.horizontal }
var popupShadow: Shadow { globalConfig.bottom.shadow }
var height: CGFloat { heights.first { $0.key == items.last?.id }?.value ?? (lastPopupConfig.contentFillsEntireScreen ? screenManager.size.height : getInitialHeight()) }
var frameMaxHeight: CGFloat? { lastPopupConfig.contentFillsEntireScreen ? .infinity : height }
var maxHeight: CGFloat { getMaxHeight() - popupBottomPadding }
var distanceFromKeyboard: CGFloat { lastPopupConfig.distanceFromKeyboard ?? globalConfig.bottom.distanceFromKeyboard }
var cornerRadius: CGFloat { let cornerRadius = lastPopupConfig.cornerRadius ?? globalConfig.bottom.cornerRadius; return lastPopupConfig.contentFillsEntireScreen ? min(cornerRadius, screenManager.cornerRadius ?? 0) : cornerRadius }
Expand Down
2 changes: 1 addition & 1 deletion Sources/Internal/Views/PopupCentreStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct PopupCentreStackView: PopupStack {
.animation(transitionEntryAnimation, value: lastPopupConfig.horizontalPadding)
.animation(height == nil ? transitionRemovalAnimation : transitionEntryAnimation, value: height)
.animation(transitionEntryAnimation, value: contentIsAnimated)
.animation(transitionEntryAnimation, value: keyboardManager.height)
.animation(.keyboard, value: keyboardManager.height)
.transition(getTransition())
.onChange(of: items, perform: onItemsChange)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Internal/Views/PopupTopStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private extension PopupTopStackView {
.background(getBackgroundColour(for: item), overlayColour: getStackOverlayColour(item), radius: getCornerRadius(item), corners: getCorners(), shadow: popupShadow)
.padding(.horizontal, lastPopupConfig.popupPadding.horizontal)
.offset(y: getOffset(item))
.scaleEffect(getScale(item), anchor: .bottom)
.scaleEffect(x: getScale(item))
.opacity(getOpacity(item))
.compositingGroup()
.focusSectionIfAvailable()
Expand Down
7 changes: 3 additions & 4 deletions Sources/Internal/Views/PopupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ struct PopupView: View {
let globalConfig: GlobalConfig
@State private var zIndex: ZIndex = .init()
@ObservedObject private var popupManager: PopupManager = .shared
@ObservedObject private var screenManager: ScreenManager = .shared


var body: some View { createBody() }
Expand All @@ -29,7 +28,6 @@ struct PopupView: View {
let globalConfig: GlobalConfig
@State private var zIndex: ZIndex = .init()
@ObservedObject private var popupManager: PopupManager = .shared
@ObservedObject private var screenManager: ScreenManager = .shared


var body: some View {
Expand All @@ -46,7 +44,6 @@ private extension PopupView {
func createBody() -> some View {
createPopupStackView()
.ignoresSafeArea()
.frame(height: screenManager.size.height)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.animation(stackAnimation, value: popupManager.views.map(\.id))
.onChange(of: popupManager.views.count, perform: onViewsCountChange)
Expand Down Expand Up @@ -85,7 +82,9 @@ private extension PopupView {
}

private extension PopupView {
func onViewsCountChange(_ count: Int) { zIndex.reshuffle(popupManager.views.last) }
func onViewsCountChange(_ count: Int) { DispatchQueue.main.asyncAfter(deadline: .now() + (!popupManager.presenting && zIndex.centre == 3 ? 0.4 : 0)) {
zIndex.reshuffle(popupManager.views.last)
}}
}

private extension PopupView {
Expand Down
5 changes: 1 addition & 4 deletions Sources/Public/Extensions/Public+Popup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ public extension Popup {

/// Hides the overlay for the selected popup
@discardableResult func hideOverlay() -> some Popup { PopupManager.hideOverlay(self); return self }
}

// MARK: - Dependency Injections
public extension Popup {
/// Supplies an observable object to a view’s hierarchy.
func environmentObject<T: ObservableObject>(_ object: T) -> any Popup { AnyPopup<Config>(self, object) }
@discardableResult func environmentObject<T: ObservableObject>(_ object: T) -> any Popup { AnyPopup<Config>(self, object) }
}

// MARK: - Available Popups
Expand Down