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 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 var items = ((IShellItemController)ShellItem).GetItems(); for (int i = _bottomView.MaxItemCount - 1; i < items.Count; i++) { var closure_i = i; var shellContent = 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(); var services = MauiContext.Services; var provider = services.GetRequiredService <IImageSourceServiceProvider>(); var icon = shellContent.Icon; shellContent.Icon.LoadImage( MauiContext, (result) => { image.SetImageDrawable(result?.Value); if (result?.Value != null) { var color = Colors.Black.MultiplyAlpha(0.6f).ToPlatform(); result.Value.SetTint(color); } }); innerLayout.AddView(image); using (var text = new TextView(Context)) { text.Typeface = services.GetRequiredService <IFontManager>() .GetTypeface(Font.OfSize("sans-serif-medium", 0.0)); 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); }