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 _rightMarginConstraint;
private NSLayoutConstraint _bottomMarginConstraint; 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; TranslatesAutoresizingMaskIntoConstraints = false;
BackgroundColor = UIColor.DarkGray; BackgroundColor = UIColor.DarkGray;
@ -53,7 +54,7 @@ namespace Bit.iOS.Core.Views
public UILabel MessageLabel { get; set; } public UILabel MessageLabel { get; set; }
public nfloat LeftMargin { get; set; } = 5; public nfloat LeftMargin { get; set; } = 5;
public nfloat RightMargin { 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 nfloat Height { get; set; } = 44;
public void Show() public void Show()

View file

@ -35,8 +35,7 @@ namespace Bit.iOS.Controls
return; return;
} }
var tabs = Element as TabbedPage; if(Element is TabbedPage tabs)
if(tabs != null)
{ {
for(int i = 0; i < TabBar.Items.Length; i++) 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) public void Toast(string text, bool longDuration = false)
{ {
new Toast(text) var t = new Toast(text)
{ {
Duration = TimeSpan.FromSeconds(longDuration ? 5 : 3) Duration = TimeSpan.FromSeconds(longDuration ? 5 : 3)
}.Show(); };
if(TabBarVisible())
{
t.BottomMargin = 55;
}
t.Show();
} }
public void CopyToClipboard(string text) public void CopyToClipboard(string text)
@ -278,13 +285,8 @@ namespace Bit.iOS.Services
_progressAlert.View.TintColor = UIColor.Black; _progressAlert.View.TintColor = UIColor.Black;
_progressAlert.View.Add(loadingIndicator); _progressAlert.View.Add(loadingIndicator);
var window = UIApplication.SharedApplication.KeyWindow; var vc = GetPresentedViewController();
var vc = window.RootViewController; vc?.PresentViewController(_progressAlert, true, null);
while(vc.PresentedViewController != null)
{
vc = vc.PresentedViewController;
}
vc.PresentViewController(_progressAlert, true, null);
} }
public void HideLoading() public void HideLoading()
@ -304,5 +306,23 @@ namespace Bit.iOS.Services
{ {
throw new NotImplementedException(); 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;
}
} }
} }