Skip to content

Commit

Permalink
Fixed issue where params weren't being passed through
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuftor committed Nov 24, 2024
1 parent cd140ac commit a4a9733
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The changelog for `Superwall`. Also see the [releases](https://github.com/superwall/react-native-superwall/releases) on GitHub.

## 1.4.2

### Fixes

- Fixes an issue where params that were passed with `getPresentationResult(event:params:)` were being dropped.

## 1.4.1

### Enhancements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.superwallreactnative.models.SuperwallOptions
import com.superwallreactnative.models.convertMapToReadableMap
import com.superwallreactnative.models.convertReadableMapToMap
import com.superwallreactnative.models.asString
import com.superwallreactnative.models.convertReadableMapToCompactMap
import com.superwallreactnative.models.toJson
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -272,8 +271,7 @@ class SuperwallReactNativeModule(private val reactContext: ReactApplicationConte
promise: Promise
) {
CoroutineScope(Dispatchers.IO).launch {
val paramsMap = params?.let { convertReadableMapToCompactMap(it) }
val result = Superwall.instance.getPresentationResult(event, paramsMap)
val result = Superwall.instance.getPresentationResult(event, params?.toHashMap())
launch(Dispatchers.Main) {
promise.resolve(result.toJson())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,3 @@ fun convertReadableMapToMap(readableMap: ReadableMap): Map<String, Any?> {
}
return map
}

fun convertReadableMapToCompactMap(readableMap: ReadableMap): Map<String, Any> {
val map: MutableMap<String, Any> = HashMap()
val iterator = readableMap.keySetIterator()
while (iterator.hasNextKey()) {
val key = iterator.nextKey()
when (val value = readableMap.getType(key)) {
ReadableType.String -> map[key] = readableMap.getString(key) ?: continue
ReadableType.Boolean -> map[key] = readableMap.getBoolean(key)
ReadableType.Number -> map[key] = readableMap.getDouble(key)
ReadableType.Map -> map[key] = convertReadableMapToMap(readableMap.getMap(key)!!)
ReadableType.Null -> continue
else -> {}
}
}
return map
}
2 changes: 1 addition & 1 deletion ios/SuperwallReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class SuperwallReactNative: RCTEventEmitter {
@objc(getPresentationResult:params:withResolver:withRejecter:)
func getPresentationResult(
event: String,
params: [String: Any],
params: [String: Any]?,
resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock
) {
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.4.1",
"version": "1.4.2",
"description": "The React Native package for Superwall",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
9 changes: 8 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,14 @@ export default class Superwall {
params?: Map<String, any>
): Promise<PresentationResult> {
await this.awaitConfig();
return await SuperwallReactNative.getPresentationResult(event, params);
let paramsObject = {};
if (params) {
paramsObject = Object.fromEntries(params);
}
return await SuperwallReactNative.getPresentationResult(
event,
paramsObject
);
}

async getConfigurationStatus(): Promise<ConfigurationStatus> {
Expand Down

0 comments on commit a4a9733

Please sign in to comment.