diff --git a/Chat/Chat/Chat.csproj b/Chat/Chat/Chat.csproj index d5ca7539..f2c42e0b 100644 --- a/Chat/Chat/Chat.csproj +++ b/Chat/Chat/Chat.csproj @@ -127,10 +127,12 @@ OutgoingCell.cs + + \ No newline at end of file diff --git a/Chat/Chat/ChatInput/ChatInputView.cs b/Chat/Chat/ChatInput/ChatInputView.cs new file mode 100644 index 00000000..08e74b3c --- /dev/null +++ b/Chat/Chat/ChatInput/ChatInputView.cs @@ -0,0 +1,49 @@ +using System; + +using UIKit; +using Foundation; + +namespace Chat +{ + public partial class ChatInputView : UIView + { + public UITextView TextView { get; private set; } + public UIButton SendButton { get; private set; } + + public ChatInputView() + { + TextView = new UITextView (); + TextView.Layer.BorderColor = UIColor.FromRGB (200, 200, 205).CGColor; + TextView.Layer.BorderWidth = (float)0.5; + TextView.Layer.CornerRadius = 5; + TextView.BackgroundColor = UIColor.FromWhiteAlpha (250, 1); + TextView.TranslatesAutoresizingMaskIntoConstraints = false; + + SendButton = new UIButton (); + SendButton.SetTitle ("Send", UIControlState.Normal); + SendButton.Font = UIFont.SystemFontOfSize (15, UIFontWeight.Bold); + SendButton.TranslatesAutoresizingMaskIntoConstraints = false; + SendButton.SetTitleColor (UIColor.FromRGB (142, 142, 147), UIControlState.Disabled); + SendButton.SetTitleColor (UIColor.FromRGB (1, 122, 255), UIControlState.Normal); + + AddSubviews (TextView, SendButton); + + var c1 = NSLayoutConstraint.FromVisualFormat ("H:|-[input]-[button]-|", + NSLayoutFormatOptions.DirectionLeadingToTrailing, + "input", TextView, + "button", SendButton + ); + var c2 = NSLayoutConstraint.FromVisualFormat ("V:|-[input]-|", + NSLayoutFormatOptions.DirectionLeadingToTrailing, + "input", TextView + ); + var c3 = NSLayoutConstraint.FromVisualFormat ("V:[button]-|", + NSLayoutFormatOptions.DirectionLeadingToTrailing, + "button", SendButton + ); + AddConstraints (c1); + AddConstraints (c2); + AddConstraints (c3); + } + } +} \ No newline at end of file diff --git a/Chat/Chat/ChatViewController.cs b/Chat/Chat/ChatViewController.cs index b78dcafd..1c96f4d8 100644 --- a/Chat/Chat/ChatViewController.cs +++ b/Chat/Chat/ChatViewController.cs @@ -21,6 +21,19 @@ namespace Chat // We need dummy input for keeping keyboard visible during showing menu DummyInput hiddenInput; + ChatInputView chatInputView; + UIButton SendButton { + get { + return chatInputView.SendButton; + } + } + + UITextView TextView { + get { + return chatInputView.TextView; + } + } + NSIndexPath LastIndexPath { get { return NSIndexPath.FromRowSection (messages.Count - 1, 0); @@ -52,15 +65,21 @@ namespace Chat }; View.AddSubview (hiddenInput); - chatSrc = new ChatSource (messages, ShowMenu); + chatInputView = new ChatInputView (); + SendButton.TouchUpInside += OnSendClicked; + TextView.Changed += OnTextChanged; TextView.Layer.BorderColor = UIColor.FromRGB (200, 200, 205).CGColor; TextView.Layer.BorderWidth = (float)0.5; TextView.Layer.CornerRadius = 5; TextView.BackgroundColor = UIColor.FromWhiteAlpha (250, 1); + + chatSrc = new ChatSource (messages, ShowMenu); TableView.Source = chatSrc; TableView.SeparatorStyle = UITableViewCellSeparatorStyle.None; + + UpdateToolbar (); } public override void ViewWillAppear (bool animated) @@ -75,6 +94,23 @@ namespace Chat UpdateButtonState (); } + void UpdateToolbar () + { + chatInputView.TranslatesAutoresizingMaskIntoConstraints = false; + Chat.AddSubview (chatInputView); + + var c1 = NSLayoutConstraint.FromVisualFormat ("H:|[chat]|", + NSLayoutFormatOptions.DirectionLeadingToTrailing, + "chat", chatInputView + ); + var c2 = NSLayoutConstraint.FromVisualFormat ("V:|[chat]|", + NSLayoutFormatOptions.DirectionLeadingToTrailing, + "chat", chatInputView + ); + Chat.AddConstraints (c1); + Chat.AddConstraints (c2); + } + void KeyboardWillShowHandler (object sender, UIKeyboardEventArgs e) { UpdateButtomLayoutConstraint (e); diff --git a/Chat/Chat/ChatViewController.designer.cs b/Chat/Chat/ChatViewController.designer.cs index 1ee1c56f..31f839c1 100644 --- a/Chat/Chat/ChatViewController.designer.cs +++ b/Chat/Chat/ChatViewController.designer.cs @@ -18,14 +18,8 @@ namespace Chat [Outlet] UIKit.UIToolbar Chat { get; set; } - [Outlet] - UIKit.UIButton SendButton { get; set; } - [Outlet] UIKit.UITableView TableView { get; set; } - - [Outlet] - UIKit.UITextView TextView { get; set; } void ReleaseDesignerOutlets () { @@ -34,25 +28,15 @@ namespace Chat BottomConstraint = null; } - if (SendButton != null) { - SendButton.Dispose (); - SendButton = null; + if (Chat != null) { + Chat.Dispose (); + Chat = null; } if (TableView != null) { TableView.Dispose (); TableView = null; } - - if (TextView != null) { - TextView.Dispose (); - TextView = null; - } - - if (Chat != null) { - Chat.Dispose (); - Chat = null; - } } } } diff --git a/Chat/Chat/MainStoryboard_iPhone.storyboard b/Chat/Chat/MainStoryboard_iPhone.storyboard index 3501a4a4..fd047682 100644 --- a/Chat/Chat/MainStoryboard_iPhone.storyboard +++ b/Chat/Chat/MainStoryboard_iPhone.storyboard @@ -90,40 +90,7 @@ - - - - - - - - - - Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. - - - - - - - - - - - - - - - - - + @@ -140,9 +107,7 @@ - -