Skip to content

Commit b31c4ca

Browse files
authored
Merge pull request #114 from acaliaro/main
feat: add activity indicator scale
2 parents 94e8267 + 91066ee commit b31c4ca

File tree

4 files changed

+35
-25
lines changed

4 files changed

+35
-25
lines changed

BTProgressHUD.sln

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29209.62
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.11.35327.3
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BTProgressHUD", "BTProgressHUD\BTProgressHUD.csproj", "{8ECDFDC5-42D0-4540-9691-830EEB2ED874}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BTProgressHUD", "BTProgressHUD\BTProgressHUD.csproj", "{8ECDFDC5-42D0-4540-9691-830EEB2ED874}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{519BA8F9-8A37-4096-BCCB-A66EE0DAA697}"
99
ProjectSection(SolutionItems) = preProject
@@ -13,12 +13,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
1313
EndProject
1414
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{CCCB766D-95A7-4FCE-81BE-F9A8F1B3589B}"
1515
ProjectSection(SolutionItems) = preProject
16+
build.cake = build.cake
1617
.github\workflows\build.yml = .github\workflows\build.yml
1718
.github\workflows\release-nuget.yml = .github\workflows\release-nuget.yml
18-
build.cake = build.cake
1919
EndProjectSection
2020
EndProject
21-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BTProgressHUDDemo", "BTProgressHUDDemo\BTProgressHUDDemo.csproj", "{E8BFFAAB-E4E7-4FD2-9B48-AC708EA2F38B}"
21+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BTProgressHUDDemo", "BTProgressHUDDemo\BTProgressHUDDemo.csproj", "{E8BFFAAB-E4E7-4FD2-9B48-AC708EA2F38B}"
2222
EndProject
2323
Global
2424
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -56,6 +56,7 @@ Global
5656
{E8BFFAAB-E4E7-4FD2-9B48-AC708EA2F38B}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
5757
{E8BFFAAB-E4E7-4FD2-9B48-AC708EA2F38B}.Debug|iPhone.ActiveCfg = Debug|Any CPU
5858
{E8BFFAAB-E4E7-4FD2-9B48-AC708EA2F38B}.Debug|iPhone.Build.0 = Debug|Any CPU
59+
{E8BFFAAB-E4E7-4FD2-9B48-AC708EA2F38B}.Debug|iPhone.Deploy.0 = Debug|Any CPU
5960
{E8BFFAAB-E4E7-4FD2-9B48-AC708EA2F38B}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
6061
{E8BFFAAB-E4E7-4FD2-9B48-AC708EA2F38B}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
6162
{E8BFFAAB-E4E7-4FD2-9B48-AC708EA2F38B}.Release|iPhone.ActiveCfg = Release|Any CPU
@@ -66,10 +67,10 @@ Global
6667
GlobalSection(SolutionProperties) = preSolution
6768
HideSolutionNode = FALSE
6869
EndGlobalSection
69-
GlobalSection(ExtensibilityGlobals) = postSolution
70-
SolutionGuid = {FF80CC4C-1CE6-457A-BA02-04A7F403B8A3}
71-
EndGlobalSection
7270
GlobalSection(NestedProjects) = preSolution
7371
{CCCB766D-95A7-4FCE-81BE-F9A8F1B3589B} = {519BA8F9-8A37-4096-BCCB-A66EE0DAA697}
7472
EndGlobalSection
73+
GlobalSection(ExtensibilityGlobals) = postSolution
74+
SolutionGuid = {FF80CC4C-1CE6-457A-BA02-04A7F403B8A3}
75+
EndGlobalSection
7576
EndGlobal

BTProgressHUD/ProgressHUD.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public sealed class ProgressHUD : UIView
5858
private CAShapeLayer? _ringLayer;
5959
private List<NSObject>? _eventListeners;
6060
private bool _displayContinuousImage;
61-
61+
6262
private ToastPosition _toastPosition = ToastPosition.Center;
6363

6464
public static void Initialize()
@@ -162,7 +162,7 @@ public UIImage InfoOutlineFullImage
162162

163163
public bool IsVisible => Alpha == 1;
164164

165-
static Dictionary<NativeHandle, ProgressHUD> windowHuds = new ();
165+
static Dictionary<NativeHandle, ProgressHUD> windowHuds = new();
166166

167167
public static ProgressHUD? For(UIWindow? window)
168168
{
@@ -205,7 +205,7 @@ public UIImage InfoOutlineFullImage
205205

206206
return For(window);
207207
}
208-
208+
209209
CAShapeLayer RingLayer
210210
{
211211
get
@@ -270,13 +270,13 @@ UIView HudView
270270
Translucent = true,
271271
BarTintColor = ProgressHUDAppearance.HudBackgroundColor,
272272
BackgroundColor = ProgressHUDAppearance.HudBackgroundColor
273-
};
273+
};
274274
}
275275

276276
hudView.AutoresizingMask =
277277
UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleTopMargin |
278278
UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleLeftMargin;
279-
279+
280280
hudView.Layer.CornerRadius = ProgressHUDAppearance.HudCornerRadius;
281281
hudView.Layer.MasksToBounds = true;
282282

@@ -302,7 +302,7 @@ UILabel StringLabel
302302
Font = ProgressHUDAppearance.HudFont,
303303
Lines = 0
304304
};
305-
305+
306306
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
307307
if (_stringLabel.Superview == null)
308308
{
@@ -327,7 +327,7 @@ UIButton CancelHudButton
327327
_cancelHud.SetTitleColor(ProgressHUDAppearance.HudButtonTextColor, UIControlState.Normal);
328328
UserInteractionEnabled = true;
329329
}
330-
330+
331331
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
332332
if (_cancelHud.Superview == null)
333333
{
@@ -371,10 +371,12 @@ UIActivityIndicatorView SpinnerView
371371
UIActivityIndicatorViewStyle.WhiteLarge)
372372
{
373373
HidesWhenStopped = true,
374-
Bounds = new CGRect(0, 0, 37, 37),
374+
Bounds = new CGRect(0, 0, 37, 37 ),
375375
Color = ProgressHUDAppearance.RingColor
376376
};
377377

378+
_spinnerView.Transform = CGAffineTransform.MakeScale(ProgressHUDAppearance.ActivityIndicatorScale, ProgressHUDAppearance.ActivityIndicatorScale);
379+
378380
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
379381
if (_spinnerView.Superview == null)
380382
HudView.AddSubview(_spinnerView);
@@ -583,7 +585,7 @@ private void ShowProgressWorker(
583585
OverlayView.Hidden = false;
584586
_toastPosition = toastPosition;
585587
PositionHUD(null);
586-
588+
587589
if (Alpha != 1)
588590
{
589591
RegisterNotifications();
@@ -833,8 +835,8 @@ private void PositionHUD(NSNotification? notification)
833835
var orientationFrame = activeWindowBounds.Value;
834836

835837
var activeHeight = GetActiveHeight(ignoreOrientation, orientation, orientationFrame, keyboardHeight);
836-
837-
float posY = MathF.Floor(activeHeight * 0.45f);
838+
839+
float posY = MathF.Floor(activeHeight * 0.45f);
838840
float posX = (float)orientationFrame.Size.Width / 2f;
839841
float textHeight = (float)StringLabel.Frame.Height / 2f + 40;
840842

@@ -844,7 +846,7 @@ private void PositionHUD(NSNotification? notification)
844846
ToastPosition.Top => textHeight,
845847
_ => posY
846848
};
847-
849+
848850
CGPoint newCenter;
849851
float rotateAngle;
850852

@@ -1073,7 +1075,7 @@ private float AdjustSizesForText(string? text, float hudHeight, bool imageUsed,
10731075
{
10741076
if (string.IsNullOrEmpty(text))
10751077
return hudHeight;
1076-
1078+
10771079
var lineCount = Math.Min(10, text!.Split('\n').Length + 1);
10781080

10791081
var stringSize = new NSString(text).GetBoundingRect(new CGSize(200, 30 * lineCount),

BTProgressHUD/ProgressHUDAppearance.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using UIKit;
33

44
namespace BigTed;
@@ -30,7 +30,8 @@ public static class ProgressHUDAppearance
3030
public const float DefaultRingThickness = 1f;
3131
public const float DefaultHudCornerRadius = 10f;
3232
public const double DefaultProgressUpdateInterval = 300;
33-
33+
public const float DefaultActivityIndicatorScale = 1f;
34+
3435
/// <summary>
3536
/// Get or set definite progress indicator ring radius to control its size
3637
/// </summary>
@@ -45,7 +46,12 @@ public static class ProgressHUDAppearance
4546
/// Get or set update interval for definite progress indicator ring animation
4647
/// </summary>
4748
public static double RingProgressUpdateInterval { get; set; } = DefaultProgressUpdateInterval;
48-
49+
50+
/// <summary>
51+
/// Get or set definite activity indicator scale to control its size
52+
/// </summary>
53+
public static float ActivityIndicatorScale { get; set; } = DefaultActivityIndicatorScale;
54+
4955
/// <summary>
5056
/// Get or set definite progress indicator ring foreground color
5157
/// </summary>

BTProgressHUDDemo/MainViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public MainViewModel()
1919
{
2020
BTProgressHUD.Dismiss();
2121
}, false),
22-
Create("Show", () => BTProgressHUD.Show(), true),
22+
Create("Show", () => { ProgressHUDAppearance.ActivityIndicatorScale = ProgressHUDAppearance.DefaultActivityIndicatorScale; BTProgressHUD.Show(); }, true),
23+
Create("Show with scaled activity indicator", () => { ProgressHUDAppearance.ActivityIndicatorScale = 2f; BTProgressHUD.Show(); }, true),
2324
Create("Cancel problem 3", () => BTProgressHUD.Show("Cancel", () => KillAfter(), "Cancel and text"), false),
2425
Create("Cancel problem 2", () => BTProgressHUD.Show("Cancel", () => KillAfter()), false),
2526
Create("Cancel problem", () => BTProgressHUD.Show("Cancel", () => KillAfter(), "This is a multilinetext\nSome more text\n more text\n and again more text"), false),

0 commit comments

Comments
 (0)