Created
February 12, 2024 21:46
-
-
Save sebjvidal/2cbd624841d7f433e1f2c7d62bd37604 to your computer and use it in GitHub Desktop.
Slider
This file contains hidden or 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
import SwiftUI | |
struct ContentView: View { | |
@State var isExpanded: Bool = false | |
@State var width: CGFloat = 100 | |
var body: some View { | |
ZStack(alignment: .leading) { | |
Capsule() | |
Capsule() | |
.foregroundStyle(.green) | |
.frame(width: width) | |
.animation(.easeInOut, value: isExpanded) | |
} | |
.frame(height: isExpanded ? 25 : 10) | |
.clipShape(Capsule()) | |
.gesture( | |
DragGesture() | |
.onChanged { value in | |
width = value.location.x | |
withAnimation { | |
isExpanded = true | |
} | |
} | |
.onEnded { value in | |
withAnimation { | |
isExpanded = false | |
} | |
} | |
) | |
.padding(.horizontal) | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment