|
@@ -10,9 +10,10 @@
|
|
|
#import "FLEXArgumentInputTextView.h"
|
|
#import "FLEXArgumentInputTextView.h"
|
|
|
#import "FLEXUtility.h"
|
|
#import "FLEXUtility.h"
|
|
|
|
|
|
|
|
-@interface FLEXArgumentInputTextView () <UITextViewDelegate>
|
|
|
|
|
|
|
+@interface FLEXArgumentInputTextView ()
|
|
|
|
|
|
|
|
-@property (nonatomic, strong) UITextView *inputTextView;
|
|
|
|
|
|
|
+@property (nonatomic) UITextView *inputTextView;
|
|
|
|
|
+@property (nonatomic) UILabel *placeholderLabel;
|
|
|
@property (nonatomic, readonly) NSUInteger numberOfInputLines;
|
|
@property (nonatomic, readonly) NSUInteger numberOfInputLines;
|
|
|
|
|
|
|
|
@end
|
|
@end
|
|
@@ -23,23 +24,31 @@
|
|
|
{
|
|
{
|
|
|
self = [super initWithArgumentTypeEncoding:typeEncoding];
|
|
self = [super initWithArgumentTypeEncoding:typeEncoding];
|
|
|
if (self) {
|
|
if (self) {
|
|
|
- self.inputTextView = [[UITextView alloc] init];
|
|
|
|
|
|
|
+ self.inputTextView = [UITextView new];
|
|
|
self.inputTextView.font = [[self class] inputFont];
|
|
self.inputTextView.font = [[self class] inputFont];
|
|
|
self.inputTextView.backgroundColor = [FLEXColor primaryBackgroundColor];
|
|
self.inputTextView.backgroundColor = [FLEXColor primaryBackgroundColor];
|
|
|
self.inputTextView.layer.borderColor = [[FLEXColor borderColor] CGColor];
|
|
self.inputTextView.layer.borderColor = [[FLEXColor borderColor] CGColor];
|
|
|
- self.inputTextView.layer.borderWidth = 1.0;
|
|
|
|
|
|
|
+ self.inputTextView.layer.borderWidth = 1.f;
|
|
|
|
|
+ self.inputTextView.layer.cornerRadius = 5.f;
|
|
|
self.inputTextView.autocapitalizationType = UITextAutocapitalizationTypeNone;
|
|
self.inputTextView.autocapitalizationType = UITextAutocapitalizationTypeNone;
|
|
|
self.inputTextView.autocorrectionType = UITextAutocorrectionTypeNo;
|
|
self.inputTextView.autocorrectionType = UITextAutocorrectionTypeNo;
|
|
|
self.inputTextView.delegate = self;
|
|
self.inputTextView.delegate = self;
|
|
|
self.inputTextView.inputAccessoryView = [self createToolBar];
|
|
self.inputTextView.inputAccessoryView = [self createToolBar];
|
|
|
[self addSubview:self.inputTextView];
|
|
[self addSubview:self.inputTextView];
|
|
|
|
|
+
|
|
|
|
|
+ self.placeholderLabel = [UILabel new];
|
|
|
|
|
+ self.placeholderLabel.font = self.inputTextView.font;
|
|
|
|
|
+ self.placeholderLabel.textColor = [FLEXColor deemphasizedTextColor];
|
|
|
|
|
+ self.placeholderLabel.numberOfLines = 0;
|
|
|
|
|
+ [self.inputTextView addSubview:self.placeholderLabel];
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
return self;
|
|
return self;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#pragma mark - private
|
|
|
|
|
|
|
+#pragma mark - Private
|
|
|
|
|
|
|
|
-- (UIToolbar*)createToolBar
|
|
|
|
|
|
|
+- (UIToolbar *)createToolBar
|
|
|
{
|
|
{
|
|
|
UIToolbar *toolBar = [UIToolbar new];
|
|
UIToolbar *toolBar = [UIToolbar new];
|
|
|
[toolBar sizeToFit];
|
|
[toolBar sizeToFit];
|
|
@@ -54,12 +63,25 @@
|
|
|
[self.inputTextView resignFirstResponder];
|
|
[self.inputTextView resignFirstResponder];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+- (void)setInputPlaceholderText:(NSString *)placeholder
|
|
|
|
|
+{
|
|
|
|
|
+ self.placeholderLabel.text = placeholder;
|
|
|
|
|
+ if (placeholder.length) {
|
|
|
|
|
+ if (!self.inputTextView.text.length) {
|
|
|
|
|
+ self.placeholderLabel.hidden = NO;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ self.placeholderLabel.hidden = YES;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ self.placeholderLabel.hidden = YES;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-#pragma mark - Text View Changes
|
|
|
|
|
|
|
+ [self setNeedsLayout];
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
-- (void)textViewDidChange:(UITextView *)textView
|
|
|
|
|
|
|
+- (NSString *)inputPlaceholderText
|
|
|
{
|
|
{
|
|
|
- [self.delegate argumentInputViewValueDidChange:self];
|
|
|
|
|
|
|
+ return self.placeholderLabel.text;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -78,6 +100,16 @@
|
|
|
[super layoutSubviews];
|
|
[super layoutSubviews];
|
|
|
|
|
|
|
|
self.inputTextView.frame = CGRectMake(0, self.topInputFieldVerticalLayoutGuide, self.bounds.size.width, [self inputTextViewHeight]);
|
|
self.inputTextView.frame = CGRectMake(0, self.topInputFieldVerticalLayoutGuide, self.bounds.size.width, [self inputTextViewHeight]);
|
|
|
|
|
+ // Placeholder label is positioned by insetting origin,
|
|
|
|
|
+ // which is the line fragment padding for X and 0 for Y,
|
|
|
|
|
+ // by the content inset then the text container inset
|
|
|
|
|
+ CGFloat leading = self.inputTextView.textContainer.lineFragmentPadding;
|
|
|
|
|
+ CGSize s = self.inputTextView.frame.size;
|
|
|
|
|
+ self.placeholderLabel.frame = CGRectMake(leading, 0, s.width, s.height);
|
|
|
|
|
+ self.placeholderLabel.frame = UIEdgeInsetsInsetRect(
|
|
|
|
|
+ UIEdgeInsetsInsetRect(self.placeholderLabel.frame, self.inputTextView.contentInset),
|
|
|
|
|
+ self.inputTextView.textContainerInset
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger)numberOfInputLines
|
|
- (NSUInteger)numberOfInputLines
|
|
@@ -104,9 +136,11 @@
|
|
|
return fitSize;
|
|
return fitSize;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
#pragma mark - Trait collection changes
|
|
#pragma mark - Trait collection changes
|
|
|
|
|
|
|
|
-- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
|
|
|
|
|
|
|
+- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
|
|
|
|
|
+{
|
|
|
#if FLEX_AT_LEAST_IOS13_SDK
|
|
#if FLEX_AT_LEAST_IOS13_SDK
|
|
|
if (@available(iOS 13.0, *)) {
|
|
if (@available(iOS 13.0, *)) {
|
|
|
if (previousTraitCollection.userInterfaceStyle != self.traitCollection.userInterfaceStyle) {
|
|
if (previousTraitCollection.userInterfaceStyle != self.traitCollection.userInterfaceStyle) {
|
|
@@ -124,4 +158,13 @@
|
|
|
return [FLEXUtility defaultFontOfSize:14.0];
|
|
return [FLEXUtility defaultFontOfSize:14.0];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+#pragma mark - UITextViewDelegate
|
|
|
|
|
+
|
|
|
|
|
+- (void)textViewDidChange:(UITextView *)textView
|
|
|
|
|
+{
|
|
|
|
|
+ [self.delegate argumentInputViewValueDidChange:self];
|
|
|
|
|
+ self.placeholderLabel.hidden = !(self.inputPlaceholderText.length && !textView.text.length);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
@end
|
|
@end
|