@umituz/react-native-subscription 2.27.59 → 2.27.61
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.27.
|
|
3
|
+
"version": "2.27.61",
|
|
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",
|
|
@@ -97,5 +97,10 @@ export interface DeductCreditsResult {
|
|
|
97
97
|
|
|
98
98
|
export const DEFAULT_CREDITS_CONFIG: CreditsConfig = {
|
|
99
99
|
collectionName: "user_credits",
|
|
100
|
-
creditLimit:
|
|
100
|
+
creditLimit: 10,
|
|
101
|
+
packageAllocations: {
|
|
102
|
+
weekly: { credits: 10 },
|
|
103
|
+
monthly: { credits: 25 },
|
|
104
|
+
yearly: { credits: 200 },
|
|
105
|
+
},
|
|
101
106
|
};
|
|
@@ -6,6 +6,7 @@ export * from "./useDeductCredit";
|
|
|
6
6
|
export * from "./useFeatureGate";
|
|
7
7
|
export * from "./usePaywallVisibility";
|
|
8
8
|
export * from "./usePremium";
|
|
9
|
+
export * from "./usePremiumGate";
|
|
9
10
|
export * from "./useSubscriptionSettingsConfig";
|
|
10
11
|
export * from "./useSubscriptionStatus";
|
|
11
12
|
export * from "./feedback/usePaywallFeedback";
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* usePremiumGate Hook
|
|
3
|
+
*
|
|
4
|
+
* Simplified hook for premium-only apps (no credit system).
|
|
5
|
+
* Provides screen-level and action-level premium gates.
|
|
6
|
+
*
|
|
7
|
+
* @example Screen-Level Gate
|
|
8
|
+
* ```tsx
|
|
9
|
+
* const { isPremium, requireScreen } = usePremiumGate();
|
|
10
|
+
*
|
|
11
|
+
* useEffect(() => {
|
|
12
|
+
* requireScreen(); // Auto-opens paywall if not premium
|
|
13
|
+
* }, [requireScreen]);
|
|
14
|
+
*
|
|
15
|
+
* if (!isPremium) return null;
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example Action-Level Gate
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const { requirePremium } = usePremiumGate();
|
|
21
|
+
*
|
|
22
|
+
* const handleAction = () => {
|
|
23
|
+
* requirePremium(() => {
|
|
24
|
+
* // Action code here
|
|
25
|
+
* });
|
|
26
|
+
* };
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { useCallback, useEffect } from "react";
|
|
31
|
+
import { useSubscriptionStatus } from "./useSubscriptionStatus";
|
|
32
|
+
import { paywallControl } from "./usePaywallVisibility";
|
|
33
|
+
|
|
34
|
+
export interface UsePremiumGateResult {
|
|
35
|
+
/** Whether user has premium access */
|
|
36
|
+
isPremium: boolean;
|
|
37
|
+
/** Whether subscription status is loading */
|
|
38
|
+
isLoading: boolean;
|
|
39
|
+
/** Action-level gate: runs callback only if user has premium */
|
|
40
|
+
requirePremium: (onSuccess: () => void) => void;
|
|
41
|
+
/** Screen-level gate: opens paywall if not premium */
|
|
42
|
+
requireScreen: () => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const usePremiumGate = (): UsePremiumGateResult => {
|
|
46
|
+
const { isPremium, isLoading } = useSubscriptionStatus();
|
|
47
|
+
|
|
48
|
+
const requirePremium = useCallback(
|
|
49
|
+
(onSuccess: () => void) => {
|
|
50
|
+
if (isLoading) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (isPremium) {
|
|
55
|
+
onSuccess();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
paywallControl.open();
|
|
60
|
+
},
|
|
61
|
+
[isPremium, isLoading]
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const requireScreen = useCallback(() => {
|
|
65
|
+
if (!isLoading && !isPremium) {
|
|
66
|
+
paywallControl.open();
|
|
67
|
+
}
|
|
68
|
+
}, [isPremium, isLoading]);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
isPremium,
|
|
72
|
+
isLoading,
|
|
73
|
+
requirePremium,
|
|
74
|
+
requireScreen,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* useSubscription Hook (Alias for usePremiumGate)
|
|
80
|
+
*
|
|
81
|
+
* Simpler name for premium-only apps.
|
|
82
|
+
* Same functionality as usePremiumGate.
|
|
83
|
+
*/
|
|
84
|
+
export const useSubscription = usePremiumGate;
|