Repo created
This commit is contained in:
parent
4af19165ec
commit
68073add76
12458 changed files with 12350765 additions and 2 deletions
87
iphone/Maps/UI/Editor/Cells/MWMNoteCell.m
Normal file
87
iphone/Maps/UI/Editor/Cells/MWMNoteCell.m
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#import "MWMNoteCell.h"
|
||||
#import "MWMTextView.h"
|
||||
|
||||
static CGFloat const kTopTextViewOffset = 12.;
|
||||
static NSString *const kTextViewContentSizeKeyPath = @"contentSize";
|
||||
static CGFloat const kMinimalTextViewHeight = 44.;
|
||||
static void *kContext = &kContext;
|
||||
|
||||
@interface MWMNoteCell () <UITextViewDelegate>
|
||||
|
||||
@property(nonatomic) IBOutlet MWMTextView *textView;
|
||||
@property(nonatomic) IBOutlet NSLayoutConstraint *textViewHeight;
|
||||
@property(weak, nonatomic) id<MWMNoteCellDelegate> delegate;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MWMNoteCell
|
||||
|
||||
- (void)configWithDelegate:(id<MWMNoteCellDelegate>)delegate
|
||||
noteText:(NSString *)text
|
||||
placeholder:(NSString *)placeholder {
|
||||
self.delegate = delegate;
|
||||
self.textView.text = text;
|
||||
self.textView.keyboardAppearance = [UIColor isNightMode] ? UIKeyboardAppearanceDark : UIKeyboardAppearanceDefault;
|
||||
self.textView.placeholder = placeholder;
|
||||
}
|
||||
|
||||
- (void)updateTextViewForHeight:(CGFloat)height {
|
||||
id<MWMNoteCellDelegate> delegate = self.delegate;
|
||||
if (height > kMinimalTextViewHeight) {
|
||||
[delegate cell:self didChangeSizeAndText:self.textView.text];
|
||||
}
|
||||
|
||||
[self setNeedsLayout];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath
|
||||
ofObject:(id)object
|
||||
change:(NSDictionary *)change
|
||||
context:(void *)context {
|
||||
if (context == kContext) {
|
||||
NSValue *s = change[NSKeyValueChangeNewKey];
|
||||
CGFloat height = s.CGSizeValue.height;
|
||||
[self updateTextViewForHeight:height];
|
||||
return;
|
||||
}
|
||||
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
}
|
||||
|
||||
- (CGFloat)cellHeight {
|
||||
return self.textViewHeight.constant + 2 * kTopTextViewOffset;
|
||||
}
|
||||
|
||||
- (CGFloat)textViewContentHeight {
|
||||
return self.textView.contentSize.height;
|
||||
}
|
||||
|
||||
+ (CGFloat)minimalHeight {
|
||||
return kMinimalTextViewHeight;
|
||||
}
|
||||
|
||||
- (void)textViewDidEndEditing:(UITextView *)textView {
|
||||
[self.delegate cell:self didFinishEditingWithText:textView.text];
|
||||
[self unregisterObserver];
|
||||
}
|
||||
|
||||
- (void)textViewDidBeginEditing:(UITextView *)textView {
|
||||
[self registerObserver];
|
||||
}
|
||||
|
||||
- (void)textViewDidChange:(UITextView *)textView {
|
||||
[textView sizeToFit];
|
||||
}
|
||||
|
||||
- (void)unregisterObserver {
|
||||
[self.textView removeObserver:self forKeyPath:kTextViewContentSizeKeyPath context:kContext];
|
||||
}
|
||||
|
||||
- (void)registerObserver {
|
||||
[self.textView addObserver:self
|
||||
forKeyPath:kTextViewContentSizeKeyPath
|
||||
options:NSKeyValueObservingOptionNew
|
||||
context:kContext];
|
||||
}
|
||||
|
||||
@end
|
||||
Loading…
Add table
Add a link
Reference in a new issue