@selligent-marketing-cloud/selligent-react-native 4.0.0 → 4.0.2

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.
@@ -64,7 +64,7 @@ dependencies {
64
64
  implementation 'androidx.cardview:cardview:1.0.0'
65
65
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1'
66
66
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3'
67
- implementation 'com.selligent.sdk:selligent_mobile_reactnative_sdk:3.8.1'
67
+ implementation 'com.selligent.sdk:selligent_mobile_reactnative_sdk:3.8.2'
68
68
  }
69
69
 
70
70
  def loadSelligentSettings(variant) {
@@ -0,0 +1,11 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ @interface CustomEvent : NSObject
4
+
5
+ @property(nonatomic) NSString *_Nonnull name;
6
+ @property(nonatomic) NSString *_Nonnull type;
7
+ @property(nonatomic) NSDictionary *_Nullable data;
8
+
9
+ + (instancetype _Nonnull) eventWithData:(NSDictionary*_Nullable)data AndName:(NSString*_Nonnull)name AndType:(NSString*_Nonnull)type;
10
+
11
+ @end
@@ -0,0 +1,18 @@
1
+ #import "CustomEvent.h"
2
+
3
+ @implementation CustomEvent
4
+
5
+ + (instancetype) eventWithData:(NSDictionary*)data AndName:(NSString*)name AndType:(NSString*)type {
6
+ return [[self alloc] initWithData:data AndName:name AndType: type];
7
+ }
8
+
9
+ - (instancetype) initWithData:(NSDictionary*)data AndName:(NSString*)name AndType:(NSString*)type {
10
+ self = [super init];
11
+ self.data = data;
12
+ self.type = type;
13
+ self.name = name;
14
+
15
+ return self;
16
+ }
17
+
18
+ @end
@@ -1,11 +1,3 @@
1
- //
2
- // RNSelligentMapper.h
3
- // SelligentDevAppRN
4
- //
5
- // Created by Marc Biosca on 16/5/23.
6
- // Copyright © 2023 Facebook. All rights reserved.
7
- //
8
-
9
1
  #if __has_include(<React/RCTBridgeModule.h>)
10
2
  #import <React/RCTBridgeModule.h>
11
3
  #import <React/RCTEventEmitter.h>
@@ -18,4 +10,7 @@
18
10
 
19
11
  @interface RNSelligentMapper : RCTEventEmitter <RCTBridgeModule, RNSelligentEventHandlerProtocol>
20
12
 
13
+ @property (nonatomic) BOOL listeningEvents;
14
+ @property (nonatomic) NSMutableArray * pendingEvents;
15
+
21
16
  @end
@@ -1,4 +1,5 @@
1
1
  #import "RNSelligentMapper.h"
2
+ #import "CustomEvent.h"
2
3
 
3
4
  @implementation RNSelligentMapper
4
5
 
@@ -8,6 +9,8 @@ RCT_EXPORT_MODULE(RNSelligent)
8
9
  self = [super init];
9
10
 
10
11
  RNSelligent.eventDelegate = self;
12
+ self.pendingEvents = [NSMutableArray new];
13
+ [RNSelligent subscribeToEvents:@[]];
11
14
 
12
15
  return self;
13
16
  }
@@ -133,10 +136,27 @@ RCT_EXPORT_METHOD(sendEvent:(NSDictionary *)data successCallback:(RCTResponseSen
133
136
 
134
137
  RCT_EXPORT_METHOD(subscribeToEvents:(NSArray<NSString *> *)events) {
135
138
  [RNSelligent subscribeToEvents:events];
139
+ self.listeningEvents = true;
140
+ [self sendPendingEvents];
136
141
  }
137
142
 
138
143
  - (void) sendBroadcastEventWithName:(NSString * _Nonnull)name type:(NSString * _Nonnull)type data:(NSDictionary * _Nullable)data {
139
- [self sendEventWithName:name body:@{@"data": data ?: [NSNull null], @"broadcastEventType": type}];
144
+ if (self.listeningEvents) {
145
+ [self sendEventWithName:name body:@{@"data": data ?: [NSNull null], @"broadcastEventType": type}];
146
+ }
147
+ else {
148
+ [self.pendingEvents addObject:[CustomEvent eventWithData:data AndName:name AndType:type]];
149
+ }
150
+ }
151
+
152
+ - (void) sendPendingEvents {
153
+ if (self.pendingEvents.count == 0) { return; }
154
+
155
+ for (CustomEvent* event in self.pendingEvents) {
156
+ [self sendEventWithName:event.name body:@{@"data": event.data ?: [NSNull null], @"broadcastEventType": event.type}];
157
+ }
158
+
159
+ self.pendingEvents = [NSMutableArray new];
140
160
  }
141
161
 
142
162
  - (NSArray<NSString *> *) supportedEvents {
@@ -153,4 +173,4 @@ RCT_EXPORT_METHOD(subscribeToEvents:(NSArray<NSString *> *)events) {
153
173
  ];
154
174
  }
155
175
 
156
- @end
176
+ @end
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  },
5
5
  "name": "@selligent-marketing-cloud/selligent-react-native",
6
6
  "title": "Marigold Engage React Native",
7
- "version": "4.0.0",
7
+ "version": "4.0.2",
8
8
  "description": "React Native wrapper for the Marigold Engage Android and iOS SDKs",
9
9
  "main": "index.js",
10
10
  "repository": {