diff options
author | Vitaly Takmazov | 2023-05-13 18:06:44 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-05-14 01:15:35 +0300 |
commit | ea7006ad743375855fab434f4e6e9caf4274bfb5 (patch) | |
tree | 6c18f47b81e070407c57fa1b6dd9dd2363f6197d | |
parent | cc94c2555c22cd51722034ac1ff02a0c041653c4 (diff) |
MessageInputView conversion
-rw-r--r-- | Juick.xcodeproj/project.pbxproj | 12 | ||||
-rw-r--r-- | Juick/ViewControllers/ChatViewController.h | 3 | ||||
-rw-r--r-- | Juick/ViewControllers/ChatViewController.m | 2 | ||||
-rw-r--r-- | Juick/Views/MessageInputView.h | 29 | ||||
-rw-r--r-- | Juick/Views/MessageInputView.m | 36 | ||||
-rw-r--r-- | Juick/Views/MessageInputView.swift | 47 | ||||
-rw-r--r-- | Juick/Views/MessageInputView.xib | 16 |
7 files changed, 63 insertions, 82 deletions
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 = "<group>"; }; 776D4EE22A0FD1A300C8BD91 /* ContentLoadingCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentLoadingCell.swift; sourceTree = "<group>"; }; 776D4EE42A0FD4B500C8BD91 /* ConversationCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationCell.swift; sourceTree = "<group>"; }; + 776D4EE62A0FD96C00C8BD91 /* MessageInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageInputView.swift; sourceTree = "<group>"; }; 7785605E2343D24E00BB37A2 /* NSData+Hex.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+Hex.h"; sourceTree = "<group>"; }; 7785605F2343D24E00BB37A2 /* NSData+Hex.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+Hex.m"; sourceTree = "<group>"; }; 778560612344CF6F00BB37A2 /* JuickNavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JuickNavigationController.h; sourceTree = "<group>"; }; @@ -175,8 +176,6 @@ 77B099A4189D57F000A84F59 /* User.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = User.h; sourceTree = "<group>"; }; 77B099A5189D57F000A84F59 /* User.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = User.m; sourceTree = "<group>"; }; 77B8B398207A52BD005CB20C /* MessageInputView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MessageInputView.xib; sourceTree = "<group>"; }; - 77B8B39A207A5629005CB20C /* MessageInputView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MessageInputView.h; sourceTree = "<group>"; }; - 77B8B39B207A5629005CB20C /* MessageInputView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MessageInputView.m; sourceTree = "<group>"; }; 77B8DCD42093FC03000DBB04 /* BlogViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BlogViewController.h; sourceTree = "<group>"; }; 77B8DCD52093FC03000DBB04 /* BlogViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BlogViewController.m; sourceTree = "<group>"; }; 77C3648B2241B3060017522C /* DeviceRegistration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceRegistration.m; sourceTree = "<group>"; }; @@ -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 = "<group>"; @@ -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 <UIKit/UIKit.h> #import "User.h" -#import "MessageInputView.h" + +@protocol MessageInputDelegate; @interface ChatViewController : UIViewController<MessageInputDelegate, UITableViewDelegate, UITableViewDataSource> @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 <UIKit/UIKit.h> - -@protocol MessageInputDelegate <NSObject> - --(void) textSent:(NSString *)text; - -@end - -@interface MessageInputView : UIVisualEffectView<UITextViewDelegate> -@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<MessageInputDelegate> 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 @@ <?xml version="1.0" encoding="UTF-8"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> <device id="retina4_7" orientation="portrait" appearance="light"/> <dependencies> <deployment identifier="iOS"/> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/> <capability name="Named colors" minToolsVersion="9.0"/> <capability name="Safe area layout guides" minToolsVersion="9.0"/> <capability name="System colors in document resources" minToolsVersion="11.0"/> @@ -12,22 +12,22 @@ <objects> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> - <visualEffectView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="2Ze-bx-tgN" customClass="MessageInputView"> + <visualEffectView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="2Ze-bx-tgN" customClass="MessageInputView" customModule="Juick" customModuleProvider="target"> <rect key="frame" x="0.0" y="0.0" width="320" height="55"/> <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="Jo1-Go-4dO"> <rect key="frame" x="0.0" y="0.0" width="320" height="55"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> <stackView opaque="NO" contentMode="scaleToFill" alignment="bottom" spacing="6" translatesAutoresizingMaskIntoConstraints="NO" id="OCM-7q-caQ"> - <rect key="frame" x="8" y="8" width="296" height="39"/> + <rect key="frame" x="8" y="28" width="296" height="19"/> <subviews> <button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="999" horizontalCompressionResistancePriority="999" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="112-Yb-83a"> - <rect key="frame" x="0.0" y="10" width="30" height="29"/> + <rect key="frame" x="0.0" y="0.0" width="30" height="19"/> <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> <state key="normal" title="@"/> </button> <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" textAlignment="natural" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="tWq-jg-tXW"> - <rect key="frame" x="36" y="0.0" width="220" height="39"/> + <rect key="frame" x="36" y="0.0" width="214" height="19"/> <color key="backgroundColor" systemColor="systemBackgroundColor"/> <constraints> <constraint firstAttribute="height" constant="39" id="Dhd-rY-QS9"/> @@ -40,11 +40,11 @@ </connections> </textView> <button opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="999" horizontalCompressionResistancePriority="999" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iUb-5g-Btb"> - <rect key="frame" x="262" y="10" width="34" height="29"/> + <rect key="frame" x="256" y="0.0" width="40" height="19"/> <fontDescription key="fontDescription" style="UICTFontTextStyleBody"/> <state key="normal" title="Send"/> <connections> - <action selector="sendPressed:" destination="2Ze-bx-tgN" eventType="touchUpInside" id="8Nq-cB-tho"/> + <action selector="sendPressed:" destination="2Ze-bx-tgN" eventType="touchUpInside" id="Isb-Pi-Qc2"/> </connections> </button> </subviews> |