File tree Expand file tree Collapse file tree 2 files changed +49
-2
lines changed
Expand file tree Collapse file tree 2 files changed +49
-2
lines changed Original file line number Diff line number Diff 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
2626Install ** React Native Draft.js Render** on your React Native project, using NPM or Yarn:
Original file line number Diff line number Diff line change 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+ ` ` `
You can’t perform that action at this time.
0 commit comments