[Android] AppCompat NavigationBar should handle Transluscent Flags (#1287)

* AppCompat NavigationBar handle Transluscent Flags

* Handle padding on Navigationbar when rotated

if the app uses any TransluscentFlags padding will be added to the Toolbar. When device is rotated a new height is calculated. This leads to the Toolbar being reset by ResetToolbar(). If the old toolbar was adjusted by toppadding the new toolbar should get the same padding to not be layout out under the statusbar
This commit is contained in:
bentmar 2017-12-13 13:37:58 +01:00 коммит произвёл Rui Marinho
Родитель 8ede382d02
Коммит 8ee768ce5f
1 изменённых файлов: 27 добавлений и 1 удалений

Просмотреть файл

@ -38,6 +38,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
ActionBarDrawerToggle _drawerToggle;
FragmentManager _fragmentManager;
int _lastActionBarHeight = -1;
int _statusbarHeight;
AToolbar _toolbar;
ToolbarTracker _toolbarTracker;
DrawerMultiplexedListener _drawerListener;
@ -395,6 +396,14 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
if (actionBarHeight <= 0)
return Device.Info.CurrentOrientation.IsPortrait() ? (int)Context.ToPixels(56) : (int)Context.ToPixels(48);
if (((Activity)Context).Window.Attributes.Flags.HasFlag(WindowManagerFlags.TranslucentStatus) || ((Activity)Context).Window.Attributes.Flags.HasFlag(WindowManagerFlags.TranslucentNavigation))
{
if (_toolbar.PaddingTop == 0)
_toolbar.SetPadding(0, GetStatusBarHeight(), 0, 0);
return actionBarHeight + GetStatusBarHeight();
}
return actionBarHeight;
}
@ -410,6 +419,18 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
valueAnim.Update += (s, a) => icon.Progress = (float)a.Animation.AnimatedValue;
valueAnim.Start();
}
int GetStatusBarHeight()
{
if (_statusbarHeight > 0)
return _statusbarHeight;
int resourceId = Resources.GetIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0)
_statusbarHeight = Resources.GetDimensionPixelSize(resourceId);
return _statusbarHeight;
}
void AnimateArrowOut()
{
@ -606,6 +627,11 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
_toolbar = null;
SetupToolbar();
// if the old toolbar had padding from transluscentflags, set it to the new toolbar
if (oldToolbar.PaddingTop != 0)
_toolbar.SetPadding(0, oldToolbar.PaddingTop, 0, 0);
RegisterToolbar();
UpdateToolbar();
UpdateMenu();
@ -911,4 +937,4 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
}
}
}
}
}