From 59dd53767c631a16135f169fd253509e3708bbe8 Mon Sep 17 00:00:00 2001 From: Ian Rumac Date: Tue, 5 Nov 2024 11:31:50 +0100 Subject: [PATCH 1/6] Fix configuration status serialization on Android --- .../SuperwallReactNativeModule.kt | 3 ++- .../models/ConfigurationStatus.kt | 2 +- src/public/ConfigurationStatus.ts | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/superwallreactnative/SuperwallReactNativeModule.kt b/android/src/main/java/com/superwallreactnative/SuperwallReactNativeModule.kt index 38f5d62..2296fc6 100644 --- a/android/src/main/java/com/superwallreactnative/SuperwallReactNativeModule.kt +++ b/android/src/main/java/com/superwallreactnative/SuperwallReactNativeModule.kt @@ -26,6 +26,7 @@ import com.superwallreactnative.models.SubscriptionStatus import com.superwallreactnative.models.SuperwallOptions import com.superwallreactnative.models.convertMapToReadableMap import com.superwallreactnative.models.convertReadableMapToMap +import com.superwallreactnative.models.toRNString import com.superwallreactnative.models.toJson import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -184,7 +185,7 @@ class SuperwallReactNativeModule(private val reactContext: ReactApplicationConte @ReactMethod fun getConfigurationStatus(promise: Promise) { - promise.resolve(Superwall.instance.configurationState.toString()) + promise.resolve(Superwall.instance.configurationState.toRNString()) } @ReactMethod diff --git a/android/src/main/java/com/superwallreactnative/models/ConfigurationStatus.kt b/android/src/main/java/com/superwallreactnative/models/ConfigurationStatus.kt index f1d7ab1..ae90261 100644 --- a/android/src/main/java/com/superwallreactnative/models/ConfigurationStatus.kt +++ b/android/src/main/java/com/superwallreactnative/models/ConfigurationStatus.kt @@ -2,7 +2,7 @@ package com.superwallreactnative.models import com.superwall.sdk.config.models.ConfigurationStatus -fun ConfigurationStatus.toString(): String { +fun ConfigurationStatus.toRNString(): String { return when (this) { ConfigurationStatus.Pending -> "PENDING" ConfigurationStatus.Configured -> "CONFIGURED" diff --git a/src/public/ConfigurationStatus.ts b/src/public/ConfigurationStatus.ts index 08dd5b2..670fae2 100644 --- a/src/public/ConfigurationStatus.ts +++ b/src/public/ConfigurationStatus.ts @@ -17,4 +17,15 @@ export namespace ConfigurationStatus { return ConfigurationStatus.PENDING; } } + + export function toString(value: ConfigurationStatus): string { + switch (value) { + case ConfigurationStatus.FAILED: + return 'FAILED'; + case ConfigurationStatus.PENDING: + return 'PENDING'; + case ConfigurationStatus.CONFIGURED: + return 'CONFIGURED'; + } + } } From 0b302d27adac57418bcde4b1dd4f822a417db1e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20To=CC=88r?= <3296904+yusuftor@users.noreply.github.com> Date: Fri, 8 Nov 2024 21:14:38 +0100 Subject: [PATCH 2/6] Make purchase controller bridge a singleton --- .../main/java/com/PurchaseContollerProvider.kt | 15 +++++++++++++++ .../SuperwallReactNativeModule.kt | 2 +- ios/Bridges/PurchaseControllerBridge.swift | 4 ++++ ios/SuperwallReactNative.swift | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 android/src/main/java/com/PurchaseContollerProvider.kt diff --git a/android/src/main/java/com/PurchaseContollerProvider.kt b/android/src/main/java/com/PurchaseContollerProvider.kt new file mode 100644 index 0000000..b517d98 --- /dev/null +++ b/android/src/main/java/com/PurchaseContollerProvider.kt @@ -0,0 +1,15 @@ +package com.superwallreactnative + +import android.content.Context +import com.superwall.sdk.delegate.subscription_controller.PurchaseController + +object PurchaseControllerProvider { + private var instance: PurchaseControllerBridge? = null + + fun getInstance(context: Context): PurchaseControllerBridge { + if (instance == null) { + instance = PurchaseControllerBridge(context as ReactContext) + } + return instance!! + } +} diff --git a/android/src/main/java/com/superwallreactnative/SuperwallReactNativeModule.kt b/android/src/main/java/com/superwallreactnative/SuperwallReactNativeModule.kt index 38f5d62..ed518bb 100644 --- a/android/src/main/java/com/superwallreactnative/SuperwallReactNativeModule.kt +++ b/android/src/main/java/com/superwallreactnative/SuperwallReactNativeModule.kt @@ -33,7 +33,7 @@ import kotlinx.coroutines.launch class SuperwallReactNativeModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { - private val purchaseController = PurchaseControllerBridge(reactContext) + private val purchaseController: PurchaseControllerBridge = PurchaseControllerProvider.getInstance(reactContext) private var delegate: SuperwallDelegateBridge? = null private val activityProvider: ActivityProvider = ReactNativeActivityProvider(reactContext) diff --git a/ios/Bridges/PurchaseControllerBridge.swift b/ios/Bridges/PurchaseControllerBridge.swift index da99e18..ffb350d 100644 --- a/ios/Bridges/PurchaseControllerBridge.swift +++ b/ios/Bridges/PurchaseControllerBridge.swift @@ -2,9 +2,13 @@ import StoreKit import SuperwallKit final class PurchaseControllerBridge: PurchaseController { + static let shared = PurchaseControllerBridge() + var purchaseCompletion: ((PurchaseResult) -> Void)? var restoreCompletion: ((RestorationResult) -> Void)? + private init() {} + func purchase(product: SKProduct) async -> PurchaseResult { SuperwallReactNative.emitter.sendEvent( withName: "purchaseFromAppStore", diff --git a/ios/SuperwallReactNative.swift b/ios/SuperwallReactNative.swift index 835379e..6ba845c 100644 --- a/ios/SuperwallReactNative.swift +++ b/ios/SuperwallReactNative.swift @@ -3,7 +3,7 @@ import SuperwallKit @objc(SuperwallReactNative) class SuperwallReactNative: RCTEventEmitter { static var emitter: RCTEventEmitter! - private var purchaseController = PurchaseControllerBridge() + private let purchaseController = PurchaseControllerBridge.shared private var delegate: SuperwallDelegateBridge? override init() { From 219de1face489ff518a1191dc92a620e2c3e68e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20To=CC=88r?= <3296904+yusuftor@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:39:41 +0100 Subject: [PATCH 3/6] Update version to 1.3.5 --- CHANGELOG.md | 6 ++++++ example/ios/Podfile.lock | 4 ++-- package.json | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dafce10..c59a841 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The changelog for `Superwall`. Also see the [releases](https://github.com/superwall/react-native-superwall/releases) on GitHub. +## 1.3.5 + +### Fixes + +- Fixes issue where the `PurchaseController` functions wouldn't get called on hot restart of the app. + ## 1.3.4 ### Enhancements diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index de50763..68ad1a5 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1119,7 +1119,7 @@ PODS: - React-Core - SocketRocket (0.6.1) - Superscript (0.1.12) - - superwall-react-native (1.3.4): + - superwall-react-native (1.3.5): - glog - RCT-Folly (= 2022.05.16.00) - React-Core @@ -1393,7 +1393,7 @@ SPEC CHECKSUMS: RNPurchases: 06957eb2f35bd7bb336d32fccf3534d45a3fda8a SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 Superscript: 1ed1b4364f93bd16be05d085bba7357dbab95c83 - superwall-react-native: be4cd6ea0670a4f2f08986309a7ca27ee5f0e684 + superwall-react-native: 515aa62b5dc9452e3148a91fb645e08c4b0e1deb SuperwallKit: ff739c94ebc351ae210c8b0f0b3931e930d74053 Yoga: 1b901a6d6eeba4e8a2e8f308f708691cdb5db312 diff --git a/package.json b/package.json index 181b9e1..d130085 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@superwall/react-native-superwall", - "version": "1.3.4", + "version": "1.3.5", "description": "The React Native package for Superwall", "main": "lib/commonjs/index", "module": "lib/module/index", From eb0fcdd83fe7645b980778697bee7ea668aac52d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20To=CC=88r?= <3296904+yusuftor@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:46:02 +0100 Subject: [PATCH 4/6] Update PurchaseContollerProvider.kt --- android/src/main/java/com/PurchaseContollerProvider.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/PurchaseContollerProvider.kt b/android/src/main/java/com/PurchaseContollerProvider.kt index b517d98..1c88fde 100644 --- a/android/src/main/java/com/PurchaseContollerProvider.kt +++ b/android/src/main/java/com/PurchaseContollerProvider.kt @@ -1,6 +1,7 @@ package com.superwallreactnative import android.content.Context +import com.facebook.react.bridge.ReactApplicationContext import com.superwall.sdk.delegate.subscription_controller.PurchaseController object PurchaseControllerProvider { @@ -8,7 +9,7 @@ object PurchaseControllerProvider { fun getInstance(context: Context): PurchaseControllerBridge { if (instance == null) { - instance = PurchaseControllerBridge(context as ReactContext) + instance = PurchaseControllerBridge(context as ReactApplicationContext) } return instance!! } From a34d0a839567a56ceada7afd9a9d4ce6f06a699a Mon Sep 17 00:00:00 2001 From: Ian Rumac Date: Mon, 11 Nov 2024 13:34:44 +0100 Subject: [PATCH 5/6] Fix purchase controller retrieval, configuration status serialization and lint issues with readableArray --- android/src/main/java/com/PurchaseContollerProvider.kt | 6 ++++-- .../com/superwallreactnative/SuperwallReactNativeModule.kt | 3 ++- .../bridges/PurchaseControllerBridge.kt | 2 +- .../com/superwallreactnative/models/ConfigurationStatus.kt | 2 +- src/index.tsx | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/com/PurchaseContollerProvider.kt b/android/src/main/java/com/PurchaseContollerProvider.kt index 1c88fde..e896129 100644 --- a/android/src/main/java/com/PurchaseContollerProvider.kt +++ b/android/src/main/java/com/PurchaseContollerProvider.kt @@ -7,9 +7,11 @@ import com.superwall.sdk.delegate.subscription_controller.PurchaseController object PurchaseControllerProvider { private var instance: PurchaseControllerBridge? = null - fun getInstance(context: Context): PurchaseControllerBridge { + fun getInstance(context: ReactApplicationContext): PurchaseControllerBridge { if (instance == null) { - instance = PurchaseControllerBridge(context as ReactApplicationContext) + instance = PurchaseControllerBridge(context) + } else { + instance?.reactContext = context } return instance!! } diff --git a/android/src/main/java/com/superwallreactnative/SuperwallReactNativeModule.kt b/android/src/main/java/com/superwallreactnative/SuperwallReactNativeModule.kt index ed518bb..900a3c4 100644 --- a/android/src/main/java/com/superwallreactnative/SuperwallReactNativeModule.kt +++ b/android/src/main/java/com/superwallreactnative/SuperwallReactNativeModule.kt @@ -26,6 +26,7 @@ import com.superwallreactnative.models.SubscriptionStatus import com.superwallreactnative.models.SuperwallOptions import com.superwallreactnative.models.convertMapToReadableMap import com.superwallreactnative.models.convertReadableMapToMap +import com.superwallreactnative.models.asString import com.superwallreactnative.models.toJson import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -184,7 +185,7 @@ class SuperwallReactNativeModule(private val reactContext: ReactApplicationConte @ReactMethod fun getConfigurationStatus(promise: Promise) { - promise.resolve(Superwall.instance.configurationState.toString()) + promise.resolve(Superwall.instance.configurationState.asString()) } @ReactMethod diff --git a/android/src/main/java/com/superwallreactnative/bridges/PurchaseControllerBridge.kt b/android/src/main/java/com/superwallreactnative/bridges/PurchaseControllerBridge.kt index 6d9d9a4..2b90367 100644 --- a/android/src/main/java/com/superwallreactnative/bridges/PurchaseControllerBridge.kt +++ b/android/src/main/java/com/superwallreactnative/bridges/PurchaseControllerBridge.kt @@ -11,7 +11,7 @@ import kotlinx.coroutines.future.await import java.util.concurrent.CompletableFuture class PurchaseControllerBridge( - private val reactContext: ReactContext + var reactContext: ReactContext ): PurchaseController { var purchasePromise: CompletableFuture? = null var restorePromise: CompletableFuture? = null diff --git a/android/src/main/java/com/superwallreactnative/models/ConfigurationStatus.kt b/android/src/main/java/com/superwallreactnative/models/ConfigurationStatus.kt index f1d7ab1..499f39a 100644 --- a/android/src/main/java/com/superwallreactnative/models/ConfigurationStatus.kt +++ b/android/src/main/java/com/superwallreactnative/models/ConfigurationStatus.kt @@ -2,7 +2,7 @@ package com.superwallreactnative.models import com.superwall.sdk.config.models.ConfigurationStatus -fun ConfigurationStatus.toString(): String { +fun ConfigurationStatus.asString(): String { return when (this) { ConfigurationStatus.Pending -> "PENDING" ConfigurationStatus.Configured -> "CONFIGURED" diff --git a/src/index.tsx b/src/index.tsx index 079c56d..d14b010 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -366,7 +366,7 @@ export default class Superwall { async preloadPaywalls(eventNames: Set) { await this.awaitConfig(); - await SuperwallReactNative.preloadPaywalls(eventNames); + await SuperwallReactNative.preloadPaywalls(Array.from(eventNames)); } async setUserAttributes(userAttributes: UserAttributes) { From 16fbdcd2983417db45ed4943bb0a3a6b3cef5f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20To=CC=88r?= <3296904+yusuftor@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:14:39 +0100 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c59a841..2aff716 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ The changelog for `Superwall`. Also see the [releases](https://github.com/superw ### Fixes - Fixes issue where the `PurchaseController` functions wouldn't get called on hot restart of the app. +- Fixes issue with configuration status serialization on Android. +- Fixes issue with preloading paywalls on Android. ## 1.3.4