@umituz/react-native-subscription 2.17.12 → 2.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-subscription",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.1",
|
|
4
4
|
"description": "Complete subscription management with RevenueCat, paywall UI, and credits system for React Native apps",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -13,17 +13,19 @@ import { usePaywallActions } from "../hooks/usePaywallActions";
|
|
|
13
13
|
import type { PaywallContainerProps } from "./PaywallContainer.types";
|
|
14
14
|
|
|
15
15
|
export const PaywallContainer: React.FC<PaywallContainerProps> = (props) => {
|
|
16
|
-
const { userId, isAnonymous = false, translations, mode = "subscription", legalUrls, features, heroImage, bestValueIdentifier, creditsLabel, creditAmounts, packageFilterConfig, source
|
|
16
|
+
const { userId, isAnonymous = false, translations, mode = "subscription", legalUrls, features, heroImage, bestValueIdentifier, creditsLabel, creditAmounts, packageFilterConfig, source, onPurchaseSuccess, onPurchaseError, onAuthRequired, visible, onClose } = props;
|
|
17
17
|
|
|
18
|
-
const { showPaywall, closePaywall } = usePaywallVisibility();
|
|
18
|
+
const { showPaywall, closePaywall, currentSource } = usePaywallVisibility();
|
|
19
19
|
const isVisible = visible ?? showPaywall;
|
|
20
20
|
const handleClose = onClose ?? closePaywall;
|
|
21
21
|
|
|
22
|
+
const purchaseSource = source ?? currentSource ?? "settings";
|
|
23
|
+
|
|
22
24
|
const { data: allPackages = [], isLoading } = useSubscriptionPackages(userId ?? undefined);
|
|
23
25
|
const { handlePurchase, handleRestore } = usePaywallActions({
|
|
24
26
|
userId: userId ?? undefined,
|
|
25
27
|
isAnonymous,
|
|
26
|
-
source,
|
|
28
|
+
source: purchaseSource,
|
|
27
29
|
onPurchaseSuccess,
|
|
28
30
|
onPurchaseError,
|
|
29
31
|
onAuthRequired,
|
|
@@ -5,10 +5,16 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { useCallback, useSyncExternalStore } from "react";
|
|
8
|
+
import type { PurchaseSource } from "../../domain/entities/Credits";
|
|
8
9
|
|
|
9
10
|
type Listener = () => void;
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
interface PaywallState {
|
|
13
|
+
visible: boolean;
|
|
14
|
+
source?: PurchaseSource;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let paywallState: PaywallState = { visible: false, source: undefined };
|
|
12
18
|
const listeners = new Set<Listener>();
|
|
13
19
|
|
|
14
20
|
const subscribe = (listener: Listener): (() => void) => {
|
|
@@ -16,10 +22,10 @@ const subscribe = (listener: Listener): (() => void) => {
|
|
|
16
22
|
return () => listeners.delete(listener);
|
|
17
23
|
};
|
|
18
24
|
|
|
19
|
-
const getSnapshot = ():
|
|
25
|
+
const getSnapshot = (): PaywallState => paywallState;
|
|
20
26
|
|
|
21
|
-
const
|
|
22
|
-
|
|
27
|
+
const setPaywallState = (visible: boolean, source?: PurchaseSource): void => {
|
|
28
|
+
paywallState = { visible, source };
|
|
23
29
|
listeners.forEach((listener) => listener());
|
|
24
30
|
};
|
|
25
31
|
|
|
@@ -27,35 +33,38 @@ const setPaywallVisible = (visible: boolean): void => {
|
|
|
27
33
|
* Direct paywall control for non-React contexts (e.g., appInitializer)
|
|
28
34
|
*/
|
|
29
35
|
export const paywallControl = {
|
|
30
|
-
open: () =>
|
|
31
|
-
close: () =>
|
|
32
|
-
isOpen: () =>
|
|
36
|
+
open: (source?: PurchaseSource) => setPaywallState(true, source),
|
|
37
|
+
close: () => setPaywallState(false, undefined),
|
|
38
|
+
isOpen: () => paywallState.visible,
|
|
39
|
+
getSource: () => paywallState.source,
|
|
33
40
|
};
|
|
34
41
|
|
|
35
42
|
export interface UsePaywallVisibilityResult {
|
|
36
43
|
showPaywall: boolean;
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
currentSource?: PurchaseSource;
|
|
45
|
+
setShowPaywall: (visible: boolean, source?: PurchaseSource) => void;
|
|
46
|
+
openPaywall: (source?: PurchaseSource) => void;
|
|
39
47
|
closePaywall: () => void;
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
export function usePaywallVisibility(): UsePaywallVisibilityResult {
|
|
43
|
-
const
|
|
51
|
+
const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
44
52
|
|
|
45
|
-
const setShowPaywall = useCallback((visible: boolean) => {
|
|
46
|
-
|
|
53
|
+
const setShowPaywall = useCallback((visible: boolean, source?: PurchaseSource) => {
|
|
54
|
+
setPaywallState(visible, source);
|
|
47
55
|
}, []);
|
|
48
56
|
|
|
49
|
-
const openPaywall = useCallback(() => {
|
|
50
|
-
|
|
57
|
+
const openPaywall = useCallback((source?: PurchaseSource) => {
|
|
58
|
+
setPaywallState(true, source);
|
|
51
59
|
}, []);
|
|
52
60
|
|
|
53
61
|
const closePaywall = useCallback(() => {
|
|
54
|
-
|
|
62
|
+
setPaywallState(false, undefined);
|
|
55
63
|
}, []);
|
|
56
64
|
|
|
57
65
|
return {
|
|
58
|
-
showPaywall,
|
|
66
|
+
showPaywall: state.visible,
|
|
67
|
+
currentSource: state.source,
|
|
59
68
|
setShowPaywall,
|
|
60
69
|
openPaywall,
|
|
61
70
|
closePaywall,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Package-driven: all logic handled internally
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { useMemo } from "react";
|
|
7
|
+
import { useMemo, useCallback } from "react";
|
|
8
8
|
import { useCredits } from "./useCredits";
|
|
9
9
|
import { useSubscriptionStatus } from "./useSubscriptionStatus";
|
|
10
10
|
import { useCustomerInfo } from "../../revenuecat/presentation/hooks/useCustomerInfo";
|
|
@@ -55,6 +55,10 @@ export const useSubscriptionSettingsConfig = (
|
|
|
55
55
|
const { customerInfo } = useCustomerInfo();
|
|
56
56
|
const { openPaywall } = usePaywallVisibility();
|
|
57
57
|
|
|
58
|
+
const handleOpenPaywall = useCallback(() => {
|
|
59
|
+
openPaywall("settings");
|
|
60
|
+
}, [openPaywall]);
|
|
61
|
+
|
|
58
62
|
// RevenueCat entitlement info - dynamically using configured entitlementId
|
|
59
63
|
const entitlementId = SubscriptionManager.getEntitlementId() || "premium";
|
|
60
64
|
const premiumEntitlement = customerInfo?.entitlements.active[entitlementId];
|
|
@@ -137,7 +141,7 @@ export const useSubscriptionSettingsConfig = (
|
|
|
137
141
|
? translations.statusActive
|
|
138
142
|
: translations.statusFree,
|
|
139
143
|
icon: "diamond",
|
|
140
|
-
onPress:
|
|
144
|
+
onPress: handleOpenPaywall,
|
|
141
145
|
},
|
|
142
146
|
sectionConfig: {
|
|
143
147
|
statusType,
|
|
@@ -163,7 +167,7 @@ export const useSubscriptionSettingsConfig = (
|
|
|
163
167
|
manageButton: translations.manageButton,
|
|
164
168
|
upgradeButton: translations.upgradeButton,
|
|
165
169
|
},
|
|
166
|
-
onUpgrade:
|
|
170
|
+
onUpgrade: handleOpenPaywall,
|
|
167
171
|
upgradePrompt,
|
|
168
172
|
},
|
|
169
173
|
}),
|
|
@@ -177,7 +181,7 @@ export const useSubscriptionSettingsConfig = (
|
|
|
177
181
|
daysRemaining,
|
|
178
182
|
willRenew,
|
|
179
183
|
creditsArray,
|
|
180
|
-
|
|
184
|
+
handleOpenPaywall,
|
|
181
185
|
upgradePrompt,
|
|
182
186
|
]
|
|
183
187
|
);
|