Skip to content

Commit b7d274a

Browse files
author
Raphael Freitas
committed
Add documentation for Atomic Types
1 parent 251271f commit b7d274a

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ Join the [#react-native-render](https://draftjs.slack.com/messages/react_native_
1919
## Documentation
2020

2121
* [Get Started](https://github.com/globocom/react-native-draftjs-render/blob/master/docs/GetStarted.md)
22-
* [Custom Styles](https://github.com/globocom/react-native-draftjs-render/blob/master/docs/CustomStyles.md)
23-
* Atomic Types (to do).
22+
* [Add Custom Styles](https://github.com/globocom/react-native-draftjs-render/blob/master/docs/CustomStyles.md)
23+
* [Handle Atomic Types](https://github.com/globocom/react-native-draftjs-render/blob/master/docs/AtomicTypes.md)
2424

2525
## Getting Started
2626
Install **React Native Draft.js Render** on your React Native project, using NPM or Yarn:

docs/AtomicTypes.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Atomic Types
2+
3+
RNDraftJSRender makes it easy to handle atomic elements with a `atomicHandler` function. Take a look at this example:
4+
5+
Let's say that we have a atomic of type `image` inside our `contentState.blocks`.
6+
7+
```json
8+
{
9+
"blocks": [
10+
{
11+
"key": "3tvln",
12+
"type": "atomic",
13+
"data": {
14+
"type": "image",
15+
"uri": "https://lorempixel.com/400/200/"
16+
}
17+
}
18+
]
19+
}
20+
```
21+
22+
You can render this atomic passing a callback called `atomicHandler` to RNDraftJSRender.
23+
24+
```js
25+
const atomicHandler = (item: Object, entityMap: Object): ?React$Element<*> => {
26+
switch (item.data.type) {
27+
case 'image':
28+
return (
29+
<View key={item.key} style={{ flex: 1 }}>
30+
<Image
31+
style={{ width: 288, height: 161 }}
32+
source={{ uri: item.data.uri }}
33+
/>
34+
</View>
35+
);
36+
default:
37+
return null;
38+
}
39+
};
40+
41+
const props = {
42+
contentState,
43+
atomicHandler,
44+
};
45+
46+
const blocks = getRNDraftJSBlocks(props);
47+
```

0 commit comments

Comments
 (0)