-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from c-villain/issue-13-swipe-hint
add swipe hint modifier
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Sources/SwipeActions/ViewModifiers/SwipeHintModifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |