From b84be51f78afd2aaf8061d0df41627ab2c8269a0 Mon Sep 17 00:00:00 2001 From: Dannykcw <106027442+Dannykcw@users.noreply.github.com> Date: Tue, 29 Apr 2025 18:51:49 -0700 Subject: [PATCH 1/4] Added initial TextEditorWithPlaceHolder --- .../SecondaryAccent.colorset/Contents.json | 3 ++ Canopy/Canopy/TextEditorWithPlaceHolder.swift | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 Canopy/Canopy/TextEditorWithPlaceHolder.swift diff --git a/Canopy/Canopy/Assets.xcassets/SecondaryAccent.colorset/Contents.json b/Canopy/Canopy/Assets.xcassets/SecondaryAccent.colorset/Contents.json index 1bf444a..72ac497 100644 --- a/Canopy/Canopy/Assets.xcassets/SecondaryAccent.colorset/Contents.json +++ b/Canopy/Canopy/Assets.xcassets/SecondaryAccent.colorset/Contents.json @@ -12,6 +12,9 @@ }, "idiom" : "universal" }, + { + "idiom" : "universal" + }, { "appearances" : [ { diff --git a/Canopy/Canopy/TextEditorWithPlaceHolder.swift b/Canopy/Canopy/TextEditorWithPlaceHolder.swift new file mode 100644 index 0000000..9458765 --- /dev/null +++ b/Canopy/Canopy/TextEditorWithPlaceHolder.swift @@ -0,0 +1,49 @@ +// +// TextEditorWithPlaceHolder.swift +// Canopy +// +// Created by Danny Kwong on 4/29/25. +// +import SwiftUI + +struct TextEditorWithPlaceholder: View { + @Binding var text: String + var placeholder: String + + var body: some View { + ZStack(alignment: .topLeading) { + if text.isEmpty { + Text(placeholder) + .fontWeight(.light) + .padding(.top, 10) + .padding(.leading, 6) + .foregroundColor(.secondaryAccent) + } + + TextEditor(text: $text) + .scrollContentBackground(.hidden) // Hide default background + .background(Color(UIColor.secondarySystemBackground)) // Match surrounding background + .frame(minHeight: 150, maxHeight: 300) + .opacity(text.isEmpty ? 0.7 : 1.0) + } + .padding() + .background( + RoundedRectangle(cornerRadius: 12, style: .continuous) + .fill(Color(UIColor.secondarySystemBackground)) + ) + .clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous)) + } +} + +#Preview("Light Mode") { + TextEditorWithPlaceholder(text: .constant(""), placeholder: "What's on your mind today?") + .preferredColorScheme(.dark) + .padding() +} + +#Preview("Dark Mode") { + TextEditorWithPlaceholder(text: .constant(""), placeholder: "What's on your mind today?") + .padding() + .preferredColorScheme(.light) + .padding() +} From 407d693819e49a21bc112309c4ba01d58810f158 Mon Sep 17 00:00:00 2001 From: Dannykcw <106027442+Dannykcw@users.noreply.github.com> Date: Tue, 29 Apr 2025 19:08:33 -0700 Subject: [PATCH 2/4] Fix theme --- Canopy/Canopy/StyleGuide/Theme.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Canopy/Canopy/StyleGuide/Theme.swift b/Canopy/Canopy/StyleGuide/Theme.swift index f13fe47..dc931a6 100644 --- a/Canopy/Canopy/StyleGuide/Theme.swift +++ b/Canopy/Canopy/StyleGuide/Theme.swift @@ -9,9 +9,9 @@ import Foundation import SwiftUI struct Theme { - static let PrimaryColor: Color = Color("Primary") - static let BackgroundColor: Color = Color("Background") - static let PrimaryAccentColor: Color = Color("PrimaryAccent") - static let SecondaryAccentColor: Color = Color("SecondaryAccent") - static let TertiaryAccentColor: Color = Color("TertiaryAccent") + static let PrimaryColor: Color = Color(.primary) + static let BackgroundColor: Color = Color(.background) + static let PrimaryAccentColor: Color = Color(.primaryAccent) + static let SecondaryAccentColor: Color = Color(.secondaryAccent) + static let TertiaryAccentColor: Color = Color(.teriaryAccent) } From c83ad89f2fb4c560fd5660a3cddeecd01737f2c7 Mon Sep 17 00:00:00 2001 From: Dannykcw <106027442+Dannykcw@users.noreply.github.com> Date: Tue, 29 Apr 2025 19:08:54 -0700 Subject: [PATCH 3/4] Refactor Contradiction diary --- Canopy/Canopy/ContradictionDiary.swift | 42 +++++++++++--------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/Canopy/Canopy/ContradictionDiary.swift b/Canopy/Canopy/ContradictionDiary.swift index 9b4d1e7..1d51395 100644 --- a/Canopy/Canopy/ContradictionDiary.swift +++ b/Canopy/Canopy/ContradictionDiary.swift @@ -34,7 +34,7 @@ struct ContradictionDiary: View { ScrollView { VStack(alignment: .leading) { VStack { - headerAndInputCard + header } .background( Image("SunMoonBackground") @@ -42,7 +42,7 @@ struct ContradictionDiary: View { .opacity(0.4) .ignoresSafeArea() ) - + suggestionsSection } .padding(.horizontal) @@ -51,12 +51,7 @@ struct ContradictionDiary: View { .background(Theme.BackgroundColor.ignoresSafeArea()) } - private var headerAndInputCard: some View { - VStack(alignment: .leading) { - header - inputCard - } - } + @State private var userPrompt: String = "" private var header: some View { ZStack { @@ -77,25 +72,21 @@ struct ContradictionDiary: View { .font(TextStyle.body) .foregroundColor(Theme.SecondaryAccentColor) .padding(.horizontal, 24) + VStack { + TextEditorWithPlaceholder( + text: $userPrompt, + placeholder: "What's on your mind today?", + textColor: .black + ) + .cornerRadius(16) + .opacity(0.4) + } + .padding(.horizontal, 24) } .padding(.vertical, 32) } } - private var inputCard: some View { - RoundedRectangle(cornerRadius: 16) - .fill(Theme.TertiaryAccentColor) - .frame(height: 140) - .overlay( - Text("What's on your mind today?") - .font(TextStyle.body) - .foregroundColor(Theme.SecondaryAccentColor) - .padding() - .multilineTextAlignment(.center) - .frame(maxWidth: .infinity, alignment: .center) - ) - } - private var suggestionsSection: some View { VStack(alignment: .leading, spacing: 12) { Text("Suggestions") @@ -104,6 +95,7 @@ struct ContradictionDiary: View { ForEach(displayItems) { item in SuggestionCardView(item: item) + } } } @@ -125,17 +117,19 @@ private struct SuggestionCardView: View { .fill(Theme.TertiaryAccentColor) .frame(height: 50) .redacted(reason: .placeholder) + .padding(.horizontal, 16) } else { ZStack(alignment: .leading) { RoundedRectangle(cornerRadius: 20) .fill(Theme.PrimaryAccentColor) - .frame(height: 60) + .frame(height: 80) Text(item.text) .font(TextStyle.body) .foregroundColor(.white) - .padding(.horizontal, 16) + .padding(.horizontal, 20) } + .padding(.horizontal, 16) } } } From e311ea710b33e49a8687b806f6fe4fe3d44da5d7 Mon Sep 17 00:00:00 2001 From: Dannykcw <106027442+Dannykcw@users.noreply.github.com> Date: Tue, 29 Apr 2025 19:09:25 -0700 Subject: [PATCH 4/4] Revised TextEditorWithPlaceHolder --- Canopy/Canopy/TextEditorWithPlaceHolder.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Canopy/Canopy/TextEditorWithPlaceHolder.swift b/Canopy/Canopy/TextEditorWithPlaceHolder.swift index 9458765..9269b9c 100644 --- a/Canopy/Canopy/TextEditorWithPlaceHolder.swift +++ b/Canopy/Canopy/TextEditorWithPlaceHolder.swift @@ -9,27 +9,31 @@ import SwiftUI struct TextEditorWithPlaceholder: View { @Binding var text: String var placeholder: String + var textColor: Color = .primary + var placeholderColor: Color = .gray + var backgroundColor: Color = Color(UIColor.secondarySystemBackground) var body: some View { ZStack(alignment: .topLeading) { if text.isEmpty { Text(placeholder) - .fontWeight(.light) + .foregroundColor(placeholderColor) .padding(.top, 10) .padding(.leading, 6) - .foregroundColor(.secondaryAccent) + .opacity(0.8) } TextEditor(text: $text) - .scrollContentBackground(.hidden) // Hide default background - .background(Color(UIColor.secondarySystemBackground)) // Match surrounding background + .foregroundColor(textColor) + .scrollContentBackground(.hidden) + .background(backgroundColor) .frame(minHeight: 150, maxHeight: 300) .opacity(text.isEmpty ? 0.7 : 1.0) } .padding() .background( RoundedRectangle(cornerRadius: 12, style: .continuous) - .fill(Color(UIColor.secondarySystemBackground)) + .fill(backgroundColor) ) .clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous)) }