Skip to main content

React Native SDK

Getting Started

If you haven't already, please start with the Getting Started Guide below.

Installation

The first step is to install the Polls Platform React Native SDK.

npm install @polls-platform/react-native
info

From react-native 0.60 autolinking will take care of the link step but don't forget to run pod install

React Native modules that include native Objective-C, Swift, Java, or Kotlin code have to be "linked" so that the compiler knows to include them in the app.

react-native link @polls-platform/react-native

NOTE: If you ever need to uninstall the Polls Platform React Native SDK, run react-native unlink @polls-platform/react-native to unlink it.

iOS

If using CocoaPods, in the ios/ directory run:

pod install

Peer Dependencies

At this time, the SDK is implemented as a wrapper of a Web View. This method has several advantages:

  • It makes the footprint of the SDK very small
  • It ensures proper separation to avoid any unwanted interactions
  • You control exactly what data is shared from your app to the Embedded Poll Web View

React Native WebView

React Native Webview is a required peer dependency. Please follow the instructions in the WebView Getting Started Guide.

Create a Poll

Once you have installed the SDK and dependencies, you're ready to create your first poll.

import {  initializePolls,  DomainConfigType,  PollResponse,  createPoll,  Environment,} from "@polls-platform/react-native";initializePolls({  apiKey: "YOUR API KEY",  domainConfig: {    type: DomainConfigType.subdomain,    subdomain: "YOUR SUBDOMAIN",  },  environment: Environment.production,});// creating a poll is synchronous and instantaneousconst poll: PollResponse = createPoll({  title,  ownerId,  settings,  options,});// the poll can be opened immediately// in the browser, or embedded in your siteconsole.log("Poll URL", poll.url);

Setting up Poll Data

The following is a more complete example of setting up fields for a poll.

import {  createPoll,  PollResponse,  OptionRequest,  OptionType,} from "@polls-platform/react-native";const options: OptionRequest[] = [  {    resourceId: "1", // the id of this resource in your system    title: "This is the first option",    type: OptionType.defaultTemplate,    subtitle: "Subtitles are displayed below the title",    details: "Descriptions are on the third line",    url: "https://example.com/1",    imageUrl: "https://example.com/images/1.png",  },  {    resourceId: "2", // the id of this resource in your system    title: "This is the second option",    type: OptionType.defaultTemplate,    subtitle: "Subtitles are displayed below the title",    details: "Descriptions are on the third line",    url: "https://example.com/2",    imageUrl: "https://example.com/images/2.png",  },];const poll: PollResponse = createPoll({  title: "Which one should we buy?",  ownerId: ownerId,  settings: {    multipleVotes: true,  },  options: options,});

Opening the Poll

Continue to the next section to learn about the various options for opening the Poll.