Skip to content

Commit

Permalink
style add indicator support
Browse files Browse the repository at this point in the history
  • Loading branch information
holysin committed Nov 21, 2023
1 parent 638f38f commit a28698b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
4 changes: 2 additions & 2 deletions AlertToast.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ Pod::Spec.new do |spec|
#

# spec.platform = :ios
spec.platforms = { :ios => "13.0", :osx => "11.0" }
spec.platforms = { :ios => "14.0", :osx => "11.0" }

# When using multiple platforms
# spec.ios.deployment_target = "13.0"
# spec.ios.deployment_target = "14.0"
# spec.osx.deployment_target = "11.0"
# spec.watchos.deployment_target = "2.0"
# spec.tvos.deployment_target = "9.0"
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import PackageDescription
let package = Package(
name: "AlertToast",
platforms: [
.iOS(.v13),
.iOS(.v14),
.macOS(.v11)
],
products: [
Expand Down
9 changes: 7 additions & 2 deletions Sources/AlertToast/ActivityIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import SwiftUI
#if os(macOS)
@available(macOS 11, *)
struct ActivityIndicator: NSViewRepresentable {


let color: Color

func makeNSView(context: NSViewRepresentableContext<ActivityIndicator>) -> NSProgressIndicator {
let nsView = NSProgressIndicator()

Expand All @@ -25,9 +27,11 @@ struct ActivityIndicator: NSViewRepresentable {
}
}
#else
@available(iOS 13, *)
@available(iOS 14, *)
struct ActivityIndicator: UIViewRepresentable {

let color: Color

func makeUIView(context: UIViewRepresentableContext<ActivityIndicator>) -> UIActivityIndicatorView {

let progressView = UIActivityIndicatorView(style: .large)
Expand All @@ -37,6 +41,7 @@ struct ActivityIndicator: UIViewRepresentable {
}

func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext<ActivityIndicator>) {
uiView.color = UIColor(color)
}
}
#endif
44 changes: 26 additions & 18 deletions Sources/AlertToast/AlertToast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import SwiftUI
import Combine

@available(iOS 13, macOS 11, *)
@available(iOS 14, macOS 11, *)
fileprivate struct AnimatedCheckmark: View {

///Checkmark color
Expand Down Expand Up @@ -46,7 +46,7 @@ fileprivate struct AnimatedCheckmark: View {
}
}

@available(iOS 13, macOS 11, *)
@available(iOS 14, macOS 11, *)
fileprivate struct AnimatedXmark: View {

///xmark color
Expand Down Expand Up @@ -88,7 +88,7 @@ fileprivate struct AnimatedXmark: View {

//MARK: - Main View

@available(iOS 13, macOS 11, *)
@available(iOS 14, macOS 11, *)
public struct AlertToast: View{

public enum BannerAnimation{
Expand Down Expand Up @@ -137,47 +137,55 @@ public struct AlertToast: View{
titleColor: Color? = nil,
subTitleColor: Color? = nil,
titleFont: Font? = nil,
subTitleFont: Font? = nil)
subTitleFont: Font? = nil,
activityIndicatorColor: Color? = nil)

///Get background color
var backgroundColor: Color? {
switch self{
case .style(backgroundColor: let color, _, _, _, _):
case .style(backgroundColor: let color, _, _, _, _, _):
return color
}
}

/// Get title color
var titleColor: Color? {
switch self{
case .style(_,let color, _,_,_):
case .style(_,let color, _,_,_,_):
return color
}
}

/// Get subTitle color
var subtitleColor: Color? {
switch self{
case .style(_,_, let color, _,_):
case .style(_,_, let color, _,_,_):
return color
}
}

/// Get title font
var titleFont: Font? {
switch self {
case .style(_, _, _, titleFont: let font, _):
case .style(_, _, _, titleFont: let font, _,_):
return font
}
}

/// Get subTitle font
var subTitleFont: Font? {
switch self {
case .style(_, _, _, _, subTitleFont: let font):
case .style(_, _, _, _, subTitleFont: let font,_):
return font
}
}

var activityIndicatorColor: Color? {
switch self {
case .style(_, _, _, _, _, let color):
return color
}
}
}

///The display mode
Expand Down Expand Up @@ -246,7 +254,7 @@ public struct AlertToast: View{
.renderingMode(.template)
.foregroundColor(color)
case .loading:
ActivityIndicator()
ActivityIndicator(color: style?.activityIndicatorColor ?? .white)
case .regular:
EmptyView()
}
Expand Down Expand Up @@ -292,7 +300,7 @@ public struct AlertToast: View{
.hudModifier()
.foregroundColor(color)
case .loading:
ActivityIndicator()
ActivityIndicator(color: style?.activityIndicatorColor ?? .white)
case .regular:
EmptyView()
}
Expand Down Expand Up @@ -359,7 +367,7 @@ public struct AlertToast: View{
.padding(.bottom)
Spacer()
case .loading:
ActivityIndicator()
ActivityIndicator(color: style?.activityIndicatorColor ?? .white)
case .regular:
EmptyView()
}
Expand Down Expand Up @@ -399,7 +407,7 @@ public struct AlertToast: View{
}
}

@available(iOS 13, macOS 11, *)
@available(iOS 14, macOS 11, *)
public struct AlertToastModifier: ViewModifier{

///Presentation `Binding<Bool>`
Expand Down Expand Up @@ -596,7 +604,7 @@ public struct AlertToastModifier: ViewModifier{
}

///Fileprivate View Modifier for dynamic frame when alert type is `.regular` / `.loading`
@available(iOS 13, macOS 11, *)
@available(iOS 14, macOS 11, *)
fileprivate struct WithFrameModifier: ViewModifier{

var withFrame: Bool
Expand All @@ -616,7 +624,7 @@ fileprivate struct WithFrameModifier: ViewModifier{
}

///Fileprivate View Modifier to change the alert background
@available(iOS 13, macOS 11, *)
@available(iOS 14, macOS 11, *)
fileprivate struct BackgroundModifier: ViewModifier{

var color: Color?
Expand All @@ -634,7 +642,7 @@ fileprivate struct BackgroundModifier: ViewModifier{
}

///Fileprivate View Modifier to change the text colors
@available(iOS 13, macOS 11, *)
@available(iOS 14, macOS 11, *)
fileprivate struct TextForegroundModifier: ViewModifier{

var color: Color?
Expand All @@ -650,7 +658,7 @@ fileprivate struct TextForegroundModifier: ViewModifier{
}
}

@available(iOS 13, macOS 11, *)
@available(iOS 14, macOS 11, *)
fileprivate extension Image{

func hudModifier() -> some View{
Expand All @@ -662,7 +670,7 @@ fileprivate extension Image{
}
}

//@available(iOS 13, macOS 11, *)
//@available(iOS 14, macOS 11, *)
public extension View{

/// Return some view w/o frame depends on the condition.
Expand Down
2 changes: 1 addition & 1 deletion Sources/AlertToast/BlurView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct BlurView: NSViewRepresentable {

#else

@available(iOS 13, *)
@available(iOS 14, *)
public struct BlurView: UIViewRepresentable {
public typealias UIViewType = UIVisualEffectView

Expand Down

0 comments on commit a28698b

Please sign in to comment.