adjust toast bottom margin depending on tab bar

This commit is contained in:
Kyle Spearrin 2017-12-23 00:34:07 -05:00
parent 2823a86b4e
commit 0c0a928e87
3 changed files with 33 additions and 13 deletions

View File

@ -12,7 +12,8 @@ namespace Bit.iOS.Core.Views
private NSLayoutConstraint _rightMarginConstraint;
private NSLayoutConstraint _bottomMarginConstraint;
public Toast(string text) : base(CoreGraphics.CGRect.FromLTRB(0, 0, 320, 44))
public Toast(string text)
: base(CoreGraphics.CGRect.FromLTRB(0, 0, 320, 44))
{
TranslatesAutoresizingMaskIntoConstraints = false;
BackgroundColor = UIColor.DarkGray;
@ -53,7 +54,7 @@ namespace Bit.iOS.Core.Views
public UILabel MessageLabel { get; set; }
public nfloat LeftMargin { get; set; } = 5;
public nfloat RightMargin { get; set; } = 5;
public nfloat BottomMargin { get; set; } = 55;
public nfloat BottomMargin { get; set; } = 5;
public nfloat Height { get; set; } = 44;
public void Show()

View File

@ -35,8 +35,7 @@ namespace Bit.iOS.Controls
return;
}
var tabs = Element as TabbedPage;
if(tabs != null)
if(Element is TabbedPage tabs)
{
for(int i = 0; i < TabBar.Items.Length; i++)
{

View File

@ -31,10 +31,17 @@ namespace Bit.iOS.Services
public void Toast(string text, bool longDuration = false)
{
new Toast(text)
var t = new Toast(text)
{
Duration = TimeSpan.FromSeconds(longDuration ? 5 : 3)
}.Show();
};
if(TabBarVisible())
{
t.BottomMargin = 55;
}
t.Show();
}
public void CopyToClipboard(string text)
@ -278,13 +285,8 @@ namespace Bit.iOS.Services
_progressAlert.View.TintColor = UIColor.Black;
_progressAlert.View.Add(loadingIndicator);
var window = UIApplication.SharedApplication.KeyWindow;
var vc = window.RootViewController;
while(vc.PresentedViewController != null)
{
vc = vc.PresentedViewController;
}
vc.PresentViewController(_progressAlert, true, null);
var vc = GetPresentedViewController();
vc?.PresentViewController(_progressAlert, true, null);
}
public void HideLoading()
@ -304,5 +306,23 @@ namespace Bit.iOS.Services
{
throw new NotImplementedException();
}
private UIViewController GetPresentedViewController()
{
var window = UIApplication.SharedApplication.KeyWindow;
var vc = window.RootViewController;
while(vc.PresentedViewController != null)
{
vc = vc.PresentedViewController;
}
return vc;
}
private bool TabBarVisible()
{
var vc = GetPresentedViewController();
return vc?.TabBarController != null && !vc.TabBarController.TabBar.Hidden;
}
}
}