Skip to content

Instantly share code, notes, and snippets.

@hesbryce
Created April 2, 2024 04:33
Show Gist options
  • Save hesbryce/7322d0ef32b4573bb832a7fb999ac2d2 to your computer and use it in GitHub Desktop.
Save hesbryce/7322d0ef32b4573bb832a7fb999ac2d2 to your computer and use it in GitHub Desktop.
Stamina Bar set goal
//
// SetStaminaBarGoalView.swift
// Stamina Bar Watch App
//
// Created by Bryce Ellis on 6/12/23.
//
import Foundation
import SwiftUI
struct SetStaminaBarGoalView: View {
@State private var staminaPercentage = 100.0
@State private var isEditing = false
var body: some View {
VStack {
Text("Set Stamina Goal")
Image("\(Int(staminaPercentage))")
.resizable()
.aspectRatio(contentMode: .fit)
.onTapGesture {
self.isEditing = true
}
// The label displaying the current stamina percentage
Text("\(Int(staminaPercentage))%")
.focusable(isEditing)
.digitalCrownRotation($staminaPercentage, from: 1, through: 100, by: 1, sensitivity: .low, isContinuous: false, isHapticFeedbackEnabled: true)
.onReceive(NotificationCenter.default.publisher(for: WKExtension.applicationDidBecomeActiveNotification)) { _ in
self.isEditing = false
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment