From 81ac3708a3674bc925b2c23692f181f7d687c5bd Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 25 Feb 2023 18:22:41 -0500 Subject: [PATCH] Tweak compose placeholders --- .../Screens/Compose/MainComposeTextView.swift | 56 +++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/Tusker/Screens/Compose/MainComposeTextView.swift b/Tusker/Screens/Compose/MainComposeTextView.swift index c56574a9..2ba9dae4 100644 --- a/Tusker/Screens/Compose/MainComposeTextView.swift +++ b/Tusker/Screens/Compose/MainComposeTextView.swift @@ -9,29 +9,9 @@ import SwiftUI import Pachyderm -struct MainComposeTextView: View { +struct MainComposeTextView: View, PlaceholderViewProvider { @ObservedObject var draft: Draft - @State private var placeholder: Text = { - let components = Calendar.current.dateComponents([.month, .day], from: Date()) - if components.month == 3 && components.day == 14 { - if Date().formatted(date: .numeric, time: .omitted).starts(with: "3") { - return Text("Happy π day!") - } - } else if components.month == 9 && components.day == 5 { - // https://weirder.earth/@noracodes/109276419847254552 - // https://retrocomputing.stackexchange.com/questions/14763/what-warning-was-given-on-attempting-to-post-to-usenet-circa-1990 - return Text("This program posts news to thousands of machines throughout the entire populated world. Please be sure you know what you are doing.").italic() - } else if components.month == 9 && components.day == 21 { - return Text("Do you remember?") - } else if components.month == 10 && components.day == 31 { - if .random() { - return Text("Post something spooky!") - } else { - return Text("Any questions?") - } - } - return Text("What's on your mind?") - }() + @State private var placeholder: PlaceholderView = Self.placeholderView() let minHeight: CGFloat = 150 @State private var height: CGFloat? @@ -68,6 +48,38 @@ struct MainComposeTextView: View { } } } + + @ViewBuilder + static func placeholderView() -> some View { + let components = Calendar.current.dateComponents([.month, .day], from: Date()) + if components.month == 3 && components.day == 14, + Date().formatted(date: .numeric, time: .omitted).starts(with: "3") { + Text("Happy π day!") + } else if components.month == 4 && components.day == 1 { + Text("April Fool's!").rotationEffect(.radians(.pi), anchor: .center) + } else if components.month == 9 && components.day == 5 { + // https://weirder.earth/@noracodes/109276419847254552 + // https://retrocomputing.stackexchange.com/questions/14763/what-warning-was-given-on-attempting-to-post-to-usenet-circa-1990 + Text("This program posts news to thousands of machines throughout the entire populated world. Please be sure you know what you are doing.").italic() + } else if components.month == 9 && components.day == 21 { + Text("Do you remember?") + } else if components.month == 10 && components.day == 31 { + if .random() { + Text("Post something spooky!") + } else { + Text("Any questions?") + } + } else { + Text("What's on your mind?") + } + } +} + +// exists to provide access to the type alias since the @State property needs it to be explicit +private protocol PlaceholderViewProvider { + associatedtype PlaceholderView: View + @ViewBuilder + static func placeholderView() -> PlaceholderView } struct MainComposeWrappedTextView: UIViewRepresentable {