|
| 1 | +#if ANDROID |
| 2 | +using Android.Content; |
| 3 | +using Android.OS; |
| 4 | +using View = Android.Views.View; |
| 5 | +using Google.Android.Material.BottomSheet; |
| 6 | +#endif |
| 7 | +using Microsoft.Maui.Platform; |
| 8 | +namespace Maui.Controls.Sample.Issues; |
| 9 | + |
| 10 | +[Issue(IssueTracker.Github, 13356, "Java.Lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponent.", PlatformAffected.Android)] |
| 11 | +public class Issue13356 : TestContentPage |
| 12 | +{ |
| 13 | + protected override void Init() |
| 14 | + { |
| 15 | + var stack = new VerticalStackLayout |
| 16 | + { |
| 17 | + Spacing = 25, |
| 18 | + Padding = new Thickness(30, 0), |
| 19 | + VerticalOptions = LayoutOptions.Center, |
| 20 | + Children = |
| 21 | + { |
| 22 | + CreateButton("Show Button Dialog", "showButtonDialogButton", Button_Dialog_clicked), |
| 23 | + CreateButton("Show CheckBox Dialog", "showCheckBoxDialogButton", CheckBox_Dialog_clicked), |
| 24 | + } |
| 25 | + }; |
| 26 | + |
| 27 | + Content = new ScrollView { Content = stack }; |
| 28 | + } |
| 29 | + |
| 30 | + Button CreateButton(string text, string automationId, EventHandler eventHandler) => |
| 31 | + new() |
| 32 | + { |
| 33 | + Text = text, |
| 34 | + AutomationId = automationId, |
| 35 | + HorizontalOptions = LayoutOptions.Center, |
| 36 | + Command = new Command(() => eventHandler?.Invoke(this, EventArgs.Empty)) |
| 37 | + }; |
| 38 | + |
| 39 | + void Button_Dialog_clicked(object sender, EventArgs e) |
| 40 | + { |
| 41 | +#if ANDROID |
| 42 | + var droidContext = Handler.MauiContext.Context; |
| 43 | + using var myDialog = new Issue13356Dialog(droidContext) |
| 44 | + { |
| 45 | + Content = new Button { Text = "Dialog Button", Padding = new Thickness(30) } |
| 46 | + .ToPlatform(Application.Current.Handler.MauiContext) |
| 47 | + }; |
| 48 | + myDialog.ShowDialog(); |
| 49 | +#endif |
| 50 | + } |
| 51 | + |
| 52 | + void CheckBox_Dialog_clicked(object sender, EventArgs e) |
| 53 | + { |
| 54 | +#if ANDROID |
| 55 | + var droidContext = Handler.MauiContext.Context; |
| 56 | + using var myDialog = new Issue13356Dialog(droidContext) |
| 57 | + { |
| 58 | + Content = new CheckBox(){AutomationId = "DialogCheckBox" } |
| 59 | + .ToPlatform(Application.Current.Handler.MauiContext) |
| 60 | + }; |
| 61 | + myDialog.ShowDialog(); |
| 62 | +#endif |
| 63 | + } |
| 64 | + |
| 65 | +#if ANDROID |
| 66 | + public class Issue13356Dialog : BottomSheetDialog |
| 67 | + { |
| 68 | + public View Content { get; set; } |
| 69 | + |
| 70 | + public Issue13356Dialog(Context context) : base(context) { } |
| 71 | + |
| 72 | + protected override void OnCreate(Bundle savedInstanceState) |
| 73 | + { |
| 74 | + base.OnCreate(savedInstanceState); |
| 75 | + SetContentView(Content); |
| 76 | + } |
| 77 | + |
| 78 | + public void ShowDialog() |
| 79 | + { |
| 80 | + if (!IsShowing) |
| 81 | + Show(); |
| 82 | + } |
| 83 | + } |
| 84 | +#endif |
| 85 | +} |
0 commit comments