diff --git a/Sources/UI/SwiftUI/View Modifiers/PhotoPreviewModifier.swift b/Sources/UI/SwiftUI/View Modifiers/PhotoPreviewModifier.swift index 373b4028..d9470416 100644 --- a/Sources/UI/SwiftUI/View Modifiers/PhotoPreviewModifier.swift +++ b/Sources/UI/SwiftUI/View Modifiers/PhotoPreviewModifier.swift @@ -8,7 +8,7 @@ import SwiftUI -@available(iOS 15.0, *) +@available(iOS 16.0, *) struct PhotoPreviewModifier: ViewModifier { @Binding var presented: Bool let items: [PhotoPreview.Item] @@ -27,7 +27,7 @@ struct PhotoPreviewModifier: ViewModifier { } } -@available(iOS 15.0, *) +@available(iOS 16.0, *) public extension View { func photoPreview( present: Binding, @@ -42,7 +42,7 @@ public extension View { } } -@available(iOS 15.0, *) +@available(iOS 16.0, *) extension PhotoPreviewModifier { struct PresentationBackgroundModifier: ViewModifier { let color: Color @@ -58,7 +58,7 @@ extension PhotoPreviewModifier { } } -@available(iOS 15.0, *) +@available(iOS 16.0, *) extension View { func presentationBackgroundIfAvailable(_ color: Color) -> some View { modifier(PhotoPreviewModifier.PresentationBackgroundModifier(color: color)) diff --git a/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+Configuration.swift b/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+Configuration.swift index 9d648932..2522c65b 100644 --- a/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+Configuration.swift +++ b/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+Configuration.swift @@ -8,7 +8,7 @@ import SwiftUI -@available(iOS 15.0, *) +@available(iOS 16.0, *) public extension PhotoPreview { struct Configuration { public var backgroundColor: Color @@ -30,7 +30,7 @@ public extension PhotoPreview { } } -@available(iOS 15.0, *) +@available(iOS 16.0, *) public extension PhotoPreview.Configuration { static var `default`: PhotoPreview.Configuration { .init( diff --git a/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+ImageLoader.swift b/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+ImageLoader.swift index 51daedf3..4f875b5c 100644 --- a/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+ImageLoader.swift +++ b/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+ImageLoader.swift @@ -8,7 +8,7 @@ import SwiftUI -@available(iOS 15.0, *) +@available(iOS 16.0, *) extension PhotoPreview { @MainActor class ImageLoader: ObservableObject { @@ -39,7 +39,7 @@ extension PhotoPreview { } // MARK: - State -@available(iOS 15.0, *) +@available(iOS 16.0, *) extension PhotoPreview.ImageLoader { enum State: Equatable { case initial diff --git a/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+Item.swift b/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+Item.swift index 88f60769..509a9635 100644 --- a/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+Item.swift +++ b/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+Item.swift @@ -8,7 +8,7 @@ import SwiftUI -@available(iOS 15.0, *) +@available(iOS 16.0, *) public extension PhotoPreview { struct Item { public var image: Image? diff --git a/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+ItemView.swift b/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+ItemView.swift index d97eec23..f2766d6a 100644 --- a/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+ItemView.swift +++ b/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview+ItemView.swift @@ -11,7 +11,7 @@ import Kingfisher #endif import SwiftUI -@available(iOS 15.0, *) +@available(iOS 16.0, *) extension PhotoPreview { struct ItemView: View { typealias VoidHandler = () -> Swift.Void @@ -64,7 +64,7 @@ extension PhotoPreview { } // MARK: - Views -@available(iOS 15.0, *) +@available(iOS 16.0, *) extension PhotoPreview.ItemView { var imageView: some View { Group { @@ -128,7 +128,7 @@ extension PhotoPreview.ItemView { } // MARK: - Helper methods -@available(iOS 15.0, *) +@available(iOS 16.0, *) extension PhotoPreview.ItemView { func endDrag(animated: Bool = true) { initialDragOffset = .zero @@ -194,7 +194,7 @@ extension PhotoPreview.ItemView { } // MARK: - Gestures -@available(iOS 15.0, *) +@available(iOS 16.0, *) extension PhotoPreview.ItemView { var magnificationGesture: some Gesture { MagnificationGesture() @@ -225,14 +225,7 @@ extension PhotoPreview.ItemView { initialDragOffset = value.translation } let imageWidth = screenSize.width * scale - let maxXOffset = max((imageWidth - screenSize.width) / 2, 0) + dragHorizontalPadding let newXOffset = lastOffset.width + value.translation.width - initialDragOffset.width - if offset.width >= maxXOffset || offset.width <= -maxXOffset { - onDragChanged(value.translation.width) - dragEnabled = false - initialDragOffset = .zero - return - } let newYOffset = lastOffset.height + value.translation.height - initialDragOffset.height offset = CGSize( width: newXOffset, diff --git a/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview.swift b/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview.swift index a7e3241a..97e167cb 100644 --- a/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview.swift +++ b/Sources/UI/SwiftUI/Views/PhotoPreview/PhotoPreview.swift @@ -9,12 +9,13 @@ #if os(iOS) import SwiftUI -@available(iOS 15.0, *) +@available(iOS 16.0, *) public struct PhotoPreview: View { let items: [Item] let configuration: Configuration @Binding var presented: Bool - @State var currentIndex = 0 + @State var position: Int? + @State var currentIndex: Int = 0 @State var offset: CGFloat = 0 @State var verticalOffset: CGFloat = 0 @State var imageViewDragEnabled: Bool = false @@ -24,6 +25,7 @@ public struct PhotoPreview: View { @State var shouldSwitchDragDirection: Bool = true @State var backgroundOpacity: CGFloat = 1 @State var initialDragOffset: CGFloat = .zero + @State var horizontalOffset: CGFloat = .zero public init( items: [Item], @@ -53,38 +55,30 @@ public struct PhotoPreview: View { } // MARK: - ViewBuilders -@available(iOS 15.0, *) +@available(iOS 16.0, *) extension PhotoPreview { var scrollView: some View { GeometryReader { geometry in - ScrollView(.horizontal, showsIndicators: false) { - LazyHStack(spacing: 0) { - ForEach(0.. some Gesture { DragGesture() @@ -224,7 +218,7 @@ extension PhotoPreview { dragDirection = abs(value.translation.width) > abs(value.translation.height) ? .horizontal : .vertical } if dragDirection == .horizontal { - horizontalDragChanged(with: value) +// horizontalDragChanged(with: value) } else if imageViewLastOffset == .zero, offset == 0 { verticalDragChanged(with: value) }