summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-06-28 07:01:38 -0700
committerFuwn <[email protected]>2025-06-28 07:01:38 -0700
commit3237aba391df6c7ba1cec821d7692e916741e378 (patch)
treef436b1a767a3902015dc47a46b300af977b0e3a8
parentfeat: Development commit (diff)
downloadsora-testing-3237aba391df6c7ba1cec821d7692e916741e378.tar.xz
sora-testing-3237aba391df6c7ba1cec821d7692e916741e378.zip
feat: Development commit
-rw-r--r--Sora/Views/InteractiveImageView.swift108
1 files changed, 47 insertions, 61 deletions
diff --git a/Sora/Views/InteractiveImageView.swift b/Sora/Views/InteractiveImageView.swift
index dafe9b2..19c4dce 100644
--- a/Sora/Views/InteractiveImageView.swift
+++ b/Sora/Views/InteractiveImageView.swift
@@ -11,8 +11,7 @@ struct InteractiveImageView<MenuItems: View>: View {
@State private var previousOffset: CGSize = .zero
@State private var zoomAnchor: UnitPoint = .center
- @ViewBuilder
- private func primaryImageContent(image: Image) -> some View {
+ var body: some View {
Group {
image
.resizable()
@@ -22,73 +21,60 @@ struct InteractiveImageView<MenuItems: View>: View {
.scaleEffect(currentScale, anchor: zoomAnchor)
.offset(currentOffset)
.frame(maxWidth: .infinity, maxHeight: .infinity)
- }
-
- @ViewBuilder
- private func imageContent(image: Image) -> some View {
- if #available(iOS 26.0, *) {
- primaryImageContent(image: image)
- } else {
- primaryImageContent(image: image)
- .clipped()
- }
- }
-
- var body: some View {
- imageContent(image: image)
- .background(
- GeometryReader { geometry in
- Color.clear
- .onAppear {
- screenWidth = geometry.size.width
- screenHeight = geometry.size.height
+ .ifiOS26Unavailable { $0.clipped() }
+ .background(
+ GeometryReader { geometry in
+ Color.clear
+ .onAppear {
+ screenWidth = geometry.size.width
+ screenHeight = geometry.size.height
+ }
+ }
+ )
+ .gesture(
+ MagnifyGesture()
+ .onChanged { gesture in
+ withAnimation(.interactiveSpring()) {
+ if previousScale == 1 {
+ zoomAnchor = gesture.startAnchor
}
- }
- )
- .gesture(
- MagnifyGesture()
- .onChanged { gesture in
- withAnimation(.interactiveSpring()) {
- if previousScale == 1 {
- zoomAnchor = gesture.startAnchor
- }
- currentScale = max(previousScale * gesture.magnification, 1)
- }
+ currentScale = max(previousScale * gesture.magnification, 1)
}
- .onEnded { _ in
- previousScale = currentScale
- }
- .simultaneously(
- with: (currentScale > 1 ? DragGesture(minimumDistance: 0) : nil)
- .onChanged { gesture in
- withAnimation(.interactiveSpring()) {
- var newOffset: CGSize = .zero
- let offset = gesture.translation
+ }
+ .onEnded { _ in
+ previousScale = currentScale
+ }
+ .simultaneously(
+ with: (currentScale > 1 ? DragGesture(minimumDistance: 0) : nil)
+ .onChanged { gesture in
+ withAnimation(.interactiveSpring()) {
+ var newOffset: CGSize = .zero
+ let offset = gesture.translation
- newOffset.width = offset.width + previousOffset.width
- newOffset.height = offset.height + previousOffset.height
+ newOffset.width = offset.width + previousOffset.width
+ newOffset.height = offset.height + previousOffset.height
- currentOffset = clampOffset(offset: newOffset)
- }
- }
- .onEnded { _ in
- previousOffset = currentOffset
+ currentOffset = clampOffset(offset: newOffset)
}
- )
- )
- .highPriorityGesture(
- TapGesture(count: 2)
- .onEnded {
- withAnimation {
- currentScale = currentScale == 1 ? 2 : 1
- previousScale = currentScale
- currentOffset = .zero
- previousOffset = .zero
- zoomAnchor = .center
}
+ .onEnded { _ in
+ previousOffset = currentOffset
+ }
+ )
+ )
+ .highPriorityGesture(
+ TapGesture(count: 2)
+ .onEnded {
+ withAnimation {
+ currentScale = currentScale == 1 ? 2 : 1
+ previousScale = currentScale
+ currentOffset = .zero
+ previousOffset = .zero
+ zoomAnchor = .center
}
- )
+ }
+ )
}
private func clampOffset(offset: CGSize = .zero) -> CGSize {