From ea7006ad743375855fab434f4e6e9caf4274bfb5 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 13 May 2023 18:06:44 +0300 Subject: MessageInputView conversion --- Juick/ViewControllers/ChatViewController.h | 3 +- Juick/ViewControllers/ChatViewController.m | 2 +- Juick/Views/MessageInputView.h | 29 ------------------ Juick/Views/MessageInputView.m | 36 ----------------------- Juick/Views/MessageInputView.swift | 47 ++++++++++++++++++++++++++++++ Juick/Views/MessageInputView.xib | 16 +++++----- 6 files changed, 58 insertions(+), 75 deletions(-) delete mode 100644 Juick/Views/MessageInputView.h delete mode 100644 Juick/Views/MessageInputView.m create mode 100644 Juick/Views/MessageInputView.swift (limited to 'Juick') diff --git a/Juick/ViewControllers/ChatViewController.h b/Juick/ViewControllers/ChatViewController.h index f23ecc8..a1d4739 100644 --- a/Juick/ViewControllers/ChatViewController.h +++ b/Juick/ViewControllers/ChatViewController.h @@ -8,7 +8,8 @@ #import #import "User.h" -#import "MessageInputView.h" + +@protocol MessageInputDelegate; @interface ChatViewController : UIViewController @property(nonatomic, strong) NSMutableArray *messages; diff --git a/Juick/ViewControllers/ChatViewController.m b/Juick/ViewControllers/ChatViewController.m index 9ca024c..86d7b2f 100644 --- a/Juick/ViewControllers/ChatViewController.m +++ b/Juick/ViewControllers/ChatViewController.m @@ -9,7 +9,7 @@ #import "ChatViewController.h" #import "BubbleMessageCell.h" -#import "MessageInputView.h" +#import "Juick-Swift.h" #define kMessageInputInitialHeight 50 diff --git a/Juick/Views/MessageInputView.h b/Juick/Views/MessageInputView.h deleted file mode 100644 index 9cf3652..0000000 --- a/Juick/Views/MessageInputView.h +++ /dev/null @@ -1,29 +0,0 @@ -// -// MessageInputView.h -// Juick -// -// Created by Vitaly Takmazov on 08/04/2018. -// Copyright © 2018 com.juick. All rights reserved. -// - -#import - -@protocol MessageInputDelegate - --(void) textSent:(NSString *)text; - -@end - -@interface MessageInputView : UIVisualEffectView -@property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint; -@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textHeightConstraint; -@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topMarginConstraint; -@property (strong, nonatomic) IBOutlet UITextView *textView; - -@property (weak, nonatomic) IBOutlet UIButton *sendButton; - -- (IBAction)sendPressed:(id)sender; - -@property (nonatomic, weak) id delegate; - -@end diff --git a/Juick/Views/MessageInputView.m b/Juick/Views/MessageInputView.m deleted file mode 100644 index 054ded7..0000000 --- a/Juick/Views/MessageInputView.m +++ /dev/null @@ -1,36 +0,0 @@ -// -// MessageInputView.m -// Juick -// -// Created by Vitaly Takmazov on 08/04/2018. -// Copyright © 2018 com.juick. All rights reserved. -// - -#import "MessageInputView.h" - -@implementation MessageInputView - -- (CGSize) textSize { - CGSize size = CGSizeMake(self.textView.bounds.size.width, FLT_MAX); - return [self.textView sizeThatFits:size]; -} - -- (CGSize) intrinsicContentSize { - CGSize viewSize = [self textSize]; - viewSize.height = viewSize.height + self.bottomConstraint.constant + self.topMarginConstraint.constant; - return viewSize; -} - -- (void)textViewDidChange:(UITextView *)textView { - if ([self textSize].height != self.textHeightConstraint.constant) { - self.textHeightConstraint.constant = [self textSize].height; - [self layoutIfNeeded]; - } - [self.sendButton setEnabled:[self.textView.text length] > 0]; -} - -- (IBAction)sendPressed:(id)sender { - [self.delegate textSent:self.textView.text]; - self.textView.text = nil; -} -@end diff --git a/Juick/Views/MessageInputView.swift b/Juick/Views/MessageInputView.swift new file mode 100644 index 0000000..2a923e2 --- /dev/null +++ b/Juick/Views/MessageInputView.swift @@ -0,0 +1,47 @@ +// +// MessageInputView.swift +// Juick +// +// Created by Vitaly Takmazov on 13.05.2023. +// Copyright © 2023 com.juick. All rights reserved. +// + +import UIKit + +@objc protocol MessageInputDelegate { + @objc func textSent(_ text: String) +} + +@objc +class MessageInputView: UIVisualEffectView, UITextViewDelegate { + @IBOutlet weak var bottomConstraint: NSLayoutConstraint! + @IBOutlet weak var textHeightConstraint: NSLayoutConstraint! + @IBOutlet weak var topMarginConstraint: NSLayoutConstraint! + @IBOutlet weak var textView: UITextView! + @IBOutlet weak var sendButton: UIButton! + + @IBAction func sendPressed(_ sender: Any) { + self.delegate?.textSent(self.textView.text) + self.textView.text = nil + } + @objc var delegate: MessageInputDelegate? + + func textSize() -> CGSize { + let size = CGSizeMake(self.textView.bounds.size.width, CGFloat(Float.greatestFiniteMagnitude)) + return self.textView.sizeThatFits(size) + } + + override var intrinsicContentSize: CGSize { + var viewSize = self.textSize() + viewSize.height = viewSize.height + self.bottomConstraint.constant + self.topMarginConstraint.constant + return viewSize + } + + func textViewDidChange(_ textView: UITextView) { + if (self.textSize().height != self.textHeightConstraint.constant) { + self.textHeightConstraint.constant = self.textSize().height + layoutIfNeeded() + } + self.sendButton.isEnabled = self.textView.text.count > 0 + } +} diff --git a/Juick/Views/MessageInputView.xib b/Juick/Views/MessageInputView.xib index d7e76df..dc02c17 100644 --- a/Juick/Views/MessageInputView.xib +++ b/Juick/Views/MessageInputView.xib @@ -1,9 +1,9 @@ - + - + @@ -12,22 +12,22 @@ - + - + - + @@ -40,11 +40,11 @@ -- cgit v1.2.3