Enable sending messages with pills

This commit is contained in:
aringenbach
2022-05-02 13:35:35 +02:00
parent 968c2e34c5
commit 8d65cd8a40
17 changed files with 555 additions and 175 deletions

View File

@@ -77,7 +77,7 @@ static const NSTimeInterval kActionMenuComposerHeightAnimationDuration = .3;
self.isEncryptionEnabled = _isEncryptionEnabled;
[self updateUIWithTextMessage:nil animated:NO];
[self updateUIWithAttributedTextMessage:nil animated:NO];
self.textView.toolbarDelegate = self;
@@ -154,18 +154,41 @@ static const NSTimeInterval kActionMenuComposerHeightAnimationDuration = .3;
- (void)setTextMessage:(NSString *)textMessage
{
[super setTextMessage:textMessage];
self.textView.text = textMessage;
[self updateUIWithTextMessage:textMessage animated:YES];
if (!textMessage)
{
[self setAttributedTextMessage:nil];
}
}
- (void)setAttributedTextMessage:(NSAttributedString *)attributedTextMessage
{
self.textView.attributedText = attributedTextMessage;
[self updateUIWithAttributedTextMessage:attributedTextMessage animated:YES];
[self textViewDidChange:self.textView];
}
- (NSAttributedString *)attributedTextMessage
{
return self.textView.attributedText;
}
- (NSString *)textMessage
{
return self.textView.text;
}
- (UIFont *)textDefaultFont
{
if (self.textView.font)
{
return self.textView.font;
}
else
{
return ThemeService.shared.theme.fonts.body;
}
}
- (void)setIsEncryptionEnabled:(BOOL)isEncryptionEnabled
{
_isEncryptionEnabled = isEncryptionEnabled;
@@ -329,9 +352,10 @@ static const NSTimeInterval kActionMenuComposerHeightAnimationDuration = .3;
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSString *newText = [textView.text stringByReplacingCharactersInRange:range withString:text];
[self updateUIWithTextMessage:newText animated:YES];
NSMutableAttributedString *newText = [[NSMutableAttributedString alloc] initWithAttributedString:textView.attributedText];
[newText replaceCharactersInRange:range withString:text];
[self updateUIWithAttributedTextMessage:newText animated:YES];
return YES;
}
@@ -466,15 +490,15 @@ static const NSTimeInterval kActionMenuComposerHeightAnimationDuration = .3;
#pragma mark - Private
- (void)updateUIWithTextMessage:(NSString *)textMessage animated:(BOOL)animated
- (void)updateUIWithAttributedTextMessage:(NSAttributedString *)attributedTextMessage animated:(BOOL)animated
{
self.actionMenuOpened = NO;
[UIView animateWithDuration:(animated ? 0.15f : 0.0f) animations:^{
self.rightInputToolbarButton.alpha = textMessage.length ? 1.0f : 0.0f;
self.rightInputToolbarButton.enabled = textMessage.length;
self.rightInputToolbarButton.alpha = attributedTextMessage.length ? 1.0f : 0.0f;
self.rightInputToolbarButton.enabled = attributedTextMessage.length;
self.voiceMessageToolbarView.alpha = textMessage.length ? 0.0f : 1.0;
self.voiceMessageToolbarView.alpha = attributedTextMessage.length ? 0.0f : 1.0;
}];
}