Grayed button when disabled

This commit is contained in:
Lumaa 2024-01-24 19:40:14 +01:00
parent f36ce5ff96
commit 447fe8263b
2 changed files with 12 additions and 3 deletions

View File

@ -5,6 +5,15 @@ import SwiftUI
struct LargeButton: ButtonStyle {
var filled: Bool = false
var height: CGFloat? = nil
var disabled: Bool = false
private var fillColor: Color {
if disabled {
Color.gray
} else {
Color(uiColor: UIColor.label)
}
}
func makeBody(configuration: Configuration) -> some View {
configuration.label
@ -12,7 +21,7 @@ struct LargeButton: ButtonStyle {
.padding(.vertical, height)
.background {
if filled {
Color(uiColor: UIColor.label)
fillColor
}
}
.foregroundStyle(filled ? Color(uiColor: UIColor.systemBackground) : Color(uiColor: UIColor.label))

View File

@ -37,7 +37,7 @@ struct PostingView: View {
VStack(alignment: .leading) {
// MARK: Status main content
VStack(alignment: .leading, spacing: 10) {
Text(accountManager.forceAccount().username)
Text("@\(accountManager.forceAccount().username)")
.multilineTextAlignment(.leading)
.bold()
@ -116,7 +116,7 @@ struct PostingView: View {
}
}
.disabled(postingStatus || viewModel.postText.length <= 0)
.buttonStyle(LargeButton(filled: true, height: 7.5))
.buttonStyle(LargeButton(filled: true, height: 7.5, disabled: postingStatus || viewModel.postText.length <= 0))
}
.padding()
}