-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33aac1e
commit 62ec80c
Showing
7 changed files
with
287 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using Trimble.Modus.Components; | ||
|
||
namespace DemoApp.ViewModels | ||
{ | ||
public partial class DisplayAlertSampleViewModel : ObservableObject | ||
{ | ||
[ObservableProperty] string _title; | ||
[ObservableProperty] string _message; | ||
[ObservableProperty] string _primaryButtonText; | ||
[ObservableProperty] string _secondaryButtonText; | ||
public DisplayAlertSampleViewModel() | ||
{ | ||
Title = "Alert"; | ||
Message = "Do you want to delete?"; | ||
PrimaryButtonText = "Okay"; | ||
SecondaryButtonText = ""; | ||
} | ||
|
||
[RelayCommand] | ||
async Task ShowAlert() | ||
{ | ||
var confirmationDialog = new DisplayAlert(Title, Message, PrimaryButtonText, SecondaryButtonText); | ||
confirmationDialog.OnPrimaryButtonClicked += delegate { OnPrimarySelected(); }; | ||
confirmationDialog.OnSecondaryButtonClicked += delegate { OnSecondarySelected(); }; | ||
await confirmationDialog.Show(); | ||
} | ||
|
||
void OnPrimarySelected() | ||
{ | ||
Console.WriteLine("Primary button clicked"); | ||
} | ||
|
||
void OnSecondarySelected() | ||
{ | ||
Console.WriteLine("Secondary button clicked"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:modus="http://modus.trimble.com/components" | ||
x:Class="DemoApp.Views.DisplayAlertSamplePage" | ||
Title="DisplayAlertSamplePage"> | ||
<VerticalStackLayout Spacing="10" Padding="10"> | ||
<modus:TMButton Title="Show Display Alert" | ||
Command="{Binding ShowAlertCommand}" | ||
HorizontalOptions="Center" /> | ||
<modus:TMInput Placeholder="Title" | ||
Text="{Binding Title}" /> | ||
<modus:TMInput Placeholder="Message" | ||
Text="{Binding Message}" /> | ||
<modus:TMInput Placeholder="Primary text" | ||
Text="{Binding PrimaryButtonText}" /> | ||
<modus:TMInput Placeholder="Secondary text" | ||
Text="{Binding SecondaryButtonText}" /> | ||
</VerticalStackLayout> | ||
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using DemoApp.ViewModels; | ||
|
||
namespace DemoApp.Views; | ||
|
||
public partial class DisplayAlertSamplePage : ContentPage | ||
{ | ||
DisplayAlertSampleViewModel _viewModel = new DisplayAlertSampleViewModel(); | ||
public DisplayAlertSamplePage() | ||
{ | ||
InitializeComponent(); | ||
BindingContext = _viewModel; | ||
} | ||
} |
87 changes: 78 additions & 9 deletions
87
Trimble.Modus.Components/Controls/TMModal/DisplayAlert.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,81 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<Modus:PopupPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:Modus="clr-namespace:Trimble.Modus.Components" | ||
x:Class="Trimble.Modus.Components.Controls.TMModal.DisplayAlert"> | ||
<VerticalStackLayout> | ||
<Label | ||
Text="Welcome to .NET MAUI!" | ||
VerticalOptions="Center" | ||
HorizontalOptions="Center" /> | ||
</VerticalStackLayout> | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:Modus="clr-namespace:Trimble.Modus.Components" | ||
xmlns:color="clr-namespace:Trimble.Modus.Components.Styles" | ||
xmlns:converters="clr-namespace:Trimble.Modus.Components.Converters" | ||
BackgroundColor="{x:StaticResource ModalGraySemiTransparent}" | ||
x:Class="Trimble.Modus.Components.DisplayAlert"> | ||
<ContentPage.Resources> | ||
<ResourceDictionary> | ||
<converters:StringNotNullOrEmptyBoolConverter x:Key="StringNotNullOrEmptyBoolConverter" /> | ||
<ResourceDictionary.MergedDictionaries> | ||
<color:Colors /> | ||
</ResourceDictionary.MergedDictionaries> | ||
</ResourceDictionary> | ||
</ContentPage.Resources> | ||
<Border StrokeThickness="0" | ||
Padding="15,5" | ||
BackgroundColor="{x:StaticResource ModalShadowColor}"> | ||
<Grid VerticalOptions="CenterAndExpand" | ||
HorizontalOptions="FillAndExpand" | ||
Padding="16"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="10" /> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="10" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<StackLayout Orientation="Vertical" | ||
Grid.Row="0" | ||
Grid.Column="1" | ||
BackgroundColor="White" | ||
VerticalOptions="CenterAndExpand" | ||
Spacing="16" | ||
HorizontalOptions="FillAndExpand" | ||
Padding="16,16,16,8"> | ||
<Label Text="{Binding Title}" | ||
VerticalOptions="Center" | ||
FontFamily="OpenSansSemibold" | ||
FontSize="16" | ||
TextColor="{StaticResource Black}" | ||
HorizontalOptions="Start" /> | ||
|
||
<Label Text="{Binding Message}" | ||
HorizontalOptions="Start" | ||
VerticalOptions="StartAndExpand" | ||
FontSize="14" | ||
TextColor="{x:StaticResource Black}" | ||
LineBreakMode="WordWrap" /> | ||
</StackLayout> | ||
|
||
<Grid HorizontalOptions="Fill" | ||
Grid.Row="1" | ||
Grid.Column="1" | ||
RowDefinitions="Auto" | ||
ColumnDefinitions="*,Auto,10,Auto" | ||
BackgroundColor="White" | ||
Padding="16"> | ||
<Modus:TMButton Grid.Column="1" | ||
Title="{Binding SecondaryText}" | ||
VerticalOptions="Center" | ||
HorizontalOptions="StartAndExpand" | ||
ButtonStyle="BorderLess" | ||
Size="Small" | ||
IsVisible="{Binding SecondaryText,Converter={StaticResource StringNotNullOrEmptyBoolConverter}}" | ||
x:Name="SecondaryButton" /> | ||
<Modus:TMButton Grid.Column="3" | ||
VerticalOptions="Center" | ||
Title="{Binding PrimaryText}" | ||
HorizontalOptions="EndAndExpand" | ||
ButtonStyle="Fill" | ||
Size="Small" | ||
x:Name="PrimaryButton" /> | ||
</Grid> | ||
</Grid> | ||
</Border> | ||
</Modus:PopupPage> |
133 changes: 127 additions & 6 deletions
133
Trimble.Modus.Components/Controls/TMModal/DisplayAlert.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,130 @@ | ||
namespace Trimble.Modus.Components.Controls.TMModal; | ||
using Trimble.Modus.Components.Popup.Services; | ||
|
||
namespace Trimble.Modus.Components; | ||
|
||
public partial class DisplayAlert | ||
{ | ||
public DisplayAlert() | ||
{ | ||
InitializeComponent(); | ||
} | ||
{ | ||
private bool closeOnDisappearing = true; | ||
TaskCompletionSource<bool> buttonTappedTask = new TaskCompletionSource<bool>(); | ||
/// <summary> | ||
/// Gets or sets the text for the title label in the control | ||
/// </summary> | ||
public static readonly BindableProperty TitleTextProperty = | ||
BindableProperty.Create(nameof(Title), typeof(string), typeof(DisplayAlert)); | ||
|
||
/// <summary> | ||
/// Gets or sets the text for the title label in the control | ||
/// </summary> | ||
public static readonly BindableProperty MessageTextProperty = | ||
BindableProperty.Create(nameof(Message), typeof(string), typeof(DisplayAlert)); | ||
|
||
/// <summary> | ||
/// Gets or sets the text for the title label in the control | ||
/// </summary> | ||
public static readonly BindableProperty PrimaryTextProperty = | ||
BindableProperty.Create(nameof(PrimaryText), typeof(string), typeof(DisplayAlert)); | ||
|
||
/// <summary> | ||
/// Gets or sets the text for the title label in the control | ||
/// </summary> | ||
public static readonly BindableProperty SecondaryTextProperty = | ||
BindableProperty.Create(nameof(SecondaryText), typeof(string), typeof(DisplayAlert)); | ||
|
||
|
||
/// <summary> | ||
/// Gets or sets title text | ||
/// </summary> | ||
public new string Title | ||
{ | ||
get { return (string)GetValue(TitleTextProperty); } | ||
set { SetValue(TitleTextProperty, value); } | ||
} | ||
|
||
public string Message | ||
{ | ||
get { return (string)GetValue(MessageTextProperty); } | ||
set { SetValue(MessageTextProperty, value); } | ||
} | ||
|
||
public string PrimaryText | ||
{ | ||
get { return (string)GetValue(PrimaryTextProperty); } | ||
set { SetValue(PrimaryTextProperty, value); } | ||
} | ||
|
||
public string SecondaryText | ||
{ | ||
get { return (string)GetValue(SecondaryTextProperty); } | ||
set { SetValue(SecondaryTextProperty, value); } | ||
} | ||
|
||
/// <summary> | ||
/// Occurs when primary button is clicked | ||
/// </summary> | ||
public event EventHandler OnPrimaryButtonClicked | ||
{ | ||
add | ||
{ | ||
PrimaryButton.Clicked += value; | ||
} | ||
|
||
remove | ||
{ | ||
PrimaryButton.Clicked -= value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Occurs when secondary button is clicked | ||
/// </summary> | ||
public event EventHandler OnSecondaryButtonClicked | ||
{ | ||
add | ||
{ | ||
SecondaryButton.Clicked += value; | ||
} | ||
|
||
remove | ||
{ | ||
SecondaryButton.Clicked -= value; | ||
} | ||
} | ||
|
||
|
||
public DisplayAlert(string title, string message = "", string primaryButtonText = "Okay", string secondaryText = "") | ||
{ | ||
InitializeComponent(); | ||
BindingContext = this; | ||
Title = title; | ||
Message = message; | ||
PrimaryText = primaryButtonText; | ||
SecondaryText = secondaryText; | ||
PrimaryButton.Clicked += ClosePopup; | ||
SecondaryButton.Clicked += ClosePopup; | ||
Disappearing += OnDisappearing; | ||
} | ||
|
||
private void OnDisappearing(object sender, EventArgs e) | ||
{ | ||
if (closeOnDisappearing) | ||
ClosePopup(sender, e); | ||
} | ||
|
||
public Task<bool> Show() | ||
{ | ||
PopupService.Instance.PresentAsync(this); | ||
return buttonTappedTask.Task; | ||
} | ||
|
||
private void ClosePopup(object sender, EventArgs e) | ||
{ | ||
closeOnDisappearing = false; | ||
PrimaryButton.Clicked -= ClosePopup; | ||
SecondaryButton.Clicked -= ClosePopup; | ||
Task.Run(async () => | ||
{ | ||
await PopupService.Instance.DismissAsync(); | ||
buttonTappedTask.SetResult(sender == PrimaryButton); | ||
}); | ||
} | ||
} |