Skip to content

Commit 0f0bc06

Browse files
author
Aleksandr Sychev
committed
Merge branch 'release/0.5.1'
2 parents 3865410 + 600e4ec commit 0f0bc06

10 files changed

Lines changed: 110 additions & 160 deletions

ASYSimpleChatTextView.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = "ASYSimpleChatTextView"
11-
s.version = "0.5"
11+
s.version = "0.5.1"
1212
s.summary = "Tool to create a simple chat TextView"
1313

1414
s.description = <<-DESC
@@ -19,10 +19,10 @@ Tool to create a simple chat TextView<<-DESC
1919
s.license = 'MIT'
2020
s.author = { "Sychev Aleksandr" => "brain89g@gmail.com" }
2121
s.source = { :git => "https://github.com/Brain89/ASYSimpleChatTextView.git", :tag => s.version.to_s }
22-
s.header_mappings_dir = 'Pod'
22+
s.header_mappings_dir = 'Pod/Classes'
2323

2424
s.platform = :ios, '7.0'
2525
s.requires_arc = true
2626

27-
s.source_files = 'Pod/**/*'
27+
s.source_files = 'Pod/Classes/**/*'
2828
end

Pod/ASYInputViewObserver.m

Lines changed: 0 additions & 110 deletions
This file was deleted.

Pod/ASYSimpleChatTextViewHandler.h renamed to Pod/Classes/ASYSimpleChatTextViewHandler.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ typedef NS_ENUM(NSUInteger, ASYSimpleChatTextViewPosition) {
2525
/**
2626
Undefined (not set)
2727
*/
28-
ASYSimpleChatTextViewPositionUndefined = -1,
28+
ASYSimpleChatTextViewPositionUndefined = NSUIntegerMax,
2929
/**
3030
TextView is at the bottom of scrollView
3131
*/
@@ -102,24 +102,24 @@ typedef NS_ENUM(NSUInteger, ASYSimpleChatTextViewPosition) {
102102
/**
103103
Returns an instance of ASYSimpleChatTextViewHandler
104104
105-
@param textView The UITextView which needs to be resized
106-
@param heightConstraint The height constraint of textview (changeable)
105+
@param textView The UITextView which needs to be resized
106+
@param textViewHeightConstraint The height constraint of textview (changeable)
107107
*/
108108
- (nullable instancetype)initWithTextView:(nonnull UITextView *)textView
109-
andHeightConstraint:(nonnull NSLayoutConstraint *)heightConstraint;
109+
withHeightConstraint:(nonnull NSLayoutConstraint *)textViewHeightConstraint;
110110

111111
/**
112112
Returns an instance of ASYSimpleChatTextViewHandler
113113
114114
@param textView The UITextView which needs to be resized
115-
@param heightConstraint The height constraint of textview (changeable)
116-
@param scrollViewKeyboardConstraint The constraint to manipulate vertical position if inputView frame changes (changeable)
115+
@param textViewHeightConstraint The height constraint of textview (changeable)
117116
@param scrollView The UIScrollView that animates along with textView and heightConstraint
117+
@param scrollViewKeyboardConstraint The constraint to manipulate vertical position if inputView frame changes (changeable)
118118
*/
119119
- (nullable instancetype)initWithTextView:(nonnull UITextView *)textView
120-
heightConstraint:(nonnull NSLayoutConstraint *)heightConstraint
121-
scrollViewKeyboardConstraint:(nullable NSLayoutConstraint *)scrollViewKeyboardConstraint
122-
andObservableScrollView:(nullable __kindof UIScrollView *)scrollView NS_DESIGNATED_INITIALIZER;
120+
withHeightConstraint:(nonnull NSLayoutConstraint *)textViewHeightConstraint
121+
andObservableScrollView:(nullable __kindof UIScrollView *)scrollView
122+
withKeyboardConstraint:(nullable NSLayoutConstraint *)scrollViewKeyboardConstraint NS_DESIGNATED_INITIALIZER;
123123

124124
/**
125125
Limits resizing of UITextView between minimumNumberOfLines and maximumNumberOfLines

Pod/ASYSimpleChatTextViewHandler.m renamed to Pod/Classes/ASYSimpleChatTextViewHandler.m

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#import "ASYRootViewFinder.h"
2222

2323
static CGFloat const ASYSimpleChatTextViewDefaultAnimationDuration = 0.34;
24-
static float const ASYSimpleChatTextViewHeightConstraintPriority = 999.0;
2524
static NSUInteger const ASYSimpleChatTextViewDefaultMinimumNumberOfLines = 1u;
2625
static NSUInteger const ASYSimpleChatTextViewDefaultMaximumNumberOfLines = NSUIntegerMax;
2726

@@ -32,6 +31,8 @@ @interface ASYSimpleChatTextViewHandler () <ASYInputViewObserverDelegate>
3231
@property (nonnull, nonatomic, strong, readwrite) NSLayoutConstraint *scrollViewKeyboardConstraint;
3332
@property (nonnull, nonatomic, strong, readwrite) UIScrollView *observableScrollView;
3433

34+
@property (nonatomic, assign) CGFloat scrollViewKeyboardConstraintOriginConstant;
35+
3536
@property (nonatomic, assign, readwrite) NSUInteger minimumNumberOfLines;
3637
@property (nonatomic, assign, readwrite) NSUInteger maximumNumberOfLines;
3738

@@ -53,22 +54,18 @@ - (void)dealloc {
5354
}
5455

5556
- (nullable instancetype)initWithTextView:(nonnull UITextView *)textView
56-
heightConstraint:(nonnull NSLayoutConstraint *)heightConstraint
57-
scrollViewKeyboardConstraint:(nullable NSLayoutConstraint *)scrollViewKeyboardConstraint
58-
andObservableScrollView:(nullable __kindof UIScrollView *)scrollView {
57+
withHeightConstraint:(nonnull NSLayoutConstraint *)textViewHeightConstraint
58+
andObservableScrollView:(nullable __kindof UIScrollView *)scrollView
59+
withKeyboardConstraint:(nullable NSLayoutConstraint *)scrollViewKeyboardConstraint {
5960
self = [super init];
6061
if (self) {
6162
_chatTextView = textView;
62-
_heightConstraint = heightConstraint;
63+
_heightConstraint = textViewHeightConstraint;
6364
_scrollViewKeyboardConstraint = scrollViewKeyboardConstraint;
64-
/**
65-
@author Aleksandr Sychev
66-
67-
Fix 'UIView-Encapsulated-Layout-Height' priority conflict
68-
*/
69-
_scrollViewKeyboardConstraint.priority = ASYSimpleChatTextViewHeightConstraintPriority;
7065
_observableScrollView = scrollView;
7166

67+
_scrollViewKeyboardConstraintOriginConstant = _scrollViewKeyboardConstraint.constant;
68+
7269
_inputViewObserver = [ASYInputViewObserver new];
7370
_rootViewFinder = [ASYRootViewFinder new];
7471
_converter = [ASYAnimationCurveToAnimationOptionsConverter new];
@@ -94,11 +91,11 @@ - (nullable instancetype)initWithTextView:(nonnull UITextView *)textView
9491
}
9592

9693
- (nullable instancetype)initWithTextView:(nonnull UITextView *)textView
97-
andHeightConstraint:(nonnull NSLayoutConstraint *)heightConstraint {
94+
withHeightConstraint:(nonnull NSLayoutConstraint *)textViewHeightConstraint {
9895
return [self initWithTextView:textView
99-
heightConstraint:heightConstraint
100-
scrollViewKeyboardConstraint:nil
101-
andObservableScrollView:nil];
96+
withHeightConstraint:textViewHeightConstraint
97+
andObservableScrollView:nil
98+
withKeyboardConstraint:nil];
10299
}
103100

104101
#pragma clang diagnostic push
@@ -140,7 +137,7 @@ - (void)setText:(nullable NSString *)text animated:(BOOL)animated {
140137

141138
self.chatTextView.text = text;
142139
if (text.length == 0u) {
143-
[self updateVerticalAlignmentWithHeight:self.minimumHeight animated:animated];
140+
[self updateWithHeight:self.minimumHeight animated:animated];
144141
} else {
145142
[self resizeTextViewAnimated:animated];
146143
}
@@ -153,7 +150,7 @@ - (void)setAttributedText:(nullable NSAttributedString *)attributedText animated
153150

154151
self.chatTextView.attributedText = attributedText;
155152
if (attributedText.length == 0u) {
156-
[self updateVerticalAlignmentWithHeight:self.minimumHeight animated:animated];
153+
[self updateWithHeight:self.minimumHeight animated:animated];
157154
} else {
158155
[self resizeTextViewAnimated:animated];
159156
}
@@ -196,15 +193,23 @@ - (void)handleTextViewTextDidChange:(NSNotification *)notification {
196193
#pragma mark - InputViewObserverDelegate methods
197194

198195
- (void)observer:(nonnull ASYInputViewObserver *)observer
199-
caughtAcessoryViewFrameWillChangeWithHeightDelta:(CGFloat)inputAccessoryViewHeightDelta
200-
animationDuration:(NSTimeInterval)inputAccessoryViewAnimationDuration
201-
animationCurve:(UIViewAnimationCurve)animationCurve {
202-
CGFloat updatedConstraintConstant = inputAccessoryViewHeightDelta + CGRectGetHeight(self.chatTextView.inputAccessoryView.frame);
196+
caughtAcessoryViewFrameWillChangeWithMinY:(CGFloat)inputAccessoryViewMinY
197+
animationDuration:(NSTimeInterval)inputAccessoryViewAnimationDuration
198+
animationCurve:(UIViewAnimationCurve)animationCurve {
199+
CGFloat constraintOffset = CGRectGetMaxY([UIScreen mainScreen].bounds) - inputAccessoryViewMinY +
200+
CGRectGetHeight(self.chatTextView.inputAccessoryView.frame);
203201
CGFloat currentDataInScrollViewOffset =
204202
MAX(CGRectGetHeight(self.observableScrollView.frame) - self.observableScrollView.contentSize.height, 0.0);
205-
CGFloat updatedContentOffsetY =
206-
MAX(self.observableScrollView.contentOffset.y + updatedConstraintConstant - currentDataInScrollViewOffset, 0.0);
207-
self.scrollViewKeyboardConstraint.constant += updatedConstraintConstant;
203+
204+
/**
205+
Increase because scrollViewKeyboardConstraintOriginConstant should change only for ASYSimpleChatTextViewPositionAtScrollViewBottom
206+
*/
207+
CGFloat updatedConstraintConstant = self.scrollViewKeyboardConstraintOriginConstant + constraintOffset;
208+
CGFloat previousConstraintConstant = self.scrollViewKeyboardConstraint.constant;
209+
self.scrollViewKeyboardConstraint.constant = MAX(self.scrollViewKeyboardConstraintOriginConstant, updatedConstraintConstant);
210+
CGFloat constraintDelta = previousConstraintConstant - self.scrollViewKeyboardConstraint.constant;
211+
CGFloat updatedScrollViewContentOffsetY =
212+
MAX(self.observableScrollView.contentOffset.y - constraintDelta - currentDataInScrollViewOffset, 0.0);
208213

209214
UIView *rootView = [self.rootViewFinder findRootViewOf:self.chatTextView];
210215
UIViewAnimationOptions optionsFromCurve = [self.converter convert:animationCurve];
@@ -215,7 +220,7 @@ - (void)observer:(nonnull ASYInputViewObserver *)observer
215220
[rootView layoutIfNeeded];
216221
if (self.textViewPositionInRelationToScrollView == ASYSimpleChatTextViewPositionAtScrollViewBottom) {
217222
self.observableScrollView.contentOffset =
218-
CGPointMake(self.observableScrollView.contentOffset.x, updatedContentOffsetY);
223+
CGPointMake(self.observableScrollView.contentOffset.x, updatedScrollViewContentOffsetY);
219224
}
220225
}
221226
completion:nil];
@@ -260,19 +265,19 @@ - (NSUInteger)currentNumberOfLines {
260265

261266
- (void)resizeTextViewAnimated:(BOOL)animated {
262267
NSUInteger textViewNumberOfLines = self.currentNumberOfLines;
263-
CGFloat verticalAlignmentConstant = 0.0;
268+
CGFloat heightConstant = 0.0;
264269
if (textViewNumberOfLines <= self.minimumNumberOfLines) {
265-
verticalAlignmentConstant = self.minimumHeight;
270+
heightConstant = self.minimumHeight;
266271
} else if ((textViewNumberOfLines > self.minimumNumberOfLines) && (textViewNumberOfLines <= self.maximumNumberOfLines)) {
267272
CGFloat currentHeight = [self currentHeight];
268-
verticalAlignmentConstant = (currentHeight > self.minimumHeight)
269-
? ((currentHeight < self.maximumHeight) ? currentHeight : self.maximumHeight)
270-
: self.minimumHeight;
273+
heightConstant = (currentHeight > self.minimumHeight)
274+
? ((currentHeight < self.maximumHeight) ? currentHeight : self.maximumHeight)
275+
: self.minimumHeight;
271276
} else if (textViewNumberOfLines > self.maximumNumberOfLines) {
272-
verticalAlignmentConstant = self.maximumHeight;
277+
heightConstant = self.maximumHeight;
273278
}
274-
if (self.heightConstraint.constant != verticalAlignmentConstant) {
275-
[self updateVerticalAlignmentWithHeight:verticalAlignmentConstant animated:animated];
279+
if (self.heightConstraint.constant != heightConstant) {
280+
[self updateWithHeight:heightConstant animated:animated];
276281
}
277282
if (textViewNumberOfLines <= self.maximumNumberOfLines) {
278283
[self.chatTextView setContentOffset:CGPointZero animated:YES];
@@ -295,7 +300,7 @@ - (void)updateHeightAndResize {
295300
[self resizeTextViewAnimated:NO];
296301
}
297302

298-
- (void)updateVerticalAlignmentWithHeight:(CGFloat)height animated:(BOOL)animated {
303+
- (void)updateWithHeight:(CGFloat)height animated:(BOOL)animated {
299304
CGFloat originalHeight = CGRectGetHeight(self.chatTextView.frame);
300305
CGPoint updatedContentOffset = [self calculateUpdatedScrollViewContentOffsetWithHeight:height];
301306
self.heightConstraint.constant = height;

Pod/ASYAnimationCurveToAnimationOptionsConverter.h renamed to Pod/Classes/Helpers/ASYAnimationCurveToAnimationOptionsConverter.h

File renamed without changes.

Pod/ASYAnimationCurveToAnimationOptionsConverter.m renamed to Pod/Classes/Helpers/ASYAnimationCurveToAnimationOptionsConverter.m

File renamed without changes.

Pod/ASYInputViewObserver.h renamed to Pod/Classes/Helpers/ASYInputViewObserver.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
@required
3636

3737
/**
38-
Notifies if inputView frame will really change
38+
Notifies if inputView frame will change
3939
*/
4040
- (void)observer:(nonnull ASYInputViewObserver *)observer
41-
caughtAcessoryViewFrameWillChangeWithHeightDelta:(CGFloat)inputAccessoryViewHeightDelta
42-
animationDuration:(NSTimeInterval)inputAccessoryViewAnimationDuration
43-
animationCurve:(UIViewAnimationCurve)animationCurve;
41+
caughtAcessoryViewFrameWillChangeWithMinY:(CGFloat)inputAccessoryViewMinY
42+
animationDuration:(NSTimeInterval)inputAccessoryViewAnimationDuration
43+
animationCurve:(UIViewAnimationCurve)animationCurve;
4444

4545
@end

0 commit comments

Comments
 (0)