Last active
July 25, 2020 16:22
-
-
Save mattyoung/1716e3a6b36c18d2a939742c41626566 to your computer and use it in GitHub Desktop.
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 AnimateForever: View { | |
@State private var flag = false | |
var body: some View { | |
VStack { | |
Rectangle() | |
// on rectangle, foregroundColor() animate | |
.foregroundColor(flag ? Color.green : Color.red) | |
.frame(width: 150, height: 100) | |
Text("Blah blah blah blah") | |
// this animate!! | |
.scaleEffect(flag ? 1 : 3) | |
// ??? why the color is not animating? | |
// it's a bug! see above rectangle works | |
.foregroundColor(flag ? .green : .red) | |
BoxIn() | |
.foregroundColor(flag ? .green : .red) | |
// works in sim or device, but in Xcode preview, | |
if flag { | |
Text("Blah blah blah blah") | |
.foregroundColor(.green) | |
} else { | |
Text("Blah blah blah blah") | |
.foregroundColor(.red) | |
} | |
} | |
.onAppear { withAnimation(Animation.linear.repeatForever()) { flag.toggle() } } | |
} | |
} | |
// Even when wrapping Text/Image in a view, foregroundColor() still do not animate | |
struct BoxIn: View { | |
var body: some View { | |
VStack { | |
Text("Hello blah blah") | |
Image(systemName: "folder.fill.badge.plus") | |
.resizable() | |
.aspectRatio(contentMode: .fit) | |
.frame(width: 100) | |
Circle() | |
.frame(width: 150, height: 150) | |
} | |
.padding() | |
.border(Color.yellow) | |
.padding(.vertical, 50) | |
} | |
} | |
struct AnimateForever_Previews: PreviewProvider { | |
static var previews: some View { | |
AnimateForever() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment