Skip to content

Commit 9854598

Browse files
authored
feat: comment view open animation (#322)
1 parent 8c1cadd commit 9854598

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

Splajompy/Extensions/View.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import SwiftUI
2+
3+
extension View {
4+
@ViewBuilder
5+
func modify(@ViewBuilder _ fn: (Self) -> some View) -> some View {
6+
fn(self)
7+
}
8+
}

Splajompy/Extensions/Zoomable.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@
169169
}
170170

171171
extension View {
172-
@ViewBuilder
173-
fileprivate func modify(@ViewBuilder _ fn: (Self) -> some View) -> some View {
174-
fn(self)
175-
}
176-
177172
@ViewBuilder
178173
fileprivate func animatableTransformEffect(_ transform: CGAffineTransform)
179174
-> some View

Splajompy/Posts/PostView.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct PostView: View {
4141
var onPostPinned: () -> Void
4242
var onPostUnpinned: () -> Void
4343

44+
@Namespace private var namespace
4445
@State private var isShowingComments = false
4546
@State private var isReporting = false
4647
@State private var showReportAlert = false
@@ -88,6 +89,15 @@ struct PostView: View {
8889
.padding(.horizontal, 16)
8990
.sheet(isPresented: $isShowingComments) {
9091
CommentsView(postId: post.post.postId, postManager: postManager)
92+
.modify {
93+
#if os(iOS)
94+
if #available(iOS 18, *) {
95+
$0.navigationTransition(
96+
.zoom(sourceID: "comments", in: namespace)
97+
)
98+
}
99+
#endif
100+
}
91101
}
92102
.alert("Post Reported", isPresented: $showReportAlert) {
93103
Button("OK") {}
@@ -244,7 +254,10 @@ struct PostView: View {
244254
}
245255
}
246256

247-
Button(role: .destructive, action: { showDeleteConfirmation = true }) {
257+
Button(
258+
role: .destructive,
259+
action: { showDeleteConfirmation = true }
260+
) {
248261
Label("Delete", systemImage: "trash")
249262
.foregroundColor(.red)
250263
}
@@ -307,6 +320,11 @@ struct PostView: View {
307320
}
308321
.buttonStyle(.plain)
309322
.sensoryFeedback(.impact, trigger: isShowingComments)
323+
.modify {
324+
if #available(iOS 18, *) {
325+
$0.matchedTransitionSource(id: "comments", in: namespace)
326+
}
327+
}
310328

311329
Divider()
312330
.padding(.vertical, 5)

0 commit comments

Comments
 (0)