Skip to content

Commit a7f0084

Browse files
Update variable names
1 parent 16919f7 commit a7f0084

File tree

4 files changed

+44
-36
lines changed

4 files changed

+44
-36
lines changed

samples/CommunityToolkit.Maui.Sample/Pages/Alerts/SnackbarPage.xaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
</pages:BasePage.Resources>
1616

1717
<VerticalStackLayout Spacing="12">
18-
<Button x:Name="DisplayCustomSnackbarButton2"
19-
Text="Display Custom Snackbar"
20-
Clicked="DisplayCustomSnackbarButtonClicked2"
21-
TextColor="{Binding Source={RelativeSource Self}, Path=BackgroundColor, Converter={StaticResource ColorToColorForTextConverter}, x:DataType=Button}"/>
22-
23-
2418
<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."
2519
LineBreakMode = "WordWrap" />
2620

@@ -31,7 +25,12 @@
3125
Text="Display Default Snackbar"/>
3226

3327
<Button x:Name="DisplayCustomSnackbarButton"
28+
Text="Display Custom Snackbar"
3429
Clicked="DisplayCustomSnackbarButtonClicked"
30+
TextColor="{Binding Source={RelativeSource Self}, Path=BackgroundColor, Converter={StaticResource ColorToColorForTextConverter}, x:DataType=Button}"/>
31+
32+
<Button x:Name="DisplayCustomSnackbarButtonAnchoredToButton"
33+
Clicked="DisplayCustomSnackbarAnchoredToButtonClicked"
3534
TextColor="{Binding Source={RelativeSource Self}, Path=BackgroundColor, Converter={StaticResource ColorToColorForTextConverter}, x:DataType=Button}"/>
3635

3736
<Button x:Name="DisplaySnackbarInModalButton"

samples/CommunityToolkit.Maui.Sample/Pages/Alerts/SnackbarPage.xaml.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public SnackbarPage(SnackbarViewModel snackbarViewModel) : base(snackbarViewMode
2525
{
2626
InitializeComponent();
2727

28-
DisplayCustomSnackbarButton.Text = displayCustomSnackbarText;
28+
DisplayCustomSnackbarButtonAnchoredToButton.Text = displayCustomSnackbarText;
2929

3030
Snackbar.Shown += Snackbar_Shown;
3131
Snackbar.Dismissed += Snackbar_Dismissed;
@@ -34,9 +34,9 @@ public SnackbarPage(SnackbarViewModel snackbarViewModel) : base(snackbarViewMode
3434
async void DisplayDefaultSnackbarButtonClicked(object? sender, EventArgs args) =>
3535
await this.DisplaySnackbar("This is a Snackbar.\nIt will disappear in 3 seconds.\nOr click OK to dismiss immediately");
3636

37-
async void DisplayCustomSnackbarButtonClicked(object? sender, EventArgs args)
37+
async void DisplayCustomSnackbarAnchoredToButtonClicked(object? sender, EventArgs args)
3838
{
39-
if (DisplayCustomSnackbarButton.Text is displayCustomSnackbarText)
39+
if (DisplayCustomSnackbarButtonAnchoredToButton.Text is displayCustomSnackbarText)
4040
{
4141
var options = new SnackbarOptions
4242
{
@@ -52,20 +52,20 @@ async void DisplayCustomSnackbarButtonClicked(object? sender, EventArgs args)
5252
"This is a customized Snackbar",
5353
async () =>
5454
{
55-
await DisplayCustomSnackbarButton.BackgroundColorTo(colors[Random.Shared.Next(colors.Count)], length: 500);
56-
DisplayCustomSnackbarButton.Text = displayCustomSnackbarText;
55+
await DisplayCustomSnackbarButtonAnchoredToButton.BackgroundColorTo(colors[Random.Shared.Next(colors.Count)], length: 500);
56+
DisplayCustomSnackbarButtonAnchoredToButton.Text = displayCustomSnackbarText;
5757
},
5858
FontAwesomeIcons.Microsoft,
5959
TimeSpan.FromSeconds(30),
6060
options,
61-
DisplayCustomSnackbarButton);
61+
DisplayCustomSnackbarButtonAnchoredToButton);
6262

6363
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
6464
await customSnackbar.Show(cts.Token);
6565

66-
DisplayCustomSnackbarButton.Text = dismissCustomSnackbarText;
66+
DisplayCustomSnackbarButtonAnchoredToButton.Text = dismissCustomSnackbarText;
6767
}
68-
else if (DisplayCustomSnackbarButton.Text is dismissCustomSnackbarText)
68+
else if (DisplayCustomSnackbarButtonAnchoredToButton.Text is dismissCustomSnackbarText)
6969
{
7070
if (customSnackbar is not null)
7171
{
@@ -75,14 +75,15 @@ async void DisplayCustomSnackbarButtonClicked(object? sender, EventArgs args)
7575
customSnackbar.Dispose();
7676
}
7777

78-
DisplayCustomSnackbarButton.Text = displayCustomSnackbarText;
78+
DisplayCustomSnackbarButtonAnchoredToButton.Text = displayCustomSnackbarText;
7979
}
8080
else
8181
{
82-
throw new NotSupportedException($"{nameof(DisplayCustomSnackbarButton)}.{nameof(ITextButton.Text)} Not Recognized");
82+
throw new NotSupportedException($"{nameof(DisplayCustomSnackbarButtonAnchoredToButton)}.{nameof(ITextButton.Text)} Not Recognized");
8383
}
8484
}
85-
async void DisplayCustomSnackbarButtonClicked2(object sender, EventArgs e)
85+
86+
async void DisplayCustomSnackbarButtonClicked(object sender, EventArgs e)
8687
{
8788
var options = new SnackbarOptions
8889
{
@@ -94,9 +95,10 @@ async void DisplayCustomSnackbarButtonClicked2(object sender, EventArgs e)
9495
CornerRadius = new CornerRadius(10),
9596
Font = Font.SystemFontOfSize(14),
9697
};
97-
await DisplayCustomSnackbarButton2.DisplaySnackbar(
98+
99+
await DisplayCustomSnackbarButton.DisplaySnackbar(
98100
"This is a customized Snackbar",
99-
() => DisplayCustomSnackbarButton2.BackgroundColor = Colors.Blue,
101+
() => DisplayCustomSnackbarButton.BackgroundColor = Colors.Blue,
100102
"Close",
101103
TimeSpan.FromSeconds(5),
102104
options);

src/CommunityToolkit.Maui.Core/Views/Alert/Alert.macios.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ public void Dismiss()
6262
/// <summary>
6363
/// Show the <see cref="Alert"/> on the screen
6464
/// </summary>
65-
/// <param name="stretch">Should stretch alert container horizontally</param>
66-
public void Show(bool stretch = false)
65+
/// <param name="shouldFillAndExpandHorizontally">Should stretch container horizontally to fit the screen</param>
66+
public void Show(bool shouldFillAndExpandHorizontally = false)
6767
{
6868
AlertView.AnchorView = Anchor;
6969

70-
AlertView.Setup(stretch);
70+
AlertView.Setup(shouldFillAndExpandHorizontally);
7171

7272
timer = NSTimer.CreateScheduledTimer(Duration, t =>
7373
{

src/CommunityToolkit.Maui.Core/Views/Alert/AlertView.macios.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ public class AlertView : UIView
2020
/// PopupView Children
2121
/// </summary>
2222
public IReadOnlyList<UIView> Children => children;
23-
23+
2424
/// <summary>
25-
/// <see cref="UIView"/> on which Alert will appear. When null, <see cref="AlertView"/> will appear at bottom of screen.
25+
/// <see cref="AlertViewVisualOptions"/>
2626
/// </summary>
27-
public UIView? AnchorView { get; set; }
27+
public AlertViewVisualOptions VisualOptions { get; } = new();
2828

2929
/// <summary>
30-
/// <see cref="AlertViewVisualOptions"/>
30+
/// <see cref="UIView"/> on which Alert will appear. When null, <see cref="AlertView"/> will appear at bottom of screen.
3131
/// </summary>
32-
public AlertViewVisualOptions VisualOptions { get; } = new();
32+
public UIView? AnchorView { get; set; }
3333

3434
/// <summary>
3535
/// Container of <see cref="AlertView"/>
@@ -50,27 +50,31 @@ public class AlertView : UIView
5050
/// <summary>
5151
/// Initializes <see cref="AlertView"/>
5252
/// </summary>
53-
/// <param name="stretch">Should stretch container horizontally</param>
54-
public void Setup(bool stretch = false)
53+
/// <param name="shouldFillAndExpandHorizontally">Should stretch container horizontally to fit the screen</param>
54+
public void Setup(bool shouldFillAndExpandHorizontally = false)
5555
{
5656
Initialize();
57-
ConstraintInParent(stretch);
57+
ConstraintInParent(shouldFillAndExpandHorizontally);
5858
}
5959

6060
/// <inheritdoc />
6161
public override void LayoutSubviews()
6262
{
6363
base.LayoutSubviews();
64-
_ = Container ?? throw new InvalidOperationException($"{nameof(AlertView)}.{nameof(Initialize)} not called");
64+
65+
if (Container is null)
66+
{
67+
throw new InvalidOperationException($"{nameof(AlertView)}.{nameof(Initialize)} must be called before {nameof(LayoutSubviews)}");
68+
}
6569

6670
if (AnchorView is null)
6771
{
6872
this.SafeBottomAnchor().ConstraintEqualTo(ParentView.SafeBottomAnchor(), -defaultSpacing).Active = true;
6973
this.SafeTopAnchor().ConstraintGreaterThanOrEqualTo(ParentView.SafeTopAnchor(), defaultSpacing).Active = true;
7074
}
71-
else
75+
else if (AnchorView.Superview is not null)
7276
{
73-
var anchorViewPosition = AnchorView.Superview!.ConvertRectToView(AnchorView.Frame, null);
77+
var anchorViewPosition = AnchorView.Superview.ConvertRectToView(AnchorView.Frame, null);
7478
if (anchorViewPosition.Top < Container.Frame.Height + SafeAreaLayoutGuide.LayoutFrame.Bottom)
7579
{
7680
this.SafeTopAnchor().ConstraintEqualTo(AnchorView.SafeBottomAnchor(), defaultSpacing).Active = true;
@@ -82,11 +86,14 @@ public override void LayoutSubviews()
8286
}
8387
}
8488

85-
void ConstraintInParent(bool stretch)
89+
void ConstraintInParent(bool shouldFillAndExpandHorizontally)
8690
{
87-
_ = Container ?? throw new InvalidOperationException($"{nameof(AlertView)}.{nameof(Initialize)} not called");
91+
if (Container is null)
92+
{
93+
throw new InvalidOperationException($"{nameof(AlertView)}.{nameof(Initialize)} must be called before {nameof(LayoutSubviews)}");
94+
}
8895

89-
if (stretch)
96+
if (shouldFillAndExpandHorizontally)
9097
{
9198
this.SafeLeadingAnchor().ConstraintEqualTo(ParentView.SafeLeadingAnchor(), defaultSpacing).Active = true;
9299
this.SafeTrailingAnchor().ConstraintEqualTo(ParentView.SafeTrailingAnchor(), -defaultSpacing).Active = true;

0 commit comments

Comments
 (0)