Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Alerts (Alert, Prompt and ActionSheet) #1328

Merged
merged 23 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Compatibility/Core/src/WinUI/FormsFlyout.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ public FormsFlyout(ActionSheetArguments sheetOptions)
TitleBlock.Text = options.Title ?? string.Empty;
OptionsList.ItemsSource = options.Buttons.ToList();

if (options.FlowDirection == Microsoft.Maui.Controls.FlowDirection.RightToLeft)
if (options.FlowDirection == Maui.FlowDirection.RightToLeft)
{
TitleBlock.FlowDirection = Microsoft.UI.Xaml.FlowDirection.RightToLeft;
OptionsList.FlowDirection = Microsoft.UI.Xaml.FlowDirection.RightToLeft;
TitleBlock.FlowDirection = UI.Xaml.FlowDirection.RightToLeft;
OptionsList.FlowDirection = UI.Xaml.FlowDirection.RightToLeft;
}
else if (options.FlowDirection == Microsoft.Maui.Controls.FlowDirection.LeftToRight)
else if (options.FlowDirection == Maui.FlowDirection.LeftToRight)
{
TitleBlock.FlowDirection = Microsoft.UI.Xaml.FlowDirection.LeftToRight;
OptionsList.FlowDirection = Microsoft.UI.Xaml.FlowDirection.LeftToRight;
TitleBlock.FlowDirection = UI.Xaml.FlowDirection.LeftToRight;
OptionsList.FlowDirection = UI.Xaml.FlowDirection.LeftToRight;
}

if (options.FlowDirection == Microsoft.Maui.Controls.FlowDirection.RightToLeft)
if (options.FlowDirection == Maui.FlowDirection.RightToLeft)
{
if (options.Cancel != null)
{
Expand Down
57 changes: 56 additions & 1 deletion src/Controls/samples/Controls.Sample/Pages/MainPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void SetupMauiLayout()
verticalStack.Add(CreateTransformations());
verticalStack.Add(CreateAnimations());
verticalStack.Add(CreateShapes());
verticalStack.Add(CreateAlerts());

verticalStack.Add(new Label { Text = " ", Padding = new Thickness(10) });
var label = new Label { Text = "End-aligned text", BackgroundColor = Colors.Fuchsia, HorizontalTextAlignment = TextAlignment.End };
Expand Down Expand Up @@ -275,6 +276,7 @@ void SetupMauiLayout()
verticalStack.Add(picker);

verticalStack.Add(new Slider());
verticalStack.Add(new Slider { MinimumTrackColor = Colors.Orange, MaximumTrackColor = Colors.Purple, ThumbColor = Colors.GreenYellow });
verticalStack.Add(new Slider { ThumbImageSource = "dotnet_bot.png" });

verticalStack.Add(new Stepper());
Expand Down Expand Up @@ -601,6 +603,59 @@ IView CreateShapes()
return verticalStack;
}

IView CreateAlerts()
{
var simpleAlertButton = new Button { Text = "Simple Alert" };

simpleAlertButton.Clicked += async (sender, args) =>
{
await DisplayAlert("Alert", "You have been alerted", "OK");
};

var yesNoAlertButton = new Button { Text = "Yes/No Alert" };

yesNoAlertButton.Clicked += async (sender, args) =>
{
bool answer = await DisplayAlert("Question?", "Would you like to play a game", "Yes", "No");
Debug.WriteLine("Answer: " + answer);
};

var simpleActionSheetButton = new Button { Text = "Simple ActionSheet" };

simpleActionSheetButton.Clicked += async (sender, args) =>
{
string action = await DisplayActionSheet("ActionSheet: Send to?", "Cancel", null, "Email", "Twitter", "Facebook");
Debug.WriteLine("Action: " + action);
};

var cancelDeleteActionSheetButton = new Button { Text = "Cancel/Delete ActionSheet" };

cancelDeleteActionSheetButton.Clicked += async (sender, args) =>
{
string action = await DisplayActionSheet("ActionSheet: SavePhoto?", "Cancel", "Delete", "Photo Roll", "Email");
Debug.WriteLine("Action: " + action);
};

var simplePromptButton = new Button { Text = "Simple Prompt" };

simplePromptButton.Clicked += async (sender, args) =>
{
string action = await DisplayPromptAsync("Question 1", "What's your name?");
Debug.WriteLine("Action: " + action);
};

var verticalStack = new VerticalStackLayout
{
simpleAlertButton,
yesNoAlertButton,
simpleActionSheetButton,
cancelDeleteActionSheetButton,
simplePromptButton
};

return verticalStack;
}

void AddTextResizeDemo(Microsoft.Maui.ILayout layout)
{
var resizeTestButton = new Button { Text = "Resize Test" };
Expand Down Expand Up @@ -687,4 +742,4 @@ public void Draw(ICanvas canvas, RectangleF dirtyRect)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

namespace Microsoft.Maui.Controls
{
[TypeConverter(typeof(FlowDirectionConverter))]
public enum FlowDirection
{
MatchParent = 0,
LeftToRight = 1,
RightToLeft = 2,
}

[Xaml.TypeConversion(typeof(FlowDirection))]
public class FlowDirectionConverter : TypeConverter
{
Expand Down
28 changes: 14 additions & 14 deletions src/Controls/src/Core/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace Microsoft.Maui.Controls
{
public partial class Page : VisualElement, ILayout, IPageController, IElementConfiguration<Page>, IPaddingElement
{
public const string BusySetSignalName = "Microsoft.Maui.Controls.BusySet";
public const string BusySetSignalName = AlertConstants.BusySetSignalName;

public const string AlertSignalName = "Microsoft.Maui.Controls.SendAlert";
public const string AlertSignalName = AlertConstants.AlertSignalName;

public const string PromptSignalName = "Microsoft.Maui.Controls.SendPrompt";
public const string PromptSignalName = AlertConstants.PromptSignalName;

public const string ActionSheetSignalName = "Microsoft.Maui.Controls.ShowActionSheet";
public const string ActionSheetSignalName = AlertConstants.ActionSheetSignalName;

internal static readonly BindableProperty IgnoresContainerAreaProperty = BindableProperty.Create("IgnoresContainerArea", typeof(bool), typeof(Page), false);

Expand Down Expand Up @@ -165,9 +165,9 @@ public Task<string> DisplayActionSheet(string title, string cancel, string destr
args.FlowDirection = flowDirection;

if (IsPlatformEnabled)
MessagingCenter.Send(this, ActionSheetSignalName, args);
MessagingCenter.Send((IPage)this, ActionSheetSignalName, args);
else
_pendingActions.Add(() => MessagingCenter.Send(this, ActionSheetSignalName, args));
_pendingActions.Add(() => MessagingCenter.Send((IPage)this, ActionSheetSignalName, args));

return args.Result.Task;
}
Expand Down Expand Up @@ -196,9 +196,9 @@ public Task<bool> DisplayAlert(string title, string message, string accept, stri
args.FlowDirection = flowDirection;

if (IsPlatformEnabled)
MessagingCenter.Send(this, AlertSignalName, args);
MessagingCenter.Send((IPage)this, AlertSignalName, args);
else
_pendingActions.Add(() => MessagingCenter.Send(this, AlertSignalName, args));
_pendingActions.Add(() => MessagingCenter.Send((IPage)this, AlertSignalName, args));

return args.Result.Task;
}
Expand All @@ -208,9 +208,9 @@ public Task<bool> DisplayAlert(string title, string message, string accept, stri
var args = new PromptArguments(title, message, accept, cancel, placeholder, maxLength, keyboard, initialValue);

if (IsPlatformEnabled)
MessagingCenter.Send(this, PromptSignalName, args);
MessagingCenter.Send((IPage)this, PromptSignalName, args);
else
_pendingActions.Add(() => MessagingCenter.Send(this, PromptSignalName, args));
_pendingActions.Add(() => MessagingCenter.Send((IPage)this, PromptSignalName, args));

return args.Result.Task;
}
Expand Down Expand Up @@ -413,9 +413,9 @@ public void SendAppearing()
if (IsBusy)
{
if (IsPlatformEnabled)
MessagingCenter.Send(this, BusySetSignalName, true);
MessagingCenter.Send((IPage)this, BusySetSignalName, true);
else
_pendingActions.Add(() => MessagingCenter.Send(this, BusySetSignalName, true));
_pendingActions.Add(() => MessagingCenter.Send((IPage)this, BusySetSignalName, true));
}

OnAppearing();
Expand All @@ -436,7 +436,7 @@ public void SendDisappearing()
_hasAppeared = false;

if (IsBusy)
MessagingCenter.Send(this, BusySetSignalName, false);
MessagingCenter.Send((IPage)this, BusySetSignalName, false);

var pageContainer = this as IPageContainer<Page>;
pageContainer?.CurrentPage?.SendDisappearing();
Expand Down Expand Up @@ -493,7 +493,7 @@ void OnPageBusyChanged()
if (!_hasAppeared)
return;

MessagingCenter.Send(this, BusySetSignalName, IsBusy);
MessagingCenter.Send((IPage)this, BusySetSignalName, IsBusy);
}

void OnToolbarItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
Expand Down
1 change: 1 addition & 0 deletions src/Controls/src/Core/TypeConverterAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public sealed class TypeConverterAttribute : Attribute
{ typeof(CornerRadius), typeof(CornerRadiusTypeConverter) },
{ typeof(Color), typeof(ColorTypeConverter) },
{ typeof(Font), typeof(FontTypeConverter) },
{ typeof(FlowDirection), typeof(FlowDirectionConverter) },
{ typeof(Keyboard), typeof(KeyboardTypeConverter) },
{ typeof(Rectangle), typeof(RectangleTypeConverter) },
{ typeof(Size), typeof(SizeTypeConverter) },
Expand Down
Loading