diff --git a/src/iOS.Core/Views/Toast.cs b/src/iOS.Core/Views/Toast.cs index b10b8ff51..e076b32dc 100644 --- a/src/iOS.Core/Views/Toast.cs +++ b/src/iOS.Core/Views/Toast.cs @@ -12,7 +12,7 @@ namespace Bit.iOS.Core.Views private NSLayoutConstraint _rightMarginConstraint; private NSLayoutConstraint _bottomMarginConstraint; - public Toast(string text) + public Toast(string text) : base(CoreGraphics.CGRect.FromLTRB(0, 0, 320, 38)) { TranslatesAutoresizingMaskIntoConstraints = false; @@ -47,9 +47,11 @@ namespace Bit.iOS.Core.Views AddConstraints(hMessageConstraints); AddConstraints(vMessageConstraints); - AddGestureRecognizer(new UITapGestureRecognizer(() => Dismiss())); + AddGestureRecognizer(new UITapGestureRecognizer(() => Dismiss(false))); } + public bool Dismissed { get; set; } + public Action DismissCallback { get; set; } public TimeSpan Duration { get; set; } = TimeSpan.FromSeconds(3); public UILabel MessageLabel { get; set; } public nfloat LeftMargin { get; set; } = 5; @@ -104,17 +106,28 @@ namespace Bit.iOS.Core.Views public void Dismiss(bool animated = true) { + if(Dismissed) + { + return; + } + + Dismissed = true; _dismissTimer?.Invalidate(); _dismissTimer = null; if(!animated) { RemoveFromSuperview(); + DismissCallback?.Invoke(); return; } SetNeedsLayout(); - Animate(0.3f, 0, UIViewAnimationOptions.CurveEaseIn, () => { Alpha = 0; }, RemoveFromSuperview); + Animate(0.3f, 0, UIViewAnimationOptions.CurveEaseIn, () => { Alpha = 0; }, () => + { + RemoveFromSuperview(); + DismissCallback?.Invoke(); + }); } private void ShowWithAnimation() diff --git a/src/iOS/Services/DeviceActionService.cs b/src/iOS/Services/DeviceActionService.cs index e10747608..f94c89ae2 100644 --- a/src/iOS/Services/DeviceActionService.cs +++ b/src/iOS/Services/DeviceActionService.cs @@ -21,6 +21,7 @@ namespace Bit.iOS.Services private readonly IAppSettingsService _appSettingsService; private readonly IDeviceInfoService _deviceInfoService; private UIAlertController _progressAlert; + private Toast _toast; public DeviceActionService( IAppSettingsService appSettingsService, @@ -32,17 +33,27 @@ namespace Bit.iOS.Services public void Toast(string text, bool longDuration = false) { - var t = new Toast(text) + if(_toast != null && !_toast.Dismissed) + { + _toast.Dismiss(false); + } + + _toast = new Toast(text) { Duration = TimeSpan.FromSeconds(longDuration ? 5 : 3) }; if(TabBarVisible()) { - t.BottomMargin = 55; + _toast.BottomMargin = 55; } - t.Show(); + _toast.Show(); + _toast.DismissCallback = () => + { + _toast?.Dispose(); + _toast = null; + }; } public void CopyToClipboard(string text) @@ -277,6 +288,11 @@ namespace Bit.iOS.Services public void ShowLoading(string text) { + if(_progressAlert != null) + { + HideLoading(); + } + var loadingIndicator = new UIActivityIndicatorView(new CGRect(10, 5, 50, 50)); loadingIndicator.HidesWhenStopped = true; loadingIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray; @@ -300,7 +316,6 @@ namespace Bit.iOS.Services _progressAlert.DismissViewController(true, () => { }); _progressAlert.Dispose(); _progressAlert = null; - } public Task LaunchAppAsync(string appName, Page page)