Skip to content

Commit

Permalink
179 Alert Dialogue Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sofiya-kumar committed Aug 31, 2023
1 parent 33aac1e commit 62ec80c
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 17 deletions.
3 changes: 3 additions & 0 deletions DemoApp/DemoApp/DemoApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@
</ItemGroup>

<ItemGroup>
<MauiXaml Update="Views\DisplayAlertSamplePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\ProgressBarSamplePage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
Expand Down
8 changes: 6 additions & 2 deletions DemoApp/DemoApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public MainPage()
"Accordion",
"Chips",
"Switch",
"ProgressBar"
"ProgressBar",
"Display Alert"
};
BindingContext = this;
}
Expand Down Expand Up @@ -100,7 +101,10 @@ private void ItemTapped(object sender, ItemTappedEventArgs e)
break;
case "Switch":
Navigation.PushAsync(new SwitchSamplePage());
break;
break;
case "Display Alert":
Navigation.PushAsync(new DisplayAlertSamplePage());
break;
default:
Console.WriteLine("Default Case");
break;
Expand Down
40 changes: 40 additions & 0 deletions DemoApp/DemoApp/ViewModels/DisplayAlertSampleViewModel.cs
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");
}
}
}
20 changes: 20 additions & 0 deletions DemoApp/DemoApp/Views/DisplayAlertSamplePage.xaml
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>
13 changes: 13 additions & 0 deletions DemoApp/DemoApp/Views/DisplayAlertSamplePage.xaml.cs
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 Trimble.Modus.Components/Controls/TMModal/DisplayAlert.xaml
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 Trimble.Modus.Components/Controls/TMModal/DisplayAlert.xaml.cs
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);
});
}
}

0 comments on commit 62ec80c

Please sign in to comment.