-
Notifications
You must be signed in to change notification settings - Fork 315
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
Paywalls Components Packages and Selected State #4249
Open
jamesrb1
wants to merge
142
commits into
main
Choose a base branch
from
paywalls-components/packages
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Conflicts: # Sources/Paywalls/Components/PaywallComponentBases.swift
So that an outter package group can read the value of an inner package group.
jamesrb1
commented
Sep 13, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PurchaseButton is a stand-in for now (it doesn't work, obviously). But it does know what package it is meant to purchase.
jamesrb1
changed the title
[WIP] Paywalls Components Packages and Selected State
Paywalls Components Packages and Selected State
Sep 13, 2024
aboedo
reviewed
Sep 13, 2024
Tests/TestingApps/PaywallsTester/PaywallsTester/Config/SamplePaywalls.swift
Outdated
Show resolved
Hide resolved
Tests/TestingApps/PaywallsTester/PaywallsTester/Config/SamplePaywalls.swift
Outdated
Show resolved
Hide resolved
Tests/TestingApps/PaywallsTester/PaywallsTester/Config/SamplePaywalls.swift
Outdated
Show resolved
Hide resolved
Tests/TestingApps/PaywallsTester/PaywallsTester/Config/SamplePaywalls.swift
Outdated
Show resolved
Hide resolved
Tests/TestingApps/PaywallsTester/PaywallsTester/Config/SamplePaywalls.swift
Outdated
Show resolved
Hide resolved
Tests/TestingApps/PaywallsTester/PaywallsTester/Config/SamplePaywalls.swift
Outdated
Show resolved
Hide resolved
More work here needed in this area at some point.
vegaro
added
feat:Paywall Components
pr:RevenueCatUI
pr:RevenueCatUI
and removed
Paywalls Components
labels
Sep 17, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces package components and the ability for components to have a selected state. They are together because users select a package.
Selection
Models
Components now have an optional property of their own type, eg
TextComponent
now has a propertywhich is a duplicate of the component, but with different properties to visually represent the selected state.
The model classes are
class
objects so that they can hold recursive self-references, and madefinal
for concurrency.ViewModels
View model properties are now functions, where the accessor (ie the view) requests the property based on selection state, eg:
where
Views
Views now have an environment variable,
@Environment(\.selectionState) var selectionState
, which they use to read their selection state. An example of how it's used:You may wonder if we would be better off adding
selectionState
directly to the view model, so that the view did not need to repeatedly pass in this state. The reason we don't do this is because SwiftUI is designed to handle transient view state like selection directly in the view itself. A good common example of this is the state that holds if a sheet should be presented. By keeping this type of state in the view, the viewmodel is simplified by being stateless (to this sort of state), and able to concern itself solely with the preparation of business logic for display. The view decides which business logic to present.Packages
There are two new components here: PackageGroupComponent and PackageComponent.
Package:
These are the individual buttons representing a particular package that the user can select to purchase.
PackageComponent
Comes with a
packageID
, and a list of other components which are used to construct its visual appearance.PackageComponentViewModel
When the PackageComponentViewModel is created, it validates that the package is available from the Offering. If not, it throws, and the paywall cannot be displayed (it displays a fallback paywall instead). This is the same system as is done for localization.
PackageComponentView
The view is typically a
Button
, where the action sets the selected package ID, and the label is its list of components:It can also be created as a non-button (by showing the components directly), for use when the package is to be selected in a manner other than tapping on it (such as in a carousel).
It determines the
selectionState
for the components displayed in its label by comparing its package's ID to the currently selected one:PackageGroup:
The purpose of the Package Group is associate a group of packages together for selection purposes (where selecting one will unselect the others), to hold the value of the currently selected package, and to associate a Purchase Button with a package for purchase. It has no visual appearance.
PackageGroupComponent
Comes with a
defaultSelectedPackageID
and list of components to displayPackageGroupComponentViewModel
Nothing of specific note here.
PackageGroupComponentView
This holds a reference to a
PackageSelectionManager
, which which holds the value of the currently selected packageID, and which it passes down through the environment.