Last active
May 16, 2022 20:01
-
-
Save pennisi/a17f1ff2f45aa850a3779159a4d0ff16 to your computer and use it in GitHub Desktop.
SwiftUI custom Transition thingy
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
// | |
// ContentView.swift | |
// TestTest | |
// | |
// Created by Sandro Pennisi on 16.05.22. | |
// | |
import SwiftUI | |
struct WhateverModifier: ViewModifier { | |
let height: Double | |
func body(content: Content) -> some View { | |
content | |
.mask { | |
Rectangle() | |
.frame(maxHeight: height) | |
} | |
} | |
} | |
struct ContentView: View { | |
@State var expanded = false | |
var body: some View { | |
VStack(alignment: .leading) { | |
Text("Hi I am some great cool text and I'm awesome. Hi I am some great cool text and I'm awesome. Hi I am some great cool text and I'm awesome. Hi I am some great cool text and I'm awesome. ") | |
Button { | |
expanded.toggle() | |
} label: { | |
Text("Tap me") | |
} | |
if expanded { | |
Image("img") | |
.resizable() | |
.aspectRatio(contentMode: .fit) | |
.transition(.modifier(active: WhateverModifier(height: 0), identity: WhateverModifier(height: .infinity))) | |
} | |
Text("Hi I am some great cool text and I'm awesome. Hi I am some great cool text and I'm awesome. Hi I am some great cool text and I'm awesome. Hi I am some great cool text and I'm awesome. Hi I am some great cool text and I'm awesome. Hi I am some great cool text and I'm awesome. ") | |
} | |
.animation(.default, value: expanded) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment