Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.3.5 #23

Merged
merged 8 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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.
- Fixes issue with configuration status serialization on Android.
- Fixes issue with preloading paywalls on Android.

## 1.3.4

### Enhancements
Expand Down
18 changes: 18 additions & 0 deletions android/src/main/java/com/PurchaseContollerProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.superwallreactnative

import android.content.Context
import com.facebook.react.bridge.ReactApplicationContext
import com.superwall.sdk.delegate.subscription_controller.PurchaseController

object PurchaseControllerProvider {
private var instance: PurchaseControllerBridge? = null

fun getInstance(context: ReactApplicationContext): PurchaseControllerBridge {
if (instance == null) {
instance = PurchaseControllerBridge(context)
} else {
instance?.reactContext = context
}
return instance!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ 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
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)

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PurchaseResult>? = null
var restorePromise: CompletableFuture<RestorationResult>? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ 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"
ConfigurationStatus.Failed -> "FAILED"
}
}
}
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1393,7 +1393,7 @@ SPEC CHECKSUMS:
RNPurchases: 06957eb2f35bd7bb336d32fccf3534d45a3fda8a
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Superscript: 1ed1b4364f93bd16be05d085bba7357dbab95c83
superwall-react-native: be4cd6ea0670a4f2f08986309a7ca27ee5f0e684
superwall-react-native: 515aa62b5dc9452e3148a91fb645e08c4b0e1deb
SuperwallKit: ff739c94ebc351ae210c8b0f0b3931e930d74053
Yoga: 1b901a6d6eeba4e8a2e8f308f708691cdb5db312

Expand Down
4 changes: 4 additions & 0 deletions ios/Bridges/PurchaseControllerBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion ios/SuperwallReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
);

this.eventEmitter.addListener('restore', async () => {
var restorationResult =

Check failure on line 140 in src/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
await Superwall.purchaseController?.restorePurchases();
if (restorationResult == null) {
return;
Expand Down Expand Up @@ -366,7 +366,7 @@

async preloadPaywalls(eventNames: Set<string>) {
await this.awaitConfig();
await SuperwallReactNative.preloadPaywalls(eventNames);
await SuperwallReactNative.preloadPaywalls(Array.from(eventNames));
}

async setUserAttributes(userAttributes: UserAttributes) {
Expand Down
11 changes: 11 additions & 0 deletions src/public/ConfigurationStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
}
Loading