2015-11-20 13:12:37 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 OpenMarket Ltd
|
2017-03-08 15:14:41 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2015-11-20 13:12:37 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "TableViewCellWithLabelAndLargeTextView.h"
|
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
#import "ThemeService.h"
|
2019-01-10 17:00:45 +00:00
|
|
|
#import "Riot-Swift.h"
|
2016-07-08 13:02:09 +00:00
|
|
|
|
2015-11-20 13:12:37 +00:00
|
|
|
@implementation TableViewCellWithLabelAndLargeTextView
|
|
|
|
|
2016-07-01 13:50:37 +00:00
|
|
|
- (void)awakeFromNib
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-07-01 13:50:37 +00:00
|
|
|
[super awakeFromNib];
|
|
|
|
|
|
|
|
// Adjust text view
|
|
|
|
// Remove the container inset: this operation impacts only the vertical margin.
|
|
|
|
// Reset textContainer.lineFragmentPadding to remove horizontal margin.
|
|
|
|
_textView.textContainerInset = UIEdgeInsetsZero;
|
|
|
|
_textView.textContainer.lineFragmentPadding = 0;
|
|
|
|
}
|
|
|
|
|
2017-08-08 14:05:43 +00:00
|
|
|
- (void)customizeTableViewCellRendering
|
|
|
|
{
|
|
|
|
[super customizeTableViewCellRendering];
|
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
_label.textColor = ThemeService.shared.theme.textPrimaryColor;
|
|
|
|
_textView.textColor = ThemeService.shared.theme.textPrimaryColor;
|
2017-08-08 14:05:43 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 13:50:37 +00:00
|
|
|
- (void)layoutSubviews
|
|
|
|
{
|
|
|
|
[super layoutSubviews];
|
|
|
|
|
|
|
|
CGFloat cellWidth = self.contentView.frame.size.width;
|
|
|
|
|
|
|
|
CGRect frame = _label.frame;
|
|
|
|
CGFloat minTextViewPosX = frame.origin.x + frame.size.width + _labelTrailingMinConstraint.constant;
|
|
|
|
|
|
|
|
CGFloat maxTextViewWidth = cellWidth - minTextViewPosX - _textViewTrailingConstraint.constant;
|
|
|
|
|
2016-07-11 22:13:05 +00:00
|
|
|
if (_textView.isEditable && _textView.isFirstResponder)
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-07-01 13:50:37 +00:00
|
|
|
// Use the full available width when the field is edited
|
|
|
|
_textViewWidthConstraint.constant = maxTextViewWidth;
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
2016-07-01 13:50:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Adjust the text view width to display it on the right side of the cell
|
|
|
|
CGSize size = _textView.frame.size;
|
|
|
|
size.width = maxTextViewWidth;
|
|
|
|
|
|
|
|
size = [_textView sizeThatFits:size];
|
|
|
|
|
|
|
|
_textViewWidthConstraint.constant = size.width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
- (void)textViewDidBeginEditing:(UITextView *)textView;
|
|
|
|
{
|
|
|
|
[self setNeedsLayout];
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 13:50:37 +00:00
|
|
|
- (void)textViewDidEndEditing:(UITextView *)textView
|
2015-11-20 13:12:37 +00:00
|
|
|
{
|
2016-07-01 13:50:37 +00:00
|
|
|
[self setNeedsLayout];
|
2015-11-20 13:12:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|