Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// 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
You can’t perform that action at this time.