-
Notifications
You must be signed in to change notification settings - Fork 501
SnackBar #5
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
Merged
TheCodeTraveler
merged 38 commits into
CommunityToolkit:main
from
VladislavAntonyuk:vantonyuk/snackbar
Nov 27, 2021
Merged
SnackBar #5
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
37b8579
SnackBar/Toast
VladislavAntonyuk c17bf53
Fix DisplaySnackBarAsync Task never completes if another SnackBar app…
VladislavAntonyuk 916fc58
Add samples
VladislavAntonyuk 3a79cd1
Update src/CommunityToolkit.Maui/Views/Snackbar/Options/SnackBarActio…
VladislavAntonyuk 9c2ade3
Apply suggestions from code review
VladislavAntonyuk ce72c10
Base Toast and Snackbar
VladislavAntonyuk 4d60e6e
Remove toast, update sample, remove ios
VladislavAntonyuk c2a6a38
Add border, padding, fix tests, call events
VladislavAntonyuk 8d6f126
remove base popup, fix anchor view
VladislavAntonyuk ca8c147
rebase on main, ios, macos snackbar
VladislavAntonyuk db3dd8b
implement ITextStyle
VladislavAntonyuk 6eb2206
styles for ios/macos
VladislavAntonyuk 2347e57
documentation
VladislavAntonyuk 90079ac
Merge branch 'main' into vantonyuk/snackbar
VladislavAntonyuk c32e466
set android action button font
VladislavAntonyuk 8c5eec7
Fix font
VladislavAntonyuk 38ace05
base tests
VladislavAntonyuk 8126f31
Add tests, IPlatformPopupExtensions
VladislavAntonyuk aaf38a5
Remove unused tasks from pipeline
VladislavAntonyuk a221d06
Add Windows
VladislavAntonyuk c6589f5
fix styles
VladislavAntonyuk 040479c
Add padding, fix ios font size
VladislavAntonyuk 8ee1d85
Unsubscribe from events
VladislavAntonyuk b68f68c
Minor code style tweaks
VladislavAntonyuk c508b2d
Update azure-pipelines.yml
TheCodeTraveler dcac25c
Update CommunityToolkit.Maui.Sample.csproj
TheCodeTraveler db35efc
`dotnet format`
TheCodeTraveler 9d1b36f
Implement `IDisposable` Per .NET Guidelines
TheCodeTraveler 4e33ffa
`dotnet format`
TheCodeTraveler 022ffdd
`SnackBar` -> `Snackbar`
TheCodeTraveler 84899c9
`SnackBar` -> `Snackbar`, Windows
TheCodeTraveler 7a51152
Update Snackbar Architecture
TheCodeTraveler 259016c
`dotnet format`
TheCodeTraveler 451b385
Refactor Snackbar Namespace to Alert`
TheCodeTraveler e22d151
Update SnackBar.shared.cs
TheCodeTraveler 688d8d1
Fix CR comments
VladislavAntonyuk 4af19e6
Fix behavior on Windows and ios
VladislavAntonyuk 7024408
Add tests
VladislavAntonyuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
10 changes: 10 additions & 0 deletions
10
samples/CommunityToolkit.Maui.Sample/Pages/Alerts/AlertsGalleryPage.cs
This file contains hidden or 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,10 @@ | ||
| using CommunityToolkit.Maui.Sample.ViewModels.Alerts; | ||
|
|
||
| namespace CommunityToolkit.Maui.Sample.Pages.Alerts; | ||
|
|
||
| public class AlertsGalleryPage : BaseGalleryPage<AlertsGalleryViewModel> | ||
| { | ||
| public AlertsGalleryPage() : base("Alerts") | ||
| { | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
samples/CommunityToolkit.Maui.Sample/Pages/Alerts/SnackbarPage.xaml
This file contains hidden or 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,37 @@ | ||
| <?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" | ||
| xmlns:converters="clr-namespace:CommunityToolkit.Maui.Converters;assembly=CommunityToolkit.Maui" | ||
| x:Class="CommunityToolkit.Maui.Sample.Pages.Alerts.SnackbarPage"> | ||
|
|
||
| <pages:BasePage.Resources> | ||
| <ResourceDictionary> | ||
| <converters:ColorToColorForTextConverter x:Key="ColorToColorForTextConverter"/> | ||
| </ResourceDictionary> | ||
| </pages:BasePage.Resources> | ||
|
|
||
| <VerticalStackLayout Spacing="12"> | ||
|
|
||
| <Label Text="The Snackbar is a timed alert that appears at the bottom of the screen by default. It is dismissed after a configurable duration of time. Snackbar is fully customizable and can be anchored to any IView." | ||
| LineBreakMode = "WordWrap" /> | ||
|
|
||
| <Label Text="Windows uses toast notifications to display snackbar. Make sure you switched off Focus Assist." | ||
| IsVisible="false"> | ||
| <Label.IsVisible> | ||
| <OnPlatform x:TypeArguments="x:Boolean"> | ||
| <On Platform="UWP" Value="true" /> | ||
| </OnPlatform> | ||
| </Label.IsVisible> | ||
| </Label> | ||
|
|
||
| <Button Clicked="DisplayDefaultSnackbarButtonClicked" | ||
| Text="Display Default Snackbar"/> | ||
|
|
||
| <Button x:Name="DisplayCustomSnackbarButton" | ||
| Clicked="DisplayCustomSnackbarButtonClicked" | ||
| TextColor="{Binding Source={RelativeSource Self}, Path=BackgroundColor, Converter={StaticResource ColorToColorForTextConverter}}"/> | ||
|
|
||
| </VerticalStackLayout> | ||
|
|
||
| </pages:BasePage> |
75 changes: 75 additions & 0 deletions
75
samples/CommunityToolkit.Maui.Sample/Pages/Alerts/SnackbarPage.xaml.cs
This file contains hidden or 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,75 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Reflection; | ||
| using CommunityToolkit.Maui.Alerts.Snackbar; | ||
| using CommunityToolkit.Maui.Extensions; | ||
| using Microsoft.Maui; | ||
| using Microsoft.Maui.Graphics; | ||
|
|
||
| namespace CommunityToolkit.Maui.Sample.Pages.Alerts; | ||
|
|
||
| public partial class SnackbarPage : BasePage | ||
| { | ||
| const string _displayCustomSnackbarText = "Display a Custom Snackbar, Anchored to this Button"; | ||
| const string _dismissCustomSnackbarText = "Dismiss Custom Snackbar"; | ||
| readonly IReadOnlyList<Color> _colors = typeof(Colors) | ||
| .GetFields(BindingFlags.Static | BindingFlags.Public) | ||
| .ToDictionary(c => c.Name, c => (Color)(c.GetValue(null) ?? throw new InvalidOperationException())) | ||
| .Values.ToList(); | ||
|
|
||
| ISnackbar? _customSnackbar; | ||
|
|
||
| public SnackbarPage() | ||
| { | ||
| InitializeComponent(); | ||
|
|
||
| DisplayCustomSnackbarButton ??= new(); | ||
| DisplayCustomSnackbarButton.Text = _displayCustomSnackbarText; | ||
| } | ||
|
|
||
| async void DisplayDefaultSnackbarButtonClicked(object? sender, EventArgs args) => | ||
| await this.DisplaySnackbar("This is a Snackbar.\nIt will disappear in 3 seconds.\nOr click OK to dismiss immediately"); | ||
|
|
||
| async void DisplayCustomSnackbarButtonClicked(object? sender, EventArgs args) | ||
| { | ||
| if (DisplayCustomSnackbarButton.Text is _displayCustomSnackbarText) | ||
| { | ||
| var options = new SnackbarOptions | ||
| { | ||
| BackgroundColor = Colors.Red, | ||
| TextColor = Colors.Green, | ||
| ActionButtonTextColor = Colors.Yellow, | ||
| CornerRadius = new CornerRadius(10), | ||
| Font = Font.SystemFontOfSize(14), | ||
| }; | ||
|
|
||
| _customSnackbar = Snackbar.Make( | ||
| "This is a customized Snackbar", | ||
| async () => | ||
| { | ||
| await DisplayCustomSnackbarButton.BackgroundColorTo(_colors[new Random().Next(_colors.Count)], length: 500); | ||
| DisplayCustomSnackbarButton.Text = _displayCustomSnackbarText; | ||
| }, | ||
| "Change Button Color", | ||
| TimeSpan.FromSeconds(30), | ||
| options, | ||
| DisplayCustomSnackbarButton); | ||
|
|
||
| await _customSnackbar.Show(); | ||
|
|
||
| DisplayCustomSnackbarButton.Text = _dismissCustomSnackbarText; | ||
| } | ||
| else if (DisplayCustomSnackbarButton.Text is _dismissCustomSnackbarText) | ||
| { | ||
| if (_customSnackbar is not null) | ||
| await _customSnackbar.Dismiss(); | ||
|
|
||
| DisplayCustomSnackbarButton.Text = _displayCustomSnackbarText; | ||
| } | ||
| else | ||
| { | ||
| throw new NotImplementedException($"{nameof(DisplayCustomSnackbarButton)}.{nameof(ITextButton.Text)} Not Recognized"); | ||
| } | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
samples/CommunityToolkit.Maui.Sample/Platforms/Android/MainActivity.cs
This file contains hidden or 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,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.
|
||
| protected override void OnCreate(Bundle? savedInstanceState) | ||
| { | ||
| base.OnCreate(savedInstanceState); | ||
| Microsoft.Maui.Essentials.Platform.Init(this, savedInstanceState); | ||
| } | ||
| } | ||
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
samples/CommunityToolkit.Maui.Sample/ViewModels/Alerts/AlertsGalleryViewModel.cs
This file contains hidden or 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 System.Collections.Generic; | ||
| using CommunityToolkit.Maui.Sample.Models; | ||
| using CommunityToolkit.Maui.Sample.Pages.Alerts; | ||
|
|
||
| namespace CommunityToolkit.Maui.Sample.ViewModels.Alerts; | ||
|
|
||
| public class AlertsGalleryViewModel : BaseGalleryViewModel | ||
| { | ||
| protected override IEnumerable<SectionModel> CreateItems() => new[] | ||
| { | ||
| new SectionModel(typeof(SnackbarPage), "Snackbar", "Show Snackbar Alert") | ||
| }; | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.