Last active
June 17, 2022 15:23
-
-
Save mattyoung/267e7b6b8ee6a8dea40f72669f5d6a7f to your computer and use it in GitHub Desktop.
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
| import SwiftUI | |
| extension Double { | |
| var zeroToOneCycle: Self { | |
| self >= 0.9 ? 0 : self + 0.1 | |
| } | |
| } | |
| struct ProgressSymbol: View{ | |
| let date: Date | |
| let symbolName: String | |
| @State private var level = Double.zero | |
| var body: some View { | |
| VStack { | |
| Image(systemName: symbolName, variableValue: level) | |
| .symbolRenderingMode(.multicolor) | |
| .font(.system(size: 70)) | |
| .foregroundColor(.mint) | |
| Text(level, format: .percent.precision(.fractionLength(0))) | |
| .foregroundColor(.secondary) | |
| } | |
| .onChange(of: date) { _ in | |
| level = level.zeroToOneCycle | |
| } | |
| } | |
| } | |
| struct SFSymbolVariableColorByYasuhitoNagatomo: View { | |
| let symbols = [ | |
| "rays", "slowmo", "timelapse", | |
| "aqi.medium", "water.waves", "ellipsis.bubble", | |
| "wand.and.rays", "cellularbars", "person.3.sequence.fill", | |
| "square.stack.3d.up.fill", "touchid", "livephoto" | |
| ] | |
| var body: some View { | |
| VStack { | |
| Text("SF Symbols 4 Variable Color") | |
| .font(.largeTitle) | |
| TimelineView(.periodic(from: .now, by: 0.5)) { context in | |
| ScrollView { | |
| LazyVGrid(columns: [GridItem(), GridItem(), GridItem()]) { | |
| ForEach(symbols, id: \.self) { | |
| ProgressSymbol(date: context.date, symbolName: $0) | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| struct SFSymbolVariableColorByYasuhitoNagatomo_Previews: PreviewProvider { | |
| static var previews: some View { | |
| SFSymbolVariableColorByYasuhitoNagatomo() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment