diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 3ebec944..44156737 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -82,7 +82,6 @@ D663626C21361C6700C9CBA2 /* Account+Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = D663626B21361C6700C9CBA2 /* Account+Preferences.swift */; }; D663626F213632A000C9CBA2 /* Compose.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D663626E213632A000C9CBA2 /* Compose.storyboard */; }; D66362712136338600C9CBA2 /* ComposeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66362702136338600C9CBA2 /* ComposeViewController.swift */; }; - D66362732136FFC600C9CBA2 /* UITextView+Placeholder.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66362722136FFC600C9CBA2 /* UITextView+Placeholder.swift */; }; D66362752137068A00C9CBA2 /* Visibility+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66362742137068A00C9CBA2 /* Visibility+Helpers.swift */; }; D667E5E12134937B0057A976 /* StatusTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D667E5E02134937B0057A976 /* StatusTableViewCell.xib */; }; D667E5E3213499F70057A976 /* Profile.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D667E5E2213499F70057A976 /* Profile.storyboard */; }; @@ -245,7 +244,6 @@ D663626B21361C6700C9CBA2 /* Account+Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Account+Preferences.swift"; sourceTree = ""; }; D663626E213632A000C9CBA2 /* Compose.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Compose.storyboard; sourceTree = ""; }; D66362702136338600C9CBA2 /* ComposeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeViewController.swift; sourceTree = ""; }; - D66362722136FFC600C9CBA2 /* UITextView+Placeholder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextView+Placeholder.swift"; sourceTree = ""; }; D66362742137068A00C9CBA2 /* Visibility+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Visibility+Helpers.swift"; sourceTree = ""; }; D667E5E02134937B0057A976 /* StatusTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = StatusTableViewCell.xib; sourceTree = ""; }; D667E5E2213499F70057A976 /* Profile.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Profile.storyboard; sourceTree = ""; }; @@ -576,7 +574,6 @@ D667E5F02134D5050057A976 /* UIViewController+Delegates.swift */, D667E5F72135C3040057A976 /* Mastodon+Equatable.swift */, D663626B21361C6700C9CBA2 /* Account+Preferences.swift */, - D66362722136FFC600C9CBA2 /* UITextView+Placeholder.swift */, D66362742137068A00C9CBA2 /* Visibility+Helpers.swift */, D6333B362137838300CE884A /* AttributedString+Trim.swift */, D6333B782139AEFD00CE884A /* Date+TimeAgo.swift */, @@ -985,7 +982,6 @@ D641C777213CAA9E004B4513 /* ActionNotificationTableViewCell.swift in Sources */, D64D0AB12128D9AE005A6F37 /* OnboardingViewController.swift in Sources */, D663626821360E2C00C9CBA2 /* PreferencesTableViewController.swift in Sources */, - D66362732136FFC600C9CBA2 /* UITextView+Placeholder.swift in Sources */, D64F80E2215875CC00BEF393 /* XCBActionType.swift in Sources */, D66362752137068A00C9CBA2 /* Visibility+Helpers.swift in Sources */, D646C95A213B5D0500269FB5 /* LargeImageInteractionController.swift in Sources */, diff --git a/Tusker/Extensions/UITextView+Placeholder.swift b/Tusker/Extensions/UITextView+Placeholder.swift deleted file mode 100644 index 110403a2..00000000 --- a/Tusker/Extensions/UITextView+Placeholder.swift +++ /dev/null @@ -1,66 +0,0 @@ -// -// PlaceholderTextView.swift -// Tusker -// -// Created by Shadowfacts on 8/29/18. -// Copyright © 2018 Shadowfacts. All rights reserved. -// - -import UIKit - -// Source: https://finnwea.com/blog/adding-placeholders-to-uitextviews-in-swift/ -extension UITextView: UITextViewDelegate { - - override open var bounds: CGRect { - didSet { - resizePlaceholder() - } - } - - var placeholder: String? { - get { - return (viewWithTag(100) as? UILabel)?.text - } - set { - if let placeholderLabel = viewWithTag(100) as? UILabel { - placeholderLabel.text = newValue - placeholderLabel.sizeToFit() - } else { - guard let newValue = newValue else { return } - addPlaceholder(newValue) - } - } - } - - public func textViewDidChange(_ textView: UITextView) { - if let placeholderLabel = viewWithTag(100) as? UILabel { - placeholderLabel.isHidden = !text.isEmpty - } - } - - private func resizePlaceholder() { - guard let placeholderLabel = viewWithTag(100) as? UILabel else { fatalError() } - let labelX = textContainer.lineFragmentPadding - let labelY = textContainerInset.top - let labelWidth = frame.width - (labelX * 2) - let labelHeight = placeholderLabel.frame.height - placeholderLabel.frame = CGRect(x: labelX, y: labelY, width: labelWidth, height: labelHeight) - } - - private func addPlaceholder(_ placeholderText: String) { - let placeholderLabel = UILabel() - - placeholderLabel.text = placeholderText - placeholderLabel.sizeToFit() - placeholderLabel.font = font - placeholderLabel.textColor = .lightGray - placeholderLabel.tag = 100 - - placeholderLabel.isHighlighted = !text.isEmpty - - addSubview(placeholderLabel) - resizePlaceholder() - delegate = self - - } -} diff --git a/Tusker/Screens/Compose/Compose.storyboard b/Tusker/Screens/Compose/Compose.storyboard index ffeb548d..f30fdfb3 100644 --- a/Tusker/Screens/Compose/Compose.storyboard +++ b/Tusker/Screens/Compose/Compose.storyboard @@ -144,13 +144,21 @@ + + + @@ -188,6 +196,7 @@ + diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index f4121279..0a8a5b06 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -37,6 +37,7 @@ class ComposeViewController: UIViewController { @IBOutlet weak var inReplyToContentLabel: StatusContentLabel! @IBOutlet weak var inReplyToLabel: UILabel! @IBOutlet weak var statusTextView: UITextView! + @IBOutlet weak var placeholderLabel: UILabel! @IBOutlet weak var charactersRemainingLabel: UILabel! @IBOutlet weak var visibilityButton: UIButton! @IBOutlet weak var postButton: UIButton! @@ -70,7 +71,6 @@ class ComposeViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - statusTextView.placeholder = "What is on your mind?" statusTextView.layer.cornerRadius = 5 statusTextView.layer.masksToBounds = true statusTextView.delegate = self @@ -102,7 +102,6 @@ class ComposeViewController: UIViewController { statusTextView.text = "@\(inReplyTo.account.acct) " } statusTextView.text += inReplyTo.mentions.filter({ $0.id != MastodonController.shared.account.id }).map({ "@\($0.acct) " }).joined() - statusTextView.textViewDidChange(statusTextView) contentWarning = inReplyTo.sensitive contentWarningTextField.text = inReplyTo.spoilerText visibility = inReplyTo.visibility @@ -113,14 +112,13 @@ class ComposeViewController: UIViewController { if let mentioningAcct = mentioningAcct { statusTextView.text += "@\(mentioningAcct) " - statusTextView.textViewDidChange(statusTextView) } if let text = text { statusTextView.text += text - statusTextView.textViewDidChange(statusTextView) } updateCharactersRemaining() + updatePlaceholder() progressView.progress = 0 } @@ -151,6 +149,10 @@ class ComposeViewController: UIViewController { charactersRemainingLabel.text = remaining.description } + func updatePlaceholder() { + placeholderLabel.isHidden = !statusTextView.text.isEmpty + } + // MARK: - Navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { @@ -299,6 +301,7 @@ extension ComposeViewController: UITextFieldDelegate { extension ComposeViewController: UITextViewDelegate { func textViewDidChange(_ textView: UITextView) { updateCharactersRemaining() + updatePlaceholder() } }