Skip to content

Commit 5b89bcb

Browse files
authored
Update code snippets for new paywall to exclude displayCloseButton parameter (#1041)
* Update code snippets for new paywall to exclude displayCloseButton parameter * Rename * Fix * Fix
1 parent 088c207 commit 5b89bcb

12 files changed

+96
-13
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import SwiftUI
2+
3+
import RevenueCat
4+
import RevenueCatUI
5+
6+
struct App: View {
7+
@State
8+
var displayPaywall = false
9+
10+
var body: some View {
11+
ContentView()
12+
.sheet(isPresented: self.$displayPaywall) {
13+
PaywallView()
14+
}
15+
}
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'package:purchases_ui_flutter/purchases_ui_flutter.dart';
2+
3+
// Note: Avoid placing PaywallView inside a modal or bottom sheet (e.g., using showModalBottomSheet).
4+
// Instead, include it directly in your widget.
5+
@override
6+
Widget build(BuildContext context) {
7+
return Scaffold(
8+
body: SafeArea(
9+
child: Center(
10+
child: PaywallView(
11+
offering: offering, // Optional Offering object obtained through getOfferings
12+
displayCloseButton: true,
13+
onRestoreCompleted: (CustomerInfo customerInfo) {
14+
// Optional listener. Called when a restore has been completed.
15+
// This may be called even if no entitlements have been granted.
16+
}
17+
onDismiss: () {
18+
// Dismiss the paywall, i.e. remove the view, navigate to another screen, etc.
19+
// Will be called when the close button is pressed (if enabled) or when a purchase succeeds.
20+
},
21+
),
22+
),
23+
),
24+
);
25+
}

code_blocks/tools/paywalls_flutter_2.dart renamed to code_blocks/tools/paywalls_flutter_2_new.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ Widget build(BuildContext context) {
2121
),
2222
),
2323
);
24-
}
24+
}

code_blocks/tools/paywalls_kmp_1.kts renamed to code_blocks/tools/paywalls_kmp_1_legacy.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ val options = remember {
44
}
55
}
66

7-
Paywall(options)
7+
Paywall(options)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
val options = remember {
2+
PaywallOptions(dismissRequest = { TODO("Handle dismiss") })
3+
}
4+
5+
Paywall(options)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import { View } from 'react-native';
3+
4+
import RevenueCatUI from 'react-native-purchases-ui';
5+
6+
// Display current offering
7+
return (
8+
<View style={{ flex: 1 }}>
9+
<RevenueCatUI.Paywall
10+
options={{ displayCloseButton: true }}
11+
onDismiss={() => {
12+
// Dismiss the paywall, i.e. remove the view, navigate to another screen, etc.
13+
// Will be called when the close button is pressed (if enabled) or when a purchase succeeds.
14+
}}
15+
/>
16+
</View>
17+
);
18+
19+
// If you need to display a specific offering:
20+
return (
21+
<View style={{ flex: 1 }}>
22+
<RevenueCatUI.Paywall
23+
options={{
24+
offering: offering, // Optional Offering object obtained through getOfferings
25+
displayCloseButton: true
26+
}}
27+
onRestoreCompleted={({customerInfo}: { customerInfo: CustomerInfo }) => {
28+
// Optional listener. Called when a restore has been completed.
29+
// This may be called even if no entitlements have been granted.
30+
}
31+
onDismiss={() => {
32+
// Dismiss the paywall, i.e. remove the view, navigate to another screen, etc.
33+
// Will be called when the close button is pressed (if enabled) or when a purchase succeeds.
34+
}}
35+
/>
36+
</View>
37+
);

code_blocks/tools/paywalls_rn_2.ts.txt renamed to code_blocks/tools/paywalls_rn_2_new.ts.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ return (
3232
}}
3333
/>
3434
</View>
35-
);
35+
);

docs/playbooks/guides/freemium.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import swiftui from "@site/code_blocks/tools/paywalls_1.swift?raw";
7878
import kotlin from "@site/code_blocks/tools/paywalls_1.kt?raw";
7979
import react from "@site/code_blocks/tools/paywalls_rn_1.ts.txt?raw";
8080
import flutter from "@site/code_blocks/tools/paywalls_flutter_1.dart?raw";
81-
import kmp from "@site/code_blocks/tools/paywalls_kmp_1.kts?raw";
81+
import kmp from "@site/code_blocks/tools/paywalls_kmp_1_new.kts?raw";
8282

8383
<RCCodeBlock
8484
tabs={[

docs/playbooks/guides/hard-paywall.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Given that you want to block any user's access to your app features if they have
6161
import swiftui from "@site/code_blocks/tools/paywalls_9.swift?raw";
6262
import kotlin from "@site/code_blocks/tools/paywalls_7.kt?raw";
6363
import react from "@site/code_blocks/tools/paywalls_rn_7.ts.txt?raw";
64-
import flutter from "@site/code_blocks/tools/paywalls_flutter_2.dart?raw";
64+
import flutter from "@site/code_blocks/tools/paywalls_flutter_2_new.dart?raw";
6565
import kmp from "@site/code_blocks/tools/paywalls_kmp_3.kts?raw";
6666

6767
<RCCodeBlock

0 commit comments

Comments
 (0)