Basic Setup
Setting up the react-native-paywall library is simple and straightforward. Follow the steps below to get started with integrating the PaywallComponent in your React Native application.
Initializing usePaywall
To use the PaywallComponent, start by importing and initializing the usePaywall hook. This hook provides all the necessary methods to display and manage your paywalls.
Try the Demo
You can experiment with the react-native-paywall component directly in the browser:
Example: A Simple Paywall
Here's a basic example of integrating the react-native-paywall into a simple app:
import React from 'react';
import { View, Button } from 'react-native';
import { usePaywall } from 'react-native-paywall';
const App = () => {
// Initialize the usePaywall hook
const { showPaywall, hidePaywall, PaywallComponent } = usePaywall();
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
{/* Button to trigger the paywall */}
<Button title="Show Paywall" onPress={() => showPaywall('istanbul')} />
{/* Render the paywall component */}
<PaywallComponent
onContinue={(selectedIndex) => {
console.log(`User continued with plan index: ${selectedIndex}`);
hidePaywall(); // Hide the paywall after selection
}}
headerText="Ignite your child's curiosity"
descriptionText="Get access to all our educational content trusted by thousands of parents"
buttonText="Subscribe Now"
products={[
{
identifier: '$rc_monthly',
product: {
title: 'Monthly Plan',
priceString: '$4.99',
},
},
{
identifier: '$rc_annual',
product: {
title: 'Annual Plan',
priceString: '$39.99',
},
},
]}
backgroundColor="#f0f0f0"
buttonBgColor="#008CBA"
buttonTextColor="#FFFFFF"
/>
</View>
);
};
export default App;
Step-by-Step Explanation
-
Import the Hook and Component
Import theusePaywallhook andPaywallComponentfrom the library. -
Initialize
usePaywall
Call theusePaywallhook to access the following methods:showPaywall: Display the paywall with a specific type (e.g.,'istanbul').hidePaywall: Hide the currently displayed paywall.PaywallComponent: The UI component for the paywall.
-
Trigger the Paywall
Use theshowPaywallmethod to display the paywall. Pass a unique type (e.g.,'istanbul') to differentiate between multiple paywalls. -
Customize the Component
Pass props toPaywallComponentto configure the paywall:- Content Props:
headerText,descriptionText,buttonText, andproducts. - Styling Props:
backgroundColor,buttonBgColor,buttonTextColor.
- Content Props:
-
Handle User Actions
UseonContinueto handle the user's selection andhidePaywallto close the paywall.