clevertap-react-native 3.0.0 → 3.1.1
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 +29 -0
- package/android/build.gradle +3 -3
- package/android/gradle/wrapper/gradle-wrapper.properties +3 -3
- package/android/gradlew +0 -0
- package/android/src/main/java/com/clevertap/react/CleverTapCustomTemplates.kt +66 -0
- package/android/src/main/java/com/clevertap/react/CleverTapEvent.kt +9 -2
- package/android/src/main/java/com/clevertap/react/CleverTapModuleImpl.java +180 -0
- package/android/src/main/java/com/clevertap/react/CleverTapUtils.java +5 -7
- package/android/src/newarch/CleverTapModule.kt +92 -0
- package/android/src/oldarch/CleverTapModule.kt +108 -2
- package/clevertap-react-native.podspec +1 -1
- package/docs/CustomCodeTemplates.md +215 -0
- package/docs/Variables.md +55 -0
- package/docs/integration.md +42 -46
- package/ios/CleverTapReact/CleverTapReact.h +8 -1
- package/ios/CleverTapReact/CleverTapReact.mm +208 -23
- package/ios/CleverTapReact/CleverTapReactAppFunctionPresenter.h +20 -0
- package/ios/CleverTapReact/CleverTapReactAppFunctionPresenter.mm +21 -0
- package/ios/CleverTapReact/CleverTapReactCustomTemplates.h +42 -0
- package/ios/CleverTapReact/CleverTapReactCustomTemplates.mm +51 -0
- package/ios/CleverTapReact/CleverTapReactManager.h +0 -1
- package/ios/CleverTapReact/CleverTapReactManager.mm +0 -17
- package/ios/CleverTapReact/CleverTapReactTemplatePresenter.h +22 -0
- package/ios/CleverTapReact/CleverTapReactTemplatePresenter.mm +21 -0
- package/ios/CleverTapReact.xcodeproj/project.pbxproj +24 -0
- package/package.json +3 -3
- package/src/NativeCleverTapModule.ts +24 -1
- package/src/index.d.ts +150 -10
- package/src/index.js +187 -3
- package/android/.gradle/8.2/checksums/checksums.lock +0 -0
- package/android/.gradle/8.2/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/8.2/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/8.2/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/8.2/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.2/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/8.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/8.2/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.2/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/8.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.2/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/8.2/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/config.properties +0 -2
- package/android/.gradle/file-system.probe +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.settings/org.eclipse.buildship.core.prefs +0 -2
- package/android/local.properties +0 -8
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
#import "CleverTap+CTVar.h"
|
|
21
21
|
#import "CTVar.h"
|
|
22
22
|
#import "CleverTapReactPendingEvent.h"
|
|
23
|
+
#import "CTTemplateContext.h"
|
|
23
24
|
|
|
24
25
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
25
26
|
#import <CTTurboModuleSpec/CTTurboModuleSpec.h>
|
|
@@ -60,10 +61,15 @@ RCT_EXPORT_MODULE();
|
|
|
60
61
|
kCleverTapPushNotificationClicked: kCleverTapPushNotificationClicked,
|
|
61
62
|
kCleverTapPushPermissionResponseReceived: kCleverTapPushPermissionResponseReceived,
|
|
62
63
|
kCleverTapInAppNotificationShowed: kCleverTapInAppNotificationShowed,
|
|
63
|
-
kCleverTapOnVariablesChanged:
|
|
64
|
-
|
|
65
|
-
kCleverTapOnValueChanged:
|
|
66
|
-
|
|
64
|
+
kCleverTapOnVariablesChanged: kCleverTapOnVariablesChanged,
|
|
65
|
+
kCleverTapOnOneTimeVariablesChanged: kCleverTapOnOneTimeVariablesChanged,
|
|
66
|
+
kCleverTapOnValueChanged: kCleverTapOnValueChanged,
|
|
67
|
+
kCleverTapOnVariablesChangedAndNoDownloadsPending: kCleverTapOnVariablesChangedAndNoDownloadsPending,
|
|
68
|
+
kCleverTapOnceVariablesChangedAndNoDownloadsPending: kCleverTapOnceVariablesChangedAndNoDownloadsPending,
|
|
69
|
+
kCleverTapOnFileValueChanged: kCleverTapOnFileValueChanged,
|
|
70
|
+
kCleverTapCustomTemplatePresent: kCleverTapCustomTemplatePresent,
|
|
71
|
+
kCleverTapCustomFunctionPresent: kCleverTapCustomFunctionPresent,
|
|
72
|
+
kCleverTapCustomTemplateClose: kCleverTapCustomTemplateClose,
|
|
67
73
|
kXPS: kXPS
|
|
68
74
|
};
|
|
69
75
|
}
|
|
@@ -1032,6 +1038,15 @@ RCT_EXPORT_METHOD(defineVariables:(NSDictionary*)variables) {
|
|
|
1032
1038
|
}];
|
|
1033
1039
|
}
|
|
1034
1040
|
|
|
1041
|
+
RCT_EXPORT_METHOD(defineFileVariable:(NSString*)fileVariable) {
|
|
1042
|
+
RCTLogInfo(@"[CleverTap defineFileVariable]");
|
|
1043
|
+
if (!fileVariable) return;
|
|
1044
|
+
CTVar *fileVar = [[self cleverTapInstance] defineFileVar:fileVariable];
|
|
1045
|
+
if (fileVar) {
|
|
1046
|
+
self.allVariables[fileVariable] = fileVar;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1035
1050
|
RCT_EXPORT_METHOD(onVariablesChanged) {
|
|
1036
1051
|
RCTLogInfo(@"[CleverTap onVariablesChanged]");
|
|
1037
1052
|
[[self cleverTapInstance]onVariablesChanged:^{
|
|
@@ -1039,6 +1054,13 @@ RCT_EXPORT_METHOD(onVariablesChanged) {
|
|
|
1039
1054
|
}];
|
|
1040
1055
|
}
|
|
1041
1056
|
|
|
1057
|
+
RCT_EXPORT_METHOD(onOneTimeVariablesChanged) {
|
|
1058
|
+
RCTLogInfo(@"[CleverTap onOneTimeVariablesChanged]");
|
|
1059
|
+
[[self cleverTapInstance] onceVariablesChanged:^{
|
|
1060
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapOnOneTimeVariablesChanged object:nil userInfo:[self getVariableValues]];
|
|
1061
|
+
}];
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1042
1064
|
RCT_EXPORT_METHOD(onValueChanged:(NSString*)name) {
|
|
1043
1065
|
RCTLogInfo(@"[CleverTap onValueChanged]");
|
|
1044
1066
|
CTVar *var = self.allVariables[name];
|
|
@@ -1052,23 +1074,164 @@ RCT_EXPORT_METHOD(onValueChanged:(NSString*)name) {
|
|
|
1052
1074
|
}
|
|
1053
1075
|
}
|
|
1054
1076
|
|
|
1077
|
+
RCT_EXPORT_METHOD(onVariablesChangedAndNoDownloadsPending) {
|
|
1078
|
+
RCTLogInfo(@"[CleverTap onVariablesChangedAndNoDownloadsPending]");
|
|
1079
|
+
[[self cleverTapInstance]onVariablesChangedAndNoDownloadsPending:^{
|
|
1080
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapOnVariablesChangedAndNoDownloadsPending object:nil userInfo:[self getVariableValues]];
|
|
1081
|
+
}];
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
RCT_EXPORT_METHOD(onceVariablesChangedAndNoDownloadsPending) {
|
|
1085
|
+
RCTLogInfo(@"[CleverTap onceVariablesChangedAndNoDownloadsPending]");
|
|
1086
|
+
[[self cleverTapInstance] onceVariablesChangedAndNoDownloadsPending:^{
|
|
1087
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapOnceVariablesChangedAndNoDownloadsPending object:nil userInfo:[self getVariableValues]];
|
|
1088
|
+
}];
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
RCT_EXPORT_METHOD(onFileValueChanged:(NSString*)name) {
|
|
1092
|
+
RCTLogInfo(@"[CleverTap onFileChanged]");
|
|
1093
|
+
CTVar *var = self.allVariables[name];
|
|
1094
|
+
if (var) {
|
|
1095
|
+
[var onFileIsReady:^{
|
|
1096
|
+
NSDictionary *varFileResult = @{
|
|
1097
|
+
var.name: var.value
|
|
1098
|
+
};
|
|
1099
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:kCleverTapOnFileValueChanged object:nil userInfo:varFileResult];
|
|
1100
|
+
}];
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
# pragma mark - Custom Code Templates
|
|
1105
|
+
|
|
1106
|
+
RCT_EXPORT_METHOD(syncCustomTemplates) {
|
|
1107
|
+
RCTLogInfo(@"[CleverTap syncCustomTemplates]");
|
|
1108
|
+
[[self cleverTapInstance] syncCustomTemplates];
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
RCT_EXPORT_METHOD(syncCustomTemplatesInProd:(BOOL)isProduction) {
|
|
1112
|
+
RCTLogInfo(@"[CleverTap syncCustomTemplates:isProduction]");
|
|
1113
|
+
[[self cleverTapInstance] syncCustomTemplates:isProduction];
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
RCT_EXPORT_METHOD(customTemplateGetBooleanArg:(NSString *)templateName argName:(NSString *)argName resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
1117
|
+
[self resolveWithTemplateContext:templateName resolve:resolve reject:reject block:^id(CTTemplateContext *context) {
|
|
1118
|
+
NSNumber *number = [context numberNamed:argName];
|
|
1119
|
+
return number ? number : [NSNull null];
|
|
1120
|
+
}];
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
RCT_EXPORT_METHOD(customTemplateGetFileArg:(NSString *)templateName argName:(NSString *)argName resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
1124
|
+
[self resolveWithTemplateContext:templateName resolve:resolve reject:reject block:^id(CTTemplateContext *context) {
|
|
1125
|
+
NSString *filePath = [context fileNamed:argName];
|
|
1126
|
+
return filePath ? filePath : [NSNull null];
|
|
1127
|
+
}];
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
RCT_EXPORT_METHOD(customTemplateGetNumberArg:(NSString *)templateName argName:(NSString *)argName resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
1131
|
+
[self resolveWithTemplateContext:templateName resolve:resolve reject:reject block:^id(CTTemplateContext *context) {
|
|
1132
|
+
NSNumber *number = [context numberNamed:argName];
|
|
1133
|
+
return number ? number : [NSNull null];
|
|
1134
|
+
}];
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
RCT_EXPORT_METHOD(customTemplateGetObjectArg:(NSString *)templateName argName:(NSString *)argName resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
1138
|
+
[self resolveWithTemplateContext:templateName resolve:resolve reject:reject block:^id(CTTemplateContext *context) {
|
|
1139
|
+
NSDictionary *dictionary = [context dictionaryNamed:argName];
|
|
1140
|
+
return dictionary ? dictionary : [NSNull null];
|
|
1141
|
+
}];
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
RCT_EXPORT_METHOD(customTemplateGetStringArg:(NSString *)templateName argName:(NSString *)argName resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
1145
|
+
[self resolveWithTemplateContext:templateName resolve:resolve reject:reject block:^id(CTTemplateContext *context) {
|
|
1146
|
+
NSString *str = [context stringNamed:argName];
|
|
1147
|
+
return str ? str : [NSNull null];
|
|
1148
|
+
}];
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
RCT_EXPORT_METHOD(customTemplateRunAction:(NSString *)templateName argName:(NSString *)argName resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
1152
|
+
[self resolveWithTemplateContext:templateName resolve:resolve reject:reject block:^id(CTTemplateContext *context) {
|
|
1153
|
+
[context triggerActionNamed:argName];
|
|
1154
|
+
return nil;
|
|
1155
|
+
}];
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
RCT_EXPORT_METHOD(customTemplateSetDismissed:(NSString *)templateName resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
1159
|
+
[self resolveWithTemplateContext:templateName resolve:resolve reject:reject block:^id(CTTemplateContext *context) {
|
|
1160
|
+
[context dismissed];
|
|
1161
|
+
return nil;
|
|
1162
|
+
}];
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
RCT_EXPORT_METHOD(customTemplateSetPresented:(NSString *)templateName
|
|
1166
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
1167
|
+
reject:(RCTPromiseRejectBlock)reject) {
|
|
1168
|
+
[self resolveWithTemplateContext:templateName resolve:resolve reject:reject block:^id(CTTemplateContext *context) {
|
|
1169
|
+
[context presented];
|
|
1170
|
+
return nil;
|
|
1171
|
+
}];
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
RCT_EXPORT_METHOD(customTemplateContextToString:(NSString *)templateName
|
|
1175
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
1176
|
+
reject:(RCTPromiseRejectBlock)reject) {
|
|
1177
|
+
[self resolveWithTemplateContext:templateName resolve:resolve reject:reject block:^id(CTTemplateContext *context) {
|
|
1178
|
+
return [context debugDescription];
|
|
1179
|
+
}];
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
- (void)resolveWithTemplateContext:(NSString *)templateName
|
|
1183
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
1184
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
1185
|
+
block: (id (^)(CTTemplateContext *context))blockName {
|
|
1186
|
+
if (![self cleverTapInstance]) {
|
|
1187
|
+
reject(@"CustomTemplateError", @"CleverTap is not initialized", nil);
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
CTTemplateContext *context = [[self cleverTapInstance] activeContextForTemplate:templateName];
|
|
1192
|
+
if (!context) {
|
|
1193
|
+
reject(@"CustomTemplateError",
|
|
1194
|
+
[NSString stringWithFormat:@"Custom template: %@ is not currently being presented", templateName],
|
|
1195
|
+
nil);
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
resolve(blockName(context));
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1055
1202
|
# pragma mark - Event emitter
|
|
1056
1203
|
|
|
1204
|
+
/// A collection of events sent before ReactNative has started observing events.
|
|
1057
1205
|
static NSMutableDictionary<NSString *, NSMutableArray<CleverTapReactPendingEvent *> *> *pendingEvents = [NSMutableDictionary dictionary];
|
|
1058
1206
|
|
|
1207
|
+
/// Indicates if ``startObserving`` has been called which means a listener/observer has been added.
|
|
1059
1208
|
static BOOL isObserving;
|
|
1060
|
-
static NSMutableSet<NSString *> *observedEvents = [NSMutableSet set];
|
|
1061
1209
|
|
|
1062
|
-
|
|
1210
|
+
/// A set of event names that a listener/observer has been added for.
|
|
1211
|
+
static NSMutableSet<NSString *> *observedEvents = [NSMutableSet set];
|
|
1063
1212
|
|
|
1213
|
+
/// A set of event names that needs to be observed since they can be sent before ReactNative has started observing events.
|
|
1214
|
+
static NSMutableSet<NSString *> *observableEvents = [NSMutableSet setWithObjects:
|
|
1215
|
+
kCleverTapPushNotificationClicked,
|
|
1216
|
+
kCleverTapProfileDidInitialize,
|
|
1217
|
+
kCleverTapDisplayUnitsLoaded,
|
|
1218
|
+
kCleverTapInAppNotificationShowed,
|
|
1219
|
+
kCleverTapInAppNotificationDismissed,
|
|
1220
|
+
kCleverTapInAppNotificationButtonTapped,
|
|
1221
|
+
kCleverTapProductConfigDidInitialize,
|
|
1222
|
+
kCleverTapCustomTemplatePresent,
|
|
1223
|
+
kCleverTapCustomFunctionPresent,
|
|
1224
|
+
kCleverTapCustomTemplateClose,
|
|
1225
|
+
kCleverTapFeatureFlagsDidUpdate, nil];
|
|
1226
|
+
|
|
1227
|
+
/// Time out in seconds, after which pending events are cleared.
|
|
1228
|
+
/// See ``startObserving`` for details.
|
|
1064
1229
|
const int PENDING_EVENTS_TIME_OUT = 5;
|
|
1065
1230
|
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
* @param name the name of the observed event
|
|
1071
|
-
*/
|
|
1231
|
+
/// Called when a observer/listener is added for the event.
|
|
1232
|
+
/// Post the pending events for the event name.
|
|
1233
|
+
///
|
|
1234
|
+
/// @param name The name of the observed event.
|
|
1072
1235
|
RCT_EXPORT_METHOD(onEventListenerAdded:(NSString*)name) {
|
|
1073
1236
|
[observedEvents addObject:name];
|
|
1074
1237
|
NSArray *pendingEventsForName = pendingEvents[name];
|
|
@@ -1081,16 +1244,14 @@ RCT_EXPORT_METHOD(onEventListenerAdded:(NSString*)name) {
|
|
|
1081
1244
|
}
|
|
1082
1245
|
}
|
|
1083
1246
|
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
* @param body the event body parameters
|
|
1093
|
-
*/
|
|
1247
|
+
/// Send event when ReactNative has started observing events.
|
|
1248
|
+
/// This happens when the first observer/listener is added in ReactNative.
|
|
1249
|
+
/// If events are sent before that, the events are queued.
|
|
1250
|
+
/// Events expected to be queued are specified in ``observableEvents``.
|
|
1251
|
+
/// If ReactNative has started observing and the event is observed, see ``observedEvents``, the events are emitted directly.
|
|
1252
|
+
///
|
|
1253
|
+
/// @param name The event name.
|
|
1254
|
+
/// @param body The event body parameters.
|
|
1094
1255
|
+ (void)sendEventOnObserving:(NSString *)name body:(id)body {
|
|
1095
1256
|
if (!isObserving && ![observableEvents containsObject:name]) {
|
|
1096
1257
|
RCTLogWarn(@"[CleverTap: %@ is sent before observing and is not part of the observable events]", name);
|
|
@@ -1111,7 +1272,31 @@ RCT_EXPORT_METHOD(onEventListenerAdded:(NSString*)name) {
|
|
|
1111
1272
|
}
|
|
1112
1273
|
|
|
1113
1274
|
- (NSArray<NSString *> *)supportedEvents {
|
|
1114
|
-
return @[kCleverTapProfileDidInitialize,
|
|
1275
|
+
return @[kCleverTapProfileDidInitialize,
|
|
1276
|
+
kCleverTapProfileSync,
|
|
1277
|
+
kCleverTapInAppNotificationShowed,
|
|
1278
|
+
kCleverTapInAppNotificationDismissed,
|
|
1279
|
+
kCleverTapInAppNotificationButtonTapped,
|
|
1280
|
+
kCleverTapInboxDidInitialize,
|
|
1281
|
+
kCleverTapInboxMessagesDidUpdate,
|
|
1282
|
+
kCleverTapInboxMessageButtonTapped,
|
|
1283
|
+
kCleverTapInboxMessageTapped,
|
|
1284
|
+
kCleverTapDisplayUnitsLoaded,
|
|
1285
|
+
kCleverTapFeatureFlagsDidUpdate,
|
|
1286
|
+
kCleverTapProductConfigDidFetch,
|
|
1287
|
+
kCleverTapProductConfigDidActivate,
|
|
1288
|
+
kCleverTapProductConfigDidInitialize,
|
|
1289
|
+
kCleverTapPushNotificationClicked,
|
|
1290
|
+
kCleverTapPushPermissionResponseReceived,
|
|
1291
|
+
kCleverTapOnVariablesChanged,
|
|
1292
|
+
kCleverTapOnOneTimeVariablesChanged,
|
|
1293
|
+
kCleverTapOnValueChanged,
|
|
1294
|
+
kCleverTapOnVariablesChangedAndNoDownloadsPending,
|
|
1295
|
+
kCleverTapOnceVariablesChangedAndNoDownloadsPending,
|
|
1296
|
+
kCleverTapOnFileValueChanged,
|
|
1297
|
+
kCleverTapCustomTemplatePresent,
|
|
1298
|
+
kCleverTapCustomFunctionPresent,
|
|
1299
|
+
kCleverTapCustomTemplateClose];
|
|
1115
1300
|
}
|
|
1116
1301
|
|
|
1117
1302
|
- (void)startObserving {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CleverTapReactAppFunctionPresenter.h
|
|
3
|
+
// CleverTapReact
|
|
4
|
+
//
|
|
5
|
+
// Created by Nikola Zagorchev on 2.10.24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
#import "CTTemplatePresenter.h"
|
|
10
|
+
|
|
11
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
12
|
+
|
|
13
|
+
/// A `CTTemplatePresenter` handling App Functions presentation.
|
|
14
|
+
/// Posts a `kCleverTapCustomFunctionPresent` notification to ReactNative
|
|
15
|
+
/// when an App Function onPresent is called.
|
|
16
|
+
@interface CleverTapReactAppFunctionPresenter : NSObject <CTTemplatePresenter>
|
|
17
|
+
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CleverTapReactAppFunctionPresenter.m
|
|
3
|
+
// CleverTapReact
|
|
4
|
+
//
|
|
5
|
+
// Created by Nikola Zagorchev on 2.10.24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import "CleverTapReactAppFunctionPresenter.h"
|
|
9
|
+
#import "CleverTapReact.h"
|
|
10
|
+
|
|
11
|
+
@implementation CleverTapReactAppFunctionPresenter
|
|
12
|
+
|
|
13
|
+
- (void)onPresent:(nonnull CTTemplateContext *)context {
|
|
14
|
+
[CleverTapReact sendEventOnObserving:kCleverTapCustomFunctionPresent body:context.templateName];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
- (void)onCloseClicked:(nonnull CTTemplateContext *)context {
|
|
18
|
+
// NOOP - App Functions cannot have Action arguments.
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CleverTapReactCustomTemplates.h
|
|
3
|
+
// CleverTapReact
|
|
4
|
+
//
|
|
5
|
+
// Created by Nikola Zagorchev on 2.10.24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
|
|
10
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
11
|
+
|
|
12
|
+
/// Registers Custom Templates and App Functions using JSON templates definitions.
|
|
13
|
+
@interface CleverTapReactCustomTemplates : NSObject
|
|
14
|
+
|
|
15
|
+
/// Registers Custom Templates and App Functions given JSON templates definition file names.
|
|
16
|
+
/// Provide the file name only, without the json extension.
|
|
17
|
+
/// Uses the main bundle to get the file path. Ensure the files are aded to the Copy Bundle Resources phase.
|
|
18
|
+
/// Supports multiple file names with a nil termination.
|
|
19
|
+
///
|
|
20
|
+
/// Example registering Custom Templates and App Functions using JSON templates definition.
|
|
21
|
+
/// The JSON file name is "templates.json".
|
|
22
|
+
/// ```
|
|
23
|
+
/// [CleverTapReactCustomTemplates registerCustomTemplates:@"templates", nil];
|
|
24
|
+
/// ```
|
|
25
|
+
///
|
|
26
|
+
/// @param firstJsonAsset The first JSON templates definition file name.
|
|
27
|
+
/// @param ... A comma-separated list of additional file names, ending with nil.
|
|
28
|
+
+ (void)registerCustomTemplates:(NSString *)firstJsonAsset, ... NS_REQUIRES_NIL_TERMINATION;
|
|
29
|
+
|
|
30
|
+
/// Registers Custom Templates and App Functions given JSON templates definition file names.
|
|
31
|
+
/// Use the bundle where the resources are.
|
|
32
|
+
/// Provide the file name only, without the json extension.
|
|
33
|
+
/// Supports multiple file names with a nil termination.
|
|
34
|
+
///
|
|
35
|
+
/// @param bundle The bundle where the JSON resources are.
|
|
36
|
+
/// @param firstJsonAsset The first JSON templates definition file name.
|
|
37
|
+
/// @param ... A comma-separated list of additional file names, ending with nil.
|
|
38
|
+
+ (void)registerCustomTemplates:(NSBundle *)bundle jsonFileNames:(NSString *)firstJsonAsset, ... NS_REQUIRES_NIL_TERMINATION;
|
|
39
|
+
|
|
40
|
+
@end
|
|
41
|
+
|
|
42
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CleverTapReactCustomTemplates.m
|
|
3
|
+
// CleverTapReact
|
|
4
|
+
//
|
|
5
|
+
// Created by Nikola Zagorchev on 2.10.24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <React/RCTLog.h>
|
|
9
|
+
|
|
10
|
+
#import "CleverTapReactCustomTemplates.h"
|
|
11
|
+
#import "CleverTapReactTemplatePresenter.h"
|
|
12
|
+
#import "CleverTapReactAppFunctionPresenter.h"
|
|
13
|
+
#import "CTJsonTemplateProducer.h"
|
|
14
|
+
#import "CTCustomTemplatesManager.h"
|
|
15
|
+
|
|
16
|
+
@implementation CleverTapReactCustomTemplates
|
|
17
|
+
|
|
18
|
+
+ (void)registerCustomTemplates:(nonnull NSString *)firstJsonAsset, ... NS_REQUIRES_NIL_TERMINATION {
|
|
19
|
+
va_list args;
|
|
20
|
+
va_start(args, firstJsonAsset);
|
|
21
|
+
|
|
22
|
+
NSBundle *bundle = [NSBundle mainBundle];
|
|
23
|
+
[self registerCustomTemplates:bundle firstJsonAsset:firstJsonAsset args:args];
|
|
24
|
+
va_end(args);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
+ (void)registerCustomTemplates:(nonnull NSBundle *)bundle jsonFileNames:(nonnull NSString *)firstJsonAsset, ... NS_REQUIRES_NIL_TERMINATION {
|
|
28
|
+
va_list args;
|
|
29
|
+
va_start(args, firstJsonAsset);
|
|
30
|
+
|
|
31
|
+
[self registerCustomTemplates:bundle firstJsonAsset:firstJsonAsset args:args];
|
|
32
|
+
va_end(args);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
+ (void)registerCustomTemplates:(NSBundle * _Nonnull)bundle firstJsonAsset:(NSString * _Nonnull)firstJsonAsset args:(va_list)args {
|
|
36
|
+
CleverTapReactTemplatePresenter *templatePresenter = [[CleverTapReactTemplatePresenter alloc] init];
|
|
37
|
+
CleverTapReactAppFunctionPresenter *functionPresenter = [[CleverTapReactAppFunctionPresenter alloc] init];
|
|
38
|
+
for (NSString *arg = firstJsonAsset; arg != nil; arg = va_arg(args, NSString*)) {
|
|
39
|
+
NSString *filePath = [bundle pathForResource:arg ofType:@"json"];
|
|
40
|
+
if (filePath) {
|
|
41
|
+
NSString *definitionsJson = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
|
|
42
|
+
|
|
43
|
+
CTJsonTemplateProducer *producer = [[CTJsonTemplateProducer alloc] initWithJson:definitionsJson templatePresenter:templatePresenter functionPresenter:functionPresenter];
|
|
44
|
+
[CleverTap registerCustomInAppTemplates:producer];
|
|
45
|
+
} else {
|
|
46
|
+
RCTLogError(@"Custom templates JSON file not found. File name: \"%@\" in bundle: %@.", arg, bundle);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@end
|
|
@@ -38,11 +38,6 @@
|
|
|
38
38
|
- (instancetype)init {
|
|
39
39
|
self = [super init];
|
|
40
40
|
if (self) {
|
|
41
|
-
|
|
42
|
-
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
43
|
-
selector:@selector(handleContentDidAppearNotification:)
|
|
44
|
-
name:RCTContentDidAppearNotification
|
|
45
|
-
object:nil];
|
|
46
41
|
CleverTap *clevertap = [CleverTap sharedInstance];
|
|
47
42
|
[self setDelegates:clevertap];
|
|
48
43
|
}
|
|
@@ -63,7 +58,6 @@
|
|
|
63
58
|
- (void)applicationDidLaunchWithOptions:(NSDictionary *)options {
|
|
64
59
|
NSDictionary *notification = [options valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
|
|
65
60
|
if (notification){
|
|
66
|
-
self.pendingPushNotificationExtras = notification;
|
|
67
61
|
if (notification[@"wzrk_dl"]) {
|
|
68
62
|
self.launchDeepLink = notification[@"wzrk_dl"];
|
|
69
63
|
RCTLogInfo(@"CleverTapReact: setting launch deeplink: %@", self.launchDeepLink);
|
|
@@ -171,15 +165,4 @@
|
|
|
171
165
|
[self postNotificationWithName:kCleverTapPushPermissionResponseReceived andBody:body];
|
|
172
166
|
}
|
|
173
167
|
|
|
174
|
-
- (void)handleContentDidAppearNotification:(NSNotification *)notification {
|
|
175
|
-
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
176
|
-
|
|
177
|
-
NSMutableDictionary *pushNotificationExtras = [NSMutableDictionary new];
|
|
178
|
-
NSDictionary *customExtras = self.pendingPushNotificationExtras;
|
|
179
|
-
if (customExtras != nil) {
|
|
180
|
-
pushNotificationExtras = [NSMutableDictionary dictionaryWithDictionary:customExtras];
|
|
181
|
-
[self postNotificationWithName:kCleverTapPushNotificationClicked andBody:pushNotificationExtras];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
168
|
@end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CleverTapReactTemplatePresenter.h
|
|
3
|
+
// CleverTapReact
|
|
4
|
+
//
|
|
5
|
+
// Created by Nikola Zagorchev on 2.10.24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
#import "CTTemplatePresenter.h"
|
|
10
|
+
|
|
11
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
12
|
+
|
|
13
|
+
/// A `CTTemplatePresenter` handling Custom Templates presentation.
|
|
14
|
+
/// Posts a `kCleverTapCustomTemplatePresent` notification to ReactNative
|
|
15
|
+
/// when a Custom Template `onPresent:` is called.
|
|
16
|
+
/// Posts a `kCleverTapCustomTemplateClose` notification to ReactNative
|
|
17
|
+
/// when a Custom Template `onCloseClicked:` is called.
|
|
18
|
+
@interface CleverTapReactTemplatePresenter : NSObject <CTTemplatePresenter>
|
|
19
|
+
|
|
20
|
+
@end
|
|
21
|
+
|
|
22
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// CleverTapReactTemplatePresenter.m
|
|
3
|
+
// CleverTapReact
|
|
4
|
+
//
|
|
5
|
+
// Created by Nikola Zagorchev on 2.10.24.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import "CleverTapReactTemplatePresenter.h"
|
|
9
|
+
#import "CleverTapReact.h"
|
|
10
|
+
|
|
11
|
+
@implementation CleverTapReactTemplatePresenter
|
|
12
|
+
|
|
13
|
+
- (void)onPresent:(nonnull CTTemplateContext *)context {
|
|
14
|
+
[CleverTapReact sendEventOnObserving:kCleverTapCustomTemplatePresent body:context.templateName];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
- (void)onCloseClicked:(nonnull CTTemplateContext *)context {
|
|
18
|
+
[CleverTapReact sendEventOnObserving:kCleverTapCustomTemplateClose body:context.templateName];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@end
|
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
5266DAB91E4B9C16000008F5 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5266DAB61E4B9B8C000008F5 /* UIKit.framework */; };
|
|
16
16
|
5266DABA1E4B9C20000008F5 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52DFC6831E4B990A00EDC368 /* SystemConfiguration.framework */; };
|
|
17
17
|
5266DADB1E4BB5BD000008F5 /* CleverTapSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5266DAD91E4BB598000008F5 /* CleverTapSDK.framework */; };
|
|
18
|
+
6B102BB02CAD8B7800296828 /* CleverTapReactCustomTemplates.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B102BAE2CAD8B7800296828 /* CleverTapReactCustomTemplates.h */; };
|
|
19
|
+
6B102BB42CAD8BB700296828 /* CleverTapReactTemplatePresenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B102BB22CAD8BB700296828 /* CleverTapReactTemplatePresenter.h */; };
|
|
20
|
+
6B102BB82CAD8BEE00296828 /* CleverTapReactAppFunctionPresenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B102BB62CAD8BEE00296828 /* CleverTapReactAppFunctionPresenter.h */; };
|
|
21
|
+
6B102BBF2CADE31500296828 /* CleverTapReactCustomTemplates.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6B102BBC2CADE31500296828 /* CleverTapReactCustomTemplates.mm */; };
|
|
22
|
+
6B102BC02CADE31500296828 /* CleverTapReactTemplatePresenter.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6B102BBD2CADE31500296828 /* CleverTapReactTemplatePresenter.mm */; };
|
|
23
|
+
6B102BC12CADE31500296828 /* CleverTapReactAppFunctionPresenter.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6B102BBE2CADE31500296828 /* CleverTapReactAppFunctionPresenter.mm */; };
|
|
18
24
|
6B587A032BC02ECD0077493E /* CleverTapReactPendingEvent.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6B587A022BC02ECD0077493E /* CleverTapReactPendingEvent.mm */; };
|
|
19
25
|
6B587A042BC02ECD0077493E /* CleverTapReactPendingEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B587A012BC02ECD0077493E /* CleverTapReactPendingEvent.h */; };
|
|
20
26
|
/* End PBXBuildFile section */
|
|
@@ -43,6 +49,12 @@
|
|
|
43
49
|
52DFC6831E4B990A00EDC368 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
|
|
44
50
|
52DFC6851E4B991000EDC368 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; };
|
|
45
51
|
5D72D2E81C16249000E22EC1 /* libCleverTapReact.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCleverTapReact.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
52
|
+
6B102BAE2CAD8B7800296828 /* CleverTapReactCustomTemplates.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CleverTapReactCustomTemplates.h; sourceTree = "<group>"; };
|
|
53
|
+
6B102BB22CAD8BB700296828 /* CleverTapReactTemplatePresenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CleverTapReactTemplatePresenter.h; sourceTree = "<group>"; };
|
|
54
|
+
6B102BB62CAD8BEE00296828 /* CleverTapReactAppFunctionPresenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CleverTapReactAppFunctionPresenter.h; sourceTree = "<group>"; };
|
|
55
|
+
6B102BBC2CADE31500296828 /* CleverTapReactCustomTemplates.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CleverTapReactCustomTemplates.mm; sourceTree = "<group>"; };
|
|
56
|
+
6B102BBD2CADE31500296828 /* CleverTapReactTemplatePresenter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CleverTapReactTemplatePresenter.mm; sourceTree = "<group>"; };
|
|
57
|
+
6B102BBE2CADE31500296828 /* CleverTapReactAppFunctionPresenter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CleverTapReactAppFunctionPresenter.mm; sourceTree = "<group>"; };
|
|
46
58
|
6B587A012BC02ECD0077493E /* CleverTapReactPendingEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CleverTapReactPendingEvent.h; sourceTree = "<group>"; };
|
|
47
59
|
6B587A022BC02ECD0077493E /* CleverTapReactPendingEvent.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CleverTapReactPendingEvent.mm; sourceTree = "<group>"; };
|
|
48
60
|
/* End PBXFileReference section */
|
|
@@ -71,6 +83,12 @@
|
|
|
71
83
|
52344FBC1E4CE7F000661762 /* CleverTapReactManager.mm */,
|
|
72
84
|
6B587A012BC02ECD0077493E /* CleverTapReactPendingEvent.h */,
|
|
73
85
|
6B587A022BC02ECD0077493E /* CleverTapReactPendingEvent.mm */,
|
|
86
|
+
6B102BAE2CAD8B7800296828 /* CleverTapReactCustomTemplates.h */,
|
|
87
|
+
6B102BBC2CADE31500296828 /* CleverTapReactCustomTemplates.mm */,
|
|
88
|
+
6B102BB22CAD8BB700296828 /* CleverTapReactTemplatePresenter.h */,
|
|
89
|
+
6B102BBD2CADE31500296828 /* CleverTapReactTemplatePresenter.mm */,
|
|
90
|
+
6B102BB62CAD8BEE00296828 /* CleverTapReactAppFunctionPresenter.h */,
|
|
91
|
+
6B102BBE2CADE31500296828 /* CleverTapReactAppFunctionPresenter.mm */,
|
|
74
92
|
);
|
|
75
93
|
path = CleverTapReact;
|
|
76
94
|
sourceTree = "<group>";
|
|
@@ -110,6 +128,9 @@
|
|
|
110
128
|
isa = PBXHeadersBuildPhase;
|
|
111
129
|
buildActionMask = 2147483647;
|
|
112
130
|
files = (
|
|
131
|
+
6B102BB42CAD8BB700296828 /* CleverTapReactTemplatePresenter.h in Headers */,
|
|
132
|
+
6B102BB02CAD8B7800296828 /* CleverTapReactCustomTemplates.h in Headers */,
|
|
133
|
+
6B102BB82CAD8BEE00296828 /* CleverTapReactAppFunctionPresenter.h in Headers */,
|
|
113
134
|
52344FC21E4CEC3200661762 /* CleverTapReactManager.h in Headers */,
|
|
114
135
|
6B587A042BC02ECD0077493E /* CleverTapReactPendingEvent.h in Headers */,
|
|
115
136
|
);
|
|
@@ -174,8 +195,11 @@
|
|
|
174
195
|
buildActionMask = 2147483647;
|
|
175
196
|
files = (
|
|
176
197
|
52344FBF1E4CE7F000661762 /* CleverTapReactManager.mm in Sources */,
|
|
198
|
+
6B102BC12CADE31500296828 /* CleverTapReactAppFunctionPresenter.mm in Sources */,
|
|
177
199
|
52344FBE1E4CE7F000661762 /* CleverTapReact.mm in Sources */,
|
|
200
|
+
6B102BBF2CADE31500296828 /* CleverTapReactCustomTemplates.mm in Sources */,
|
|
178
201
|
6B587A032BC02ECD0077493E /* CleverTapReactPendingEvent.mm in Sources */,
|
|
202
|
+
6B102BC02CADE31500296828 /* CleverTapReactTemplatePresenter.mm in Sources */,
|
|
179
203
|
);
|
|
180
204
|
runOnlyForDeploymentPostprocessing = 0;
|
|
181
205
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clevertap-react-native",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "CleverTap React Native SDK.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"segmentation"
|
|
33
33
|
],
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"react-native": "
|
|
35
|
+
"react-native": ">=0.65.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"eslint": "^4.18.2",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"eslint-plugin-standard": "^2.0.0",
|
|
45
45
|
"i": "^0.3.6",
|
|
46
46
|
"react": "^17.0.2",
|
|
47
|
-
"react-native": "
|
|
47
|
+
"react-native": ">=0.65.0"
|
|
48
48
|
},
|
|
49
49
|
"codegenConfig": {
|
|
50
50
|
"name": "CTTurboModuleSpec",
|