Skip to content

Commit 903b46c

Browse files
authored
Merge pull request #292 from rees46/feat/DEV-776-RN-SDK-Stories
docs(stories): RN SDK stories
2 parents cfe3d78 + 7986b10 commit 903b46c

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

source/includes/_stories.md.erb

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ StoriesView storiesView = new StoriesView(this, "STORY BLOCK CODE");
150150
((ViewGroup) findViewById(R.id.stories)).addView(storiesView);
151151
<%= config[:android_sdk_package_name] %>.initializeStoriesView(storiesView);
152152

153+
```
154+
```jsx
155+
import <%= config[:rn_sdk_package_name] %> from '<%= config[:rn_sdk_package_code] %>/react-native-sdk';
156+
import { Platform } from 'react-native';
157+
158+
const sdk = new <%= config[:rn_sdk_package_name] %>(
159+
'YOUR_API_KEY',
160+
Platform.OS, // 'ios' or 'android'
161+
true // debug mode enabled (true or false)
162+
);
153163
```
154164

155165
## Show stories block on request
@@ -206,6 +216,55 @@ public func collectionView(_ collectionView: UICollectionView, didSelectItemAt i
206216
// indexPath.row is the index of the chosen element
207217
// showStoriesByUserClick tries to get a story from the stories array, and then renders it
208218
}
219+
```
220+
```jsx
221+
222+
/* Due to the asynchronized SDK initialization it is reccomended to wait until SDK is ready */
223+
224+
if (sdk.isInit()) {
225+
// SDK is ready
226+
}
227+
/* Getting the list of stories */
228+
229+
const response = await sdk.getStories('STORIES_CODE');
230+
if (response && response.stories) {
231+
const allStories = response.stories;
232+
}
233+
234+
/* Display of the list of stories */
235+
236+
<StoriesList
237+
sdk={sdk}
238+
code="STORIES_CODE"
239+
onStoryPress={(story, index, settings) => {
240+
// Processing the user's choice of story on press
241+
}}
242+
/>
243+
244+
245+
/* Displaying a single story
246+
247+
Parameters:
248+
- visible: whether the story viewer is shown
249+
- stories: an array of stories fetched from the server
250+
- initialStoryIndex: the index of the story that will be displayed first
251+
- settings: story style settings
252+
- onClose: callback triggered when the story viewer is closed
253+
- sdk: links the component to the SDK to interact with the API
254+
- code: story set code
255+
*/
256+
257+
<StoryViewer
258+
visible={storiesVisible}
259+
stories={allStories}
260+
initialStoryIndex={0}
261+
settings={storiesSettings}
262+
onClose={() => setStoriesVisible(false)}
263+
sdk={sdk}
264+
code="STORIES_CODE"
265+
/>
266+
267+
209268
```
210269

211270
After initializing the SDK, you can request a block of stories. To start initialization, follow the [instructions](#stories-initialization) in the Stories initialization section.
@@ -329,6 +388,23 @@ stories.settings.products_button_font_family = Typeface.DEFAULT_BOLD;
329388

330389

331390
```jsx
391+
392+
/* Customizing story styles
393+
394+
You can use SDK default font and color themes,
395+
or provide your own settings object to override them
396+
397+
*/
398+
399+
<StoryViewer
400+
visible={storiesVisible}
401+
stories={allStories}
402+
initialStoryIndex={0}
403+
settings={YOUR_CUSTOM_SETTINGS}
404+
onClose={() => setStoriesVisible(false)}
405+
sdk={sdk}
406+
code="STORIES_CODE"
407+
/>
332408
```
333409
After initializing the SDK, you can set the desired style configuration for the fonts and buttons of the Stories block.
334410

0 commit comments

Comments
 (0)