-
Notifications
You must be signed in to change notification settings - Fork 84
/
index.js
70 lines (60 loc) · 2.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* @file Paywall Screen.
* @author Vadim Savin
*/
import React, { useEffect, useState } from 'react';
import { View, Text, FlatList, Alert } from 'react-native';
import Purchases from 'react-native-purchases';
import { PackageItem } from '../../components';
import styles from './styles.js';
/*
An example paywall that uses the current offering.
*/
const PaywallScreen = () => {
// - State for all available package
const [packages, setPackages] = useState([]);
// - State for displaying an overlay view
const [isPurchasing, setIsPurchasing] = useState(false);
useEffect(() => {
// Get current available packages
const getPackages = async () => {
try {
const offerings = await Purchases.getOfferings();
if (offerings.current !== null && offerings.current.availablePackages.length !== 0) {
setPackages(offerings.current.availablePackages);
}
} catch (e) {
Alert.alert('Error getting offers', e.message);
}
};
getPackages();
}, []);
const header = () => <Text style={styles.text}>Magic Weather Premium</Text>;
const footer = () => {
console.warn(
"Modify this value to reflect your app's Privacy Policy and Terms & Conditions agreements. Required to make it through App Review.",
);
return (
<Text style={styles.text}>
Don't forget to add your subscription terms and conditions. Read more about this here:
https://www.revenuecat.com/blog/schedule-2-section-3-8-b
</Text>
);
};
return (
<View style={styles.page}>
{/* The paywall flat list displaying each package */}
<FlatList
data={packages}
renderItem={({ item }) => <PackageItem purchasePackage={item} setIsPurchasing={setIsPurchasing} />}
keyExtractor={(item) => item.identifier}
ListHeaderComponent={header}
ListHeaderComponentStyle={styles.headerFooterContainer}
ListFooterComponent={footer}
ListFooterComponentStyle={styles.headerFooterContainer}
/>
{isPurchasing && <View style={styles.overlay} />}
</View>
);
};
export default PaywallScreen;