@tryheliumai/paywall-sdk-react-native 0.1.3 → 0.1.5
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/lib/commonjs/native-interface.js +83 -23
- package/lib/commonjs/native-interface.js.map +1 -1
- package/lib/module/native-interface.js +83 -24
- package/lib/module/native-interface.js.map +1 -1
- package/lib/typescript/commonjs/src/native-interface.d.ts +6 -1
- package/lib/typescript/commonjs/src/native-interface.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types.d.ts +1 -0
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
- package/lib/typescript/module/src/native-interface.d.ts +6 -1
- package/lib/typescript/module/src/native-interface.d.ts.map +1 -1
- package/lib/typescript/module/src/types.d.ts +1 -0
- package/lib/typescript/module/src/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/native-interface.tsx +85 -28
- package/src/types.ts +1 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.presentUpsell = exports.initialize = exports.hideUpsell = exports.UpsellView = exports.HeliumProvider = exports.HELIUM_CTA_NAMES = void 0;
|
|
6
|
+
exports.useHelium = exports.presentUpsell = exports.initialize = exports.hideUpsell = exports.UpsellView = exports.HeliumProvider = exports.HELIUM_CTA_NAMES = void 0;
|
|
7
7
|
var _reactNative = require("react-native");
|
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -27,7 +27,24 @@ providerMountedPromise = new Promise(resolve => {
|
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
+
// Create a context for the download status
|
|
31
|
+
|
|
32
|
+
const HeliumContext = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
33
|
+
|
|
34
|
+
// Create a ref to store the context setter
|
|
35
|
+
let setDownloadStatusRef = null;
|
|
36
|
+
|
|
37
|
+
// Hook to use the Helium context
|
|
38
|
+
const useHelium = () => {
|
|
39
|
+
const context = (0, _react.useContext)(HeliumContext);
|
|
40
|
+
if (!context) {
|
|
41
|
+
throw new Error('useHelium must be used within a HeliumProvider');
|
|
42
|
+
}
|
|
43
|
+
return context;
|
|
44
|
+
};
|
|
45
|
+
|
|
30
46
|
// Move NativeHeliumUpsellView to a singleton pattern
|
|
47
|
+
exports.useHelium = useHelium;
|
|
31
48
|
let NativeHeliumUpsellView = null;
|
|
32
49
|
const getNativeHeliumUpsellView = () => {
|
|
33
50
|
if (!NativeHeliumUpsellView) {
|
|
@@ -37,21 +54,37 @@ const getNativeHeliumUpsellView = () => {
|
|
|
37
54
|
};
|
|
38
55
|
// Create a ref to store the fallback view reference
|
|
39
56
|
const fallbackRef = /*#__PURE__*/(0, _react.createRef)();
|
|
57
|
+
// Store a reference to the fallback view component
|
|
58
|
+
let FallbackViewComponent = null;
|
|
40
59
|
|
|
41
60
|
// Provider component to be rendered at the app root
|
|
42
61
|
const HeliumProvider = ({
|
|
43
62
|
children,
|
|
44
63
|
fallbackView: FallbackView
|
|
45
64
|
}) => {
|
|
65
|
+
// Add state for download status
|
|
66
|
+
const [downloadStatus, setDownloadStatus] = (0, _react.useState)('notStarted');
|
|
67
|
+
|
|
68
|
+
// Store the setter in the ref so it can be accessed outside of components
|
|
69
|
+
(0, _react.useEffect)(() => {
|
|
70
|
+
setDownloadStatusRef = setDownloadStatus;
|
|
71
|
+
// Store the fallback view component for later use
|
|
72
|
+
FallbackViewComponent = FallbackView;
|
|
73
|
+
}, [setDownloadStatus, FallbackView]);
|
|
46
74
|
(0, _react.useEffect)(() => {
|
|
47
75
|
isProviderMounted = true;
|
|
48
76
|
// Resolve the promise when the provider is mounted
|
|
49
77
|
resolveProviderMounted();
|
|
50
78
|
return () => {
|
|
51
79
|
isProviderMounted = false;
|
|
80
|
+
setDownloadStatusRef = null;
|
|
52
81
|
};
|
|
53
82
|
}, []);
|
|
54
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
|
83
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(HeliumContext.Provider, {
|
|
84
|
+
value: {
|
|
85
|
+
downloadStatus,
|
|
86
|
+
setDownloadStatus
|
|
87
|
+
},
|
|
55
88
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
56
89
|
ref: fallbackRef,
|
|
57
90
|
collapsable: false,
|
|
@@ -75,28 +108,21 @@ const initialize = async (heliumCallbacks, config = {}) => {
|
|
|
75
108
|
throw new Error('Failed to get fallback view reference. Make sure HeliumProvider is mounted with a fallback view.');
|
|
76
109
|
}
|
|
77
110
|
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
transactionId: event.transactionId,
|
|
83
|
-
status: status
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// Set up restore purchases event listener
|
|
88
|
-
heliumEventEmitter.addListener('helium_restore_purchases', async event => {
|
|
89
|
-
const success = await heliumCallbacks.restorePurchases();
|
|
90
|
-
HeliumBridge.handleRestoreResponse({
|
|
91
|
-
transactionId: event.transactionId,
|
|
92
|
-
status: success ? 'restored' : 'failed'
|
|
93
|
-
});
|
|
94
|
-
});
|
|
111
|
+
// Update download status to inProgress
|
|
112
|
+
if (setDownloadStatusRef) {
|
|
113
|
+
setDownloadStatusRef('inProgress');
|
|
114
|
+
}
|
|
95
115
|
|
|
96
|
-
// Set up
|
|
116
|
+
// Set up event listeners
|
|
97
117
|
heliumEventEmitter.addListener('helium_paywall_event', event => {
|
|
98
|
-
|
|
99
|
-
|
|
118
|
+
// Handle download status events
|
|
119
|
+
if (event.type === 'paywallsDownloadSuccess' && setDownloadStatusRef) {
|
|
120
|
+
setDownloadStatusRef('success');
|
|
121
|
+
} else if (event.type === 'paywallsDownloadError' && setDownloadStatusRef) {
|
|
122
|
+
setDownloadStatusRef('failed');
|
|
123
|
+
}
|
|
124
|
+
// Handle fallback view visibility
|
|
125
|
+
else if (event.type === 'paywallOpen' && event.paywallTemplateName === 'Fallback') {
|
|
100
126
|
if (fallbackRef.current) {
|
|
101
127
|
fallbackRef.current.setNativeProps({
|
|
102
128
|
style: {
|
|
@@ -105,7 +131,6 @@ const initialize = async (heliumCallbacks, config = {}) => {
|
|
|
105
131
|
});
|
|
106
132
|
}
|
|
107
133
|
} else if (event.type === 'paywallClose' && event.paywallTemplateName === 'Fallback') {
|
|
108
|
-
// Update fallback view visibility if the ref exists
|
|
109
134
|
if (fallbackRef.current) {
|
|
110
135
|
fallbackRef.current.setNativeProps({
|
|
111
136
|
style: {
|
|
@@ -114,9 +139,29 @@ const initialize = async (heliumCallbacks, config = {}) => {
|
|
|
114
139
|
});
|
|
115
140
|
}
|
|
116
141
|
}
|
|
142
|
+
|
|
143
|
+
// Forward all events to the callback
|
|
117
144
|
heliumCallbacks.onHeliumPaywallEvent(event);
|
|
118
145
|
});
|
|
119
146
|
|
|
147
|
+
// Set up purchase event listener
|
|
148
|
+
heliumEventEmitter.addListener('helium_make_purchase', async event => {
|
|
149
|
+
const status = await heliumCallbacks.makePurchase(event.productId);
|
|
150
|
+
HeliumBridge.handlePurchaseResponse({
|
|
151
|
+
transactionId: event.transactionId,
|
|
152
|
+
status: status
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Set up restore purchases event listener
|
|
157
|
+
heliumEventEmitter.addListener('helium_restore_purchases', async event => {
|
|
158
|
+
const success = await heliumCallbacks.restorePurchases();
|
|
159
|
+
HeliumBridge.handleRestoreResponse({
|
|
160
|
+
transactionId: event.transactionId,
|
|
161
|
+
status: success ? 'restored' : 'failed'
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
120
165
|
// Initialize the bridge with merged config
|
|
121
166
|
HeliumBridge.initialize({
|
|
122
167
|
apiKey: config.apiKey,
|
|
@@ -146,7 +191,22 @@ const UpsellView = ({
|
|
|
146
191
|
trigger,
|
|
147
192
|
style
|
|
148
193
|
}) => {
|
|
194
|
+
const {
|
|
195
|
+
downloadStatus
|
|
196
|
+
} = useHelium();
|
|
149
197
|
const NativeView = getNativeHeliumUpsellView();
|
|
198
|
+
|
|
199
|
+
// If download status is notStarted or inProgress, we haven't fully initialized yet
|
|
200
|
+
// In this case, we should render the fallback view
|
|
201
|
+
if (downloadStatus === 'notStarted' || downloadStatus === 'inProgress' || downloadStatus === 'failed') {
|
|
202
|
+
// If we have a fallback view component, render it
|
|
203
|
+
if (FallbackViewComponent) {
|
|
204
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(FallbackViewComponent, {});
|
|
205
|
+
}
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Otherwise, render the native view
|
|
150
210
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(NativeView, {
|
|
151
211
|
trigger: trigger,
|
|
152
212
|
style: [{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_react","_interopRequireWildcard","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","HeliumBridge","NativeModules","heliumEventEmitter","NativeEventEmitter","isProviderMounted","providerMountedPromise","resolveProviderMounted","Promise","resolve","NativeHeliumUpsellView","getNativeHeliumUpsellView","requireNativeComponent","fallbackRef","createRef","HeliumProvider","children","fallbackView","FallbackView","useEffect","jsxs","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_react","_interopRequireWildcard","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","HeliumBridge","NativeModules","heliumEventEmitter","NativeEventEmitter","isProviderMounted","providerMountedPromise","resolveProviderMounted","Promise","resolve","HeliumContext","createContext","undefined","setDownloadStatusRef","useHelium","context","useContext","Error","exports","NativeHeliumUpsellView","getNativeHeliumUpsellView","requireNativeComponent","fallbackRef","createRef","FallbackViewComponent","HeliumProvider","children","fallbackView","FallbackView","downloadStatus","setDownloadStatus","useState","useEffect","jsxs","Provider","value","jsx","View","ref","collapsable","style","display","initialize","heliumCallbacks","config","viewTag","findNodeHandle","current","addListener","event","type","paywallTemplateName","setNativeProps","onHeliumPaywallEvent","status","makePurchase","productId","handlePurchaseResponse","transactionId","success","restorePurchases","handleRestoreResponse","apiKey","fallbackPaywall","triggers","customUserId","customAPIEndpoint","customUserTraits","presentUpsell","triggerName","hideUpsell","UpsellView","trigger","NativeView","flex","HELIUM_CTA_NAMES","SCHEDULE_CALL","SUBSCRIBE_BUTTON"],"sourceRoot":"../../src","sources":["native-interface.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AAAyF,IAAAG,WAAA,GAAAH,OAAA;AAAA,SAAAI,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc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,CAAC;AAACnD,OAAA,CAAAkD,aAAA,GAAAA,aAAA;AAEK,MAAME,UAAU,GAAGA,CAAA,KAAM;EAC9BrE,YAAY,CAACqE,UAAU,CAAC,CAAC;AAC3B,CAAC;;AAED;AAAApD,OAAA,CAAAoD,UAAA,GAAAA,UAAA;AACO,MAAMC,UAA2C,GAAGA,CAAC;EAAEC,OAAO;EAAEhC;AAAM,CAAC,KAAK;EACjF,MAAM;IAAEX;EAAe,CAAC,GAAGf,SAAS,CAAC,CAAC;EACtC,MAAM2D,UAAU,GAAGrD,yBAAyB,CAAC,CAAC;;EAE9C;EACA;EACA,IAAIS,cAAc,KAAK,YAAY,IAAIA,cAAc,KAAK,YAAY,IAAIA,cAAc,KAAK,QAAQ,EAAE;IACrG;IACA,IAAIL,qBAAqB,EAAE;MACzB,oBAAO,IAAA5C,WAAA,CAAAwD,GAAA,EAACZ,qBAAqB,IAAE,CAAC;IAClC;IAEA,OAAO,IAAI;EACb;;EAEA;EACA,oBACE,IAAA5C,WAAA,CAAAwD,GAAA,EAACqC,UAAU;IACTD,OAAO,EAAEA,OAAQ;IACjBhC,KAAK,EAAE,CAAC;MAAEkC,IAAI,EAAE;IAAE,CAAC,EAAElC,KAAK;EAAE,CAC7B,CAAC;AAEN,CAAC;AAACtB,OAAA,CAAAqD,UAAA,GAAAA,UAAA;AAEK,MAAMI,gBAAgB,GAAAzD,OAAA,CAAAyD,gBAAA,GAAG;EAC9BC,aAAa,EAAE,eAAe;EAC9BC,gBAAgB,EAAE;AACpB,CAAC","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { findNodeHandle, NativeModules, View, NativeEventEmitter, requireNativeComponent } from 'react-native';
|
|
4
|
-
import React, { createRef, useEffect } from 'react';
|
|
5
|
-
import { jsx as _jsx,
|
|
4
|
+
import React, { createRef, useEffect, useState, createContext, useContext } from 'react';
|
|
5
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
6
|
const {
|
|
7
7
|
HeliumBridge
|
|
8
8
|
} = NativeModules;
|
|
@@ -21,6 +21,22 @@ providerMountedPromise = new Promise(resolve => {
|
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
+
// Create a context for the download status
|
|
25
|
+
|
|
26
|
+
const HeliumContext = /*#__PURE__*/createContext(undefined);
|
|
27
|
+
|
|
28
|
+
// Create a ref to store the context setter
|
|
29
|
+
let setDownloadStatusRef = null;
|
|
30
|
+
|
|
31
|
+
// Hook to use the Helium context
|
|
32
|
+
export const useHelium = () => {
|
|
33
|
+
const context = useContext(HeliumContext);
|
|
34
|
+
if (!context) {
|
|
35
|
+
throw new Error('useHelium must be used within a HeliumProvider');
|
|
36
|
+
}
|
|
37
|
+
return context;
|
|
38
|
+
};
|
|
39
|
+
|
|
24
40
|
// Move NativeHeliumUpsellView to a singleton pattern
|
|
25
41
|
let NativeHeliumUpsellView = null;
|
|
26
42
|
const getNativeHeliumUpsellView = () => {
|
|
@@ -31,21 +47,37 @@ const getNativeHeliumUpsellView = () => {
|
|
|
31
47
|
};
|
|
32
48
|
// Create a ref to store the fallback view reference
|
|
33
49
|
const fallbackRef = /*#__PURE__*/createRef();
|
|
50
|
+
// Store a reference to the fallback view component
|
|
51
|
+
let FallbackViewComponent = null;
|
|
34
52
|
|
|
35
53
|
// Provider component to be rendered at the app root
|
|
36
54
|
export const HeliumProvider = ({
|
|
37
55
|
children,
|
|
38
56
|
fallbackView: FallbackView
|
|
39
57
|
}) => {
|
|
58
|
+
// Add state for download status
|
|
59
|
+
const [downloadStatus, setDownloadStatus] = useState('notStarted');
|
|
60
|
+
|
|
61
|
+
// Store the setter in the ref so it can be accessed outside of components
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
setDownloadStatusRef = setDownloadStatus;
|
|
64
|
+
// Store the fallback view component for later use
|
|
65
|
+
FallbackViewComponent = FallbackView;
|
|
66
|
+
}, [setDownloadStatus, FallbackView]);
|
|
40
67
|
useEffect(() => {
|
|
41
68
|
isProviderMounted = true;
|
|
42
69
|
// Resolve the promise when the provider is mounted
|
|
43
70
|
resolveProviderMounted();
|
|
44
71
|
return () => {
|
|
45
72
|
isProviderMounted = false;
|
|
73
|
+
setDownloadStatusRef = null;
|
|
46
74
|
};
|
|
47
75
|
}, []);
|
|
48
|
-
return /*#__PURE__*/_jsxs(
|
|
76
|
+
return /*#__PURE__*/_jsxs(HeliumContext.Provider, {
|
|
77
|
+
value: {
|
|
78
|
+
downloadStatus,
|
|
79
|
+
setDownloadStatus
|
|
80
|
+
},
|
|
49
81
|
children: [/*#__PURE__*/_jsx(View, {
|
|
50
82
|
ref: fallbackRef,
|
|
51
83
|
collapsable: false,
|
|
@@ -68,28 +100,21 @@ export const initialize = async (heliumCallbacks, config = {}) => {
|
|
|
68
100
|
throw new Error('Failed to get fallback view reference. Make sure HeliumProvider is mounted with a fallback view.');
|
|
69
101
|
}
|
|
70
102
|
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
transactionId: event.transactionId,
|
|
76
|
-
status: status
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// Set up restore purchases event listener
|
|
81
|
-
heliumEventEmitter.addListener('helium_restore_purchases', async event => {
|
|
82
|
-
const success = await heliumCallbacks.restorePurchases();
|
|
83
|
-
HeliumBridge.handleRestoreResponse({
|
|
84
|
-
transactionId: event.transactionId,
|
|
85
|
-
status: success ? 'restored' : 'failed'
|
|
86
|
-
});
|
|
87
|
-
});
|
|
103
|
+
// Update download status to inProgress
|
|
104
|
+
if (setDownloadStatusRef) {
|
|
105
|
+
setDownloadStatusRef('inProgress');
|
|
106
|
+
}
|
|
88
107
|
|
|
89
|
-
// Set up
|
|
108
|
+
// Set up event listeners
|
|
90
109
|
heliumEventEmitter.addListener('helium_paywall_event', event => {
|
|
91
|
-
|
|
92
|
-
|
|
110
|
+
// Handle download status events
|
|
111
|
+
if (event.type === 'paywallsDownloadSuccess' && setDownloadStatusRef) {
|
|
112
|
+
setDownloadStatusRef('success');
|
|
113
|
+
} else if (event.type === 'paywallsDownloadError' && setDownloadStatusRef) {
|
|
114
|
+
setDownloadStatusRef('failed');
|
|
115
|
+
}
|
|
116
|
+
// Handle fallback view visibility
|
|
117
|
+
else if (event.type === 'paywallOpen' && event.paywallTemplateName === 'Fallback') {
|
|
93
118
|
if (fallbackRef.current) {
|
|
94
119
|
fallbackRef.current.setNativeProps({
|
|
95
120
|
style: {
|
|
@@ -98,7 +123,6 @@ export const initialize = async (heliumCallbacks, config = {}) => {
|
|
|
98
123
|
});
|
|
99
124
|
}
|
|
100
125
|
} else if (event.type === 'paywallClose' && event.paywallTemplateName === 'Fallback') {
|
|
101
|
-
// Update fallback view visibility if the ref exists
|
|
102
126
|
if (fallbackRef.current) {
|
|
103
127
|
fallbackRef.current.setNativeProps({
|
|
104
128
|
style: {
|
|
@@ -107,9 +131,29 @@ export const initialize = async (heliumCallbacks, config = {}) => {
|
|
|
107
131
|
});
|
|
108
132
|
}
|
|
109
133
|
}
|
|
134
|
+
|
|
135
|
+
// Forward all events to the callback
|
|
110
136
|
heliumCallbacks.onHeliumPaywallEvent(event);
|
|
111
137
|
});
|
|
112
138
|
|
|
139
|
+
// Set up purchase event listener
|
|
140
|
+
heliumEventEmitter.addListener('helium_make_purchase', async event => {
|
|
141
|
+
const status = await heliumCallbacks.makePurchase(event.productId);
|
|
142
|
+
HeliumBridge.handlePurchaseResponse({
|
|
143
|
+
transactionId: event.transactionId,
|
|
144
|
+
status: status
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Set up restore purchases event listener
|
|
149
|
+
heliumEventEmitter.addListener('helium_restore_purchases', async event => {
|
|
150
|
+
const success = await heliumCallbacks.restorePurchases();
|
|
151
|
+
HeliumBridge.handleRestoreResponse({
|
|
152
|
+
transactionId: event.transactionId,
|
|
153
|
+
status: success ? 'restored' : 'failed'
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
113
157
|
// Initialize the bridge with merged config
|
|
114
158
|
HeliumBridge.initialize({
|
|
115
159
|
apiKey: config.apiKey,
|
|
@@ -136,7 +180,22 @@ export const UpsellView = ({
|
|
|
136
180
|
trigger,
|
|
137
181
|
style
|
|
138
182
|
}) => {
|
|
183
|
+
const {
|
|
184
|
+
downloadStatus
|
|
185
|
+
} = useHelium();
|
|
139
186
|
const NativeView = getNativeHeliumUpsellView();
|
|
187
|
+
|
|
188
|
+
// If download status is notStarted or inProgress, we haven't fully initialized yet
|
|
189
|
+
// In this case, we should render the fallback view
|
|
190
|
+
if (downloadStatus === 'notStarted' || downloadStatus === 'inProgress' || downloadStatus === 'failed') {
|
|
191
|
+
// If we have a fallback view component, render it
|
|
192
|
+
if (FallbackViewComponent) {
|
|
193
|
+
return /*#__PURE__*/_jsx(FallbackViewComponent, {});
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Otherwise, render the native view
|
|
140
199
|
return /*#__PURE__*/_jsx(NativeView, {
|
|
141
200
|
trigger: trigger,
|
|
142
201
|
style: [{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["findNodeHandle","NativeModules","View","NativeEventEmitter","requireNativeComponent","React","createRef","useEffect","
|
|
1
|
+
{"version":3,"names":["findNodeHandle","NativeModules","View","NativeEventEmitter","requireNativeComponent","React","createRef","useEffect","useState","createContext","useContext","jsx","_jsx","jsxs","_jsxs","HeliumBridge","heliumEventEmitter","isProviderMounted","providerMountedPromise","resolveProviderMounted","Promise","resolve","HeliumContext","undefined","setDownloadStatusRef","useHelium","context","Error","NativeHeliumUpsellView","getNativeHeliumUpsellView","fallbackRef","FallbackViewComponent","HeliumProvider","children","fallbackView","FallbackView","downloadStatus","setDownloadStatus","Provider","value","ref","collapsable","style","display","initialize","heliumCallbacks","config","viewTag","current","addListener","event","type","paywallTemplateName","setNativeProps","onHeliumPaywallEvent","status","makePurchase","productId","handlePurchaseResponse","transactionId","success","restorePurchases","handleRestoreResponse","apiKey","fallbackPaywall","triggers","customUserId","customAPIEndpoint","customUserTraits","presentUpsell","triggerName","hideUpsell","UpsellView","trigger","NativeView","flex","HELIUM_CTA_NAMES","SCHEDULE_CALL","SUBSCRIBE_BUTTON"],"sourceRoot":"../../src","sources":["native-interface.tsx"],"mappings":";;AAAA,SAASA,cAAc,EAAEC,aAAa,EAAEC,IAAI,EAAEC,kBAAkB,EAAEC,sBAAsB,QAAQ,cAAc;AAC9G,OAAOC,KAAK,IAAIC,SAAS,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,aAAa,EAAEC,UAAU,QAAQ,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAGzF,MAAM;EAAEC;AAAa,CAAC,GAAGd,aAAa;AACtC,MAAMe,kBAAkB,GAAG,IAAIb,kBAAkB,CAACY,YAAY,CAAC;AAE/D,IAAIE,iBAAiB,GAAG,KAAK;AAC7B;AACA,IAAIC,sBAAqC;AACzC,IAAIC,sBAAkC;;AAEtC;AACAD,sBAAsB,GAAG,IAAIE,OAAO,CAAQC,OAAO,IAAK;EACtDF,sBAAsB,GAAGE,OAAO;EAChC;EACA,IAAIJ,iBAAiB,EAAE;IACrBI,OAAO,CAAC,CAAC;EACX;AACF,CAAC,CAAC;;AAEF;;AAMA,MAAMC,aAAa,gBAAGb,aAAa,CAAgCc,SAAS,CAAC;;AAE7E;AACA,IAAIC,oBAAqE,GAAG,IAAI;;AAEhF;AACA,OAAO,MAAMC,SAAS,GAAGA,CAAA,KAAM;EAC7B,MAAMC,OAAO,GAAGhB,UAAU,CAACY,aAAa,CAAC;EACzC,IAAI,CAACI,OAAO,EAAE;IACZ,MAAM,IAAIC,KAAK,CAAC,gDAAgD,CAAC;EACnE;EACA,OAAOD,OAAO;AAChB,CAAC;;AAED;AACA,IAAIE,sBAA2B,GAAG,IAAI;AACtC,MAAMC,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EACjF,MAAM;IAAEN;EAAe,CAAC,GAAGX,SAAS,CAAC,CAAC;EACtC,MAAMiD,UAAU,GAAG7C,yBAAyB,CAAC,CAAC;;EAE9C;EACA;EACA,IAAIO,cAAc,KAAK,YAAY,IAAIA,cAAc,KAAK,YAAY,IAAIA,cAAc,KAAK,QAAQ,EAAE;IACrG;IACA,IAAIL,qBAAqB,EAAE;MACzB,oBAAOnB,IAAA,CAACmB,qBAAqB,IAAE,CAAC;IAClC;IAEA,OAAO,IAAI;EACb;;EAEA;EACA,oBACEnB,IAAA,CAAC8D,UAAU;IACTD,OAAO,EAAEA,OAAQ;IACjB/B,KAAK,EAAE,CAAC;MAAEiC,IAAI,EAAE;IAAE,CAAC,EAAEjC,KAAK;EAAE,CAC7B,CAAC;AAEN,CAAC;AAED,OAAO,MAAMkC,gBAAgB,GAAG;EAC9BC,aAAa,EAAE,eAAe;EAC9BC,gBAAgB,EAAE;AACpB,CAAC","ignoreList":[]}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { HeliumCallbacks, HeliumConfig, HeliumUpsellViewProps } from './types';
|
|
2
|
+
import type { HeliumCallbacks, HeliumConfig, HeliumUpsellViewProps, HeliumDownloadStatus } from './types';
|
|
3
|
+
interface HeliumContextType {
|
|
4
|
+
downloadStatus: HeliumDownloadStatus;
|
|
5
|
+
setDownloadStatus: (status: HeliumDownloadStatus) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const useHelium: () => HeliumContextType;
|
|
3
8
|
interface HeliumProviderProps {
|
|
4
9
|
children: React.ReactNode;
|
|
5
10
|
fallbackView: React.ComponentType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-interface.d.ts","sourceRoot":"","sources":["../../../../src/native-interface.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"native-interface.d.ts","sourceRoot":"","sources":["../../../../src/native-interface.tsx"],"names":[],"mappings":"AACA,OAAO,KAAoE,MAAM,OAAO,CAAC;AACzF,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAoB1G,UAAU,iBAAiB;IACzB,cAAc,EAAE,oBAAoB,CAAC;IACrC,iBAAiB,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;CAC3D;AAQD,eAAO,MAAM,SAAS,yBAMrB,CAAC;AAWF,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,YAAY,EAAE,KAAK,CAAC,aAAa,CAAC;CACnC;AAQD,eAAO,MAAM,cAAc,6CAA8C,mBAAmB,4CAmC3F,CAAC;AAGF,eAAO,MAAM,UAAU,oBAA2B,eAAe,WAAU,OAAO,CAAC,YAAY,CAAC,kBAoF/F,CAAC;AAGF,eAAO,MAAM,aAAa,gBAAiB,MAAM,SAEhD,CAAC;AAEF,eAAO,MAAM,UAAU,YAEtB,CAAC;AAGF,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAsBtD,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;CAG5B,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type HeliumTransactionStatus = 'completed' | 'failed' | 'cancelled' | 'pending' | 'restored';
|
|
2
|
+
export type HeliumDownloadStatus = 'success' | 'failed' | 'inProgress' | 'notStarted';
|
|
2
3
|
export interface HeliumCallbacks {
|
|
3
4
|
makePurchase: (productId: string) => Promise<HeliumTransactionStatus>;
|
|
4
5
|
restorePurchases: () => Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC;AACpG,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,GAAG,YAAY,CAAC;AAEtF,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtE,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACzC,oBAAoB,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { HeliumCallbacks, HeliumConfig, HeliumUpsellViewProps } from './types';
|
|
2
|
+
import type { HeliumCallbacks, HeliumConfig, HeliumUpsellViewProps, HeliumDownloadStatus } from './types';
|
|
3
|
+
interface HeliumContextType {
|
|
4
|
+
downloadStatus: HeliumDownloadStatus;
|
|
5
|
+
setDownloadStatus: (status: HeliumDownloadStatus) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const useHelium: () => HeliumContextType;
|
|
3
8
|
interface HeliumProviderProps {
|
|
4
9
|
children: React.ReactNode;
|
|
5
10
|
fallbackView: React.ComponentType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-interface.d.ts","sourceRoot":"","sources":["../../../../src/native-interface.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"native-interface.d.ts","sourceRoot":"","sources":["../../../../src/native-interface.tsx"],"names":[],"mappings":"AACA,OAAO,KAAoE,MAAM,OAAO,CAAC;AACzF,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAoB1G,UAAU,iBAAiB;IACzB,cAAc,EAAE,oBAAoB,CAAC;IACrC,iBAAiB,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;CAC3D;AAQD,eAAO,MAAM,SAAS,yBAMrB,CAAC;AAWF,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,YAAY,EAAE,KAAK,CAAC,aAAa,CAAC;CACnC;AAQD,eAAO,MAAM,cAAc,6CAA8C,mBAAmB,4CAmC3F,CAAC;AAGF,eAAO,MAAM,UAAU,oBAA2B,eAAe,WAAU,OAAO,CAAC,YAAY,CAAC,kBAoF/F,CAAC;AAGF,eAAO,MAAM,aAAa,gBAAiB,MAAM,SAEhD,CAAC;AAEF,eAAO,MAAM,UAAU,YAEtB,CAAC;AAGF,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAsBtD,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;CAG5B,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type HeliumTransactionStatus = 'completed' | 'failed' | 'cancelled' | 'pending' | 'restored';
|
|
2
|
+
export type HeliumDownloadStatus = 'success' | 'failed' | 'inProgress' | 'notStarted';
|
|
2
3
|
export interface HeliumCallbacks {
|
|
3
4
|
makePurchase: (productId: string) => Promise<HeliumTransactionStatus>;
|
|
4
5
|
restorePurchases: () => Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,uBAAuB,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC;AACpG,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,QAAQ,GAAG,YAAY,GAAG,YAAY,CAAC;AAEtF,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtE,gBAAgB,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACzC,oBAAoB,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;CACb"}
|
package/package.json
CHANGED
package/src/native-interface.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { findNodeHandle, NativeModules, View, NativeEventEmitter, requireNativeComponent } from 'react-native';
|
|
2
|
-
import React, { createRef, useEffect } from 'react';
|
|
3
|
-
import type { HeliumCallbacks, HeliumConfig, HeliumUpsellViewProps } from './types';
|
|
2
|
+
import React, { createRef, useEffect, useState, createContext, useContext } from 'react';
|
|
3
|
+
import type { HeliumCallbacks, HeliumConfig, HeliumUpsellViewProps, HeliumDownloadStatus } from './types';
|
|
4
4
|
|
|
5
5
|
const { HeliumBridge } = NativeModules;
|
|
6
6
|
const heliumEventEmitter = new NativeEventEmitter(HeliumBridge);
|
|
@@ -19,6 +19,26 @@ providerMountedPromise = new Promise<void>((resolve) => {
|
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
+
// Create a context for the download status
|
|
23
|
+
interface HeliumContextType {
|
|
24
|
+
downloadStatus: HeliumDownloadStatus;
|
|
25
|
+
setDownloadStatus: (status: HeliumDownloadStatus) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const HeliumContext = createContext<HeliumContextType | undefined>(undefined);
|
|
29
|
+
|
|
30
|
+
// Create a ref to store the context setter
|
|
31
|
+
let setDownloadStatusRef: ((status: HeliumDownloadStatus) => void) | null = null;
|
|
32
|
+
|
|
33
|
+
// Hook to use the Helium context
|
|
34
|
+
export const useHelium = () => {
|
|
35
|
+
const context = useContext(HeliumContext);
|
|
36
|
+
if (!context) {
|
|
37
|
+
throw new Error('useHelium must be used within a HeliumProvider');
|
|
38
|
+
}
|
|
39
|
+
return context;
|
|
40
|
+
};
|
|
41
|
+
|
|
22
42
|
// Move NativeHeliumUpsellView to a singleton pattern
|
|
23
43
|
let NativeHeliumUpsellView: any = null;
|
|
24
44
|
const getNativeHeliumUpsellView = () => {
|
|
@@ -35,9 +55,20 @@ interface HeliumProviderProps {
|
|
|
35
55
|
|
|
36
56
|
// Create a ref to store the fallback view reference
|
|
37
57
|
const fallbackRef = createRef<View>();
|
|
58
|
+
// Store a reference to the fallback view component
|
|
59
|
+
let FallbackViewComponent: React.ComponentType | null = null;
|
|
38
60
|
|
|
39
61
|
// Provider component to be rendered at the app root
|
|
40
62
|
export const HeliumProvider = ({ children, fallbackView: FallbackView }: HeliumProviderProps) => {
|
|
63
|
+
// Add state for download status
|
|
64
|
+
const [downloadStatus, setDownloadStatus] = useState<HeliumDownloadStatus>('notStarted');
|
|
65
|
+
|
|
66
|
+
// Store the setter in the ref so it can be accessed outside of components
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
setDownloadStatusRef = setDownloadStatus;
|
|
69
|
+
// Store the fallback view component for later use
|
|
70
|
+
FallbackViewComponent = FallbackView;
|
|
71
|
+
}, [setDownloadStatus, FallbackView]);
|
|
41
72
|
|
|
42
73
|
useEffect(() => {
|
|
43
74
|
isProviderMounted = true;
|
|
@@ -45,11 +76,12 @@ export const HeliumProvider = ({ children, fallbackView: FallbackView }: HeliumP
|
|
|
45
76
|
resolveProviderMounted();
|
|
46
77
|
return () => {
|
|
47
78
|
isProviderMounted = false;
|
|
79
|
+
setDownloadStatusRef = null;
|
|
48
80
|
};
|
|
49
81
|
}, []);
|
|
50
82
|
|
|
51
83
|
return (
|
|
52
|
-
|
|
84
|
+
<HeliumContext.Provider value={{ downloadStatus, setDownloadStatus }}>
|
|
53
85
|
<View
|
|
54
86
|
ref={fallbackRef}
|
|
55
87
|
collapsable={false}
|
|
@@ -60,7 +92,7 @@ export const HeliumProvider = ({ children, fallbackView: FallbackView }: HeliumP
|
|
|
60
92
|
<FallbackView />
|
|
61
93
|
</View>
|
|
62
94
|
{children}
|
|
63
|
-
|
|
95
|
+
</HeliumContext.Provider>
|
|
64
96
|
);
|
|
65
97
|
};
|
|
66
98
|
|
|
@@ -76,6 +108,41 @@ export const initialize = async (heliumCallbacks: HeliumCallbacks, config: Parti
|
|
|
76
108
|
throw new Error('Failed to get fallback view reference. Make sure HeliumProvider is mounted with a fallback view.');
|
|
77
109
|
}
|
|
78
110
|
|
|
111
|
+
// Update download status to inProgress
|
|
112
|
+
if (setDownloadStatusRef) {
|
|
113
|
+
setDownloadStatusRef('inProgress');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Set up event listeners
|
|
117
|
+
heliumEventEmitter.addListener(
|
|
118
|
+
'helium_paywall_event',
|
|
119
|
+
(event: any) => {
|
|
120
|
+
// Handle download status events
|
|
121
|
+
if (event.type === 'paywallsDownloadSuccess' && setDownloadStatusRef) {
|
|
122
|
+
setDownloadStatusRef('success');
|
|
123
|
+
} else if (event.type === 'paywallsDownloadError' && setDownloadStatusRef) {
|
|
124
|
+
setDownloadStatusRef('failed');
|
|
125
|
+
}
|
|
126
|
+
// Handle fallback view visibility
|
|
127
|
+
else if (event.type === 'paywallOpen' && event.paywallTemplateName === 'Fallback') {
|
|
128
|
+
if (fallbackRef.current) {
|
|
129
|
+
fallbackRef.current.setNativeProps({
|
|
130
|
+
style: { display: 'flex' }
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
} else if (event.type === 'paywallClose' && event.paywallTemplateName === 'Fallback') {
|
|
134
|
+
if (fallbackRef.current) {
|
|
135
|
+
fallbackRef.current.setNativeProps({
|
|
136
|
+
style: { display: 'none' }
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Forward all events to the callback
|
|
142
|
+
heliumCallbacks.onHeliumPaywallEvent(event);
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
|
|
79
146
|
// Set up purchase event listener
|
|
80
147
|
heliumEventEmitter.addListener(
|
|
81
148
|
'helium_make_purchase',
|
|
@@ -100,30 +167,6 @@ export const initialize = async (heliumCallbacks: HeliumCallbacks, config: Parti
|
|
|
100
167
|
}
|
|
101
168
|
);
|
|
102
169
|
|
|
103
|
-
// Set up paywall event listener
|
|
104
|
-
heliumEventEmitter.addListener(
|
|
105
|
-
'helium_paywall_event',
|
|
106
|
-
(event: any) => {
|
|
107
|
-
|
|
108
|
-
if (event.type === 'paywallOpen' && event.paywallTemplateName === 'Fallback') {
|
|
109
|
-
// Update fallback view visibility if the ref exists
|
|
110
|
-
if (fallbackRef.current) {
|
|
111
|
-
fallbackRef.current.setNativeProps({
|
|
112
|
-
style: { display: 'flex' }
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
} else if (event.type === 'paywallClose' && event.paywallTemplateName === 'Fallback') {
|
|
116
|
-
// Update fallback view visibility if the ref exists
|
|
117
|
-
if (fallbackRef.current) {
|
|
118
|
-
fallbackRef.current.setNativeProps({
|
|
119
|
-
style: { display: 'none' }
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
heliumCallbacks.onHeliumPaywallEvent(event);
|
|
124
|
-
}
|
|
125
|
-
);
|
|
126
|
-
|
|
127
170
|
// Initialize the bridge with merged config
|
|
128
171
|
HeliumBridge.initialize(
|
|
129
172
|
{
|
|
@@ -151,7 +194,21 @@ export const hideUpsell = () => {
|
|
|
151
194
|
|
|
152
195
|
// Update the UpsellView component to handle the style prop
|
|
153
196
|
export const UpsellView: React.FC<HeliumUpsellViewProps> = ({ trigger, style }) => {
|
|
197
|
+
const { downloadStatus } = useHelium();
|
|
154
198
|
const NativeView = getNativeHeliumUpsellView();
|
|
199
|
+
|
|
200
|
+
// If download status is notStarted or inProgress, we haven't fully initialized yet
|
|
201
|
+
// In this case, we should render the fallback view
|
|
202
|
+
if (downloadStatus === 'notStarted' || downloadStatus === 'inProgress' || downloadStatus === 'failed') {
|
|
203
|
+
// If we have a fallback view component, render it
|
|
204
|
+
if (FallbackViewComponent) {
|
|
205
|
+
return <FallbackViewComponent />;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Otherwise, render the native view
|
|
155
212
|
return (
|
|
156
213
|
<NativeView
|
|
157
214
|
trigger={trigger}
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type HeliumTransactionStatus = 'completed' | 'failed' | 'cancelled' | 'pending' | 'restored';
|
|
2
|
+
export type HeliumDownloadStatus = 'success' | 'failed' | 'inProgress' | 'notStarted';
|
|
2
3
|
|
|
3
4
|
export interface HeliumCallbacks {
|
|
4
5
|
makePurchase: (productId: string) => Promise<HeliumTransactionStatus>;
|