Skip to content

Instantly share code, notes, and snippets.

@sebjvidal
Created February 12, 2024 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebjvidal/2cbd624841d7f433e1f2c7d62bd37604 to your computer and use it in GitHub Desktop.
Save sebjvidal/2cbd624841d7f433e1f2c7d62bd37604 to your computer and use it in GitHub Desktop.
Slider
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