Skip to content

Commit

Permalink
Allow customization of ProgressHUD through ProgressHUDAppearance
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheesebaron committed May 13, 2024
1 parent 4ecc282 commit 6d58d5a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 38 deletions.
3 changes: 0 additions & 3 deletions BTProgressHUD/BTProgressHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public static void Dismiss()
public static bool IsVisible
=> ProgressHUD.ForDefaultWindow()?.IsVisible ?? false;




public static void Show(UIWindow forWindow, string? status = null, float progress = -1, MaskType maskType = MaskType.None)
{
ProgressHUD.For(forWindow)?.Show(status, progress, maskType);
Expand Down
49 changes: 16 additions & 33 deletions BTProgressHUD/ProgressHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public sealed class ProgressHUD : UIView

private static readonly NSObject obj = new();

private UIImage? _errorImage;
private UIImage? _successImage;
private UIImage? _infoImage;
private UIImage? _errorOutlineImage;
private UIImage? _successOutlineImage;
private UIImage? _infoOutlineImage;
private UIImage? _errorOutlineFullImage;
private UIImage? _successOutlineFullImage;
private UIImage? _infoOutlineFullImage;
private UIImage? _errorImage = ProgressHUDAppearance.ErrorImage;
private UIImage? _successImage = ProgressHUDAppearance.SuccessImage;
private UIImage? _infoImage = ProgressHUDAppearance.InfoImage;
private UIImage? _errorOutlineImage = ProgressHUDAppearance.ErrorOutlineImage;
private UIImage? _successOutlineImage = ProgressHUDAppearance.SuccessOutlineImage;
private UIImage? _infoOutlineImage = ProgressHUDAppearance.InfoOutlineImage;
private UIImage? _errorOutlineFullImage = ProgressHUDAppearance.ErrorOutlineFullImage;
private UIImage? _successOutlineFullImage = ProgressHUDAppearance.SuccessOutlineFullImage;
private UIImage? _infoOutlineFullImage = ProgressHUDAppearance.InfoOutlineFullImage;

private MaskType _maskType;
private NSTimer? _fadeoutTimer;
Expand Down Expand Up @@ -100,20 +100,17 @@ public ProgressHUD(UIWindow window) : base(window.Bounds)
BackgroundColor = UIColor.Clear;
Alpha = 0;
AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

SetOSSpecificLookAndFeel();
}

public UIWindow HudWindow { get; private set; }

public static CGRect KeyboardSize { get; private set; } = CGRect.Empty;

public UIColor HudBackgroundColour { get; set; } = UIColor.FromWhiteAlpha(0.0f, 0.8f);
public UIColor HudForegroundColor { get; set; } = UIColor.White;
public UIColor HudStatusShadowColor { get; set; } = UIColor.Black;
public UIColor HudToastBackgroundColor { get; set; } = UIColor.Clear;
public UIFont HudFont { get; set; } = UIFont.BoldSystemFontOfSize(16f);
public UITextAlignment HudTextAlignment { get; set; } = UITextAlignment.Center;
public UIColor HudBackgroundColour { get; set; } = ProgressHUDAppearance.HudBackgroundColour;
public UIColor HudForegroundColor { get; set; } = ProgressHUDAppearance.HudForegroundColor;
public UIColor HudToastBackgroundColor { get; set; } = ProgressHUDAppearance.HudToastBackgroundColor;
public UIFont HudFont { get; set; } = ProgressHUDAppearance.HudFont;
public UITextAlignment HudTextAlignment { get; set; } = ProgressHUDAppearance.HudTextAlignment;
public Ring Ring { get; } = new();

public UIImage ErrorImage
Expand Down Expand Up @@ -216,8 +213,8 @@ public UIImage InfoOutlineFullImage
return For(window);
}

public float RingRadius { get; set; } = 14f;
public float RingThickness { get; set; } = 6f;
public float RingRadius { get; set; } = ProgressHUDAppearance.RingRadius;
public float RingThickness { get; set; } = ProgressHUDAppearance.RingThickness;

CAShapeLayer RingLayer
{
Expand Down Expand Up @@ -379,20 +376,6 @@ UIActivityIndicatorView SpinnerView
}
}

private void SetOSSpecificLookAndFeel()
{
HudBackgroundColour =
(System.OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13))
? UIColor.SystemBackground.ColorWithAlpha(0.8f) : UIColor.White.ColorWithAlpha(0.8f);
HudForegroundColor =
(System.OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13))
? UIColor.Label.ColorWithAlpha(0.8f) : UIColor.FromWhiteAlpha(0.0f, 0.8f);
HudStatusShadowColor =
(System.OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13))
? UIColor.Label.ColorWithAlpha(0.8f) : UIColor.FromWhiteAlpha(200f / 255f, 0.8f);
RingThickness = 1f;
}

public void Show(string? status = null, float progress = -1, MaskType maskType = MaskType.None, double timeoutMs = 1000)
{
obj.InvokeOnMainThread(() => ShowProgressWorker(progress, status, maskType, timeoutMs: timeoutMs));
Expand Down
43 changes: 43 additions & 0 deletions BTProgressHUD/ProgressHUDAppearance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using UIKit;

namespace BigTed;

public static class ProgressHUDAppearance
{
public static UIColor DefaultHudBackgroundColour { get; } =
OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ?
UIColor.SystemBackground.ColorWithAlpha(0.8f) :
UIColor.White.ColorWithAlpha(0.8f);

public static UIColor DefaultHudForegroundColor { get; } =
OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ?
UIColor.Label.ColorWithAlpha(0.8f) :
UIColor.FromWhiteAlpha(0.0f, 0.8f);

public static UIColor DefaultHudToastBackgroundColor { get; } = UIColor.Clear;
public static UIFont DefaultHudFont { get; } = UIFont.BoldSystemFontOfSize(16f);
public static UITextAlignment DefaultHudTextAlignment { get; } = UITextAlignment.Center;
public const float DefaultRingRadius = 14f;
public const float DefaultRingThickness = 1f;

public static float RingRadius { get; set; } = DefaultRingRadius;
public static float RingThickness { get; set; } = DefaultRingThickness;


public static UIColor HudBackgroundColour { get; set; } = DefaultHudBackgroundColour;
public static UIColor HudForegroundColor { get; set; } = DefaultHudForegroundColor;
public static UIColor HudToastBackgroundColor { get; set; } = DefaultHudToastBackgroundColor;
public static UIFont HudFont { get; set; } = DefaultHudFont;
public static UITextAlignment HudTextAlignment { get; set; } = DefaultHudTextAlignment;

public static UIImage? ErrorImage { get; set; }
public static UIImage? SuccessImage { get; set; }
public static UIImage? InfoImage { get; set; }
public static UIImage? ErrorOutlineImage { get; set; }
public static UIImage? SuccessOutlineImage { get; set; }
public static UIImage? InfoOutlineImage { get; set; }
public static UIImage? ErrorOutlineFullImage { get; set; }
public static UIImage? SuccessOutlineFullImage { get; set; }
public static UIImage? InfoOutlineFullImage { get; set; }
}
9 changes: 7 additions & 2 deletions BTProgressHUDDemo/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace BTProgressHUDDemo2;
using BigTed;
using UIKit;

namespace BTProgressHUDDemo2;

public static class MauiProgram
{
Expand All @@ -14,7 +17,9 @@ public static MauiApp CreateMauiApp()
});

#if IOS || MACCATALYST
BigTed.ProgressHUD.Initialize();
ProgressHUD.Initialize();
ProgressHUDAppearance.HudFont = UIFont.PreferredHeadline;
ProgressHUDAppearance.HudForegroundColor = UIColor.Purple;
#endif

return builder.Build();
Expand Down

0 comments on commit 6d58d5a

Please sign in to comment.