Skip to content

Commit

Permalink
Optional Big BG Watch View
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-b-m committed Mar 29, 2023
1 parent c77855b commit 74cfbac
Showing 1 changed file with 53 additions and 4 deletions.
57 changes: 53 additions & 4 deletions FreeAPSWatch WatchKit Extension/Views/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ struct MainView: View {
@GestureState var isDetectingLongPress = false
@State var completedLongPress = false

@State var completedLongPressOfBG = false
@GestureState var isDetectingLongPressOfBG = false

private var healthStore = HKHealthStore()
let heartRateQuantity = HKUnit(from: "count/min")

Expand All @@ -33,9 +36,13 @@ struct MainView: View {
}
}
VStack {
header
Spacer()
buttons
if !completedLongPressOfBG {
header
Spacer()
buttons
} else {
bigHeader
}
}

if state.isConfirmationViewActive {
Expand Down Expand Up @@ -153,7 +160,36 @@ struct MainView: View {
}
Spacer()
.onAppear(perform: start)
}.padding()
}
.padding()
// .scaleEffect(isDetectingLongPressOfBG ? 3 : 1)
.gesture(longPresBGs)
}

var bigHeader: some View {
VStack(alignment: .center) {
HStack {
Text(state.glucose).font(.custom("Big BG", size: 55))
Text(state.trend)
.scaledToFill()
.minimumScaleFactor(0.5)
}
Text(state.delta).font(.caption2).foregroundColor(.gray)

Spacer()
Spacer()

HStack {
Circle().stroke(color, lineWidth: 5).frame(width: 26, height: 26).padding(10)
}

if state.lastLoopDate != nil {
Text(timeString).font(.caption2).foregroundColor(.gray)
} else {
Text("--").font(.caption2).foregroundColor(.gray)
}
} // .scaleEffect(isDetectingLongPressOfBG ? 3 : 1)
.gesture(longPresBGs)
}

var longPress: some Gesture {
Expand All @@ -169,6 +205,19 @@ struct MainView: View {
}
}

var longPresBGs: some Gesture {
LongPressGesture(minimumDuration: 1)
.updating($isDetectingLongPressOfBG) { currentState, gestureState,
_ in
gestureState = currentState
}
.onEnded { _ in
if completedLongPressOfBG {
completedLongPressOfBG = false
} else { completedLongPressOfBG = true }
}
}

var buttons: some View {
HStack(alignment: .center) {
NavigationLink(isActive: $state.isCarbsViewActive) {
Expand Down

0 comments on commit 74cfbac

Please sign in to comment.