Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 129 additions & 66 deletions frontend/ios/App/Watch/RestHold.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import WatchKit
* The rest and a hold, on the set page. Both are about one number, so that number is big and
* nothing else competes with it:
*
* rest the time left, a bar draining under it, what is up next (and what to load), the effort
* of the set just done as four chips, then −15 s, Skip and +15 s; ‹ opens the set just
* done to fix it while the rest runs on
* rest the time left in the accent, a bar draining under it, −15, Skip and +15 as outlined
* capsules, the effort of the set just done as four chips, then what is up next (and what
* to load); ‹ opens the set just done to fix it while the rest runs on
* hold the seconds left, a bar in the hold's teal (orange for the last five), and Stop
*
* The buttons wait a second after the rest comes up (the thumb that hit Done is still there).
Expand All @@ -16,109 +16,168 @@ import WatchKit
struct RestView: View {
@EnvironmentObject var store: SessionStore
let end: Date
@Environment(\.isLuminanceReduced) private var dimmed
@Environment(\.isLuminanceReduced) private var luminanceReduced
// CI's Always On, which the pager's pages don't get as an environment value (see ClipView)
private var dimmed: Bool { luminanceReduced || SessionStore.demoAOD }
@Environment(\.accent) private var accent
@Environment(\.dynamicTypeSize) private var typeSize
@ScaledMetric(relativeTo: .largeTitle) private var timeSize: CGFloat = 46
@ScaledMetric(relativeTo: .largeTitle) private var timeSize: CGFloat = 40
/// The screen's height from which the effort label and 38 pt chips fit: 45, 46 and 49 mm (242, 248, 257 pt), not 41 or 44 mm (215, 224).
private static let roomyHeight: CGFloat = 235

var body: some View {
GeometryReader { g in
let roomy = g.size.height >= 175 && !typeSize.isAccessibilitySize
let roomy = g.size.height >= Self.roomyHeight && !typeSize.isAccessibilitySize
VStack(spacing: 4) {
HStack(spacing: 0) {
// The time left in the accent in the top row, level with the system clock (the page has no
// title to push it down); the ‹ is a glass circle before it.
HStack(spacing: 4) {
if store.lastLogged != nil {
ArrowButton(left: true, enabled: true) { store.fixLast() }
.opacity(dimmed ? 0 : 1)
} else {
Color.clear.frame(width: 30, height: 1)
}
VStack(spacing: -2) {
Text("Rest").font(.system(.caption2, design: .rounded).weight(.semibold)).foregroundStyle(Theme.label2)
Text(timerInterval: SafeNum.timerRange(min(Date(), end), end), countsDown: true)
.font(.system(size: timeSize, weight: .semibold, design: .rounded).monospacedDigit())
.foregroundStyle(dimmed ? Color.white.opacity(0.75) : Color.white)
.lineLimit(1)
.minimumScaleFactor(0.5)
.multilineTextAlignment(.center)
Button { store.fixLast() } label: {
Image(systemName: "chevron.left").font(.system(size: 14, weight: .bold)).frame(width: 34, height: 34)
}
.glassCircle()
.opacity(dimmed ? 0 : 1)
.accessibilityLabel(Text("Back"))
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
.frame(maxWidth: .infinity)
Color.clear.frame(width: 30, height: 1)
Text(timerInterval: SafeNum.timerRange(min(Date(), end), end), countsDown: true)
.font(.system(size: timeSize, weight: .semibold, design: .rounded).monospacedDigit())
.foregroundStyle(accent.opacity(dimmed ? 0.75 : 1))
.lineLimit(1)
.minimumScaleFactor(typeSize.isAccessibilitySize ? 0.5 : 0.85) // the clock's corner leaves 0.85 enough
.padding(.leading, 4)
.frame(maxWidth: .infinity, alignment: .leading)
Color.clear.frame(width: 50, height: 1) // the clock's corner
}
.frame(height: 40)
if store.show.restRing {
TimeBar(start: store.restStartedAt ?? end.addingTimeInterval(-90), end: end, color: accent)
.frame(height: 5)
.padding(.horizontal, 6)
}
if store.show.showNext { upNext(roomy: roomy) }
Spacer(minLength: 0)
if store.canRateLast && !dimmed {
EffortChips(roomy: roomy)
.frame(height: 4)
.padding(.horizontal, 4)
.opacity(dimmed ? 0.75 : 1)
}
HStack(spacing: 4) {
EdgeButton(systemImage: "gobackward.15", label: Text(verbatim: "−15 s"), size: 40) { store.minusRest() }
HStack(spacing: 6) {
Button { store.minusRest() } label: {
Text(verbatim: "−15").font(.system(.body, design: .rounded).weight(.bold)).frame(width: 40)
}
.buttonStyle(OutlineCapsule())
.accessibilityLabel(Text(verbatim: "−15 s"))
Button { store.skipRestAndGo() } label: {
Label { Text("Skip") } icon: { Image(systemName: "forward.end.fill") }
.labelStyle(typeSize.isAccessibilitySize ? AnyLabelStyle(.iconOnly) : AnyLabelStyle(.titleAndIcon))
.frame(maxWidth: .infinity)
Text("Skip").font(.system(.callout, design: .rounded).weight(.semibold)).lineLimit(1).minimumScaleFactor(0.6).frame(maxWidth: .infinity)
}
.buttonStyle(OutlineCapsule())
Button { store.addRest(15) } label: {
Text(verbatim: "+15").font(.system(.body, design: .rounded).weight(.bold)).frame(width: 40)
}
.buttonStyle(RowButtonStyle())
EdgeButton(systemImage: "goforward.15", label: Text(verbatim: "+15 s"), size: 40) { store.addRest(15) }
.buttonStyle(OutlineCapsule())
.accessibilityLabel(Text(verbatim: "+15 s"))
}
.opacity(dimmed ? 0 : 1)
.padding(.top, 5) // 4 + 5: the buttons sit right under the bar
let chips = store.canRateLast && !dimmed
if chips {
EffortChips(label: roomy, tall: roomy)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if store.show.showNext { upNext(roomy: roomy, name: true).padding(.top, 2) }
Spacer(minLength: 0) // spare height goes at the bottom, above the page dots
}
.frame(width: g.size.width, height: g.size.height)
.frame(width: g.size.width, height: g.size.height - 12, alignment: .top) // 12: the page dots
}
.ignoresSafeArea(edges: [.top, .bottom])
.padding(.horizontal, 2)
.dynamicTypeSize(...DynamicTypeSize.accessibility2)
}

/// "Up next: Bench Press, set 3 · Left", and under it what to load (#911).
@ViewBuilder private func upNext(roomy: Bool) -> some View {
/// "Up next" in the accent, the set after it ("Bench Press, set 3 · Left") and what to load (#911).
@ViewBuilder private func upNext(roomy: Bool, name: Bool) -> some View {
if let e = store.entry, let si = store.setIndex {
VStack(spacing: 0) {
Group {
if let side = store.sideUp {
Text("Up next") + Text(verbatim: ": ") + Text("\(e.name), set \(Int64(SetNav.place(e, si).n))") + Text(verbatim: " · ")
+ Text(side == "L" ? LocalizedStringKey("Left") : LocalizedStringKey("Right"))
} else {
Text("Up next") + Text(verbatim: ": ") + Text("\(e.name), set \(Int64(SetNav.place(e, si).n))")
VStack(alignment: .leading, spacing: 0) {
Text("Up next").font(.system(.footnote, design: .rounded).weight(.bold)).foregroundStyle(accent)
if name && !typeSize.isAccessibilitySize {
Group {
if let side = store.sideUp {
Text("\(e.name), set \(Int64(SetNav.place(e, si).n))") + Text(verbatim: " · ")
+ Text(side == "L" ? LocalizedStringKey("Left") : LocalizedStringKey("Right"))
} else {
Text("\(e.name), set \(Int64(SetNav.place(e, si).n))")
}
}
.font(.system(.footnote, design: .rounded))
.foregroundStyle(Theme.label2)
.lineLimit(roomy ? 2 : 1)
.truncationMode(.middle)
.minimumScaleFactor(0.85)
}
.font(.system(.caption2, design: .rounded))
.foregroundStyle(Theme.label2)
.lineLimit(roomy ? 2 : 1)
.minimumScaleFactor(0.7)
.multilineTextAlignment(.center)
if let numbers = store.nextSetNumbers {
Text(verbatim: numbers)
.font(.system(.footnote, design: .rounded).weight(.semibold).monospacedDigit())
.font(.system(roomy ? .callout : .footnote, design: .rounded).weight(.semibold).monospacedDigit())
.foregroundStyle(Theme.label2)
.lineLimit(1)
.minimumScaleFactor(0.6)
.minimumScaleFactor(0.85)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.leading, 4)
}
}
}

private extension View {
/// A round Liquid Glass button on watchOS 26; the old filled circle before it.
@ViewBuilder func glassCircle() -> some View {
if #available(watchOS 26, *) {
buttonStyle(.plain).glassEffect(.regular.interactive(), in: .circle)
} else {
buttonStyle(.plain).background(Circle().fill(Theme.surface))
}
}
}

/// "RIR · How hard was that set?" and four chips; once rated, the rating in a small capsule
/// that opens the chips again.
/// The rest screen's buttons: a thin white outline, no fill, 38 pt tall (the look of the old Coaich app).
struct OutlineCapsule: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.font(.system(.body, design: .rounded).weight(.semibold))
.foregroundStyle(.white)
.frame(height: 38)
.background(Capsule().fill(configuration.isPressed ? Theme.surface2 : Color.clear))
.overlay(Capsule().strokeBorder(.white.opacity(0.5), lineWidth: 1.5))
.contentShape(Capsule())
}
}

/// "RIR · Bench Press, set 2" and four round chips outlined in their effort colour; once rated,
/// the rating in a small capsule that opens the chips again.
struct EffortChips: View {
@EnvironmentObject var store: SessionStore
let roomy: Bool
let label: Bool // the "RIR · exercise" line above the chips
let tall: Bool // 38 pt chips; 34 where the screen is short
@State private var again = false

/// The exercise and set the chips rate: the one just done.
private var rated: Text? {
guard let ref = store.lastLogged, let w = store.workout, w.entries.indices.contains(ref.entry) else { return nil }
let e = w.entries[ref.entry]
guard e.sets.indices.contains(ref.set) else { return nil }
return Text("\(e.name), set \(Int64(SetNav.place(e, ref.set).n))")
}

var body: some View {
content.frame(height: (label ? 26 : 0) + (tall ? 38 : 34)) // fixed: the rated capsule must not move what is below
}

@ViewBuilder private var content: some View {
let kind = store.effortKind ?? "rir"
if let rated = store.lastRated, !again {
Button { again = true } label: {
HStack(spacing: 4) {
Text(verbatim: "\(Effort.name(kind)) \(Effort.chipLabel(kind, rated))")
Image(systemName: "checkmark").font(.system(size: 10, weight: .bold))
}
.font(.system(.caption2, design: .rounded).weight(.semibold).monospacedDigit())
.font(.system(.footnote, design: .rounded).weight(.bold).monospacedDigit())
.foregroundStyle(Effort.color(kind, rated))
.padding(.horizontal, 10)
.frame(minHeight: 26)
.frame(minHeight: tall ? 38 : 34)
.background(Capsule().fill(Effort.color(kind, rated).opacity(0.18)))
}
.buttonStyle(.plain)
Expand All @@ -127,12 +186,15 @@ struct EffortChips: View {
.accessibilityHint(Text("Tap to change it."))
} else {
VStack(spacing: 2) {
if roomy {
(Text(verbatim: "\(Effort.name(kind)) · ") + Text("How hard was that set?"))
.font(.system(size: 10, design: .rounded))
if label {
(Text(verbatim: "\(Effort.name(kind)) · ") + (self.rated ?? Text("How hard was that set?")))
.font(.system(.footnote, design: .rounded).weight(.bold))
.foregroundStyle(Theme.label2)
.lineLimit(1)
.minimumScaleFactor(0.6)
.truncationMode(.middle)
.minimumScaleFactor(0.85)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.leading, 4)
}
HStack(spacing: 4) {
ForEach(Effort.chips(kind), id: \.self) { v in
Expand All @@ -141,10 +203,11 @@ struct EffortChips: View {
again = false
} label: {
Text(verbatim: Effort.chipLabel(kind, v))
.font(.system(.footnote, design: .rounded).weight(.semibold).monospacedDigit())
.foregroundStyle(Effort.color(kind, v))
.frame(maxWidth: .infinity, minHeight: 28)
.background(Capsule().fill(Effort.color(kind, v).opacity(0.18)))
.font(.system(.body, design: .rounded).weight(.bold).monospacedDigit())
.foregroundStyle(.white)
.frame(maxWidth: .infinity, minHeight: tall ? 38 : 34, maxHeight: tall ? 38 : 34)
.overlay(Capsule().strokeBorder(Effort.color(kind, v), lineWidth: 1.5))
.contentShape(Capsule())
}
.buttonStyle(.plain)
.accessibilityLabel(Text(verbatim: "\(Effort.name(kind)) \(Effort.chipLabel(kind, v))"))
Expand Down
Loading