Skip to content

Commit 94857d8

Browse files
author
ignacio
committed
Adds intrinsicContentSize as part of SLKTypingIndicatorProtocol
1 parent 150e8d6 commit 94857d8

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

Examples/Messenger-Shared/TypingIndicatorView.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ - (void)configureSubviews
4747

4848
#pragma mark - SLKTypingIndicatorProtocol
4949

50+
- (CGSize)intrinsicContentSize
51+
{
52+
return CGSizeMake(UIViewNoIntrinsicMetric, [self height]);
53+
}
54+
5055
- (void)dismissIndicator
5156
{
5257
if (self.isVisible) {
@@ -57,11 +62,6 @@ - (void)dismissIndicator
5762

5863
#pragma mark - UIView
5964

60-
- (CGSize)intrinsicContentSize
61-
{
62-
return CGSizeMake(UIViewNoIntrinsicMetric, [self height]);
63-
}
64-
6565
- (void)layoutSubviews
6666
{
6767
[super layoutSubviews];

Source/Classes/SLKTypingIndicatorProtocol.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
*/
2828
@property (nonatomic, getter = isVisible) BOOL visible;
2929

30+
/**
31+
Returns the natural size for the receiving view, considering only properties of the view itself.
32+
SLKTextViewController uses Auto-Layout internally, so this API is the most appropriate way to update the view dimensions dynamically.
33+
You can return UIViewNoIntrinsicMetric for any intrinsic size of a given dimension.
34+
*/
35+
- (CGSize)intrinsicContentSize;
36+
3037
@optional
3138

3239
/**

Source/Classes/SLKTypingIndicatorView.m

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ - (void)slk_commonInit
7777

7878
#pragma mark - SLKTypingIndicatorProtocol
7979

80+
- (CGSize)intrinsicContentSize
81+
{
82+
return CGSizeMake(UIViewNoIntrinsicMetric, [self height]);
83+
}
84+
8085
- (void)setVisible:(BOOL)visible
8186
{
8287
// Skip when updating the same value, specially to avoid inovking KVO unnecessary
@@ -97,21 +102,15 @@ - (void)setVisible:(BOOL)visible
97102
[self didChangeValueForKey:NSStringFromSelector(@selector(isVisible))];
98103
}
99104

100-
101-
#pragma mark - Getters
102-
103-
- (CGSize)intrinsicContentSize
105+
- (void)dismissIndicator
104106
{
105-
return CGSizeMake(UIViewNoIntrinsicMetric, [self height]);
107+
if (self.isVisible) {
108+
self.visible = NO;
109+
}
106110
}
107111

108-
- (CGFloat)height
109-
{
110-
CGFloat height = self.textFont.lineHeight;
111-
height += self.contentInset.top;
112-
height += self.contentInset.bottom;
113-
return height;
114-
}
112+
113+
#pragma mark - Getters
115114

116115
- (UILabel *)textLabel
117116
{
@@ -166,6 +165,14 @@ - (NSAttributedString *)attributedString
166165
return attributedString;
167166
}
168167

168+
- (CGFloat)height
169+
{
170+
CGFloat height = self.textFont.lineHeight;
171+
height += self.contentInset.top;
172+
height += self.contentInset.bottom;
173+
return height;
174+
}
175+
169176

170177
#pragma mark - Setters
171178

@@ -248,13 +255,6 @@ - (void)removeUsername:(NSString *)username
248255
}
249256
}
250257

251-
- (void)dismissIndicator
252-
{
253-
if (self.isVisible) {
254-
self.visible = NO;
255-
}
256-
}
257-
258258

259259
#pragma mark - Private Methods
260260

0 commit comments

Comments
 (0)