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.xcodeproj/project.pbxproj | 12 ++++---- 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 +++++----- 7 files changed, 63 insertions(+), 82 deletions(-) delete mode 100644 Juick/Views/MessageInputView.h delete mode 100644 Juick/Views/MessageInputView.m create mode 100644 Juick/Views/MessageInputView.swift diff --git a/Juick.xcodeproj/project.pbxproj b/Juick.xcodeproj/project.pbxproj index 7201ebe..1d00963 100644 --- a/Juick.xcodeproj/project.pbxproj +++ b/Juick.xcodeproj/project.pbxproj @@ -43,6 +43,7 @@ 776C41C11FD3FF6E0063B82E /* FeedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 776C41C01FD3FF6E0063B82E /* FeedViewController.m */; }; 776D4EE32A0FD1A300C8BD91 /* ContentLoadingCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 776D4EE22A0FD1A300C8BD91 /* ContentLoadingCell.swift */; }; 776D4EE52A0FD4B500C8BD91 /* ConversationCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 776D4EE42A0FD4B500C8BD91 /* ConversationCell.swift */; }; + 776D4EE72A0FD96C00C8BD91 /* MessageInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 776D4EE62A0FD96C00C8BD91 /* MessageInputView.swift */; }; 778560602343D24E00BB37A2 /* NSData+Hex.m in Sources */ = {isa = PBXBuildFile; fileRef = 7785605F2343D24E00BB37A2 /* NSData+Hex.m */; }; 778560632344CF6F00BB37A2 /* JuickNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 778560622344CF6F00BB37A2 /* JuickNavigationController.m */; }; 77975A1D182B6E9A00410C2B /* NewPostViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 77975A1C182B6E9A00410C2B /* NewPostViewController.m */; }; @@ -51,7 +52,6 @@ 77B09994189D0B9900A84F59 /* UIImage+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 77B09993189D0B9900A84F59 /* UIImage+Utils.m */; }; 77B099A6189D57F000A84F59 /* User.m in Sources */ = {isa = PBXBuildFile; fileRef = 77B099A5189D57F000A84F59 /* User.m */; }; 77B8B399207A52BD005CB20C /* MessageInputView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 77B8B398207A52BD005CB20C /* MessageInputView.xib */; }; - 77B8B39C207A5629005CB20C /* MessageInputView.m in Sources */ = {isa = PBXBuildFile; fileRef = 77B8B39B207A5629005CB20C /* MessageInputView.m */; }; 77B8DCD62093FC03000DBB04 /* BlogViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 77B8DCD52093FC03000DBB04 /* BlogViewController.m */; }; 77C3648C2241B3060017522C /* DeviceRegistration.m in Sources */ = {isa = PBXBuildFile; fileRef = 77C3648B2241B3060017522C /* DeviceRegistration.m */; }; 77C364922243FAEF0017522C /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 77C364912243FAEF0017522C /* Colors.xcassets */; }; @@ -160,6 +160,7 @@ 776C41C01FD3FF6E0063B82E /* FeedViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FeedViewController.m; sourceTree = ""; }; 776D4EE22A0FD1A300C8BD91 /* ContentLoadingCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentLoadingCell.swift; sourceTree = ""; }; 776D4EE42A0FD4B500C8BD91 /* ConversationCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationCell.swift; sourceTree = ""; }; + 776D4EE62A0FD96C00C8BD91 /* MessageInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageInputView.swift; sourceTree = ""; }; 7785605E2343D24E00BB37A2 /* NSData+Hex.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+Hex.h"; sourceTree = ""; }; 7785605F2343D24E00BB37A2 /* NSData+Hex.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+Hex.m"; sourceTree = ""; }; 778560612344CF6F00BB37A2 /* JuickNavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JuickNavigationController.h; sourceTree = ""; }; @@ -175,8 +176,6 @@ 77B099A4189D57F000A84F59 /* User.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = User.h; sourceTree = ""; }; 77B099A5189D57F000A84F59 /* User.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = User.m; sourceTree = ""; }; 77B8B398207A52BD005CB20C /* MessageInputView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MessageInputView.xib; sourceTree = ""; }; - 77B8B39A207A5629005CB20C /* MessageInputView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MessageInputView.h; sourceTree = ""; }; - 77B8B39B207A5629005CB20C /* MessageInputView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MessageInputView.m; sourceTree = ""; }; 77B8DCD42093FC03000DBB04 /* BlogViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BlogViewController.h; sourceTree = ""; }; 77B8DCD52093FC03000DBB04 /* BlogViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BlogViewController.m; sourceTree = ""; }; 77C3648B2241B3060017522C /* DeviceRegistration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceRegistration.m; sourceTree = ""; }; @@ -423,11 +422,10 @@ 77E61A5C1FD4682B00B4E304 /* QuoteView.h */, 77E61A5D1FD4682B00B4E304 /* QuoteView.m */, 77E61A5A1FD467FC00B4E304 /* QuoteView.xib */, - 77B8B39A207A5629005CB20C /* MessageInputView.h */, - 77B8B39B207A5629005CB20C /* MessageInputView.m */, + 776D4EE62A0FD96C00C8BD91 /* MessageInputView.swift */, 77B8B398207A52BD005CB20C /* MessageInputView.xib */, - 7761133721766A3000D350CD /* ContentLoadingCell.xib */, 776D4EE22A0FD1A300C8BD91 /* ContentLoadingCell.swift */, + 7761133721766A3000D350CD /* ContentLoadingCell.xib */, ); path = Views; sourceTree = ""; @@ -612,6 +610,7 @@ 773E63A3204BE036008B8F8D /* BubbleMessageCell.m in Sources */, 77975A1D182B6E9A00410C2B /* NewPostViewController.m in Sources */, 774746AD239F82A10001C7F9 /* NSDate+TimeAgo.m in Sources */, + 776D4EE72A0FD96C00C8BD91 /* MessageInputView.swift in Sources */, 77C36495224417E90017522C /* DiscoverViewController.m in Sources */, 77E35A82189A5B5A00B2D216 /* LoginViewController.m in Sources */, 776D4EE52A0FD4B500C8BD91 /* ConversationCell.swift in Sources */, @@ -620,7 +619,6 @@ 776C41BD1FD3EF180063B82E /* MessageCell.m in Sources */, 77317BB8181BBE8500D60005 /* main.m in Sources */, 7705301B25D4414D0058DCE6 /* User+UIView.m in Sources */, - 77B8B39C207A5629005CB20C /* MessageInputView.m in Sources */, 77C3648C2241B3060017522C /* DeviceRegistration.m in Sources */, 774528C21F930C06004D110B /* Attachment.m in Sources */, 778560632344CF6F00BB37A2 /* JuickNavigationController.m in Sources */, 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