Update BottomNavigationViewUtils.cs: removing redundant Dispose() calls (#5298)

* Update BottomNavigationViewUtils.cs

Remove Dispose() and using statement as we don't destroy items.

Casting objects to classes that implements IDisposable interface dosen't mean we need call Dispose() on them, and surely we don't want call it here.

* Update BottomNavigationViewUtils.cs

Fixed typo: removed closing parenthesis, added semicolon
This commit is contained in:
PawKanarek 2019-06-01 03:45:58 +02:00 коммит произвёл Samantha Houts
Родитель a0fcf30bc3
Коммит e120e7d15a
1 изменённых файлов: 33 добавлений и 39 удалений

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

@ -24,46 +24,40 @@ namespace Xamarin.Forms.Platform.Android
{
try
{
using (var menuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView)
var menuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView;
if (menuView == null)
{
if (menuView == null)
{
System.Diagnostics.Debug.WriteLine("Unable to find BottomNavigationMenuView");
return;
}
#if __ANDROID_28__
if (enableShiftMode)
bottomNavigationView.LabelVisibilityMode = ALabelVisibilityMode.LabelVisibilityAuto;
else
bottomNavigationView.LabelVisibilityMode = ALabelVisibilityMode.LabelVisibilityLabeled;
#else
var shiftMode = menuView.Class.GetDeclaredField("mShiftingMode");
shiftMode.Accessible = true;
shiftMode.SetBoolean(menuView, enableShiftMode);
shiftMode.Accessible = false;
shiftMode.Dispose();
#endif
for (int i = 0; i < menuView.ChildCount; i++)
{
var child = menuView.GetChildAt(i);
var item = child as BottomNavigationItemView;
if (item != null)
{
#if __ANDROID_28__
item.SetShifting(enableItemShiftMode);
#else
item.SetShiftingMode(enableItemShiftMode);
#endif
item.SetChecked(item.ItemData.IsChecked);
}
child.Dispose();
}
menuView.UpdateMenuView();
System.Diagnostics.Debug.WriteLine("Unable to find BottomNavigationMenuView");
return;
}
#if __ANDROID_28__
if (enableShiftMode)
bottomNavigationView.LabelVisibilityMode = ALabelVisibilityMode.LabelVisibilityAuto;
else
bottomNavigationView.LabelVisibilityMode = ALabelVisibilityMode.LabelVisibilityLabeled;
#else
var shiftMode = menuView.Class.GetDeclaredField("mShiftingMode");
shiftMode.Accessible = true;
shiftMode.SetBoolean(menuView, enableShiftMode);
shiftMode.Accessible = false;
shiftMode.Dispose();
#endif
for (int i = 0; i < menuView.ChildCount; i++)
{
var child = menuView.GetChildAt(i);
var item = child as BottomNavigationItemView;
if (item != null)
{
#if __ANDROID_28__
item.SetShifting(enableItemShiftMode);
#else
item.SetShiftingMode(enableItemShiftMode);
#endif
item.SetChecked(item.ItemData.IsChecked);
}
}
menuView.UpdateMenuView();
}
catch (Exception ex)
{
@ -71,4 +65,4 @@ namespace Xamarin.Forms.Platform.Android
}
}
}
}
}