Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 2089053

Browse files
nheagyjkmassel
authored andcommitted
Simplify LoginTextField's placeholder code
- also makes it more reliable, previously it was only colored once and if changed it reverted to iOS default (which was happening for unknown reasons)
1 parent d289ea1 commit 2089053

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

WordPressAuthenticator/NUX/WPWalkthroughTextField.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ IB_DESIGNABLE
66
@property (nonatomic) IBInspectable BOOL showTopLineSeparator;
77
@property (nonatomic) IBInspectable BOOL showSecureTextEntryToggle;
88
@property (nonatomic) IBInspectable UIImage *leftViewImage;
9-
@property (nonatomic, strong) UIButton *secureTextEntryToggle;
109

1110
/// Width for the left view. Set to 0 to use the given frame in the view.
1211
/// Default is: 30
@@ -39,6 +38,5 @@ IB_DESIGNABLE
3938
@property (nonatomic) UIEdgeInsets contentInsets;
4039

4140
- (instancetype)initWithLeftViewImage:(UIImage *)image;
42-
- (void)setupPlaceholder;
4341

4442
@end

WordPressAuthenticator/NUX/WPWalkthroughTextField.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@import Gridicons;
99

1010
@interface WPWalkthroughTextField ()
11+
@property (nonatomic, strong) UIButton *secureTextEntryToggle;
1112
@property (nonatomic, strong) UIImage *secureTextEntryImageVisible;
1213
@property (nonatomic, strong) UIImage *secureTextEntryImageHidden;
1314
@end
@@ -85,13 +86,9 @@ - (void)commonInit
8586
self.showTopLineSeparator = NO;
8687
self.showSecureTextEntryToggle = NO;
8788

88-
[self setupPlaceholder];
89-
}
90-
91-
- (void)setupPlaceholder
92-
{
9389
// Apply styles to the placeholder if one was set in IB.
9490
if (self.placeholder) {
91+
// colors here are overridden in LoginTextField
9592
NSDictionary *attributes = @{
9693
NSForegroundColorAttributeName : WPStyleGuide.greyLighten10,
9794
NSFontAttributeName : self.font,
@@ -114,6 +111,7 @@ - (void)configureSecureTextEntryToggle {
114111

115112
self.secureTextEntryToggle = [UIButton buttonWithType:UIButtonTypeCustom];
116113
self.secureTextEntryToggle.clipsToBounds = true;
114+
// colors here are overridden in LoginTextField
117115
self.secureTextEntryToggle.tintColor = [WPStyleGuide greyLighten10];
118116
[self.secureTextEntryToggle addTarget:self action:@selector(secureTextEntryToggleAction:) forControlEvents:UIControlEventTouchUpInside];
119117

WordPressAuthenticator/Signin/Login.storyboard

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@
470470
<rect key="frame" x="0.0" y="44" width="383" height="44"/>
471471
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
472472
<accessibility key="accessibilityConfiguration" identifier="passwordField"/>
473+
<nil key="textColor"/>
473474
<fontDescription key="fontDescription" type="system" pointSize="14"/>
474475
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" returnKeyType="next" enablesReturnKeyAutomatically="YES" secureTextEntry="YES" textContentType="one-time-code"/>
475476
<userDefinedRuntimeAttributes>

WordPressAuthenticator/UI/LoginTextField.swift

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ import WordPressShared
33

44
open class LoginTextField: WPWalkthroughTextField {
55

6-
override open func awakeFromNib() {
7-
super.awakeFromNib()
8-
guard let secureTextEntryToggle = secureTextEntryToggle else {
9-
return
10-
}
11-
secureTextEntryToggle.tintColor = WordPressAuthenticator.shared.style.placeholderColor
12-
}
13-
146
override open func draw(_ rect: CGRect) {
157
if showTopLineSeparator {
168
guard let context = UIGraphicsGetCurrentContext() else {
@@ -22,16 +14,19 @@ open class LoginTextField: WPWalkthroughTextField {
2214
}
2315
}
2416

25-
override open func setupPlaceholder() {
26-
guard let placeholder = placeholder,
27-
let font = font else {
28-
return
17+
override open var placeholder: String? {
18+
didSet {
19+
guard let placeholder = placeholder,
20+
let font = font else {
21+
return
22+
}
23+
24+
let attributes: [NSAttributedString.Key : Any] = [
25+
.foregroundColor: WordPressAuthenticator.shared.style.placeholderColor,
26+
.font: font
27+
]
28+
attributedPlaceholder = NSAttributedString(string: placeholder, attributes: attributes)
2929
}
30-
let attributes: [NSAttributedString.Key: Any] = [
31-
.foregroundColor: WordPressAuthenticator.shared.style.placeholderColor,
32-
.font: font
33-
]
34-
self.attributedPlaceholder = NSAttributedString(string: placeholder, attributes: attributes)
3530
}
3631

3732
override open var leftViewImage: UIImage! {

0 commit comments

Comments
 (0)