Skip to content

Commit

Permalink
[Button-557] Merge to main
Browse files Browse the repository at this point in the history
  • Loading branch information
robergro committed Jan 18, 2024
1 parent 6c2f2d8 commit 55f1cc9
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ struct ButtonContainerView<ContainerView: View, ViewModel: ButtonMainViewModel &
@ScaledMetric private var borderRadius: CGFloat
private let padding: EdgeInsets?

@State private var isPressed: Bool = false

private let action: () -> Void

// MARK: - Components
Expand Down Expand Up @@ -52,7 +54,7 @@ struct ButtonContainerView<ContainerView: View, ViewModel: ButtonMainViewModel &
self.contentView()
}
.buttonStyle(PressedButtonStyle(
viewModel: self.viewModel
isPressed: self.$isPressed
))
.padding(self.padding)
.frame(height: self.height)
Expand All @@ -67,6 +69,9 @@ struct ButtonContainerView<ContainerView: View, ViewModel: ButtonMainViewModel &
.disabled(self.viewModel.state?.isUserInteractionEnabled == false)
.opacity(self.viewModel.state?.opacity ?? .zero)
.accessibilityIdentifier(ButtonAccessibilityIdentifier.button)
.onChange(of: self.isPressed) { isPressed in
self.viewModel.setIsPressed(isPressed)
}
}
}

Expand Down Expand Up @@ -97,21 +102,3 @@ private extension View {
))
}
}

// MARK: - Style

private struct PressedButtonStyle<ViewModel: ButtonMainViewModel & ButtonMainSUIViewModel>: ButtonStyle {

// MARK: - Properties

let viewModel: ViewModel

// MARK: - View

func makeBody(configuration: Configuration) -> some View {
configuration.label
.onChange(of: configuration.isPressed) { value in
self.viewModel.setIsPressed(value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public struct ButtonView: View {
return self
}

/// Set the switch to selected.
/// Set the button to selected.
/// - Parameters:
/// - text: The switch is selected or not.
/// - Returns: Current Button View.
Expand Down
3 changes: 2 additions & 1 deletion spark/Demo/Classes/Enum/UIComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation


struct UIComponent: RawRepresentable, CaseIterable, Equatable {
static var allCases: [UIComponent] = [.badge, .button, .checkbox, .chip, .icon, .progressBarIndeterminate, .progressBarSingle, .radioButton, .ratingDisplay, .ratingInput, .spinner, .star, .switchButton, .tab, .tag, .textField]
static var allCases: [UIComponent] = [.badge, .button, .iconButton, .checkbox, .chip, .icon, .progressBarIndeterminate, .progressBarSingle, .radioButton, .ratingDisplay, .ratingInput, .spinner, .star, .switchButton, .tab, .tag, .textField]

var rawValue: String

Expand All @@ -19,6 +19,7 @@ struct UIComponent: RawRepresentable, CaseIterable, Equatable {
static let checkbox = UIComponent(rawValue: "Checkbox")
static let chip = UIComponent(rawValue: "Chip")
static let icon = UIComponent(rawValue: "Icon")
static let iconButton = UIComponent(rawValue: "Icon Button")
static let progressBarIndeterminate = UIComponent(rawValue: "Progress Bar Indeterminate")
static let progressBarSingle = UIComponent(rawValue: "Progress Bar Single")
static let radioButton = UIComponent(rawValue: "Radio Button")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ struct ButtonComponentView: View {
)

EnumSelector(
title: "Content (selectec state)",
dialogTitle: "Select a selectec content",
title: "Content (selected state)",
dialogTitle: "Select a selected content",
values: ButtonContentDefault.allCases,
value: self.$contentSelected
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ struct IconButtonComponentView: View {
)

EnumSelector(
title: "Content (selectec state)",
dialogTitle: "Select a selectec content",
title: "Content (selected state)",
dialogTitle: "Select a selected content",
values: IconButtonContentDefault.allCases,
value: self.$contentSelected
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class IconButtonComponentViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "Button"
self.navigationItem.title = "Icon Button"
addPublisher()
}

Expand Down
18 changes: 8 additions & 10 deletions spark/Demo/Classes/View/ListView/Cells/ButtonCell/ButtonCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ final class ButtonCell: UITableViewCell, Configurable {
variant: .filled,
size: .medium,
shape: .rounded,
alignment: .leadingIcon,
text: "Button",
isEnabled: true
alignment: .leadingImage
)
return view
}()
Expand Down Expand Up @@ -65,14 +63,14 @@ final class ButtonCell: UITableViewCell, Configurable {

switch configuration.content {
case .text:
self.component.text = "Button"
self.component.iconImage = nil
case .iconAndText:
self.component.text = "Hello World"
self.component.iconImage = UIImage(systemName: "book.circle")
self.component.setTitle("Button", for: .normal)
self.component.setImage(nil, for: .normal)
case .imageAndText:
self.component.setTitle("Hello World", for: .normal)
self.component.setImage(UIImage(systemName: "book.circle"), for: .normal)
case .attributedText:
self.component.attributedText = self.attributeString
self.component.iconImage = nil
self.component.setAttributedTitle(self.attributeString, for: .normal)
self.component.setImage(nil, for: .normal)
default:
break
}
Expand Down
6 changes: 3 additions & 3 deletions spark/Demo/Classes/View/ListView/ListViewDatasource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ extension ListViewDataSource {

/// Button
func createButtonConfigurations() -> [ButtonConfiguration] {
[ButtonConfiguration(theme: SparkTheme.shared, intent: .main, variant: .filled, size: .medium, shape: .rounded, alignment: .leadingIcon, content: .text, isEnabled: false),
ButtonConfiguration(theme: SparkTheme.shared, intent: .basic, variant: .outlined, size: .large, shape: .square, alignment: .trailingIcon, content: .iconAndText, isEnabled: true),
ButtonConfiguration(theme: SparkTheme.shared, intent: .success, variant: .ghost, size: .small, shape: .pill, alignment: .leadingIcon, content: .attributedText, isEnabled: true)
[ButtonConfiguration(theme: SparkTheme.shared, intent: .main, variant: .filled, size: .medium, shape: .rounded, alignment: .leadingImage, content: .text, isEnabled: false),
ButtonConfiguration(theme: SparkTheme.shared, intent: .basic, variant: .outlined, size: .large, shape: .square, alignment: .trailingImage, content: .imageAndText, isEnabled: true),
ButtonConfiguration(theme: SparkTheme.shared, intent: .success, variant: .ghost, size: .small, shape: .pill, alignment: .leadingImage, content: .attributedText, isEnabled: true)
]
}

Expand Down

0 comments on commit 55f1cc9

Please sign in to comment.