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

Commit 7c2a773

Browse files
MarLoeMartin Loebgermandel-macaquerolfbjarne
authored
Fix crash in Chat sample and make it work correctly (#365)
* Fix crash in Chat sample and make it work correctly * Update Chat/Chat/ChatViewController.cs --------- Co-authored-by: Martin Loebger <extmloebger@gnresound.com> Co-authored-by: Manuel de la Pena <mandel@microsoft.com> Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
1 parent 0bc8046 commit 7c2a773

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

Chat/Chat/ChatViewController.cs

100644100755
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class ChatViewController : UIViewController {
1919

2020
NSLayoutConstraint toolbarBottomConstraint;
2121
NSLayoutConstraint toolbarHeightConstraint;
22-
int notifCount = 0;
2322

2423
ChatInputView chatInputView;
2524

@@ -142,9 +141,10 @@ void SetUpToolbar ()
142141

143142
if (UIDevice.CurrentDevice.CheckSystemVersion (11, 0)) { // iPhone X layout
144143
var safeGuide = View.SafeAreaLayoutGuide;
145-
toolbar.HeightAnchor.ConstraintEqualTo (44).Active = true;
146144
toolbar.LeadingAnchor.ConstraintEqualTo (safeGuide.LeadingAnchor).Active = true;
147145
toolbar.TrailingAnchor.ConstraintEqualTo (safeGuide.TrailingAnchor).Active = true;
146+
toolbarHeightConstraint = toolbar.HeightAnchor.ConstraintEqualTo (44);
147+
toolbarHeightConstraint.Active = true;
148148
toolbarBottomConstraint = toolbar.BottomAnchor.ConstraintEqualTo (safeGuide.BottomAnchor);
149149
toolbarBottomConstraint.Active = true;
150150
} else {
@@ -228,33 +228,18 @@ void AdjustInputToolbar (nfloat change)
228228

229229
void KeyboardWillShowHandler (object sender, UIKeyboardEventArgs e)
230230
{
231-
UpdateButtomLayoutConstraint (e);
231+
if (UIDevice.CurrentDevice.CheckSystemVersion (11, 0)) { // iPhone X layout
232+
SetToolbarContstraint (-e.FrameEnd.Height);
233+
} else {
234+
SetToolbarContstraint (e.FrameEnd.Height);
235+
}
232236
}
233237

234238
void KeyboardWillHideHandler (object sender, UIKeyboardEventArgs e)
235239
{
236-
notifCount = 0;
237240
SetToolbarContstraint (0);
238241
}
239242

240-
void UpdateButtomLayoutConstraint (UIKeyboardEventArgs e)
241-
{
242-
UIViewAnimationCurve curve = e.AnimationCurve;
243-
if (UIDevice.CurrentDevice.CheckSystemVersion (11, 0)) {
244-
UIView.Animate (e.AnimationDuration, 0, ConvertToAnimationOptions (e.AnimationCurve), () => {
245-
nfloat offsetFromBottom = toolbar.Frame.GetMaxY () - e.FrameEnd.GetMinY ();
246-
offsetFromBottom = NMath.Max (0, offsetFromBottom);
247-
if (++notifCount >= 2) { SetToolbarContstraint (-offsetFromBottom); }
248-
}, null);
249-
} else {
250-
UIView.Animate (e.AnimationDuration, 0, ConvertToAnimationOptions (e.AnimationCurve), () => {
251-
nfloat offsetFromBottom = tableView.Frame.GetMaxY () - e.FrameEnd.GetMinY ();
252-
offsetFromBottom = NMath.Max (0, offsetFromBottom);
253-
SetToolbarContstraint (offsetFromBottom);
254-
}, null);
255-
}
256-
}
257-
258243
void SetToolbarContstraint (nfloat constant)
259244
{
260245
toolbarBottomConstraint.Constant = constant;

0 commit comments

Comments
 (0)