Skip to content
Open
Changes from all 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
109 changes: 85 additions & 24 deletions SleepFocus/Screens/BehaviorOnboardingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SwiftUI

// MARK: - Question Model

private struct BehaviorQuestion: Identifiable {
struct BehaviorQuestion: Identifiable {
let id: Int
let category: String
let categoryIcon: String
Expand All @@ -15,7 +15,7 @@ private struct BehaviorQuestion: Identifiable {

// MARK: - Questions

private let allQuestions: [BehaviorQuestion] = [
let allQuestions: [BehaviorQuestion] = [

// BEHAVIOR
BehaviorQuestion(
Expand Down Expand Up @@ -194,9 +194,11 @@ struct BehaviorOnboardingView: View {

@State private var currentIndex: Int = 0
@State private var animateIn: Bool = false
@State private var showDismissConfirmation: Bool = false

private var question: BehaviorQuestion { allQuestions[currentIndex] }
private var progress: Double { Double(currentIndex + 1) / Double(allQuestions.count) }
private var isFirst: Bool { currentIndex == 0 }
private var isLast: Bool { currentIndex == allQuestions.count - 1 }

var body: some View {
Expand All @@ -205,32 +207,49 @@ struct BehaviorOnboardingView: View {

VStack(spacing: 0) {

// Progress bar
VStack(alignment: .leading, spacing: 12) {
HStack {
Text("Sleep Profile Setup")
.font(.subheadline)
.foregroundColor(.secondary)
Spacer()
Text("\(currentIndex + 1) of \(allQuestions.count)")
.font(.subheadline.monospacedDigit())
// Top bar: back button + progress counter + X button
HStack(alignment: .center) {
Button(action: goBack) {
Image(systemName: "chevron.left")
.font(.system(size: 17, weight: .semibold))
.foregroundColor(isFirst ? .clear : .accentColor)
}
.disabled(isFirst)

Spacer()

Text("\(currentIndex + 1) of \(allQuestions.count)")
.font(.subheadline.monospacedDigit())
.foregroundColor(.secondary)

Spacer()

Button(action: { showDismissConfirmation = true }) {
Image(systemName: "xmark")
.font(.system(size: 15, weight: .semibold))
.foregroundColor(.secondary)
.padding(8)
.background(Color.secondary.opacity(0.12), in: Circle())
}
GeometryReader { geo in
ZStack(alignment: .leading) {
RoundedRectangle(cornerRadius: 4)
.fill(Color.secondary.opacity(0.2))
.frame(height: 6)
RoundedRectangle(cornerRadius: 4)
.fill(Color.accentColor)
.frame(width: geo.size.width * progress, height: 6)
.animation(.spring(response: 0.4), value: progress)
}
}
.padding(.horizontal, 20)
.padding(.top, 16)

// Progress bar
GeometryReader { geo in
ZStack(alignment: .leading) {
RoundedRectangle(cornerRadius: 4)
.fill(Color.secondary.opacity(0.2))
.frame(height: 6)
RoundedRectangle(cornerRadius: 4)
.fill(Color.accentColor)
.frame(width: geo.size.width * progress, height: 6)
.animation(.spring(response: 0.4), value: progress)
}
.frame(height: 6)
}
.frame(height: 6)
.padding(.horizontal, 24)
.padding(.top, 20)
.padding(.top, 12)

Spacer()

Expand Down Expand Up @@ -302,6 +321,19 @@ struct BehaviorOnboardingView: View {
}
}
.onAppear { animateQuestion() }
.confirmationDialog(
"Finish setup later?",
isPresented: $showDismissConfirmation,
titleVisibility: .visible
) {
Button("Finish Later") {
store.save()
onComplete()
}
Button("Continue Setup", role: .cancel) {}
} message: {
Text("You can complete your Sleep Profile anytime from the Profile section in Settings.")
}
}

// MARK: - Helpers
Expand All @@ -326,6 +358,15 @@ struct BehaviorOnboardingView: View {
}
}

private func goBack() {
guard !isFirst else { return }
withAnimation(.easeIn(duration: 0.15)) { animateIn = false }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
currentIndex -= 1
animateQuestion()
}
}

private func animateQuestion() {
animateIn = false
withAnimation(.spring(response: 0.45, dampingFraction: 0.8).delay(0.05)) {
Expand All @@ -336,7 +377,7 @@ struct BehaviorOnboardingView: View {

// MARK: - Answer Button

private struct AnswerButton: View {
struct AnswerButton: View {
let label: String
let answer: BehaviorAnswer
let selected: BehaviorAnswer
Expand Down Expand Up @@ -380,3 +421,23 @@ private struct AnswerButton: View {
print("Onboarding complete")
}
}




















Loading