Skip to content

Commit

Permalink
Merge pull request #24 from c-villain/issue-13-swipe-hint
Browse files Browse the repository at this point in the history
add swipe hint modifier
  • Loading branch information
c-villain authored May 31, 2024
2 parents 270110b + 6ad9afe commit 2c8f262
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Example/iOS/ExampleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ struct ExampleView: View {
fullSwiped = true
}
}
.swipeHint( // <== HINT
cell == range.first,
hintOffset: 60
)
.listRowInsets(EdgeInsets())
}
}
Expand Down
38 changes: 38 additions & 0 deletions Sources/SwipeActions/ViewModifiers/SwipeHintModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import SwiftUI

public extension View {
@ViewBuilder
func swipeHint(_ isActive: Bool = false, hintOffset: CGFloat, delayIn: CGFloat = 0.5, delayOut: CGFloat = 1.5) -> some View {
if isActive {
modifier(
SwipeHintModifier(
hintOffset: hintOffset,
delayIn: delayIn,
delayOut: delayOut
)
)
} else {
self
}
}
}

public struct SwipeHintModifier: ViewModifier {
let hintOffset: CGFloat
let delayIn: CGFloat
let delayOut: CGFloat
@State private var offset: CGFloat = 0

public func body(content: Content) -> some View {
content
.offset(x: -offset)
.onAppear {
withAnimation(.easeInOut.delay(delayIn)) {
offset = hintOffset
}
withAnimation(.easeInOut.delay(delayOut)) {
offset = 0
}
}
}
}

0 comments on commit 2c8f262

Please sign in to comment.