From 90c22fdabd3d066c82272564822361039a4fea31 Mon Sep 17 00:00:00 2001 From: ericholguin Date: Fri, 26 May 2023 13:56:54 -0600 Subject: [PATCH] components: added reusable gradient button style --- damus.xcodeproj/project.pbxproj | 3 ++ damus/Components/GradientButtonStyle.swift | 45 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 damus/Components/GradientButtonStyle.swift diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj index 7bac2f87..0ef54e25 100644 --- a/damus.xcodeproj/project.pbxproj +++ b/damus.xcodeproj/project.pbxproj @@ -278,6 +278,7 @@ 5C42E78C29DB76D90086AAC1 /* EmptyUserSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C42E78B29DB76D90086AAC1 /* EmptyUserSearchView.swift */; }; 5C513FBA297F72980072348F /* CustomPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C513FB9297F72980072348F /* CustomPicker.swift */; }; 5C513FCC2984ACA60072348F /* QRCodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C513FCB2984ACA60072348F /* QRCodeView.swift */; }; + 5C6E1DAD2A193EC2008FC15A /* GradientButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C6E1DAC2A193EC2008FC15A /* GradientButtonStyle.swift */; }; 5C6E1DAF2A194075008FC15A /* PinkGradient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C6E1DAE2A194075008FC15A /* PinkGradient.swift */; }; 5CF72FC229B9142F00124A13 /* ShareAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CF72FC129B9142F00124A13 /* ShareAction.swift */; }; 6439E014296790CF0020672B /* ProfilePicImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6439E013296790CF0020672B /* ProfilePicImageView.swift */; }; @@ -724,6 +725,7 @@ 5C42E78B29DB76D90086AAC1 /* EmptyUserSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyUserSearchView.swift; sourceTree = ""; }; 5C513FB9297F72980072348F /* CustomPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomPicker.swift; sourceTree = ""; }; 5C513FCB2984ACA60072348F /* QRCodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeView.swift; sourceTree = ""; }; + 5C6E1DAC2A193EC2008FC15A /* GradientButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientButtonStyle.swift; sourceTree = ""; }; 5C6E1DAE2A194075008FC15A /* PinkGradient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PinkGradient.swift; sourceTree = ""; }; 5CF72FC129B9142F00124A13 /* ShareAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareAction.swift; sourceTree = ""; }; 6439E013296790CF0020672B /* ProfilePicImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfilePicImageView.swift; sourceTree = ""; }; @@ -1841,6 +1843,7 @@ 4CF0ABD82981980C00D66079 /* Lists.swift in Sources */, 501F8C5829FF5FC5001AFC1D /* Damus.xcdatamodeld in Sources */, 4C30AC8029A6A53F00E2BD5A /* ProfilePicturesView.swift in Sources */, + 5C6E1DAD2A193EC2008FC15A /* GradientButtonStyle.swift in Sources */, 4C8EC52529D1FA6C0085D9A8 /* DamusColors.swift in Sources */, 4C5C7E6A284EDE2E00A22DF5 /* SearchResultsView.swift in Sources */, 4CE1399429F0669900AC6A0B /* BigButton.swift in Sources */, diff --git a/damus/Components/GradientButtonStyle.swift b/damus/Components/GradientButtonStyle.swift new file mode 100644 index 00000000..55fd6b0e --- /dev/null +++ b/damus/Components/GradientButtonStyle.swift @@ -0,0 +1,45 @@ +// +// GradientButtonStyle.swift +// damus +// +// Created by eric on 5/20/23. +// + +import SwiftUI + +struct GradientButtonStyle: ButtonStyle { + func makeBody(configuration: Self.Configuration) -> some View { + return configuration.label + .padding() + .foregroundColor(Color.white) + .background { + RoundedRectangle(cornerRadius: 12) + .fill(PinkGradient.gradient) + } + .scaleEffect(configuration.isPressed ? 0.8 : 1) + } +} + + +struct GradientButtonStyle_Previews: PreviewProvider { + static var previews: some View { + VStack { + Button("Dynamic Size", action: { + print("dynamic size") + }) + .buttonStyle(GradientButtonStyle()) + + + Button(action: { + print("infinite width") + }) { + HStack { + Text("Infinite Width") + } + .frame(minWidth: 300, maxWidth: .infinity, alignment: .center) + } + .buttonStyle(GradientButtonStyle()) + .padding() + } + } +}