clevertap-react-native 1.0.3 → 1.1.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/CHANGELOG.md +37 -0
- package/android/build.gradle +3 -3
- package/android/src/main/java/com/clevertap/react/CleverTapModule.java +249 -48
- package/android/src/main/java/com/clevertap/react/CleverTapUtils.java +293 -0
- package/clevertap-react-native.podspec +1 -1
- package/docs/Variables.md +136 -0
- package/docs/callbackPayloadFormat.md +26 -0
- package/docs/usage.md +10 -0
- package/index.d.ts +112 -1
- package/index.js +153 -24
- package/ios/CleverTapReact/CleverTapReact.h +2 -0
- package/ios/CleverTapReact/CleverTapReact.m +144 -9
- package/ios/CleverTapReact/CleverTapReactEventEmitter.m +10 -2
- package/ios/CleverTapReact/CleverTapReactManager.m +14 -15
- package/package.json +1 -1
- package/ios/CleverTapReact/CleverTapSDK.framework.zip +0 -0
- package/ios/CleverTapReact.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/CleverTapReact.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/CleverTapReact.xcodeproj/project.xcworkspace/xcuserdata/kushagra.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/CleverTapReact.xcodeproj/xcuserdata/kushagra.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
Change Log
|
|
2
2
|
==========
|
|
3
3
|
|
|
4
|
+
Version 1.1.0 *(29th May 2023)*
|
|
5
|
+
-------------------------------------------
|
|
6
|
+
**New Features**
|
|
7
|
+
- Adds support for **Remote Config Variables**. Please refer to the [Remote Config Variables doc](https://github.com/CleverTap/clevertap-react-native/blob/da2c3188fb5db6248f136e52f4b9e3372c26e78a/docs/Variables.md) to read more on how to integrate this to your app.
|
|
8
|
+
- Adds new API `dismissInbox()` to dismiss the App Inbox screen.
|
|
9
|
+
- Adds new APIs, `markReadInboxMessagesForIDs(Array)` and `deleteInboxMessagesForIDs(Array)` to mark read and delete an array of Inbox Messages respectively.
|
|
10
|
+
|
|
11
|
+
**API Changes**
|
|
12
|
+
|
|
13
|
+
***Deprecated:*** The following methods and classes related to Product Config and Feature Flags have been marked as deprecated in this release, instead use new Remote Config Variables feature. These methods and classes will be removed in the future versions with prior notice.
|
|
14
|
+
|
|
15
|
+
- Product config
|
|
16
|
+
- `setDefaultsMap`
|
|
17
|
+
- `fetch`
|
|
18
|
+
- `activate`
|
|
19
|
+
- `fetchAndActivate`
|
|
20
|
+
- `setMinimumFetchIntervalInSeconds`
|
|
21
|
+
- `resetProductConfig`
|
|
22
|
+
- `getProductConfigString`
|
|
23
|
+
- `getProductConfigBoolean`
|
|
24
|
+
- `getNumber`
|
|
25
|
+
- `getLastFetchTimeStampInMillis`
|
|
26
|
+
|
|
27
|
+
- Feature flags
|
|
28
|
+
- `getFeatureFlag`
|
|
29
|
+
|
|
30
|
+
**Breaking Change**
|
|
31
|
+
- Streamlines the payload for various callbacks across Android and iOS platform. Refer [doc](https://github.com/CleverTap/clevertap-react-native/blob/master/docs/callbackPayloadFormat.md) for detailed changes.
|
|
32
|
+
|
|
33
|
+
**Changes**
|
|
34
|
+
- ***[Android and iOS platforms]: Adds `contentPageIndex` and `buttonIndex` arguments to the payload sent via `CleverTap.CleverTapInboxMessageTapped` listener:*** The `contentPageIndex` indicates the page index of the content, which ranges from 0 to the total number of pages for carousel templates. For non-carousel templates, the value is always 0, as they only have one page of content. The `buttonIndex` represents the index of the App Inbox button clicked (0, 1, or 2). A value of -1 in `buttonIndex` indicates the App Inbox item is clicked.
|
|
35
|
+
- ***[Android Platform] Behavioral change of CleverTap.CleverTapInboxMessageTapped listener:*** Previously, the callback was raised when the App Inbox item is clicked. Now, it is also raised when the App Inbox button is clicked. It matches the behavior in iOS platform.
|
|
36
|
+
|
|
37
|
+
**Bug Fixes**
|
|
38
|
+
- Fixes a bug where App Inbox was not respecting the App Inbox background color when no tabs are provided.
|
|
39
|
+
- Fixes the non-EU retry mechanism bug.
|
|
40
|
+
|
|
4
41
|
Version 1.0.3 *(3rd May 2023)*
|
|
5
42
|
-------------------------------------------
|
|
6
43
|
- Fixes a bug where notification clicked callbacks were not working for killed state in iOS.
|
package/android/build.gradle
CHANGED
|
@@ -21,8 +21,8 @@ android {
|
|
|
21
21
|
defaultConfig {
|
|
22
22
|
minSdkVersion 19
|
|
23
23
|
targetSdkVersion 33
|
|
24
|
-
versionCode
|
|
25
|
-
versionName "1.0
|
|
24
|
+
versionCode 110
|
|
25
|
+
versionName "1.1.0"
|
|
26
26
|
}
|
|
27
27
|
buildTypes {
|
|
28
28
|
release {
|
|
@@ -39,7 +39,7 @@ dependencies {
|
|
|
39
39
|
maven { url "$rootDir/../node_modules/react-native/android" }
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
api 'com.clevertap.android:clevertap-android-sdk:
|
|
42
|
+
api 'com.clevertap.android:clevertap-android-sdk:5.0.0'
|
|
43
43
|
implementation 'com.android.installreferrer:installreferrer:2.2'
|
|
44
44
|
//compile 'com.android.support:appcompat-v7:28.0.0'
|
|
45
45
|
implementation 'com.facebook.react:react-native:+'
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
package com.clevertap.react;
|
|
2
2
|
|
|
3
|
+
import static com.clevertap.react.CleverTapUtils.convertObjectToWritableMap;
|
|
4
|
+
import static com.clevertap.react.CleverTapUtils.getWritableArrayFromDisplayUnitList;
|
|
3
5
|
import static com.clevertap.react.CleverTapUtils.getWritableMapFromMap;
|
|
4
6
|
|
|
5
7
|
import android.annotation.SuppressLint;
|
|
@@ -34,6 +36,11 @@ import com.clevertap.android.sdk.interfaces.OnInitCleverTapIDListener;
|
|
|
34
36
|
import com.clevertap.android.sdk.product_config.CTProductConfigController;
|
|
35
37
|
import com.clevertap.android.sdk.product_config.CTProductConfigListener;
|
|
36
38
|
import com.clevertap.android.sdk.pushnotification.CTPushNotificationListener;
|
|
39
|
+
import com.clevertap.android.sdk.variables.CTVariableUtils;
|
|
40
|
+
import com.clevertap.android.sdk.variables.Var;
|
|
41
|
+
import com.clevertap.android.sdk.variables.callbacks.FetchVariablesCallback;
|
|
42
|
+
import com.clevertap.android.sdk.variables.callbacks.VariableCallback;
|
|
43
|
+
import com.clevertap.android.sdk.variables.callbacks.VariablesChangedCallback;
|
|
37
44
|
import com.facebook.react.bridge.Arguments;
|
|
38
45
|
import com.facebook.react.bridge.Callback;
|
|
39
46
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
@@ -123,6 +130,7 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
123
130
|
private static final String CLEVERTAP_INBOX_MESSAGES_DID_UPDATE = "CleverTapInboxMessagesDidUpdate";
|
|
124
131
|
|
|
125
132
|
private static final String CLEVERTAP_ON_INBOX_BUTTON_CLICK = "CleverTapInboxMessageButtonTapped";
|
|
133
|
+
|
|
126
134
|
private static final String CLEVERTAP_ON_INBOX_MESSAGE_CLICK = "CleverTapInboxMessageTapped";
|
|
127
135
|
|
|
128
136
|
private static final String CLEVERTAP_ON_INAPP_BUTTON_CLICK = "CleverTapInAppNotificationButtonTapped";
|
|
@@ -141,10 +149,16 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
141
149
|
|
|
142
150
|
private static final String CLEVERTAP_ON_PUSH_PERMISSION_RESPONSE = "CleverTapPushPermissionResponseReceived";
|
|
143
151
|
|
|
152
|
+
private static final String CLEVERTAP_ON_VARIABLES_CHANGED = "CleverTapOnVariablesChanged";
|
|
153
|
+
|
|
154
|
+
private static final String CLEVERTAP_ON_VALUE_CHANGED = "CleverTapOnValueChanged";
|
|
155
|
+
|
|
144
156
|
private final ReactApplicationContext context;
|
|
145
157
|
|
|
146
158
|
private CleverTapAPI mCleverTap;
|
|
147
159
|
|
|
160
|
+
public static Map<String, Object> variables = new HashMap<>();
|
|
161
|
+
|
|
148
162
|
public static void setInitialUri(final Uri uri) {
|
|
149
163
|
mlaunchURI = uri;
|
|
150
164
|
}
|
|
@@ -155,6 +169,15 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
155
169
|
getCleverTapAPI();
|
|
156
170
|
}
|
|
157
171
|
|
|
172
|
+
@SuppressLint("RestrictedApi")
|
|
173
|
+
@ReactMethod
|
|
174
|
+
public void setLibrary(String libName, int libVersion) {
|
|
175
|
+
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
176
|
+
if (cleverTap != null) {
|
|
177
|
+
cleverTap.setCustomSdkVersion(libName,libVersion);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
158
181
|
@ReactMethod
|
|
159
182
|
public void activate() {
|
|
160
183
|
CTProductConfigController productConfigController = getCtProductConfigController();
|
|
@@ -175,7 +198,7 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
175
198
|
WritableMap params = Arguments.createMap();
|
|
176
199
|
JSONObject data = inAppNotification.getJsonDescription();
|
|
177
200
|
if (data != null) {
|
|
178
|
-
params.
|
|
201
|
+
params.putMap("data", convertObjectToWritableMap(data));
|
|
179
202
|
}
|
|
180
203
|
sendEvent(CLEVERTAP_IN_APP_NOTIFICATION_SHOWED, params);
|
|
181
204
|
}
|
|
@@ -333,7 +356,7 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
333
356
|
String error = ErrorMessages.CLEVERTAP_NOT_INITIALIZED.getErrorMessage();
|
|
334
357
|
callbackWithErrorAndResult(callback, error, null);
|
|
335
358
|
}
|
|
336
|
-
}
|
|
359
|
+
}
|
|
337
360
|
|
|
338
361
|
@Override
|
|
339
362
|
public void onPushPermissionResponse(boolean accepted) {
|
|
@@ -479,7 +502,7 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
479
502
|
|
|
480
503
|
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
481
504
|
if (cleverTap != null) {
|
|
482
|
-
result =
|
|
505
|
+
result = getWritableArrayFromDisplayUnitList(cleverTap.getAllDisplayUnits());
|
|
483
506
|
} else {
|
|
484
507
|
error = ErrorMessages.CLEVERTAP_NOT_INITIALIZED.getErrorMessage();
|
|
485
508
|
}
|
|
@@ -534,6 +557,8 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
534
557
|
constants.put(CLEVERTAP_PRODUCT_CONFIG_DID_ACTIVATE, CLEVERTAP_PRODUCT_CONFIG_DID_ACTIVATE);
|
|
535
558
|
constants.put(CLEVERTAP_PUSH_NOTIFICATION_CLICKED, CLEVERTAP_PUSH_NOTIFICATION_CLICKED);
|
|
536
559
|
constants.put(CLEVERTAP_ON_PUSH_PERMISSION_RESPONSE, CLEVERTAP_ON_PUSH_PERMISSION_RESPONSE);
|
|
560
|
+
constants.put(CLEVERTAP_ON_VARIABLES_CHANGED, CLEVERTAP_ON_VARIABLES_CHANGED);
|
|
561
|
+
constants.put(CLEVERTAP_ON_VALUE_CHANGED, CLEVERTAP_ON_VALUE_CHANGED);
|
|
537
562
|
return constants;
|
|
538
563
|
}
|
|
539
564
|
|
|
@@ -542,13 +567,13 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
542
567
|
@ReactMethod
|
|
543
568
|
public void getDisplayUnitForId(String unitID, Callback callback) {
|
|
544
569
|
String error = null;
|
|
545
|
-
|
|
570
|
+
WritableMap result = null;
|
|
546
571
|
|
|
547
572
|
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
548
573
|
if (cleverTap != null) {
|
|
549
574
|
CleverTapDisplayUnit displayUnit = cleverTap.getDisplayUnitForId(unitID);
|
|
550
575
|
if (displayUnit != null && displayUnit.getJsonObject() != null) {
|
|
551
|
-
result = displayUnit.getJsonObject()
|
|
576
|
+
result = convertObjectToWritableMap(displayUnit.getJsonObject());
|
|
552
577
|
}
|
|
553
578
|
} else {
|
|
554
579
|
error = ErrorMessages.CLEVERTAP_NOT_INITIALIZED.getErrorMessage();
|
|
@@ -627,14 +652,14 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
627
652
|
@ReactMethod
|
|
628
653
|
public void getInboxMessageForId(String messageId, Callback callback) {
|
|
629
654
|
String error = null;
|
|
630
|
-
|
|
655
|
+
WritableMap result = null;
|
|
631
656
|
|
|
632
657
|
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
633
658
|
if (cleverTap != null) {
|
|
634
659
|
CTInboxMessage inboxMessage = cleverTap.getInboxMessageForId(messageId);
|
|
635
660
|
|
|
636
661
|
if (inboxMessage != null && inboxMessage.getData() != null) {
|
|
637
|
-
result = inboxMessage.getData()
|
|
662
|
+
result = convertObjectToWritableMap(inboxMessage.getData());
|
|
638
663
|
}
|
|
639
664
|
} else {
|
|
640
665
|
error = ErrorMessages.CLEVERTAP_NOT_INITIALIZED.getErrorMessage();
|
|
@@ -749,6 +774,26 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
749
774
|
}
|
|
750
775
|
}
|
|
751
776
|
|
|
777
|
+
@ReactMethod
|
|
778
|
+
public void markReadInboxMessagesForIDs(final ReadableArray messageIDs) {
|
|
779
|
+
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
780
|
+
if (cleverTap != null) {
|
|
781
|
+
cleverTap.markReadInboxMessagesForIDs(arrayListStringFromReadableArray(messageIDs));
|
|
782
|
+
} else {
|
|
783
|
+
Log.e(TAG, ErrorMessages.CLEVERTAP_NOT_INITIALIZED.getErrorMessage());
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
@ReactMethod
|
|
788
|
+
public void deleteInboxMessagesForIDs(final ReadableArray messageIDs) {
|
|
789
|
+
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
790
|
+
if (cleverTap != null) {
|
|
791
|
+
cleverTap.deleteInboxMessagesForIDs(arrayListStringFromReadableArray(messageIDs));
|
|
792
|
+
} else {
|
|
793
|
+
Log.e(TAG, ErrorMessages.CLEVERTAP_NOT_INITIALIZED.getErrorMessage());
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
|
|
752
797
|
@Override
|
|
753
798
|
public void onActivated() {
|
|
754
799
|
WritableMap params = Arguments.createMap();
|
|
@@ -770,7 +815,7 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
770
815
|
//Native Display callback
|
|
771
816
|
public void onDisplayUnitsLoaded(ArrayList<CleverTapDisplayUnit> units) {
|
|
772
817
|
WritableMap params = Arguments.createMap();
|
|
773
|
-
params.putArray("displayUnits",
|
|
818
|
+
params.putArray("displayUnits", getWritableArrayFromDisplayUnitList(units));
|
|
774
819
|
sendEvent(CLEVERTAP_ON_DISPLAY_UNITS_LOADED, params);
|
|
775
820
|
}
|
|
776
821
|
|
|
@@ -788,18 +833,17 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
788
833
|
}
|
|
789
834
|
|
|
790
835
|
public void onInboxButtonClick(HashMap<String, String> payload) {
|
|
791
|
-
|
|
792
836
|
sendEvent(CLEVERTAP_ON_INBOX_BUTTON_CLICK, getWritableMapFromMap(payload));
|
|
793
|
-
|
|
794
837
|
}
|
|
838
|
+
|
|
795
839
|
@Override
|
|
796
|
-
public void onInboxItemClicked(CTInboxMessage message){
|
|
840
|
+
public void onInboxItemClicked(CTInboxMessage message, int contentPageIndex, int buttonIndex) {
|
|
797
841
|
WritableMap params = Arguments.createMap();
|
|
798
842
|
JSONObject data = message.getData();
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
sendEvent(CLEVERTAP_ON_INBOX_MESSAGE_CLICK,params);
|
|
843
|
+
params.putMap("data", (data != null ? convertObjectToWritableMap(data) : params));
|
|
844
|
+
params.putInt("contentPageIndex", contentPageIndex);
|
|
845
|
+
params.putInt("buttonIndex", buttonIndex);
|
|
846
|
+
sendEvent(CLEVERTAP_ON_INBOX_MESSAGE_CLICK, params);
|
|
803
847
|
}
|
|
804
848
|
|
|
805
849
|
//Product Config Callback
|
|
@@ -1299,8 +1343,9 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
1299
1343
|
}
|
|
1300
1344
|
|
|
1301
1345
|
@ReactMethod
|
|
1302
|
-
public void setPushTokenAsStringWithRegion(String token, String type,String region) {
|
|
1303
|
-
Logger.v(
|
|
1346
|
+
public void setPushTokenAsStringWithRegion(String token, String type, String region) {
|
|
1347
|
+
Logger.v("setPushTokenAsString() called with: token = [" + token + "], type = [" + type + "], region = ["
|
|
1348
|
+
+ region + "]");
|
|
1304
1349
|
|
|
1305
1350
|
CleverTapAPI clevertap = getCleverTapAPI();
|
|
1306
1351
|
if (clevertap == null || token == null || type == null || TextUtils.isEmpty(region)) {
|
|
@@ -1309,7 +1354,7 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
1309
1354
|
|
|
1310
1355
|
switch (type) {
|
|
1311
1356
|
case XPS:
|
|
1312
|
-
clevertap.pushXiaomiRegistrationId(token,region,true);
|
|
1357
|
+
clevertap.pushXiaomiRegistrationId(token, region, true);
|
|
1313
1358
|
break;
|
|
1314
1359
|
default:
|
|
1315
1360
|
Log.e(TAG, "Unknown push token type " + type);
|
|
@@ -1327,10 +1372,17 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
1327
1372
|
}
|
|
1328
1373
|
}
|
|
1329
1374
|
|
|
1330
|
-
|
|
1375
|
+
@ReactMethod
|
|
1376
|
+
public void dismissInbox() {
|
|
1377
|
+
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
1378
|
+
if (cleverTap != null) {
|
|
1379
|
+
cleverTap.dismissAppInbox();
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1331
1382
|
|
|
1383
|
+
// Increment/Decrement Operator
|
|
1332
1384
|
@ReactMethod
|
|
1333
|
-
public void profileIncrementValueForKey(Double value,String key) {
|
|
1385
|
+
public void profileIncrementValueForKey(Double value, String key) {
|
|
1334
1386
|
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
1335
1387
|
if (cleverTap != null) {
|
|
1336
1388
|
cleverTap.incrementValue(key, value);
|
|
@@ -1338,7 +1390,7 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
1338
1390
|
}
|
|
1339
1391
|
|
|
1340
1392
|
@ReactMethod
|
|
1341
|
-
public void profileDecrementValueForKey(Double value,String key) {
|
|
1393
|
+
public void profileDecrementValueForKey(Double value, String key) {
|
|
1342
1394
|
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
1343
1395
|
if (cleverTap != null) {
|
|
1344
1396
|
cleverTap.decrementValue(key, value);
|
|
@@ -1371,6 +1423,125 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
1371
1423
|
}
|
|
1372
1424
|
}
|
|
1373
1425
|
|
|
1426
|
+
/**************************************************
|
|
1427
|
+
* Product Experience Remote Config methods starts
|
|
1428
|
+
*************************************************/
|
|
1429
|
+
@ReactMethod
|
|
1430
|
+
public void syncVariables() {
|
|
1431
|
+
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
1432
|
+
if (cleverTap != null) {
|
|
1433
|
+
cleverTap.syncVariables();
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
@ReactMethod
|
|
1438
|
+
public void syncVariablesinProd(boolean isProduction, Callback callback) {
|
|
1439
|
+
Log.i(TAG, "CleverTap syncVariablesinProd is no-op in Android");
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
@ReactMethod
|
|
1443
|
+
public void fetchVariables() {
|
|
1444
|
+
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
1445
|
+
if (cleverTap != null) {
|
|
1446
|
+
cleverTap.fetchVariables();
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
@ReactMethod
|
|
1451
|
+
public void defineVariables(ReadableMap object) {
|
|
1452
|
+
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
1453
|
+
if (cleverTap != null) {
|
|
1454
|
+
for (Map.Entry<String, Object> entry : object.toHashMap().entrySet()) {
|
|
1455
|
+
String key = entry.getKey();
|
|
1456
|
+
Object value = entry.getValue();
|
|
1457
|
+
variables.put(key, cleverTap.defineVariable(key, value));
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
@ReactMethod
|
|
1463
|
+
public void fetchVariables(final Callback callback) {
|
|
1464
|
+
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
1465
|
+
if (cleverTap != null) {
|
|
1466
|
+
cleverTap.fetchVariables(new FetchVariablesCallback() {
|
|
1467
|
+
@Override
|
|
1468
|
+
public void onVariablesFetched(final boolean isSuccess) {
|
|
1469
|
+
callbackWithErrorAndResult(callback, null, isSuccess);
|
|
1470
|
+
}
|
|
1471
|
+
});
|
|
1472
|
+
} else {
|
|
1473
|
+
String error = ErrorMessages.CLEVERTAP_NOT_INITIALIZED.getErrorMessage();
|
|
1474
|
+
callbackWithErrorAndResult(callback, error, null);
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
@ReactMethod
|
|
1479
|
+
public void getVariable(String key, final Callback callback) {
|
|
1480
|
+
String error = null;
|
|
1481
|
+
Object result = null;
|
|
1482
|
+
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
1483
|
+
if (cleverTap != null) {
|
|
1484
|
+
try {
|
|
1485
|
+
result = getVariableValue(key);
|
|
1486
|
+
} catch (IllegalArgumentException e) {
|
|
1487
|
+
error = e.getLocalizedMessage();
|
|
1488
|
+
}
|
|
1489
|
+
} else {
|
|
1490
|
+
error = ErrorMessages.CLEVERTAP_NOT_INITIALIZED.getErrorMessage();
|
|
1491
|
+
}
|
|
1492
|
+
callbackWithErrorAndResult(callback, error, result);
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
@ReactMethod
|
|
1496
|
+
public void getVariables(final Callback callback) {
|
|
1497
|
+
callbackWithErrorAndResult(callback, null, getVariablesValues());
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
@ReactMethod
|
|
1501
|
+
public void onValueChanged(final String name) {
|
|
1502
|
+
if (variables.containsKey(name)) {
|
|
1503
|
+
|
|
1504
|
+
Var<Object> var = (Var<Object>) variables.get(name);
|
|
1505
|
+
if (var != null) {
|
|
1506
|
+
var.addValueChangedCallback(new VariableCallback<Object>() {
|
|
1507
|
+
@SuppressLint("RestrictedApi")
|
|
1508
|
+
@Override
|
|
1509
|
+
public void onValueChanged(final Var<Object> variable) {
|
|
1510
|
+
WritableMap result = null;
|
|
1511
|
+
try {
|
|
1512
|
+
result = getVariableValueAsWritableMap(name);
|
|
1513
|
+
} catch (IllegalArgumentException e) {
|
|
1514
|
+
Log.e(TAG, e.getLocalizedMessage());
|
|
1515
|
+
}
|
|
1516
|
+
sendEvent(CLEVERTAP_ON_VALUE_CHANGED, result);
|
|
1517
|
+
}
|
|
1518
|
+
});
|
|
1519
|
+
} else {
|
|
1520
|
+
Log.d(TAG, "Variable value with name = " + name + " contains null value. Not setting onValueChanged callback.");
|
|
1521
|
+
}
|
|
1522
|
+
} else {
|
|
1523
|
+
Log.e(TAG, "Variable name = " + name + " does not exist. Make sure you set variable first.");
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
@ReactMethod
|
|
1528
|
+
public void onVariablesChanged() {
|
|
1529
|
+
CleverTapAPI cleverTap = getCleverTapAPI();
|
|
1530
|
+
if (cleverTap != null) {
|
|
1531
|
+
cleverTap.addVariablesChangedCallback(new VariablesChangedCallback() {
|
|
1532
|
+
@Override
|
|
1533
|
+
public void variablesChanged() {
|
|
1534
|
+
sendEvent(CLEVERTAP_ON_VARIABLES_CHANGED, getVariablesValues());
|
|
1535
|
+
}
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
/************************************************
|
|
1541
|
+
* Product Experience Remote Config methods ends
|
|
1542
|
+
************************************************/
|
|
1543
|
+
|
|
1544
|
+
|
|
1374
1545
|
/**
|
|
1375
1546
|
* result must be primitive, String or com.facebook.react.bridge.WritableArray/WritableMap
|
|
1376
1547
|
* see https://github.com/facebook/react-native/issues/3101#issuecomment-143954448
|
|
@@ -1387,6 +1558,47 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
1387
1558
|
}
|
|
1388
1559
|
}
|
|
1389
1560
|
|
|
1561
|
+
@SuppressLint("RestrictedApi")
|
|
1562
|
+
private Object getVariableValue(String name) {
|
|
1563
|
+
if (variables.containsKey(name)) {
|
|
1564
|
+
Var<?> variable = (Var<?>) variables.get(name);
|
|
1565
|
+
Object variableValue = variable.value();
|
|
1566
|
+
Object value;
|
|
1567
|
+
switch (variable.kind()) {
|
|
1568
|
+
case CTVariableUtils.DICTIONARY:
|
|
1569
|
+
value = CleverTapUtils.MapUtil.toWritableMap((Map<String, Object>) variableValue);
|
|
1570
|
+
break;
|
|
1571
|
+
default:
|
|
1572
|
+
value = variableValue;
|
|
1573
|
+
}
|
|
1574
|
+
return value;
|
|
1575
|
+
}
|
|
1576
|
+
throw new IllegalArgumentException(
|
|
1577
|
+
"Variable name = " + name + " does not exist. Make sure you set variable first.");
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
@SuppressLint("RestrictedApi")
|
|
1581
|
+
private WritableMap getVariableValueAsWritableMap(String name) {
|
|
1582
|
+
if (variables.containsKey(name)) {
|
|
1583
|
+
Var<?> variable = (Var<?>) variables.get(name);
|
|
1584
|
+
Object variableValue = variable.value();
|
|
1585
|
+
return CleverTapUtils.MapUtil.addValue(name, variable.value());
|
|
1586
|
+
}
|
|
1587
|
+
throw new IllegalArgumentException(
|
|
1588
|
+
"Variable name = " + name + " does not exist.");
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
private WritableMap getVariablesValues() {
|
|
1592
|
+
WritableMap writableMap = Arguments.createMap();
|
|
1593
|
+
for (Map.Entry<String, Object> entry : variables.entrySet()) {
|
|
1594
|
+
String key = entry.getKey();
|
|
1595
|
+
Var<?> variable = (Var<?>) entry.getValue();
|
|
1596
|
+
|
|
1597
|
+
WritableMap variableWritableMap = CleverTapUtils.MapUtil.addValue(key, variable.value());
|
|
1598
|
+
writableMap.merge(variableWritableMap);
|
|
1599
|
+
}
|
|
1600
|
+
return writableMap;
|
|
1601
|
+
}
|
|
1390
1602
|
// Listeners
|
|
1391
1603
|
|
|
1392
1604
|
private boolean checkKitkatVersion(String methodName) {
|
|
@@ -1500,7 +1712,7 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
1500
1712
|
|
|
1501
1713
|
for (CTInboxMessage message : inboxMessages) {
|
|
1502
1714
|
if (message != null && message.getData() != null) {
|
|
1503
|
-
result.
|
|
1715
|
+
result.pushMap(convertObjectToWritableMap(message.getData()));
|
|
1504
1716
|
}
|
|
1505
1717
|
}
|
|
1506
1718
|
} else {
|
|
@@ -1509,18 +1721,6 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
1509
1721
|
callbackWithErrorAndResult(callback, error, result);
|
|
1510
1722
|
}
|
|
1511
1723
|
|
|
1512
|
-
private WritableArray getWritableArrayFromList(List<CleverTapDisplayUnit> list) {
|
|
1513
|
-
WritableArray writableArray = Arguments.createArray();
|
|
1514
|
-
if (list != null) {
|
|
1515
|
-
for (CleverTapDisplayUnit item : list) {
|
|
1516
|
-
if (item != null && item.getJsonObject() != null) {
|
|
1517
|
-
writableArray.pushString(item.getJsonObject().toString());
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
return writableArray;
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
1724
|
private HashMap<String, Object> profileFromReadableMap(ReadableMap profileMap) {
|
|
1525
1725
|
if (profileMap == null) {
|
|
1526
1726
|
return null;
|
|
@@ -1661,28 +1861,28 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
1661
1861
|
);
|
|
1662
1862
|
|
|
1663
1863
|
//adds the optional parameters to the builder instance
|
|
1664
|
-
if(backgroundColor != null) {
|
|
1864
|
+
if (backgroundColor != null) {
|
|
1665
1865
|
builderWithRequiredParams.setBackgroundColor(backgroundColor);
|
|
1666
1866
|
}
|
|
1667
|
-
if(btnBorderColor != null) {
|
|
1867
|
+
if (btnBorderColor != null) {
|
|
1668
1868
|
builderWithRequiredParams.setBtnBorderColor(btnBorderColor);
|
|
1669
1869
|
}
|
|
1670
|
-
if(titleTextColor != null) {
|
|
1870
|
+
if (titleTextColor != null) {
|
|
1671
1871
|
builderWithRequiredParams.setTitleTextColor(titleTextColor);
|
|
1672
1872
|
}
|
|
1673
|
-
if(messageTextColor != null) {
|
|
1873
|
+
if (messageTextColor != null) {
|
|
1674
1874
|
builderWithRequiredParams.setMessageTextColor(messageTextColor);
|
|
1675
1875
|
}
|
|
1676
|
-
if(btnTextColor != null) {
|
|
1876
|
+
if (btnTextColor != null) {
|
|
1677
1877
|
builderWithRequiredParams.setBtnTextColor(btnTextColor);
|
|
1678
1878
|
}
|
|
1679
|
-
if(imageUrl != null) {
|
|
1879
|
+
if (imageUrl != null) {
|
|
1680
1880
|
builderWithRequiredParams.setImageUrl(imageUrl);
|
|
1681
1881
|
}
|
|
1682
|
-
if(btnBackgroundColor != null) {
|
|
1882
|
+
if (btnBackgroundColor != null) {
|
|
1683
1883
|
builderWithRequiredParams.setBtnBackgroundColor(btnBackgroundColor);
|
|
1684
1884
|
}
|
|
1685
|
-
if(btnBorderRadius != null) {
|
|
1885
|
+
if (btnBorderRadius != null) {
|
|
1686
1886
|
builderWithRequiredParams.setBtnBorderRadius(btnBorderRadius);
|
|
1687
1887
|
}
|
|
1688
1888
|
builderWithRequiredParams.setFallbackToSettings(fallbackToSettings);
|
|
@@ -1694,14 +1894,15 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
1694
1894
|
|
|
1695
1895
|
/**
|
|
1696
1896
|
* Creates an instance of the {@link CTLocalInApp.Builder.Builder6} with the required parameters.
|
|
1897
|
+
*
|
|
1697
1898
|
* @return the {@link CTLocalInApp.Builder.Builder6} instance
|
|
1698
1899
|
*/
|
|
1699
1900
|
private CTLocalInApp.Builder.Builder6 getLocalInAppBuilderWithRequiredParam(CTLocalInApp.InAppType inAppType,
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1901
|
+
String titleText,
|
|
1902
|
+
String messageText,
|
|
1903
|
+
boolean followDeviceOrientation,
|
|
1904
|
+
String positiveBtnText,
|
|
1905
|
+
String negativeBtnText) {
|
|
1705
1906
|
//throws exception if any of the required parameter is missing
|
|
1706
1907
|
if (inAppType == null || titleText == null || messageText == null || positiveBtnText == null
|
|
1707
1908
|
|| negativeBtnText == null) {
|
|
@@ -1719,7 +1920,7 @@ public class CleverTapModule extends ReactContextBaseJavaModule implements SyncL
|
|
|
1719
1920
|
|
|
1720
1921
|
//returns InAppType type from the given string
|
|
1721
1922
|
private CTLocalInApp.InAppType inAppTypeFromString(String inAppType) {
|
|
1722
|
-
if(inAppType == null) {
|
|
1923
|
+
if (inAppType == null) {
|
|
1723
1924
|
return null;
|
|
1724
1925
|
}
|
|
1725
1926
|
switch (inAppType) {
|