Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Models the Action for the ButtonComponent #4353

Merged
merged 27 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8324986
Adds scaffolding for the ButtonComponent.
JayShortway Oct 3, 2024
4200f5e
ButtonComponent uses the correct type.
JayShortway Oct 3, 2024
13c48c6
Adds an empty preview
JayShortway Oct 3, 2024
95fe157
Buttons contain text!
JayShortway Oct 4, 2024
0bfe862
First pass of the button Action enum, and some click handling.
JayShortway Oct 4, 2024
857fad6
Removes EmptyView.
JayShortway Oct 4, 2024
62b33f7
Buttons are stacks now
JayShortway Oct 4, 2024
310bee9
Merge branch 'main' into paywalls-components/button-component-1
JayShortway Oct 4, 2024
c388b8b
Merge branch 'paywalls-components/button-component-1' into paywalls-c…
JayShortway Oct 4, 2024
a5e4fa9
removes deeplink method
JayShortway Oct 4, 2024
bd8ae50
Removes oopsie from bad merge
JayShortway Oct 7, 2024
b29d263
Uses swiftlint:disable:next
JayShortway Oct 7, 2024
64a27d6
Adds deepLink URLMethod.
JayShortway Oct 7, 2024
93316d7
Adds privacyPolicy and terms cases to Destination enum.
JayShortway Oct 7, 2024
5aacf0d
Changes url properties to urlLid.
JayShortway Oct 7, 2024
26fbb79
Merge branch 'main' into paywalls-components/button-component-1
JayShortway Oct 7, 2024
0e93154
Merge branch 'paywalls-components/button-component-1' into paywalls-c…
JayShortway Oct 7, 2024
393590a
Makes ButtonComponentViewModel public for PaywallsTester
JayShortway Oct 7, 2024
c0f4f73
Merge branch 'main' into paywalls-components/button-component-1
JayShortway Oct 7, 2024
4f849b0
Merge branch 'paywalls-components/button-component-1' into paywalls-c…
JayShortway Oct 7, 2024
0d0d15c
Merge branch 'main' into paywalls-components/button-component-1
JayShortway Oct 8, 2024
dd0f48c
Merge branch 'paywalls-components/button-component-1' into paywalls-c…
JayShortway Oct 8, 2024
de4d515
Merge branch 'main' into paywalls-components/button-component-1
JayShortway Oct 9, 2024
f38e654
Merge branch 'paywalls-components/button-component-1' into paywalls-c…
JayShortway Oct 9, 2024
c2774d7
Merge branch 'main' into paywalls-components/button-component-1
JayShortway Oct 11, 2024
5f28f27
Merge branch 'paywalls-components/button-component-1' into paywalls-c…
JayShortway Oct 11, 2024
eafda3f
Merge branch 'main' into paywalls-components/button-component-2
JayShortway Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
}
Comment on lines +42 to +45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned this in a PR further down the chain but I would probably name this to performAction()since it could be a click or a tap 😇 Just a nit of mine 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, great point. I'll rename it in the other PR, since this function is moved in that PR as well.


}

#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