Skip to content

Commit 2583913

Browse files
authored
Support Liquid Glass effect (#125)
* Apply funky colors for buttons to better display effects * Default to Liquid Glass on iOS/MacCatalyst 26.0 * Update README * Update to .NET 10 RC2
1 parent b44e2ed commit 2583913

File tree

6 files changed

+79
-13
lines changed

6 files changed

+79
-13
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on: [push]
44

55
env:
66
xcodeVersion: 26.0.1
7-
dotnetVersion: 10.0.100-rc.1.25451.107
7+
dotnetVersion: 10.0.100-rc.2.25502.107
88

99
jobs:
1010
build:

BTProgressHUD/ProgressHUD.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,27 +256,40 @@ UIView HudView
256256
return _hudView;
257257

258258
UIView hudView;
259-
if (ProgressHUDAppearance.HudBackgroundColor.Equals(UIColor.Clear))
259+
if (ProgressHUDAppearance.HudBackgroundVisualEffect != null)
260260
{
261261
hudView = new UIView
262262
{
263-
BackgroundColor = ProgressHUDAppearance.HudBackgroundColor
263+
BackgroundColor = UIColor.Clear,
264264
};
265+
266+
hudView.AddSubview(new UIVisualEffectView(ProgressHUDAppearance.HudBackgroundVisualEffect)
267+
{
268+
AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
269+
});
265270
}
266271
else
267272
{
268-
hudView = new UIToolbar
273+
hudView = new UIView
269274
{
270-
Translucent = true,
271-
BarTintColor = ProgressHUDAppearance.HudBackgroundColor,
272-
BackgroundColor = ProgressHUDAppearance.HudBackgroundColor
275+
BackgroundColor = ProgressHUDAppearance.HudBackgroundColor,
273276
};
274277
}
275278

276279
hudView.AutoresizingMask =
277280
UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleTopMargin |
278281
UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleLeftMargin;
279282

283+
if (ProgressHUDAppearance.HudBorderThickness > 0)
284+
{
285+
hudView.Layer.BorderWidth = ProgressHUDAppearance.HudBorderThickness;
286+
}
287+
288+
if (ProgressHUDAppearance.HudBorderColor != null)
289+
{
290+
hudView.Layer.BorderColor = ProgressHUDAppearance.HudBorderColor.CGColor;
291+
}
292+
280293
hudView.Layer.CornerRadius = ProgressHUDAppearance.HudCornerRadius;
281294
hudView.Layer.MasksToBounds = true;
282295

BTProgressHUD/ProgressHUDAppearance.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public static class ProgressHUDAppearance
1414
OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ?
1515
UIColor.Label.ColorWithAlpha(0.8f) :
1616
UIColor.FromWhiteAlpha(0.0f, 0.8f);
17+
18+
public static UIVisualEffect DefaultBackgroundVisualEffect { get; } =
19+
OperatingSystem.IsIOSVersionAtLeast(26, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(26) ?
20+
UIGlassEffect.Create(UIGlassEffectStyle.Regular) :
21+
UIBlurEffect.FromStyle(UIBlurEffectStyle.Regular);
1722

1823
public static UIColor DefaultHudToastBackgroundColor { get; } = UIColor.Clear;
1924
public static UIFont DefaultHudFont { get; } = UIFont.BoldSystemFontOfSize(16f);
@@ -28,7 +33,19 @@ public static class ProgressHUDAppearance
2833

2934
public const float DefaultRingRadius = 14f;
3035
public const float DefaultRingThickness = 1f;
31-
public const float DefaultHudCornerRadius = 10f;
36+
public static float DefaultHudCornerRadius { get; } =
37+
OperatingSystem.IsIOSVersionAtLeast(26, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(26) ?
38+
20f : 10f;
39+
40+
public static float DefaultHudBorderThickness { get; } =
41+
OperatingSystem.IsIOSVersionAtLeast(26, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(26) ?
42+
1f : 0f;
43+
44+
public static UIColor DefaultHudBorderColor { get; } =
45+
OperatingSystem.IsIOSVersionAtLeast(26, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(26) ?
46+
UIColor.FromWhiteAlpha(1.0f, 0.3f) :
47+
UIColor.Clear;
48+
3249
public const double DefaultProgressUpdateInterval = 300;
3350
public const float DefaultActivityIndicatorScale = 1f;
3451

@@ -66,11 +83,26 @@ public static class ProgressHUDAppearance
6683
/// Get or set hud corner radius
6784
/// </summary>
6885
public static float HudCornerRadius { get; set; } = DefaultHudCornerRadius;
69-
86+
7087
/// <summary>
71-
/// Get or set hud background color
88+
/// Get or set hud background color. This only works if HudBackgroundVisualEffect is null
7289
/// </summary>
7390
public static UIColor HudBackgroundColor { get; set; } = DefaultHudBackgroundColor;
91+
92+
/// <summary>
93+
/// Get or set hud border thickness
94+
/// </summary>
95+
public static float HudBorderThickness { get; set; } = DefaultHudBorderThickness;
96+
97+
/// <summary>
98+
/// Get or set hud border color
99+
/// </summary>
100+
public static UIColor HudBorderColor { get; set; } = DefaultHudBorderColor;
101+
102+
/// <summary>
103+
/// Get or set hud background visual effect
104+
/// </summary>
105+
public static UIVisualEffect? HudBackgroundVisualEffect { get; set; } = DefaultBackgroundVisualEffect;
74106

75107
/// <summary>
76108
/// Get or set image tint color
@@ -127,6 +159,9 @@ public static void ResetToDefaults()
127159

128160
HudCornerRadius = DefaultHudCornerRadius;
129161
HudBackgroundColor = DefaultHudBackgroundColor;
162+
HudBorderThickness = DefaultHudBorderThickness;
163+
HudBackgroundVisualEffect = DefaultBackgroundVisualEffect;
164+
HudBorderThickness = DefaultHudBorderThickness;
130165
HudImageTintColor = DefaultForegroundColor;
131166
HudToastBackgroundColor = DefaultHudToastBackgroundColor;
132167
HudFont = DefaultHudFont;

BTProgressHUDDemo/MainPage.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
<DataTemplate>
1717
<VerticalStackLayout Margin="16, 2">
1818
<Button Text="{Binding Text}"
19-
Command="{Binding Command}"/>
19+
Command="{Binding Command}"
20+
BackgroundColor="{Binding Color}"/>
2021
</VerticalStackLayout>
2122
</DataTemplate>
2223
</CollectionView.ItemTemplate>

BTProgressHUDDemo/MainViewModel.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ public class MainViewModel
1111
float progress = -1;
1212
NSTimer timer;
1313

14+
Color[] colors =
15+
[
16+
Color.FromRgb(255, 59, 48),
17+
Color.FromRgb(255, 149, 0),
18+
Color.FromRgb(255, 204, 0),
19+
Color.FromRgb(76, 217, 100),
20+
Color.FromRgb(90, 200, 250),
21+
Color.FromRgb(0, 122, 255),
22+
Color.FromRgb(88, 86, 214),
23+
Color.FromRgb(255, 45, 85)
24+
];
25+
1426
public MainViewModel()
1527
{
1628
Items =
@@ -104,10 +116,10 @@ public MainViewModel()
104116
ProgressHUDAppearance.RingColor = UIColor.Green;
105117
ProgressHUDAppearance.RingBackgroundColor = UIColor.Brown;
106118

107-
ProgressHUDAppearance.HudBackgroundColor = UIColor.Yellow;
119+
ProgressHUDAppearance.HudBackgroundColor = UIColor.Brown;
108120
ProgressHUDAppearance.HudTextColor = UIColor.Purple;
109121
ProgressHUDAppearance.HudButtonTextColor = UIColor.Orange;
110-
ProgressHUDAppearance.HudCornerRadius = 2;
122+
ProgressHUDAppearance.HudCornerRadius = 16;
111123
ProgressHUDAppearance.HudTextAlignment = UITextAlignment.Left;
112124
ProgressHUDAppearance.HudTextColor = UIColor.Cyan;
113125
ProgressHUDAppearance.HudToastBackgroundColor = UIColor.Blue;
@@ -188,6 +200,7 @@ public MainViewModel()
188200

189201
CommandItem Create(string text, Action action, bool timedKill) => new CommandItem(
190202
text,
203+
colors[Random.Shared.Next(colors.Length)],
191204
new Command(() =>
192205
{
193206
try
@@ -224,6 +237,7 @@ void KillAfter()
224237

225238
public record CommandItem(
226239
string Text,
240+
Color Color,
227241
ICommand Command
228242
);
229243
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ control the following options:
8989

9090
- Corner Radius
9191
- Background Color
92+
- Background Visual Effect (overrides background color)
93+
- Border Thickness
94+
- Border Color
9295
- Image Tint Color
9396
- Text Font
9497
- Button Font

0 commit comments

Comments
 (0)