mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-26 12:16:07 +01:00
re-select support for android tabbed page buttons (#1100)
* re-select support for android tabbed page buttons * applied Sane Person Technology (tm) to index check * remove extra line
This commit is contained in:
parent
fd55cf6996
commit
c6ac9376fc
@ -120,6 +120,7 @@
|
|||||||
<Compile Include="Receivers\LockAlarmReceiver.cs" />
|
<Compile Include="Receivers\LockAlarmReceiver.cs" />
|
||||||
<Compile Include="Receivers\PackageReplacedReceiver.cs" />
|
<Compile Include="Receivers\PackageReplacedReceiver.cs" />
|
||||||
<Compile Include="Renderers\CipherViewCellRenderer.cs" />
|
<Compile Include="Renderers\CipherViewCellRenderer.cs" />
|
||||||
|
<Compile Include="Renderers\CustomTabbedRenderer.cs" />
|
||||||
<Compile Include="Renderers\ExtendedSliderRenderer.cs" />
|
<Compile Include="Renderers\ExtendedSliderRenderer.cs" />
|
||||||
<Compile Include="Renderers\CustomEditorRenderer.cs" />
|
<Compile Include="Renderers\CustomEditorRenderer.cs" />
|
||||||
<Compile Include="Renderers\CustomPickerRenderer.cs" />
|
<Compile Include="Renderers\CustomPickerRenderer.cs" />
|
||||||
|
60
src/Android/Renderers/CustomTabbedRenderer.cs
Normal file
60
src/Android/Renderers/CustomTabbedRenderer.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using Android.Content;
|
||||||
|
using Android.Views;
|
||||||
|
using Bit.Droid.Renderers;
|
||||||
|
using Google.Android.Material.BottomNavigation;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Forms.Platform.Android;
|
||||||
|
using Xamarin.Forms.Platform.Android.AppCompat;
|
||||||
|
|
||||||
|
[assembly: ExportRenderer(typeof(TabbedPage), typeof(CustomTabbedRenderer))]
|
||||||
|
namespace Bit.Droid.Renderers
|
||||||
|
{
|
||||||
|
public class CustomTabbedRenderer : TabbedPageRenderer, BottomNavigationView.IOnNavigationItemReselectedListener
|
||||||
|
{
|
||||||
|
private TabbedPage _page;
|
||||||
|
|
||||||
|
public CustomTabbedRenderer(Context context) : base(context) { }
|
||||||
|
|
||||||
|
protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
|
||||||
|
{
|
||||||
|
base.OnElementChanged(e);
|
||||||
|
if (e.NewElement != null)
|
||||||
|
{
|
||||||
|
_page = e.NewElement;
|
||||||
|
GetBottomNavigationView()?.SetOnNavigationItemReselectedListener(this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_page = e.OldElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BottomNavigationView GetBottomNavigationView()
|
||||||
|
{
|
||||||
|
for (var i = 0; i < ViewGroup.ChildCount; i++)
|
||||||
|
{
|
||||||
|
var childView = ViewGroup.GetChildAt(i);
|
||||||
|
if (childView is ViewGroup viewGroup)
|
||||||
|
{
|
||||||
|
for (var j = 0; j < viewGroup.ChildCount; j++)
|
||||||
|
{
|
||||||
|
var childRelativeLayoutView = viewGroup.GetChildAt(j);
|
||||||
|
if (childRelativeLayoutView is BottomNavigationView bottomNavigationView)
|
||||||
|
{
|
||||||
|
return bottomNavigationView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async void BottomNavigationView.IOnNavigationItemReselectedListener.OnNavigationItemReselected(IMenuItem item)
|
||||||
|
{
|
||||||
|
if (_page?.CurrentPage?.Navigation != null && _page.CurrentPage.Navigation.NavigationStack.Count > 0)
|
||||||
|
{
|
||||||
|
await _page.CurrentPage.Navigation.PopToRootAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user