react-native-pollfish-support

1.1.0 • Public • Published

react-native-pollfish-support

Getting started

$ yarn add react-native-pollfish-support

cd ios && pod install && cd ..

iOS CONFIG

  • add these code into Podfile:

  • if you are using flipper add this part: use_flipper!({ 'Flipper-Folly' => '2.3.0' })

Usage

import Pollfish from "react-native-pollfish-support";

const POLLFISH_EVENT = {
  SURVEY_RECEIVED: "surveyReceived",
  SURVEY_COMPLETED: "surveyCompleted",
  SURVEY_NOT_ELIGIBLE: "userNotEligible",
  SURVEY_NOT_AVAILABLE: "surveyNotAvailable",
  SURVEY_OPENED: "surveyOpened",
  SURVEY_CLOSED: "surveyClosed",
};

const pollfishConfig = {
  pollfishApiKey: "POLLFISH_API_KEY",
  releaseMode: true,
  customMode: true,
  offerWallMode: false,
};

const initPollfishSurvey = () =>
  Pollfish.initialize(
    pollfishConfig.pollfishApiKey,
    pollfishConfig.debugMode,
    pollfishConfig.customMode,
    pollfishConfig.offerWallMode
  );

const handleSurveyReceived = () => {
  // Do something
};
const handleSurveyClosed = () => {
  // Do something
};
const handleSurveyCompleted = () => {
  // Do something
};
const handleSurveyNotAvailable = () => {
  // Do something
};
const handleSurveyNotEligible = () => {
  // Do something
};
const openSurvey = () => {
  Pollfish.show();
};

const addPollfishListener = () => {
  Pollfish.addEventListener(
    POLLFISH_EVENT.SURVEY_RECEIVED,
    handleSurveyReceived
  );
  Pollfish.addEventListener(POLLFISH_EVENT.SURVEY_CLOSED, handleSurveyClosed);
  Pollfish.addEventListener(
    POLLFISH_EVENT.SURVEY_COMPLETED,
    handleSurveyCompleted
  );
  Pollfish.addEventListener(
    POLLFISH_EVENT.SURVEY_NOT_AVAILABLE,
    handleSurveyNotAvailable
  );
  Pollfish.addEventListener(
    POLLFISH_EVENT.SURVEY_NOT_ELIGIBLE,
    handleSurveyNotEligible
  );
};

useEffect(() => {
  initPollfishSurvey();
  addPollfishListener();
  return () => {
    Pollfish.removeAllListeners();
  };
}, []);

return <PTextButton onPress={openSurvey} />;

crying cat

Package Sidebar

Install

npm i react-native-pollfish-support

Weekly Downloads

3

Version

1.1.0

License

MIT

Unpacked Size

214 kB

Total Files

31

Last publish

Collaborators

  • ngocthien0507anttech