Skip to content

Commit eb26d1d

Browse files
authored
Merge pull request #65 from egvijayanand/working
PopupDialogs sample updated with RTL support
2 parents b32d11d + 71f52e1 commit eb26d1d

File tree

4 files changed

+145
-30
lines changed

4 files changed

+145
-30
lines changed

src/PopupDialogs/App.xaml

+35-7
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818
<x:Double x:Key="ItemSpacing">10</x:Double>
1919

2020
<Style ApplyToDerivedTypes="True" TargetType="StackBase">
21-
<Setter Property="Spacing" Value="{StaticResource ItemSpacing}" />
22-
</Style>
23-
24-
<Style x:Key="DialogStyle" TargetType="Grid">
25-
<Setter Property="BackgroundColor"
26-
Value="{AppThemeBinding Dark={StaticResource BackgroundDark}, Light={StaticResource BackgroundLight}}" />
21+
<Setter Property="Spacing"
22+
Value="{StaticResource ItemSpacing}" />
2723
</Style>
2824

2925
<Style x:Key="MauiLabel" TargetType="Label">
30-
<Setter Property="TextColor" Value="{AppThemeBinding Dark={StaticResource White}, Light={StaticResource Primary}}" />
26+
<Setter Property="TextColor"
27+
Value="{AppThemeBinding Dark={StaticResource White}, Light={StaticResource Primary}}" />
3128
</Style>
3229

3330
<Style x:Key="Action" TargetType="Button">
@@ -65,6 +62,35 @@
6562
BasedOn="{StaticResource Action}">
6663
</Style>
6764

65+
<!-- Popup Dialog Styles - START -->
66+
67+
<Style x:Key="DialogStyle" TargetType="Border">
68+
<Setter Property="BackgroundColor"
69+
Value="{AppThemeBinding Dark={StaticResource BackgroundDark}, Light={StaticResource BackgroundLight}}" />
70+
<Setter Property="Stroke"
71+
Value="{StaticResource Primary}" />
72+
<Setter Property="StrokeShape"
73+
Value="RoundRectangle 10" />
74+
<Setter Property="StrokeThickness"
75+
Value="0.5" />
76+
</Style>
77+
78+
<Style x:Key="DialogTitle" TargetType="Label">
79+
<Setter Property="FontFamily"
80+
Value="{StaticResource AppFont}" />
81+
<Setter Property="FontSize"
82+
Value="16" />
83+
<Setter Property="FontAttributes"
84+
Value="Bold" />
85+
</Style>
86+
87+
<Style x:Key="DialogMessage" TargetType="Label">
88+
<Setter Property="FontFamily"
89+
Value="{StaticResource AppFont}" />
90+
<Setter Property="FontSize"
91+
Value="{StaticResource AppFontSize}" />
92+
</Style>
93+
6894
<Style x:Key="DestructiveAction"
6995
TargetType="Button"
7096
BasedOn="{StaticResource Action}">
@@ -75,6 +101,8 @@
75101
<Setter Property="TextColor"
76102
Value="{StaticResource White}" />
77103
</Style>
104+
105+
<!-- Popup Dialog Styles - END -->
78106
</ResourceDictionary>
79107
</Application.Resources>
80108
</Application>

src/PopupDialogs/MainPage.xaml

+52-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
x:Class="PopupDialogs.MainPage">
55

66
<ScrollView>
7-
<StackLayout Padding="30" Spacing="25">
7+
<VerticalStackLayout Padding="30" Spacing="15">
88

99
<Label
1010
FontSize="32"
@@ -29,48 +29,91 @@
2929
Style="{StaticResource MauiLabel}"
3030
Text="Current count: 0" />-->
3131

32+
<Label
33+
HorizontalOptions="Center"
34+
Text="Generic abstraction" />
35+
36+
<VerticalStackLayout
37+
HorizontalOptions="Center"
38+
Spacing="15">
39+
<Button
40+
AutomationId="Alert1"
41+
Clicked="OnBtnClicked"
42+
SemanticProperties.Hint="Shows an alert dialog"
43+
Style="{StaticResource PrimaryAction}"
44+
Text="Show Alert" />
45+
<Button
46+
AutomationId="Alert2"
47+
Clicked="OnBtnClicked"
48+
SemanticProperties.Hint="Shows an alert dialog with accept and cancel actions"
49+
Style="{StaticResource PrimaryAction}"
50+
Text="Show Alert 2" />
51+
<Button
52+
AutomationId="Prompt"
53+
Clicked="OnBtnClicked"
54+
SemanticProperties.Hint="Shows a prompt dialog"
55+
Style="{StaticResource PrimaryAction}"
56+
Text="Show Prompt" />
57+
<Button
58+
AutomationId="ActionSheet"
59+
Clicked="OnBtnClicked"
60+
SemanticProperties.Hint="Shows an action sheet"
61+
Style="{StaticResource PrimaryAction}"
62+
Text="Show ActionSheet" />
63+
<Button
64+
AutomationId="Static"
65+
Clicked="OnBtnClicked"
66+
SemanticProperties.Hint="Shows an action sheet"
67+
Style="{StaticResource PrimaryAction}"
68+
Text="Static Approach" />
69+
</VerticalStackLayout>
70+
71+
<Label
72+
HorizontalOptions="Center"
73+
Text="With support for .NET MAUI FlowDirection&#10;Sample shown with the value set to Right-to-Left." />
74+
3275
<VerticalStackLayout
3376
HorizontalOptions="Center"
3477
Spacing="15">
3578
<Button
3679
AutomationId="Alert1"
37-
Clicked="OnClicked"
80+
Clicked="OnMauiBtnClicked"
3881
SemanticProperties.Hint="Shows an alert dialog"
3982
Style="{StaticResource PrimaryAction}"
4083
Text="Show Alert" />
4184
<Button
4285
AutomationId="Alert2"
43-
Clicked="OnClicked"
86+
Clicked="OnMauiBtnClicked"
4487
SemanticProperties.Hint="Shows an alert dialog with accept and cancel actions"
4588
Style="{StaticResource PrimaryAction}"
4689
Text="Show Alert 2" />
4790
<Button
4891
AutomationId="Prompt"
49-
Clicked="OnClicked"
92+
Clicked="OnMauiBtnClicked"
5093
SemanticProperties.Hint="Shows a prompt dialog"
5194
Style="{StaticResource PrimaryAction}"
5295
Text="Show Prompt" />
5396
<Button
5497
AutomationId="ActionSheet"
55-
Clicked="OnClicked"
98+
Clicked="OnMauiBtnClicked"
5699
SemanticProperties.Hint="Shows an action sheet"
57100
Style="{StaticResource PrimaryAction}"
58101
Text="Show ActionSheet" />
59102
<Button
60103
AutomationId="Static"
61-
Clicked="OnClicked"
104+
Clicked="OnMauiBtnClicked"
62105
SemanticProperties.Hint="Shows an action sheet"
63106
Style="{StaticResource PrimaryAction}"
64107
Text="Static Approach" />
65108
</VerticalStackLayout>
66109

67-
<Image
110+
<!--<Image
68111
HeightRequest="310"
69112
HorizontalOptions="Center"
70113
SemanticProperties.Description="Cute dot net bot waving hi to you!"
71114
Source="dotnet_bot.png"
72-
WidthRequest="250" />
115+
WidthRequest="250" />-->
73116

74-
</StackLayout>
117+
</VerticalStackLayout>
75118
</ScrollView>
76119
</ContentPage>

src/PopupDialogs/MainPage.xaml.cs

+57-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
using VijayAnand.MauiToolkit.Core;
2+
using VijayAnand.MauiToolkit.Services;
23

34
namespace PopupDialogs
45
{
56
public partial class MainPage : ContentPage
67
{
7-
readonly IDialogService _dialogService;
8+
readonly IDialogService _genericDialog;
9+
readonly IMauiDialogService _mauiDialog;
810

9-
public MainPage(IDialogService dialogService)
11+
public MainPage(IDialogService genericDialog, IMauiDialogService mauiDialog)
1012
{
1113
InitializeComponent();
12-
_dialogService = dialogService;
14+
_genericDialog = genericDialog;
15+
_mauiDialog = mauiDialog;
1316
}
1417

15-
private async void OnClicked(object sender, EventArgs e)
18+
private async void OnBtnClicked(object sender, EventArgs e)
1619
{
1720
if (sender is Button btn)
1821
{
@@ -24,24 +27,24 @@ private async void OnClicked(object sender, EventArgs e)
2427
switch (btn.AutomationId)
2528
{
2629
case "Alert1":
27-
await _dialogService.DisplayAlertAsync("Greeting", "Hello from .NET MAUI!!!", "OK");
30+
await _genericDialog.DisplayAlertAsync("Greeting", "Hello from .NET MAUI!!!", "OK");
2831
break;
2932
case "Alert2":
30-
var response = await _dialogService.DisplayAlertAsync("Confirm", "Would you like to proceed?", "Yes", "No");
33+
var response = await _genericDialog.DisplayAlertAsync("Confirm", "Would you like to proceed?", "Yes", "No");
3134
var message = response is true ? "Glad that you opted in." : "Sorry to miss you, hope to see you soon.";
32-
await _dialogService.DisplayAlertAsync("Response", message, "OK");
35+
await _genericDialog.DisplayAlertAsync("Response", message, "OK");
3336
break;
3437
case "Prompt":
35-
var result = await _dialogService.DisplayPromptAsync("Subscribe", "Enter your email to send notifications.", maxLength: 100, inputType: InputType.Email);
36-
38+
var result = await _genericDialog.DisplayPromptAsync("Subscribe", "Enter your email to send notifications.", maxLength: 100, inputType: InputType.Email);
39+
3740
if (!string.IsNullOrWhiteSpace(result))
3841
{
39-
await _dialogService.DisplayAlertAsync("Response", result, "OK");
42+
await _genericDialog.DisplayAlertAsync("Response", result, "OK");
4043
}
4144
break;
4245
case "ActionSheet":
43-
var action = await _dialogService.DisplayActionSheetAsync("Unsaved Changes ...", "What would you like to do?", "Cancel", "Discard", "Save", "Save", "Upload", "Share", "Discard");
44-
await _dialogService.DisplayAlertAsync("Response", action, "OK");
46+
var action = await _genericDialog.DisplayActionSheetAsync("Unsaved Changes ...", "What would you like to do?", "Cancel", "Discard", "Save", "Save", "Upload", "Share");
47+
await _genericDialog.DisplayAlertAsync("Response", action, "OK");
4548
break;
4649
default:
4750
// Static approach for custom implementation
@@ -51,5 +54,47 @@ private async void OnClicked(object sender, EventArgs e)
5154
}
5255
}
5356
}
57+
58+
private async void OnMauiBtnClicked(object sender, EventArgs e)
59+
{
60+
if (sender is Button btn)
61+
{
62+
// DI approach
63+
// Switch betwen native/custom implementations in the MauiProgram.cs
64+
// The order in which dependencies are registered determines the instance injected
65+
// The latest one wins
66+
67+
var rightToLeft = FlowDirection.RightToLeft;
68+
69+
switch (btn.AutomationId)
70+
{
71+
case "Alert1":
72+
await _mauiDialog.DisplayAlertAsync("Greeting", "Hello from .NET MAUI!!!", "OK", rightToLeft);
73+
break;
74+
case "Alert2":
75+
var response = await _mauiDialog.DisplayAlertAsync("Confirm", "Would you like to proceed?", "Yes", "No", rightToLeft);
76+
var message = response is true ? "Glad that you opted in." : "Sorry to miss you, hope to see you soon.";
77+
await _mauiDialog.DisplayAlertAsync("Response", message, "OK", rightToLeft);
78+
break;
79+
case "Prompt":
80+
var result = await _mauiDialog.DisplayPromptAsync("Subscribe", "Enter your email to send notifications.", rightToLeft, maxLength: 100, keyboard: Keyboard.Email);
81+
82+
if (!string.IsNullOrWhiteSpace(result))
83+
{
84+
await _mauiDialog.DisplayAlertAsync("Response", result, "OK", rightToLeft);
85+
}
86+
break;
87+
case "ActionSheet":
88+
var action = await _mauiDialog.DisplayActionSheetAsync("Unsaved Changes ..."/*, "What would you like to do?"*/, "Cancel", "Discard", rightToLeft, "Save", "Upload", "Share");
89+
await _mauiDialog.DisplayAlertAsync("Response", action, "OK", rightToLeft);
90+
break;
91+
default:
92+
// Static approach for custom implementation
93+
// Static approach for native dialogs soon in an upcoming preview
94+
await MauiPopupDialog.Instance.DisplayAlertAsync("Static Invocation", "Welcome to .NET MAUI!!!", "OK", rightToLeft);
95+
break;
96+
}
97+
}
98+
}
5499
}
55100
}

src/PopupDialogs/PopupDialogs.csproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@
5959
<ItemGroup>
6060
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
6161
<PackageReference Include="CommunityToolkit.Maui" Version="3.1.0" />
62-
<PackageReference Include="VijayAnand.MauiToolkit" Version="2.1.0-preview.2" />
63-
<PackageReference Include="VijayAnand.MauiToolkit.Pro" Version="2.1.0-preview.2" />
62+
<PackageReference Include="VijayAnand.MauiToolkit.Pro" Version="2.1.0-preview.3" />
6463
</ItemGroup>
6564

6665
</Project>

0 commit comments

Comments
 (0)