Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dismiss command #18

Merged
merged 3 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ private void checkIdentity(){
@ReactMethod
public void resetUserIdentity() {
Chat.INSTANCE.resetIdentity();
Log.v(TAG,"resetUserIdentity");
}

@ReactMethod
Expand Down Expand Up @@ -326,6 +325,12 @@ public void startChat(ReadableMap options) {

}

@ReactMethod
public void dismiss() {
// do nothing see https://pagopa.atlassian.net/browse/IABT-1348?focusedCommentId=31396
}


@ReactMethod
public void setNotificationToken(String token) {
PushNotificationsProvider pushProvider = Chat.INSTANCE.providers().pushNotificationsProvider();
Expand Down
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ declare module 'io-react-native-zendesk' {
// remove log data and custom fields
export function reset(): void;

// iOS only - close the current zendesk view (ticket creation, tickets list) if any
export function dismiss(): void;

// function to open a ticket
export function openTicket(): void;

Expand Down
26 changes: 20 additions & 6 deletions ios/RNZendeskChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ @implementation RNZendeskChat
NSString* logId;
NSMutableDictionary* customFields;
NSMutableArray* tags;
UIViewController *currentController;
#ifndef MAX_LOG_LENGTH
#define MAX_LOG_LENGTH 60000
#endif
Expand All @@ -84,6 +85,16 @@ @implementation RNZendeskChat
[tags removeAllObjects];
}

// dismiss the current controller shown, if any
RCT_EXPORT_METHOD(dismiss) {
dispatch_sync(dispatch_get_main_queue(), ^{
if(currentController != nil){
[currentController dismissViewControllerAnimated:TRUE completion:nil];
}
currentController = nil;
});
}

- (void) initGlobals
{
if(mutableLog == nil){
Expand Down Expand Up @@ -224,6 +235,7 @@ - (void) showHelpCenterFunction:(NSDictionary *)options {
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
currentController = topController;
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: controller];
[topController presentViewController:navControl animated:YES completion:nil];
}
Expand All @@ -242,6 +254,7 @@ - (void) openTicketFunction {
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
currentController = topController;
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: openTicketController];
[topController presentViewController:navControl animated:YES completion:nil];
}
Expand Down Expand Up @@ -292,12 +305,13 @@ - (void) startChatFunction:(NSDictionary *)options {
style: UIBarButtonItemStylePlain
target: self
action: @selector(chatClosedClicked)];
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: chatController];
[topController presentViewController:navControl animated:YES completion:nil];
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
currentController = topController;
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: chatController];
[topController presentViewController:navControl animated:YES completion:nil];
}
- (void) chatClosedClicked {
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "io-react-native-zendesk",
"version": "0.3.17",
"version": "0.3.18",
"description": "React native wrapper for Zendesk Unified SDK",
"main": "index.js",
"scripts": {
Expand Down