react-native-purchases-ui 10.12.2 → 10.13.0
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/RNPaywalls.podspec +1 -1
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/revenuecat/purchases/react/ui/BasePaywallViewManager.kt +3 -122
- package/android/src/main/java/com/revenuecat/purchases/react/ui/PaywallEventListener.kt +50 -0
- package/android/src/main/java/com/revenuecat/purchases/react/ui/RNPaywallsModule.kt +60 -12
- package/android/src/main/java/com/revenuecat/purchases/react/ui/events/{OnInteractionEvent.kt → PaywallViewEvent.kt} +8 -9
- package/ios/PaywallViewManager.m +1 -1
- package/ios/PaywallViewWrapper.h +3 -0
- package/ios/PaywallViewWrapper.m +38 -83
- package/ios/RCPaywallFooterViewManager.m +1 -1
- package/ios/RNPaywallEventForwarder.h +26 -0
- package/ios/RNPaywallEventForwarder.m +95 -0
- package/ios/RNPaywalls.h +2 -0
- package/ios/RNPaywalls.m +75 -1
- package/lib/commonjs/index.js +103 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/preview/nativeModules.js +2 -2
- package/lib/commonjs/preview/nativeModules.js.map +1 -1
- package/lib/module/index.js +103 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/preview/nativeModules.js +2 -2
- package/lib/module/preview/nativeModules.js.map +1 -1
- package/lib/typescript/src/index.d.ts +24 -8
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/preview/nativeModules.d.ts +2 -2
- package/lib/typescript/src/preview/nativeModules.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/index.tsx +87 -10
- package/src/preview/nativeModules.ts +6 -0
- package/android/src/main/java/com/revenuecat/purchases/react/ui/events/OnPurchaseCancelledEvent.kt +0 -13
- package/android/src/main/java/com/revenuecat/purchases/react/ui/events/OnPurchaseCompletedEvent.kt +0 -18
- package/android/src/main/java/com/revenuecat/purchases/react/ui/events/OnPurchaseErrorEvent.kt +0 -14
- package/android/src/main/java/com/revenuecat/purchases/react/ui/events/OnPurchasePackageInitiatedEvent.kt +0 -24
- package/android/src/main/java/com/revenuecat/purchases/react/ui/events/OnPurchaseStartedEvent.kt +0 -16
- package/android/src/main/java/com/revenuecat/purchases/react/ui/events/OnRestoreCompletedEvent.kt +0 -14
- package/android/src/main/java/com/revenuecat/purchases/react/ui/events/OnRestoreErrorEvent.kt +0 -14
- package/android/src/main/java/com/revenuecat/purchases/react/ui/events/OnRestoreStartedEvent.kt +0 -13
- package/android/src/main/java/com/revenuecat/purchases/react/ui/events/OnUrlOpenedEvent.kt +0 -21
- package/android/src/main/java/com/revenuecat/purchases/react/ui/events/OnWebCheckoutOpenedEvent.kt +0 -13
package/RNPaywalls.podspec
CHANGED
|
@@ -17,6 +17,6 @@ Pod::Spec.new do |spec|
|
|
|
17
17
|
spec.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
|
|
18
18
|
|
|
19
19
|
spec.dependency "React-Core"
|
|
20
|
-
spec.dependency "PurchasesHybridCommonUI", '19.
|
|
20
|
+
spec.dependency "PurchasesHybridCommonUI", '19.11.0'
|
|
21
21
|
spec.swift_version = '5.7'
|
|
22
22
|
end
|
package/android/build.gradle
CHANGED
|
@@ -65,7 +65,7 @@ android {
|
|
|
65
65
|
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
66
66
|
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
67
67
|
versionCode 1
|
|
68
|
-
versionName '10.
|
|
68
|
+
versionName '10.13.0'
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
buildTypes {
|
|
@@ -97,7 +97,7 @@ dependencies {
|
|
|
97
97
|
//noinspection GradleDynamicVersion
|
|
98
98
|
implementation "com.facebook.react:react-native:+"
|
|
99
99
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
100
|
-
implementation 'com.revenuecat.purchases:purchases-hybrid-common-ui:19.
|
|
100
|
+
implementation 'com.revenuecat.purchases:purchases-hybrid-common-ui:19.11.0'
|
|
101
101
|
implementation 'androidx.compose.ui:ui-android:1.5.4'
|
|
102
102
|
implementation "androidx.appcompat:appcompat:1.6.1"
|
|
103
103
|
}
|
|
@@ -4,7 +4,6 @@ import android.view.View
|
|
|
4
4
|
import com.facebook.react.bridge.ReactContext
|
|
5
5
|
import com.facebook.react.bridge.ReadableMap
|
|
6
6
|
import com.facebook.react.bridge.ReadableType
|
|
7
|
-
import com.facebook.react.bridge.WritableNativeMap
|
|
8
7
|
import com.facebook.react.common.MapBuilder
|
|
9
8
|
import com.facebook.react.uimanager.SimpleViewManager
|
|
10
9
|
import com.facebook.react.uimanager.ThemedReactContext
|
|
@@ -14,21 +13,10 @@ import com.facebook.react.uimanager.events.Event
|
|
|
14
13
|
import com.revenuecat.purchases.Package
|
|
15
14
|
import com.revenuecat.purchases.PresentedOfferingContext
|
|
16
15
|
import com.revenuecat.purchases.hybridcommon.ui.HybridPurchaseLogicBridge
|
|
17
|
-
import com.revenuecat.purchases.hybridcommon.ui.PaywallListenerWrapper
|
|
18
16
|
import com.revenuecat.purchases.react.ui.events.OnDismissEvent
|
|
19
|
-
import com.revenuecat.purchases.react.ui.events.OnInteractionEvent
|
|
20
17
|
import com.revenuecat.purchases.react.ui.events.OnPerformPurchaseEvent
|
|
21
18
|
import com.revenuecat.purchases.react.ui.events.OnPerformRestoreEvent
|
|
22
|
-
import com.revenuecat.purchases.react.ui.events.
|
|
23
|
-
import com.revenuecat.purchases.react.ui.events.OnPurchaseCompletedEvent
|
|
24
|
-
import com.revenuecat.purchases.react.ui.events.OnPurchaseErrorEvent
|
|
25
|
-
import com.revenuecat.purchases.react.ui.events.OnPurchasePackageInitiatedEvent
|
|
26
|
-
import com.revenuecat.purchases.react.ui.events.OnPurchaseStartedEvent
|
|
27
|
-
import com.revenuecat.purchases.react.ui.events.OnRestoreCompletedEvent
|
|
28
|
-
import com.revenuecat.purchases.react.ui.events.OnRestoreErrorEvent
|
|
29
|
-
import com.revenuecat.purchases.react.ui.events.OnRestoreStartedEvent
|
|
30
|
-
import com.revenuecat.purchases.react.ui.events.OnUrlOpenedEvent
|
|
31
|
-
import com.revenuecat.purchases.react.ui.events.OnWebCheckoutOpenedEvent
|
|
19
|
+
import com.revenuecat.purchases.react.ui.events.PaywallViewEvent
|
|
32
20
|
import com.revenuecat.purchases.ui.revenuecatui.CustomVariableValue
|
|
33
21
|
import com.revenuecat.purchases.ui.revenuecatui.fonts.CustomFontProvider
|
|
34
22
|
import java.util.concurrent.ConcurrentHashMap
|
|
@@ -214,108 +202,8 @@ internal abstract class BasePaywallViewManager<T : View> : SimpleViewManager<T>(
|
|
|
214
202
|
internal fun createPaywallListenerWrapper(
|
|
215
203
|
themedReactContext: ThemedReactContext,
|
|
216
204
|
view: View
|
|
217
|
-
) =
|
|
218
|
-
|
|
219
|
-
val event = OnPurchaseStartedEvent(
|
|
220
|
-
surfaceId = view.surfaceId,
|
|
221
|
-
viewTag = view.id,
|
|
222
|
-
rcPackage
|
|
223
|
-
)
|
|
224
|
-
emitEvent(themedReactContext, view.id, event)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
override fun onPurchaseCompleted(
|
|
228
|
-
customerInfo: Map<String, Any?>,
|
|
229
|
-
storeTransaction: Map<String, Any?>
|
|
230
|
-
) {
|
|
231
|
-
val event = OnPurchaseCompletedEvent(
|
|
232
|
-
surfaceId = view.surfaceId,
|
|
233
|
-
viewTag = view.id,
|
|
234
|
-
customerInfo,
|
|
235
|
-
storeTransaction
|
|
236
|
-
)
|
|
237
|
-
emitEvent(themedReactContext, view.id, event)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
override fun onPurchaseError(error: Map<String, Any?>) {
|
|
241
|
-
val event = OnPurchaseErrorEvent(
|
|
242
|
-
surfaceId = view.surfaceId,
|
|
243
|
-
viewTag = view.id,
|
|
244
|
-
error
|
|
245
|
-
)
|
|
246
|
-
emitEvent(themedReactContext, view.id, event)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
override fun onPurchaseCancelled() {
|
|
250
|
-
val event = OnPurchaseCancelledEvent(
|
|
251
|
-
surfaceId = view.surfaceId,
|
|
252
|
-
viewTag = view.id,
|
|
253
|
-
)
|
|
254
|
-
emitEvent(themedReactContext, view.id, event)
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
override fun onRestoreStarted() {
|
|
258
|
-
val event = OnRestoreStartedEvent(
|
|
259
|
-
surfaceId = view.surfaceId,
|
|
260
|
-
viewTag = view.id,
|
|
261
|
-
)
|
|
262
|
-
emitEvent(themedReactContext, view.id, event)
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
override fun onRestoreCompleted(customerInfo: Map<String, Any?>) {
|
|
266
|
-
val event = OnRestoreCompletedEvent(
|
|
267
|
-
surfaceId = view.surfaceId,
|
|
268
|
-
viewTag = view.id,
|
|
269
|
-
customerInfo,
|
|
270
|
-
)
|
|
271
|
-
emitEvent(themedReactContext, view.id, event)
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
override fun onRestoreError(error: Map<String, Any?>) {
|
|
275
|
-
val event = OnRestoreErrorEvent(
|
|
276
|
-
surfaceId = view.surfaceId,
|
|
277
|
-
viewTag = view.id,
|
|
278
|
-
error,
|
|
279
|
-
)
|
|
280
|
-
emitEvent(themedReactContext, view.id, event)
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
override fun onPurchasePackageInitiated(rcPackage: Map<String, Any?>, requestId: String) {
|
|
284
|
-
val event = OnPurchasePackageInitiatedEvent(
|
|
285
|
-
surfaceId = view.surfaceId,
|
|
286
|
-
viewTag = view.id,
|
|
287
|
-
rcPackage,
|
|
288
|
-
requestId,
|
|
289
|
-
)
|
|
290
|
-
emitEvent(themedReactContext, view.id, event)
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
override fun onWebCheckoutOpened() {
|
|
294
|
-
val event = OnWebCheckoutOpenedEvent(
|
|
295
|
-
surfaceId = view.surfaceId,
|
|
296
|
-
viewTag = view.id,
|
|
297
|
-
)
|
|
298
|
-
emitEvent(themedReactContext, view.id, event)
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
override fun onUrlOpened(url: String) {
|
|
302
|
-
val event = OnUrlOpenedEvent(
|
|
303
|
-
surfaceId = view.surfaceId,
|
|
304
|
-
viewTag = view.id,
|
|
305
|
-
url = url,
|
|
306
|
-
)
|
|
307
|
-
emitEvent(themedReactContext, view.id, event)
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
override fun onInteraction(event: Map<String, Any>) {
|
|
311
|
-
val interactionEvent = OnInteractionEvent(
|
|
312
|
-
surfaceId = view.surfaceId,
|
|
313
|
-
viewTag = view.id,
|
|
314
|
-
interaction = event,
|
|
315
|
-
)
|
|
316
|
-
emitEvent(themedReactContext, view.id, interactionEvent)
|
|
317
|
-
}
|
|
318
|
-
|
|
205
|
+
) = paywallEventListener(jsResumesPurchase = { true }) { eventName, payload ->
|
|
206
|
+
emitEvent(themedReactContext, view.id, PaywallViewEvent(view.surfaceId, view.id, eventName, payload))
|
|
319
207
|
}
|
|
320
208
|
|
|
321
209
|
internal fun getDismissHandler(
|
|
@@ -333,13 +221,6 @@ internal abstract class BasePaywallViewManager<T : View> : SimpleViewManager<T>(
|
|
|
333
221
|
return this.put(paywallEvent.eventName, registrationName)
|
|
334
222
|
}
|
|
335
223
|
|
|
336
|
-
private fun WritableNativeMap.putMap(keyMap: PaywallEventKey, dictionary: Map<String, Any?>) {
|
|
337
|
-
putMap(
|
|
338
|
-
keyMap.key,
|
|
339
|
-
RNPurchasesConverters.convertMapToWriteableMap(dictionary)
|
|
340
|
-
)
|
|
341
|
-
}
|
|
342
|
-
|
|
343
224
|
protected fun emitEvent(
|
|
344
225
|
context: ReactContext,
|
|
345
226
|
viewId: Int,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
package com.revenuecat.purchases.react.ui
|
|
2
|
+
|
|
3
|
+
import com.revenuecat.purchases.hybridcommon.ui.PaywallListenerWrapper
|
|
4
|
+
|
|
5
|
+
internal fun paywallEventListener(
|
|
6
|
+
jsResumesPurchase: () -> Boolean,
|
|
7
|
+
emit: (PaywallEventName, Map<String, Any?>) -> Unit,
|
|
8
|
+
): PaywallListenerWrapper = object : PaywallListenerWrapper() {
|
|
9
|
+
override fun onPurchaseStarted(rcPackage: Map<String, Any?>) =
|
|
10
|
+
emit(PaywallEventName.ON_PURCHASE_STARTED, mapOf(PaywallEventKey.PACKAGE.key to rcPackage))
|
|
11
|
+
|
|
12
|
+
override fun onPurchaseCompleted(customerInfo: Map<String, Any?>, storeTransaction: Map<String, Any?>) =
|
|
13
|
+
emit(
|
|
14
|
+
PaywallEventName.ON_PURCHASE_COMPLETED,
|
|
15
|
+
mapOf(
|
|
16
|
+
PaywallEventKey.CUSTOMER_INFO.key to customerInfo,
|
|
17
|
+
PaywallEventKey.STORE_TRANSACTION.key to storeTransaction,
|
|
18
|
+
),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
override fun onPurchaseError(error: Map<String, Any?>) =
|
|
22
|
+
emit(PaywallEventName.ON_PURCHASE_ERROR, mapOf(PaywallEventKey.ERROR.key to error))
|
|
23
|
+
|
|
24
|
+
override fun onPurchaseCancelled() = emit(PaywallEventName.ON_PURCHASE_CANCELLED, emptyMap())
|
|
25
|
+
|
|
26
|
+
override fun onRestoreStarted() = emit(PaywallEventName.ON_RESTORE_STARTED, emptyMap())
|
|
27
|
+
|
|
28
|
+
override fun onRestoreCompleted(customerInfo: Map<String, Any?>) =
|
|
29
|
+
emit(PaywallEventName.ON_RESTORE_COMPLETED, mapOf(PaywallEventKey.CUSTOMER_INFO.key to customerInfo))
|
|
30
|
+
|
|
31
|
+
override fun onRestoreError(error: Map<String, Any?>) =
|
|
32
|
+
emit(PaywallEventName.ON_RESTORE_ERROR, mapOf(PaywallEventKey.ERROR.key to error))
|
|
33
|
+
|
|
34
|
+
override fun onPurchasePackageInitiated(rcPackage: Map<String, Any?>, requestId: String) {
|
|
35
|
+
if (jsResumesPurchase()) {
|
|
36
|
+
emit(
|
|
37
|
+
PaywallEventName.ON_PURCHASE_PACKAGE_INITIATED,
|
|
38
|
+
mapOf(PaywallEventKey.PACKAGE.key to rcPackage, PaywallEventKey.REQUEST_ID.key to requestId),
|
|
39
|
+
)
|
|
40
|
+
} else {
|
|
41
|
+
super.onPurchasePackageInitiated(rcPackage, requestId)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override fun onWebCheckoutOpened() = emit(PaywallEventName.ON_WEB_CHECKOUT_OPENED, emptyMap())
|
|
46
|
+
|
|
47
|
+
override fun onUrlOpened(url: String) = emit(PaywallEventName.ON_URL_OPENED, mapOf(PaywallEventKey.URL.key to url))
|
|
48
|
+
|
|
49
|
+
override fun onInteraction(event: Map<String, Any>) = emit(PaywallEventName.ON_INTERACTION, event)
|
|
50
|
+
}
|
|
@@ -8,6 +8,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
|
8
8
|
import com.facebook.react.bridge.ReactMethod
|
|
9
9
|
import com.facebook.react.bridge.ReadableMap
|
|
10
10
|
import com.facebook.react.bridge.ReadableType
|
|
11
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
11
12
|
import com.revenuecat.purchases.hybridcommon.ui.HybridPurchaseLogicBridge
|
|
12
13
|
import com.revenuecat.purchases.hybridcommon.ui.PaywallListenerWrapper
|
|
13
14
|
import com.revenuecat.purchases.hybridcommon.ui.PaywallResultListener
|
|
@@ -22,23 +23,32 @@ internal class RNPaywallsModule(
|
|
|
22
23
|
|
|
23
24
|
companion object {
|
|
24
25
|
const val NAME = "RNPaywalls"
|
|
26
|
+
|
|
27
|
+
// RCTDeviceEventEmitter is global and keyed by event name alone, so these names must not
|
|
28
|
+
// collide with the ones RNCustomerCenter emits.
|
|
29
|
+
private const val PRESENTED_PAYWALL_EVENT_PREFIX = "Paywalls-"
|
|
30
|
+
private const val PRESENTATION_ID_KEY = "presentationId"
|
|
31
|
+
|
|
32
|
+
private const val MISSING_ACTIVITY_ERROR =
|
|
33
|
+
"RevenueCat paywalls can only be presented while there is a current activity"
|
|
34
|
+
private const val MISSING_FRAGMENT_ACTIVITY_ERROR =
|
|
35
|
+
"RevenueCat paywalls require applications to use a FragmentActivity"
|
|
25
36
|
}
|
|
26
37
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
else -> {
|
|
32
|
-
Log.e(NAME, "RevenueCat paywalls require applications to use a FragmentActivity")
|
|
33
|
-
null
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
38
|
+
// A presented paywall outlives a JS reload. On the New Architecture the old context reports the new
|
|
39
|
+
// runtime as active and routes events into it, so liveness has to come from this module's own teardown.
|
|
40
|
+
@Volatile
|
|
41
|
+
private var isInvalidated = false
|
|
37
42
|
|
|
38
43
|
override fun getName(): String {
|
|
39
44
|
return NAME
|
|
40
45
|
}
|
|
41
46
|
|
|
47
|
+
override fun invalidate() {
|
|
48
|
+
isInvalidated = true
|
|
49
|
+
super.invalidate()
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
@ReactMethod
|
|
43
53
|
fun presentPaywall(
|
|
44
54
|
offeringIdentifier: String?,
|
|
@@ -46,6 +56,8 @@ internal class RNPaywallsModule(
|
|
|
46
56
|
displayCloseButton: Boolean?,
|
|
47
57
|
fontFamily: String?,
|
|
48
58
|
customVariables: ReadableMap?,
|
|
59
|
+
presentationId: String?,
|
|
60
|
+
jsResumesPurchase: Boolean,
|
|
49
61
|
promise: Promise
|
|
50
62
|
) {
|
|
51
63
|
presentPaywall(
|
|
@@ -55,6 +67,8 @@ internal class RNPaywallsModule(
|
|
|
55
67
|
displayCloseButton,
|
|
56
68
|
fontFamily,
|
|
57
69
|
customVariables,
|
|
70
|
+
presentationId,
|
|
71
|
+
jsResumesPurchase,
|
|
58
72
|
promise
|
|
59
73
|
)
|
|
60
74
|
}
|
|
@@ -67,6 +81,8 @@ internal class RNPaywallsModule(
|
|
|
67
81
|
displayCloseButton: Boolean,
|
|
68
82
|
fontFamily: String?,
|
|
69
83
|
customVariables: ReadableMap?,
|
|
84
|
+
presentationId: String?,
|
|
85
|
+
jsResumesPurchase: Boolean,
|
|
70
86
|
promise: Promise
|
|
71
87
|
) {
|
|
72
88
|
presentPaywall(
|
|
@@ -76,6 +92,8 @@ internal class RNPaywallsModule(
|
|
|
76
92
|
displayCloseButton,
|
|
77
93
|
fontFamily,
|
|
78
94
|
customVariables,
|
|
95
|
+
presentationId,
|
|
96
|
+
jsResumesPurchase,
|
|
79
97
|
promise
|
|
80
98
|
)
|
|
81
99
|
}
|
|
@@ -107,9 +125,19 @@ internal class RNPaywallsModule(
|
|
|
107
125
|
displayCloseButton: Boolean?,
|
|
108
126
|
fontFamilyName: String?,
|
|
109
127
|
customVariables: ReadableMap?,
|
|
128
|
+
presentationId: String?,
|
|
129
|
+
jsResumesPurchase: Boolean,
|
|
110
130
|
promise: Promise
|
|
111
131
|
) {
|
|
112
|
-
val activity =
|
|
132
|
+
val activity = when (val currentActivity = reactApplicationContext.currentActivity) {
|
|
133
|
+
is FragmentActivity -> currentActivity
|
|
134
|
+
else -> {
|
|
135
|
+
val message = if (currentActivity == null) MISSING_ACTIVITY_ERROR else MISSING_FRAGMENT_ACTIVITY_ERROR
|
|
136
|
+
Log.e(NAME, message)
|
|
137
|
+
promise.reject("PAYWALLS_MISSING_WRONG_ACTIVITY", message, null)
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
}
|
|
113
141
|
val fontFamily = fontFamilyName?.let {
|
|
114
142
|
FontAssetManager.getPaywallFontFamily(fontFamilyName = it, activity.resources.assets)
|
|
115
143
|
}
|
|
@@ -149,9 +177,29 @@ internal class RNPaywallsModule(
|
|
|
149
177
|
}
|
|
150
178
|
},
|
|
151
179
|
fontFamily = fontFamily,
|
|
152
|
-
customVariables = customVariablesMap
|
|
180
|
+
customVariables = customVariablesMap,
|
|
181
|
+
paywallListener = presentationId?.let { routedPresentationId ->
|
|
182
|
+
paywallEventListener(
|
|
183
|
+
jsResumesPurchase = { jsResumesPurchase && !isInvalidated },
|
|
184
|
+
) { eventName, payload -> sendEvent(routedPresentationId, eventName, payload) }
|
|
185
|
+
},
|
|
153
186
|
)
|
|
154
187
|
)
|
|
155
188
|
}
|
|
156
189
|
}
|
|
190
|
+
|
|
191
|
+
private fun sendEvent(presentationId: String, event: PaywallEventName, params: Map<String, Any?>) {
|
|
192
|
+
if (isInvalidated) return
|
|
193
|
+
val eventName = PRESENTED_PAYWALL_EVENT_PREFIX + event.eventName
|
|
194
|
+
val payload = RNPurchasesConverters.convertMapToWriteableMap(params + (PRESENTATION_ID_KEY to presentationId))
|
|
195
|
+
reactApplicationContext.runOnUiQueueThread {
|
|
196
|
+
try {
|
|
197
|
+
reactApplicationContext
|
|
198
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
199
|
+
.emit(eventName, payload)
|
|
200
|
+
} catch (e: Exception) {
|
|
201
|
+
Log.e(NAME, "Error sending event $eventName", e)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
157
205
|
}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
package com.revenuecat.purchases.react.ui.events
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.WritableMap
|
|
4
|
-
import com.
|
|
4
|
+
import com.facebook.react.uimanager.events.Event
|
|
5
5
|
import com.revenuecat.purchases.react.ui.PaywallEventName
|
|
6
6
|
import com.revenuecat.purchases.react.ui.RNPurchasesConverters
|
|
7
7
|
|
|
8
|
-
internal class
|
|
8
|
+
internal class PaywallViewEvent(
|
|
9
9
|
surfaceId: Int,
|
|
10
10
|
viewTag: Int,
|
|
11
|
-
private val
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
private val paywallEventName: PaywallEventName,
|
|
12
|
+
private val payload: Map<String, Any?>,
|
|
13
|
+
) : Event<PaywallViewEvent>(surfaceId, viewTag) {
|
|
14
|
+
override fun getEventName(): String = paywallEventName.eventName
|
|
14
15
|
|
|
15
16
|
// EventDispatcherImpl merges same-name events staged in one frame unless this is false; every
|
|
16
17
|
// interaction must reach JS.
|
|
17
|
-
override fun canCoalesce(): Boolean =
|
|
18
|
+
override fun canCoalesce(): Boolean = paywallEventName != PaywallEventName.ON_INTERACTION
|
|
18
19
|
|
|
19
|
-
override fun
|
|
20
|
-
|
|
21
|
-
override fun getEventData(): WritableMap = RNPurchasesConverters.convertMapToWriteableMap(interaction)
|
|
20
|
+
override fun getEventData(): WritableMap = RNPurchasesConverters.convertMapToWriteableMap(payload)
|
|
22
21
|
}
|
package/ios/PaywallViewManager.m
CHANGED
package/ios/PaywallViewWrapper.h
CHANGED
|
@@ -28,6 +28,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
28
28
|
@property (nonatomic, copy, nullable) RCTDirectEventBlock onUrlOpened;
|
|
29
29
|
@property (nonatomic, copy, nullable) RCTDirectEventBlock onInteraction;
|
|
30
30
|
|
|
31
|
+
/// Set this as the `PaywallProxy` delegate. `PaywallProxy.delegate` is weak, so the view keeps it alive.
|
|
32
|
+
@property (nonatomic, strong, readonly) id<RCPaywallViewControllerDelegateWrapper> eventForwarder;
|
|
33
|
+
|
|
31
34
|
@property (nonatomic, strong, nullable) HybridPurchaseLogicBridge *purchaseLogicBridge;
|
|
32
35
|
@property (nonatomic, copy, nullable) UIViewController * _Nullable (^createViewController)(HybridPurchaseLogicBridge * _Nonnull);
|
|
33
36
|
|
package/ios/PaywallViewWrapper.m
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
//
|
|
7
7
|
|
|
8
8
|
#import "PaywallViewWrapper.h"
|
|
9
|
+
#import "RNPaywallEventForwarder.h"
|
|
9
10
|
#import "UIView+Extensions.h"
|
|
10
11
|
#import <React/UIView+React.h>
|
|
11
12
|
|
|
@@ -13,11 +14,42 @@
|
|
|
13
14
|
@import RevenueCat;
|
|
14
15
|
@import RevenueCatUI;
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
// Event names are the view's event block property names, so each one is looked up by key.
|
|
18
|
+
@interface PaywallViewEventForwarder : RNPaywallEventForwarder
|
|
19
|
+
|
|
20
|
+
- (instancetype)initWithView:(PaywallViewWrapper *)view;
|
|
21
|
+
|
|
22
|
+
@end
|
|
23
|
+
|
|
24
|
+
@implementation PaywallViewEventForwarder {
|
|
25
|
+
__weak PaywallViewWrapper *_view;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
- (instancetype)initWithView:(PaywallViewWrapper *)view {
|
|
29
|
+
__weak PaywallViewWrapper *weakView = view;
|
|
30
|
+
self = [super initWithEmitter:^(NSString *eventName, NSDictionary *body) {
|
|
31
|
+
RCTDirectEventBlock eventBlock = [weakView valueForKey:eventName];
|
|
32
|
+
if (eventBlock) {
|
|
33
|
+
eventBlock(body);
|
|
34
|
+
}
|
|
35
|
+
} jsResumesPurchase:^BOOL {
|
|
36
|
+
return weakView.onPurchasePackageInitiated != nil;
|
|
37
|
+
}];
|
|
38
|
+
if (self) {
|
|
39
|
+
_view = view;
|
|
40
|
+
}
|
|
41
|
+
return self;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
- (void)paywallViewControllerRequestedDismissal:(RCPaywallViewController *)controller API_AVAILABLE(ios(15.0)) {
|
|
45
|
+
[_view paywallViewControllerRequestedDismissal:controller];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
- (void)paywallViewController:(RCPaywallViewController *)controller didChangeSizeTo:(CGSize)size API_AVAILABLE(ios(15.0)) {
|
|
49
|
+
[_view paywallViewController:controller didChangeSizeTo:size];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@end
|
|
21
53
|
|
|
22
54
|
API_AVAILABLE(ios(15.0))
|
|
23
55
|
@interface PaywallViewWrapper ()
|
|
@@ -43,6 +75,7 @@ API_AVAILABLE(ios(15.0))
|
|
|
43
75
|
// See: https://github.com/RevenueCat/react-native-purchases/issues/1622
|
|
44
76
|
if ((self = [super initWithFrame:CGRectZero])) {
|
|
45
77
|
_paywallViewController = paywallViewController;
|
|
78
|
+
_eventForwarder = [[PaywallViewEventForwarder alloc] initWithView:self];
|
|
46
79
|
}
|
|
47
80
|
|
|
48
81
|
return self;
|
|
@@ -226,53 +259,6 @@ API_AVAILABLE(ios(15.0))
|
|
|
226
259
|
targetingContext:targetingContext];
|
|
227
260
|
}
|
|
228
261
|
|
|
229
|
-
- (void)paywallViewController:(RCPaywallViewController *)controller
|
|
230
|
-
didStartPurchaseWithPackage:(NSDictionary *)packageDictionary API_AVAILABLE(ios(15.0)) {
|
|
231
|
-
self.onPurchaseStarted(@{
|
|
232
|
-
KeyPackage: packageDictionary,
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
- (void)paywallViewController:(RCPaywallViewController *)controller
|
|
237
|
-
didFinishPurchasingWithCustomerInfoDictionary:(NSDictionary *)customerInfoDictionary
|
|
238
|
-
transactionDictionary:(NSDictionary *)transactionDictionary API_AVAILABLE(ios(15.0)) {
|
|
239
|
-
NSMutableDictionary *event = [NSMutableDictionary dictionaryWithObject:customerInfoDictionary
|
|
240
|
-
forKey:KeyCustomerInfo];
|
|
241
|
-
if (transactionDictionary) {
|
|
242
|
-
event[KeyStoreTransaction] = transactionDictionary;
|
|
243
|
-
}
|
|
244
|
-
self.onPurchaseCompleted([event copy]);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
- (void)paywallViewControllerDidCancelPurchase:(RCPaywallViewController *)controller API_AVAILABLE(ios(15.0)) {
|
|
248
|
-
self.onPurchaseCancelled(nil);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
- (void)paywallViewControllerDidStartRestore:(RCPaywallViewController *)controller API_AVAILABLE(ios(15.0)) {
|
|
252
|
-
self.onRestoreStarted(nil);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
- (void)paywallViewController:(RCPaywallViewController *)controller
|
|
256
|
-
didFailPurchasingWithErrorDictionary:(NSDictionary *)errorDictionary API_AVAILABLE(ios(15.0)) {
|
|
257
|
-
self.onPurchaseError(@{
|
|
258
|
-
KeyError: errorDictionary
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
- (void)paywallViewController:(RCPaywallViewController *)controller
|
|
263
|
-
didFinishRestoringWithCustomerInfoDictionary:(NSDictionary *)customerInfoDictionary API_AVAILABLE(ios(15.0)) {
|
|
264
|
-
self.onRestoreCompleted(@{
|
|
265
|
-
KeyCustomerInfo: customerInfoDictionary
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
- (void)paywallViewController:(RCPaywallViewController *)controller
|
|
270
|
-
didFailRestoringWithErrorDictionary:(NSDictionary *)errorDictionary API_AVAILABLE(ios(15.0)) {
|
|
271
|
-
self.onRestoreError(@{
|
|
272
|
-
KeyError: errorDictionary
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
|
|
276
262
|
- (void)paywallViewControllerRequestedDismissal:(RCPaywallViewController *)controller API_AVAILABLE(ios(15.0)) {
|
|
277
263
|
self.onDismiss(nil);
|
|
278
264
|
}
|
|
@@ -280,35 +266,4 @@ didFailRestoringWithErrorDictionary:(NSDictionary *)errorDictionary API_AVAILABL
|
|
|
280
266
|
- (void)paywallViewController:(RCPaywallViewController *)controller didChangeSizeTo:(CGSize)size API_AVAILABLE(ios(15.0)) {
|
|
281
267
|
}
|
|
282
268
|
|
|
283
|
-
- (void)paywallViewController:(RCPaywallViewController *)controller
|
|
284
|
-
didInitiatePurchaseWithPackageDictionary:(NSDictionary *)packageDictionary
|
|
285
|
-
requestId:(NSString *)requestId API_AVAILABLE(ios(15.0)) {
|
|
286
|
-
if (self.onPurchasePackageInitiated) {
|
|
287
|
-
self.onPurchasePackageInitiated(@{
|
|
288
|
-
KeyPackage: packageDictionary,
|
|
289
|
-
@"requestId": requestId,
|
|
290
|
-
});
|
|
291
|
-
} else {
|
|
292
|
-
[PaywallProxy resumePurchasePackageInitiatedWithRequestId:requestId shouldProceed:YES];
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
- (void)paywallViewControllerDidOpenWebCheckout:(RCPaywallViewController *)controller API_AVAILABLE(ios(15.0)) {
|
|
297
|
-
if (self.onWebCheckoutOpened) {
|
|
298
|
-
self.onWebCheckoutOpened(nil);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
- (void)paywallViewController:(RCPaywallViewController *)controller didOpenURL:(NSString *)url API_AVAILABLE(ios(15.0)) {
|
|
303
|
-
if (self.onUrlOpened) {
|
|
304
|
-
self.onUrlOpened(@{KeyUrl: url ?: @""});
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
- (void)paywallViewController:(RCPaywallViewController *)controller didTrackInteraction:(NSDictionary<NSString *, id> *)eventDictionary API_AVAILABLE(ios(15.0)) {
|
|
309
|
-
if (self.onInteraction) {
|
|
310
|
-
self.onInteraction(eventDictionary);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
269
|
@end
|
|
@@ -110,7 +110,7 @@ RCT_EXPORT_MODULE(RCPaywallFooterView)
|
|
|
110
110
|
UIViewController *footerViewController = [self.proxy createFooterPaywallView];
|
|
111
111
|
FooterViewWrapper *wrapper = [[FooterViewWrapper alloc] initWithPaywallViewController:footerViewController
|
|
112
112
|
bridge:self.bridge];
|
|
113
|
-
self.proxy.delegate = wrapper;
|
|
113
|
+
self.proxy.delegate = wrapper.eventForwarder;
|
|
114
114
|
|
|
115
115
|
return wrapper;
|
|
116
116
|
} else {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RNPaywallEventForwarder.h
|
|
3
|
+
// RNPaywalls
|
|
4
|
+
//
|
|
5
|
+
// Copyright © 2026 RevenueCat. All rights reserved.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
|
|
10
|
+
@import PurchasesHybridCommonUI;
|
|
11
|
+
|
|
12
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
13
|
+
|
|
14
|
+
typedef void (^RNPaywallEventEmitter)(NSString *eventName, NSDictionary * _Nullable body);
|
|
15
|
+
|
|
16
|
+
@interface RNPaywallEventForwarder : NSObject <RCPaywallViewControllerDelegateWrapper>
|
|
17
|
+
|
|
18
|
+
/// When `jsResumesPurchase` returns NO the purchase is resumed natively instead of emitted.
|
|
19
|
+
- (instancetype)initWithEmitter:(RNPaywallEventEmitter)emitter
|
|
20
|
+
jsResumesPurchase:(BOOL (^)(void))jsResumesPurchase;
|
|
21
|
+
|
|
22
|
+
- (instancetype)init NS_UNAVAILABLE;
|
|
23
|
+
|
|
24
|
+
@end
|
|
25
|
+
|
|
26
|
+
NS_ASSUME_NONNULL_END
|