polish iOS study flow

This commit is contained in:
2026-04-09 15:51:03 +02:00
parent 5c0aa9542a
commit 0cfd847d62
16 changed files with 508 additions and 94 deletions
@@ -2,6 +2,7 @@ import SwiftUI
struct FeedView: View {
@EnvironmentObject private var localization: LocalizationStore
@EnvironmentObject private var analytics: HermesAnalyticsClient
var body: some View {
VStack(alignment: .leading, spacing: HermesTheme.sectionSpacing) {
@@ -40,11 +41,17 @@ struct FeedView: View {
}
Button {
analytics.track("next_round_requested", attributes: ["screen_name": "feed"])
analytics.track("cta_pressed", attributes: ["screen_name": "feed", "action": "watch_preview"])
} label: {
Text(localization.string(for: "feed.cta"))
}
.buttonStyle(HermesPrimaryButtonStyle())
}
.hermesCard(elevated: true)
.onAppear {
analytics.track("feed_viewed", attributes: ["screen_name": "feed"])
analytics.track("screen_viewed", attributes: ["screen_name": "feed"])
}
}
}
@@ -2,6 +2,7 @@ import SwiftUI
struct OnboardingView: View {
@EnvironmentObject private var localization: LocalizationStore
@EnvironmentObject private var analytics: HermesAnalyticsClient
var body: some View {
VStack(alignment: .leading, spacing: HermesTheme.sectionSpacing) {
@@ -24,11 +25,17 @@ struct OnboardingView: View {
}
Button {
analytics.track("consent_accepted", attributes: ["screen_name": "onboarding"])
analytics.track("cta_pressed", attributes: ["screen_name": "onboarding", "action": "start_session"])
} label: {
Text(localization.string(for: "onboarding.start_session"))
}
.buttonStyle(HermesPrimaryButtonStyle())
}
.hermesCard(elevated: true)
.onAppear {
analytics.track("screen_viewed", attributes: ["screen_name": "onboarding"])
analytics.track("consent_viewed", attributes: ["screen_name": "onboarding"])
}
}
}
@@ -1,7 +1,48 @@
import SwiftUI
struct ResultView: View {
let title: String
let subtitle: String
let selectionLabel: String
let selectionValue: String
let outcomeLabel: String
let outcomeValue: String
let didWin: Bool
let winLabel: String
let loseLabel: String
let nextRoundTitle: String
let onNextRound: () -> Void
@EnvironmentObject private var analytics: HermesAnalyticsClient
var body: some View {
Text("Result scaffold")
VStack(alignment: .leading, spacing: HermesTheme.sectionSpacing) {
HermesSectionHeader(title: title, subtitle: subtitle)
HStack(spacing: 12) {
HermesMetricPill(label: selectionLabel, value: selectionValue)
HermesMetricPill(label: outcomeLabel, value: outcomeValue)
}
HStack(spacing: 10) {
Image(systemName: didWin ? "checkmark.seal.fill" : "xmark.seal.fill")
.foregroundStyle(didWin ? HermesTheme.positive : HermesTheme.warning)
Text(didWin ? winLabel : loseLabel)
.font(.headline.weight(.semibold))
.foregroundStyle(HermesTheme.textPrimary)
}
Button {
analytics.track("next_round_requested", attributes: ["screen_name": "result"])
onNextRound()
} label: {
Text(nextRoundTitle)
}
.buttonStyle(HermesPrimaryButtonStyle())
}
.onAppear {
analytics.track("screen_viewed", attributes: ["screen_name": "result"])
analytics.track("result_viewed", attributes: ["screen_name": "result", "selection": selectionValue, "outcome": outcomeValue])
}
}
}
@@ -1,7 +1,39 @@
import SwiftUI
struct RevealView: View {
let title: String
let subtitle: String
let statusText: String
let selectionLabel: String
let selectionValue: String
let continueTitle: String
let onContinue: () -> Void
@EnvironmentObject private var analytics: HermesAnalyticsClient
var body: some View {
Text("Reveal scaffold")
VStack(alignment: .leading, spacing: HermesTheme.sectionSpacing) {
HermesSectionHeader(title: title, subtitle: subtitle)
VStack(alignment: .leading, spacing: 12) {
HermesMetricPill(label: selectionLabel, value: selectionValue)
Text(statusText)
.font(.callout)
.foregroundStyle(HermesTheme.textSecondary)
}
Button {
analytics.track("reveal_completed", attributes: ["screen_name": "reveal", "selection": selectionValue])
onContinue()
} label: {
Text(continueTitle)
}
.buttonStyle(HermesPrimaryButtonStyle())
}
.onAppear {
analytics.track("screen_viewed", attributes: ["screen_name": "reveal"])
analytics.track("reveal_started", attributes: ["screen_name": "reveal", "selection": selectionValue])
}
}
}
+205 -81
View File
@@ -2,104 +2,228 @@ import SwiftUI
struct RoundView: View {
@EnvironmentObject private var localization: LocalizationStore
@State private var selectedOutcomeID = "home"
@EnvironmentObject private var analytics: HermesAnalyticsClient
private struct OutcomeOption: Identifiable {
let id: String
let label: String
let odds: String
@StateObject private var playerCoordinator = PlayerCoordinator()
@State private var phase: Phase = .preview
@State private var selectedOutcomeID: String? = nil
@State private var lockAt: Date = Date().addingTimeInterval(47)
@State private var transitionTask: Task<Void, Never>?
private let previewDuration: TimeInterval = 47
private let winningOutcomeID = "home"
private enum Phase {
case preview
case locked
case reveal
case result
}
private var outcomeOptions: [OutcomeOption] {
private var selectionOptions: [SelectionOption] {
[
OutcomeOption(id: "home", label: localization.string(for: "round.home"), odds: "1.85"),
OutcomeOption(id: "away", label: localization.string(for: "round.away"), odds: "2.05"),
SelectionOption(
id: "home",
title: localization.string(for: "round.home"),
subtitle: localization.string(for: "round.selection_prompt"),
odds: "1.85"
),
SelectionOption(
id: "away",
title: localization.string(for: "round.away"),
subtitle: localization.string(for: "round.selection_prompt"),
odds: "2.05"
),
]
}
private var selectedOutcome: SelectionOption? {
guard let selectedOutcomeID else {
return nil
}
return selectionOptions.first { $0.id == selectedOutcomeID }
}
private var winningOutcome: SelectionOption {
selectionOptions.first { $0.id == winningOutcomeID } ?? selectionOptions[0]
}
var body: some View {
VStack(alignment: .leading, spacing: HermesTheme.sectionSpacing) {
HermesSectionHeader(
title: localization.string(for: "round.title"),
subtitle: localization.string(for: "round.subtitle")
)
TimelineView(.periodic(from: Date(), by: 1)) { context in
let remaining = max(lockAt.timeIntervalSince(context.date), 0)
let timerLocked = remaining <= 0
let countdownText = Self.countdownText(for: remaining)
VStack(alignment: .leading, spacing: 14) {
ZStack(alignment: .topTrailing) {
RoundedRectangle(cornerRadius: HermesTheme.cornerRadius, style: .continuous)
.fill(
LinearGradient(
colors: [HermesTheme.surfaceElevated, HermesTheme.background],
startPoint: .top,
endPoint: .bottom
)
)
.frame(height: 200)
VStack(alignment: .leading, spacing: HermesTheme.sectionSpacing) {
HermesSectionHeader(
title: localization.string(for: "round.title"),
subtitle: localization.string(for: "round.subtitle")
)
Text(localization.string(for: "round.video_placeholder"))
.font(.caption.weight(.semibold))
.foregroundStyle(HermesTheme.textSecondary)
.padding(12)
}
videoSection(countdownText: countdownText, remaining: remaining, isTimerLocked: timerLocked)
HStack(spacing: 12) {
HermesCountdownBadge(
label: localization.string(for: "round.countdown_label"),
value: "00:47"
)
HermesMetricPill(label: localization.string(for: "round.odds_label"), value: "1.85 / 2.05")
}
Text(localization.string(for: "round.selection_prompt"))
.font(.callout)
.foregroundStyle(HermesTheme.textSecondary)
VStack(spacing: 10) {
ForEach(outcomeOptions) { option in
outcomeButton(option)
}
}
Button {
} label: {
Text(localization.string(for: "round.primary_cta"))
}
.buttonStyle(HermesPrimaryButtonStyle())
phaseContent(isTimerLocked: timerLocked)
}
}
.hermesCard(elevated: true)
.onAppear {
startPreview()
}
.onDisappear {
transitionTask?.cancel()
playerCoordinator.pause()
}
}
private func outcomeButton(_ option: OutcomeOption) -> some View {
let isSelected = selectedOutcomeID == option.id
return Button {
selectedOutcomeID = option.id
} label: {
HStack {
VStack(alignment: .leading, spacing: 4) {
Text(option.label)
.font(.headline.weight(.semibold))
Text(option.odds)
.font(.caption.weight(.semibold))
.foregroundStyle(isSelected ? HermesTheme.background.opacity(0.72) : HermesTheme.textSecondary)
}
Spacer()
Image(systemName: isSelected ? "checkmark.circle.fill" : "circle")
.font(.headline)
}
.padding(.horizontal, 16)
.padding(.vertical, 14)
.foregroundStyle(isSelected ? HermesTheme.background : HermesTheme.textPrimary)
.background(isSelected ? HermesTheme.accent : HermesTheme.surfaceElevated)
.overlay(
RoundedRectangle(cornerRadius: HermesTheme.insetRadius, style: .continuous)
.stroke(isSelected ? HermesTheme.accent : HermesTheme.accent.opacity(0.14), lineWidth: 1)
@ViewBuilder
private func phaseContent(isTimerLocked: Bool) -> some View {
switch phase {
case .preview, .locked:
SelectionView(
statusText: isTimerLocked || phase != .preview ? localization.string(for: "round.locked_label") : localization.string(for: "round.selection_prompt"),
options: selectionOptions,
selectedOptionID: selectedOutcomeID,
isLocked: isTimerLocked || phase != .preview,
confirmTitle: localization.string(for: "round.primary_cta"),
onSelect: handleSelection,
onConfirm: confirmSelection
)
case .reveal:
RevealView(
title: localization.string(for: "reveal.title"),
subtitle: localization.string(for: "reveal.subtitle"),
statusText: localization.string(for: "reveal.status"),
selectionLabel: localization.string(for: "result.selection_label"),
selectionValue: selectedOutcome?.title ?? localization.string(for: "round.selection_prompt"),
continueTitle: localization.string(for: "reveal.cta"),
onContinue: showResult
)
case .result:
ResultView(
title: localization.string(for: "result.title"),
subtitle: localization.string(for: "result.subtitle"),
selectionLabel: localization.string(for: "result.selection_label"),
selectionValue: selectedOutcome?.title ?? localization.string(for: "round.selection_prompt"),
outcomeLabel: localization.string(for: "result.outcome_label"),
outcomeValue: winningOutcome.title,
didWin: selectedOutcomeID == winningOutcomeID,
winLabel: localization.string(for: "result.win"),
loseLabel: localization.string(for: "result.lose"),
nextRoundTitle: localization.string(for: "result.next_round"),
onNextRound: resetRound
)
.clipShape(RoundedRectangle(cornerRadius: HermesTheme.insetRadius, style: .continuous))
}
.buttonStyle(.plain)
}
@ViewBuilder
private func videoSection(countdownText: String, remaining: TimeInterval, isTimerLocked: Bool) -> some View {
ZStack(alignment: .topTrailing) {
StudyVideoPlayerView(coordinator: playerCoordinator)
VStack(alignment: .trailing, spacing: 10) {
HermesCountdownBadge(
label: localization.string(for: "round.countdown_label"),
value: countdownText,
warning: !isTimerLocked && remaining <= 10
)
HermesMetricPill(
label: localization.string(for: "round.odds_label"),
value: "1.85 / 2.05"
)
}
.padding(12)
Text(phaseLabel(isTimerLocked: isTimerLocked))
.font(.caption.weight(.bold))
.foregroundStyle(HermesTheme.textPrimary)
.padding(.horizontal, 12)
.padding(.vertical, 8)
.background(.black.opacity(0.35))
.clipShape(Capsule())
.padding(12)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomLeading)
}
}
private func phaseLabel(isTimerLocked: Bool) -> String {
switch phase {
case .preview:
return isTimerLocked ? localization.string(for: "round.locked_label") : localization.string(for: "round.preview_label")
case .locked:
return localization.string(for: "round.locked_label")
case .reveal:
return localization.string(for: "reveal.title")
case .result:
return localization.string(for: "result.title")
}
}
private func startPreview() {
transitionTask?.cancel()
phase = .preview
lockAt = Date().addingTimeInterval(previewDuration)
selectedOutcomeID = nil
playerCoordinator.restart()
analytics.track("round_loaded", attributes: ["screen_name": "round"])
analytics.track("preview_started", attributes: ["screen_name": "round"])
analytics.track("screen_viewed", attributes: ["screen_name": "round"])
}
private func handleSelection(_ option: SelectionOption) {
guard phase == .preview else {
return
}
selectedOutcomeID = option.id
analytics.track("outcome_focused", attributes: ["screen_name": "round", "outcome_id": option.id])
analytics.track("outcome_selected", attributes: ["screen_name": "round", "outcome_id": option.id])
}
private func confirmSelection() {
guard phase == .preview, let selectedOutcomeID else {
return
}
analytics.track("selection_submitted", attributes: ["screen_name": "round", "outcome_id": selectedOutcomeID])
analytics.track("selection_accepted", attributes: ["screen_name": "round", "outcome_id": selectedOutcomeID])
analytics.track("market_locked", attributes: ["screen_name": "round", "lock_reason": "manual_selection"])
phase = .locked
playerCoordinator.pause()
transitionTask?.cancel()
transitionTask = Task { @MainActor in
try? await Task.sleep(nanoseconds: 750_000_000)
guard !Task.isCancelled else {
return
}
phase = .reveal
}
}
private func showResult() {
analytics.track("reveal_completed", attributes: ["screen_name": "round"])
phase = .result
}
private func resetRound() {
transitionTask?.cancel()
selectedOutcomeID = nil
phase = .preview
lockAt = Date().addingTimeInterval(previewDuration)
playerCoordinator.restart()
}
private static func countdownText(for remaining: TimeInterval) -> String {
let totalSeconds = max(Int(remaining.rounded(.down)), 0)
let minutes = totalSeconds / 60
let seconds = totalSeconds % 60
return String(format: "%02d:%02d", minutes, seconds)
}
}
@@ -1,7 +1,90 @@
import SwiftUI
struct SelectionOption: Identifiable, Equatable {
let id: String
let title: String
let subtitle: String
let odds: String
}
struct SelectionView: View {
let statusText: String
let options: [SelectionOption]
let selectedOptionID: String?
let isLocked: Bool
let confirmTitle: String
let onSelect: (SelectionOption) -> Void
let onConfirm: () -> Void
var body: some View {
Text("Selection scaffold")
VStack(alignment: .leading, spacing: HermesTheme.sectionSpacing) {
statusBadge
VStack(spacing: 10) {
ForEach(options) { option in
optionButton(option)
}
}
Button {
onConfirm()
} label: {
Text(confirmTitle)
}
.buttonStyle(HermesPrimaryButtonStyle())
.disabled(isLocked || selectedOptionID == nil)
}
}
private var statusBadge: some View {
HStack(spacing: 8) {
Image(systemName: isLocked ? "lock.fill" : "hand.tap.fill")
.font(.caption.weight(.semibold))
Text(statusText)
.font(.caption.weight(.semibold))
}
.foregroundStyle(isLocked ? HermesTheme.warning : HermesTheme.textSecondary)
.padding(.horizontal, 12)
.padding(.vertical, 8)
.background((isLocked ? HermesTheme.warning : HermesTheme.accent).opacity(0.16))
.clipShape(Capsule())
}
private func optionButton(_ option: SelectionOption) -> some View {
let selected = selectedOptionID == option.id
return Button {
onSelect(option)
} label: {
HStack(alignment: .center, spacing: 14) {
VStack(alignment: .leading, spacing: 4) {
Text(option.title)
.font(.headline.weight(.semibold))
Text(option.subtitle)
.font(.caption)
.foregroundStyle(selected ? HermesTheme.background.opacity(0.68) : HermesTheme.textSecondary)
}
Spacer(minLength: 8)
VStack(alignment: .trailing, spacing: 4) {
Text(option.odds)
.font(.headline.weight(.bold))
Image(systemName: selected ? "checkmark.circle.fill" : "circle")
.font(.subheadline.weight(.semibold))
}
}
.padding(.horizontal, 16)
.padding(.vertical, 14)
.foregroundStyle(selected ? HermesTheme.background : HermesTheme.textPrimary)
.background(selected ? HermesTheme.accent : HermesTheme.surfaceElevated)
.overlay(
RoundedRectangle(cornerRadius: HermesTheme.insetRadius, style: .continuous)
.stroke(selected ? HermesTheme.accent : HermesTheme.accent.opacity(0.14), lineWidth: 1)
)
.clipShape(RoundedRectangle(cornerRadius: HermesTheme.insetRadius, style: .continuous))
}
.buttonStyle(.plain)
.disabled(isLocked)
}
}