Skip to content

Commit 2c8f262

Browse files
authored
Merge pull request #24 from c-villain/issue-13-swipe-hint
add swipe hint modifier
2 parents 270110b + 6ad9afe commit 2c8f262

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Example/iOS/ExampleView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ struct ExampleView: View {
115115
fullSwiped = true
116116
}
117117
}
118+
.swipeHint( // <== HINT
119+
cell == range.first,
120+
hintOffset: 60
121+
)
118122
.listRowInsets(EdgeInsets())
119123
}
120124
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import SwiftUI
2+
3+
public extension View {
4+
@ViewBuilder
5+
func swipeHint(_ isActive: Bool = false, hintOffset: CGFloat, delayIn: CGFloat = 0.5, delayOut: CGFloat = 1.5) -> some View {
6+
if isActive {
7+
modifier(
8+
SwipeHintModifier(
9+
hintOffset: hintOffset,
10+
delayIn: delayIn,
11+
delayOut: delayOut
12+
)
13+
)
14+
} else {
15+
self
16+
}
17+
}
18+
}
19+
20+
public struct SwipeHintModifier: ViewModifier {
21+
let hintOffset: CGFloat
22+
let delayIn: CGFloat
23+
let delayOut: CGFloat
24+
@State private var offset: CGFloat = 0
25+
26+
public func body(content: Content) -> some View {
27+
content
28+
.offset(x: -offset)
29+
.onAppear {
30+
withAnimation(.easeInOut.delay(delayIn)) {
31+
offset = hintOffset
32+
}
33+
withAnimation(.easeInOut.delay(delayOut)) {
34+
offset = 0
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)