Skip to content

Commit 6e00a9e

Browse files
committed
fix: properly handle placeholder insets
1 parent 55b080f commit 6e00a9e

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

ios/inputTextView/InputTextView.mm

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ static inline BOOL CGSizeAlmostEqual(CGSize firstSize, CGSize secondSize,
1515
}
1616

1717
@implementation InputTextView {
18-
UILabel *placeholderView;
18+
UILabel *_placeholderView;
1919
CGSize _lastCommittedSize;
2020
};
2121

2222
- (instancetype)initWithFrame:(CGRect)frame {
2323
if ((self = [super initWithFrame:frame])) {
24-
placeholderView = [[UILabel alloc] initWithFrame:self.bounds];
25-
placeholderView.isAccessibilityElement = NO;
26-
placeholderView.numberOfLines = 0;
27-
[self addSubview:placeholderView];
24+
_placeholderView = [[UILabel alloc] initWithFrame:self.bounds];
25+
_placeholderView.isAccessibilityElement = NO;
26+
_placeholderView.numberOfLines = 0;
27+
[self addSubview:_placeholderView];
2828

2929
self.textContainer.lineFragmentPadding = 0;
3030
self.scrollEnabled = YES;
@@ -185,7 +185,7 @@ - (void)updatePlaceholderVisibility {
185185
BOOL shouldShow =
186186
self.placeholderText.length > 0 && self.textStorage.length == 0;
187187

188-
placeholderView.hidden = !shouldShow;
188+
_placeholderView.hidden = !shouldShow;
189189
}
190190

191191
- (void)setText:(NSString *)text {
@@ -209,7 +209,7 @@ - (void)setPlaceholderText:(NSString *)newPlaceholderText {
209209
NSMutableDictionary *attributes =
210210
[typedInput->defaultTypingAttributes mutableCopy];
211211
attributes[NSForegroundColorAttributeName] = _placeholderColor;
212-
placeholderView.attributedText =
212+
_placeholderView.attributedText =
213213
[[NSAttributedString alloc] initWithString:placeholderText
214214
attributes:attributes];
215215
[self setNeedsLayout];
@@ -220,13 +220,20 @@ - (void)layoutSubviews {
220220

221221
CGRect textFrame =
222222
UIEdgeInsetsInsetRect(self.bounds, self.textContainerInset);
223+
223224
CGFloat placeholderHeight =
224-
[placeholderView sizeThatFits:textFrame.size].height;
225+
[_placeholderView sizeThatFits:textFrame.size].height;
226+
225227
textFrame.size.height = MIN(placeholderHeight, textFrame.size.height);
226-
placeholderView.frame = textFrame;
227-
CGSize newSize =
228-
[self.layoutManager usedRectForTextContainer:self.textContainer].size;
229-
if (CGSizeAlmostEqual(newSize, _lastCommittedSize, Epsilon)) {
228+
229+
_placeholderView.frame = textFrame;
230+
231+
CGRect usedRect =
232+
[self.layoutManager usedRectForTextContainer:self.textContainer];
233+
234+
CGSize newSize = usedRect.size;
235+
236+
if (CGSizeAlmostEqual(newSize, _lastCommittedSize, 0.5)) {
230237
return;
231238
}
232239

0 commit comments

Comments
 (0)