Skip to content

Commit 5df5c92

Browse files
authored
Merge pull request #3 from verloop/android_upgrade
Adding button click listeners
2 parents 3893059 + e0076e9 commit 5df5c92

File tree

18 files changed

+92
-19
lines changed

18 files changed

+92
-19
lines changed

android/src/main/java/com/reactlibrary/VerloopSdkPackage/RNVerloopSdkModule.java

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
import com.facebook.react.bridge.ReactContextBaseJavaModule;
66
import com.facebook.react.bridge.ReactMethod;
77
import com.facebook.react.bridge.Callback;
8+
import com.facebook.react.bridge.LifecycleEventListener;
9+
10+
import com.facebook.react.modules.core.DeviceEventManagerModule;
11+
import com.facebook.react.bridge.WritableMap;
12+
import com.facebook.react.bridge.Arguments;
813

914
import android.app.Activity;
1015

1116
import io.verloop.sdk.Verloop;
17+
import io.verloop.sdk.LiveChatButtonClickListener;
1218
import io.verloop.sdk.VerloopConfig;
1319

14-
public class RNVerloopSdkModule extends ReactContextBaseJavaModule {
20+
public class RNVerloopSdkModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
1521

1622
private final ReactApplicationContext reactContext;
1723

@@ -22,26 +28,44 @@ public class RNVerloopSdkModule extends ReactContextBaseJavaModule {
2228
public RNVerloopSdkModule(ReactApplicationContext reactContext) {
2329
super(reactContext);
2430
this.reactContext = reactContext;
31+
reactContext.addLifecycleEventListener(this);
2532
}
2633

2734
@Override
2835
public String getName() {
2936
return "RNVerloopSdk";
3037
}
3138

32-
/*@Override
33-
public String getName() {
34-
return "VerloopSdk";
35-
}*/
39+
private void sendEvent(ReactApplicationContext reactContext,
40+
String eventName,
41+
WritableMap params) {
42+
reactContext
43+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
44+
.emit(eventName, params);
45+
}
46+
47+
private void setButtonClickListener(VerloopConfig verloopConfig){
48+
verloopConfig.setButtonOnClickListener(new LiveChatButtonClickListener(){
49+
public void buttonClicked(String title, String type, String payload) {
50+
WritableMap params = Arguments.createMap();
51+
params.putString("title", title);
52+
params.putString("type", type);
53+
params.putString("payload", payload);
54+
sendEvent(reactContext, "veloop_button_clicked", params);
55+
}
56+
});
57+
}
3658

3759
@ReactMethod
3860
public void createUserConfig(String clientId, String userId) {
3961
verloopConfig = new VerloopConfig(clientId, userId);
62+
setButtonClickListener(verloopConfig);
4063
}
4164

4265
@ReactMethod
4366
public void createAnonymousUserConfig(String clientId) {
4467
verloopConfig = new VerloopConfig(clientId);
68+
setButtonClickListener(verloopConfig);
4569
}
4670

4771
@ReactMethod
@@ -103,4 +127,21 @@ public void showChat() {
103127
verloop.showChat();
104128
}
105129
}
130+
131+
@Override
132+
public void onHostResume() {
133+
// do nothing
134+
}
135+
136+
@Override
137+
public void onHostPause() {
138+
// do nothing
139+
}
140+
141+
@Override
142+
public void onHostDestroy() {
143+
if(verloop != null){
144+
verloop.onStopChat();
145+
}
146+
}
106147
}

ios/RNVerloopSdk.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
A0ACB85124A3B33C00C50CE4 /* VerloopSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A0ACB85024A3B33C00C50CE4 /* VerloopSDK.framework */; };
10+
A08AD79C24AB9C18005E51FB /* VerloopSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A08AD79B24AB9C18005E51FB /* VerloopSDK.framework */; };
1111
A0D2791924A2347100CFD63C /* libRNVerloopSdk.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 134814201AA4EA6300B7C361 /* libRNVerloopSdk.a */; };
1212
B3E7B58A1CC2AC0600A0062D /* RNVerloopSdk.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RNVerloopSdk.m */; };
1313
/* End PBXBuildFile section */
@@ -26,7 +26,7 @@
2626

2727
/* Begin PBXFileReference section */
2828
134814201AA4EA6300B7C361 /* libRNVerloopSdk.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNVerloopSdk.a; sourceTree = BUILT_PRODUCTS_DIR; };
29-
A0ACB85024A3B33C00C50CE4 /* VerloopSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = VerloopSDK.framework; sourceTree = "<group>"; };
29+
A08AD79B24AB9C18005E51FB /* VerloopSDK.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = VerloopSDK.framework; sourceTree = "<group>"; };
3030
B3E7B5881CC2AC0600A0062D /* RNVerloopSdk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNVerloopSdk.h; sourceTree = "<group>"; };
3131
B3E7B5891CC2AC0600A0062D /* RNVerloopSdk.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNVerloopSdk.m; sourceTree = "<group>"; };
3232
/* End PBXFileReference section */
@@ -37,7 +37,7 @@
3737
buildActionMask = 2147483647;
3838
files = (
3939
A0D2791924A2347100CFD63C /* libRNVerloopSdk.a in Frameworks */,
40-
A0ACB85124A3B33C00C50CE4 /* VerloopSDK.framework in Frameworks */,
40+
A08AD79C24AB9C18005E51FB /* VerloopSDK.framework in Frameworks */,
4141
);
4242
runOnlyForDeploymentPostprocessing = 0;
4343
};
@@ -58,7 +58,7 @@
5858
B3E7B5881CC2AC0600A0062D /* RNVerloopSdk.h */,
5959
B3E7B5891CC2AC0600A0062D /* RNVerloopSdk.m */,
6060
134814211AA4EA7D00B7C361 /* Products */,
61-
A0ACB85024A3B33C00C50CE4 /* VerloopSDK.framework */,
61+
A08AD79B24AB9C18005E51FB /* VerloopSDK.framework */,
6262
);
6363
sourceTree = "<group>";
6464
};

ios/RNVerloopSdk/RNVerloopSdk.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11

22
#if __has_include("RCTBridgeModule.h")
33
#import "RCTBridgeModule.h"
4+
#import "RCTEventEmitter.h"
45
#else
56
#import <React/RCTBridgeModule.h>
7+
#import <React/RCTEventEmitter.h>
68
#endif
79

8-
@interface RNVerloopSdk : NSObject <RCTBridgeModule>
10+
@interface RNVerloopSdk : RCTEventEmitter <RCTBridgeModule>
911

1012
@end
1113

ios/RNVerloopSdk/RNVerloopSdk.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,31 @@ - (dispatch_queue_t)methodQueue
1111
}
1212
RCT_EXPORT_MODULE()
1313

14+
- (NSArray<NSString *> *)supportedEvents
15+
{
16+
return @[@"veloop_button_clicked"];
17+
}
18+
19+
typedef void (^LiveChatButtonClickListener)(NSString *, NSString *, NSString *);
20+
1421
VLConfig *config;
1522

1623
RCT_EXPORT_METHOD(createUserConfig:(NSString *)clientId userId:(NSString *)userId )
1724
{
18-
printf("came to createUserConfig");
1925
config = [[VLConfig alloc] initWithClientId:clientId userId:userId];
26+
[config setButtonOnClickListenerOnButtonClicked:^(NSString *title, NSString *type, NSString *payload){
27+
[self sendEventWithName:@"veloop_button_clicked" body:@{@"title": title, @"type": type, @"payload": payload }];
28+
return;
29+
}];
2030
}
2131

2232
RCT_EXPORT_METHOD(createAnonymousUserConfig:(NSString *)clientId )
2333
{
2434
config = [[VLConfig alloc] initWithClientId:clientId];
35+
[config setButtonOnClickListenerOnButtonClicked:^(NSString *title, NSString *type, NSString *payload){
36+
[self sendEventWithName:@"veloop_button_clicked" body:@{@"title": title, @"type": type, @"payload": payload }];
37+
return;
38+
}];
2539
}
2640

2741
RCT_EXPORT_METHOD(setFcmToken:(NSString *)token)

ios/VerloopSDK.framework/Headers/VerloopSDK-Swift.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ SWIFT_CLASS("_TtC10VerloopSDK8VLConfig")
217217
- (void)setUserEmailWithUserEmail:(NSString * _Nullable)email;
218218
- (void)setUserPhoneWithUserPhone:(NSString * _Nullable)phone;
219219
- (void)setRecipeIdWithRecipeId:(NSString * _Nullable)id;
220+
- (void)setButtonOnClickListenerOnButtonClicked:(void (^ _Nullable)(NSString * _Nullable, NSString * _Nullable, NSString * _Nullable))buttonClicked;
220221
- (void)putCustomFieldWithKey:(NSString * _Nonnull)key value:(NSString * _Nonnull)value scope:(enum SCOPE)scope;
221222
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
222223
+ (nonnull instancetype)new SWIFT_UNAVAILABLE_MSG("-init is unavailable");
@@ -457,6 +458,7 @@ SWIFT_CLASS("_TtC10VerloopSDK8VLConfig")
457458
- (void)setUserEmailWithUserEmail:(NSString * _Nullable)email;
458459
- (void)setUserPhoneWithUserPhone:(NSString * _Nullable)phone;
459460
- (void)setRecipeIdWithRecipeId:(NSString * _Nullable)id;
461+
- (void)setButtonOnClickListenerOnButtonClicked:(void (^ _Nullable)(NSString * _Nullable, NSString * _Nullable, NSString * _Nullable))buttonClicked;
460462
- (void)putCustomFieldWithKey:(NSString * _Nonnull)key value:(NSString * _Nonnull)value scope:(enum SCOPE)scope;
461463
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
462464
+ (nonnull instancetype)new SWIFT_UNAVAILABLE_MSG("-init is unavailable");
@@ -701,6 +703,7 @@ SWIFT_CLASS("_TtC10VerloopSDK8VLConfig")
701703
- (void)setUserEmailWithUserEmail:(NSString * _Nullable)email;
702704
- (void)setUserPhoneWithUserPhone:(NSString * _Nullable)phone;
703705
- (void)setRecipeIdWithRecipeId:(NSString * _Nullable)id;
706+
- (void)setButtonOnClickListenerOnButtonClicked:(void (^ _Nullable)(NSString * _Nullable, NSString * _Nullable, NSString * _Nullable))buttonClicked;
704707
- (void)putCustomFieldWithKey:(NSString * _Nonnull)key value:(NSString * _Nonnull)value scope:(enum SCOPE)scope;
705708
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
706709
+ (nonnull instancetype)new SWIFT_UNAVAILABLE_MSG("-init is unavailable");
@@ -941,6 +944,7 @@ SWIFT_CLASS("_TtC10VerloopSDK8VLConfig")
941944
- (void)setUserEmailWithUserEmail:(NSString * _Nullable)email;
942945
- (void)setUserPhoneWithUserPhone:(NSString * _Nullable)phone;
943946
- (void)setRecipeIdWithRecipeId:(NSString * _Nullable)id;
947+
- (void)setButtonOnClickListenerOnButtonClicked:(void (^ _Nullable)(NSString * _Nullable, NSString * _Nullable, NSString * _Nullable))buttonClicked;
944948
- (void)putCustomFieldWithKey:(NSString * _Nonnull)key value:(NSString * _Nonnull)value scope:(enum SCOPE)scope;
945949
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
946950
+ (nonnull instancetype)new SWIFT_UNAVAILABLE_MSG("-init is unavailable");
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)