Ditch pod in favor of own implementation

This commit is contained in:
nielsandriesse 2020-08-04 13:56:02 +10:00
parent 618c73b07f
commit 9b527424e6
5 changed files with 23 additions and 18 deletions

View File

@ -77,7 +77,6 @@ target 'Signal' do
pod 'FeedKit', '~> 8.1', :inhibit_warnings => true
pod 'CryptoSwift', '~> 1.3', :inhibit_warnings => true
pod 'NVActivityIndicatorView', '~> 4.7', :inhibit_warnings => true
pod 'UITextView+Placeholder', '~> 1.4', :inhibit_warnings => true
target 'SignalTests' do
inherit! :search_paths

View File

@ -130,7 +130,6 @@ PODS:
- SSZipArchive (2.2.3)
- Starscream (3.0.6)
- SwiftProtobuf (1.5.0)
- "UITextView+Placeholder (1.4.0)"
- YapDatabase/SQLCipher (3.1.1):
- YapDatabase/SQLCipher/Core (= 3.1.1)
- YapDatabase/SQLCipher/Extensions (= 3.1.1)
@ -223,7 +222,6 @@ DEPENDENCIES:
- SQLCipher (>= 4.0.1)
- SSZipArchive
- Starscream (from `https://github.com/signalapp/Starscream.git`, branch `signal-release`)
- "UITextView+Placeholder (~> 1.4)"
- YapDatabase/SQLCipher (from `https://github.com/signalapp/YapDatabase.git`, branch `signal-release`)
- YYImage
@ -243,7 +241,6 @@ SPEC REPOS:
- SQLCipher
- SSZipArchive
- SwiftProtobuf
- "UITextView+Placeholder"
- YYImage
EXTERNAL SOURCES:
@ -325,10 +322,9 @@ SPEC CHECKSUMS:
SSZipArchive: 62d4947b08730e4cda640473b0066d209ff033c9
Starscream: 8aaf1a7feb805c816d0e7d3190ef23856f6665b9
SwiftProtobuf: 241400280f912735c1e1b9fe675fdd2c6c4d42e2
"UITextView+Placeholder": d7b0c400921f66523f3a85d74f774512e14f6502
YapDatabase: b418a4baa6906e8028748938f9159807fd039af4
YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54
PODFILE CHECKSUM: 0d59a208ed95a7e5640a3e89cff48cd0a5b51e0b
PODFILE CHECKSUM: b4f88816a817cc27f499940c644c0449ef5d7cc7
COCOAPODS: 1.9.3

2
Pods

@ -1 +1 @@
Subproject commit 5d61962cd5848660e72017012f20caab92289f48
Subproject commit 71f54b041ff9b9a77fecea805aa42ac536392c40

View File

@ -3417,7 +3417,6 @@
"${BUILT_PRODUCTS_DIR}/SessionServiceKit/SessionServiceKit.framework",
"${BUILT_PRODUCTS_DIR}/Starscream/Starscream.framework",
"${BUILT_PRODUCTS_DIR}/SwiftProtobuf/SwiftProtobuf.framework",
"${BUILT_PRODUCTS_DIR}/UITextView+Placeholder/UITextView_Placeholder.framework",
"${BUILT_PRODUCTS_DIR}/YYImage/YYImage.framework",
"${BUILT_PRODUCTS_DIR}/YapDatabase/YapDatabase.framework",
"${BUILT_PRODUCTS_DIR}/libPhoneNumber-iOS/libPhoneNumber_iOS.framework",
@ -3446,7 +3445,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SessionServiceKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Starscream.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftProtobuf.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/UITextView_Placeholder.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/YYImage.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/YapDatabase.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libPhoneNumber_iOS.framework",

View File

@ -1,20 +1,28 @@
import UITextView_Placeholder
final class TextView : UITextView {
final class TextView : UITextView, UITextViewDelegate {
private let usesDefaultHeight: Bool
private let height: CGFloat
private let horizontalInset: CGFloat
private let verticalInset: CGFloat
private let placeholder: String
override var contentSize: CGSize { didSet { centerTextVertically() } }
private lazy var placeholderLabel: UILabel = {
let result = UILabel()
result.font = .systemFont(ofSize: Values.smallFontSize)
result.textColor = Colors.text.withAlphaComponent(Values.unimportantElementOpacity)
return result
}()
init(placeholder: String, usesDefaultHeight: Bool = true, customHeight: CGFloat? = nil, customHorizontalInset: CGFloat? = nil, customVerticalInset: CGFloat? = nil) {
self.usesDefaultHeight = usesDefaultHeight
self.height = customHeight ?? Values.textFieldHeight
self.horizontalInset = customHorizontalInset ?? (isIPhone5OrSmaller ? Values.mediumSpacing : Values.largeSpacing)
self.verticalInset = customVerticalInset ?? (isIPhone5OrSmaller ? Values.smallSpacing : Values.largeSpacing)
super.init(frame: CGRect.zero, textContainer: nil)
self.placeholder = placeholder
super.init(frame: CGRect.zero, textContainer: nil)
self.delegate = self
setUpStyle()
}
@ -29,12 +37,7 @@ final class TextView : UITextView {
private func setUpStyle() {
showsHorizontalScrollIndicator = false
showsVerticalScrollIndicator = false
let placeholder = NSMutableAttributedString(string: self.placeholder!)
self.placeholder = nil
let placeholderColor = Colors.text.withAlphaComponent(Values.unimportantElementOpacity)
placeholder.addAttribute(.foregroundColor, value: placeholderColor, range: NSRange(location: 0, length: placeholder.length))
placeholder.addAttribute(.font, value: UIFont.systemFont(ofSize: Values.smallFontSize), range: NSRange(location: 0, length: placeholder.length))
attributedPlaceholder = placeholder
placeholderLabel.text = placeholder
backgroundColor = .clear
textColor = Colors.text
font = .systemFont(ofSize: Values.smallFontSize)
@ -48,6 +51,15 @@ final class TextView : UITextView {
layer.cornerRadius = Values.textFieldCornerRadius
let horizontalInset = usesDefaultHeight ? self.horizontalInset : Values.mediumSpacing
textContainerInset = UIEdgeInsets(top: 0, leading: horizontalInset, bottom: 0, trailing: horizontalInset)
addSubview(placeholderLabel)
placeholderLabel.pin(.leading, to: .leading, of: self, withInset: horizontalInset + 3) // Slight visual adjustment
placeholderLabel.pin(.top, to: .top, of: self)
pin(.trailing, to: .trailing, of: placeholderLabel, withInset: horizontalInset)
pin(.bottom, to: .bottom, of: placeholderLabel)
}
func textViewDidChange(_ textView: UITextView) {
placeholderLabel.isHidden = !text.isEmpty
}
private func centerTextVertically() {