diff --git a/Chat/Chat/ChatInput/ChatInputView.cs b/Chat/Chat/ChatInput/ChatInputView.cs index 08e74b3c..3baf1225 100644 --- a/Chat/Chat/ChatInput/ChatInputView.cs +++ b/Chat/Chat/ChatInput/ChatInputView.cs @@ -7,24 +7,35 @@ namespace Chat { public partial class ChatInputView : UIView { + static readonly UIColor ButtonTextColorNormal = UIColor.FromRGB (1, 122, 255); + static readonly UIColor ButtonTextColorDisabled = UIColor.FromRGB (142, 142, 147); + static readonly UIFont ButtonFont = UIFont.SystemFontOfSize (17, UIFontWeight.Bold); + + static readonly UIColor InputBackgroundColor = UIColor.FromWhiteAlpha (250, 1); + static readonly UIColor InputBorderColor = UIColor.FromRGB (200, 200, 205); + const float BorderWidth = 0.5f; + const float CornerRadius = 5; + + const float ToolbarMinHeight = 44; + 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.Layer.BorderColor = InputBorderColor.CGColor; + TextView.Layer.BorderWidth = BorderWidth; + TextView.Layer.CornerRadius = CornerRadius; + TextView.BackgroundColor = InputBackgroundColor; TextView.TranslatesAutoresizingMaskIntoConstraints = false; SendButton = new UIButton (); SendButton.SetTitle ("Send", UIControlState.Normal); - SendButton.Font = UIFont.SystemFontOfSize (15, UIFontWeight.Bold); + SendButton.Font = ButtonFont; + SendButton.SetTitleColor (ButtonTextColorNormal, UIControlState.Normal); + SendButton.SetTitleColor (ButtonTextColorDisabled, UIControlState.Disabled); SendButton.TranslatesAutoresizingMaskIntoConstraints = false; - SendButton.SetTitleColor (UIColor.FromRGB (142, 142, 147), UIControlState.Disabled); - SendButton.SetTitleColor (UIColor.FromRGB (1, 122, 255), UIControlState.Normal); AddSubviews (TextView, SendButton); @@ -37,13 +48,11 @@ namespace Chat NSLayoutFormatOptions.DirectionLeadingToTrailing, "input", TextView ); - var c3 = NSLayoutConstraint.FromVisualFormat ("V:[button]-|", - NSLayoutFormatOptions.DirectionLeadingToTrailing, - "button", SendButton - ); + // We want Send button was centered when Toolbar has MinHeight (pin button in this state) + var c3 = NSLayoutConstraint.Create(SendButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1, -ToolbarMinHeight / 2); AddConstraints (c1); AddConstraints (c2); - AddConstraints (c3); + AddConstraint (c3); } } } \ No newline at end of file diff --git a/Chat/Chat/ChatViewController.cs b/Chat/Chat/ChatViewController.cs index 1c96f4d8..b7d1e5d5 100644 --- a/Chat/Chat/ChatViewController.cs +++ b/Chat/Chat/ChatViewController.cs @@ -68,12 +68,7 @@ namespace Chat 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; @@ -137,8 +132,7 @@ namespace Chat var offset = TableView.ContentOffset; offset.Y += newOverlap - oldOverlap; - if(offset.Y < 0) - offset.Y = 0; + offset.Y = NMath.Max(offset.Y, 0); TableView.ContentOffset = offset; }, null); } @@ -160,7 +154,6 @@ namespace Chat return NMath.Min (TableView.ContentSize.Height - TableView.ContentOffset.Y, TableView.Frame.Height); } - // returns changes in ContentInsetY and ContentOffsetY values void UpdateTableInsets() { UIEdgeInsets oldInset = TableView.ContentInset; @@ -206,7 +199,7 @@ namespace Chat var indexPaths = new NSIndexPath[] { LastIndexPath }; TableView.InsertRows(indexPaths, UITableViewRowAnimation.None); - TableView.ScrollToRow (indexPaths [0], UITableViewScrollPosition.Bottom, true); + TableView.ScrollToRow (LastIndexPath, UITableViewScrollPosition.Bottom, true); } void OnTextChanged (object sender, EventArgs e)