Created
November 2, 2019 22:12
-
-
Save wanderingmatt/aadb4e737a4f18325bc31601719e4556 to your computer and use it in GitHub Desktop.
Fading text from state change
This file contains 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 { | |
@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