Skip to content

Commit

Permalink
Added a standard Apple privacy manifest (in addition to the markdown …
Browse files Browse the repository at this point in the history
…file).

Added the ability to switch the font for the placeholder text label.
  • Loading branch information
ChrisMarshallNY committed Jan 6, 2024
1 parent 083674c commit 797660f
Show file tree
Hide file tree
Showing 35 changed files with 937 additions and 64 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
*Version 1.5.3* **January 6, 2024**
- Added a standard Apple privacy manifest (in addition to the markdown file).
- Added the ability to switch the font for the placeholder text label.

*Version 1.5.2* **January 5, 2024**
- Re-added the `RVS_PlaceholderTextView` class (It was PEBCAK).
- Updated to the latest generic toolbox dependency.
Expand Down
14 changes: 14 additions & 0 deletions PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
<key>NSPrivacyAccessedAPITypes</key>
<array/>
<key>NSPrivacyTrackingDomains</key>
<array/>
<key>NSPrivacyTracking</key>
<false/>
</dict>
</plist>
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ This method will also end editing for the view controller:
##### Color Computation Instance Methods
- [`intermediateColor(otherColor:samplePoint:isHSL:)`](https://riftvalleysoftware.github.io/RVS_UIKit_Toolbox/Extensions/UIColor.html#/s:So7UIColorC17RVS_UIKit_ToolboxE17intermediateColor05otherF011samplePoint5isHSLA2B_12CoreGraphics7CGFloatVSbtF)

#### [`RVS_PlaceholderTextView`](https://riftvalleysoftware.github.io/RVS_UIKit_Toolbox/docs/Classes/RVS_PlaceholderTextView.html)
This is a subclass of the standard [`UITextView`](https://developer.apple.com/documentation/uikit/uitextview) class. that adds the ability to provide a "placeholder," in the same manner as the [`UITextField`](https://developer.apple.com/documentation/uikit/uitextfield) class.

## The Test Harness App

Because the package is a UIKit extension, [unit tests will be less effective than a test harness](https://littlegreenviper.com/various/testing-harness-vs-unit/). We provide a fairly comprehensive test harness app, that not only provides excellent code coverage, but also acts as a template for real-world implementation.
Expand Down
4 changes: 2 additions & 2 deletions RVS_UIKit_Toolbox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.5.2;
MARKETING_VERSION = 1.5.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.riftvalleysoftware.RVS-UIKit-Toolbox-TestHarness";
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
Expand Down Expand Up @@ -530,7 +530,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.5.2;
MARKETING_VERSION = 1.5.3;
PRODUCT_BUNDLE_IDENTIFIER = "com.riftvalleysoftware.RVS-UIKit-Toolbox-TestHarness";
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_MACCATALYST = YES;
Expand Down
3 changes: 3 additions & 0 deletions RVS_UIKit_Toolbox.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 39 additions & 26 deletions Sources/RVS_UIKit_Toolbox/RVS_UIKit_Toolbox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT
The Great Rift Valley Software Company: https://riftvalleysoftware.com
Version: 1.5.2
Version: 1.5.3
*/

import UIKit
Expand Down Expand Up @@ -712,6 +712,11 @@ public extension UIColor {
// MARK: - Text View Class With Placeholder -
/* ###################################################################################################################################### */
/**
This is a subclass of the standard [`UITextView`](https://developer.apple.com/documentation/uikit/uitextview) class.
It adds the ability to provide a "placeholder," in the same manner as the [`UITextField`](https://developer.apple.com/documentation/uikit/uitextfield) class.
In this class, a label is displayed, with the placeholder text, and that label is only displayed when there is no text in the view.
*/
public class RVS_PlaceholderTextView: UITextView {
/* ################################################################## */
Expand All @@ -730,17 +735,30 @@ public class RVS_PlaceholderTextView: UITextView {
/**
This is the string that is displayed in the placeholder label. Default is empty.
*/
@IBInspectable public var placeholder: String = ""
@IBInspectable public var placeholder: String = "" {
didSet {
_placeholderLabel.removeFromSuperview()
setNeedsLayout()
}
}

/* ################################################################## */
/**
If this is true, then the placeholder is displayed in the system font (sized for the view font). Default is true.
*/
@IBInspectable public var useSystemFont: Bool = true {
didSet {
_placeholderLabel.removeFromSuperview()
setNeedsLayout()
}
}

/* ################################################################## */
/**
In our deinitializer, we make sure to remove the observer.
*/
deinit {
NotificationCenter.default.removeObserver(self,
name: UITextView.textDidChangeNotification,
object: self
)
NotificationCenter.default.removeObserver(self, name: UITextView.textDidChangeNotification, object: self)
}
}

Expand Down Expand Up @@ -769,25 +787,20 @@ public extension RVS_PlaceholderTextView {
override func layoutSubviews() {
super.layoutSubviews()

// If we already have it up, then we can skip the rest.
guard !subviews.contains(_placeholderLabel),
let pointSize = font?.pointSize
else { return }

addSubview(_placeholderLabel)
_placeholderLabel.translatesAutoresizingMaskIntoConstraints = false
_placeholderLabel.topAnchor.constraint(equalTo: topAnchor, constant: pointSize / 2).isActive = true
_placeholderLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: Self._leftInsetInDisplayUnits).isActive = true
_placeholderLabel.font = font
_placeholderLabel.textColor = .tertiaryLabel
_placeholderLabel.sizeToFit()
_placeholderLabel.text = placeholder
_placeholderLabel.isHidden = !(text ?? "").isEmpty
// We detect changes, by observing for them.
NotificationCenter.default.addObserver(self,
selector: #selector(_textViewChanged(_:)),
name: UITextView.textDidChangeNotification,
object: self
)
if !subviews.contains(_placeholderLabel) {
guard let pointSize = font?.pointSize else { return }

addSubview(_placeholderLabel)
_placeholderLabel.translatesAutoresizingMaskIntoConstraints = false
_placeholderLabel.topAnchor.constraint(equalTo: topAnchor, constant: pointSize / 2).isActive = true
_placeholderLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: Self._leftInsetInDisplayUnits).isActive = true
_placeholderLabel.font = useSystemFont ? .systemFont(ofSize: pointSize) : font
_placeholderLabel.textColor = .tertiaryLabel
_placeholderLabel.sizeToFit()
_placeholderLabel.text = placeholder
_placeholderLabel.isHidden = !(text ?? "").isEmpty
// We detect changes, by observing for them.
NotificationCenter.default.addObserver(self, selector: #selector(_textViewChanged(_:)), name: UITextView.textDidChangeNotification, object: self)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ class RVS_UIKit_Toolbox_TestHarness_Tab2_ViewController: RVS_UIKit_Toolbox_TestH
*/
@IBOutlet weak var addContainedViewButton: UIButton?

/* ################################################################## */
/**
The label for the system font switch is actually a button.
*/
@IBOutlet weak var placeholderFontLabelButton: UIButton?

/* ################################################################## */
/**
This is the use system font for placeholder switch.
*/
@IBOutlet weak var placeholderFontSwitch: UISwitch?

/* ################################################################## */
/**
This is a demo of the placeholder text view.
Expand All @@ -108,6 +120,8 @@ extension RVS_UIKit_Toolbox_TestHarness_Tab2_ViewController {
*/
override func viewDidLoad() {
super.viewDidLoad()
placeholderFontSwitch?.isOn = placeholderTextView?.useSystemFont ?? false
placeholderFontLabelButton?.setTitle(placeholderFontLabelButton?.title(for: .normal)?.localizedVariant, for: .normal)
placeholderTextView?.placeholder = placeholderTextView?.placeholder.localizedVariant ?? "ERROR"
cornerSizeSliderLabel?.text = cornerSizeSliderLabel?.text?.localizedVariant
borderWidthSliderLabel?.text = borderWidthSliderLabel?.text?.localizedVariant
Expand Down Expand Up @@ -204,4 +218,19 @@ extension RVS_UIKit_Toolbox_TestHarness_Tab2_ViewController {

addContainedViewButton?.isEnabled = 3 > (containedViewContainerView?.subviews.count ?? 3)
}

/* ################################################################## */
/**
The use system font switch (ot its label) was hit.
- parameter inControl: The item that called this. It can either be a UIButton, or a UISwitch.
*/
@IBAction func fontSwitchChanged(_ inControl: UIControl) {
if let fontSwitch = inControl as? UISwitch {
placeholderTextView?.useSystemFont = fontSwitch.isOn
} else {
placeholderFontSwitch?.setOn(!(placeholderFontSwitch?.isOn ?? true), animated: true)
placeholderFontSwitch?.sendActions(for: .valueChanged)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ The Great Rift Valley Software Company: https://riftvalleysoftware.com
"SLUG-BORDER-WIDTH-SLIDER-LABEL" = "Border Width:";
"SLUG-BORDER-COLOR-SWITCH-LABEL" = "Border Color:";
"SLUG-ADD-CONTAINED-VIEW-BUTTON" = "Add Contained View";
"SLUG-PLACEHOLDER-TEXT" = "RVS_PlaceholderTextView Placeholder Text";
"SLUG-PLACEHOLDER-TEXT" = "Placeholder Text";
"SLUG-USE-SYSTEM-FONT" = "Use System Font:";

// MARK: Tab 3 (Image)
"SLUG-JPEG-IMAGE-NAME" = "Cat";
Expand Down
Loading

0 comments on commit 797660f

Please sign in to comment.