Skip to content

Commit e21365e

Browse files
feat(nocodes): add custom variables and forceSendProperties bridges
Bumps QonversionSandwich to 7.9.0 to consume new Sandwich APIs.
1 parent 10b5a17 commit e21365e

14 files changed

Lines changed: 71 additions & 12 deletions

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
8080
dependencies {
8181
implementation "com.facebook.react:react-android"
8282
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
83-
implementation "io.qonversion:sandwich:7.8.0"
83+
implementation "io.qonversion:sandwich:7.9.0"
8484
}
8585

8686
if (isNewArchitectureEnabled()) {

android/src/main/java/com/qonversion/reactnativesdk/NoCodesModule.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,18 @@ class NoCodesModule(private val reactContext: ReactApplicationContext) : NativeN
6262
}
6363

6464
@ReactMethod
65-
override fun showScreen(contextKey: String, promise: Promise) {
65+
override fun showScreen(contextKey: String, customVariables: ReadableMap?, promise: Promise) {
6666
try {
67-
noCodesSandwich.showScreen(contextKey)
67+
val variablesMap: Map<String, String>? = customVariables?.let { map ->
68+
buildMap {
69+
val iterator = map.keySetIterator()
70+
while (iterator.hasNextKey()) {
71+
val key = iterator.nextKey()
72+
map.getString(key)?.let { put(key, it) }
73+
}
74+
}
75+
}
76+
noCodesSandwich.showScreen(contextKey, variablesMap)
6877
promise.resolve(true)
6978
} catch (e: Exception) {
7079
promise.reject(e)

android/src/main/java/com/qonversion/reactnativesdk/QonversionModule.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ class QonversionModule(reactContext: ReactApplicationContext) : NativeQonversion
153153
qonversionSandwich.userProperties(getResultListener(promise))
154154
}
155155

156+
@ReactMethod
157+
override fun forceSendProperties(promise: Promise) {
158+
qonversionSandwich.forceSendProperties {
159+
promise.resolve(null)
160+
}
161+
}
162+
156163
@ReactMethod
157164
override fun addAttributionData(map: ReadableMap?, provider: String) {
158165
try {

ios/RNNoCodes.mm

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,23 @@ - (void)setScreenPresentationConfig:(NSDictionary *)configData
5252
}
5353

5454
- (void)showScreen:(NSString *)contextKey
55+
customVariables:(NSDictionary *)customVariables
5556
resolve:(RCTPromiseResolveBlock)resolve
5657
reject:(RCTPromiseRejectBlock)reject {
58+
NSDictionary<NSString *, NSString *> *typedVariables = nil;
59+
if ([customVariables isKindOfClass:[NSDictionary class]]) {
60+
NSMutableDictionary<NSString *, NSString *> *typed = [NSMutableDictionary dictionaryWithCapacity:customVariables.count];
61+
for (NSString *key in customVariables) {
62+
id value = customVariables[key];
63+
if ([key isKindOfClass:[NSString class]] && [value isKindOfClass:[NSString class]]) {
64+
typed[key] = value;
65+
}
66+
}
67+
typedVariables = typed;
68+
}
5769
dispatch_async(dispatch_get_main_queue(), ^{
5870
@try {
59-
[self.impl showScreenWithContextKey:contextKey];
71+
[self.impl showScreenWithContextKey:contextKey customVariables:typedVariables];
6072
} @catch (NSException *exception) {
6173
QNR_LOG_EXCEPTION("showScreen", exception);
6274
}

ios/RNNoCodesImpl.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public class RNNoCodesImpl: NSObject {
7676
}
7777

7878
@MainActor @objc
79-
public func showScreen(contextKey: String) {
80-
noCodesSandwich?.showScreen(contextKey)
79+
public func showScreen(contextKey: String, customVariables: [String: String]?) {
80+
noCodesSandwich?.showScreen(contextKey, customVariables: customVariables)
8181
}
8282

8383
@MainActor @objc

ios/RNQonversion.mm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ - (void)userProperties:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectB
159159
}
160160
}
161161

162+
- (void)forceSendProperties:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
163+
@try {
164+
[self.impl forceSendProperties:resolve reject:reject];
165+
} @catch (NSException *exception) {
166+
QNR_LOG_EXCEPTION("forceSendProperties", exception);
167+
reject(@"QONBridgeException", exception.reason, nil);
168+
}
169+
}
170+
162171
- (void)checkEntitlements:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
163172
@try {
164173
[self.impl checkEntitlements:resolve reject:reject];

ios/RNQonversionImpl.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ public class RNQonversionImpl: NSObject {
109109
}
110110
}
111111

112+
@objc
113+
public func forceSendProperties(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
114+
qonversionSandwich?.forceSendProperties {
115+
resolve(nil)
116+
}
117+
}
118+
112119
@objc
113120
public func addAttributionData(_ data: [String: Any], provider: String) {
114121
qonversionSandwich?.attribution(providerKey: provider, value: data)

qonversion-react-native-sdk.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ Pod::Spec.new do |s|
1616
s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
1717
s.private_header_files = "ios/**/*.h"
1818

19-
s.dependency "QonversionSandwich", "7.8.0"
19+
s.dependency "QonversionSandwich", "7.9.0"
2020
install_modules_dependencies(s)
2121
end

src/NoCodesApi.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ export default interface NoCodesApi {
1212

1313
/**
1414
* Show the screen using its context key.
15-
* @param contextKey the context key of the screen which must be shown
15+
* @param contextKey the context key of the screen which must be shown.
16+
* @param customVariables optional map of custom variables that will be injected
17+
* into the screen's JavaScript context. Variables are scoped
18+
* to the provided contextKey and only applied to that screen.
1619
*/
17-
showScreen(contextKey: string): void;
20+
showScreen(contextKey: string, customVariables?: Record<string, string>): void;
1821

1922
/**
2023
* Close the current opened No-Code screen.

src/QonversionApi.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ export interface QonversionApi {
228228
*/
229229
userProperties(): Promise<UserProperties>;
230230

231+
/**
232+
* Force-flushes any pending user property updates to the server immediately.
233+
* Use this when you need to ensure all previously set properties have been sent
234+
* before performing an operation that depends on them.
235+
*/
236+
forceSendProperties(): Promise<void>;
237+
231238
/**
232239
* Provide a listener to be notified about asynchronous user entitlements updates.
233240
*

0 commit comments

Comments
 (0)