react-native-userleap 4.0.0 → 4.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.
@@ -1,287 +0,0 @@
1
- #import "UserLeapBindings.h"
2
- #import <React/RCTUtils.h>
3
- #import <React/RCTView.h>
4
-
5
- @implementation UserLeapBindings
6
-
7
- - (dispatch_queue_t)methodQueue
8
- {
9
- return dispatch_get_main_queue();
10
- }
11
-
12
- -(NSDictionary *) parseSurveyResult:(SprigSurveyResult *)result {
13
- SurveyState state = [result surveyState];
14
- NSString *surveyStateString = [self getSurveyState:state];
15
- NSInteger surveyId = [result surveyId];
16
- return @{@"surveyState": surveyStateString, @"surveyId": @(surveyId)};
17
- }
18
-
19
- - (NSString *)getSurveyState:(SurveyState)surveyState
20
- {
21
- NSString *surveyStateBinding = @"NO_SURVEY";
22
- switch(surveyState) {
23
- case SurveyStateDisabled:
24
- surveyStateBinding = @"DISABLED";
25
- break;
26
- case SurveyStateReady:
27
- surveyStateBinding = @"READY";
28
- break;
29
- case SurveyStateNoSurvey:
30
- surveyStateBinding = @"NO_SURVEY";
31
- break;
32
- case SurveyStatePreviousSurveyReady:
33
- surveyStateBinding = @"PREVIOUS_SURVEY_READY";
34
- break;
35
- }
36
- return surveyStateBinding;
37
- }
38
-
39
- RCT_EXPORT_MODULE()
40
-
41
- RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(visitorIdentifier)
42
- {
43
- return [[UserLeap shared] visitorIdentifier];
44
- }
45
-
46
- RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(visitorIdentifierString)
47
- {
48
- return [[UserLeap shared] visitorIdentifierString];
49
- }
50
-
51
- RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(sdkVersion)
52
- {
53
- return [[UserLeap shared] sdkVersion];
54
- }
55
-
56
- RCT_EXPORT_METHOD(configure:(NSString *)environmentId configuration:(NSDictionary *)configuration )
57
- {
58
- [[UserLeap shared] configureWithEnvironment:environmentId configuration:configuration];
59
- [[UserLeap shared] _passWithRnExtractor:self];
60
- }
61
-
62
-
63
- RCT_EXPORT_METHOD(setPreviewKey:(NSString *)previewKey)
64
- {
65
- [[UserLeap shared] setPreviewKey:previewKey];
66
- }
67
-
68
- RCT_EXPORT_METHOD(presentSurvey)
69
- {
70
- [[UserLeap shared] presentSurveyFrom:RCTPresentedViewController()];
71
- }
72
-
73
- /// Use trackEvent instead of track
74
- RCT_EXPORT_METHOD(track:(NSString *)eventName
75
- surveyStateCallback:(RCTResponseSenderBlock)callback)
76
- {
77
- if (callback != nil) {
78
- [[UserLeap shared] trackWithEventName:eventName handler:^(enum SurveyState surveyState) {
79
- callback(@[[self getSurveyState:surveyState]]);
80
- }];
81
- } else {
82
- [[UserLeap shared] trackWithEventName:eventName handler:nil];
83
- }
84
- }
85
-
86
- RCT_EXPORT_METHOD(trackEvent:(NSString *)eventName
87
- surveyResultCallback:(RCTResponseSenderBlock)callback)
88
- {
89
- EventPayload *payload = [[EventPayload alloc] initWithEventName:eventName userId:nil partnerAnonymousId:nil properties:nil handler:nil resultHandler:^(SprigSurveyResult * result) {
90
- if (callback != nil) {
91
- callback(@[[self parseSurveyResult:result]]);
92
- }
93
- }];
94
- [[UserLeap shared] trackWithPayload: payload];
95
- }
96
-
97
- /// Use trackEventWithProperties instead of trackWithProperties
98
- RCT_EXPORT_METHOD(trackWithProperties:(NSString *)eventName
99
- userId:(NSString * _Nullable)userId
100
- partnerAnonymousId:(NSString * _Nullable)partnerAnonymousId
101
- properties: (NSDictionary *)properties
102
- surveyStateCallback:(RCTResponseSenderBlock)callback)
103
- {
104
- [[UserLeap shared] trackWithEventName:eventName userId:userId partnerAnonymousId:partnerAnonymousId properties:properties handler:^(enum SurveyState surveyState) {
105
- callback(@[[self getSurveyState:surveyState]]);
106
- }];
107
-
108
- }
109
-
110
- RCT_EXPORT_METHOD(trackEventWithProperties:(NSString *)eventName
111
- userId:(NSString * _Nullable)userId
112
- partnerAnonymousId:(NSString * _Nullable)partnerAnonymousId
113
- properties: (NSDictionary *)properties
114
- surveyResultCallback:(RCTResponseSenderBlock)callback)
115
- {
116
- EventPayload *payload = [[EventPayload alloc] initWithEventName:eventName
117
- userId:userId
118
- partnerAnonymousId:partnerAnonymousId
119
- properties:properties
120
- handler:nil
121
- resultHandler:^(SprigSurveyResult * result) {
122
- if (callback != nil) {
123
- callback(@[[self parseSurveyResult:result]]);
124
- }
125
- }];
126
- [[UserLeap shared] trackWithPayload: payload];
127
- }
128
-
129
- /// Use trackEventAndIdentify instead of trackAndIdentify
130
- RCT_EXPORT_METHOD(trackAndIdentify:(NSString *)eventName
131
- userId:(NSString *)userId
132
- partnerAnonymousId:(NSString *)partnerAnonymousId
133
- handler:(RCTResponseSenderBlock)callback)
134
- {
135
- if (callback != nil) {
136
- [[UserLeap shared] trackWithEventName:eventName userId:userId partnerAnonymousId:partnerAnonymousId handler:^(enum SurveyState surveyState) {
137
- callback(@[[self getSurveyState:surveyState]]);
138
- }];
139
- } else {
140
- [[UserLeap shared] trackWithEventName:eventName userId:userId partnerAnonymousId:partnerAnonymousId handler:nil];
141
- }
142
- }
143
-
144
- RCT_EXPORT_METHOD(trackEventAndIdentify:(NSString *)eventName
145
- userId:(NSString *)userId
146
- partnerAnonymousId:(NSString *)partnerAnonymousId
147
- surveyResultCallback:(RCTResponseSenderBlock)callback)
148
- {
149
- EventPayload *payload = [[EventPayload alloc] initWithEventName:eventName
150
- userId:userId
151
- partnerAnonymousId:partnerAnonymousId
152
- properties:nil
153
- handler:nil
154
- resultHandler:^(SprigSurveyResult * result) {
155
- if (callback != nil) {
156
- callback(@[[self parseSurveyResult:result]]);
157
- }
158
- }];
159
- [[UserLeap shared] trackWithPayload: payload];
160
- }
161
-
162
- RCT_EXPORT_METHOD(setEmailAddress:(NSString *)emailAddress)
163
- {
164
- [[UserLeap shared] setEmailAddress:emailAddress];
165
- }
166
-
167
- RCT_EXPORT_METHOD(setVisitorAttribute:(NSString *)key value: (NSString *)value)
168
- {
169
- [[UserLeap shared] setVisitorAttributeWithKey:key value:value];
170
- }
171
-
172
- RCT_EXPORT_METHOD(setVisitorAttributes:(NSDictionary *)attributes)
173
- {
174
- [[UserLeap shared] setVisitorAttributes:attributes];
175
- }
176
-
177
- RCT_EXPORT_METHOD(setVisitorAttributesAndIdentify:(NSDictionary *)attributes userId:(NSString *)userId partnerAnonymousId:(NSString*)partnerAnonymousId)
178
- {
179
- [[UserLeap shared] setVisitorAttributes:attributes userId:userId partnerAnonymousId:partnerAnonymousId];
180
- }
181
-
182
- RCT_EXPORT_METHOD(removeVisitorAttributes:(NSArray<NSString *> *)attributes)
183
- {
184
- [[UserLeap shared] removeVisitorAttributes:attributes];
185
- }
186
-
187
- RCT_EXPORT_METHOD(setUserIdentifier:(NSString *)identifier)
188
- {
189
- [[UserLeap shared] setUserIdentifier:identifier];
190
- }
191
-
192
- RCT_EXPORT_METHOD(logout)
193
- {
194
- [[UserLeap shared] logout];
195
- }
196
-
197
- RCT_EXPORT_METHOD(trackAndPresent:(NSString *)eventName)
198
- {
199
- [[UserLeap shared] trackAndPresentWithEventName:eventName from:RCTPresentedViewController()];
200
- }
201
-
202
- RCT_EXPORT_METHOD(trackIdentifyAndPresent:(NSString *)eventName userId:(NSString *)userId partnerAnonymousId:(NSString *)partnerAnonymousId)
203
- {
204
- [[UserLeap shared] trackAndPresentWithEventName:eventName userId:userId partnerAnonymousId:partnerAnonymousId from:RCTPresentedViewController()];
205
- }
206
-
207
- - (_SGRNTextProperties *)textPropertiesFromView:(UIView * _Nonnull)passedView {
208
-
209
- // Text under new arch.
210
- Class ParagraphComponentView = NSClassFromString(@"RCTParagraphComponentView");
211
- if (ParagraphComponentView && [passedView isKindOfClass:ParagraphComponentView]) {
212
- NSString *text = [self extractTextFromParagraphComponentView:passedView];
213
- if (text.length == 0) return nil;
214
- _SGRNTextProperties *textProperties = [[_SGRNTextProperties alloc] init];
215
- textProperties.text = text;
216
- if ([passedView respondsToSelector:@selector(attributedText)]) {
217
- NSAttributedString *attrText = [passedView performSelector:@selector(attributedText)];
218
- if (attrText.length > 0) {
219
- NSDictionary *attrs = [attrText attributesAtIndex:0 effectiveRange:nil];
220
- if (!textProperties.color && attrs[NSForegroundColorAttributeName]) {
221
- textProperties.color = attrs[NSForegroundColorAttributeName];
222
- }
223
- if (!textProperties.font && attrs[NSFontAttributeName]) {
224
- textProperties.font = attrs[NSFontAttributeName];
225
- }
226
- NSParagraphStyle *style = attrs[NSParagraphStyleAttributeName];
227
- if (style) {
228
- textProperties.alignment = style.alignment;
229
- }
230
- }
231
- }
232
- return textProperties;
233
- }
234
- return nil;
235
- }
236
-
237
- RCT_EXPORT_METHOD(dismissActiveSurvey)
238
- {
239
- [[UserLeap shared] dismissActiveSurvey];
240
- }
241
-
242
- RCT_EXPORT_METHOD(pauseDisplayingSurveys)
243
- {
244
- [[UserLeap shared] pauseDisplayingSurveys];
245
- }
246
-
247
- RCT_EXPORT_METHOD(unpauseDisplayingSurveys)
248
- {
249
- [[UserLeap shared] unpauseDisplayingSurveys];
250
- }
251
-
252
- RCT_EXPORT_METHOD(overrideUserInterfaceMode:(NSInteger)mode)
253
- {
254
- [[UserLeap shared] overrideUserInterfaceModeWithMode:mode];
255
- }
256
-
257
- - (_SGRNViewProperties * _Nullable)propertiesFromView:(UIView * _Nonnull)passedView {
258
- if ([passedView isKindOfClass:[RCTView class]]) {
259
- RCTView *rView = (RCTView *) passedView;
260
- if (rView.borderWidth > 0) {
261
- _SGRNViewProperties *props = [[_SGRNViewProperties alloc] init];
262
- props.borderColor = rView.borderColor;
263
- props.borderWidth = rView.borderWidth;
264
- return props;
265
- }
266
- }
267
- return nil;
268
- }
269
-
270
- - (NSString *)extractTextFromParagraphComponentView:(UIView *)view {
271
- if ([view respondsToSelector:@selector(attributedText)]) {
272
- NSAttributedString *attrText = [view performSelector:@selector(attributedText)];
273
- return attrText.string;
274
- }
275
- if ([view respondsToSelector:@selector(text)]) {
276
- NSString *text = [view performSelector:@selector(text)];
277
- return text;
278
- }
279
- NSMutableString *result = [NSMutableString string];
280
- for (UIView *subview in view.subviews) {
281
- NSString *subText = [self extractTextFromParagraphComponentView:subview];
282
- if (subText) [result appendString:subText];
283
- }
284
- return result;
285
- }
286
-
287
- @end