How to use SurveyMonkey in React Native

Issue #521

1
2
3
4
5
#import <React/RCTBridgeModule.h>

@interface RNSurveyManager : NSObject <RCTBridgeModule>

@end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#import "RNSurveyManager.h"
#import <React/RCTLog.h>
#import <SurveyMonkeyiOSSDK/SurveyMonkeyiOSSDK.h>

@interface RNSurveyManager()<SMFeedbackDelegate>
@property (nonatomic, strong) SMFeedbackViewController * feedbackController;
@end

@implementation RNSurveyManager

- (instancetype)init {
self = [super init];
if (self) {
self.feedbackController = [[SMFeedbackViewController alloc] initWithSurvey:@"VV8X5QA"];
self.feedbackController.delegate = self;
}
return self;
}

+ (BOOL)requiresMainQueueSetup {
return YES;
}

- (dispatch_queue_t)methodQueue {
return dispatch_get_main_queue();
}

RCT_EXPORT_MODULE(SurveyManager);

- (void)respondentDidEndSurvey:(SMRespondent *)respondent error:(NSError *)error {
NSLog(@"respondent %@ error %@", respondent, error);
}

RCT_EXPORT_METHOD(show:(RCTResponseSenderBlock)callback) {
[UIApplication.sharedApplication.keyWindow.rootViewController
presentViewController:self.feedbackController
animated:YES
completion:^() {
callback(@[]);
}];
}

@end
1
2
3
4
5
6
7
8
9
10
// @flow

import { NativeModules } from 'react-native'

type SurveyManagerType = {
show: () => void
}

const SurveyManager: SurveyManagerType = NativeModules.SurveyManager
export default SurveyManager

Comments