Skip to content
Snippets Groups Projects
Commit babe5581 authored by Joscha's avatar Joscha
Browse files

Using VENTokenFiled in ReadView; adapted VENTokenField to be able to be read only

parent 53e3420a
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -55,6 +55,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (weak, nonatomic) id<VENTokenFieldDataSource> dataSource; @property (weak, nonatomic) id<VENTokenFieldDataSource> dataSource;
@property (strong, nonatomic, nonnull) NSMutableArray<NSString *> *textTokens; @property (strong, nonatomic, nonnull) NSMutableArray<NSString *> *textTokens;
@property (strong, nonatomic, nonnull) NSMutableArray<NSString *> *mailTokens; @property (strong, nonatomic, nonnull) NSMutableArray<NSString *> *mailTokens;
@property (atomic) BOOL readOnly;
- (void)reloadData; - (void)reloadData;
- (void)collapse; - (void)collapse;
......
...@@ -85,6 +85,7 @@ static const CGFloat VENTokenFieldDefaultMaxHeight = 2000.0;//150.0; ...@@ -85,6 +85,7 @@ static const CGFloat VENTokenFieldDefaultMaxHeight = 2000.0;//150.0;
- (void)setUpInit - (void)setUpInit
{ {
_readOnly = false;
_textTokens = [NSMutableArray array]; _textTokens = [NSMutableArray array];
_mailTokens = [NSMutableArray array]; _mailTokens = [NSMutableArray array];
_enter = false; _enter = false;
...@@ -318,8 +319,11 @@ static const CGFloat VENTokenFieldDefaultMaxHeight = 2000.0;//150.0; ...@@ -318,8 +319,11 @@ static const CGFloat VENTokenFieldDefaultMaxHeight = 2000.0;//150.0;
token.didTapTokenBlock = ^{ token.didTapTokenBlock = ^{
[weakSelf didTapToken:weakToken]; [weakSelf didTapToken:weakToken];
}; };
if (_tokens.count > 1) {
[token setTitleText:[NSString stringWithFormat:@"%@,", title]]; [token setTitleText:[NSString stringWithFormat:@"%@,", title]];
} else {
[token setTitleText:[NSString stringWithFormat:@"%@", title]];
}
token.colorScheme = [self colorSchemeForTokenAtIndex:i]; token.colorScheme = [self colorSchemeForTokenAtIndex:i];
[self.tokens addObject:token]; [self.tokens addObject:token];
...@@ -412,6 +416,9 @@ static const CGFloat VENTokenFieldDefaultMaxHeight = 2000.0;//150.0; ...@@ -412,6 +416,9 @@ static const CGFloat VENTokenFieldDefaultMaxHeight = 2000.0;//150.0;
- (VENBackspaceTextField *)inputTextField - (VENBackspaceTextField *)inputTextField
{ {
if (_readOnly) {
return nil;
}
if (!_inputTextField) { if (!_inputTextField) {
_inputTextField = [[VENBackspaceTextField alloc] init]; _inputTextField = [[VENBackspaceTextField alloc] init];
[_inputTextField setKeyboardType:self.inputTextFieldKeyboardType]; [_inputTextField setKeyboardType:self.inputTextFieldKeyboardType];
...@@ -477,6 +484,12 @@ static const CGFloat VENTokenFieldDefaultMaxHeight = 2000.0;//150.0; ...@@ -477,6 +484,12 @@ static const CGFloat VENTokenFieldDefaultMaxHeight = 2000.0;//150.0;
- (void)didTapToken:(VENToken *)token - (void)didTapToken:(VENToken *)token
{ {
if (_readOnly) {
token.highlighted = YES;
[self.delegate tokenField:self didTappedTokenTwice:[self.tokens indexOfObject:token]];
token.highlighted = NO;
return;
}
VENToken * tempToken = nil; VENToken * tempToken = nil;
for (VENToken *aToken in self.tokens) { for (VENToken *aToken in self.tokens) {
if (aToken == token) { if (aToken == token) {
...@@ -512,7 +525,7 @@ static const CGFloat VENTokenFieldDefaultMaxHeight = 2000.0;//150.0; ...@@ -512,7 +525,7 @@ static const CGFloat VENTokenFieldDefaultMaxHeight = 2000.0;//150.0;
BOOL visible = [highlightedTokens count] == 0; BOOL visible = [highlightedTokens count] == 0;
if (visible) { if (visible) {
[self inputTextFieldBecomeFirstResponder]; [self inputTextFieldBecomeFirstResponder];
} else { } else if (!_readOnly) {
[self.invisibleTextField becomeFirstResponder]; [self.invisibleTextField becomeFirstResponder];
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment