Last active
July 19, 2022 09:00
-
-
Save GoodRequestGR/6e1cf580acaac35582ca4472013ca5f4 to your computer and use it in GitHub Desktop.
How to Make a Slide to Unlock Button in SwiftUI
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
struct DraggingComponent: View { | |
let maxWidth: CGFloat | |
private let minWidth = CGFloat(50) | |
@State private var width = CGFloat(50) | |
var body: some View { | |
RoundedRectangle(cornerRadius: 16) | |
.fill(Color.blueDark) | |
.frame(width: width) | |
.gesture( | |
DragGesture() | |
.onChanged { value in | |
if value.translation.width > 0 { | |
width = min(max(value.translation.width + minWidth, minWidth), maxWidth) | |
} | |
} | |
) | |
.animation(.spring(response: 0.5, dampingFraction: 1, blendDuration: 0), value: width) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment