Skip to content

Commit

Permalink
Merge pull request exyte#175 from exyte/chore/comments
Browse files Browse the repository at this point in the history
fix comments
  • Loading branch information
f3dm76 authored Feb 27, 2024
2 parents b39defd + 069d637 commit da22c47
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 3 additions & 1 deletion PopupExample/PopupExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ struct ContentView : View {
ActionSheetSecond()
} customize: {
$0
.type(.scroll(scrollViewColor: .white, headerView: AnyView(scrollViewHeader())))
.type(.scroll(headerView: AnyView(scrollViewHeader())))
.position(.bottom)
.closeOnTap(false)
.backgroundColor(.black.opacity(0.4))
Expand Down Expand Up @@ -323,6 +323,7 @@ struct ContentView : View {
)
}

#if os(iOS)
func scrollViewHeader() -> some View {
ZStack {
Color(.white).cornerRadius(40, corners: [.topLeft, .topRight])
Expand All @@ -334,6 +335,7 @@ struct ContentView : View {
.padding(.vertical, 20)
}
}
#endif
}

struct ContentView_Previews: PreviewProvider {
Expand Down
7 changes: 2 additions & 5 deletions Source/PopupScrollViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by vadim.vitkovskiy on 15.02.2024.
//

#if os(iOS)
import UIKit

extension UIScrollView {
Expand All @@ -22,11 +23,6 @@ final class PopupScrollViewDelegate: NSObject, ObservableObject, UIScrollViewDel

var gestureIsCreated = false

var dragGesture: UIPanGestureRecognizer {
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:)))
return panGesture
}

var didReachTop: (Double) -> Void = {_ in }
var scrollEnded: (Double) -> Void = {_ in }

Expand Down Expand Up @@ -60,3 +56,4 @@ final class PopupScrollViewDelegate: NSObject, ObservableObject, UIScrollViewDel
}
}
}
#endif
17 changes: 13 additions & 4 deletions Source/PopupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public struct Popup<PopupContent: View>: ViewModifier {
case `default`
case toast
case floater(verticalPadding: CGFloat = 10, horizontalPadding: CGFloat = 10, useSafeAreaInset: Bool = true)
case scroll(scrollViewColor: Color = .white, headerView: AnyView)
#if os(iOS)
case scroll(headerView: AnyView)
#endif

var defaultPosition: Position {
if case .default = self {
Expand Down Expand Up @@ -366,9 +368,10 @@ public struct Popup<PopupContent: View>: ViewModifier {
@State private var lastDragPosition: CGSize = .zero

// MARK: - Drag to dismiss with scroll

#if os(iOS)
/// UIScrollView delegate, needed for calling didEndDragging
@StateObject private var scrollViewDelegate = PopupScrollViewDelegate()
#endif

/// Position when the scroll content offset became less than 0
@State private var scrollViewOffset: CGSize = .zero
Expand Down Expand Up @@ -474,6 +477,7 @@ public struct Popup<PopupContent: View>: ViewModifier {
return from
}

#if os(iOS)
private func configure(scrollView: UIScrollView) {
scrollView.delegate = scrollViewDelegate

Expand All @@ -496,6 +500,8 @@ public struct Popup<PopupContent: View>: ViewModifier {
}
}

#endif

var screenSize: CGSize {
#if os(iOS)
return UIScreen.main.bounds.size
Expand Down Expand Up @@ -531,15 +537,15 @@ public struct Popup<PopupContent: View>: ViewModifier {

@ViewBuilder
private func contentView() -> some View {
#if os(iOS)
switch type {
case .scroll(let scrollViewColor, let headerView):
case .scroll(let headerView):
VStack(spacing: 0) {
headerView

ScrollView {
view()
}
.background(scrollViewColor)
.introspect(.scrollView, on: .iOS(.v15, .v16, .v17)) { scrollView in
configure(scrollView: scrollView)
}
Expand All @@ -550,6 +556,9 @@ public struct Popup<PopupContent: View>: ViewModifier {
default:
view()
}
#else
view()
#endif
}

/// This is the builder for the sheet content
Expand Down

0 comments on commit da22c47

Please sign in to comment.