Skip to content

Instantly share code, notes, and snippets.

@wanderingmatt
Created November 2, 2019 22:12
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 wanderingmatt/aadb4e737a4f18325bc31601719e4556 to your computer and use it in GitHub Desktop.
Save wanderingmatt/aadb4e737a4f18325bc31601719e4556 to your computer and use it in GitHub Desktop.
Fading text from state change
import SwiftUI
struct ContentView: View {
@EnvironmentObject var taos: TaoStore
@State var tao: Tao
@State var showTao = false
fileprivate func toggleShowTao() {
withAnimation(.easeInOut(duration: 0.35)) {
self.showTao.toggle()
}
}
var body: some View {
VStack {
VStack(alignment: .leading) {
Text(self.$tao.wrappedValue.quote)
.fixedSize(horizontal: false, vertical: true)
.padding(.bottom)
.font(.system(size: 30, design: .serif))
.foregroundColor(.primary)
Text("— " + self.$tao.wrappedValue.author)
.foregroundColor(.secondary)
}
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 30)
.opacity(showTao ? 1 : 0)
}
.onAppear {
self.toggleShowTao()
}
.onTapGesture {
self.backgroundColor = ColorStore().randomBackgroundColor()
self.toggleShowTao()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) {
self.tao = self.taos.randomTao()
self.toggleShowTao()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment