Created
January 29, 2020 15:15
-
-
Save alloy/8fb6eb4bd5c613ac2e37923842e73748 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import { NativeModules } from "react-native" | |
const SurveyManager = NativeModules.SurveyManager | |
class Survey extends React.Component { | |
componentDidMount() { | |
SurveyManager.start({ ... }, prompt => { | |
this.setState({ prompt }) | |
}) | |
} | |
render() { | |
if (!this.state.prompt) { | |
return null | |
} | |
return ( | |
<View> | |
<Text>{this.state.prompt.question}</Text> | |
<Button title="Next question" onPress={() => SurveyManager.nextScreen(true) } /> | |
</View> | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface SurveyManager : NSObject <OFISurveyHandlerDelegate> | |
@property (strong) RCTResponseSenderBlock showNextScreenCallback; | |
@end | |
@implementation SurveyManager | |
RCT_EXPORT_METHOD(start:(NSDictionary *)surveyOptions | |
completion:(RCTResponseSenderBlock)showNextScreenCallback | |
{ | |
self.showNextScreenCallback = showNextScreenCallback; | |
OFFloodgateOptions *options = [[OFFloodgateOptions alloc] init]; | |
options.surveyHandlerDelegate = self; | |
// ... | |
[OfficeFloodgate initWithOptions:options]; | |
[[OfficeFloodgate getEngine] start]; | |
} | |
- (void)showPrompt:(id<OFIPrompt>)prompt | |
{ | |
self.showNextScreenCallback(@{ | |
@"question": prompt.question, | |
}); | |
} | |
RCT_EXPORT_METHOD(nextScreen:(BOOL)showNextScreen) | |
{ | |
[prompt presentNextScreenForSelectedButton:showNextScreen ? OFPromptButtonYes : OFPromptButtonNo]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment