Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Fix crash in Chat sample and make it work correctly (#365)
Browse files Browse the repository at this point in the history
* Fix crash in Chat sample and make it work correctly

* Update Chat/Chat/ChatViewController.cs

---------

Co-authored-by: Martin Loebger <[email protected]>
Co-authored-by: Manuel de la Pena <[email protected]>
Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
  • Loading branch information
4 people authored Dec 22, 2023
1 parent 0bc8046 commit 7c2a773
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions Chat/Chat/ChatViewController.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class ChatViewController : UIViewController {

NSLayoutConstraint toolbarBottomConstraint;
NSLayoutConstraint toolbarHeightConstraint;
int notifCount = 0;

ChatInputView chatInputView;

Expand Down Expand Up @@ -142,9 +141,10 @@ void SetUpToolbar ()

if (UIDevice.CurrentDevice.CheckSystemVersion (11, 0)) { // iPhone X layout
var safeGuide = View.SafeAreaLayoutGuide;
toolbar.HeightAnchor.ConstraintEqualTo (44).Active = true;
toolbar.LeadingAnchor.ConstraintEqualTo (safeGuide.LeadingAnchor).Active = true;
toolbar.TrailingAnchor.ConstraintEqualTo (safeGuide.TrailingAnchor).Active = true;
toolbarHeightConstraint = toolbar.HeightAnchor.ConstraintEqualTo (44);
toolbarHeightConstraint.Active = true;
toolbarBottomConstraint = toolbar.BottomAnchor.ConstraintEqualTo (safeGuide.BottomAnchor);
toolbarBottomConstraint.Active = true;
} else {
Expand Down Expand Up @@ -228,33 +228,18 @@ void AdjustInputToolbar (nfloat change)

void KeyboardWillShowHandler (object sender, UIKeyboardEventArgs e)
{
UpdateButtomLayoutConstraint (e);
if (UIDevice.CurrentDevice.CheckSystemVersion (11, 0)) { // iPhone X layout
SetToolbarContstraint (-e.FrameEnd.Height);
} else {
SetToolbarContstraint (e.FrameEnd.Height);
}
}

void KeyboardWillHideHandler (object sender, UIKeyboardEventArgs e)
{
notifCount = 0;
SetToolbarContstraint (0);
}

void UpdateButtomLayoutConstraint (UIKeyboardEventArgs e)
{
UIViewAnimationCurve curve = e.AnimationCurve;
if (UIDevice.CurrentDevice.CheckSystemVersion (11, 0)) {
UIView.Animate (e.AnimationDuration, 0, ConvertToAnimationOptions (e.AnimationCurve), () => {
nfloat offsetFromBottom = toolbar.Frame.GetMaxY () - e.FrameEnd.GetMinY ();
offsetFromBottom = NMath.Max (0, offsetFromBottom);
if (++notifCount >= 2) { SetToolbarContstraint (-offsetFromBottom); }
}, null);
} else {
UIView.Animate (e.AnimationDuration, 0, ConvertToAnimationOptions (e.AnimationCurve), () => {
nfloat offsetFromBottom = tableView.Frame.GetMaxY () - e.FrameEnd.GetMinY ();
offsetFromBottom = NMath.Max (0, offsetFromBottom);
SetToolbarContstraint (offsetFromBottom);
}, null);
}
}

void SetToolbarContstraint (nfloat constant)
{
toolbarBottomConstraint.Constant = constant;
Expand Down

0 comments on commit 7c2a773

Please sign in to comment.