Skip to content

Commit

Permalink
Models the Action for the ButtonComponent (#4353)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayShortway authored Oct 14, 2024
1 parent c980764 commit 2d0e236
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ struct ButtonComponentView: View {
}

var body: some View {
StackComponentView(viewModel: viewModel.stackViewModel)
Button(
action: { viewModel.onClick() },
label: { StackComponentView(viewModel: viewModel.stackViewModel) }
)
}

}
Expand All @@ -43,6 +46,7 @@ struct ButtonComponentView_Previews: PreviewProvider {
// swiftlint:disable:next force_try
viewModel: try! .init(
component: .init(
action: .navigateBack,
stack: .init(
components: [
PaywallComponent.text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class ButtonComponentViewModel {
)
}

func onClick() {
// swiftlint:disable:next todo
// TODO Handle the configured Action.
}

}

#endif
25 changes: 25 additions & 0 deletions Sources/Paywalls/Components/PaywallButtonComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,38 @@ public extension PaywallComponent {

struct ButtonComponent: PaywallComponentBase {

// swiftlint:disable:next nesting
public enum Action: Codable, Sendable, Hashable, Equatable {
case restorePurchases
case navigateTo(destination: Destination)
case navigateBack
}

// swiftlint:disable:next nesting
public enum Destination: Codable, Sendable, Hashable, Equatable {
case customerCenter
case URL(urlLid: String, method: URLMethod)
case privacyPolicy(urlLid: String, method: URLMethod)
case terms(urlLid: String, method: URLMethod)
}

// swiftlint:disable:next nesting
public enum URLMethod: Codable, Sendable, Hashable, Equatable {
case inAppBrowser
case externalBrowser
case deepLink
}

let type: ComponentType
public let action: Action
public let stack: PaywallComponent.StackComponent

public init(
action: Action,
stack: PaywallComponent.StackComponent
) {
self.type = .button
self.action = action
self.stack = stack
}

Expand Down

0 comments on commit 2d0e236

Please sign in to comment.