mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-19 11:43:24 +01:00
improve: add more capabilities to FilledButtonStyle
This commit is contained in:
@@ -10,15 +10,25 @@ import SwiftUI
|
|||||||
|
|
||||||
struct FilledButtonStyle: ButtonStyle {
|
struct FilledButtonStyle: ButtonStyle {
|
||||||
var isLoading: Bool = false
|
var isLoading: Bool = false
|
||||||
|
var hideLabelOnLoading: Bool = true
|
||||||
|
var tintColor: Color = .accentColor
|
||||||
|
|
||||||
func makeBody(configuration: Configuration) -> some View {
|
func makeBody(configuration: Configuration) -> some View {
|
||||||
ZStack {
|
HStack {
|
||||||
configuration.label
|
if !isLoading || !hideLabelOnLoading {
|
||||||
.opacity(isLoading ? 0 : 1)
|
configuration.label
|
||||||
|
}
|
||||||
|
|
||||||
if isLoading {
|
if isLoading {
|
||||||
ProgressView()
|
// We want to add padding to the left if we don't hide the label
|
||||||
.progressViewStyle(CircularProgressViewStyle())
|
if hideLabelOnLoading {
|
||||||
|
ProgressView()
|
||||||
|
.progressViewStyle(CircularProgressViewStyle())
|
||||||
|
} else {
|
||||||
|
ProgressView()
|
||||||
|
.progressViewStyle(CircularProgressViewStyle())
|
||||||
|
.padding([.leading], 2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.foregroundColor(.white)
|
.foregroundColor(.white)
|
||||||
@@ -27,10 +37,11 @@ struct FilledButtonStyle: ButtonStyle {
|
|||||||
.padding()
|
.padding()
|
||||||
.background(
|
.background(
|
||||||
RoundedRectangle(cornerRadius: 12)
|
RoundedRectangle(cornerRadius: 12)
|
||||||
.foregroundColor(.accentColor)
|
.foregroundColor(tintColor)
|
||||||
)
|
)
|
||||||
.opacity(configuration.isPressed || isLoading ? 0.7 : 1)
|
.opacity(configuration.isPressed || isLoading ? 0.7 : 1)
|
||||||
.disabled(isLoading)
|
.disabled(isLoading)
|
||||||
|
.enableInjection()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user