-
Notifications
You must be signed in to change notification settings - Fork 34
PW-73 | Add docs for custom variables #1355
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
Draft
RosieWatson
wants to merge
1
commit into
main
Choose a base branch
from
rosie/pw-73-update-docs
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.
+198
−2
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import androidx.compose.runtime.Composable | ||
| import com.revenuecat.purchases.CustomerInfo | ||
| import com.revenuecat.purchases.ui.revenuecatui.PaywallDialog | ||
| import com.revenuecat.purchases.ui.revenuecatui.PaywallOptions | ||
| import com.revenuecat.purchases.ui.revenuecatui.data.processed.CustomVariableValue | ||
|
|
||
| @Composable | ||
| fun PaywallWithCustomVariables( | ||
| customerInfo: CustomerInfo, | ||
| onDismiss: () -> Unit | ||
| ) { | ||
| val options = PaywallOptions.Builder { /* dismiss */ } | ||
| .setCustomVariables( | ||
| mapOf( | ||
| "player_name" to CustomVariableValue.String("John"), | ||
| "level" to CustomVariableValue.String("42") | ||
| ) | ||
| ) | ||
| .build() | ||
|
|
||
| PaywallDialog( | ||
| options = options, | ||
| shouldDisplayBlock = { !customerInfo.entitlements.active.containsKey("pro") } | ||
| ) | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import SwiftUI | ||
| import RevenueCat | ||
| import RevenueCatUI | ||
|
|
||
| struct App: View { | ||
| @State | ||
| var displayPaywall = false | ||
|
|
||
| var body: some View { | ||
| ContentView() | ||
| .sheet(isPresented: self.$displayPaywall) { | ||
| PaywallView() | ||
| .customPaywallVariables([ | ||
| "player_name": .string("John"), | ||
| "level": .string("42") | ||
| ]) | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import com.revenuecat.purchases.CustomerInfo | ||
| import com.revenuecat.purchases.Offering | ||
| import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallActivityLauncher | ||
| import com.revenuecat.purchases.ui.revenuecatui.data.processed.CustomVariableValue | ||
|
|
||
| class MyActivity : ComponentActivity() { | ||
| private val paywallActivityLauncher = PaywallActivityLauncher(this) | ||
|
|
||
| fun showPaywall(offering: Offering) { | ||
| paywallActivityLauncher.launch( | ||
| offering = offering, | ||
| customVariables = mapOf( | ||
| "player_name" to CustomVariableValue.String("John"), | ||
| "level" to CustomVariableValue.String("42") | ||
| ) | ||
| ) | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import UIKit | ||
| import RevenueCat | ||
| import RevenueCatUI | ||
|
|
||
| class MyViewController: UIViewController { | ||
| func showPaywall() { | ||
| let controller = PaywallViewController() | ||
|
|
||
| // Set custom variables | ||
| controller.setCustomVariable(.string("John"), forKey: "player_name") | ||
| controller.setCustomVariable(.string("42"), forKey: "level") | ||
|
|
||
| self.present(controller, animated: true) | ||
| } | ||
| } | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import 'package:purchases_ui_flutter/purchases_ui_flutter.dart'; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| body: SafeArea( | ||
| child: Center( | ||
| child: PaywallView( | ||
| offering: offering, // Optional Offering object obtained through getOfferings | ||
| customVariables: { | ||
| "player_name": "John", | ||
| "level": "42" | ||
| }, | ||
| onDismiss: () { | ||
| // Dismiss the paywall, i.e. remove the view, navigate to another screen, etc. | ||
| // Will be called when the close button is pressed (if enabled) or when a purchase succeeds. | ||
| }, | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import React from 'react'; | ||
| import { View } from 'react-native'; | ||
|
|
||
| import RevenueCatUI from 'react-native-purchases-ui'; | ||
|
|
||
| return ( | ||
| <View style={{ flex: 1 }}> | ||
| <RevenueCatUI.Paywall | ||
| options={{ | ||
| offering: offering, // Optional Offering object obtained through getOfferings | ||
| customVariables: { | ||
| player_name: "John", | ||
| level: "42" | ||
| } | ||
| }} | ||
| onDismiss={() => { | ||
| // Dismiss the paywall, i.e. remove the view, navigate to another screen, etc. | ||
| // Will be called when the close button is pressed (if enabled) or when a purchase succeeds. | ||
| }} | ||
| /> | ||
| </View> | ||
| ); |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
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
setCustomVariablemethod takes a plainString, not aCustomVariableValue. This example will not compile.Option 1 - Using the property (preferred for Swift):
Option 2 - Using the ObjC-compatible method (takes plain String):