Skip to content

Instantly share code, notes, and snippets.

@eldaroid
Last active June 29, 2024 14:57
Show Gist options
  • Save eldaroid/6da736915496998c574bb23a937157e5 to your computer and use it in GitHub Desktop.
Save eldaroid/6da736915496998c574bb23a937157e5 to your computer and use it in GitHub Desktop.
// BlurReplace, Identity, Move, Offset,
// Opacity, Push, Scale, Slide
// Asymmetric
struct ContentView: View {
@State private var showBlurReplace = false
@State private var showIdentity = false
@State private var showMove = false
@State private var showOffset = false
@State private var showOpacity = false
@State private var showPush = false
@State private var showScale = false
@State private var showSlide = false
@State private var showAsymmetric = false
var body: some View {
ScrollView {
Text("Transition types")
.font(.title)
LazyVGrid(
columns: [
GridItem(.adaptive(minimum: 200, maximum: 300)),
GridItem(.adaptive(minimum: 200, maximum: 300))
],
alignment: .listRowSeparatorLeading,
spacing: 20
) {
Group {
VStack {
Text("BlurReplace (размытие)")
.multilineTextAlignment(.center)
.bold()
.foregroundColor(.red)
if showBlurReplace {
Text("Hello, World!")
.padding(4)
.background(Color.red)
.transition(.blurReplace)
}
Button("Toggle") {
withAnimation {
showBlurReplace.toggle()
}
}
Divider()
}
VStack {
Text("Identity \n(без анимации)")
.multilineTextAlignment(.center)
.bold()
.foregroundColor(.blue)
if showIdentity {
Text("Hello, World!")
.padding(4)
.background(Color.blue)
.transition(.identity)
}
Button("Toggle") {
withAnimation {
showIdentity.toggle()
}
}
Divider()
}
VStack {
Text("Move (перемещать)")
.multilineTextAlignment(.center)
.bold()
.foregroundColor(.green)
if showMove {
Text("Hello, World!")
.padding(4)
.background(Color.green)
.transition(.move(edge: .leading))
}
Button("Toggle") {
withAnimation {
showMove.toggle()
}
}
Divider()
}
VStack {
Text("Offset (смещать)")
.multilineTextAlignment(.center)
.bold()
.foregroundColor(.yellow)
if showOffset {
Text("Hello, World!")
.padding(4)
.background(Color.yellow)
.transition(.offset(x: 200, y: 200))
}
Button("Toggle") {
withAnimation {
showOffset.toggle()
}
}
Divider()
}
VStack {
Text("Opacity (прозрачность)")
.multilineTextAlignment(.center)
.bold()
.foregroundColor(.purple)
if showOpacity {
Text("Hello, World!")
.padding(4)
.background(Color.purple)
.transition(.opacity)
}
Button("Toggle") {
withAnimation {
showOpacity.toggle()
}
}
Divider()
}
VStack {
Text("Push \n(толкать)")
.multilineTextAlignment(.center)
.bold()
.foregroundColor(.orange)
if showPush {
Text("Hello, World!")
.padding(4)
.background(Color.orange)
.transition(.move(edge: .bottom))
}
Button("Toggle") {
withAnimation {
showPush.toggle()
}
}
Divider()
}
VStack {
Text("Scale (масштабировать)")
.multilineTextAlignment(.center)
.bold()
.foregroundColor(.pink)
if showScale {
Text("Hello, World!")
.padding(4)
.background(Color.pink)
.transition(.scale)
}
Button("Toggle") {
withAnimation {
showScale.toggle()
}
}
Divider()
}
VStack {
Text("Slide \n(скользить)")
.multilineTextAlignment(.center)
.bold()
.foregroundColor(.cyan)
if showSlide {
Text("Hello, World!")
.padding(4)
.background(Color.cyan)
.transition(.slide)
}
Button("Toggle") {
withAnimation {
showSlide.toggle()
}
}
Divider()
}
}
}
VStack {
Text("Asymmetric Transition")
.multilineTextAlignment(.center)
.bold()
.foregroundColor(.gray)
if showAsymmetric {
Text("Hello, World!")
.padding(4)
.background(Color.gray)
.transition(
.asymmetric(
insertion: .move(edge: .bottom),
removal: .push(from: .leading)
)
)
}
Button("Toggle") {
withAnimation {
showAsymmetric.toggle()
}
}
Divider()
}
}
}
}
@eldaroid
Copy link
Author

GistTransitionTypes.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment