Skip to content

Instantly share code, notes, and snippets.

@alloy
Created January 29, 2020 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alloy/8fb6eb4bd5c613ac2e37923842e73748 to your computer and use it in GitHub Desktop.
Save alloy/8fb6eb4bd5c613ac2e37923842e73748 to your computer and use it in GitHub Desktop.
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>
)
}
}
@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