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

SnackBar #5

Merged
merged 38 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
37b8579
SnackBar/Toast
VladislavAntonyuk Jul 29, 2021
c17bf53
Fix DisplaySnackBarAsync Task never completes if another SnackBar app…
VladislavAntonyuk Oct 6, 2021
916fc58
Add samples
VladislavAntonyuk Oct 6, 2021
3a79cd1
Update src/CommunityToolkit.Maui/Views/Snackbar/Options/SnackBarActio…
VladislavAntonyuk Oct 16, 2021
9c2ade3
Apply suggestions from code review
VladislavAntonyuk Oct 16, 2021
ce72c10
Base Toast and Snackbar
VladislavAntonyuk Nov 21, 2021
4d60e6e
Remove toast, update sample, remove ios
VladislavAntonyuk Nov 21, 2021
c2a6a38
Add border, padding, fix tests, call events
VladislavAntonyuk Nov 21, 2021
8d6f126
remove base popup, fix anchor view
VladislavAntonyuk Nov 23, 2021
ca8c147
rebase on main, ios, macos snackbar
VladislavAntonyuk Nov 23, 2021
db3dd8b
implement ITextStyle
VladislavAntonyuk Nov 23, 2021
6eb2206
styles for ios/macos
VladislavAntonyuk Nov 24, 2021
2347e57
documentation
VladislavAntonyuk Nov 24, 2021
90079ac
Merge branch 'main' into vantonyuk/snackbar
VladislavAntonyuk Nov 24, 2021
c32e466
set android action button font
VladislavAntonyuk Nov 24, 2021
8c5eec7
Fix font
VladislavAntonyuk Nov 24, 2021
38ace05
base tests
VladislavAntonyuk Nov 25, 2021
8126f31
Add tests, IPlatformPopupExtensions
VladislavAntonyuk Nov 25, 2021
aaf38a5
Remove unused tasks from pipeline
VladislavAntonyuk Nov 25, 2021
a221d06
Add Windows
VladislavAntonyuk Nov 26, 2021
c6589f5
fix styles
VladislavAntonyuk Nov 26, 2021
040479c
Add padding, fix ios font size
VladislavAntonyuk Nov 26, 2021
8ee1d85
Unsubscribe from events
VladislavAntonyuk Nov 26, 2021
b68f68c
Minor code style tweaks
VladislavAntonyuk Nov 26, 2021
c508b2d
Update azure-pipelines.yml
brminnick Nov 26, 2021
dcac25c
Update CommunityToolkit.Maui.Sample.csproj
brminnick Nov 26, 2021
db35efc
`dotnet format`
brminnick Nov 26, 2021
9d1b36f
Implement `IDisposable` Per .NET Guidelines
brminnick Nov 26, 2021
4e33ffa
`dotnet format`
brminnick Nov 26, 2021
022ffdd
`SnackBar` -> `Snackbar`
brminnick Nov 26, 2021
84899c9
`SnackBar` -> `Snackbar`, Windows
brminnick Nov 26, 2021
7a51152
Update Snackbar Architecture
brminnick Nov 27, 2021
259016c
`dotnet format`
brminnick Nov 27, 2021
451b385
Refactor Snackbar Namespace to Alert`
brminnick Nov 27, 2021
e22d151
Update SnackBar.shared.cs
brminnick Nov 27, 2021
688d8d1
Fix CR comments
VladislavAntonyuk Nov 27, 2021
4af19e6
Fix behavior on Windows and ios
VladislavAntonyuk Nov 27, 2021
7024408
Add tests
VladislavAntonyuk Nov 27, 2021
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
27 changes: 9 additions & 18 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ jobs:
pool:
vmImage: windows-latest
steps:
# .NET 5.0 is required for maui-check
- task: UseDotNet@2
displayName: 'Install .NET 5.0 SDK'
inputs:
version: '5.0.x'
- task: UseDotNet@2
displayName: 'Install .NET SDK'
inputs:
Expand Down Expand Up @@ -77,7 +72,7 @@ jobs:
- powershell: |
$prNumber = $env:System_PullRequest_PullRequestNumber
$commitId = "$($env:System_PullRequest_SourceCommitId)".Substring(0, 7)
$fullVersionString = "$(CurrentSemanticVersionBase)-build.$prNumber+$commitId"
$fullVersionString = "$(CurrentSemanticVersionBase)-build-$prNumber.$(Build.BuildId)+$commitId"
Write-Host("GitHub PR = $prNumber, Commit = $commitId");
Write-Host ("##vso[task.setvariable variable=NugetPackageVersion;]$fullVersionString")
Write-Host "##vso[build.updatebuildnumber]$fullVersionString"
Expand All @@ -96,15 +91,13 @@ jobs:
inputs:
script: 'dotnet build $(PathToCommunityToolkitCsproj) -c Release'
- task: CmdLine@2
displayName: 'Build Community Toolkit Sample'
displayName: 'Run Unit Tests'
inputs:
script: 'dotnet build $(PathToCommunityToolkitSampleCsproj) -c Release'
script: 'dotnet test $(PathToCommunityToolkitUnitTestCsproj) -c Release'
- task: CmdLine@2
displayName: 'Run Unit Tests'
displayName: 'Build Community Toolkit Sample'
inputs:
script: |
dotnet build $(PathToCommunityToolkitUnitTestCsproj) -c Release
dotnet test $(PathToCommunityToolkitUnitTestCsproj) -c Release
script: 'dotnet build $(PathToCommunityToolkitSampleCsproj) -c Release'
- task: CmdLine@2
displayName: Pack Community Toolkit NuGets
inputs:
Expand Down Expand Up @@ -163,15 +156,13 @@ jobs:
inputs:
script: 'dotnet build $(PathToCommunityToolkitCsproj) -c Release'
- task: CmdLine@2
displayName: 'Build Community Toolkit Sample'
displayName: 'Run Unit Tests'
inputs:
script: 'dotnet build $(PathToCommunityToolkitSampleCsproj) -c Release'
script: 'dotnet test $(PathToCommunityToolkitUnitTestCsproj) -c Release'
- task: CmdLine@2
displayName: 'Run Unit Tests'
displayName: 'Build Community Toolkit Sample'
inputs:
script: |
dotnet build $(PathToCommunityToolkitUnitTestCsproj) -c Release
dotnet test $(PathToCommunityToolkitUnitTestCsproj) -c Release
script: 'dotnet build $(PathToCommunityToolkitSampleCsproj) -c Release'
- task: CmdLine@2
displayName: 'Pack CommunityToolkit NuGets'
inputs:
Expand Down
5 changes: 4 additions & 1 deletion samples/CommunityToolkit.Maui.Sample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Sampl
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3ED2C978-9DDB-48FE-8C5A-521B254F18A3}"
ProjectSection(SolutionItems) = preProject
..\.editorconfig = ..\.editorconfig
..\azure-pipelines.yml = ..\azure-pipelines.yml
..\Directory.Build.props = ..\Directory.Build.props
..\global.json = ..\global.json
..\.editorconfig = ..\.editorconfig
..\LICENSE = ..\LICENSE
..\README.md = ..\README.md
VladislavAntonyuk marked this conversation as resolved.
Show resolved Hide resolved
EndProjectSection
EndProject
Global
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-android'))">
brminnick marked this conversation as resolved.
Show resolved Hide resolved
<RuntimeIdentifiers>android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers>
</PropertyGroup>

</Project>
24 changes: 24 additions & 0 deletions samples/CommunityToolkit.Maui.Sample/Pages/Views/SnackBarPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<pages:BasePage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages"
x:Class="CommunityToolkit.Maui.Sample.Pages.Views.SnackBarPage">
<Grid ColumnDefinitions="Auto,Auto" RowDefinitions="Auto, Auto, Auto" RowSpacing="10" ColumnSpacing="10">
<Button Clicked="DisplaySnackBarClicked"
Text="Show SnackBar"
GridLayout.Column="0" GridLayout.Row="0" GridLayout.ColumnSpan="2"/>

<Button x:Name="Anchor1"
Clicked="DisplaySnackbarAnchoredClicked"
GridLayout.Column="0"
GridLayout.Row="1"
Text="Show snackbar with anchor"/>

<Button Clicked="DismissSnackbarClicked"
GridLayout.Column="1" GridLayout.Row="1"
Text="Dismiss snackbar with anchor"/>

<Label x:Name="StatusText"
GridLayout.Column="0" GridLayout.Row="2" GridLayout.ColumnSpan="2"/>
</Grid>
</pages:BasePage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Text;
using CommunityToolkit.Maui.Extensions;
using CommunityToolkit.Maui.Views.Popup.SnackBar;
using Microsoft.Maui;
using Microsoft.Maui.Graphics;

namespace CommunityToolkit.Maui.Sample.Pages.Views;

public partial class SnackBarPage : BasePage
{
ISnackbar? snackbarWithAnchor;
public SnackBarPage()
{
InitializeComponent();
Anchor1 ??= new ();
StatusText ??= new ();
}

async void DisplaySnackBarClicked(object? sender, EventArgs args)
{
await this.DisplaySnackBar(GenerateLongText(5), () =>
{
StatusText.Text = "SnackBar action button clicked";
});
}

async void DisplaySnackbarAnchoredClicked(object? sender, EventArgs args)
{
var options = new SnackbarOptions
{
BackgroundColor = Colors.Red,
TextColor = Colors.Green,
ActionButtonTextColor = Colors.Yellow,
CornerRadius = new CornerRadius(10, 20, 30, 40),
Font = Font.SystemFontOfSize(20),
CharacterSpacing = 1
};

snackbarWithAnchor = Snackbar.Make(
"Customized snackbar",
() => StatusText.Text = "SnackBar action button clicked",
"Run action",
TimeSpan.FromSeconds(30),
options,
Anchor1);

await snackbarWithAnchor.Show();
}

async void DismissSnackbarClicked(object sender, System.EventArgs e)
{
if (snackbarWithAnchor is not null)
await snackbarWithAnchor.Dismiss();
}

static string GenerateLongText(int stringDuplicationTimes)
{
const string message = "It is a very long message to test multiple strings. A B C D E F G H I I J K L M N O P Q R S T U V W X Y Z";
var result = new StringBuilder();
for (var i = 0; i < stringDuplicationTimes; i++)
{
result.AppendLine(message);
}

return result.ToString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<pages:BasePage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages"
x:Class="CommunityToolkit.Maui.Sample.Pages.Views.ViewsGalleryPage"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
xmlns:vm="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Views"
x:Name="Page"
Title="Views">

<pages:BasePage.BindingContext>
<vm:ViewsGalleryViewModel />
</pages:BasePage.BindingContext>

<StackLayout>
<ScrollView
VerticalOptions="FillAndExpand">
<StackLayout
Spacing="16">
<StackLayout
BindableLayout.ItemsSource="{Binding Items}"
Margin="6, 12, 6, 0">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame
Style="{StaticResource card}"
Margin="0, 0, 0, 6">
<Frame.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding NavigateCommand, Source={x:Reference Page}}"
CommandParameter="{Binding .}" />
</Frame.GestureRecognizers>
<Grid
RowSpacing="0"
RowDefinitions="Auto, *">
<Label
Text="{Binding Title}"
Style="{StaticResource label_section_header}"/>
<Label
Grid.Row="1"
Text="{Binding Description}"/>
</Grid>
</Frame>
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
</StackLayout>
</ScrollView>
</StackLayout>
</pages:BasePage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace CommunityToolkit.Maui.Sample.Pages.Views;

public partial class ViewsGalleryPage : BasePage
{
public ViewsGalleryPage()
{
InitializeComponent();
this.Page ??= this;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
using Android.App;
using Android.Content.PM;
using Android.OS;
using Microsoft.Maui;

namespace CommunityToolkit.Maui.Sample;

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
public class MainActivity : MauiAppCompatActivity
{
// https://github.com/dotnet/maui/pull/3345
VladislavAntonyuk marked this conversation as resolved.
Show resolved Hide resolved
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);
Microsoft.Maui.Essentials.Platform.Init(this, savedInstanceState);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CommunityToolkit.Maui.Sample.Pages.Converters;
using CommunityToolkit.Maui.Sample.Pages.Extensions;
using Microsoft.Maui.Graphics;
using CommunityToolkit.Maui.Sample.Pages.Views;

namespace CommunityToolkit.Maui.Sample.ViewModels;

Expand All @@ -19,5 +20,8 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]

new SectionModel(typeof(ExtensionsGalleryPage), "Extensions", Color.FromArgb("#00EA56"),
"Extenions lets you add methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type."),

new SectionModel(typeof(ViewsGalleryPage), "Views", Color.FromArgb("#EF6950"),
"A custom view or control allows for adding custom functionality as if it came out of the Maui box"),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using CommunityToolkit.Maui.Sample.Models;
using CommunityToolkit.Maui.Sample.Pages.Views;

namespace CommunityToolkit.Maui.Sample.ViewModels.Views;

public class ViewsGalleryViewModel : BaseGalleryViewModel
{
protected override IEnumerable<SectionModel> CreateItems() => new[]
{
new SectionModel(typeof(SnackBarPage), "SnackBar/Toast", "Show SnackBar, Toast etc")
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using CommunityToolkit.Maui.Views.Popup.SnackBar;
using CommunityToolkit.Maui.Views.Popup.SnackBar.Platforms;

namespace CommunityToolkit.Maui.UnitTests.Mocks;

class MockPlatformPopupExtensions : IPlatformPopupExtensions
{
public void Dismiss(Snackbar snackbar)
{
snackbar.OnDismissed();
}

public object Show(Snackbar snackbar)
{
return new object();
}
}
59 changes: 59 additions & 0 deletions src/CommunityToolkit.Maui.UnitTests/Views/SnackBar_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CommunityToolkit.Maui.UnitTests.Mocks;
using CommunityToolkit.Maui.Views.Popup;
using CommunityToolkit.Maui.Views.Popup.SnackBar;
using Xunit;

namespace CommunityToolkit.Maui.UnitTests.Views;

public class SnackBar_Tests : BaseTest
{
Snackbar snackbar;
public SnackBar_Tests()
{
snackbar = new Snackbar();
snackbar.PlatformPopupExtensions = new MockPlatformPopupExtensions();
}

[Fact]
public async Task SnackbarShow_IsShownTrue()
{
await snackbar.Show();
Assert.True(Snackbar.IsShown);
}

[Fact]
public async Task SnackbarDismissed_IsShownFalse()
{
await snackbar.Dismiss();
Assert.False(Snackbar.IsShown);
}

[Fact]
public async Task SnackbarShow_ShownEventRaised()
{
var receivedEvents = new List<ShownEventArgs>();
Snackbar.Shown += delegate (object? sender, ShownEventArgs e)
{
receivedEvents.Add(e);
};
await snackbar.Show();
Assert.Single(receivedEvents);
Assert.True(receivedEvents.First()?.IsShown);
}

[Fact]
public async Task SnackbarDismiss_DismissedEventRaised()
{
var receivedEvents = new List<EventArgs>();
Snackbar.Dismissed += delegate (object? sender, EventArgs e)
{
receivedEvents.Add(e);
};
await snackbar.Show();
Assert.Single(receivedEvents);
}
}
2 changes: 1 addition & 1 deletion src/CommunityToolkit.Maui/CommunityToolkit.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@
<ItemGroup Condition=" $(TargetFramework.Contains('-windows')) ">
<Compile Include="**\*.windows.cs" />
<Compile Include="**\*.windows.*.cs" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.2" />
brminnick marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

<ItemGroup Condition=" $(TargetFramework.Contains('-maccatalyst')) ">
<Compile Include="**\*.macos.cs" />
<Compile Include="**\*.macos.*.cs" />
</ItemGroup>

</Project>
Loading