protected virtual BottomSheetDialog CreateMoreBottomSheet(Action <int, BottomSheetDialog> selectCallback) { var bottomSheetDialog = new BottomSheetDialog(Context); var bottomSheetLayout = new LinearLayout(Context); using (var bottomShellLP = new LP(LP.MatchParent, LP.WrapContent)) bottomSheetLayout.LayoutParameters = bottomShellLP; bottomSheetLayout.Orientation = Orientation.Vertical; // handle the more tab for (int i = _bottomView.MaxItemCount - 1; i < ShellItem.Items.Count; i++) { var closure_i = i; var shellContent = ShellItem.Items[i]; using (var innerLayout = new LinearLayout(Context)) { innerLayout.SetClipToOutline(true); innerLayout.SetBackground(CreateItemBackgroundDrawable()); innerLayout.SetPadding(0, (int)Context.ToPixels(6), 0, (int)Context.ToPixels(6)); innerLayout.Orientation = Orientation.Horizontal; using (var param = new LP(LP.MatchParent, LP.WrapContent)) innerLayout.LayoutParameters = param; // technically the unhook isn't needed // we dont even unhook the events that dont fire void clickCallback(object s, EventArgs e) { selectCallback(closure_i, bottomSheetDialog); if (!innerLayout.IsDisposed()) { innerLayout.Click -= clickCallback; } } innerLayout.Click += clickCallback; var image = new ImageView(Context); var lp = new LinearLayout.LayoutParams((int)Context.ToPixels(32), (int)Context.ToPixels(32)) { LeftMargin = (int)Context.ToPixels(20), RightMargin = (int)Context.ToPixels(20), TopMargin = (int)Context.ToPixels(6), BottomMargin = (int)Context.ToPixels(6), Gravity = GravityFlags.Center }; image.LayoutParameters = lp; lp.Dispose(); image.ImageTintList = ColorStateList.ValueOf(Color.Black.MultiplyAlpha(0.6).ToAndroid()); ShellContext.ApplyDrawableAsync(shellContent, ShellSection.IconProperty, icon => { if (!image.IsDisposed()) { image.SetImageDrawable(icon); } }); innerLayout.AddView(image); using (var text = new TextView(Context)) { text.Typeface = "sans-serif-medium".ToTypeFace(); text.SetTextColor(AColor.Black); text.Text = shellContent.Title; lp = new LinearLayout.LayoutParams(0, LP.WrapContent) { Gravity = GravityFlags.Center, Weight = 1 }; text.LayoutParameters = lp; lp.Dispose(); innerLayout.AddView(text); } bottomSheetLayout.AddView(innerLayout); } } bottomSheetDialog.SetContentView(bottomSheetLayout); bottomSheetLayout.Dispose(); return(bottomSheetDialog); }
protected virtual async void SetupMenu(IMenu menu, int maxBottomItems, ShellItem shellItem) { menu.Clear(); bool showMore = ShellItem.Items.Count > maxBottomItems; int end = showMore ? maxBottomItems - 1 : ShellItem.Items.Count; var currentIndex = shellItem.Items.IndexOf(ShellSection); List <IMenuItem> menuItems = new List <IMenuItem>(); List <Task> loadTasks = new List <Task>(); for (int i = 0; i < end; i++) { var item = shellItem.Items[i]; using (var title = new Java.Lang.String(item.Title)) { var menuItem = menu.Add(0, i, 0, title); menuItems.Add(menuItem); loadTasks.Add(ShellContext.ApplyDrawableAsync(item, ShellSection.IconProperty, icon => { if (icon != null) { menuItem.SetIcon(icon); } })); UpdateShellSectionEnabled(item, menuItem); if (item == ShellSection) { menuItem.SetChecked(true); } } } if (showMore) { var moreString = new Java.Lang.String("More"); var menuItem = menu.Add(0, MoreTabId, 0, moreString); moreString.Dispose(); menuItem.SetIcon(Resource.Drawable.abc_ic_menu_overflow_material); if (currentIndex >= maxBottomItems - 1) { menuItem.SetChecked(true); } } UpdateTabBarVisibility(); _bottomView.SetShiftMode(false, false); if (loadTasks.Count > 0) { await Task.WhenAll(loadTasks); } foreach (var menuItem in menuItems) { menuItem.Dispose(); } }