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