damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit f2fe02032ed1debdc1101095ea9abd832a520281
parent da2bdad18d1ddc3f2bde40dcb16aca6677fd681c
Author: ericholguin <eric.holguinsanchez@gmail.com>
Date:   Fri,  8 Dec 2023 21:57:25 -0700

refactor: add customizable properties to neutral button style

Closes: https://github.com/damus-io/damus/pull/1805
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Components/NeutralButtonStyle.swift | 62++++++++++++++++++++++++++++++++++++++++++--------------------
Mdamus/Views/ProfileActionSheetView.swift | 9++++-----
2 files changed, 46 insertions(+), 25 deletions(-)

diff --git a/damus/Components/NeutralButtonStyle.swift b/damus/Components/NeutralButtonStyle.swift @@ -7,37 +7,49 @@ import SwiftUI -struct NeutralButtonStyle: ButtonStyle { - func makeBody(configuration: Self.Configuration) -> some View { - return configuration.label - .background(DamusColors.neutral1) - .cornerRadius(12) - .overlay( - RoundedRectangle(cornerRadius: 12) - .stroke(DamusColors.neutral3, lineWidth: 1) - ) - .scaleEffect(configuration.isPressed ? 0.95 : 1) +enum NeutralButtonShape { + case rounded, capsule, circle + + var style: NeutralButtonStyle { + switch self { + case .rounded: + return NeutralButtonStyle(padding: EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10), cornerRadius: 12) + case .capsule: + return NeutralButtonStyle(padding: EdgeInsets(top: 5, leading: 15, bottom: 5, trailing: 15), cornerRadius: 20) + case .circle: + return NeutralButtonStyle(padding: EdgeInsets(top: 20, leading: 20, bottom: 20, trailing: 20), cornerRadius: 9999) + } } } -struct NeutralCircleButtonStyle: ButtonStyle { - func makeBody(configuration: Self.Configuration) -> some View { - return configuration.label - .padding(20) +struct NeutralButtonStyle: ButtonStyle { + let padding: EdgeInsets + let cornerRadius: CGFloat + let scaleEffect: CGFloat + + init(padding: EdgeInsets = EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0), cornerRadius: CGFloat = 15, scaleEffect: CGFloat = 0.95) { + self.padding = padding + self.cornerRadius = cornerRadius + self.scaleEffect = scaleEffect + } + + func makeBody(configuration: Configuration) -> some View { + configuration.label + .padding(padding) .background(DamusColors.neutral1) - .cornerRadius(9999) + .cornerRadius(cornerRadius) .overlay( - RoundedRectangle(cornerRadius: 9999) + RoundedRectangle(cornerRadius: cornerRadius) .stroke(DamusColors.neutral3, lineWidth: 1) ) - .scaleEffect(configuration.isPressed ? 0.95 : 1) + .scaleEffect(configuration.isPressed ? scaleEffect : 1) } } - struct NeutralButtonStyle_Previews: PreviewProvider { static var previews: some View { VStack { + Button(action: { print("dynamic size") }) { @@ -45,8 +57,7 @@ struct NeutralButtonStyle_Previews: PreviewProvider { .padding() } .buttonStyle(NeutralButtonStyle()) - - + Button(action: { print("infinite width") }) { @@ -58,6 +69,17 @@ struct NeutralButtonStyle_Previews: PreviewProvider { } .buttonStyle(NeutralButtonStyle()) .padding() + + Button("Rounded Button", action: {}) + .buttonStyle(NeutralButtonShape.rounded.style) + .padding() + + Button("Capsule Button", action: {}) + .buttonStyle(NeutralButtonShape.capsule.style) + .padding() + + Button(action: {}, label: {Image("messages")}) + .buttonStyle(NeutralButtonShape.circle.style) } } } diff --git a/damus/Views/ProfileActionSheetView.swift b/damus/Views/ProfileActionSheetView.swift @@ -58,7 +58,7 @@ struct ProfileActionSheetView: View { .profile_button_style(scheme: colorScheme) } ) - .buttonStyle(NeutralCircleButtonStyle()) + .buttonStyle(NeutralButtonShape.circle.style) Text(NSLocalizedString("Message", comment: "Button label that allows the user to start a direct message conversation with the user shown on-screen")) .foregroundStyle(.secondary) .font(.caption) @@ -121,8 +121,7 @@ struct ProfileActionSheetView: View { } ) - - .buttonStyle(NeutralCircleButtonStyle()) + .buttonStyle(NeutralButtonShape.circle.style) } .padding() .padding(.top, 20) @@ -165,7 +164,7 @@ fileprivate struct ProfileActionSheetFollowButton: View { } ) - .buttonStyle(NeutralCircleButtonStyle()) + .buttonStyle(NeutralButtonShape.circle.style) Text(verbatim: "\(follow_btn_txt(follow_state, follows_you: follows_you))") .foregroundStyle(.secondary) @@ -292,7 +291,7 @@ fileprivate struct ProfileActionSheetZapButton: View { return true } }()) - .buttonStyle(NeutralCircleButtonStyle()) + .buttonStyle(NeutralButtonShape.circle.style) Text(button_label) .foregroundStyle(.secondary)