Created
June 28, 2019 07:55
-
-
Save CastIrony/1dab629b2041992ba685b0872a9044c0 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
// | |
// ContentView.swift | |
// BreatheUI WatchKit Extension | |
// | |
// Created by Joel Bernstein on 6/24/19. | |
// Copyright © 2019 Joel Bernstein. All rights reserved. | |
// | |
import SwiftUI | |
struct ContentView : View { | |
@State var minutes = 1.0 | |
var circleCount: Double { minutes + 5 } | |
var roundedCircleCount: Int { Int(ceil(circleCount)) } | |
var body: some View { | |
GeometryReader { proxy in | |
ZStack { | |
ForEach(1...self.roundedCircleCount) { index in | |
Circle() | |
.rotation(self.calculateAngle(index), anchor: UnitPoint(x: 0.5, y: 1)) | |
.scale(0.57) | |
.position(CGPoint(x: proxy.size.width * 0.5, y: proxy.size.width * 0.25)) | |
.foregroundColor(Color.white.opacity(self.calculateOpacity(index))) | |
} | |
} | |
} | |
.focusable(true) | |
.digitalCrownRotation($minutes, from: 1, through: 5, by: 1, sensitivity: .low, isContinuous: false, isHapticFeedbackEnabled: true) | |
} | |
func calculateAngle(_ index: Int) -> Angle | |
{ | |
return .degrees(-((Double(index) - 0.5) * (360.0 / self.circleCount))) | |
} | |
func calculateOpacity(_ index: Int) -> Double | |
{ | |
let fadeThreshold = floor(circleCount) | |
return index <= Int(fadeThreshold) ? 0.5 : 0.5 * ( circleCount - fadeThreshold ) | |
} | |
} | |
#if DEBUG | |
struct ContentView_Previews : PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment